This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmultitoken_contract.benchmark.ts
More file actions
134 lines (118 loc) · 5.06 KB
/
Copy pathmultitoken_contract.benchmark.ts
File metadata and controls
134 lines (118 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import type { Wallet } from '@aztec/aztec.js/wallet';
import { AztecAddress } from '@aztec/aztec.js/addresses';
import type { ContractFunctionInteractionCallIntent } from '@aztec/aztec.js/authorization';
// Import the new Benchmark base class and context
import { Benchmark, BenchmarkContext } from '@defi-wonderland/aztec-benchmark';
import { MultiTokenContract } from '../src/artifacts/MultiToken.js';
import {
deployMultiTokenWithMinter,
initializeMultiTokenTransferCommitment,
setupTestSuite,
ID_A,
} from '../src/ts/test/utils.js';
// Extend the BenchmarkContext from the new package
interface MultiTokenBenchmarkContext extends BenchmarkContext {
cleanup: () => Promise<void>;
wallet: Wallet;
deployer: AztecAddress;
accounts: AztecAddress[];
multiTokenContract: MultiTokenContract;
commitments: bigint[];
}
// --- Helper Functions ---
function amt(x: bigint | number) {
// MultiToken carries NO decimals (its constructor takes only name/symbol/minter/auth_contract, unlike the
// Token contract's `decimals` arg), so amounts are raw u128 values. We keep the sibling token benchmark's
// magnitudes (mint 100, move 10) without the 10**18 scaling that `parseUnits` would apply.
return BigInt(x);
}
// Use export default class extending Benchmark
export default class MultiTokenContractBenchmark extends Benchmark {
/**
* Sets up the benchmark environment for the MultiTokenContract.
* Creates wallet, gets accounts, and deploys the contract.
*/
async setup(): Promise<MultiTokenBenchmarkContext> {
const { cleanup, wallet, accounts } = await setupTestSuite(true);
const [deployer] = accounts;
// minter = deployer, auth_contract = ZERO (ARC-403 hook disabled) — mirrors the default JS suite deploy.
const multiTokenContract = await deployMultiTokenWithMinter(wallet, deployer, deployer, AztecAddress.ZERO);
// Pre-initialize the partial notes consumed by transfer_private_to_commitment / transfer_public_to_commitment.
// The commitment is id-agnostic (the completer binds the id at completion); the payer (alice) must be the
// completer, and the note must come from a PRIOR settled tx (the helper settles each one).
const [alice, bob] = accounts;
const commitment_1 = await initializeMultiTokenTransferCommitment(multiTokenContract, alice, bob, alice);
const commitment_2 = await initializeMultiTokenTransferCommitment(multiTokenContract, alice, bob, alice);
const commitments = [commitment_1, commitment_2];
return { cleanup, wallet, deployer, accounts, multiTokenContract, commitments };
}
/**
* Returns the list of MultiTokenContract methods to be benchmarked.
* Ordering matters: the mints seed the balances that the following transfers/burns/commitments spend.
* Every op is an `alice` self-spend of token id `ID_A` (nonce = 0, so no authwit is needed).
*/
getMethods(context: MultiTokenBenchmarkContext): ContractFunctionInteractionCallIntent[] {
const { multiTokenContract, accounts, wallet, commitments } = context;
const [alice, bob] = accounts;
const owner = alice;
const id = ID_A;
const methods: ContractFunctionInteractionCallIntent[] = [
// Mint methods
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.mint_to_private(owner, id, amt(100)),
},
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.mint_to_public(owner, id, amt(100)),
},
// Transfer methods
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.transfer_private_to_public(owner, bob, id, amt(10), 0),
},
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.transfer_private_to_private(owner, bob, id, amt(10), 0),
},
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.transfer_public_to_private(owner, bob, id, amt(10), 0),
},
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.transfer_public_to_public(owner, bob, id, amt(10), 0),
},
// Burn methods
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.burn_private(owner, id, amt(10), 0),
},
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.burn_public(owner, id, amt(10), 0),
},
// Partial notes methods
{
caller: alice,
action: multiTokenContract.withWallet(wallet).methods.initialize_transfer_commitment(bob, owner),
},
{
caller: alice,
action: multiTokenContract
.withWallet(wallet)
.methods.transfer_private_to_commitment(owner, id, commitments[0], amt(10), 0),
},
{
caller: alice,
action: multiTokenContract
.withWallet(wallet)
.methods.transfer_public_to_commitment(owner, id, commitments[1], amt(10), 0),
},
];
return methods.filter(Boolean);
}
async teardown(context: MultiTokenBenchmarkContext): Promise<void> {
await context.cleanup();
}
}