Skip to content

Commit aa3d3bd

Browse files
committed
feat: wallet full batchability
Allows ALL methods in the wallet to be batched (because why not). Initially I was going for allowing them on a case-by-case basis, but integrating the Wallet SDK has made apparent apps can have many interaction flows and this extra flexibility is nice. Updated the migration notes and in the process realized I missed exporting some artifacts in #19457, so here they are (protocol contract wrappers) Co-authored-by: thunkar <[email protected]>
1 parent e4fca7a commit aa3d3bd

File tree

6 files changed

+202
-71
lines changed

6 files changed

+202
-71
lines changed

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,85 @@ Aztec is in full-speed development. Literally every version breaks compatibility
99

1010
## TBD
1111

12+
### [Aztec.js] Wallet batching now supports all methods
13+
14+
The `BatchedMethod` type is now a discriminated union that ensures type safety: the `args` must match the specific method `name`. This prevents runtime errors from mismatched arguments.
15+
16+
```diff
17+
- // Before: Only 5 methods could be batched
18+
- const results = await wallet.batch([
19+
- { name: "registerSender", args: [address, "alias"] },
20+
- { name: "sendTx", args: [payload, options] },
21+
- ]);
22+
+ // After: All methods can be batched
23+
+ const results = await wallet.batch([
24+
+ { name: "getChainInfo", args: [] },
25+
+ { name: "getContractMetadata", args: [contractAddress] },
26+
+ { name: "registerSender", args: [address, "alias"] },
27+
+ { name: "simulateTx", args: [payload, options] },
28+
+ { name: "sendTx", args: [payload, options] },
29+
+ ]);
30+
```
31+
32+
### [Aztec.js] Refactored `getContractMetadata` and `getContractClassMetadata` in Wallet
33+
34+
The contract metadata methods in the `Wallet` interface have been refactored to provide more granular information and avoid expensive round-trips.
35+
36+
**`ContractMetadata`:**
37+
38+
```diff
39+
{
40+
- contractInstance?: ContractInstanceWithAddress,
41+
+ instance?: ContractInstanceWithAddress; // Instance registered in the Wallet, if any
42+
isContractInitialized: boolean; // Is the init nullifier onchain? (already there)
43+
isContractPublished: boolean; // Has the contract been published? (already there)
44+
+ isContractUpdated: boolean; // Has the contract been updated?
45+
+ updatedContractClassId?: Fr; // If updated, the new class ID
46+
}
47+
```
48+
49+
**`ContractClassMetadata`:**
50+
51+
This method loses the ability to request the contract artifact via the `includeArtifact` flag
52+
53+
```diff
54+
{
55+
- contractClass?: ContractClassWithId;
56+
- artifact?: ContractArtifact;
57+
isContractClassPubliclyRegistered: boolean; // Is the class registered onchain?
58+
+ isArtifactRegistered: boolean; // Does the Wallet know about this artifact?
59+
}
60+
```
61+
62+
- Removes expensive artifact/class transfers between wallet and app
63+
- Separates PXE storage info (`instance`, `isArtifactRegistered`) from public chain info (`isContractPublished`, `isContractClassPubliclyRegistered`)
64+
- Makes it easier to determine if actions like `registerContract` are needed
65+
66+
### [Aztec.js] Removed `UnsafeContract` and protocol contract helper functions
67+
68+
The `UnsafeContract` class and async helper functions (`getFeeJuice`, `getClassRegistryContract`, `getInstanceRegistryContract`) have been removed. Protocol contracts are now accessed via auto-generated type-safe wrappers with only the ABI (no bytecode). Since PXE always has protocol contract artifacts available, importing and using these contracts from `aztec.js` is very lightweight and follows the same pattern as regular user contracts.
69+
70+
**Migration:**
71+
72+
```diff
73+
- import { getFeeJuice, getClassRegistryContract, getInstanceRegistryContract } from '@aztec/aztec.js/contracts';
74+
+ import { FeeJuiceContract, ContractClassRegistryContract, ContractInstanceRegistryContract } from '@aztec/aztec.js/protocol';
75+
76+
- const feeJuice = await getFeeJuice(wallet);
77+
+ const feeJuice = FeeJuiceContract.at(wallet);
78+
await feeJuice.methods.check_balance(feeLimit).send().wait();
79+
80+
- const classRegistry = await getClassRegistryContract(wallet);
81+
+ const classRegistry = ContractClassRegistryContract.at(wallet);
82+
await classRegistry.methods.publish(...).send().wait();
83+
84+
- const instanceRegistry = await getInstanceRegistryContract(wallet);
85+
+ const instanceRegistry = ContractInstanceRegistryContract.at(wallet);
86+
await instanceRegistry.methods.publish_for_public_execution(...).send().wait();
87+
```
88+
89+
**Note:** The higher-level utilities like `publishInstance`, `publishContractClass`, and `broadcastPrivateFunction` from `@aztec/aztec.js/deployment` are still available and unchanged. These utilities use the new wrappers internally.
90+
1291
### [Aztec.nr] Renamed Router contract
1392

