Skip to content
Open
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
79 changes: 79 additions & 0 deletions docs/docs-developers/docs/resources/migration_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,85 @@ Aztec is in full-speed development. Literally every version breaks compatibility

## TBD

### [Aztec.js] Wallet batching now supports all methods

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.

```diff
- // Before: Only 5 methods could be batched
- const results = await wallet.batch([
- { name: "registerSender", args: [address, "alias"] },
- { name: "sendTx", args: [payload, options] },
- ]);
+ // After: All methods can be batched
+ const results = await wallet.batch([
+ { name: "getChainInfo", args: [] },
+ { name: "getContractMetadata", args: [contractAddress] },
+ { name: "registerSender", args: [address, "alias"] },
+ { name: "simulateTx", args: [payload, options] },
+ { name: "sendTx", args: [payload, options] },
+ ]);
```

### [Aztec.js] Refactored `getContractMetadata` and `getContractClassMetadata` in Wallet

The contract metadata methods in the `Wallet` interface have been refactored to provide more granular information and avoid expensive round-trips.

**`ContractMetadata`:**

```diff
{
- contractInstance?: ContractInstanceWithAddress,
+ instance?: ContractInstanceWithAddress; // Instance registered in the Wallet, if any
isContractInitialized: boolean; // Is the init nullifier onchain? (already there)
isContractPublished: boolean; // Has the contract been published? (already there)
+ isContractUpdated: boolean; // Has the contract been updated?
+ updatedContractClassId?: Fr; // If updated, the new class ID
}
```

**`ContractClassMetadata`:**

This method loses the ability to request the contract artifact via the `includeArtifact` flag

```diff
{
- contractClass?: ContractClassWithId;
- artifact?: ContractArtifact;
isContractClassPubliclyRegistered: boolean; // Is the class registered onchain?
+ isArtifactRegistered: boolean; // Does the Wallet know about this artifact?
}
```

- Removes expensive artifact/class transfers between wallet and app
- Separates PXE storage info (`instance`, `isArtifactRegistered`) from public chain info (`isContractPublished`, `isContractClassPubliclyRegistered`)
- Makes it easier to determine if actions like `registerContract` are needed

### [Aztec.js] Removed `UnsafeContract` and protocol contract helper functions

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.

**Migration:**

```diff
- import { getFeeJuice, getClassRegistryContract, getInstanceRegistryContract } from '@aztec/aztec.js/contracts';
+ import { FeeJuiceContract, ContractClassRegistryContract, ContractInstanceRegistryContract } from '@aztec/aztec.js/protocol';

- const feeJuice = await getFeeJuice(wallet);
+ const feeJuice = FeeJuiceContract.at(wallet);
await feeJuice.methods.check_balance(feeLimit).send().wait();

- const classRegistry = await getClassRegistryContract(wallet);
+ const classRegistry = ContractClassRegistryContract.at(wallet);
await classRegistry.methods.publish(...).send().wait();

- const instanceRegistry = await getInstanceRegistryContract(wallet);
+ const instanceRegistry = ContractInstanceRegistryContract.at(wallet);
await instanceRegistry.methods.publish_for_public_execution(...).send().wait();
```

**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.

### [Aztec.nr] Renamed Router contract

