Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Nicer API for instance deployment #4493

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/api/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { registerContractClass } from '../deployment/register_class.js';
export { broadcastPrivateFunction, broadcastUnconstrainedFunction } from '../deployment/broadcast_function.js';
export { deployInstance } from '../deployment/deploy_instance.js';
28 changes: 28 additions & 0 deletions yarn-project/aztec.js/src/deployment/deploy_instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ContractInstanceWithAddress } from '@aztec/types/contracts';

import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js';
import { Wallet } from '../wallet/index.js';
import { getDeployerContract } from './protocol_contracts.js';

/**
* Sets up a call to the canonical deployer contract to publicly deploy a contract instance.
* @param wallet - The wallet to use for the deployment.
* @param instance - The instance to deploy.
* @param opts - Additional options.
*/
export function deployInstance(
wallet: Wallet,
instance: ContractInstanceWithAddress,
opts: { /** Set to true to *not* mix in the deployer into the address. */ universalDeploy?: boolean } = {},
): ContractFunctionInteraction {
const deployer = getDeployerContract(wallet);
const { salt, contractClassId, portalContractAddress, publicKeysHash } = instance;
return deployer.methods.deploy(
salt,
contractClassId,
instance.initializationHash,
portalContractAddress,
publicKeysHash,
!!opts.universalDeploy,
);
}
7 changes: 7 additions & 0 deletions yarn-project/aztec.js/src/deployment/protocol_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer';
import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer';

import { UnsafeContract } from '../contract/unsafe_contract.js';
import { Wallet } from '../wallet/index.js';
Expand All @@ -8,3 +9,9 @@ export function getRegistererContract(wallet: Wallet) {
const { artifact, instance } = getCanonicalClassRegisterer();
return new UnsafeContract(instance, artifact, wallet);
}

/** Returns a Contract wrapper for the instance deployer. */
export function getDeployerContract(wallet: Wallet) {
const { artifact, instance } = getCanonicalInstanceDeployer();
return new UnsafeContract(instance, artifact, wallet);
}
15 changes: 6 additions & 9 deletions yarn-project/end-to-end/src/e2e_deploy_contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import {
import {
broadcastPrivateFunction,
broadcastUnconstrainedFunction,
deployInstance,
registerContractClass,
} from '@aztec/aztec.js/deployment';
import { ContractClassIdPreimage, Point, PublicKey, computePublicKeysHash } from '@aztec/circuits.js';
import { ContractClassIdPreimage, Point, PublicKey } from '@aztec/circuits.js';
import { siloNullifier } from '@aztec/circuits.js/abis';
import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { ContractInstanceDeployerContract, StatefulTestContract } from '@aztec/noir-contracts';
Expand Down Expand Up @@ -307,16 +308,12 @@ describe('e2e_deploy_contract', () => {
const salt = Fr.random();
const portalAddress = EthAddress.random();
publicKey = Point.random();
const publicKeysHash = computePublicKeysHash(publicKey);

instance = getContractInstanceFromDeployParams(artifact, initArgs, salt, publicKey, portalAddress);
logger(
`Deploying contract instance at ${instance.address.toString()} with class id ${instance.contractClassId.toString()}`,
);
const tx = await deployer.methods
.deploy(salt, contractClass.id, instance.initializationHash, portalAddress, publicKeysHash, false)
.send()
.wait();
const { address, contractClassId } = instance;
logger(`Deploying contract instance at ${address.toString()} class id ${contractClassId.toString()}`);

const tx = await deployInstance(wallet, instance).send().wait();
deployTxHash = tx.txHash;
});

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/protocol-contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Protocol Contracts

Canonical Noir contracts used to power the Aztec Network protocol.
Noir contract artifacts used to power the Aztec Network protocol, along with their canonical deployment information.

Includes:
- Contract class registerer
Expand Down
Loading