Skip to content

Commit

Permalink
feat: Nicer API for instance deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Feb 7, 2024
1 parent 2fccdf2 commit ba6a2d3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
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,
);
}
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

0 comments on commit ba6a2d3

Please sign in to comment.