@aztec-labs/ethereum 6.0.0-nightly.20260829

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 (272) hide show
  1. package/README.md +3 -0
  2. package/dest/account.d.ts +2 -0
  3. package/dest/account.d.ts.map +1 -0
  4. package/dest/account.js +4 -0
  5. package/dest/chain.d.ts +25 -0
  6. package/dest/chain.d.ts.map +1 -0
  7. package/dest/chain.js +53 -0
  8. package/dest/client.d.ts +42 -0
  9. package/dest/client.d.ts.map +1 -0
  10. package/dest/client.js +104 -0
  11. package/dest/config.d.ts +103 -0
  12. package/dest/config.d.ts.map +1 -0
  13. package/dest/config.js +233 -0
  14. package/dest/constants.d.ts +4 -0
  15. package/dest/constants.d.ts.map +1 -0
  16. package/dest/constants.js +2 -0
  17. package/dest/contracts/chain_state_override.d.ts +81 -0
  18. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  19. package/dest/contracts/chain_state_override.js +139 -0
  20. package/dest/contracts/empire_base.d.ts +30 -0
  21. package/dest/contracts/empire_base.d.ts.map +1 -0
  22. package/dest/contracts/empire_base.js +84 -0
  23. package/dest/contracts/errors.d.ts +7 -0
  24. package/dest/contracts/errors.d.ts.map +1 -0
  25. package/dest/contracts/errors.js +12 -0
  26. package/dest/contracts/fee_asset_handler.d.ts +20 -0
  27. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  28. package/dest/contracts/fee_asset_handler.js +59 -0
  29. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  30. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  31. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  32. package/dest/contracts/fee_juice.d.ts +14 -0
  33. package/dest/contracts/fee_juice.d.ts.map +1 -0
  34. package/dest/contracts/fee_juice.js +59 -0
  35. package/dest/contracts/governance.d.ts +192 -0
  36. package/dest/contracts/governance.d.ts.map +1 -0
  37. package/dest/contracts/governance.js +471 -0
  38. package/dest/contracts/governance_proposer.d.ts +63 -0
  39. package/dest/contracts/governance_proposer.d.ts.map +1 -0
  40. package/dest/contracts/governance_proposer.js +536 -0
  41. package/dest/contracts/gse.d.ts +38 -0
  42. package/dest/contracts/gse.d.ts.map +1 -0
  43. package/dest/contracts/gse.js +81 -0
  44. package/dest/contracts/inbox.d.ts +94 -0
  45. package/dest/contracts/inbox.d.ts.map +1 -0
  46. package/dest/contracts/inbox.js +141 -0
  47. package/dest/contracts/index.d.ts +18 -0
  48. package/dest/contracts/index.d.ts.map +1 -0
  49. package/dest/contracts/index.js +17 -0
  50. package/dest/contracts/log.d.ts +13 -0
  51. package/dest/contracts/log.d.ts.map +1 -0
  52. package/dest/contracts/log.js +1 -0
  53. package/dest/contracts/multicall.d.ts +138 -0
  54. package/dest/contracts/multicall.d.ts.map +1 -0
  55. package/dest/contracts/multicall.js +266 -0
  56. package/dest/contracts/outbox.d.ts +64 -0
  57. package/dest/contracts/outbox.d.ts.map +1 -0
  58. package/dest/contracts/outbox.js +113 -0
  59. package/dest/contracts/registry.d.ts +31 -0
  60. package/dest/contracts/registry.d.ts.map +1 -0
  61. package/dest/contracts/registry.js +142 -0
  62. package/dest/contracts/rollup.d.ts +5836 -0
  63. package/dest/contracts/rollup.d.ts.map +1 -0
  64. package/dest/contracts/rollup.js +1612 -0
  65. package/dest/contracts/slasher_contract.d.ts +44 -0
  66. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  67. package/dest/contracts/slasher_contract.js +75 -0
  68. package/dest/contracts/slashing_proposer.d.ts +174 -0
  69. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  70. package/dest/contracts/slashing_proposer.js +755 -0
  71. package/dest/contracts/utils.d.ts +3 -0
  72. package/dest/contracts/utils.d.ts.map +1 -0
  73. package/dest/contracts/utils.js +11 -0
  74. package/dest/contracts/watch_event.d.ts +36 -0
  75. package/dest/contracts/watch_event.d.ts.map +1 -0
  76. package/dest/contracts/watch_event.js +66 -0
  77. package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
  78. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  79. package/dest/deploy_aztec_l1_contracts.js +424 -0
  80. package/dest/deploy_l1_contract.d.ts +68 -0
  81. package/dest/deploy_l1_contract.d.ts.map +1 -0
  82. package/dest/deploy_l1_contract.js +312 -0
  83. package/dest/eth-signer/eth-signer.d.ts +21 -0
  84. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  85. package/dest/eth-signer/eth-signer.js +5 -0
  86. package/dest/eth-signer/index.d.ts +2 -0
  87. package/dest/eth-signer/index.d.ts.map +1 -0
  88. package/dest/eth-signer/index.js +1 -0
  89. package/dest/forwarder_proxy.d.ts +32 -0
  90. package/dest/forwarder_proxy.d.ts.map +1 -0
  91. package/dest/forwarder_proxy.js +93 -0
  92. package/dest/foundry_binary.d.ts +13 -0
  93. package/dest/foundry_binary.d.ts.map +1 -0
  94. package/dest/foundry_binary.js +52 -0
  95. package/dest/l1_artifacts.d.ts +81896 -0
  96. package/dest/l1_artifacts.d.ts.map +1 -0
  97. package/dest/l1_artifacts.js +151 -0
  98. package/dest/l1_contract_addresses.d.ts +73 -0
  99. package/dest/l1_contract_addresses.d.ts.map +1 -0
  100. package/dest/l1_contract_addresses.js +120 -0
  101. package/dest/l1_reader.d.ts +18 -0
  102. package/dest/l1_reader.d.ts.map +1 -0
  103. package/dest/l1_reader.js +35 -0
  104. package/dest/l1_tx_utils/config.d.ts +65 -0
  105. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  106. package/dest/l1_tx_utils/config.js +109 -0
  107. package/dest/l1_tx_utils/constants.d.ts +12 -0
  108. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  109. package/dest/l1_tx_utils/constants.js +39 -0
  110. package/dest/l1_tx_utils/factory.d.ts +32 -0
  111. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  112. package/dest/l1_tx_utils/factory.js +22 -0
  113. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  114. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  115. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  116. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  117. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  118. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  119. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  120. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  121. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  122. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  123. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  124. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  125. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  126. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  127. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  128. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  129. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  130. package/dest/l1_tx_utils/index-blobs.js +2 -0
  131. package/dest/l1_tx_utils/index.d.ts +13 -0
  132. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  133. package/dest/l1_tx_utils/index.js +13 -0
  134. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  135. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  136. package/dest/l1_tx_utils/interfaces.js +4 -0
  137. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
  138. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  139. package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
  140. package/dest/l1_tx_utils/l1_tx_utils.d.ts +113 -0
  141. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  142. package/dest/l1_tx_utils/l1_tx_utils.js +720 -0
  143. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
  144. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  145. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +357 -0
  146. package/dest/l1_tx_utils/signer.d.ts +4 -0
  147. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  148. package/dest/l1_tx_utils/signer.js +16 -0
  149. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  150. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  151. package/dest/l1_tx_utils/tx_delayer.js +223 -0
  152. package/dest/l1_tx_utils/types.d.ts +93 -0
  153. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  154. package/dest/l1_tx_utils/types.js +36 -0
  155. package/dest/l1_tx_utils/utils.d.ts +4 -0
  156. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  157. package/dest/l1_tx_utils/utils.js +14 -0
  158. package/dest/l1_types.d.ts +6 -0
  159. package/dest/l1_types.d.ts.map +1 -0
  160. package/dest/l1_types.js +1 -0
  161. package/dest/publisher_manager.d.ts +42 -0
  162. package/dest/publisher_manager.d.ts.map +1 -0
  163. package/dest/publisher_manager.js +199 -0
  164. package/dest/queries.d.ts +25 -0
  165. package/dest/queries.d.ts.map +1 -0
  166. package/dest/queries.js +144 -0
  167. package/dest/test/blob_kzg_warmup.d.ts +19 -0
  168. package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
  169. package/dest/test/blob_kzg_warmup.js +64 -0
  170. package/dest/test/chain_monitor.d.ts +126 -0
  171. package/dest/test/chain_monitor.d.ts.map +1 -0
  172. package/dest/test/chain_monitor.js +314 -0
  173. package/dest/test/eth_cheat_codes.d.ts +260 -0
  174. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  175. package/dest/test/eth_cheat_codes.js +608 -0
  176. package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
  177. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
  178. package/dest/test/eth_cheat_codes_with_state.js +34 -0
  179. package/dest/test/index.d.ts +8 -0
  180. package/dest/test/index.d.ts.map +1 -0
  181. package/dest/test/index.js +7 -0
  182. package/dest/test/recording_rpc_server.d.ts +18 -0
  183. package/dest/test/recording_rpc_server.d.ts.map +1 -0
  184. package/dest/test/recording_rpc_server.js +68 -0
  185. package/dest/test/rollup_cheat_codes.d.ts +142 -0
  186. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  187. package/dest/test/rollup_cheat_codes.js +338 -0
  188. package/dest/test/start_anvil.d.ts +40 -0
  189. package/dest/test/start_anvil.d.ts.map +1 -0
  190. package/dest/test/start_anvil.js +210 -0
  191. package/dest/test/upgrade_utils.d.ts +12 -0
  192. package/dest/test/upgrade_utils.d.ts.map +1 -0
  193. package/dest/test/upgrade_utils.js +111 -0
  194. package/dest/types.d.ts +68 -0
  195. package/dest/types.d.ts.map +1 -0
  196. package/dest/types.js +3 -0
  197. package/dest/utils.d.ts +45 -0
  198. package/dest/utils.d.ts.map +1 -0
  199. package/dest/utils.js +260 -0
  200. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  201. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  202. package/dest/zkPassportVerifierAddress.js +11 -0
  203. package/package.json +122 -0
  204. package/src/account.ts +5 -0
  205. package/src/chain.ts +71 -0
  206. package/src/client.ts +165 -0
  207. package/src/config.ts +342 -0
  208. package/src/constants.ts +4 -0
  209. package/src/contracts/README.md +157 -0
  210. package/src/contracts/chain_state_override.ts +203 -0
  211. package/src/contracts/empire_base.ts +89 -0
  212. package/src/contracts/errors.ts +13 -0
  213. package/src/contracts/fee_asset_handler.ts +66 -0
  214. package/src/contracts/fee_asset_price_oracle.ts +284 -0
  215. package/src/contracts/fee_juice.ts +57 -0
  216. package/src/contracts/governance.ts +597 -0
  217. package/src/contracts/governance_proposer.ts +181 -0
  218. package/src/contracts/gse.ts +105 -0
  219. package/src/contracts/inbox.ts +223 -0
  220. package/src/contracts/index.ts +17 -0
  221. package/src/contracts/log.ts +13 -0
  222. package/src/contracts/multicall.ts +298 -0
  223. package/src/contracts/outbox.ts +132 -0
  224. package/src/contracts/registry.ts +161 -0
  225. package/src/contracts/rollup.ts +1502 -0
  226. package/src/contracts/slasher_contract.ts +89 -0
  227. package/src/contracts/slashing_proposer.ts +397 -0
  228. package/src/contracts/utils.ts +14 -0
  229. package/src/contracts/watch_event.ts +109 -0
  230. package/src/deploy_aztec_l1_contracts.ts +663 -0
  231. package/src/deploy_l1_contract.ts +361 -0
  232. package/src/eth-signer/eth-signer.ts +24 -0
  233. package/src/eth-signer/index.ts +1 -0
  234. package/src/forwarder_proxy.ts +107 -0
  235. package/src/foundry_binary.ts +57 -0
  236. package/src/l1_artifacts.ts +231 -0
  237. package/src/l1_contract_addresses.ts +149 -0
  238. package/src/l1_reader.ts +57 -0
  239. package/src/l1_tx_utils/README.md +177 -0
  240. package/src/l1_tx_utils/config.ts +181 -0
  241. package/src/l1_tx_utils/constants.ts +29 -0
  242. package/src/l1_tx_utils/factory.ts +64 -0
  243. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  244. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +162 -0
  245. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +244 -0
  246. package/src/l1_tx_utils/fee-strategies/types.ts +55 -0
  247. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +107 -0
  248. package/src/l1_tx_utils/index-blobs.ts +2 -0
  249. package/src/l1_tx_utils/index.ts +15 -0
  250. package/src/l1_tx_utils/interfaces.ts +86 -0
  251. package/src/l1_tx_utils/l1_fee_analyzer.ts +874 -0
  252. package/src/l1_tx_utils/l1_tx_utils.ts +840 -0
  253. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +459 -0
  254. package/src/l1_tx_utils/signer.ts +27 -0
  255. package/src/l1_tx_utils/tx_delayer.ts +302 -0
  256. package/src/l1_tx_utils/types.ts +116 -0
  257. package/src/l1_tx_utils/utils.ts +15 -0
  258. package/src/l1_types.ts +6 -0
  259. package/src/publisher_manager.ts +239 -0
  260. package/src/queries.ts +189 -0
  261. package/src/test/blob_kzg_warmup.ts +65 -0
  262. package/src/test/chain_monitor.ts +389 -0
  263. package/src/test/eth_cheat_codes.ts +624 -0
  264. package/src/test/eth_cheat_codes_with_state.ts +38 -0
  265. package/src/test/index.ts +7 -0
  266. package/src/test/recording_rpc_server.ts +69 -0
  267. package/src/test/rollup_cheat_codes.ts +398 -0
  268. package/src/test/start_anvil.ts +255 -0
  269. package/src/test/upgrade_utils.ts +109 -0
  270. package/src/types.ts +97 -0
  271. package/src/utils.ts +344 -0
  272. package/src/zkPassportVerifierAddress.ts +15 -0
