@aztec/ethereum 0.0.0-test.1 → 0.0.1-commit.017a351

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 (285) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/chain.d.ts +1 -1
  5. package/dest/client.d.ts +28 -4
  6. package/dest/client.d.ts.map +1 -1
  7. package/dest/client.js +73 -3
  8. package/dest/config.d.ts +70 -23
  9. package/dest/config.d.ts.map +1 -1
  10. package/dest/config.js +151 -34
  11. package/dest/constants.d.ts +1 -1
  12. package/dest/contracts/chain_state_override.d.ts +78 -0
  13. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  14. package/dest/contracts/chain_state_override.js +137 -0
  15. package/dest/contracts/empire_base.d.ts +25 -8
  16. package/dest/contracts/empire_base.d.ts.map +1 -1
  17. package/dest/contracts/empire_base.js +75 -2
  18. package/dest/contracts/errors.d.ts +7 -0
  19. package/dest/contracts/errors.d.ts.map +1 -0
  20. package/dest/contracts/errors.js +12 -0
  21. package/dest/contracts/fee_asset_handler.d.ts +20 -0
  22. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_handler.js +59 -0
  24. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  25. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  26. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  27. package/dest/contracts/fee_juice.d.ts +6 -7
  28. package/dest/contracts/fee_juice.d.ts.map +1 -1
  29. package/dest/contracts/fee_juice.js +27 -20
  30. package/dest/contracts/governance.d.ts +131 -43
  31. package/dest/contracts/governance.d.ts.map +1 -1
  32. package/dest/contracts/governance.js +281 -87
  33. package/dest/contracts/governance_proposer.d.ts +49 -13
  34. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  35. package/dest/contracts/governance_proposer.js +483 -26
  36. package/dest/contracts/gse.d.ts +32 -0
  37. package/dest/contracts/gse.d.ts.map +1 -0
  38. package/dest/contracts/gse.js +72 -0
  39. package/dest/contracts/inbox.d.ts +47 -0
  40. package/dest/contracts/inbox.d.ts.map +1 -0
  41. package/dest/contracts/inbox.js +85 -0
  42. package/dest/contracts/index.d.ts +11 -2
  43. package/dest/contracts/index.d.ts.map +1 -1
  44. package/dest/contracts/index.js +10 -1
  45. package/dest/contracts/log.d.ts +13 -0
  46. package/dest/contracts/log.d.ts.map +1 -0
  47. package/dest/contracts/log.js +1 -0
  48. package/dest/contracts/multicall.d.ts +136 -0
  49. package/dest/contracts/multicall.d.ts.map +1 -0
  50. package/dest/contracts/multicall.js +264 -0
  51. package/dest/contracts/outbox.d.ts +64 -0
  52. package/dest/contracts/outbox.d.ts.map +1 -0
  53. package/dest/contracts/outbox.js +113 -0
  54. package/dest/contracts/registry.d.ts +12 -5
  55. package/dest/contracts/registry.d.ts.map +1 -1
  56. package/dest/contracts/registry.js +74 -17
  57. package/dest/contracts/rollup.d.ts +5526 -52
  58. package/dest/contracts/rollup.d.ts.map +1 -1
  59. package/dest/contracts/rollup.js +1446 -118
  60. package/dest/contracts/slasher_contract.d.ts +44 -0
  61. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  62. package/dest/contracts/slasher_contract.js +75 -0
  63. package/dest/contracts/slashing_proposer.d.ts +133 -15
  64. package/dest/contracts/slashing_proposer.d.ts.map +1 -1
  65. package/dest/contracts/slashing_proposer.js +293 -22
  66. package/dest/contracts/utils.d.ts +3 -0
  67. package/dest/contracts/utils.d.ts.map +1 -0
  68. package/dest/contracts/utils.js +11 -0
  69. package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
  70. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  71. package/dest/deploy_aztec_l1_contracts.js +411 -0
  72. package/dest/deploy_l1_contract.d.ts +68 -0
  73. package/dest/deploy_l1_contract.d.ts.map +1 -0
  74. package/dest/deploy_l1_contract.js +312 -0
  75. package/dest/eth-signer/eth-signer.d.ts +21 -0
  76. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  77. package/dest/eth-signer/eth-signer.js +5 -0
  78. package/dest/eth-signer/index.d.ts +2 -0
  79. package/dest/eth-signer/index.d.ts.map +1 -0
  80. package/dest/eth-signer/index.js +1 -0
  81. package/dest/forwarder_proxy.d.ts +32 -0
  82. package/dest/forwarder_proxy.d.ts.map +1 -0
  83. package/dest/forwarder_proxy.js +93 -0
  84. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  85. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  86. package/dest/generated/l1-contracts-defaults.js +30 -0
  87. package/dest/l1_artifacts.d.ts +79270 -0
  88. package/dest/l1_artifacts.d.ts.map +1 -0
  89. package/dest/l1_artifacts.js +151 -0
  90. package/dest/l1_contract_addresses.d.ts +61 -45
  91. package/dest/l1_contract_addresses.d.ts.map +1 -1
  92. package/dest/l1_contract_addresses.js +99 -76
  93. package/dest/l1_reader.d.ts +8 -6
  94. package/dest/l1_reader.d.ts.map +1 -1
  95. package/dest/l1_reader.js +20 -12
  96. package/dest/l1_tx_utils/config.d.ts +65 -0
  97. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/config.js +109 -0
  99. package/dest/l1_tx_utils/constants.d.ts +12 -0
  100. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  101. package/dest/l1_tx_utils/constants.js +39 -0
  102. package/dest/l1_tx_utils/factory.d.ts +32 -0
  103. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  104. package/dest/l1_tx_utils/factory.js +22 -0
  105. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  106. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  107. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  108. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  109. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  110. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  111. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  112. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  113. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  114. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  115. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  116. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  117. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  118. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  119. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  120. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  121. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  122. package/dest/l1_tx_utils/index-blobs.js +2 -0
  123. package/dest/l1_tx_utils/index.d.ts +13 -0
  124. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  125. package/dest/l1_tx_utils/index.js +13 -0
  126. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  127. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  128. package/dest/l1_tx_utils/interfaces.js +4 -0
  129. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  130. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  131. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  132. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  133. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  134. package/dest/l1_tx_utils/l1_tx_utils.js +658 -0
  135. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  136. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  137. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +328 -0
  138. package/dest/l1_tx_utils/signer.d.ts +4 -0
  139. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  140. package/dest/l1_tx_utils/signer.js +16 -0
  141. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  142. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  143. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  144. package/dest/l1_tx_utils/types.d.ts +67 -0
  145. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  146. package/dest/l1_tx_utils/types.js +26 -0
  147. package/dest/l1_tx_utils/utils.d.ts +4 -0
  148. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  149. package/dest/l1_tx_utils/utils.js +14 -0
  150. package/dest/l1_types.d.ts +6 -0
  151. package/dest/l1_types.d.ts.map +1 -0
  152. package/dest/l1_types.js +1 -0
  153. package/dest/publisher_manager.d.ts +30 -0
  154. package/dest/publisher_manager.d.ts.map +1 -0
  155. package/dest/publisher_manager.js +162 -0
  156. package/dest/queries.d.ts +17 -4
  157. package/dest/queries.d.ts.map +1 -1
  158. package/dest/queries.js +120 -12
  159. package/dest/test/chain_monitor.d.ts +95 -0
  160. package/dest/test/chain_monitor.d.ts.map +1 -0
  161. package/dest/test/chain_monitor.js +249 -0
  162. package/dest/test/eth_cheat_codes.d.ts +237 -0
  163. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  164. package/dest/test/eth_cheat_codes.js +573 -0
  165. package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
  166. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  167. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  168. package/dest/test/index.d.ts +4 -3
  169. package/dest/test/index.d.ts.map +1 -1
  170. package/dest/test/index.js +3 -2
  171. package/dest/test/rollup_cheat_codes.d.ts +118 -0
  172. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  173. package/dest/test/rollup_cheat_codes.js +344 -0
  174. package/dest/test/start_anvil.d.ts +30 -2
  175. package/dest/test/start_anvil.d.ts.map +1 -1
  176. package/dest/test/start_anvil.js +147 -24
  177. package/dest/test/upgrade_utils.d.ts +6 -5
  178. package/dest/test/upgrade_utils.d.ts.map +1 -1
  179. package/dest/test/upgrade_utils.js +23 -16
  180. package/dest/types.d.ts +62 -8
  181. package/dest/types.d.ts.map +1 -1
  182. package/dest/types.js +3 -1
  183. package/dest/utils.d.ts +25 -4
  184. package/dest/utils.d.ts.map +1 -1
  185. package/dest/utils.js +142 -91
  186. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  187. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  188. package/dest/zkPassportVerifierAddress.js +11 -0
  189. package/package.json +52 -26
  190. package/src/account.ts +5 -0
  191. package/src/client.ts +107 -5
  192. package/src/config.ts +218 -43
  193. package/src/contracts/README.md +157 -0
  194. package/src/contracts/chain_state_override.ts +200 -0
  195. package/src/contracts/empire_base.ts +77 -7
  196. package/src/contracts/errors.ts +13 -0
  197. package/src/contracts/fee_asset_handler.ts +66 -0
  198. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  199. package/src/contracts/fee_juice.ts +29 -15
  200. package/src/contracts/governance.ts +343 -74
  201. package/src/contracts/governance_proposer.ts +128 -25
  202. package/src/contracts/gse.ts +88 -0
  203. package/src/contracts/inbox.ts +123 -0
  204. package/src/contracts/index.ts +10 -1
  205. package/src/contracts/log.ts +13 -0
  206. package/src/contracts/multicall.ts +296 -0
  207. package/src/contracts/outbox.ts +132 -0
  208. package/src/contracts/registry.ts +81 -26
  209. package/src/contracts/rollup.ts +1246 -90
  210. package/src/contracts/slasher_contract.ts +89 -0
  211. package/src/contracts/slashing_proposer.ts +296 -27
  212. package/src/contracts/utils.ts +14 -0
  213. package/src/deploy_aztec_l1_contracts.ts +646 -0
  214. package/src/deploy_l1_contract.ts +362 -0
  215. package/src/eth-signer/eth-signer.ts +25 -0
  216. package/src/eth-signer/index.ts +1 -0
  217. package/src/forwarder_proxy.ts +108 -0
  218. package/src/generated/l1-contracts-defaults.ts +32 -0
  219. package/src/l1_artifacts.ts +231 -0
  220. package/src/l1_contract_addresses.ts +121 -80
  221. package/src/l1_reader.ts +31 -16
  222. package/src/l1_tx_utils/README.md +177 -0
  223. package/src/l1_tx_utils/config.ts +181 -0
  224. package/src/l1_tx_utils/constants.ts +29 -0
  225. package/src/l1_tx_utils/factory.ts +64 -0
  226. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  227. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  228. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  229. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  230. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  231. package/src/l1_tx_utils/index-blobs.ts +2 -0
  232. package/src/l1_tx_utils/index.ts +15 -0
  233. package/src/l1_tx_utils/interfaces.ts +86 -0
  234. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  235. package/src/l1_tx_utils/l1_tx_utils.ts +789 -0
  236. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +424 -0
  237. package/src/l1_tx_utils/signer.ts +28 -0
  238. package/src/l1_tx_utils/tx_delayer.ts +303 -0
  239. package/src/l1_tx_utils/types.ts +85 -0
  240. package/src/l1_tx_utils/utils.ts +16 -0
  241. package/src/l1_types.ts +6 -0
  242. package/src/publisher_manager.ts +203 -0
  243. package/src/queries.ts +149 -17
  244. package/src/test/chain_monitor.ts +307 -0
  245. package/src/test/eth_cheat_codes.ts +600 -0
  246. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  247. package/src/test/index.ts +3 -2
  248. package/src/test/rollup_cheat_codes.ts +388 -0
  249. package/src/test/start_anvil.ts +189 -22
  250. package/src/test/upgrade_utils.ts +30 -21
  251. package/src/types.ts +71 -7
  252. package/src/utils.ts +164 -96
  253. package/src/zkPassportVerifierAddress.ts +15 -0
  254. package/dest/contracts/forwarder.d.ts +0 -24
  255. package/dest/contracts/forwarder.d.ts.map +0 -1
  256. package/dest/contracts/forwarder.js +0 -101
  257. package/dest/deploy_l1_contracts.d.ts +0 -21210
  258. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  259. package/dest/deploy_l1_contracts.js +0 -687
  260. package/dest/eth_cheat_codes.d.ts +0 -147
  261. package/dest/eth_cheat_codes.d.ts.map +0 -1
  262. package/dest/eth_cheat_codes.js +0 -303
  263. package/dest/index.d.ts +0 -14
  264. package/dest/index.d.ts.map +0 -1
  265. package/dest/index.js +0 -13
  266. package/dest/l1_tx_utils.d.ts +0 -192
  267. package/dest/l1_tx_utils.d.ts.map +0 -1
  268. package/dest/l1_tx_utils.js +0 -641
  269. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  270. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  271. package/dest/l1_tx_utils_with_blobs.js +0 -64
  272. package/dest/test/delayed_tx_utils.d.ts +0 -8
  273. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  274. package/dest/test/delayed_tx_utils.js +0 -21
  275. package/dest/test/tx_delayer.d.ts +0 -25
  276. package/dest/test/tx_delayer.d.ts.map +0 -1
  277. package/dest/test/tx_delayer.js +0 -116
  278. package/src/contracts/forwarder.ts +0 -132
  279. package/src/deploy_l1_contracts.ts +0 -948
  280. package/src/eth_cheat_codes.ts +0 -314
  281. package/src/index.ts +0 -13
  282. package/src/l1_tx_utils.ts +0 -847
  283. package/src/l1_tx_utils_with_blobs.ts +0 -86
  284. package/src/test/delayed_tx_utils.ts +0 -24
  285. package/src/test/tx_delayer.ts +0 -163