`Router` contract has been renamed as `PublicChecks` contract.
Expand Down
7 changes: 7 additions & 0 deletions yarn-project/aztec.js/src/api/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
export { ProtocolContractAddress } from '@aztec/protocol-contracts';
export { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';

export { AuthRegistryContract } from '../contract/protocol_contracts/auth-registry.js';
export { ContractClassRegistryContract } from '../contract/protocol_contracts/contract-class-registry.js';
export { ContractInstanceRegistryContract } from '../contract/protocol_contracts/contract-instance-registry.js';
export { FeeJuiceContract } from '../contract/protocol_contracts/fee-juice.js';
export { MultiCallEntrypointContract } from '../contract/protocol_contracts/multi-call-entrypoint.js';
export { PublicChecksContract } from '../contract/protocol_contracts/public-checks.js';
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/contract/batch_call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export class BatchCall extends BaseContractInteraction {
{ indexedExecutionPayloads: [], utility: [], publicIndex: 0, privateIndex: 0 },
);

const batchRequests: Array<BatchedMethod<'simulateUtility'> | BatchedMethod<'simulateTx'>> = [];
const batchRequests: BatchedMethod[] = [];

// Add utility calls to batch
for (const [call] of utility) {
batchRequests.push({
name: 'simulateUtility' as const,
args: [call, options?.authWitnesses] as const,
args: [call, options?.authWitnesses],
});
}

Expand Down
60 changes: 48 additions & 12 deletions yarn-project/aztec.js/src/wallet/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import type {
Aliased,
BatchResults,
BatchableMethods,
BatchedMethod,
ContractClassMetadata,
ContractMetadata,
Expand Down Expand Up @@ -235,6 +234,10 @@ describe('WalletSchema', () => {
const simulateOpts: SimulateOptions = {
from: await AztecAddress.random(),
};
const profileOpts: ProfileOptions = {
from: await AztecAddress.random(),
profileMode: 'gates',
};

const call = {
name: 'testFunction',
Expand Down Expand Up @@ -267,24 +270,57 @@ describe('WalletSchema', () => {
storageLayout: {},
};

const methods: BatchedMethod<keyof BatchableMethods>[] = [
const eventMetadata: EventMetadataDefinition = {
eventSelector: EventSelector.fromField(new Fr(1)),
abiType: { kind: 'field' },
fieldNames: ['field1'],
};

const methods: BatchedMethod[] = [
{ name: 'getChainInfo', args: [] },
{ name: 'getTxReceipt', args: [TxHash.random()] },
{ name: 'getContractMetadata', args: [address1] },
{ name: 'getContractClassMetadata', args: [Fr.random()] },
{
name: 'getPrivateEvents',
args: [eventMetadata, { contractAddress: address1, scopes: [address2], fromBlock: BlockNumber(1) }],
},
{ name: 'registerSender', args: [address1, 'alias1'] },
{ name: 'getAddressBook', args: [] },
{ name: 'getAccounts', args: [] },
{ name: 'registerContract', args: [mockInstance, mockArtifact, undefined] },
{ name: 'sendTx', args: [exec, opts] },
{ name: 'simulateUtility', args: [call, [AuthWitness.random()]] },
{ name: 'simulateTx', args: [exec, simulateOpts] },
{ name: 'simulateUtility', args: [call, [AuthWitness.random()]] },
{ name: 'profileTx', args: [exec, profileOpts] },
{ name: 'sendTx', args: [exec, opts] },
{ name: 'createAuthWit', args: [address1, Fr.random()] },
];

const results = await context.client.batch(methods);
expect(results).toHaveLength(5);
expect(results[0]).toEqual({ name: 'registerSender', result: expect.any(AztecAddress) });
expect(results[1]).toEqual({
expect(results).toHaveLength(14);
expect(results[0]).toEqual({ name: 'getChainInfo', result: { chainId: expect.any(Fr), version: expect.any(Fr) } });
expect(results[1]).toEqual({ name: 'getTxReceipt', result: expect.any(TxReceipt) });
expect(results[2]).toEqual({
name: 'getContractMetadata',
result: expect.objectContaining({ isContractInitialized: expect.any(Boolean) }),
});
expect(results[3]).toEqual({
name: 'getContractClassMetadata',
result: expect.objectContaining({ isArtifactRegistered: expect.any(Boolean) }),
});
expect(results[4]).toEqual({ name: 'getPrivateEvents', result: expect.any(Array) });
expect(results[5]).toEqual({ name: 'registerSender', result: expect.any(AztecAddress) });
expect(results[6]).toEqual({ name: 'getAddressBook', result: expect.any(Array) });
expect(results[7]).toEqual({ name: 'getAccounts', result: expect.any(Array) });
expect(results[8]).toEqual({
name: 'registerContract',
result: expect.objectContaining({ address: expect.any(AztecAddress) }),
});
expect(results[2]).toEqual({ name: 'sendTx', result: expect.any(TxHash) });
expect(results[3]).toEqual({ name: 'simulateUtility', result: expect.any(UtilitySimulationResult) });
expect(results[4]).toEqual({ name: 'simulateTx', result: expect.any(TxSimulationResult) });
expect(results[9]).toEqual({ name: 'simulateTx', result: expect.any(TxSimulationResult) });
expect(results[10]).toEqual({ name: 'simulateUtility', result: expect.any(UtilitySimulationResult) });
expect(results[11]).toEqual({ name: 'profileTx', result: expect.any(TxProfileResult) });
expect(results[12]).toEqual({ name: 'sendTx', result: expect.any(TxHash) });
expect(results[13]).toEqual({ name: 'createAuthWit', result: expect.any(AuthWitness) });
});
});

Expand Down Expand Up @@ -381,7 +417,7 @@ class MockWallet implements Wallet {
return Promise.resolve(AuthWitness.random());
}

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