@@ -0,0 +1,1612 @@
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
372
+ }
373
+ var _initProto;
374
+ import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
375
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
376
+ import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
377
+ import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec-labs/foundation/branded-types';
378
+ import { Buffer32 } from '@aztec-labs/foundation/buffer';
379
+ import { Fr } from '@aztec-labs/foundation/curves/bn254';
380
+ import { memoize } from '@aztec-labs/foundation/decorators';
381
+ import { EthAddress } from '@aztec-labs/foundation/eth-address';
382
+ import { createLogger } from '@aztec-labs/foundation/log';
383
+ import { makeBackoff, retry } from '@aztec-labs/foundation/retry';
384
+ import { getErrorCause } from '@aztec-labs/foundation/types';
385
+ import chunk from 'lodash.chunk';
386
+ import { ContractFunctionRevertedError, RpcRequestError, decodeErrorResult, encodeAbiParameters, encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
387
+ import { getPublicClient } from '../client.js';
388
+ import { formatViemError } from '../utils.js';
389
+ import { GSEContract } from './gse.js';
390
+ import { SlasherContract } from './slasher_contract.js';
391
+ import { SlashingProposerContract } from './slashing_proposer.js';
392
+ import { checkBlockTag } from './utils.js';
393
+ import { watchContractEvent } from './watch_event.js';
394
+ /**
395
+ * Status of a validator/attester in the staking system.
396
+ * Matches the Status enum in StakingLib.sol
397
+ */ export var AttesterStatus = /*#__PURE__*/ function(AttesterStatus) {
398
+ AttesterStatus[AttesterStatus["NONE"] = 0] = "NONE";
399
+ AttesterStatus[AttesterStatus["VALIDATING"] = 1] = "VALIDATING";
400
+ AttesterStatus[AttesterStatus["ZOMBIE"] = 2] = "ZOMBIE";
401
+ AttesterStatus[AttesterStatus["EXITING"] = 3] = "EXITING";
402
+ return AttesterStatus;
403
+ }({});
404
+ /**
405
+ * Field offsets within the CompressedTempCheckpointLog struct in Solidity storage. The `SlotNumber`
406
+ * word also packs the inbox consumption counts, which Solidity places in the same slot.
407
+ */ export var TempCheckpointLogField = /*#__PURE__*/ function(TempCheckpointLogField) {
408
+ TempCheckpointLogField[TempCheckpointLogField["HeaderHash"] = 0] = "HeaderHash";
409
+ TempCheckpointLogField[TempCheckpointLogField["BlobCommitmentsHash"] = 1] = "BlobCommitmentsHash";
410
+ TempCheckpointLogField[TempCheckpointLogField["OutHash"] = 2] = "OutHash";
411
+ TempCheckpointLogField[TempCheckpointLogField["AttestationsHash"] = 3] = "AttestationsHash";
412
+ TempCheckpointLogField[TempCheckpointLogField["PayloadDigest"] = 4] = "PayloadDigest";
413
+ TempCheckpointLogField[TempCheckpointLogField["SlotNumber"] = 5] = "SlotNumber";
414
+ TempCheckpointLogField[TempCheckpointLogField["FeeHeader"] = 6] = "FeeHeader";
415
+ TempCheckpointLogField[TempCheckpointLogField["InboxRollingHash"] = 7] = "InboxRollingHash";
416
+ return TempCheckpointLogField;
417
+ }({});
418
+ const INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR = 'ValidatorSelection__InsufficientValidatorSetSize';
419
+ /** SlasherUpdated events are rare governance operations, so their watcher polls well below the client's interval. */ const SLASHER_UPDATED_POLLING_INTERVAL_MS = 60_000;
420
+ function isValidatorSelectionError(err, errorName) {
421
+ return getErrorCause(err, ContractFunctionRevertedError)?.data?.errorName === errorName || decodeRpcRequestErrorName(err) === errorName;
422
+ }
423
+ function decodeRpcRequestErrorName(err) {
424
+ const data = getErrorCause(err, RpcRequestError)?.data;
425
+ if (!isHexString(data)) {
426
+ return undefined;
427
+ }
428
+ try {
429
+ return decodeErrorResult({
430
+ abi: RollupAbi,
431
+ data
432
+ }).errorName;
433
+ } catch {
434
+ return undefined;
435
+ }
436
+ }
437
+ function isHexString(value) {
438
+ return typeof value === 'string' && value.startsWith('0x');
439
+ }
440
+ function requireUintFits(value, bits, name) {
441
+ if (value < 0n || value >= 1n << BigInt(bits)) {
442
+ throw new Error(`${name} ${value} does not fit in uint${bits}`);
443
+ }
444
+ return value;
445
+ }
446
+ export class RollupContract {
447
+ client;
448
+ static{
449
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
450
+ [
451
+ memoize,
452
+ 2,
453
+ "getL1StartBlock"
454
+ ],
455
+ [
456
+ memoize,
457
+ 2,
458
+ "getL1GenesisTime"
459
+ ],
460
+ [
461
+ memoize,
462
+ 2,
463
+ "getProofSubmissionEpochs"
464
+ ],
465
+ [
466
+ memoize,
467
+ 2,
468
+ "getEpochDuration"
469
+ ],
470
+ [
471
+ memoize,
472
+ 2,
473
+ "getSlotDuration"
474
+ ],
475
+ [
476
+ memoize,
477
+ 2,
478
+ "getTargetCommitteeSize"
479
+ ],
480
+ [
481
+ memoize,
482
+ 2,
483
+ "getEjectionThreshold"
484
+ ],
485
+ [
486
+ memoize,
487
+ 2,
488
+ "getLocalEjectionThreshold"
489
+ ],
490
+ [
491
+ memoize,
492
+ 2,
493
+ "getLagInEpochsForValidatorSet"
494
+ ],
495
+ [
496
+ memoize,
497
+ 2,
498
+ "getLagInEpochsForRandao"
499
+ ],
500
+ [
501
+ memoize,
502
+ 2,
503
+ "getActivationThreshold"
504
+ ],
505
+ [
506
+ memoize,
507
+ 2,
508
+ "getExitDelay"
509
+ ],
510
+ [
511
+ memoize,
512
+ 2,
513
+ "getManaTarget"
514
+ ],
515
+ [
516
+ memoize,
517
+ 2,
518
+ "getProvingCostPerMana"
519
+ ],
520
+ [
521
+ memoize,
522
+ 2,
523
+ "getProvingCostPerManaInFeeAsset"
524
+ ],
525
+ [
526
+ memoize,
527
+ 2,
528
+ "getManaLimit"
529
+ ],
530
+ [
531
+ memoize,
532
+ 2,
533
+ "getVersion"
534
+ ],
535
+ [
536
+ memoize,
537
+ 2,
538
+ "getGenesisArchiveTreeRoot"
539
+ ],
540
+ [
541
+ memoize,
542
+ 2,
543
+ "getVkTreeRoot"
544
+ ],
545
+ [
546
+ memoize,
547
+ 2,
548
+ "getProtocolContractsHash"
549
+ ],
550
+ [
551
+ memoize,
552
+ 2,
553
+ "getRollupConstants"
554
+ ]
555
+ ], []));
556
+ }
557
+ rollup;
558
+ logger;
559
+ static cachedStfStorageSlot;
560
+ cachedEscapeHatch;
561
+ static get checkBlobStorageSlot() {
562
+ const asString = RollupStorage.find((storage)=>storage.label === 'checkBlob')?.slot;
563
+ if (asString === undefined) {
564
+ throw new Error('checkBlobStorageSlot not found');
565
+ }
566
+ return BigInt(asString);
567
+ }
568
+ static get stfStorageSlot() {
569
+ return RollupContract.cachedStfStorageSlot ??= keccak256(Buffer.from('aztec.stf.storage', 'utf-8'));
570
+ }
571
+ static getFromL1ContractsValues(deployL1ContractsValues) {
572
+ const { l1Client, l1ContractAddresses: { rollupAddress } } = deployL1ContractsValues;
573
+ return new RollupContract(l1Client, rollupAddress.toString());
574
+ }
575
+ static getFromConfig(config) {
576
+ const client = getPublicClient(config);
577
+ const address = config.rollupAddress.toString();
578
+ return new RollupContract(client, address);
579
+ }
580
+ constructor(client, address){
581
+ this.client = client;
582
+ this.logger = (_initProto(this), createLogger('ethereum:rollup'));
583
+ if (address instanceof EthAddress) {
584
+ address = address.toString();
585
+ }
586
+ this.rollup = getContract({
587
+ address,
588
+ abi: RollupAbi,
589
+ client
590
+ });
591
+ }
592
+ async getGSE() {
593
+ return EthAddress.fromString(await this.rollup.read.getGSE());
594
+ }
595
+ get address() {
596
+ return this.rollup.address;
597
+ }
598
+ getContract() {
599
+ return this.rollup;
600
+ }
601
+ async getSlashingProposer() {
602
+ const slasher = await this.getSlasherContract();
603
+ if (!slasher) {
604
+ return undefined;
605
+ }
606
+ const proposerAddress = await slasher.getProposer();
607
+ if (proposerAddress.isZero()) {
608
+ return undefined;
609
+ }
610
+ return new SlashingProposerContract(this.client, proposerAddress);
611
+ }
612
+ getL1StartBlock() {
613
+ return this.rollup.read.L1_BLOCK_AT_GENESIS();
614
+ }
615
+ getL1GenesisTime() {
616
+ return this.rollup.read.getGenesisTime();
617
+ }
618
+ async getProofSubmissionEpochs() {
619
+ return Number(await this.rollup.read.getProofSubmissionEpochs());
620
+ }
621
+ async getEpochDuration() {
622
+ return Number(await this.rollup.read.getEpochDuration());
623
+ }
624
+ async getSlotDuration() {
625
+ return Number(await this.rollup.read.getSlotDuration());
626
+ }
627
+ async getTargetCommitteeSize() {
628
+ return Number(await this.rollup.read.getTargetCommitteeSize());
629
+ }
630
+ getEjectionThreshold() {
631
+ return this.rollup.read.getEjectionThreshold();
632
+ }
633
+ getLocalEjectionThreshold() {
634
+ return this.rollup.read.getLocalEjectionThreshold();
635
+ }
636
+ async getLagInEpochsForValidatorSet() {
637
+ return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
638
+ }
639
+ async getLagInEpochsForRandao() {
640
+ return Number(await this.rollup.read.getLagInEpochsForRandao());
641
+ }
642
+ getActivationThreshold() {
643
+ return this.rollup.read.getActivationThreshold();
644
+ }
645
+ async getExitDelay() {
646
+ return Number(await this.rollup.read.getExitDelay());
647
+ }
648
+ getManaTarget() {
649
+ return this.rollup.read.getManaTarget();
650
+ }
651
+ getProvingCostPerMana() {
652
+ return this.rollup.read.getProvingCostPerManaInEth();
653
+ }
654
+ getProvingCostPerManaInFeeAsset() {
655
+ return this.rollup.read.getProvingCostPerManaInFeeAsset();
656
+ }
657
+ getManaLimit() {
658
+ return this.rollup.read.getManaLimit();
659
+ }
660
+ getVersion() {
661
+ return this.rollup.read.getVersion();
662
+ }
663
+ async getGenesisArchiveTreeRoot() {
664
+ return Fr.fromString(await this.rollup.read.archiveAt([
665
+ 0n
666
+ ]));
667
+ }
668
+ async getVkTreeRoot() {
669
+ const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
670
+ const value = await this.client.getStorageAt({
671
+ address: this.address,
672
+ slot: `0x${slot.toString(16)}`
673
+ });
674
+ return Fr.fromString(value ?? '0x0');
675
+ }
676
+ async getProtocolContractsHash() {
677
+ const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
678
+ const value = await this.client.getStorageAt({
679
+ address: this.address,
680
+ slot: `0x${slot.toString(16)}`
681
+ });
682
+ return Fr.fromString(value ?? '0x0');
683
+ }
684
+ /**
685
+ * Returns rollup constants used for epoch queries.
686
+ * Return type is `L1RollupConstants` which is defined in stdlib,
687
+ * so we cant reference it until we move this contract to that package.
688
+ */ async getRollupConstants() {
689
+ const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs, targetCommitteeSize, rollupManaLimit] = await Promise.all([
690
+ this.getL1StartBlock(),
691
+ this.getL1GenesisTime(),
692
+ this.getSlotDuration(),
693
+ this.getEpochDuration(),
694
+ this.getProofSubmissionEpochs(),
695
+ this.getTargetCommitteeSize(),
696
+ this.getManaLimit()
697
+ ]);
698
+ return {
699
+ l1StartBlock,
700
+ l1GenesisTime,
701
+ slotDuration,
702
+ epochDuration: Number(epochDuration),
703
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
704
+ targetCommitteeSize,
705
+ rollupManaLimit: Number(rollupManaLimit)
706
+ };
707
+ }
708
+ async getSlasherAddress() {
709
+ return EthAddress.fromString(await this.rollup.read.getSlasher());
710
+ }
711
+ /**
712
+ * Returns the configured escape hatch contract address, or zero if disabled.
713
+ */ async getEscapeHatchAddress() {
714
+ return EthAddress.fromString(await this.rollup.read.getEscapeHatch());
715
+ }
716
+ async getEscapeHatchContract() {
717
+ const escapeHatchAddress = await this.getEscapeHatchAddress();
718
+ if (escapeHatchAddress.isZero()) {
719
+ return undefined;
720
+ }
721
+ // Cache the viem contract wrapper since it will be used frequently.
722
+ if (!this.cachedEscapeHatch || !this.cachedEscapeHatch.address.equals(escapeHatchAddress)) {
723
+ this.cachedEscapeHatch = {
724
+ address: escapeHatchAddress,
725
+ contract: getContract({
726
+ address: escapeHatchAddress.toString(),
727
+ abi: EscapeHatchAbi,
728
+ client: this.client
729
+ })
730
+ };
731
+ }
732
+ return this.cachedEscapeHatch.contract;
733
+ }
734
+ /**
735
+ * Returns whether the escape hatch is open for the given epoch.
736
+ * If escape hatch is not configured, returns false.
737
+ *
738
+ * This function is intentionally defensive: any failure to query the escape hatch
739
+ * (RPC issues, transient errors, etc.) is treated as "closed" to avoid callers
740
+ * needing to sprinkle try/catch everywhere.
741
+ */ async isEscapeHatchOpen(epoch) {
742
+ try {
743
+ const escapeHatch = await this.getEscapeHatchContract();
744
+ if (!escapeHatch) {
745
+ return false;
746
+ }
747
+ const [isOpen] = await escapeHatch.read.isHatchOpen([
748
+ BigInt(epoch)
749
+ ]);
750
+ return isOpen;
751
+ } catch (err) {
752
+ this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
753
+ epoch: Number(epoch),
754
+ error: err
755
+ });
756
+ return false;
757
+ }
758
+ }
759
+ /**
760
+ * Returns a SlasherContract instance for interacting with the slasher contract.
761
+ */ async getSlasherContract() {
762
+ const slasherAddress = await this.getSlasherAddress();
763
+ if (slasherAddress.isZero()) {
764
+ return undefined;
765
+ }
766
+ return new SlasherContract(this.client, slasherAddress);
767
+ }
768
+ async getOwner() {
769
+ return EthAddress.fromString(await this.rollup.read.owner());
770
+ }
771
+ async getActiveAttesterCount(options) {
772
+ await checkBlockTag(options?.blockNumber, this.client);
773
+ return Number(await this.rollup.read.getActiveAttesterCount(options));
774
+ }
775
+ /**
776
+ * Number of attesters that were staked at the given (historical) L1 timestamp. This is the count that
777
+ * validator-set sampling uses to decide whether an epoch gets a committee, and the historical counterpart
778
+ * of {@link getActiveAttesterCount} (which reads at the latest L1 block).
779
+ */ async getAttesterCountAtTime(timestamp, options) {
780
+ const gse = new GSEContract(this.client, await this.getGSE());
781
+ return gse.getAttesterCountAtTime(this.address, timestamp, options);
782
+ }
783
+ async getSlashingProposerAddress() {
784
+ const slasher = await this.getSlasherContract();
785
+ if (!slasher) {
786
+ return EthAddress.ZERO;
787
+ }
788
+ return await slasher.getProposer();
789
+ }
790
+ getCheckpointReward() {
791
+ return this.rollup.read.getCheckpointReward();
792
+ }
793
+ async getCheckpointNumber(options) {
794
+ await checkBlockTag(options?.blockNumber, this.client);
795
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber(options));
796
+ }
797
+ async getProvenCheckpointNumber(options) {
798
+ await checkBlockTag(options?.blockNumber, this.client);
799
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
800
+ }
801
+ async getSlotNumber(options) {
802
+ await checkBlockTag(options?.blockNumber, this.client);
803
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot(options));
804
+ }
805
+ async getL1FeesAt(timestamp, options) {
806
+ await checkBlockTag(options?.blockNumber, this.client);
807
+ const result = await this.rollup.read.getL1FeesAt([
808
+ timestamp
809
+ ], options);
810
+ return {
811
+ baseFee: result.baseFee,
812
+ blobFee: result.blobFee
813
+ };
814
+ }
815
+ async getFeeHeader(checkpointNumber) {
816
+ const result = await this.rollup.read.getFeeHeader([
817
+ checkpointNumber
818
+ ]);
819
+ return {
820
+ excessMana: result.excessMana,
821
+ manaUsed: result.manaUsed,
822
+ ethPerFeeAsset: result.ethPerFeeAsset,
823
+ congestionCost: result.congestionCost,
824
+ proverCost: result.proverCost
825
+ };
826
+ }
827
+ getEthPerFeeAsset() {
828
+ return this.rollup.read.getEthPerFeeAsset();
829
+ }
830
+ async getCommitteeAt(timestamp) {
831
+ const { result } = await this.client.simulateContract({
832
+ address: this.address,
833
+ abi: RollupAbi,
834
+ functionName: 'getCommitteeAt',
835
+ args: [
836
+ timestamp
837
+ ]
838
+ }).catch((e)=>{
839
+ if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
840
+ return {
841
+ result: undefined
842
+ };
843
+ }
844
+ throw e;
845
+ });
846
+ return result ? result.map((addr)=>EthAddress.fromString(addr)) : undefined;
847
+ }
848
+ async getSampleSeedAt(timestamp) {
849
+ return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([
850
+ timestamp
851
+ ]));
852
+ }
853
+ async getCurrentSampleSeed() {
854
+ return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
855
+ }
856
+ async getCurrentEpoch() {
857
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
858
+ }
859
+ async getCurrentEpochCommittee() {
860
+ const { result } = await this.client.simulateContract({
861
+ address: this.address,
862
+ abi: RollupAbi,
863
+ functionName: 'getCurrentEpochCommittee',
864
+ args: []
865
+ }).catch((e)=>{
866
+ if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
867
+ return {
868
+ result: undefined
869
+ };
870
+ }
871
+ throw e;
872
+ });
873
+ return result ? result.map((addr)=>EthAddress.fromString(addr)) : undefined;
874
+ }
875
+ async getCurrentProposer() {
876
+ const { result } = await this.client.simulateContract({
877
+ address: this.address,
878
+ abi: RollupAbi,
879
+ functionName: 'getCurrentProposer',
880
+ args: []
881
+ });
882
+ return EthAddress.fromString(result);
883
+ }
884
+ async getProposerAt(timestamp) {
885
+ const { result } = await this.client.simulateContract({
886
+ address: this.address,
887
+ abi: RollupAbi,
888
+ functionName: 'getProposerAt',
889
+ args: [
890
+ timestamp
891
+ ]
892
+ });
893
+ return EthAddress.fromString(result);
894
+ }
895
+ async getCheckpoint(checkpointNumber, options) {
896
+ await checkBlockTag(options?.blockNumber, this.client);
897
+ const result = await this.rollup.read.getCheckpoint([
898
+ BigInt(checkpointNumber)
899
+ ], options);
900
+ return {
901
+ archive: Fr.fromString(result.archive),
902
+ headerHash: Buffer32.fromString(result.headerHash),
903
+ blobCommitmentsHash: Buffer32.fromString(result.blobCommitmentsHash),
904
+ attestationsHash: Buffer32.fromString(result.attestationsHash),
905
+ payloadDigest: Buffer32.fromString(result.payloadDigest),
906
+ slotNumber: SlotNumber.fromBigInt(result.slotNumber),
907
+ feeHeader: {
908
+ excessMana: result.feeHeader.excessMana,
909
+ manaUsed: result.feeHeader.manaUsed,
910
+ ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
911
+ congestionCost: result.feeHeader.congestionCost,
912
+ proverCost: result.feeHeader.proverCost
913
+ }
914
+ };
915
+ }
916
+ /** Returns the pending checkpoint from the rollup contract */ getPendingCheckpoint() {
917
+ // We retry because of race conditions during prunes: we may get a pending checkpoint number which is immediately
918
+ // reorged out due to a prune happening, causing the subsequent getCheckpoint call to fail. So we try again in that case.
919
+ return retry(async ()=>{
920
+ const pendingCheckpointNumber = await this.getCheckpointNumber();
921
+ const pendingCheckpoint = await this.getCheckpoint(pendingCheckpointNumber);
922
+ return pendingCheckpoint;
923
+ }, 'getting pending checkpoint', makeBackoff([
924
+ 0.5,
925
+ 0.5,
926
+ 0.5
927
+ ]));
928
+ }
929
+ /**
930
+ * Returns the effective pending checkpoint, accounting for potential prunes.
931
+ * When a prune can happen, the L1 contract uses the proven checkpoint instead of the pending one.
932
+ * This mirrors the behavior of getEffectivePendingCheckpointNumber in STFLib.sol.
933
+ * @param atTimestamp - The timestamp to evaluate pruneability at. Defaults to the current L1 block timestamp.
934
+ * @param options - Optional L1 block number to pin the queries to.
935
+ */ getEffectivePendingCheckpoint(atTimestamp, options) {
936
+ return retry(async ()=>{
937
+ const timestamp = atTimestamp ?? (await this.client.getBlock()).timestamp;
938
+ const canPrune = await this.canPruneAtTime(timestamp, options);
939
+ if (canPrune) {
940
+ const provenCheckpointNumber = await this.getProvenCheckpointNumber(options);
941
+ return await this.getCheckpoint(provenCheckpointNumber, options);
942
+ }
943
+ const pendingCheckpointNumber = await this.getCheckpointNumber(options);
944
+ return await this.getCheckpoint(pendingCheckpointNumber, options);
945
+ }, 'getting effective pending checkpoint', makeBackoff([
946
+ 0.5,
947
+ 0.5,
948
+ 0.5
949
+ ]));
950
+ }
951
+ async getTips() {
952
+ const { pending, proven } = await this.rollup.read.getTips();
953
+ return {
954
+ pending: CheckpointNumber.fromBigInt(pending),
955
+ proven: CheckpointNumber.fromBigInt(proven)
956
+ };
957
+ }
958
+ getTimestampForSlot(slot) {
959
+ return this.rollup.read.getTimestampForSlot([
960
+ BigInt(slot)
961
+ ]);
962
+ }
963
+ async getEntryQueueLength() {
964
+ return Number(await this.rollup.read.getEntryQueueLength());
965
+ }
966
+ async getAvailableValidatorFlushes() {
967
+ return Number(await this.rollup.read.getAvailableValidatorFlushes());
968
+ }
969
+ async getNextFlushableEpoch() {
970
+ return EpochNumber.fromBigInt(await this.rollup.read.getNextFlushableEpoch());
971
+ }
972
+ async getCurrentEpochNumber() {
973
+ return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
974
+ }
975
+ async getEpochNumberForCheckpoint(checkpointNumber) {
976
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochForCheckpoint([
977
+ BigInt(checkpointNumber)
978
+ ]));
979
+ }
980
+ async getRollupAddresses() {
981
+ const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress, gseAddress] = (await Promise.all([
982
+ this.rollup.read.getInbox(),
983
+ this.rollup.read.getOutbox(),
984
+ this.rollup.read.getFeeAssetPortal(),
985
+ this.rollup.read.getRewardDistributor(),
986
+ this.rollup.read.getFeeAsset(),
987
+ this.rollup.read.getStakingAsset(),
988
+ this.rollup.read.getGSE()
989
+ ])).map(EthAddress.fromString);
990
+ return {
991
+ rollupAddress: EthAddress.fromString(this.address),
992
+ inboxAddress,
993
+ outboxAddress,
994
+ feeJuicePortalAddress,
995
+ feeJuiceAddress,
996
+ stakingAssetAddress,
997
+ rewardDistributorAddress,
998
+ gseAddress
999
+ };
1000
+ }
1001
+ async getFeeJuicePortal() {
1002
+ return EthAddress.fromString(await this.rollup.read.getFeeAssetPortal());
1003
+ }
1004
+ async getEpochNumberForSlotNumber(slotNumber) {
1005
+ return EpochNumber.fromBigInt(await this.rollup.read.getEpochAtSlot([
1006
+ BigInt(slotNumber)
1007
+ ]));
1008
+ }
1009
+ async getEpochProofPublicInputs(args) {
1010
+ const result = await this.rollup.read.getEpochProofPublicInputs(args);
1011
+ return result.map(Fr.fromString);
1012
+ }
1013
+ async validateHeader(args, account) {
1014
+ try {
1015
+ await this.client.simulateContract({
1016
+ address: this.address,
1017
+ abi: RollupAbi,
1018
+ functionName: 'validateHeaderWithAttestations',
1019
+ args,
1020
+ account
1021
+ });
1022
+ } catch (error) {
1023
+ throw formatViemError(error);
1024
+ }
1025
+ }
1026
+ /**
1027
+ * @notice Calls `canProposeAtTime` with the time of the next Ethereum block and the sender address
1028
+ *
1029
+ * @dev Throws if unable to propose
1030
+ *
1031
+ * @param archive - The archive that we expect to be current state
1032
+ * @return [slot, checkpointNumber, timeOfNextL1Slot] - If you can propose, the L2 slot number, checkpoint number and
1033
+ * timestamp of the next L1 block
1034
+ * @throws otherwise
1035
+ */ async canProposeAt(archive, account, timestamp, stateOverride = []) {
1036
+ const timeOfNextL1Slot = timestamp;
1037
+ const who = typeof account === 'string' ? account : account.address;
1038
+ try {
1039
+ const { result: [slot, checkpointNumber] } = await this.client.simulateContract({
1040
+ address: this.address,
1041
+ abi: RollupAbi,
1042
+ functionName: 'canProposeAtTime',
1043
+ args: [
1044
+ timeOfNextL1Slot,
1045
+ `0x${archive.toString('hex')}`,
1046
+ who
1047
+ ],
1048
+ account,
1049
+ stateOverride
1050
+ });
1051
+ return {
1052
+ slot: SlotNumber.fromBigInt(slot),
1053
+ checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber),
1054
+ timeOfNextL1Slot
1055
+ };
1056
+ } catch (err) {
1057
+ throw formatViemError(err);
1058
+ }
1059
+ }
1060
+ /**
1061
+ * Returns a state override that sets the pending and/or proven checkpoint numbers. Useful for simulations.
1062
+ * Both values share a single storage slot (pending in the upper 128 bits, proven in the lower 128 bits), so
1063
+ * a single combined override is emitted to avoid the second state-diff clobbering the first. The current live
1064
+ * value is read once to preserve any half not being overridden. Returns an empty override if neither is set.
1065
+ *
1066
+ * Throws if the resulting `proven > pending`, which would crash the simulation: `STFLib.canPruneAtTime` calls
1067
+ * `getEpochForCheckpoint(proven + 1)` whenever `pending != proven`, and that asserts `_n <= tips.pending`.
1068
+ */ async makeChainTipsOverride(override) {
1069
+ if (override.pending === undefined && override.proven === undefined) {
1070
+ return [];
1071
+ }
1072
+ const slot = RollupContract.stfStorageSlot;
1073
+ const currentValue = await this.client.getStorageAt({
1074
+ address: this.address,
1075
+ slot
1076
+ });
1077
+ const currentRaw = currentValue ? hexToBigInt(currentValue) : 0n;
1078
+ const currentPending = currentRaw >> 128n;
1079
+ const currentProven = currentRaw & (1n << 128n) - 1n;
1080
+ const newPending = override.pending !== undefined ? BigInt(override.pending) : currentPending;
1081
+ const newProven = override.proven !== undefined ? BigInt(override.proven) : currentProven;
1082
+ if (newProven > newPending) {
1083
+ throw new Error(`Invalid chain tips override: proven (${newProven}) > pending (${newPending})`);
1084
+ }
1085
+ const newValue = newPending << 128n | newProven;
1086
+ return [
1087
+ {
1088
+ address: this.address,
1089
+ stateDiff: [
1090
+ {
1091
+ slot,
1092
+ value: `0x${newValue.toString(16).padStart(64, '0')}`
1093
+ }
1094
+ ]
1095
+ }
1096
+ ];
1097
+ }
1098
+ /**
1099
+ * Returns a state override that patches `tempCheckpointLogs[checkpointNumber]` with every field that
1100
+ * the L1 contract reads during `propose()` for the checkpoint that builds on top of it (proposer
1101
+ * pipelining simulation). Mirrors the writes done by `ProposeLib.addTempCheckpointLog`.
1102
+ *
1103
+ * `blobCommitmentsHash` and `attestationsHash` are intentionally not exposed here — the propose path
1104
+ * never asserts against them, so leaving them at storage zero is harmless.
1105
+ *
1106
+ * One diff entry is emitted per storage word touched, so words left out keep their on-chain values.
1107
+ * `slotNumber` and the two inbox consumption counts share a word: any of them rewrites all three.
1108
+ */ async makeTempCheckpointLogOverride(checkpointNumber, fields) {
1109
+ const constants = await this.getRollupConstants();
1110
+ const slotAt = (field)=>`0x${this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants).toString(16).padStart(64, '0')}`;
1111
+ const word = (v)=>`0x${v.toString(16).padStart(64, '0')}`;
1112
+ const stateDiff = [];
1113
+ if (fields.headerHash) {
1114
+ stateDiff.push({
1115
+ slot: slotAt(0),
1116
+ value: fields.headerHash.toString()
1117
+ });
1118
+ }
1119
+ if (fields.outHash) {
1120
+ stateDiff.push({
1121
+ slot: slotAt(2),
1122
+ value: fields.outHash.toString()
1123
+ });
1124
+ }
1125
+ if (fields.payloadDigest) {
1126
+ stateDiff.push({
1127
+ slot: slotAt(4),
1128
+ value: fields.payloadDigest.toString()
1129
+ });
1130
+ }
1131
+ if (fields.slotNumber !== undefined || fields.inboxMsgTotal !== undefined) {
1132
+ // The L1 struct packs the slot number and the inbox consumption count into one word, so this
1133
+ // diff always writes both. Widths are enforced here because the L1 writers cast through
1134
+ // SafeCast and revert on overflow; a malformed override must surface rather than silently truncate
1135
+ // into a neighbouring field.
1136
+ const slotNumber = requireUintFits(BigInt(fields.slotNumber ?? 0), 32, 'slotNumber');
1137
+ const inboxMsgTotal = requireUintFits(fields.inboxMsgTotal ?? 0n, 64, 'inboxMsgTotal');
1138
+ stateDiff.push({
1139
+ slot: slotAt(5),
1140
+ value: word(slotNumber | inboxMsgTotal << 32n)
1141
+ });
1142
+ }
1143
+ if (fields.feeHeader) {
1144
+ stateDiff.push({
1145
+ slot: slotAt(6),
1146
+ value: word(RollupContract.compressFeeHeader(fields.feeHeader))
1147
+ });
1148
+ }
1149
+ if (stateDiff.length === 0) {
1150
+ return [];
1151
+ }
1152
+ return [
1153
+ {
1154
+ address: this.address,
1155
+ stateDiff
1156
+ }
1157
+ ];
1158
+ }
1159
+ /**
1160
+ * Returns a state override that sets archives[checkpointNumber] to the given archive value.
1161
+ * Used when simulating a canProposeAtTime call where the local archive differs from L1
1162
+ * (e.g. pipelining where the parent checkpoint hasn't landed on L1 yet).
1163
+ */ makeArchiveOverride(checkpointNumber, archive) {
1164
+ const archivesMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 1n;
1165
+ const archiveSlot = hexToBigInt(keccak256(encodeAbiParameters([
1166
+ {
1167
+ type: 'uint256'
1168
+ },
1169
+ {
1170
+ type: 'uint256'
1171
+ }
1172
+ ], [
1173
+ BigInt(checkpointNumber),
1174
+ archivesMappingBase
1175
+ ])));
1176
+ return [
1177
+ {
1178
+ address: this.address,
1179
+ stateDiff: [
1180
+ {
1181
+ slot: `0x${archiveSlot.toString(16).padStart(64, '0')}`,
1182
+ value: archive.toString()
1183
+ }
1184
+ ]
1185
+ }
1186
+ ];
1187
+ }
1188
+ /** Merges multiple StateOverride arrays, combining stateDiff entries for the same address. */ static mergeStateOverrides(...overrides) {
1189
+ const byAddress = new Map();
1190
+ for (const override of overrides){
1191
+ for (const entry of override){
1192
+ const key = entry.address.toLowerCase();
1193
+ const existing = byAddress.get(key);
1194
+ if (existing) {
1195
+ existing.stateDiff.push(...entry.stateDiff ?? []);
1196
+ if (entry.balance !== undefined) {
1197
+ existing.balance = entry.balance;
1198
+ }
1199
+ } else {
1200
+ byAddress.set(key, {
1201
+ address: entry.address,
1202
+ balance: entry.balance,
1203
+ stateDiff: [
1204
+ ...entry.stateDiff ?? []
1205
+ ]
1206
+ });
1207
+ }
1208
+ }
1209
+ }
1210
+ return [
1211
+ ...byAddress.values()
1212
+ ];
1213
+ }
1214
+ /** Compresses a FeeHeader into a uint256 matching FeeHeaderLib.compress() in FeeStructs.sol. */ static compressFeeHeader(feeHeader) {
1215
+ const MASK_48_BITS = (1n << 48n) - 1n;
1216
+ const MASK_64_BITS = (1n << 64n) - 1n;
1217
+ const MASK_63_BITS = (1n << 63n) - 1n;
1218
+ let value = BigInt(feeHeader.manaUsed) & (1n << 32n) - 1n; // bits [0:31]
1219
+ value |= (feeHeader.excessMana < MASK_48_BITS ? feeHeader.excessMana : MASK_48_BITS) << 32n; // bits [32:79]
1220
+ value |= (BigInt(feeHeader.ethPerFeeAsset) & MASK_48_BITS) << 80n; // bits [80:127]
1221
+ value |= (feeHeader.congestionCost < MASK_64_BITS ? feeHeader.congestionCost : MASK_64_BITS) << 128n; // bits [128:191]
1222
+ value |= (feeHeader.proverCost < MASK_63_BITS ? feeHeader.proverCost : MASK_63_BITS) << 192n; // bits [192:254]
1223
+ value |= 1n << 255n; // preheat flag
1224
+ return value;
1225
+ }
1226
+ /** Computes the fee header for a child checkpoint given parent fee header and child data.
1227
+ * Must stay in sync with Solidity FeeLib.sol (computeNewEthPerFeeAsset, clampedAdd). */ static computeChildFeeHeader(parentFeeHeader, childManaUsed, feeAssetPriceModifier, manaTarget) {
1228
+ const MIN_ETH_PER_FEE_ASSET = 100n;
1229
+ const MAX_ETH_PER_FEE_ASSET = 100_000_000_000_000n; // 1e14, matches FeeLib.sol
1230
+ // excessMana = clampedAdd(parent.excessMana + parent.manaUsed, -manaTarget)
1231
+ const sum = parentFeeHeader.excessMana + parentFeeHeader.manaUsed;
1232
+ const excessMana = sum > manaTarget ? sum - manaTarget : 0n;
1233
+ // ethPerFeeAsset = computeNewEthPerFeeAsset(max(parent.ethPerFeeAsset, MIN), modifier)
1234
+ const parentPrice = parentFeeHeader.ethPerFeeAsset > MIN_ETH_PER_FEE_ASSET ? parentFeeHeader.ethPerFeeAsset : MIN_ETH_PER_FEE_ASSET;
1235
+ let newPrice;
1236
+ if (feeAssetPriceModifier >= 0n) {
1237
+ newPrice = parentPrice * (10_000n + feeAssetPriceModifier) / 10_000n;
1238
+ } else {
1239
+ const absMod = -feeAssetPriceModifier;
1240
+ newPrice = parentPrice * (10_000n - absMod) / 10_000n;
1241
+ }
1242
+ if (newPrice < MIN_ETH_PER_FEE_ASSET) {
1243
+ newPrice = MIN_ETH_PER_FEE_ASSET;
1244
+ }
1245
+ if (newPrice > MAX_ETH_PER_FEE_ASSET) {
1246
+ newPrice = MAX_ETH_PER_FEE_ASSET;
1247
+ }
1248
+ return {
1249
+ excessMana,
1250
+ manaUsed: childManaUsed,
1251
+ ethPerFeeAsset: newPrice,
1252
+ congestionCost: 0n,
1253
+ proverCost: 0n
1254
+ };
1255
+ }
1256
+ /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */ buildInvalidateBadAttestationRequest(checkpointNumber, attestationsAndSigners, committee, invalidIndex) {
1257
+ return {
1258
+ to: this.address,
1259
+ abi: RollupAbi,
1260
+ data: encodeFunctionData({
1261
+ abi: RollupAbi,
1262
+ functionName: 'invalidateBadAttestation',
1263
+ args: [
1264
+ BigInt(checkpointNumber),
1265
+ attestationsAndSigners,
1266
+ committee.map((addr)=>addr.toString()),
1267
+ BigInt(invalidIndex)
1268
+ ]
1269
+ })
1270
+ };
1271
+ }
1272
+ /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */ buildInvalidateInsufficientAttestationsRequest(checkpointNumber, attestationsAndSigners, committee) {
1273
+ return {
1274
+ to: this.address,
1275
+ abi: RollupAbi,
1276
+ data: encodeFunctionData({
1277
+ abi: RollupAbi,
1278
+ functionName: 'invalidateInsufficientAttestations',
1279
+ args: [
1280
+ BigInt(checkpointNumber),
1281
+ attestationsAndSigners,
1282
+ committee.map((addr)=>addr.toString())
1283
+ ]
1284
+ })
1285
+ };
1286
+ }
1287
+ /** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */ getHasSubmittedProof(epochNumber, numberOfCheckpointsInEpoch, prover) {
1288
+ if (prover instanceof EthAddress) {
1289
+ prover = prover.toString();
1290
+ }
1291
+ return this.rollup.read.getHasSubmitted([
1292
+ BigInt(epochNumber),
1293
+ BigInt(numberOfCheckpointsInEpoch),
1294
+ prover
1295
+ ]);
1296
+ }
1297
+ getManaMinFeeAt(timestamp, inFeeAsset, stateOverride) {
1298
+ return this.rollup.read.getManaMinFeeAt([
1299
+ timestamp,
1300
+ inFeeAsset
1301
+ ], {
1302
+ stateOverride
1303
+ });
1304
+ }
1305
+ async getManaMinFeeComponentsAt(timestamp, inFeeAsset) {
1306
+ const result = await this.rollup.read.getManaMinFeeComponentsAt([
1307
+ timestamp,
1308
+ inFeeAsset
1309
+ ]);
1310
+ return {
1311
+ sequencerCost: result.sequencerCost,
1312
+ proverCost: result.proverCost,
1313
+ congestionCost: result.congestionCost,
1314
+ congestionMultiplier: result.congestionMultiplier
1315
+ };
1316
+ }
1317
+ async getSlotAt(timestamp) {
1318
+ return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([
1319
+ timestamp
1320
+ ]));
1321
+ }
1322
+ async status(checkpointNumber, options) {
1323
+ await checkBlockTag(options?.blockNumber, this.client);
1324
+ const result = await this.rollup.read.status([
1325
+ BigInt(checkpointNumber)
1326
+ ], options);
1327
+ return {
1328
+ provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
1329
+ provenArchive: Fr.fromString(result[1]),
1330
+ pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
1331
+ pendingArchive: Fr.fromString(result[3]),
1332
+ archiveOfMyCheckpoint: Fr.fromString(result[4])
1333
+ };
1334
+ }
1335
+ async canPruneAtTime(timestamp, options) {
1336
+ await checkBlockTag(options?.blockNumber, this.client);
1337
+ return this.rollup.read.canPruneAtTime([
1338
+ timestamp
1339
+ ], options);
1340
+ }
1341
+ async archive() {
1342
+ return Fr.fromString(await this.rollup.read.archive());
1343
+ }
1344
+ async archiveAt(checkpointNumber) {
1345
+ return Fr.fromString(await this.rollup.read.archiveAt([
1346
+ BigInt(checkpointNumber)
1347
+ ]));
1348
+ }
1349
+ getSequencerRewards(address) {
1350
+ if (address instanceof EthAddress) {
1351
+ address = address.toString();
1352
+ }
1353
+ return this.rollup.read.getSequencerRewards([
1354
+ address
1355
+ ]);
1356
+ }
1357
+ getSpecificProverRewardsForEpoch(epoch, prover) {
1358
+ if (prover instanceof EthAddress) {
1359
+ prover = prover.toString();
1360
+ }
1361
+ return this.rollup.read.getSpecificProverRewardsForEpoch([
1362
+ epoch,
1363
+ prover
1364
+ ]);
1365
+ }
1366
+ async getAttesters(timestamp) {
1367
+ // Pin every read to a single L1 block so the attester count and the chunked index reads
1368
+ // observe a consistent set. Without this, the count and each chunk default to `latest` and
1369
+ // can straddle a block boundary (or reorg), yielding an inconsistent or truncated set.
1370
+ const block = await this.client.getBlock();
1371
+ const blockNumber = block.number ?? undefined;
1372
+ const ts = timestamp ?? block.timestamp;
1373
+ const attesterSize = await this.getActiveAttesterCount({
1374
+ blockNumber
1375
+ });
1376
+ const gse = new GSEContract(this.client, await this.getGSE());
1377
+ const indices = Array.from({
1378
+ length: attesterSize
1379
+ }, (_, i)=>BigInt(i));
1380
+ const chunks = chunk(indices, 1000);
1381
+ const results = await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk, {
1382
+ blockNumber
1383
+ })));
1384
+ return results.flat().map((addr)=>EthAddress.fromString(addr));
1385
+ }
1386
+ async getAttesterView(address) {
1387
+ if (address instanceof EthAddress) {
1388
+ address = address.toString();
1389
+ }
1390
+ const result = await this.rollup.read.getAttesterView([
1391
+ address
1392
+ ]);
1393
+ return {
1394
+ status: result.status,
1395
+ effectiveBalance: result.effectiveBalance,
1396
+ exit: {
1397
+ withdrawalId: result.exit.withdrawalId,
1398
+ amount: result.exit.amount,
1399
+ exitableAt: result.exit.exitableAt,
1400
+ recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
1401
+ isRecipient: result.exit.isRecipient,
1402
+ exists: result.exit.exists
1403
+ },
1404
+ config: {
1405
+ publicKey: {
1406
+ x: result.config.publicKey.x,
1407
+ y: result.config.publicKey.y
1408
+ },
1409
+ withdrawer: EthAddress.fromString(result.config.withdrawer)
1410
+ }
1411
+ };
1412
+ }
1413
+ async getStatus(address) {
1414
+ if (address instanceof EthAddress) {
1415
+ address = address.toString();
1416
+ }
1417
+ return await this.rollup.read.getStatus([
1418
+ address
1419
+ ]);
1420
+ }
1421
+ async getBlobCommitmentsHash(checkpointNumber) {
1422
+ return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([
1423
+ BigInt(checkpointNumber)
1424
+ ]));
1425
+ }
1426
+ async getCurrentBlobCommitmentsHash() {
1427
+ return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
1428
+ }
1429
+ async getStakingAsset() {
1430
+ return EthAddress.fromString(await this.rollup.read.getStakingAsset());
1431
+ }
1432
+ async getRewardConfig() {
1433
+ const result = await this.rollup.read.getRewardConfig();
1434
+ return {
1435
+ rewardDistributor: EthAddress.fromString(result.rewardDistributor),
1436
+ sequencerBps: BigInt(result.sequencerBps),
1437
+ booster: EthAddress.fromString(result.booster),
1438
+ checkpointReward: result.checkpointReward
1439
+ };
1440
+ }
1441
+ setupEpoch(l1TxUtils) {
1442
+ return l1TxUtils.sendAndMonitorTransaction({
1443
+ to: this.address,
1444
+ abi: RollupAbi,
1445
+ data: encodeFunctionData({
1446
+ abi: RollupAbi,
1447
+ functionName: 'setupEpoch',
1448
+ args: []
1449
+ })
1450
+ });
1451
+ }
1452
+ vote(l1TxUtils, proposalId) {
1453
+ return l1TxUtils.sendAndMonitorTransaction({
1454
+ to: this.address,
1455
+ abi: RollupAbi,
1456
+ data: encodeFunctionData({
1457
+ abi: RollupAbi,
1458
+ functionName: 'vote',
1459
+ args: [
1460
+ proposalId
1461
+ ]
1462
+ })
1463
+ });
1464
+ }
1465
+ /**
1466
+ * Watches for SlasherUpdated events. Events are delivered by polling `eth_getLogs`: a reorg may re-emit them and
1467
+ * removals are never reported, and events mined within roughly one polling interval of subscribing may be missed.
1468
+ * Slasher rotations are rare governance operations, so by default this polls much slower than the other watchers.
1469
+ */ listenToSlasherChanged(callback, options) {
1470
+ return watchContractEvent(this.client, this.logger, {
1471
+ address: this.address,
1472
+ abi: RollupAbi,
1473
+ eventName: 'SlasherUpdated',
1474
+ onLog: (log)=>{
1475
+ const { oldSlasher, newSlasher } = log.args;
1476
+ if (oldSlasher && newSlasher) {
1477
+ return callback({
1478
+ oldSlasher,
1479
+ newSlasher
1480
+ });
1481
+ }
1482
+ }
1483
+ }, {
1484
+ pollingIntervalMs: SLASHER_UPDATED_POLLING_INTERVAL_MS,
1485
+ ...options
1486
+ });
1487
+ }
1488
+ /**
1489
+ * Watches for CheckpointInvalidated events. Events are delivered by polling `eth_getLogs`: a reorg may re-emit
1490
+ * them and removals are never reported, and events mined within roughly one polling interval of subscribing may
1491
+ * be missed.
1492
+ */ listenToCheckpointInvalidated(callback, options) {
1493
+ return watchContractEvent(this.client, this.logger, {
1494
+ address: this.address,
1495
+ abi: RollupAbi,
1496
+ eventName: 'CheckpointInvalidated',
1497
+ onLog: (log)=>{
1498
+ const { checkpointNumber } = log.args;
1499
+ if (checkpointNumber !== undefined) {
1500
+ return callback({
1501
+ checkpointNumber: CheckpointNumber.fromBigInt(checkpointNumber),
1502
+ event: log
1503
+ });
1504
+ }
1505
+ }
1506
+ }, options);
1507
+ }
1508
+ async getSlashEvents(l1BlockHash) {
1509
+ const events = await this.rollup.getEvents.Slashed({}, {
1510
+ blockHash: l1BlockHash,
1511
+ strict: true
1512
+ });
1513
+ return events.map((event)=>({
1514
+ amount: event.args.amount,
1515
+ attester: EthAddress.fromString(event.args.attester)
1516
+ }));
1517
+ }
1518
+ /**
1519
+ * Watches for Slashed events. Events are delivered by polling `eth_getLogs`: a reorg may re-emit them and
1520
+ * removals are never reported, and events mined within roughly one polling interval of subscribing may be missed.
1521
+ */ listenToSlash(callback, options) {
1522
+ return watchContractEvent(this.client, this.logger, {
1523
+ address: this.address,
1524
+ abi: RollupAbi,
1525
+ eventName: 'Slashed',
1526
+ strict: true,
1527
+ onLog: (log)=>callback({
1528
+ amount: log.args.amount,
1529
+ attester: EthAddress.fromString(log.args.attester)
1530
+ })
1531
+ }, options);
1532
+ }
1533
+ /**
1534
+ * Fetches OwnershipTransferred events emitted on the L1 block this rollup was deployed on.
1535
+ * The Rollup inherits from Ownable and emits this event in its constructor, so the event
1536
+ * is guaranteed to exist on `l1StartBlock` for any correctly deployed rollup. Used as a
1537
+ * probe to detect RPC nodes that prune historical logs.
1538
+ */ async getOwnershipTransferredEventsAtDeploy() {
1539
+ const l1StartBlock = await this.getL1StartBlock();
1540
+ return await this.rollup.getEvents.OwnershipTransferred({}, {
1541
+ fromBlock: l1StartBlock,
1542
+ toBlock: l1StartBlock
1543
+ });
1544
+ }
1545
+ /** Fetches CheckpointProposed events within the given block range. */ async getCheckpointProposedEvents(fromBlock, toBlock) {
1546
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, {
1547
+ fromBlock,
1548
+ toBlock
1549
+ });
1550
+ return logs.filter((log)=>log.blockNumber >= fromBlock && log.blockNumber <= toBlock).map((log)=>({
1551
+ l1BlockNumber: log.blockNumber,
1552
+ l1BlockHash: Buffer32.fromString(log.blockHash),
1553
+ l1TransactionHash: log.transactionHash,
1554
+ args: {
1555
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber),
1556
+ archive: Fr.fromString(log.args.archive),
1557
+ versionedBlobHashes: log.args.versionedBlobHashes.map((h)=>Buffer.from(h.slice(2), 'hex')),
1558
+ attestationsHash: (()=>{
1559
+ if (!log.args.attestationsHash) {
1560
+ throw new Error(`CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`);
1561
+ }
1562
+ return Buffer32.fromString(log.args.attestationsHash);
1563
+ })(),
1564
+ payloadDigest: (()=>{
1565
+ if (!log.args.payloadDigest) {
1566
+ throw new Error(`CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`);
1567
+ }
1568
+ return Buffer32.fromString(log.args.payloadDigest);
1569
+ })()
1570
+ }
1571
+ }));
1572
+ }
1573
+ /** Packs pending and proven checkpoint numbers into the chain tips storage format. */ static packChainTips(pendingCheckpointNumber, provenCheckpointNumber) {
1574
+ return pendingCheckpointNumber << 128n | provenCheckpointNumber & (1n << 128n) - 1n;
1575
+ }
1576
+ /** Storage slot for the chain tips (offset 0 within the STF storage struct). */ static get chainTipsStorageSlot() {
1577
+ return BigInt(RollupContract.stfStorageSlot);
1578
+ }
1579
+ /**
1580
+ * Computes the storage slot for a field within a tempCheckpointLog entry.
1581
+ * @param checkpointNumber - The checkpoint number
1582
+ * @param field - The field within the CompressedTempCheckpointLog struct
1583
+ */ async getTempCheckpointLogStorageSlot(checkpointNumber, field) {
1584
+ const [epochDuration, proofSubmissionEpochs] = await Promise.all([
1585
+ this.getEpochDuration(),
1586
+ this.getProofSubmissionEpochs()
1587
+ ]);
1588
+ return this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, {
1589
+ epochDuration,
1590
+ proofSubmissionEpochs
1591
+ });
1592
+ }
1593
+ computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants) {
1594
+ const fieldOffset = BigInt(field);
1595
+ const { epochDuration, proofSubmissionEpochs } = constants;
1596
+ const roundaboutSize = BigInt(epochDuration) * (BigInt(proofSubmissionEpochs) + 1n) + 1n;
1597
+ const tempCheckpointLogsBase = BigInt(RollupContract.stfStorageSlot) + 2n;
1598
+ const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
1599
+ const entryBase = BigInt(keccak256(encodeAbiParameters([
1600
+ {
1601
+ type: 'uint256'
1602
+ },
1603
+ {
1604
+ type: 'uint256'
1605
+ }
1606
+ ], [
1607
+ circularIndex,
1608
+ tempCheckpointLogsBase
1609
+ ])));
1610
+ return entryBase + fieldOffset;
1611
+ }
1612
+ }