1493
`Router` contract has been renamed as `PublicChecks` contract.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
export { ProtocolContractAddress } from '@aztec/protocol-contracts';
22
export { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
3+
4+
export { AuthRegistryContract } from '../contract/protocol_contracts/auth-registry.js';
5+
export { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
6+
export { ContractInstanceRegistryContract } from '../contract/protocol_contracts/contract-instance-registry.js';
7+
export { FeeJuiceContract } from '../contract/protocol_contracts/fee-juice.js';
8+
export { MultiCallEntrypointContract } from '../contract/protocol_contracts/multi-call-entrypoint.js';
9+
export { PublicChecksContract } from '../contract/protocol_contracts/public-checks.js';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ export class BatchCall extends BaseContractInteraction {
7676
{ indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
7777
);
7878

79-
const batchRequests: Array<BatchedMethod<'simulateUtility'> | BatchedMethod<'simulateTx'>> = [];
79+
const batchRequests: BatchedMethod[] = [];
8080

8181
// Add utility calls to batch
8282
for (const [call] of utility) {
8383
batchRequests.push({
8484
name: 'simulateUtility' as const,
85-
args: [call, options?.authWitnesses] as const,
85+
args: [call, options?.authWitnesses],
8686
});
8787
}
8888

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

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import type {
2222
Aliased,
2323
BatchResults,
24-
BatchableMethods,
2524
BatchedMethod,
2625
ContractClassMetadata,
2726
ContractMetadata,
@@ -235,6 +234,10 @@ describe('WalletSchema', () => {
235234
const simulateOpts: SimulateOptions = {
236235
from: await AztecAddress.random(),
237236
};
237+
const profileOpts: ProfileOptions = {
238+
from: await AztecAddress.random(),
239+
profileMode: 'gates',
240+
};
238241

239242
const call = {
240243
name: 'testFunction',
@@ -267,24 +270,57 @@ describe('WalletSchema', () => {
267270
storageLayout: {},
268271
};
269272

270-
const methods: BatchedMethod<keyof BatchableMethods>[] = [
273+
const eventMetadata: EventMetadataDefinition = {
274+
eventSelector: EventSelector.fromField(new Fr(1)),
275+
abiType: { kind: 'field' },
276+
fieldNames: ['field1'],
277+
};
278+
279+
const methods: BatchedMethod[] = [
280+
{ name: 'getChainInfo', args: [] },
281+
{ name: 'getTxReceipt', args: [TxHash.random()] },
282+
{ name: 'getContractMetadata', args: [address1] },
283+
{ name: 'getContractClassMetadata', args: [Fr.random()] },
284+
{
285+
name: 'getPrivateEvents',
286+
args: [eventMetadata, { contractAddress: address1, scopes: [address2], fromBlock: BlockNumber(1) }],
287+
},
271288
{ name: 'registerSender', args: [address1, 'alias1'] },
289+
{ name: 'getAddressBook', args: [] },
290+
{ name: 'getAccounts', args: [] },
272291
{ name: 'registerContract', args: [mockInstance, mockArtifact, undefined] },
273-
{ name: 'sendTx', args: [exec, opts] },
274-
{ name: 'simulateUtility', args: [call, [AuthWitness.random()]] },
275292
{ name: 'simulateTx', args: [exec, simulateOpts] },
293+
{ name: 'simulateUtility', args: [call, [AuthWitness.random()]] },
294+
{ name: 'profileTx', args: [exec, profileOpts] },
295+
{ name: 'sendTx', args: [exec, opts] },
296+
{ name: 'createAuthWit', args: [address1, Fr.random()] },
276297
];
277298

278299
const results = await context.client.batch(methods);
279-
expect(results).toHaveLength(5);
280-
expect(results[0]).toEqual({ name: 'registerSender', result: expect.any(AztecAddress) });
281-
expect(results[1]).toEqual({
300+
expect(results).toHaveLength(14);
301+
expect(results[0]).toEqual({ name: 'getChainInfo', result: { chainId: expect.any(Fr), version: expect.any(Fr) } });
302+
expect(results[1]).toEqual({ name: 'getTxReceipt', result: expect.any(TxReceipt) });
303+
expect(results[2]).toEqual({
304+
name: 'getContractMetadata',
305+
result: expect.objectContaining({ isContractInitialized: expect.any(Boolean) }),
306+
});
307+
expect(results[3]).toEqual({
308+
name: 'getContractClassMetadata',
309+
result: expect.objectContaining({ isArtifactRegistered: expect.any(Boolean) }),
310+
});
311+
expect(results[4]).toEqual({ name: 'getPrivateEvents', result: expect.any(Array) });
312+
expect(results[5]).toEqual({ name: 'registerSender', result: expect.any(AztecAddress) });
313+
expect(results[6]).toEqual({ name: 'getAddressBook', result: expect.any(Array) });
314+
expect(results[7]).toEqual({ name: 'getAccounts', result: expect.any(Array) });
315+
expect(results[8]).toEqual({
282316
name: 'registerContract',
283317
result: expect.objectContaining({ address: expect.any(AztecAddress) }),
284318
});
285-
expect(results[2]).toEqual({ name: 'sendTx', result: expect.any(TxHash) });
286-
expect(results[3]).toEqual({ name: 'simulateUtility', result: expect.any(UtilitySimulationResult) });
287-
expect(results[4]).toEqual({ name: 'simulateTx', result: expect.any(TxSimulationResult) });
319+
expect(results[9]).toEqual({ name: 'simulateTx', result: expect.any(TxSimulationResult) });
320+
expect(results[10]).toEqual({ name: 'simulateUtility', result: expect.any(UtilitySimulationResult) });
321+
expect(results[11]).toEqual({ name: 'profileTx', result: expect.any(TxProfileResult) });
322+
expect(results[12]).toEqual({ name: 'sendTx', result: expect.any(TxHash) });
323+
expect(results[13]).toEqual({ name: 'createAuthWit', result: expect.any(AuthWitness) });
288324
});
289325
});
290326

@@ -381,7 +417,7 @@ class MockWallet implements Wallet {
381417
return Promise.resolve(AuthWitness.random());
382418
}
383419

384-
async batch<const T extends readonly BatchedMethod<keyof BatchableMethods>[]>(methods: T): Promise<BatchResults<T>> {
420+
async batch<const T extends readonly BatchedMethod[]>(methods: T): Promise<BatchResults<T>> {
385421
const results: any[] = [];
386422
for (const method of methods) {
387423
const { name, args } = method;
@@ -390,7 +426,7 @@ class MockWallet implements Wallet {
390426
// 2. `args` matches the parameter types of that specific method
391427
// 3. The return type is correctly mapped in BatchResults<T>
392428
// We use dynamic dispatch here for simplicity, but the types are enforced at the call site.
393-
const fn = this[name] as (...args: any[]) => Promise<any>;
429+
const fn = (this as any)[name] as (...args: any[]) => Promise<any>;
394430
const result = await fn.apply(this, args);
395431
// Wrap result with method name for discriminated union deserialization
396432
results.push({ name, result });

0 commit comments

Comments
 (0)