@aztec/aztec 0.0.1-commit.b655e406 → 0.0.1-commit.b9865e97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +1 -1
  2. package/dest/bin/index.d.ts +1 -1
  3. package/dest/bin/index.js +13 -6
  4. package/dest/cli/admin_api_key_store.d.ts +45 -0
  5. package/dest/cli/admin_api_key_store.d.ts.map +1 -0
  6. package/dest/cli/admin_api_key_store.js +98 -0
  7. package/dest/cli/aztec_start_action.d.ts +1 -1
  8. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  9. package/dest/cli/aztec_start_action.js +90 -31
  10. package/dest/cli/aztec_start_options.d.ts +2 -2
  11. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  12. package/dest/cli/aztec_start_options.js +60 -53
  13. package/dest/cli/cli.d.ts +1 -1
  14. package/dest/cli/cli.js +7 -7
  15. package/dest/cli/cmds/compile.d.ts +4 -0
  16. package/dest/cli/cmds/compile.d.ts.map +1 -0
  17. package/dest/cli/cmds/compile.js +166 -0
  18. package/dest/cli/cmds/migrate_ha_db.d.ts +3 -0
  19. package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
  20. package/dest/cli/cmds/migrate_ha_db.js +27 -0
  21. package/dest/cli/cmds/profile.d.ts +4 -0
  22. package/dest/cli/cmds/profile.d.ts.map +1 -0
  23. package/dest/cli/cmds/profile.js +8 -0
  24. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  25. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  26. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  27. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  28. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  29. package/dest/cli/cmds/profile_gates.js +76 -0
  30. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  31. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  32. package/dest/cli/cmds/profile_utils.js +50 -0
  33. package/dest/cli/cmds/standby.d.ts +30 -0
  34. package/dest/cli/cmds/standby.d.ts.map +1 -0
  35. package/dest/cli/cmds/standby.js +97 -0
  36. package/dest/cli/cmds/start_bot.d.ts +3 -3
  37. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  38. package/dest/cli/cmds/start_bot.js +13 -9
  39. package/dest/cli/cmds/start_node.d.ts +3 -2
  40. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  41. package/dest/cli/cmds/start_node.js +79 -39
  42. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +2 -2
  43. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
  44. package/dest/cli/cmds/start_p2p_bootstrap.js +2 -3
  45. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  46. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  47. package/dest/cli/cmds/start_prover_agent.js +8 -20
  48. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  49. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  50. package/dest/cli/cmds/start_prover_broker.js +25 -16
  51. package/dest/cli/cmds/start_txe.d.ts +2 -2
  52. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  53. package/dest/cli/cmds/start_txe.js +6 -5
  54. package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
  55. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  56. package/dest/cli/cmds/utils/artifacts.js +24 -0
  57. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  58. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  59. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  60. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  61. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  62. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  63. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  64. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  65. package/dest/cli/cmds/utils/spawn.js +16 -0
  66. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  67. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  68. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  69. package/dest/cli/index.d.ts +1 -1
  70. package/dest/cli/preload_crs.d.ts +1 -1
  71. package/dest/cli/util.d.ts +12 -23
  72. package/dest/cli/util.d.ts.map +1 -1
  73. package/dest/cli/util.js +57 -91
  74. package/dest/cli/versioning.d.ts +1 -1
  75. package/dest/examples/token.d.ts +1 -1
  76. package/dest/examples/token.js +10 -10
  77. package/dest/examples/util.d.ts +2 -2
  78. package/dest/examples/util.d.ts.map +1 -1
  79. package/dest/index.d.ts +2 -2
  80. package/dest/index.d.ts.map +1 -1
  81. package/dest/index.js +1 -1
  82. package/dest/local-network/auth_registry.d.ts +5 -0
  83. package/dest/local-network/auth_registry.d.ts.map +1 -0
  84. package/dest/local-network/auth_registry.js +17 -0
  85. package/dest/local-network/banana_fpc.d.ts +11 -0
  86. package/dest/local-network/banana_fpc.d.ts.map +1 -0
  87. package/dest/{sandbox → local-network}/banana_fpc.js +14 -10
  88. package/dest/local-network/index.d.ts +4 -0
  89. package/dest/local-network/index.d.ts.map +1 -0
  90. package/dest/{sandbox → local-network}/index.js +1 -1
  91. package/dest/local-network/local-network.d.ts +50 -0
  92. package/dest/local-network/local-network.d.ts.map +1 -0
  93. package/dest/local-network/local-network.js +248 -0
  94. package/dest/local-network/sponsored_fpc.d.ts +5 -0
  95. package/dest/local-network/sponsored_fpc.d.ts.map +1 -0
  96. package/dest/mnemonic.d.ts +1 -1
  97. package/dest/splash.d.ts +1 -1
  98. package/dest/testing/anvil_test_watcher.d.ts +26 -6
  99. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  100. package/dest/testing/anvil_test_watcher.js +128 -35
  101. package/dest/testing/cheat_codes.d.ts +18 -17
  102. package/dest/testing/cheat_codes.d.ts.map +1 -1
  103. package/dest/testing/cheat_codes.js +72 -36
  104. package/dest/testing/epoch_test_settler.d.ts +19 -0
  105. package/dest/testing/epoch_test_settler.d.ts.map +1 -0
  106. package/dest/testing/epoch_test_settler.js +63 -0
  107. package/dest/testing/index.d.ts +4 -2
  108. package/dest/testing/index.d.ts.map +1 -1
  109. package/dest/testing/index.js +2 -0
  110. package/dest/testing/token_allowed_setup.d.ts +7 -0
  111. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  112. package/dest/testing/token_allowed_setup.js +20 -0
  113. package/package.json +42 -37
  114. package/scripts/add_crate.sh +53 -0
  115. package/scripts/aztec.sh +73 -0
  116. package/scripts/init.sh +39 -0
  117. package/scripts/new.sh +83 -0
  118. package/scripts/setup_workspace.sh +69 -0
  119. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  120. package/scripts/templates/blank/contract/src/main.nr +10 -0
  121. package/scripts/templates/blank/test/Nargo.toml +7 -0
  122. package/scripts/templates/blank/test/src/lib.nr +11 -0
  123. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  124. package/scripts/templates/counter/contract/src/main.nr +48 -0
  125. package/scripts/templates/counter/test/Nargo.toml +7 -0
  126. package/scripts/templates/counter/test/src/lib.nr +32 -0
  127. package/src/bin/index.ts +14 -6
  128. package/src/cli/admin_api_key_store.ts +128 -0
  129. package/src/cli/aztec_start_action.ts +83 -26
  130. package/src/cli/aztec_start_options.ts +68 -59
  131. package/src/cli/cli.ts +11 -11
  132. package/src/cli/cmds/compile.ts +192 -0
  133. package/src/cli/cmds/migrate_ha_db.ts +43 -0
  134. package/src/cli/cmds/profile.ts +26 -0
  135. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  136. package/src/cli/cmds/profile_gates.ts +84 -0
  137. package/src/cli/cmds/profile_utils.ts +58 -0
  138. package/src/cli/cmds/standby.ts +132 -0
  139. package/src/cli/cmds/start_bot.ts +12 -11
  140. package/src/cli/cmds/start_node.ts +90 -44
  141. package/src/cli/cmds/start_p2p_bootstrap.ts +3 -3
  142. package/src/cli/cmds/start_prover_agent.ts +9 -20
  143. package/src/cli/cmds/start_prover_broker.ts +29 -26
  144. package/src/cli/cmds/start_txe.ts +7 -5
  145. package/src/cli/cmds/utils/artifacts.ts +44 -0
  146. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  147. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  148. package/src/cli/cmds/utils/spawn.ts +16 -0
  149. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  150. package/src/cli/util.ts +66 -104
  151. package/src/examples/token.ts +11 -11
  152. package/src/examples/util.ts +1 -1
  153. package/src/index.ts +2 -2
  154. package/src/local-network/auth_registry.ts +19 -0
  155. package/src/{sandbox → local-network}/banana_fpc.ts +17 -9
  156. package/src/{sandbox → local-network}/index.ts +1 -1
  157. package/src/local-network/local-network.ts +303 -0
  158. package/src/{sandbox → local-network}/sponsored_fpc.ts +3 -2
  159. package/src/testing/anvil_test_watcher.ts +142 -33
  160. package/src/testing/cheat_codes.ts +92 -38
  161. package/src/testing/epoch_test_settler.ts +69 -0
  162. package/src/testing/index.ts +3 -1
  163. package/src/testing/token_allowed_setup.ts +19 -0
  164. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  165. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  166. package/dest/cli/cmds/start_archiver.js +0 -50
  167. package/dest/cli/cmds/start_blob_sink.d.ts +0 -3
  168. package/dest/cli/cmds/start_blob_sink.d.ts.map +0 -1
  169. package/dest/cli/cmds/start_blob_sink.js +0 -33
  170. package/dest/cli/cmds/start_prover_node.d.ts +0 -7
  171. package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
  172. package/dest/cli/cmds/start_prover_node.js +0 -108
  173. package/dest/cli/release_version.d.ts +0 -2
  174. package/dest/cli/release_version.d.ts.map +0 -1
  175. package/dest/cli/release_version.js +0 -14
  176. package/dest/sandbox/banana_fpc.d.ts +0 -10
  177. package/dest/sandbox/banana_fpc.d.ts.map +0 -1
  178. package/dest/sandbox/index.d.ts +0 -4
  179. package/dest/sandbox/index.d.ts.map +0 -1
  180. package/dest/sandbox/sandbox.d.ts +0 -74
  181. package/dest/sandbox/sandbox.d.ts.map +0 -1
  182. package/dest/sandbox/sandbox.js +0 -183
  183. package/dest/sandbox/sponsored_fpc.d.ts +0 -4
  184. package/dest/sandbox/sponsored_fpc.d.ts.map +0 -1
  185. package/src/cli/cmds/start_archiver.ts +0 -61
  186. package/src/cli/cmds/start_blob_sink.ts +0 -57
  187. package/src/cli/cmds/start_prover_node.ts +0 -124
  188. package/src/cli/release_version.ts +0 -21
  189. package/src/sandbox/sandbox.ts +0 -242
  190. /package/dest/{sandbox → local-network}/sponsored_fpc.js +0 -0
