diff --git a/yarn-project/aztec.js/src/api/deployment.ts b/yarn-project/aztec.js/src/api/deployment.ts index f0dd21091cb..e6e2ad24521 100644 --- a/yarn-project/aztec.js/src/api/deployment.ts +++ b/yarn-project/aztec.js/src/api/deployment.ts @@ -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'; diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts new file mode 100644 index 00000000000..21f49fe07c9 --- /dev/null +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -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, + ); +} diff --git a/yarn-project/aztec.js/src/deployment/protocol_contracts.ts b/yarn-project/aztec.js/src/deployment/protocol_contracts.ts index b14c64509f5..c7d59c59d63 100644 --- a/yarn-project/aztec.js/src/deployment/protocol_contracts.ts +++ b/yarn-project/aztec.js/src/deployment/protocol_contracts.ts @@ -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'; @@ -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); +} diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index e493dece908..6dfc3d9e208 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -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'; @@ -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; }); diff --git a/yarn-project/protocol-contracts/README.md b/yarn-project/protocol-contracts/README.md index 7a863ea8a26..a8d9392ed5d 100644 --- a/yarn-project/protocol-contracts/README.md +++ b/yarn-project/protocol-contracts/README.md @@ -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