@@ -0,0 +1,223 @@
1
+ import { omit } from '@aztec/foundation/collection';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { retryUntil } from '@aztec/foundation/retry';
4
+ import { inspect } from 'util';
5
+ import { keccak256, parseTransaction, publicActions, recoverTransactionAddress, serializeTransaction, walletActions } from 'viem';
6
+ const MAX_WAIT_TIME_SECONDS = 180;
7
+ export function waitUntilBlock(client, blockNumber, logger, timeout) {
8
+ const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
9
+ return retryUntil(async ()=>{
10
+ const currentBlockNumber = await publicClient.getBlockNumber({
11
+ cacheTime: 0
12
+ });
13
+ logger?.debug(`Block number is ${currentBlockNumber} (waiting until ${blockNumber})`);
14
+ return currentBlockNumber >= BigInt(blockNumber);
15
+ }, `Wait until L1 block ${blockNumber}`, timeout ?? MAX_WAIT_TIME_SECONDS, 0.1);
16
+ }
17
+ export function waitUntilL1Timestamp(client, timestamp, logger, timeout) {
18
+ const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
19
+ let lastBlock = undefined;
20
+ return retryUntil(async ()=>{
21
+ const currentBlockNumber = await publicClient.getBlockNumber({
22
+ cacheTime: 0
23
+ });
24
+ if (currentBlockNumber === lastBlock) {
25
+ return false;
26
+ }
27
+ lastBlock = currentBlockNumber;
28
+ const currentBlock = await publicClient.getBlock({
29
+ includeTransactions: false,
30
+ blockNumber: currentBlockNumber
31
+ });
32
+ const currentTs = currentBlock.timestamp;
33
+ logger?.debug(`Block timstamp is ${currentTs} (waiting until ${timestamp})`);
34
+ return currentTs >= BigInt(timestamp);
35
+ }, `Wait until L1 timestamp ${timestamp}`, timeout ?? MAX_WAIT_TIME_SECONDS, 0.1);
36
+ }
37
+ /** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */ export class Delayer {
38
+ dateProvider;
39
+ logger;
40
+ maxInclusionTimeIntoSlot;
41
+ ethereumSlotDuration;
42
+ nextWait;
43
+ sentTxHashes;
44
+ cancelledTxs;
45
+ constructor(dateProvider, opts, bindings){
46
+ this.dateProvider = dateProvider;
47
+ this.maxInclusionTimeIntoSlot = undefined;
48
+ this.nextWait = undefined;
49
+ this.sentTxHashes = [];
50
+ this.cancelledTxs = [];
51
+ this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
52
+ this.logger = createLogger('ethereum:tx_delayer', bindings);
53
+ }
54
+ /** Returns the logger instance used by this delayer. */ getLogger() {
55
+ return this.logger;
56
+ }
57
+ /** Returns the hashes of all effectively sent txs. */ getSentTxHashes() {
58
+ return this.sentTxHashes;
59
+ }
60
+ /** Returns the raw hex for all cancelled txs. */ getCancelledTxs() {
61
+ return this.cancelledTxs;
62
+ }
63
+ /** Delays the next tx to be sent so it lands on the given L1 block number. */ pauseNextTxUntilBlock(l1BlockNumber, timeoutSeconds) {
64
+ this.nextWait = {
65
+ l1BlockNumber: BigInt(l1BlockNumber),
66
+ timeoutSeconds
67
+ };
68
+ }
69
+ /** Delays the next tx to be sent so it lands on the given timestamp. */ pauseNextTxUntilTimestamp(l1Timestamp, timeoutSeconds) {
70
+ this.nextWait = {
71
+ l1Timestamp: BigInt(l1Timestamp),
72
+ timeoutSeconds
73
+ };
74
+ }
75
+ /** Delays the next tx to be sent indefinitely. */ cancelNextTx() {
76
+ this.nextWait = {
77
+ indefinitely: true
78
+ };
79
+ }
80
+ /**
81
+ * Sets max inclusion time into slot. If more than this many seconds have passed
82
+ * since the last L1 block was mined, then any tx will not be mined in the current
83
+ * L1 slot but will be deferred for the next one.
84
+ */ setMaxInclusionTimeIntoSlot(seconds) {
85
+ this.maxInclusionTimeIntoSlot = seconds;
86
+ }
87
+ }
88
+ /**
89
+ * Creates a new Delayer instance. Exposed so callers can create a single shared delayer
90
+ * and pass it to multiple `wrapClientWithDelayer` calls.
91
+ */ export function createDelayer(dateProvider, opts, bindings) {
92
+ return new Delayer(dateProvider, opts, bindings);
93
+ }
94
+ /** Tries to recover the sender address from a serialized signed transaction. */ async function tryRecoverSender(serializedTransaction) {
95
+ try {
96
+ return await recoverTransactionAddress({
97
+ serializedTransaction: serializedTransaction
98
+ });
99
+ } catch {
100
+ return undefined;
101
+ }
102
+ }
103
+ /**
104
+ * Wraps a viem client with tx delaying logic. Returns the wrapped client.
105
+ * The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
106
+ */ export function wrapClientWithDelayer(client, delayer) {
107
+ const logger = delayer.getLogger();
108
+ // Cast to ExtendedViemWalletClient for the extend chain since it has sendRawTransaction.
109
+ // The sendRawTransaction override is applied to all clients regardless of type.
110
+ const withRawTx = client// Tweak sendRawTransaction so it uses the delay defined in the delayer.
111
+ // Note that this will only work with local accounts (ie accounts for which we have the private key).
112
+ // Transactions signed by the node will not be delayed since they use sendTransaction directly,
113
+ // but we do not use them in our codebase at all.
114
+ .extend((client)=>({
115
+ async sendRawTransaction (...args) {
116
+ let wait;
117
+ let txHash;
118
+ const { serializedTransaction } = args[0];
119
+ const publicClient = client;
120
+ const sender = await tryRecoverSender(serializedTransaction);
121
+ if (delayer.nextWait !== undefined) {
122
+ // Check if we have been instructed to delay the next tx.
123
+ const waitUntil = delayer.nextWait;
124
+ delayer.nextWait = undefined;
125
+ // Compute the tx hash manually so we emulate sendRawTransaction response
126
+ txHash = computeTxHash(serializedTransaction);
127
+ // Cancel tx outright if instructed
128
+ if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
129
+ logger.info(`Cancelling tx ${txHash}`, {
130
+ sender
131
+ });
132
+ delayer.cancelledTxs.push(serializedTransaction);
133
+ return Promise.resolve(txHash);
134
+ }
135
+ // Or wait until the desired block number or timestamp
136
+ wait = 'l1BlockNumber' in waitUntil ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger, waitUntil.timeoutSeconds) : 'l1Timestamp' in waitUntil ? waitUntilL1Timestamp(publicClient, waitUntil.l1Timestamp - delayer.ethereumSlotDuration, logger, waitUntil.timeoutSeconds) : undefined;
137
+ logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
138
+ sender,
139
+ argsLen: args.length,
140
+ ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars')
141
+ });
142
+ } else if (delayer.maxInclusionTimeIntoSlot !== undefined) {
143
+ // Check if we need to delay txs sent too close to the end of the slot.
144
+ const currentBlock = await publicClient.getBlock({
145
+ includeTransactions: false
146
+ });
147
+ const { timestamp: lastBlockTimestamp, number } = currentBlock;
148
+ const now = delayer.dateProvider.now();
149
+ txHash = computeTxHash(serializedTransaction);
150
+ const logData = {
151
+ sender,
152
+ ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
153
+ lastBlockTimestamp,
154
+ now,
155
+ maxInclusionTimeIntoSlot: delayer.maxInclusionTimeIntoSlot
156
+ };
157
+ if (now / 1000 - Number(lastBlockTimestamp) > delayer.maxInclusionTimeIntoSlot) {
158
+ // If the last block was mined more than `maxInclusionTimeIntoSlot` seconds ago, then we cannot include
159
+ // any txs in the current slot, so we delay the tx until the next slot.
160
+ logger.info(`Delaying inclusion of tx ${txHash} until the next slot since it was sent too late`, logData);
161
+ wait = waitUntilBlock(publicClient, number + 1n, logger);
162
+ } else {
163
+ logger.debug(`Immediately sending tx ${txHash} as it was received early enough in the slot`, logData);
164
+ }
165
+ }
166
+ if (wait !== undefined) {
167
+ // Do not await here so we can return the tx hash immediately as if it had been sent on the spot.
168
+ // Instead, delay it so it lands on the desired block number or timestamp, assuming anvil will
169
+ // mine it immediately.
170
+ void wait.then(async ()=>{
171
+ const clientTxHash = await client.sendRawTransaction(...args);
172
+ if (clientTxHash !== txHash) {
173
+ logger.error(`Tx hash returned by the client does not match computed one`, {
174
+ clientTxHash,
175
+ computedTxHash: txHash
176
+ });
177
+ }
178
+ logger.info(`Sent previously delayed tx ${clientTxHash}`, {
179
+ sender
180
+ });
181
+ delayer.sentTxHashes.push(clientTxHash);
182
+ }).catch((err)=>logger.error(`Error sending tx after delay`, err));
183
+ return Promise.resolve(txHash);
184
+ } else {
185
+ const txHash = await client.sendRawTransaction(...args);
186
+ logger.debug(`Sent tx immediately ${txHash}`, {
187
+ sender
188
+ });
189
+ delayer.sentTxHashes.push(txHash);
190
+ return txHash;
191
+ }
192
+ }
193
+ }));
194
+ // Only re-bind wallet actions (sendTransaction, writeContract, deployContract) for wallet clients.
195
+ // This is needed for tests that use wallet actions directly rather than sendRawTransaction.
196
+ const isWalletClient = 'account' in client && client.account !== undefined;
197
+ const extended = isWalletClient ? withRawTx// Re-extend with sendTransaction so it uses the modified sendRawTransaction.
198
+ .extend((client)=>({
199
+ sendTransaction: walletActions(client).sendTransaction
200
+ }))// And with the actions that depend on the modified sendTransaction
201
+ .extend((client)=>({
202
+ writeContract: walletActions(client).writeContract,
203
+ deployContract: walletActions(client).deployContract
204
+ })) : withRawTx;
205
+ return extended;
206
+ }
207
+ /**
208
+ * Compute the tx hash given the serialized tx. Note that if this is a blob tx, we need to
209
+ * exclude the blobs, commitments, and proofs from the hash.
210
+ */ function computeTxHash(serializedTransaction) {
211
+ if (serializedTransaction.startsWith('0x03')) {
212
+ const parsed = parseTransaction(serializedTransaction);
213
+ if (parsed.blobs || parsed.sidecars) {
214
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
215
+ const { blobs, sidecars, ...rest } = parsed;
216
+ return keccak256(serializeTransaction({
217
+ type: 'eip4844',
218
+ ...rest
219
+ }));
220
+ }
221
+ }
222
+ return keccak256(serializedTransaction);
223
+ }
@@ -0,0 +1,67 @@
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { ViemTransactionSignature } from '@aztec/foundation/eth-signature';
4
+ import type { Abi, Address, Hex, TransactionReceipt, TransactionSerializable } from 'viem';
5
+ import type { L1TxUtilsConfig } from './config.js';
6
+ export interface L1TxRequest {
7
+ to: Address | null;
8
+ data?: Hex;
9
+ value?: bigint;
10
+ abi?: Abi;
11
+ }
12
+ export type L1TxConfig = Partial<L1TxUtilsConfig> & {
13
+ gasLimit?: bigint;
14
+ txTimeoutAt?: Date;
15
+ };
16
+ export interface L1BlobInputs {
17
+ blobs: Uint8Array[];
18
+ kzg: BlobKzgInstance;
19
+ maxFeePerBlobGas?: bigint;
20
+ }
21
+ export interface GasPrice {
22
+ maxFeePerGas: bigint;
23
+ maxPriorityFeePerGas: bigint;
24
+ maxFeePerBlobGas?: bigint;
25
+ }
26
+ export type TransactionStats = {
27
+ /** Address of the sender. */
28
+ sender: string;
29
+ /** Hash of the transaction. */
30
+ transactionHash: string;
31
+ /** Size in bytes of the tx calldata */
32
+ calldataSize: number;
33
+ /** Gas required to pay for the calldata inclusion (depends on size and number of zeros) */
34
+ calldataGas: number;
35
+ };
36
+ export declare enum TxUtilsState {
37
+ IDLE = 0,
38
+ SENT = 1,
39
+ SPEED_UP = 2,
40
+ CANCELLED = 3,
41
+ NOT_MINED = 4,
42
+ MINED = 5
43
+ }
44
+ export declare const TerminalTxUtilsState: TxUtilsState[];
45
+ export type L1TxState = {
46
+ id: number;
47
+ txHashes: Hex[];
48
+ cancelTxHashes: Hex[];
49
+ gasLimit: bigint;
50
+ gasPrice: GasPrice;
51
+ txConfigOverrides: L1TxConfig;
52
+ request: L1TxRequest;
53
+ status: TxUtilsState;
54
+ nonce: number;
55
+ sentAtL1Ts: Date;
56
+ lastSentAtL1Ts: Date;
57
+ receipt?: TransactionReceipt;
58
+ blobInputs: L1BlobInputs | undefined;
59
+ };
60
+ export type SigningCallback = (transaction: TransactionSerializable, signingAddress: EthAddress) => Promise<ViemTransactionSignature>;
61
+ export declare class UnknownMinedTxError extends Error {
62
+ constructor(nonce: number, account: string);
63
+ }
64
+ export declare class DroppedTransactionError extends Error {
65
+ constructor(nonce: number, account: string);
66
+ }
67
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxlQUFlLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUM3RCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDM0QsT0FBTyxLQUFLLEVBQUUsd0JBQXdCLEVBQU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2
+ TxUtilsState[TxUtilsState["IDLE"] = 0] = "IDLE";
3
+ TxUtilsState[TxUtilsState["SENT"] = 1] = "SENT";
4
+ TxUtilsState[TxUtilsState["SPEED_UP"] = 2] = "SPEED_UP";
5
+ TxUtilsState[TxUtilsState["CANCELLED"] = 3] = "CANCELLED";
6
+ TxUtilsState[TxUtilsState["NOT_MINED"] = 4] = "NOT_MINED";
7
+ TxUtilsState[TxUtilsState["MINED"] = 5] = "MINED";
8
+ return TxUtilsState;
9
+ }({});
10
+ export const TerminalTxUtilsState = [
11
+ 0,
12
+ 5,
13
+ 4
14
+ ];
15
+ export class UnknownMinedTxError extends Error {
16
+ constructor(nonce, account){
17
+ super(`Nonce ${nonce} from account ${account} is MINED but not by one of our expected transactions`);
18
+ this.name = 'UnknownMinedTxError';
19
+ }
20
+ }
21
+ export class DroppedTransactionError extends Error {
22
+ constructor(nonce, account){
23
+ super(`Transaction with nonce ${nonce} from account ${account} was dropped from the mempool`);
24
+ this.name = 'DroppedTransactionError';
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ import type { ContractFunctionExecutionError } from 'viem';
2
+ export declare function tryGetCustomErrorNameContractFunction(err: ContractFunctionExecutionError): string;
3
+ export declare function getCalldataGasUsage(data: Uint8Array): number;
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy91dGlscy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSw4QkFBOEIsRUFBRSxNQUFNLE1BQU0sQ0FBQztBQUUzRCx3QkFBZ0IscUNBQXFDLENBQUMsR0FBRyxFQUFFLDhCQUE4QixVQUV4RjtBQU9ELHdCQUFnQixtQkFBbUIsQ0FBQyxJQUFJLEVBQUUsVUFBVSxVQUVuRCJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,MAAM,CAAC;AAE3D,wBAAgB,qCAAqC,CAAC,GAAG,EAAE,8BAA8B,UAExF;AAOD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,UAEnD"}
@@ -0,0 +1,14 @@
1
+ import { compactArray } from '@aztec/foundation/collection';
2
+ export function tryGetCustomErrorNameContractFunction(err) {
3
+ return compactArray([
4
+ err.shortMessage,
5
+ ...(err.metaMessages ?? []).slice(0, 2).map((s)=>s.trim())
6
+ ]).join(' ');
7
+ }
8
+ /*
9
+ * Returns cost of calldata usage in Ethereum.
10
+ * @param data - Calldata.
11
+ * @returns 4 for each zero byte, 16 for each nonzero.
12
+ */ export function getCalldataGasUsage(data) {
13
+ return data.filter((byte)=>byte === 0).length * 4 + data.filter((byte)=>byte !== 0).length * 16;
14
+ }
@@ -0,0 +1,6 @@
1
+ import type { Buffer32 } from '@aztec/foundation/buffer';
2
+ export type L1BlockId = {
3
+ l1BlockNumber: bigint;
4
+ l1BlockHash: Buffer32;
5
+ };
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibDFfdHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9sMV90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxRQUFRLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUV6RCxNQUFNLE1BQU0sU0FBUyxHQUFHO0lBQ3RCLGFBQWEsRUFBRSxNQUFNLENBQUM7SUFDdEIsV0FBVyxFQUFFLFFBQVEsQ0FBQztDQUN2QixDQUFDIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"l1_types.d.ts","sourceRoot":"","sources":["../src/l1_types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,MAAM,SAAS,GAAG;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,QAAQ,CAAC;CACvB,CAAC"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,30 @@
1
+ import { type LoggerBindings } from '@aztec/foundation/log';
2
+ import { L1TxUtils } from './l1_tx_utils/index.js';
3
+ export type PublisherFilter<UtilsType extends L1TxUtils> = (utils: UtilsType) => boolean;
4
+ /** Config accepted by PublisherManager. */
5
+ type PublisherManagerConfig = {
6
+ publisherAllowInvalidStates?: boolean;
7
+ publisherFundingThreshold?: bigint;
8
+ publisherFundingAmount?: bigint;
9
+ };
10
+ export declare class PublisherManager<UtilsType extends L1TxUtils = L1TxUtils> {
11
+ private publishers;
12
+ private log;
13
+ private config;
14
+ private static readonly FUNDING_CHECK_INTERVAL_MS;
15
+ private funder?;
16
+ private fundingPromise?;
17
+ constructor(publishers: UtilsType[], config: PublisherManagerConfig, opts?: {
18
+ bindings?: LoggerBindings;
19
+ funder?: UtilsType;
20
+ });
21
+ /** Loads the state of all publishers and the funder, and starts periodic funding checks. */
22
+ start(): Promise<void>;
23
+ /** Stops the funding loop and interrupts all publishers. */
24
+ stop(): Promise<void>;
25
+ getAvailablePublisher(filter?: PublisherFilter<UtilsType>): Promise<UtilsType>;
26
+ private triggerFundingIfNeeded;
27
+ private fundPublishers;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGlzaGVyX21hbmFnZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9wdWJsaXNoZXJfbWFuYWdlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQWUsS0FBSyxjQUFjLEVBQWdCLE1BQU0sdUJBQXVCLENB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AC,MAAM,GAAE,eAAe,CAAC,SAAS,CAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CA+CtG;YAGa,sBAAsB;YAqCtB,cAAc;CAU7B"}
@@ -0,0 +1,162 @@
1
+ import { pick } from '@aztec/foundation/collection';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { RunningPromise } from '@aztec/foundation/running-promise';
4
+ import { Multicall3 } from './contracts/multicall.js';
5
+ import { TxUtilsState } from './l1_tx_utils/index.js';
6
+ // Defines the order in which we prioritise publishers based on their state (first is better)
7
+ const sortOrder = [
8
+ // Always prefer sending from idle publishers
9
+ TxUtilsState.IDLE,
10
+ // Then from publishers that have sent a tx and it got mined
11
+ TxUtilsState.MINED,
12
+ // Then from publishers that have sent a tx but it's in-flight
13
+ TxUtilsState.SPEED_UP,
14
+ TxUtilsState.SENT,
15
+ // We leave cancelled and not-mined states for last, since these represent failures to mines and could be problematic
16
+ TxUtilsState.CANCELLED,
17
+ TxUtilsState.NOT_MINED
18
+ ];
19
+ // Which states represent a busy publisher that we should avoid if possible
20
+ const busyStates = [
21
+ TxUtilsState.SENT,
22
+ TxUtilsState.SPEED_UP,
23
+ TxUtilsState.CANCELLED,
24
+ TxUtilsState.NOT_MINED
25
+ ];
26
+ export class PublisherManager {
27
+ publishers;
28
+ log;
29
+ config;
30
+ static FUNDING_CHECK_INTERVAL_MS = 2 * 60 * 1000;
31
+ funder;
32
+ fundingPromise;
33
+ constructor(publishers, config, opts){
34
+ this.publishers = publishers;
35
+ this.funder = opts?.funder;
36
+ this.log = createLogger('publisher:manager', opts?.bindings);
37
+ this.log.info(`PublisherManager initialized with ${publishers.length} publishers.`);
38
+ this.publishers = publishers;
39
+ this.config = pick(config, 'publisherAllowInvalidStates', 'publisherFundingThreshold', 'publisherFundingAmount');
40
+ const hasThreshold = this.config.publisherFundingThreshold !== undefined;
41
+ const hasAmount = this.config.publisherFundingAmount !== undefined;
42
+ if (hasThreshold !== hasAmount) {
43
+ this.log.warn(`Incomplete funding config: both publisherFundingThreshold and publisherFundingAmount must be set`);
44
+ }
45
+ if (this.funder) {
46
+ const funderAddress = this.funder.getSenderAddress();
47
+ if (publishers.some((p)=>p.getSenderAddress().equals(funderAddress))) {
48
+ this.log.error(`Funding account ${funderAddress} is also a publisher, disabling funding to avoid self-funding`);
49
+ this.funder = undefined;
50
+ }
51
+ }
52
+ }
53
+ /** Loads the state of all publishers and the funder, and starts periodic funding checks. */ async start() {
54
+ await Promise.all([
55
+ ...this.publishers.map((pub)=>pub.loadStateAndResumeMonitoring()),
56
+ this.funder?.loadStateAndResumeMonitoring()
57
+ ]);
58
+ if (this.funder && this.config.publisherFundingThreshold !== undefined && this.config.publisherFundingAmount !== undefined) {
59
+ this.fundingPromise = new RunningPromise(()=>this.triggerFundingIfNeeded(), this.log, PublisherManager.FUNDING_CHECK_INTERVAL_MS);
60
+ this.fundingPromise.start();
61
+ }
62
+ }
63
+ /** Stops the funding loop and interrupts all publishers. */ async stop() {
64
+ await this.fundingPromise?.stop();
65
+ this.publishers.forEach((pub)=>pub.interrupt());
66
+ this.funder?.interrupt();
67
+ }
68
+ // Finds and prioritises available publishers based on
69
+ // 1. Validity as per the provided filter function
70
+ // 2. Validity based on the state the publisher is in
71
+ // 3. Priority based on state as defined by sortOrder
72
+ // 4. Then priority based on highest balance
73
+ // 5. Then priority based on least recently used
74
+ async getAvailablePublisher(filter = ()=>true) {
75
+ this.log.debug(`Getting available publisher`, {
76
+ publishers: this.publishers.map((p)=>({
77
+ address: p.getSenderAddress(),
78
+ state: p.state,
79
+ lastMined: p.lastMinedAtBlockNumber
80
+ }))
81
+ });
82
+ // Extract the valid publishers
83
+ let validPublishers = this.publishers.filter((pub)=>!busyStates.includes(pub.state) && filter(pub));
84
+ // If none found but we allow invalid (busy) states, try again including them
85
+ if (validPublishers.length === 0 && this.config.publisherAllowInvalidStates) {
86
+ this.log.warn(`No valid publishers found. Trying again including invalid states.`);
87
+ validPublishers = this.publishers.filter((pub)=>filter(pub));
88
+ }
89
+ // Error if none found
90
+ if (validPublishers.length === 0) {
91
+ throw new Error(`Failed to find an available publisher.`);
92
+ }
93
+ // Get the balances
94
+ const publishersWithBalance = await Promise.all(validPublishers.map(async (pub)=>{
95
+ return {
96
+ balance: await pub.getSenderBalance(),
97
+ publisher: pub
98
+ };
99
+ }));
100
+ // Sort based on state, then balance, then time since last use
101
+ const sortedPublishers = publishersWithBalance.sort((a, b)=>{
102
+ const stateComparison = sortOrder.indexOf(a.publisher.state) - sortOrder.indexOf(b.publisher.state);
103
+ if (stateComparison !== 0) {
104
+ return stateComparison;
105
+ }
106
+ const balanceComparison = Number(b.balance - a.balance);
107
+ if (balanceComparison !== 0) {
108
+ return balanceComparison;
109
+ }
110
+ const lastUsedComparison = Number((a.publisher.lastMinedAtBlockNumber ?? 0n) - (b.publisher.lastMinedAtBlockNumber ?? 0n));
111
+ return lastUsedComparison;
112
+ });
113
+ return sortedPublishers[0].publisher;
114
+ }
115
+ /** Check all publisher balances and fund those below threshold. */ async triggerFundingIfNeeded() {
116
+ const { funder, config } = this;
117
+ if (!funder || config.publisherFundingThreshold === undefined || config.publisherFundingAmount === undefined) {
118
+ return;
119
+ }
120
+ const allBalances = await Promise.all(this.publishers.map(async (pub)=>({
121
+ balance: await pub.getSenderBalance(),
122
+ publisher: pub
123
+ })));
124
+ const lowBalance = allBalances.filter((p)=>p.balance < config.publisherFundingThreshold);
125
+ if (lowBalance.length === 0) {
126
+ return;
127
+ }
128
+ const fundingAmount = config.publisherFundingAmount;
129
+ const funderBalance = await funder.getSenderBalance();
130
+ if (funderBalance < 10n * fundingAmount) {
131
+ this.log.warn(`Funding account balance is low`, {
132
+ funderBalance,
133
+ threshold: 10n * fundingAmount
134
+ });
135
+ }
136
+ const affordableCount = Number(funderBalance / fundingAmount);
137
+ if (affordableCount === 0) {
138
+ this.log.error(`Funding account balance too low to fund any publisher`, {
139
+ funderBalance,
140
+ fundingAmount
141
+ });
142
+ return;
143
+ }
144
+ if (affordableCount < lowBalance.length) {
145
+ this.log.warn(`Funder can only afford ${affordableCount}/${lowBalance.length} publishers`, {
146
+ funderBalance,
147
+ fundingAmount
148
+ });
149
+ }
150
+ const toFund = lowBalance.slice(0, affordableCount).map((p)=>p.publisher);
151
+ await this.fundPublishers(toFund);
152
+ }
153
+ /** Fund publishers via a single Multicall3 aggregate3Value transaction. */ async fundPublishers(publishers) {
154
+ const fundingAmount = this.config.publisherFundingAmount;
155
+ const calls = publishers.map((pub)=>({
156
+ to: pub.getSenderAddress().toString(),
157
+ value: fundingAmount
158
+ }));
159
+ await Multicall3.forwardValue(calls, this.funder, this.log);
160
+ this.log.info(`Funded ${publishers.length} publishers`);
161
+ }
162
+ }
package/dest/queries.d.ts CHANGED
@@ -1,6 +1,17 @@
1
- import type { EthAddress } from '@aztec/foundation/eth-address';
2
- import type { L1ContractsConfig } from './config.js';
3
- import type { ViemPublicClient } from './types.js';
1
+ import { EthAddress } from '@aztec/foundation/eth-address';
2
+ import { type Block } from 'viem';
3
+ import { type L1ContractsConfig } from './config.js';
4
+ import type { ViemClient, ViemPublicClient } from './types.js';
5
+ /**
6
+ * Returns the L1 finalized block, or `undefined` if the chain does not yet have one
7
+ * (common on freshly started devnets). Rethrows any other RPC error.
8
+ */
9
+ export declare function getFinalizedL1Block(client: ViemClient): Promise<Block<bigint, false, 'finalized'> | undefined>;
10
+ /**
11
+ * Returns true if the error originates from an RPC call that failed because
12
+ * the "finalized" (or "safe") block tag is not yet available on the chain.
13
+ */
14
+ export declare function isFinalizedBlockTagNotFoundError(err: unknown): boolean;
4
15
  /** Reads the L1ContractsConfig from L1 contracts. */
5
16
  export declare function getL1ContractsConfig(publicClient: ViemPublicClient, addresses: {
6
17
  governanceAddress: EthAddress;
@@ -8,5 +19,7 @@ export declare function getL1ContractsConfig(publicClient: ViemPublicClient, add
8
19
  }): Promise<Omit<L1ContractsConfig, 'ethereumSlotDuration'> & {
9
20
  l1StartBlock: bigint;
10
21
  l1GenesisTime: bigint;
22
+ rollupVersion: number;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LGFBQWEsRUFBRSxNQUFNLENBQUM7SUFDdEIsYUFBYSxFQUFFLE1BQU0sQ0FBQztJQUN0QixzQkFBc0IsRUFBRSxLQUFLLE1BQU0sRUFBRSxDQUFDO0NBQ3ZDLENBQ0YsQ0F1R0EifQ==
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,qDAAqD;AACrD,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,gBAAgB,EAC9B,SAAS,EAAE;IAAE,iBAAiB,EAAE,UAAU,CAAC;IAAC,aAAa,CAAC,EAAE,UAAU,CAAA;CAAE,GACvE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CA8C5G"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAa,KAAK,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7C,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAK/E,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,SAAS,CAAC,CASpH;AAmBD;;;GAGG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,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