@@ -1,4 +1,5 @@
1
1
  import { RollupCheatCodes } from '@aztec/ethereum/test';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
2
3
  import { createLogger } from '@aztec/foundation/log';
3
4
  import { RunningPromise } from '@aztec/foundation/running-promise';
4
5
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
@@ -12,7 +13,8 @@ import { getAddress, getContract } from 'viem';
12
13
  */ export class AnvilTestWatcher {
13
14
  cheatcodes;
14
15
  dateProvider;
15
- isSandbox;
16
+ isLocalNetwork;
17
+ isMarkingAsProven;
16
18
  rollup;
17
19
  rollupCheatCodes;
18
20
  l2SlotDuration;
@@ -20,13 +22,21 @@ import { getAddress, getContract } from 'viem';
20
22
  syncDateProviderPromise;
21
23
  markingAsProvenRunningPromise;
22
24
  logger;
23
- isMarkingAsProven;
24
- constructor(cheatcodes, rollupAddress, l1Client, dateProvider){
25
+ // Optional callback to check if there are pending txs in the mempool.
26
+ getPendingTxCount;
27
+ // Optional callback to check if the sequencer is actively building a block.
28
+ isSequencerBuilding;
29
+ // Tracks when we first observed the current unfilled slot with pending txs (real wall time).
30
+ unfilledSlotFirstSeen;
31
+ // Latest target slot for which the proposer has built a block destined for L1 but which has
32
+ // not yet been committed. Set by the proposer-pipelining hook from `block-proposed` events so
33
+ // the watcher can advance L1 (and the injected date provider) to the target slot ahead of the
34
+ // publisher's `sendRequestsAt` sleep, instead of waiting a full wall-clock slot.
35
+ proposedTargetSlot;
36
+ constructor(cheatcodes, rollupAddress, l1Client, dateProvider, opts = {}){
25
37
  this.cheatcodes = cheatcodes;
26
38
  this.dateProvider = dateProvider;
27
- this.isSandbox = false;
28
39
  this.logger = createLogger(`aztecjs:utils:watcher`);
29
- this.isMarkingAsProven = true;
30
40
  this.rollup = getContract({
31
41
  address: getAddress(rollupAddress.toString()),
32
42
  abi: RollupAbi,
@@ -35,14 +45,32 @@ import { getAddress, getContract } from 'viem';
35
45
  this.rollupCheatCodes = new RollupCheatCodes(this.cheatcodes, {
36
46
  rollupAddress
37
47
  });
48
+ this.isLocalNetwork = opts.isLocalNetwork ?? false;
49
+ this.isMarkingAsProven = opts.isMarkingAsProven ?? true;
38
50
  this.logger.debug(`Watcher created for rollup at ${rollupAddress}`);
39
51
  }
40
52
  setIsMarkingAsProven(isMarkingAsProven) {
41
53
  this.logger.warn(`Watcher is now ${isMarkingAsProven ? 'marking' : 'not marking'} blocks as proven`);
42
54
  this.isMarkingAsProven = isMarkingAsProven;
43
55
  }
44
- setIsSandbox(isSandbox) {
45
- this.isSandbox = isSandbox;
56
+ setisLocalNetwork(isLocalNetwork) {
57
+ this.isLocalNetwork = isLocalNetwork;
58
+ }
59
+ /** Sets a callback to check for pending txs, used to skip unfilled slots faster when txs are waiting. */ setGetPendingTxCount(fn) {
60
+ this.getPendingTxCount = fn;
61
+ }
62
+ /** Sets a callback to check if the sequencer is actively building, to avoid warping while it works. */ setIsSequencerBuilding(fn) {
63
+ this.isSequencerBuilding = fn;
64
+ }
65
+ /**
66
+ * Records the target slot for which the proposer has built a block destined for L1. Used by
67
+ * the local-network watcher to fast-forward L1 (and the injected date provider) ahead of the
68
+ * pipelined publisher's `sendRequestsAt` sleep so it ends promptly instead of waiting a full
69
+ * wall-clock slot. Only ratchets up — late warps for stale slots are no-ops.
70
+ */ setProposedTargetSlot(slot) {
71
+ if (this.proposedTargetSlot === undefined || slot > this.proposedTargetSlot) {
72
+ this.proposedTargetSlot = slot;
73
+ }
46
74
  }
47
75
  async start() {
48
76
  if (this.filledRunningPromise) {
@@ -52,7 +80,7 @@ import { getAddress, getContract } from 'viem';
52
80
  this.l2SlotDuration = config.slotDuration;
53
81
  // If auto mining is not supported (e.g., we are on a real network), then we
54
82
  // will simple do nothing. But if on an anvil or the like, this make sure that
55
- // the sandbox and tests don't break because time is frozen and we never get to
83
+ // the local network and tests don't break because time is frozen and we never get to
56
84
  // the next slot.
57
85
  const isAutoMining = await this.cheatcodes.isAutoMining();
58
86
  if (isAutoMining) {
@@ -84,59 +112,124 @@ import { getAddress, getContract } from 'viem';
84
112
  await this.rollupCheatCodes.markAsProven();
85
113
  }
86
114
  async syncDateProviderToL1IfBehind() {
87
- // this doesn't apply to the sandbox, because we don't have a date provider in the sandbox
115
+ // this doesn't apply to the local network, because we don't have a date provider in the local network
88
116
  if (!this.dateProvider) {
89
117
  return;
90
118
  }
91
- const l1Time = await this.cheatcodes.timestamp() * 1000;
119
+ const l1Time = await this.cheatcodes.lastBlockTimestamp() * 1000;
92
120
  const wallTime = this.dateProvider.now();
93
121
  if (l1Time > wallTime) {
94
122
  this.logger.warn(`L1 is ahead of wall time. Syncing wall time to L1 time`);
95
123
  this.dateProvider.setTime(l1Time);
96
124
  } else if (l1Time + Number(this.l2SlotDuration) * 1000 < wallTime) {
97
- this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to wall time`);
98
- await this.cheatcodes.warp(Math.ceil(wallTime / 1000));
125
+ // Warp L1 to the slot boundary at-or-before wall time. Rounding to a slot boundary (rather than
126
+ // `ceil(wallTime / 1000)`) keeps this loop's target aligned with `warpTimeIfNeeded`'s
127
+ // `nextSlotTimestamp` target, avoiding a race where the two loops pick timestamps a fraction of
128
+ // a second apart and one of them is then rejected by anvil as non-monotonic.
129
+ const wallSec = Math.floor(wallTime / 1000);
130
+ const targetSlot = await this.rollup.read.getSlotAt([
131
+ BigInt(wallSec)
132
+ ]);
133
+ const targetTimestamp = Number(await this.rollup.read.getTimestampForSlot([
134
+ targetSlot
135
+ ]));
136
+ this.logger.warn(`L1 is more than 1 L2 slot behind wall time. Warping to slot ${targetSlot} boundary`);
137
+ await this.warpToTimestamp(targetTimestamp);
99
138
  }
100
139
  }
101
140
  async warpTimeIfNeeded() {
102
141
  try {
103
- const currentSlot = await this.rollup.read.getCurrentSlot();
104
- const pendingBlockNumber = BigInt(await this.rollup.read.getPendingBlockNumber());
105
- const blockLog = await this.rollup.read.getBlock([
106
- pendingBlockNumber
142
+ const currentSlot = SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
143
+ const pendingCheckpointNumber = await this.rollup.read.getPendingCheckpointNumber();
144
+ const checkpointLog = await this.rollup.read.getCheckpoint([
145
+ pendingCheckpointNumber
107
146
  ]);
147
+ const nextSlot = SlotNumber(currentSlot + 1);
108
148
  const nextSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
109
- currentSlot + 1n
149
+ BigInt(nextSlot)
110
150
  ]));
111
- if (currentSlot === blockLog.slotNumber) {
112
- // We should jump to the next slot
113
- try {
114
- await this.cheatcodes.warp(nextSlotTimestamp, {
115
- resetBlockInterval: true
116
- });
117
- } catch (e) {
118
- this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
151
+ if (BigInt(currentSlot) === checkpointLog.slotNumber) {
152
+ // The current slot has been filled, we should jump to the next slot.
153
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
154
+ this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
119
155
  }
120
- this.logger.info(`Slot ${currentSlot} was filled, jumped to next slot`);
121
156
  return;
122
157
  }
123
- // If we are not in sandbox, we don't need to warp time
124
- if (!this.isSandbox) {
158
+ // If we are not in local network, we don't need to warp time
159
+ if (!this.isLocalNetwork) {
125
160
  return;
126
161
  }
162
+ // Pipelined-publish shortcut: if the proposer has built a block destined for a slot
163
+ // beyond the current L1 slot, fast-forward L1 to that slot's timestamp so the publisher's
164
+ // `sendRequestsAt(targetSlot)` sleep ends and the multicall mines inside the target slot.
165
+ // Without this, the publisher waits up to a full real-time slot for wall clock to catch up.
166
+ if (this.proposedTargetSlot !== undefined && this.proposedTargetSlot > currentSlot) {
167
+ const targetSlotTimestamp = Number(await this.rollup.read.getTimestampForSlot([
168
+ BigInt(this.proposedTargetSlot)
169
+ ]));
170
+ if (await this.warpToTimestamp(targetSlotTimestamp)) {
171
+ this.logger.info(`Warped L1 to target slot ${this.proposedTargetSlot} for pipelined publish`);
172
+ }
173
+ return;
174
+ }
175
+ // If there are pending txs and the sequencer missed them, warp quickly (after a 2s real-time debounce) so the
176
+ // sequencer can retry in the next slot. Without this, we'd have to wait a full real-time slot duration (~36s) for
177
+ // the dateProvider to catch up to the next slot timestamp. We skip the warp if the sequencer is actively building
178
+ // to avoid invalidating its in-progress work.
179
+ if (this.getPendingTxCount) {
180
+ const pendingTxs = await this.getPendingTxCount();
181
+ if (pendingTxs > 0) {
182
+ if (this.isSequencerBuilding?.()) {
183
+ this.unfilledSlotFirstSeen = undefined;
184
+ return;
185
+ }
186
+ const realNow = Date.now();
187
+ if (!this.unfilledSlotFirstSeen || this.unfilledSlotFirstSeen.slot !== currentSlot) {
188
+ this.unfilledSlotFirstSeen = {
189
+ slot: currentSlot,
190
+ realTime: realNow
191
+ };
192
+ return;
193
+ }
194
+ if (realNow - this.unfilledSlotFirstSeen.realTime > 2000) {
195
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
196
+ this.logger.info(`Slot ${currentSlot} was missed with pending txs, jumped to next slot`);
197
+ }
198
+ this.unfilledSlotFirstSeen = undefined;
199
+ }
200
+ return;
201
+ }
202
+ }
203
+ // Fallback: warp when the dateProvider time has passed the next slot timestamp.
127
204
  const currentTimestamp = this.dateProvider?.now() ?? Date.now();
128
205
  if (currentTimestamp > nextSlotTimestamp * 1000) {
129
- try {
130
- await this.cheatcodes.warp(nextSlotTimestamp, {
131
- resetBlockInterval: true
132
- });
133
- } catch (e) {
134
- this.logger.error(`Failed to warp to timestamp ${nextSlotTimestamp}: ${e}`);
206
+ if (await this.warpToTimestamp(nextSlotTimestamp)) {
207
+ this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
135
208
  }
136
- this.logger.info(`Slot ${currentSlot} was missed, jumped to next slot`);
137
209
  }
138
210
  } catch {
139
211
  this.logger.error('mineIfSlotFilled failed');
140
212
  }
141
213
  }
214
+ /**
215
+ * Warps L1 to `timestamp`, unless L1 is already at or past it. Returns true when a warp actually
216
+ * happened, false when skipped or on error. Callers use the return value to gate success logs.
217
+ */ async warpToTimestamp(timestamp) {
218
+ try {
219
+ // Anvil rejects evm_setNextBlockTimestamp values <= the current block's timestamp. The two
220
+ // watcher loops can race and pick targets a fraction of a second apart; skip here rather than
221
+ // letting the second one error out noisily.
222
+ const lastTimestamp = await this.cheatcodes.lastBlockTimestamp();
223
+ if (timestamp <= lastTimestamp) {
224
+ return false;
225
+ }
226
+ await this.cheatcodes.warp(timestamp, {
227
+ resetBlockInterval: true
228
+ });
229
+ return true;
230
+ } catch (e) {
231
+ this.logger.error(`Failed to warp to timestamp ${timestamp}: ${e}`);
232
+ return false;
233
+ }
234
+ }
142
235
  }
@@ -1,7 +1,7 @@
1
1
  import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
2
  import type { DateProvider } from '@aztec/foundation/timer';
3
- import type { SequencerClient } from '@aztec/sequencer-client';
4
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
3
+ import type { AutomineSequencer } from '@aztec/sequencer-client';
4
+ import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
5
5
  /**
6
6
  * A class that provides utility functions for interacting with the chain.
7
7
  * @deprecated There used to be 3 kinds of cheat codes: eth, rollup and aztec. We have nuked the Aztec ones because
@@ -13,31 +13,32 @@ export declare class CheatCodes {
13
13
  eth: EthCheatCodes;
14
14
  /** Cheat codes for the Aztec Rollup contract on L1. */
15
15
  rollup: RollupCheatCodes;
16
+ /** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */
17
+ private automine?;
18
+ private logger;
16
19
  constructor(
17
20
  /** Cheat codes for L1.*/
18
21
  eth: EthCheatCodes,
19
22
  /** Cheat codes for the Aztec Rollup contract on L1. */
20
- rollup: RollupCheatCodes);
21
- static create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider): Promise<CheatCodes>;
23
+ rollup: RollupCheatCodes,
24
+ /** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */
25
+ automine?: AutomineSequencer | undefined);
26
+ static create(rpcUrls: string[], node: AztecNode, dateProvider: DateProvider, automine?: AutomineSequencer): Promise<CheatCodes>;
22
27
  /**
23
28
  * Warps the L1 timestamp to a target timestamp and mines an L2 block that advances the L2 timestamp to at least
24
- * the target timestamp. L2 timestamp is not advanced exactly to the target timestamp because it is determined
25
- * by the slot number, which advances in fixed intervals.
26
- * This is useful for testing time-dependent contract behavior.
27
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
28
- * @param node - The Aztec node used to query if a new block has been mined.
29
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
30
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
31
+ * @param node - The Aztec node used to force an empty block to be mined.
29
32
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
30
33
  */
31
- warpL2TimeAtLeastTo(sequencerClient: SequencerClient, node: AztecNode, targetTimestamp: bigint | number): Promise<void>;
34
+ warpL2TimeAtLeastTo(node: AztecNode & AztecNodeDebug, targetTimestamp: bigint | number): Promise<void>;
32
35
  /**
33
36
  * Warps the L1 timestamp forward by a specified duration and mines an L2 block that advances the L2 timestamp at
34
- * least by the duration. L2 timestamp is not advanced exactly by the duration because it is determined by the slot
35
- * number, which advances in fixed intervals.
36
- * This is useful for testing time-dependent contract behavior.
37
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
38
- * @param node - The Aztec node used to query if a new block has been mined.
37
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
38
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
39
+ * @param node - The Aztec node used to force an empty block to be mined.
39
40
  * @param duration - The duration to advance time by (in seconds)
40
41
  */
41
- warpL2TimeAtLeastBy(sequencerClient: SequencerClient, node: AztecNode, duration: bigint | number): Promise<void>;
42
+ warpL2TimeAtLeastBy(node: AztecNode & AztecNodeDebug, duration: bigint | number): Promise<void>;
42
43
  }
43
- //# sourceMappingURL=cheat_codes.d.ts.map
44
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hlYXRfY29kZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0aW5nL2NoZWF0X2NvZGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxhQUFhLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUd2RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUM1RCxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQ2pFLE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxjQUFjLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUVqRjs7Ozs7R0FLRztBQUNILHFCQUFhLFVBQVU7SUFJbkIseUJBQXlCO0lBQ2xCLEdBQUcsRUFBRSxhQUFhO0lBQ3pCLHVEQUF1RDtJQUNoRCxNQUFNLEVBQUUsZ0JBQWdCO0lBQy9CLHdGQUF3RjtJQUN4RixPQUFPLENBQUMsUUFBUSxDQUFDO0lBUm5CLE9BQU8sQ0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U,CAAC,CAOrB;IAED;;;;;;OAMG;IACG,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,cAAc,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,iBA4D3F;IAED;;;;;;OAMG;IACG,mBAAmB,CAAC,IAAI,EAAE,SAAS,GAAG,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,iBAepF;CACF"}
@@ -1,5 +1,6 @@
1
1
  import { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
2
- import { retryUntil } from '@aztec/foundation/retry';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { createLogger } from '@aztec/foundation/log';
3
4
  /**
4
5
  * A class that provides utility functions for interacting with the chain.
5
6
  * @deprecated There used to be 3 kinds of cheat codes: eth, rollup and aztec. We have nuked the Aztec ones because
@@ -8,55 +9,90 @@ import { retryUntil } from '@aztec/foundation/retry';
8
9
  */ export class CheatCodes {
9
10
  eth;
10
11
  rollup;
11
- constructor(/** Cheat codes for L1.*/ eth, /** Cheat codes for the Aztec Rollup contract on L1. */ rollup){
12
+ automine;
13
+ logger;
14
+ constructor(/** Cheat codes for L1.*/ eth, /** Cheat codes for the Aztec Rollup contract on L1. */ rollup, /** When wired, redirects time-warps through the AutomineSequencer queue (test-only). */ automine){
12
15
  this.eth = eth;
13
16
  this.rollup = rollup;
17
+ this.automine = automine;
18
+ this.logger = createLogger('aztecjs:cheat_codes');
14
19
  }
15
- static async create(rpcUrls, node, dateProvider) {
20
+ static async create(rpcUrls, node, dateProvider, automine) {
16
21
  const ethCheatCodes = new EthCheatCodes(rpcUrls, dateProvider);
17
22
  const rollupCheatCodes = new RollupCheatCodes(ethCheatCodes, await node.getNodeInfo().then((n)=>n.l1ContractAddresses));
18
- return new CheatCodes(ethCheatCodes, rollupCheatCodes);
23
+ return new CheatCodes(ethCheatCodes, rollupCheatCodes, automine);
19
24
  }
20
25
  /**
21
26
  * Warps the L1 timestamp to a target timestamp and mines an L2 block that advances the L2 timestamp to at least
22
- * the target timestamp. L2 timestamp is not advanced exactly to the target timestamp because it is determined
23
- * by the slot number, which advances in fixed intervals.
24
- * This is useful for testing time-dependent contract behavior.
25
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
26
- * @param node - The Aztec node used to query if a new block has been mined.
27
+ * the target timestamp. If the target timestamp falls within the current L2 slot (which already has a block),
28
+ * the timestamp is automatically adjusted forward to the start of the next slot so that `mineBlock()` succeeds.
29
+ * @param node - The Aztec node used to force an empty block to be mined.
27
30
  * @param targetTimestamp - The target timestamp to warp to (in seconds)
28
- */ async warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp) {
29
- const currentL2BlockNumber = await node.getBlockNumber();
30
- // We warp the L1 timestamp
31
- await this.eth.warp(targetTimestamp, {
31
+ */ async warpL2TimeAtLeastTo(node, targetTimestamp) {
32
+ const targetBigInt = BigInt(targetTimestamp);
33
+ const currentTimestamp = BigInt(await this.eth.lastBlockTimestamp());
34
+ if (targetBigInt <= currentTimestamp) {
35
+ throw new Error(`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} is not in the future (current L1 timestamp is ${currentTimestamp}).`);
36
+ }
37
+ // AutomineSequencer owns time control through its serial queue — delegate to keep warps atomic
38
+ // with respect to any in-flight build, and avoid the mineBlock-loop hack below.
39
+ // `warpTo` internally builds an empty L2 checkpoint, which auto-mines exactly one L1 block at
40
+ // the target slot boundary, so no separate `node.mineBlock()` is needed here.
41
+ if (this.automine) {
42
+ await this.automine.warpTo(Number(targetBigInt));
43
+ return;
44
+ }
45
+ const currentSlot = await this.rollup.getSlot();
46
+ const targetSlot = await this.rollup.getSlotAt(targetBigInt);
47
+ let effectiveTimestamp = targetBigInt;
48
+ let effectiveTargetSlot = targetSlot;
49
+ if (targetSlot <= currentSlot) {
50
+ // Target lands in the same (or earlier) slot — auto-adjust to the next slot's start.
51
+ const nextSlot = SlotNumber(currentSlot + 1);
52
+ const nextSlotTimestamp = await this.rollup.getTimestampForSlot(nextSlot);
53
+ this.logger.warn(`warpL2TimeAtLeastTo: target timestamp ${targetBigInt} falls in current slot ${currentSlot}. ` + `Auto-adjusting to start of slot ${nextSlot} at timestamp ${nextSlotTimestamp}.`);
54
+ effectiveTimestamp = nextSlotTimestamp;
55
+ effectiveTargetSlot = nextSlot;
56
+ }
57
+ await this.eth.warp(effectiveTimestamp, {
32
58
  resetBlockInterval: true
33
59
  });
34
- // Wait until an L2 block is mined
35
- const sequencer = sequencerClient.getSequencer();
36
- const minTxsPerBlock = sequencer.getConfig().minTxsPerBlock;
37
- sequencer.updateConfig({
38
- minTxsPerBlock: 0
39
- });
40
- await retryUntil(async ()=>{
41
- const newL2BlockNumber = await node.getBlockNumber();
42
- return newL2BlockNumber > currentL2BlockNumber;
43
- }, 'new block after warping L2 time', 36, 1);
44
- // Restore original minTxsPerBlock
45
- sequencer.updateConfig({
46
- minTxsPerBlock
47
- });
60
+ // The sequencer's polling loop may have a `work()` cycle in flight that captured pre-warp slot/timestamp values
61
+ // just before our warp landed. That cycle would mine an L2 block at the stale slot — the L1 sync prunes such a
62
+ // block from the canonical chain, but it lingers in local world state and the PXE will use it as the anchor for
63
+ // subsequent txs, leading to `expiration_timestamp` values that are already in the past relative to L1. Mine
64
+ // until we observe an L2 block at (or past) the post-warp slot, ensuring the next tx anchors to a fresh block.
65
+ const maxAttempts = 5;
66
+ for(let attempt = 1; attempt <= maxAttempts; attempt++){
67
+ await node.mineBlock();
68
+ const blockData = await node.getBlockData('latest');
69
+ const blockSlot = blockData?.header.globalVariables.slotNumber;
70
+ if (blockSlot !== undefined && BigInt(blockSlot) >= BigInt(effectiveTargetSlot)) {
71
+ return;
72
+ }
73
+ this.logger.warn(`warpL2TimeAtLeastTo: mined L2 block at slot ${blockSlot}, expected at least ${effectiveTargetSlot}. ` + `Retrying mineBlock (attempt ${attempt}/${maxAttempts}).`);
74
+ }
75
+ throw new Error(`warpL2TimeAtLeastTo: failed to mine an L2 block at or past slot ${effectiveTargetSlot} after ${maxAttempts} attempts.`);
48
76
  }
49
77
  /**
50
78
  * Warps the L1 timestamp forward by a specified duration and mines an L2 block that advances the L2 timestamp at
51
- * least by the duration. L2 timestamp is not advanced exactly by the duration because it is determined by the slot
52
- * number, which advances in fixed intervals.
53
- * This is useful for testing time-dependent contract behavior.
54
- * @param sequencerClient - The sequencer client to use to force an empty block to be mined.
55
- * @param node - The Aztec node used to query if a new block has been mined.
79
+ * least by the duration. If the duration is too short to cross an L2 slot boundary, the warp is automatically
80
+ * extended to the start of the next slot so that `mineBlock()` succeeds.
81
+ * @param node - The Aztec node used to force an empty block to be mined.
56
82
  * @param duration - The duration to advance time by (in seconds)
57
- */ async warpL2TimeAtLeastBy(sequencerClient, node, duration) {
58
- const currentTimestamp = await this.eth.timestamp();
59
- const targetTimestamp = BigInt(currentTimestamp) + BigInt(duration);
60
- await this.warpL2TimeAtLeastTo(sequencerClient, node, targetTimestamp);
83
+ */ async warpL2TimeAtLeastBy(node, duration) {
84
+ if (BigInt(duration) <= 0n) {
85
+ throw new Error(`warpL2TimeAtLeastBy: duration must be positive, got ${duration} seconds.`);
86
+ }
87
+ // Advance relative to whichever clock leads. A live sequencer mines L2 blocks at slot boundaries that can run
88
+ // ahead of anvil's L1 timestamp, so basing the target on L1 alone would advance the L2 timestamp by less than
89
+ // `duration`. Anchoring to the latest L2 block timestamp when it leads guarantees the post-warp L2 block is at
90
+ // least `duration` ahead of the current one.
91
+ const currentL1Timestamp = BigInt(await this.eth.lastBlockTimestamp());
92
+ const latestBlockData = await node.getBlockData('latest');
93
+ const latestL2Timestamp = latestBlockData ? BigInt(latestBlockData.header.globalVariables.timestamp) : 0n;
94
+ const baseTimestamp = latestL2Timestamp > currentL1Timestamp ? latestL2Timestamp : currentL1Timestamp;
95
+ const targetTimestamp = baseTimestamp + BigInt(duration);
96
+ await this.warpL2TimeAtLeastTo(node, targetTimestamp);
61
97
  }
62
98
  }
@@ -0,0 +1,19 @@
1
+ import { type EthCheatCodes } from '@aztec/ethereum/test';
2
+ import { type EpochNumber } from '@aztec/foundation/branded-types';
3
+ import type { Logger } from '@aztec/foundation/log';
4
+ import type { EthAddress, L2BlockSource } from '@aztec/stdlib/block';
5
+ export declare class EpochTestSettler {
6
+ private l2BlockSource;
7
+ private log;
8
+ private options;
9
+ private rollupCheatCodes;
10
+ private epochMonitor?;
11
+ constructor(cheatcodes: EthCheatCodes, rollupAddress: EthAddress, l2BlockSource: L2BlockSource, log: Logger, options: {
12
+ pollingIntervalMs: number;
13
+ provingDelayMs?: number;
14
+ });
15
+ start(): Promise<void>;
16
+ stop(): Promise<void>;
17
+ handleEpochReadyToProve(epoch: EpochNumber): Promise<boolean>;
18
+ }
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXBvY2hfdGVzdF9zZXR0bGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdGVzdGluZy9lcG9jaF90ZXN0X3NldHRsZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssYUFBYSxFQUFvQixNQUFNLHNCQUFzQixDQUFDO0FBQzVFLE9BQU8sRUFBRSxLQUFLLFdBQVcsRUFBYyxNQUFNLGlDQUFpQyxDQUFDO0FBQy9FLE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRXBELE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxhQUFhLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUdyRSxxQkFBYSxnQkFBZ0I7SUFPekIsT0FBTyxDQUFDLGFBQWE7SUFDckIsT0FBTyxDQUFDLEdBQUc7SUFDWCxPQUFPLENBQUMsT0FBTztJQVJqQixPQUFPLENBQUMsZ0JBQWdCLENBQW1CO0lBQzNDLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0FBZTtJQUVwQyxZQUNFLFVBQVUsRUFBRSxhQUFhLEVB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
@@ -0,0 +1,63 @@
1
+ import { RollupCheatCodes } from '@aztec/ethereum/test';
2
+ import { SlotNumber } from '@aztec/foundation/branded-types';
3
+ import { EpochMonitor } from '@aztec/prover-node';
4
+ import { computeEpochOutHash } from '@aztec/stdlib/messaging';
5
+ export class EpochTestSettler {
6
+ l2BlockSource;
7
+ log;
8
+ options;
9
+ rollupCheatCodes;
10
+ epochMonitor;
11
+ constructor(cheatcodes, rollupAddress, l2BlockSource, log, options){
12
+ this.l2BlockSource = l2BlockSource;
13
+ this.log = log;
14
+ this.options = options;
15
+ this.rollupCheatCodes = new RollupCheatCodes(cheatcodes, {
16
+ rollupAddress
17
+ });
18
+ }
19
+ async start() {
20
+ const { epochDuration } = await this.rollupCheatCodes.getConfig();
21
+ this.epochMonitor = new EpochMonitor(this.l2BlockSource, {
22
+ epochDuration: Number(epochDuration)
23
+ }, this.options);
24
+ this.epochMonitor.start(this);
25
+ }
26
+ async stop() {
27
+ await this.epochMonitor?.stop();
28
+ }
29
+ async handleEpochReadyToProve(epoch) {
30
+ const blocks = await this.l2BlockSource.getBlocks({
31
+ epoch,
32
+ onlyCheckpointed: true
33
+ });
34
+ this.log.info(`Settling epoch ${epoch} with blocks ${blocks[0]?.header.getBlockNumber()} to ${blocks.at(-1)?.header.getBlockNumber()}`, {
35
+ blocks: blocks.map((b)=>b.toBlockInfo())
36
+ });
37
+ const messagesInEpoch = [];
38
+ let previousSlotNumber = SlotNumber.ZERO;
39
+ let checkpointIndex = -1;
40
+ for (const block of blocks){
41
+ const slotNumber = block.header.globalVariables.slotNumber;
42
+ if (slotNumber !== previousSlotNumber) {
43
+ checkpointIndex++;
44
+ messagesInEpoch[checkpointIndex] = [];
45
+ previousSlotNumber = slotNumber;
46
+ }
47
+ messagesInEpoch[checkpointIndex].push(block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs));
48
+ }
49
+ const outHash = computeEpochOutHash(messagesInEpoch);
50
+ if (!outHash.isZero()) {
51
+ await this.rollupCheatCodes.insertOutbox(epoch, messagesInEpoch.length, outHash.toBigInt());
52
+ } else {
53
+ this.log.info(`No L2 to L1 messages in epoch ${epoch}`);
54
+ }
55
+ const lastCheckpoint = blocks.at(-1)?.checkpointNumber;
56
+ if (lastCheckpoint !== undefined) {
57
+ await this.rollupCheatCodes.markAsProven(lastCheckpoint);
58
+ } else {
59
+ this.log.warn(`No checkpoint found for epoch ${epoch}`);
60
+ }
61
+ return true;
62
+ }
63
+ }
@@ -1,4 +1,6 @@
1
- export { AnvilTestWatcher } from './anvil_test_watcher.js';
1
+ export { AnvilTestWatcher, type AnvilTestWatcherOpts } from './anvil_test_watcher.js';
2
2
  export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
3
3
  export { CheatCodes } from './cheat_codes.js';
4
- //# sourceMappingURL=index.d.ts.map
4
+ export { EpochTestSettler } from './epoch_test_settler.js';
5
+ export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0aW5nL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxLQUFLLG9CQUFvQixFQUFFLE1BQU0seUJBQXlCLENBQUM7QUFDdEYsT0FBTyxFQUFFLGFBQWEsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3ZFLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUM5QyxPQUFPLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUMzRCxPQUFPLEVBQUUsNkJBQTZCLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQyJ9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,3 +1,5 @@
1
1
  export { AnvilTestWatcher } from './anvil_test_watcher.js';
2
2
  export { EthCheatCodes, RollupCheatCodes } from '@aztec/ethereum/test';
3
3
  export { CheatCodes } from './cheat_codes.js';
4
+ export { EpochTestSettler } from './epoch_test_settler.js';
5
+ export { getTokenAllowedSetupFunctions } from './token_allowed_setup.js';
@@ -0,0 +1,7 @@
1
+ import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
2
+ /**
3
+ * Returns Token-specific allowlist entries needed for FPC-based fee payments.
4
+ * These are test-only: FPC-based fee payment with custom tokens won't work on mainnet alpha.
5
+ */
6
+ export declare function getTokenAllowedSetupFunctions(): Promise<AllowedElement[]>;
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9rZW5fYWxsb3dlZF9zZXR1cC5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Rlc3RpbmcvdG9rZW5fYWxsb3dlZF9zZXR1cC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEtBQUssRUFBRSxjQUFjLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUV0RTs7O0dBR0c7QUFDSCx3QkFBc0IsNkJBQTZCLElBQUksT0FBTyxDQUFDLGNBQWMsRUFBRSxDQUFDLENBUy9FIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token_allowed_setup.d.ts","sourceRoot":"","sources":["../../src/testing/token_allowed_setup.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;;GAGG;AACH,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAS/E"}
@@ -0,0 +1,20 @@
1
+ import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
2
+ import { buildAllowedElement } from '@aztec/p2p/msg_validators';
3
+ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
4
+ /**
5
+ * Returns Token-specific allowlist entries needed for FPC-based fee payments.
6
+ * These are test-only: FPC-based fee payment with custom tokens won't work on mainnet alpha.
7
+ */ export async function getTokenAllowedSetupFunctions() {
8
+ const tokenClassId = (await getContractClassFromArtifact(TokenContractArtifact)).id;
9
+ const target = {
10
+ classId: tokenClassId
11
+ };
12
+ return Promise.all([
13
+ // Token: needed for private transfers via FPC (transfer_to_public enqueues this)
14
+ buildAllowedElement(TokenContractArtifact, target, '_increase_public_balance', {
15
+ onlySelf: true
16
+ }),
17
+ // Token: needed for public transfers via FPC (fee_entrypoint_public enqueues this)
18
+ buildAllowedElement(TokenContractArtifact, target, 'transfer_in_public')
19
+ ]);
20
+ }