Skip to content

Commit 151fbfa

Browse files
authored
feat: merge-train/fairies (#20684)
BEGIN_COMMIT_OVERRIDE refactor: auto-inject contract address into scopes for account deploys (#20665) END_COMMIT_OVERRIDE
2 parents 27c0146 + 93b507c commit 151fbfa

File tree

11 files changed

+67
-40
lines changed

11 files changed

+67
-40
lines changed

yarn-project/aztec.js/src/contract/deploy_method.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
1414

1515
import { publishContractClass } from '../deployment/publish_class.js';
1616
import { publishInstance } from '../deployment/publish_instance.js';
17-
import type { SendOptions, Wallet } from '../wallet/wallet.js';
17+
import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from '../wallet/wallet.js';
1818
import { BaseContractInteraction } from './base_contract_interaction.js';
1919
import type { ContractBase } from './contract_base.js';
2020
import { ContractFunctionInteraction } from './contract_function_interaction.js';
@@ -207,7 +207,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
207207
* @param options - Deploy options with wait parameter
208208
* @returns Send options with wait parameter
209209
*/
210-
private convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
210+
protected convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
211211
options: DeployOptions<W>,
212212
// eslint-disable-next-line jsdoc/require-jsdoc
213213
): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
@@ -219,6 +219,24 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
219219
} as any;
220220
}
221221

222+
/**
223+
* Converts deploy simulation options into wallet-level simulate options.
224+
* @param options - The deploy simulation options to convert.
225+
*/
226+
protected convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
227+
return toSimulateOptions(options);
228+
}
229+
230+
/**
231+
* Converts deploy profile options into wallet-level profile options.
232+
* @param options - The deploy profile options to convert.
233+
*/
234+
protected convertDeployOptionsToProfileOptions(
235+
options: DeployOptionsWithoutWait & ProfileInteractionOptions,
236+
): ProfileOptions {
237+
return toProfileOptions(options);
238+
}
239+
222240
/**
223241
* Adds this contract to the wallet and returns the Contract object.
224242
* @param options - Deployment options.
@@ -368,7 +386,10 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
368386
*/
369387
public async simulate(options: SimulateDeployOptions): Promise<SimulationReturn<true>> {
370388
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
371-
const simulatedTx = await this.wallet.simulateTx(executionPayload, toSimulateOptions(options));
389+
const simulatedTx = await this.wallet.simulateTx(
390+
executionPayload,
391+
this.convertDeployOptionsToSimulateOptions(options),
392+
);
372393

373394
const { gasLimits, teardownGasLimits } = getGasLimits(simulatedTx, options.fee?.estimatedGasPadding);
374395
this.log.verbose(
@@ -390,11 +411,7 @@ export class DeployMethod<TContract extends ContractBase = ContractBase> extends
390411
*/
391412
public async profile(options: DeployOptionsWithoutWait & ProfileInteractionOptions): Promise<TxProfileResult> {
392413
const executionPayload = await this.request(this.convertDeployOptionsToRequestOptions(options));
393-
return await this.wallet.profileTx(executionPayload, {
394-
...toProfileOptions(options),
395-
profileMode: options.profileMode,
396-
skipProofGeneration: options.skipProofGeneration,
397-
});
414+
return await this.wallet.profileTx(executionPayload, this.convertDeployOptionsToProfileOptions(options));
398415
}
399416

400417
/** Return this deployment address. */

yarn-project/aztec.js/src/wallet/deploy_account_method.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@ import type { Account } from '../account/account.js';
99
import type { Contract } from '../contract/contract.js';
1010
import type { ContractBase } from '../contract/contract_base.js';
1111
import {
12+
type DeployInteractionWaitOptions,
1213
DeployMethod,
14+
type DeployOptions,
1315
type DeployOptionsWithoutWait,
1416
type RequestDeployOptions,
1517
type SimulateDeployOptions,
1618
} from '../contract/deploy_method.js';
17-
import type { FeePaymentMethodOption, InteractionWaitOptions } from '../contract/interaction_options.js';
19+
import type {
20+
FeePaymentMethodOption,
21+
InteractionWaitOptions,
22+
ProfileInteractionOptions,
23+
} from '../contract/interaction_options.js';
24+
import type { WaitOpts } from '../contract/wait_opts.js';
1825
import type { FeePaymentMethod } from '../fee/fee_payment_method.js';
1926
import { AccountEntrypointMetaPaymentMethod } from './account_entrypoint_meta_payment_method.js';
20-
import type { Wallet } from './index.js';
27+
import type { ProfileOptions, SendOptions, SimulateOptions, Wallet } from './index.js';
2128

2229
/**
2330
* Extended fee payment method option for account deployments that includes entrypoint wrapping options
@@ -147,4 +154,34 @@ export class DeployAccountMethod<TContract extends ContractBase = Contract> exte
147154
deployer: options.from,
148155
};
149156
}
157+
158+
protected override convertDeployOptionsToSendOptions<W extends DeployInteractionWaitOptions>(
159+
options: DeployOptions<W>,
160+
// eslint-disable-next-line jsdoc/require-jsdoc
161+
): SendOptions<W extends { returnReceipt: true } ? WaitOpts : W> {
162+
return super.convertDeployOptionsToSendOptions(this.injectContractAddressIntoScopes(options));
163+
}
164+
165+
protected override convertDeployOptionsToSimulateOptions(options: SimulateDeployOptions): SimulateOptions {
166+
return super.convertDeployOptionsToSimulateOptions(this.injectContractAddressIntoScopes(options));
167+
}
168+
169+
protected override convertDeployOptionsToProfileOptions(
170+
options: DeployOptionsWithoutWait & ProfileInteractionOptions,
171+
): ProfileOptions {
172+
return super.convertDeployOptionsToProfileOptions(this.injectContractAddressIntoScopes(options));
173+
}
174+
175+
/**
176+
* Injects the contract's own address into scopes so the constructor can access its own keys.
177+
* @param options - The deploy options to augment with the contract address.
178+
*/
179+
// eslint-disable-next-line jsdoc/require-jsdoc
180+
private injectContractAddressIntoScopes<T extends { additionalScopes?: AztecAddress[] }>(options: T): T {
181+
if (!this.address) {
182+
throw new Error('Instance not yet constructed. This is a bug!');
183+
}
184+
const existing = options.additionalScopes ?? [];
185+
return { ...options, additionalScopes: [...existing, this.address] };
186+
}
150187
}

yarn-project/cli-wallet/src/cmds/create_account.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ export async function createAccount(
7979
skipInstancePublication: !publicDeploy,
8080
skipInitialization,
8181
from,
82-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
83-
additionalScopes: [address],
8482
fee: { paymentMethod, gasSettings },
8583
};
8684

yarn-project/end-to-end/src/composed/docs_examples.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ describe('docs_examples', () => {
3232
const newAccountDeployMethod = await newAccountManager.getDeployMethod();
3333
await newAccountDeployMethod.send({
3434
from: prefundedAccount.address,
35-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
36-
additionalScopes: [newAccountManager.address],
3735
});
3836
const newAccountAddress = newAccountManager.address;
3937
const defaultAccountAddress = prefundedAccount.address;

yarn-project/end-to-end/src/composed/e2e_local_network_example.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ describe('e2e_local_network_example', () => {
145145
return await Promise.all(
146146
accountManagers.map(async x => {
147147
const deployMethod = await x.getDeployMethod();
148-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
149-
await deployMethod.send({ from: fundedAccount, additionalScopes: [x.address] });
148+
await deployMethod.send({ from: fundedAccount });
150149
return x;
151150
}),
152151
);

yarn-project/end-to-end/src/e2e_fees/account_init.test.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ describe('e2e_fees account_init', () => {
9191

9292
const tx = await bobsDeployMethod.send({
9393
from: AztecAddress.ZERO,
94-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
95-
additionalScopes: [bobsAddress],
9694
wait: { returnReceipt: true },
9795
});
9896

@@ -105,8 +103,6 @@ describe('e2e_fees account_init', () => {
105103
const paymentMethod = new FeeJuicePaymentMethodWithClaim(bobsAddress, claim);
106104
const tx = await bobsDeployMethod.send({
107105
from: AztecAddress.ZERO,
108-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
109-
additionalScopes: [bobsAddress],
110106
fee: { paymentMethod },
111107
wait: { returnReceipt: true },
112108
});
@@ -127,8 +123,6 @@ describe('e2e_fees account_init', () => {
127123
const paymentMethod = new PrivateFeePaymentMethod(bananaFPC.address, bobsAddress, wallet, gasSettings);
128124
const tx = await bobsDeployMethod.send({
129125
from: AztecAddress.ZERO,
130-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
131-
additionalScopes: [bobsAddress],
132126
fee: { paymentMethod },
133127
wait: { returnReceipt: true },
134128
});
@@ -158,8 +152,6 @@ describe('e2e_fees account_init', () => {
158152
const paymentMethod = new PublicFeePaymentMethod(bananaFPC.address, bobsAddress, wallet, gasSettings);
159153
const tx = await bobsDeployMethod.send({
160154
from: AztecAddress.ZERO,
161-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
162-
additionalScopes: [bobsAddress],
163155
skipInstancePublication: false,
164156
fee: { paymentMethod },
165157
wait: { returnReceipt: true },

yarn-project/end-to-end/src/e2e_fees/fee_juice_payments.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ describe('e2e_fees Fee Juice payments', () => {
3434
// Alice pays for Bob's account contract deployment.
3535
const bobsDeployMethod = await bobsAccountManager.getDeployMethod();
3636
bobAddress = bobsAccountManager.address;
37-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
38-
await bobsDeployMethod.send({ from: aliceAddress, additionalScopes: [bobAddress] });
37+
await bobsDeployMethod.send({ from: aliceAddress });
3938
});
4039

4140
afterAll(async () => {

yarn-project/end-to-end/src/fixtures/setup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,6 @@ export const deployAccounts =
841841
const deployMethod = await accountManager.getDeployMethod();
842842
await deployMethod.send({
843843
from: AztecAddress.ZERO,
844-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
845-
additionalScopes: [accountManager.address],
846844
skipClassPublication: i !== 0, // Publish the contract class at most once.
847845
});
848846
}

yarn-project/end-to-end/src/shared/submit-transactions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export const submitTxsTo = async (
2121
const deployMethod = await accountManager.getDeployMethod();
2222
const txHash = await deployMethod.send({
2323
from: submitter,
24-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
25-
additionalScopes: [accountManager.address],
2624
wait: NO_WAIT,
2725
});
2826

yarn-project/end-to-end/src/spartan/setup_test_wallets.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ export async function deploySponsoredTestAccountsWithTokens(
9090
const recipientDeployMethod = await recipientAccount.getDeployMethod();
9191
await recipientDeployMethod.send({
9292
from: AztecAddress.ZERO,
93-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
94-
additionalScopes: [recipientAccount.address],
9593
fee: { paymentMethod },
9694
wait: { timeout: 2400 },
9795
});
@@ -100,8 +98,6 @@ export async function deploySponsoredTestAccountsWithTokens(
10098
const deployMethod = await a.getDeployMethod();
10199
await deployMethod.send({
102100
from: AztecAddress.ZERO,
103-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
104-
additionalScopes: [a.address],
105101
fee: { paymentMethod },
106102
wait: { timeout: 2400 },
107103
}); // increase timeout on purpose in order to account for two empty epochs
@@ -144,8 +140,6 @@ async function deployAccountWithDiagnostics(
144140
try {
145141
txHash = await deployMethod.send({
146142
from: AztecAddress.ZERO,
147-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
148-
additionalScopes: [account.address],
149143
fee: { paymentMethod },
150144
wait: NO_WAIT,
151145
});
@@ -240,8 +234,7 @@ export async function deployTestAccountsWithTokens(
240234
fundedAccounts.map(async (a, i) => {
241235
const paymentMethod = new FeeJuicePaymentMethodWithClaim(a.address, claims[i]);
242236
const deployMethod = await a.getDeployMethod();
243-
// The account constructor initializes storage vars that need the contract's own nullifier key, so we need to add it to scopes.
244-
await deployMethod.send({ from: AztecAddress.ZERO, additionalScopes: [a.address], fee: { paymentMethod } });
237+
await deployMethod.send({ from: AztecAddress.ZERO, fee: { paymentMethod } });
245238
logger.info(`Account deployed at ${a.address}`);
246239
}),
247240
);

0 commit comments

Comments
 (0)