@aztec/ethereum 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0

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 (224) hide show
  1. package/dest/client.d.ts +25 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +60 -4
  4. package/dest/config.d.ts +45 -73
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +114 -386
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/empire_base.d.ts +2 -1
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  13. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  14. package/dest/contracts/fee_asset_handler.js +11 -9
  15. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  16. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  17. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  18. package/dest/contracts/governance.d.ts +110 -33
  19. package/dest/contracts/governance.d.ts.map +1 -1
  20. package/dest/contracts/governance.js +207 -16
  21. package/dest/contracts/governance_proposer.d.ts +34 -1
  22. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  23. package/dest/contracts/governance_proposer.js +447 -10
  24. package/dest/contracts/gse.d.ts +4 -2
  25. package/dest/contracts/gse.d.ts.map +1 -1
  26. package/dest/contracts/gse.js +2 -2
  27. package/dest/contracts/inbox.d.ts +24 -3
  28. package/dest/contracts/inbox.d.ts.map +1 -1
  29. package/dest/contracts/inbox.js +42 -2
  30. package/dest/contracts/index.d.ts +6 -3
  31. package/dest/contracts/index.d.ts.map +1 -1
  32. package/dest/contracts/index.js +5 -2
  33. package/dest/contracts/log.d.ts +13 -0
  34. package/dest/contracts/log.d.ts.map +1 -0
  35. package/dest/contracts/log.js +1 -0
  36. package/dest/contracts/multicall.d.ts +130 -13
  37. package/dest/contracts/multicall.d.ts.map +1 -1
  38. package/dest/contracts/multicall.js +203 -93
  39. package/dest/contracts/outbox.d.ts +64 -0
  40. package/dest/contracts/outbox.d.ts.map +1 -0
  41. package/dest/contracts/outbox.js +113 -0
  42. package/dest/contracts/registry.d.ts +3 -1
  43. package/dest/contracts/registry.d.ts.map +1 -1
  44. package/dest/contracts/registry.js +30 -1
  45. package/dest/contracts/rollup.d.ts +5571 -102
  46. package/dest/contracts/rollup.d.ts.map +1 -1
  47. package/dest/contracts/rollup.js +1076 -192
  48. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +5 -5
  49. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  50. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
  51. package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
  52. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  53. package/dest/deploy_aztec_l1_contracts.js +424 -0
  54. package/dest/deploy_l1_contract.d.ts +68 -0
  55. package/dest/deploy_l1_contract.d.ts.map +1 -0
  56. package/dest/deploy_l1_contract.js +312 -0
  57. package/dest/forwarder_proxy.d.ts +32 -0
  58. package/dest/forwarder_proxy.d.ts.map +1 -0
  59. package/dest/forwarder_proxy.js +93 -0
  60. package/dest/foundry_binary.d.ts +13 -0
  61. package/dest/foundry_binary.d.ts.map +1 -0
  62. package/dest/foundry_binary.js +52 -0
  63. package/dest/l1_artifacts.d.ts +19674 -16606
  64. package/dest/l1_artifacts.d.ts.map +1 -1
  65. package/dest/l1_artifacts.js +9 -24
  66. package/dest/l1_contract_addresses.d.ts +61 -65
  67. package/dest/l1_contract_addresses.d.ts.map +1 -1
  68. package/dest/l1_contract_addresses.js +99 -80
  69. package/dest/l1_reader.d.ts +7 -5
  70. package/dest/l1_reader.d.ts.map +1 -1
  71. package/dest/l1_reader.js +15 -7
  72. package/dest/l1_tx_utils/config.d.ts +9 -3
  73. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  74. package/dest/l1_tx_utils/config.js +34 -7
  75. package/dest/l1_tx_utils/constants.d.ts +8 -2
  76. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  77. package/dest/l1_tx_utils/constants.js +27 -2
  78. package/dest/l1_tx_utils/factory.d.ts +18 -10
  79. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  80. package/dest/l1_tx_utils/factory.js +17 -7
  81. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  82. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  83. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  84. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  85. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  86. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  87. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  88. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  89. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  90. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  91. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  92. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  93. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  94. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  95. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  96. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  97. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  98. package/dest/l1_tx_utils/index-blobs.js +2 -0
  99. package/dest/l1_tx_utils/index.d.ts +4 -1
  100. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  101. package/dest/l1_tx_utils/index.js +3 -0
  102. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  103. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  104. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +252 -0
  105. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  106. package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
  107. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
  108. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  109. package/dest/l1_tx_utils/l1_tx_utils.js +202 -92
  110. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
  111. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  112. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +63 -165
  113. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  114. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  115. package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
  116. package/dest/l1_tx_utils/types.d.ts +27 -1
  117. package/dest/l1_tx_utils/types.d.ts.map +1 -1
  118. package/dest/l1_tx_utils/types.js +10 -0
  119. package/dest/publisher_manager.d.ts +34 -7
  120. package/dest/publisher_manager.d.ts.map +1 -1
  121. package/dest/publisher_manager.js +119 -8
  122. package/dest/queries.d.ts +14 -3
  123. package/dest/queries.d.ts.map +1 -1
  124. package/dest/queries.js +80 -7
  125. package/dest/test/blob_kzg_warmup.d.ts +19 -0
  126. package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
  127. package/dest/test/blob_kzg_warmup.js +64 -0
  128. package/dest/test/chain_monitor.d.ts +55 -4
  129. package/dest/test/chain_monitor.d.ts.map +1 -1
  130. package/dest/test/chain_monitor.js +105 -5
  131. package/dest/test/eth_cheat_codes.d.ts +49 -6
  132. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  133. package/dest/test/eth_cheat_codes.js +93 -43
  134. package/dest/test/index.d.ts +2 -3
  135. package/dest/test/index.d.ts.map +1 -1
  136. package/dest/test/index.js +1 -2
  137. package/dest/test/rollup_cheat_codes.d.ts +64 -4
  138. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  139. package/dest/test/rollup_cheat_codes.js +109 -8
  140. package/dest/test/start_anvil.d.ts +24 -2
  141. package/dest/test/start_anvil.d.ts.map +1 -1
  142. package/dest/test/start_anvil.js +182 -32
  143. package/dest/test/upgrade_utils.js +2 -2
  144. package/dest/types.d.ts +57 -2
  145. package/dest/types.d.ts.map +1 -1
  146. package/dest/utils.d.ts +24 -4
  147. package/dest/utils.d.ts.map +1 -1
  148. package/dest/utils.js +112 -16
  149. package/package.json +31 -15
  150. package/src/client.ts +66 -2
  151. package/src/config.ts +153 -469
  152. package/src/contracts/README.md +157 -0
  153. package/src/contracts/chain_state_override.ts +200 -0
  154. package/src/contracts/empire_base.ts +1 -1
  155. package/src/contracts/fee_asset_handler.ts +10 -7
  156. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  157. package/src/contracts/governance.ts +279 -13
  158. package/src/contracts/governance_proposer.ts +64 -3
  159. package/src/contracts/gse.ts +7 -2
  160. package/src/contracts/inbox.ts +64 -4
  161. package/src/contracts/index.ts +5 -2
  162. package/src/contracts/log.ts +13 -0
  163. package/src/contracts/multicall.ts +247 -103
  164. package/src/contracts/outbox.ts +132 -0
  165. package/src/contracts/registry.ts +31 -1
  166. package/src/contracts/rollup.ts +789 -154
  167. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +18 -14
  168. package/src/deploy_aztec_l1_contracts.ts +664 -0
  169. package/src/deploy_l1_contract.ts +362 -0
  170. package/src/forwarder_proxy.ts +108 -0
  171. package/src/foundry_binary.ts +57 -0
  172. package/src/l1_artifacts.ts +12 -35
  173. package/src/l1_contract_addresses.ts +120 -92
  174. package/src/l1_reader.ts +25 -10
  175. package/src/l1_tx_utils/config.ts +47 -9
  176. package/src/l1_tx_utils/constants.ts +13 -2
  177. package/src/l1_tx_utils/factory.ts +31 -31
  178. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  179. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  180. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  181. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  182. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  183. package/src/l1_tx_utils/index-blobs.ts +2 -0
  184. package/src/l1_tx_utils/index.ts +3 -0
  185. package/src/l1_tx_utils/interfaces.ts +1 -1
  186. package/src/l1_tx_utils/l1_fee_analyzer.ts +875 -0
  187. package/src/l1_tx_utils/l1_tx_utils.ts +194 -72
  188. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +77 -211
  189. package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
  190. package/src/l1_tx_utils/types.ts +32 -0
  191. package/src/publisher_manager.ts +145 -12
  192. package/src/queries.ts +87 -7
  193. package/src/test/blob_kzg_warmup.ts +65 -0
  194. package/src/test/chain_monitor.ts +150 -4
  195. package/src/test/eth_cheat_codes.ts +84 -47
  196. package/src/test/index.ts +1 -2
  197. package/src/test/rollup_cheat_codes.ts +136 -8
  198. package/src/test/start_anvil.ts +213 -31
  199. package/src/test/upgrade_utils.ts +2 -2
  200. package/src/types.ts +62 -0
  201. package/src/utils.ts +128 -19
  202. package/dest/contracts/empire_slashing_proposer.d.ts +0 -66
  203. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  204. package/dest/contracts/empire_slashing_proposer.js +0 -200
  205. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  206. package/dest/deploy_l1_contracts.d.ts +0 -673
  207. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  208. package/dest/deploy_l1_contracts.js +0 -1491
  209. package/dest/index.d.ts +0 -18
  210. package/dest/index.d.ts.map +0 -1
  211. package/dest/index.js +0 -17
  212. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  213. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  214. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  215. package/dest/test/delayed_tx_utils.d.ts +0 -13
  216. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  217. package/dest/test/delayed_tx_utils.js +0 -28
  218. package/dest/test/tx_delayer.d.ts +0 -36
  219. package/dest/test/tx_delayer.d.ts.map +0 -1
  220. package/src/contracts/empire_slashing_proposer.ts +0 -265
  221. package/src/deploy_l1_contracts.ts +0 -1869
  222. package/src/index.ts +0 -17
  223. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  224. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,33 +1,551 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
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
+ };
6
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;
7
374
  import { CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
375
+ import { Buffer32 } from '@aztec/foundation/buffer';
376
+ import { Fr } from '@aztec/foundation/curves/bn254';
8
377
  import { memoize } from '@aztec/foundation/decorators';
9
378
  import { EthAddress } from '@aztec/foundation/eth-address';
379
+ import { createLogger } from '@aztec/foundation/log';
380
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
381
+ import { getErrorCause } from '@aztec/foundation/types';
382
+ import { EscapeHatchAbi } from '@aztec/l1-artifacts/EscapeHatchAbi';
10
383
  import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
11
384
  import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
12
385
  import chunk from 'lodash.chunk';
13
- import { encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
386
+ import { ContractFunctionRevertedError, RpcRequestError, decodeErrorResult, encodeAbiParameters, encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
14
387
  import { getPublicClient } from '../client.js';
15
388
  import { formatViemError } from '../utils.js';
16
- import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
17
389
  import { GSEContract } from './gse.js';
18
390
  import { SlasherContract } from './slasher_contract.js';
19
- import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
391
+ import { SlashingProposerContract } from './slashing_proposer.js';
20
392
  import { checkBlockTag } from './utils.js';
21
- export var SlashingProposerType = /*#__PURE__*/ function(SlashingProposerType) {
22
- SlashingProposerType[SlashingProposerType["None"] = 0] = "None";
23
- SlashingProposerType[SlashingProposerType["Tally"] = 1] = "Tally";
24
- SlashingProposerType[SlashingProposerType["Empire"] = 2] = "Empire";
25
- return SlashingProposerType;
393
+ /**
394
+ * Status of a validator/attester in the staking system.
395
+ * Matches the Status enum in StakingLib.sol
396
+ */ export var AttesterStatus = /*#__PURE__*/ function(AttesterStatus) {
397
+ AttesterStatus[AttesterStatus["NONE"] = 0] = "NONE";
398
+ AttesterStatus[AttesterStatus["VALIDATING"] = 1] = "VALIDATING";
399
+ AttesterStatus[AttesterStatus["ZOMBIE"] = 2] = "ZOMBIE";
400
+ AttesterStatus[AttesterStatus["EXITING"] = 3] = "EXITING";
401
+ return AttesterStatus;
402
+ }({});
403
+ /** Field offsets within the CompressedTempCheckpointLog struct in Solidity storage. */ export var TempCheckpointLogField = /*#__PURE__*/ function(TempCheckpointLogField) {
404
+ TempCheckpointLogField[TempCheckpointLogField["HeaderHash"] = 0] = "HeaderHash";
405
+ TempCheckpointLogField[TempCheckpointLogField["BlobCommitmentsHash"] = 1] = "BlobCommitmentsHash";
406
+ TempCheckpointLogField[TempCheckpointLogField["OutHash"] = 2] = "OutHash";
407
+ TempCheckpointLogField[TempCheckpointLogField["AttestationsHash"] = 3] = "AttestationsHash";
408
+ TempCheckpointLogField[TempCheckpointLogField["PayloadDigest"] = 4] = "PayloadDigest";
409
+ TempCheckpointLogField[TempCheckpointLogField["SlotNumber"] = 5] = "SlotNumber";
410
+ TempCheckpointLogField[TempCheckpointLogField["FeeHeader"] = 6] = "FeeHeader";
411
+ return TempCheckpointLogField;
26
412
  }({});
413
+ const INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR = 'ValidatorSelection__InsufficientValidatorSetSize';
414
+ function isValidatorSelectionError(err, errorName) {
415
+ return getErrorCause(err, ContractFunctionRevertedError)?.data?.errorName === errorName || decodeRpcRequestErrorName(err) === errorName;
416
+ }
417
+ function decodeRpcRequestErrorName(err) {
418
+ const data = getErrorCause(err, RpcRequestError)?.data;
419
+ if (!isHexString(data)) {
420
+ return undefined;
421
+ }
422
+ try {
423
+ return decodeErrorResult({
424
+ abi: RollupAbi,
425
+ data
426
+ }).errorName;
427
+ } catch {
428
+ return undefined;
429
+ }
430
+ }
431
+ function isHexString(value) {
432
+ return typeof value === 'string' && value.startsWith('0x');
433
+ }
27
434
  export class RollupContract {
28
435
  client;
436
+ static{
437
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
438
+ [
439
+ memoize,
440
+ 2,
441
+ "getL1StartBlock"
442
+ ],
443
+ [
444
+ memoize,
445
+ 2,
446
+ "getL1GenesisTime"
447
+ ],
448
+ [
449
+ memoize,
450
+ 2,
451
+ "getProofSubmissionEpochs"
452
+ ],
453
+ [
454
+ memoize,
455
+ 2,
456
+ "getEpochDuration"
457
+ ],
458
+ [
459
+ memoize,
460
+ 2,
461
+ "getSlotDuration"
462
+ ],
463
+ [
464
+ memoize,
465
+ 2,
466
+ "getTargetCommitteeSize"
467
+ ],
468
+ [
469
+ memoize,
470
+ 2,
471
+ "getEjectionThreshold"
472
+ ],
473
+ [
474
+ memoize,
475
+ 2,
476
+ "getLocalEjectionThreshold"
477
+ ],
478
+ [
479
+ memoize,
480
+ 2,
481
+ "getLagInEpochsForValidatorSet"
482
+ ],
483
+ [
484
+ memoize,
485
+ 2,
486
+ "getLagInEpochsForRandao"
487
+ ],
488
+ [
489
+ memoize,
490
+ 2,
491
+ "getActivationThreshold"
492
+ ],
493
+ [
494
+ memoize,
495
+ 2,
496
+ "getExitDelay"
497
+ ],
498
+ [
499
+ memoize,
500
+ 2,
501
+ "getManaTarget"
502
+ ],
503
+ [
504
+ memoize,
505
+ 2,
506
+ "getProvingCostPerMana"
507
+ ],
508
+ [
509
+ memoize,
510
+ 2,
511
+ "getProvingCostPerManaInFeeAsset"
512
+ ],
513
+ [
514
+ memoize,
515
+ 2,
516
+ "getManaLimit"
517
+ ],
518
+ [
519
+ memoize,
520
+ 2,
521
+ "getVersion"
522
+ ],
523
+ [
524
+ memoize,
525
+ 2,
526
+ "getGenesisArchiveTreeRoot"
527
+ ],
528
+ [
529
+ memoize,
530
+ 2,
531
+ "getVkTreeRoot"
532
+ ],
533
+ [
534
+ memoize,
535
+ 2,
536
+ "getProtocolContractsHash"
537
+ ],
538
+ [
539
+ memoize,
540
+ 2,
541
+ "getRollupConstants"
542
+ ]
543
+ ], []));
544
+ }
29
545
  rollup;
546
+ logger;
30
547
  static cachedStfStorageSlot;
548
+ cachedEscapeHatch;
31
549
  static get checkBlobStorageSlot() {
32
550
  const asString = RollupStorage.find((storage)=>storage.label === 'checkBlob')?.slot;
33
551
  if (asString === undefined) {
@@ -44,11 +562,12 @@ export class RollupContract {
44
562
  }
45
563
  static getFromConfig(config) {
46
564
  const client = getPublicClient(config);
47
- const address = config.l1Contracts.rollupAddress.toString();
565
+ const address = config.rollupAddress.toString();
48
566
  return new RollupContract(client, address);
49
567
  }
50
568
  constructor(client, address){
51
569
  this.client = client;
570
+ this.logger = (_initProto(this), createLogger('ethereum:rollup'));
52
571
  if (address instanceof EthAddress) {
53
572
  address = address.toString();
54
573
  }
@@ -58,8 +577,8 @@ export class RollupContract {
58
577
  client
59
578
  });
60
579
  }
61
- getGSE() {
62
- return this.rollup.read.getGSE();
580
+ async getGSE() {
581
+ return EthAddress.fromString(await this.rollup.read.getGSE());
63
582
  }
64
583
  get address() {
65
584
  return this.rollup.address;
@@ -73,34 +592,10 @@ export class RollupContract {
73
592
  return undefined;
74
593
  }
75
594
  const proposerAddress = await slasher.getProposer();
76
- const proposerAbi = [
77
- {
78
- type: 'function',
79
- name: 'SLASHING_PROPOSER_TYPE',
80
- inputs: [],
81
- outputs: [
82
- {
83
- name: '',
84
- type: 'uint8',
85
- internalType: 'enum SlasherFlavor'
86
- }
87
- ],
88
- stateMutability: 'view'
89
- }
90
- ];
91
- const proposer = getContract({
92
- address: proposerAddress.toString(),
93
- abi: proposerAbi,
94
- client: this.client
95
- });
96
- const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
97
- if (proposerType === 1..valueOf()) {
98
- return new TallySlashingProposerContract(this.client, proposerAddress);
99
- } else if (proposerType === 2..valueOf()) {
100
- return new EmpireSlashingProposerContract(this.client, proposerAddress);
101
- } else {
102
- throw new Error(`Unknown slashing proposer type: ${proposerType}`);
595
+ if (proposerAddress.isZero()) {
596
+ return undefined;
103
597
  }
598
+ return new SlashingProposerContract(this.client, proposerAddress);
104
599
  }
105
600
  getL1StartBlock() {
106
601
  return this.rollup.read.L1_BLOCK_AT_GENESIS();
@@ -108,17 +603,17 @@ export class RollupContract {
108
603
  getL1GenesisTime() {
109
604
  return this.rollup.read.getGenesisTime();
110
605
  }
111
- getProofSubmissionEpochs() {
112
- return this.rollup.read.getProofSubmissionEpochs();
606
+ async getProofSubmissionEpochs() {
607
+ return Number(await this.rollup.read.getProofSubmissionEpochs());
113
608
  }
114
- getEpochDuration() {
115
- return this.rollup.read.getEpochDuration();
609
+ async getEpochDuration() {
610
+ return Number(await this.rollup.read.getEpochDuration());
116
611
  }
117
612
  async getSlotDuration() {
118
613
  return Number(await this.rollup.read.getSlotDuration());
119
614
  }
120
- getTargetCommitteeSize() {
121
- return this.rollup.read.getTargetCommitteeSize();
615
+ async getTargetCommitteeSize() {
616
+ return Number(await this.rollup.read.getTargetCommitteeSize());
122
617
  }
123
618
  getEjectionThreshold() {
124
619
  return this.rollup.read.getEjectionThreshold();
@@ -126,17 +621,17 @@ export class RollupContract {
126
621
  getLocalEjectionThreshold() {
127
622
  return this.rollup.read.getLocalEjectionThreshold();
128
623
  }
129
- getLagInEpochsForValidatorSet() {
130
- return this.rollup.read.getLagInEpochsForValidatorSet();
624
+ async getLagInEpochsForValidatorSet() {
625
+ return Number(await this.rollup.read.getLagInEpochsForValidatorSet());
131
626
  }
132
- getLagInEpochsForRandao() {
133
- return this.rollup.read.getLagInEpochsForRandao();
627
+ async getLagInEpochsForRandao() {
628
+ return Number(await this.rollup.read.getLagInEpochsForRandao());
134
629
  }
135
630
  getActivationThreshold() {
136
631
  return this.rollup.read.getActivationThreshold();
137
632
  }
138
- getExitDelay() {
139
- return this.rollup.read.getExitDelay();
633
+ async getExitDelay() {
634
+ return Number(await this.rollup.read.getExitDelay());
140
635
  }
141
636
  getManaTarget() {
142
637
  return this.rollup.read.getManaTarget();
@@ -154,47 +649,116 @@ export class RollupContract {
154
649
  return this.rollup.read.getVersion();
155
650
  }
156
651
  async getGenesisArchiveTreeRoot() {
157
- return await this.rollup.read.archiveAt([
652
+ return Fr.fromString(await this.rollup.read.archiveAt([
158
653
  0n
159
- ]);
654
+ ]));
655
+ }
656
+ async getVkTreeRoot() {
657
+ const slot = BigInt(RollupContract.stfStorageSlot) + 3n;
658
+ const value = await this.client.getStorageAt({
659
+ address: this.address,
660
+ slot: `0x${slot.toString(16)}`
661
+ });
662
+ return Fr.fromString(value ?? '0x0');
663
+ }
664
+ async getProtocolContractsHash() {
665
+ const slot = BigInt(RollupContract.stfStorageSlot) + 4n;
666
+ const value = await this.client.getStorageAt({
667
+ address: this.address,
668
+ slot: `0x${slot.toString(16)}`
669
+ });
670
+ return Fr.fromString(value ?? '0x0');
160
671
  }
161
672
  /**
162
673
  * Returns rollup constants used for epoch queries.
163
674
  * Return type is `L1RollupConstants` which is defined in stdlib,
164
675
  * so we cant reference it until we move this contract to that package.
165
676
  */ async getRollupConstants() {
166
- const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs] = await Promise.all([
677
+ const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs, targetCommitteeSize, rollupManaLimit] = await Promise.all([
167
678
  this.getL1StartBlock(),
168
679
  this.getL1GenesisTime(),
169
680
  this.getSlotDuration(),
170
681
  this.getEpochDuration(),
171
- this.getProofSubmissionEpochs()
682
+ this.getProofSubmissionEpochs(),
683
+ this.getTargetCommitteeSize(),
684
+ this.getManaLimit()
172
685
  ]);
173
686
  return {
174
687
  l1StartBlock,
175
688
  l1GenesisTime,
176
689
  slotDuration,
177
690
  epochDuration: Number(epochDuration),
178
- proofSubmissionEpochs: Number(proofSubmissionEpochs)
691
+ proofSubmissionEpochs: Number(proofSubmissionEpochs),
692
+ targetCommitteeSize,
693
+ rollupManaLimit: Number(rollupManaLimit)
179
694
  };
180
695
  }
181
- getSlasherAddress() {
182
- return this.rollup.read.getSlasher();
696
+ async getSlasherAddress() {
697
+ return EthAddress.fromString(await this.rollup.read.getSlasher());
698
+ }
699
+ /**
700
+ * Returns the configured escape hatch contract address, or zero if disabled.
701
+ */ async getEscapeHatchAddress() {
702
+ return EthAddress.fromString(await this.rollup.read.getEscapeHatch());
703
+ }
704
+ async getEscapeHatchContract() {
705
+ const escapeHatchAddress = await this.getEscapeHatchAddress();
706
+ if (escapeHatchAddress.isZero()) {
707
+ return undefined;
708
+ }
709
+ // Cache the viem contract wrapper since it will be used frequently.
710
+ if (!this.cachedEscapeHatch || !this.cachedEscapeHatch.address.equals(escapeHatchAddress)) {
711
+ this.cachedEscapeHatch = {
712
+ address: escapeHatchAddress,
713
+ contract: getContract({
714
+ address: escapeHatchAddress.toString(),
715
+ abi: EscapeHatchAbi,
716
+ client: this.client
717
+ })
718
+ };
719
+ }
720
+ return this.cachedEscapeHatch.contract;
721
+ }
722
+ /**
723
+ * Returns whether the escape hatch is open for the given epoch.
724
+ * If escape hatch is not configured, returns false.
725
+ *
726
+ * This function is intentionally defensive: any failure to query the escape hatch
727
+ * (RPC issues, transient errors, etc.) is treated as "closed" to avoid callers
728
+ * needing to sprinkle try/catch everywhere.
729
+ */ async isEscapeHatchOpen(epoch) {
730
+ try {
731
+ const escapeHatch = await this.getEscapeHatchContract();
732
+ if (!escapeHatch) {
733
+ return false;
734
+ }
735
+ const [isOpen] = await escapeHatch.read.isHatchOpen([
736
+ BigInt(epoch)
737
+ ]);
738
+ return isOpen;
739
+ } catch (err) {
740
+ this.logger.warn('isEscapeHatchOpen failed (treating as closed); RPC or contract error may cause liveness risk', {
741
+ epoch: Number(epoch),
742
+ error: err
743
+ });
744
+ return false;
745
+ }
183
746
  }
184
747
  /**
185
748
  * Returns a SlasherContract instance for interacting with the slasher contract.
186
749
  */ async getSlasherContract() {
187
- const slasherAddress = EthAddress.fromString(await this.getSlasherAddress());
750
+ const slasherAddress = await this.getSlasherAddress();
188
751
  if (slasherAddress.isZero()) {
189
752
  return undefined;
190
753
  }
191
754
  return new SlasherContract(this.client, slasherAddress);
192
755
  }
193
- getOwner() {
194
- return this.rollup.read.owner();
756
+ async getOwner() {
757
+ return EthAddress.fromString(await this.rollup.read.owner());
195
758
  }
196
- getActiveAttesterCount() {
197
- return this.rollup.read.getActiveAttesterCount();
759
+ async getActiveAttesterCount(options) {
760
+ await checkBlockTag(options?.blockNumber, this.client);
761
+ return Number(await this.rollup.read.getActiveAttesterCount(options));
198
762
  }
199
763
  async getSlashingProposerAddress() {
200
764
  const slasher = await this.getSlasherContract();
@@ -206,22 +770,42 @@ export class RollupContract {
206
770
  getCheckpointReward() {
207
771
  return this.rollup.read.getCheckpointReward();
208
772
  }
209
- async getCheckpointNumber() {
210
- return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber());
773
+ async getCheckpointNumber(options) {
774
+ await checkBlockTag(options?.blockNumber, this.client);
775
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getPendingCheckpointNumber(options));
211
776
  }
212
- async getProvenCheckpointNumber() {
213
- return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber());
777
+ async getProvenCheckpointNumber(options) {
778
+ await checkBlockTag(options?.blockNumber, this.client);
779
+ return CheckpointNumber.fromBigInt(await this.rollup.read.getProvenCheckpointNumber(options));
214
780
  }
215
- async getSlotNumber() {
216
- return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot());
781
+ async getSlotNumber(options) {
782
+ await checkBlockTag(options?.blockNumber, this.client);
783
+ return SlotNumber.fromBigInt(await this.rollup.read.getCurrentSlot(options));
217
784
  }
218
- getL1FeesAt(timestamp) {
219
- return this.rollup.read.getL1FeesAt([
785
+ async getL1FeesAt(timestamp, options) {
786
+ await checkBlockTag(options?.blockNumber, this.client);
787
+ const result = await this.rollup.read.getL1FeesAt([
220
788
  timestamp
789
+ ], options);
790
+ return {
791
+ baseFee: result.baseFee,
792
+ blobFee: result.blobFee
793
+ };
794
+ }
795
+ async getFeeHeader(checkpointNumber) {
796
+ const result = await this.rollup.read.getFeeHeader([
797
+ checkpointNumber
221
798
  ]);
799
+ return {
800
+ excessMana: result.excessMana,
801
+ manaUsed: result.manaUsed,
802
+ ethPerFeeAsset: result.ethPerFeeAsset,
803
+ congestionCost: result.congestionCost,
804
+ proverCost: result.proverCost
805
+ };
222
806
  }
223
- getFeeAssetPerEth() {
224
- return this.rollup.read.getFeeAssetPerEth();
807
+ getEthPerFeeAsset() {
808
+ return this.rollup.read.getEthPerFeeAsset();
225
809
  }
226
810
  async getCommitteeAt(timestamp) {
227
811
  const { result } = await this.client.simulateContract({
@@ -232,22 +816,22 @@ export class RollupContract {
232
816
  timestamp
233
817
  ]
234
818
  }).catch((e)=>{
235
- if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
819
+ if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
236
820
  return {
237
821
  result: undefined
238
822
  };
239
823
  }
240
824
  throw e;
241
825
  });
242
- return result;
826
+ return result ? result.map((addr)=>EthAddress.fromString(addr)) : undefined;
243
827
  }
244
- getSampleSeedAt(timestamp) {
245
- return this.rollup.read.getSampleSeedAt([
828
+ async getSampleSeedAt(timestamp) {
829
+ return Buffer32.fromBigInt(await this.rollup.read.getSampleSeedAt([
246
830
  timestamp
247
- ]);
831
+ ]));
248
832
  }
249
- getCurrentSampleSeed() {
250
- return this.rollup.read.getCurrentSampleSeed();
833
+ async getCurrentSampleSeed() {
834
+ return Buffer32.fromBigInt(await this.rollup.read.getCurrentSampleSeed());
251
835
  }
252
836
  async getCurrentEpoch() {
253
837
  return EpochNumber.fromBigInt(await this.rollup.read.getCurrentEpoch());
@@ -259,14 +843,14 @@ export class RollupContract {
259
843
  functionName: 'getCurrentEpochCommittee',
260
844
  args: []
261
845
  }).catch((e)=>{
262
- if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
846
+ if (isValidatorSelectionError(e, INSUFFICIENT_VALIDATOR_SET_SIZE_ERROR)) {
263
847
  return {
264
848
  result: undefined
265
849
  };
266
850
  }
267
851
  throw e;
268
852
  });
269
- return result;
853
+ return result ? result.map((addr)=>EthAddress.fromString(addr)) : undefined;
270
854
  }
271
855
  async getCurrentProposer() {
272
856
  const { result } = await this.client.simulateContract({
@@ -275,7 +859,7 @@ export class RollupContract {
275
859
  functionName: 'getCurrentProposer',
276
860
  args: []
277
861
  });
278
- return result;
862
+ return EthAddress.fromString(result);
279
863
  }
280
864
  async getProposerAt(timestamp) {
281
865
  const { result } = await this.client.simulateContract({
@@ -286,12 +870,63 @@ export class RollupContract {
286
870
  timestamp
287
871
  ]
288
872
  });
289
- return result;
873
+ return EthAddress.fromString(result);
290
874
  }
291
- getCheckpoint(checkpointNumber) {
292
- return this.rollup.read.getCheckpoint([
875
+ async getCheckpoint(checkpointNumber, options) {
876
+ await checkBlockTag(options?.blockNumber, this.client);
877
+ const result = await this.rollup.read.getCheckpoint([
293
878
  BigInt(checkpointNumber)
294
- ]);
879
+ ], options);
880
+ return {
881
+ archive: Fr.fromString(result.archive),
882
+ headerHash: Buffer32.fromString(result.headerHash),
883
+ blobCommitmentsHash: Buffer32.fromString(result.blobCommitmentsHash),
884
+ attestationsHash: Buffer32.fromString(result.attestationsHash),
885
+ payloadDigest: Buffer32.fromString(result.payloadDigest),
886
+ slotNumber: SlotNumber.fromBigInt(result.slotNumber),
887
+ feeHeader: {
888
+ excessMana: result.feeHeader.excessMana,
889
+ manaUsed: result.feeHeader.manaUsed,
890
+ ethPerFeeAsset: result.feeHeader.ethPerFeeAsset,
891
+ congestionCost: result.feeHeader.congestionCost,
892
+ proverCost: result.feeHeader.proverCost
893
+ }
894
+ };
895
+ }
896
+ /** Returns the pending checkpoint from the rollup contract */ getPendingCheckpoint() {
897
+ // We retry because of race conditions during prunes: we may get a pending checkpoint number which is immediately
898
+ // reorged out due to a prune happening, causing the subsequent getCheckpoint call to fail. So we try again in that case.
899
+ return retry(async ()=>{
900
+ const pendingCheckpointNumber = await this.getCheckpointNumber();
901
+ const pendingCheckpoint = await this.getCheckpoint(pendingCheckpointNumber);
902
+ return pendingCheckpoint;
903
+ }, 'getting pending checkpoint', makeBackoff([
904
+ 0.5,
905
+ 0.5,
906
+ 0.5
907
+ ]));
908
+ }
909
+ /**
910
+ * Returns the effective pending checkpoint, accounting for potential prunes.
911
+ * When a prune can happen, the L1 contract uses the proven checkpoint instead of the pending one.
912
+ * This mirrors the behavior of getEffectivePendingCheckpointNumber in STFLib.sol.
913
+ * @param atTimestamp - The timestamp to evaluate pruneability at. Defaults to the current L1 block timestamp.
914
+ * @param options - Optional L1 block number to pin the queries to.
915
+ */ getEffectivePendingCheckpoint(atTimestamp, options) {
916
+ return retry(async ()=>{
917
+ const timestamp = atTimestamp ?? (await this.client.getBlock()).timestamp;
918
+ const canPrune = await this.canPruneAtTime(timestamp, options);
919
+ if (canPrune) {
920
+ const provenCheckpointNumber = await this.getProvenCheckpointNumber(options);
921
+ return await this.getCheckpoint(provenCheckpointNumber, options);
922
+ }
923
+ const pendingCheckpointNumber = await this.getCheckpointNumber(options);
924
+ return await this.getCheckpoint(pendingCheckpointNumber, options);
925
+ }, 'getting effective pending checkpoint', makeBackoff([
926
+ 0.5,
927
+ 0.5,
928
+ 0.5
929
+ ]));
295
930
  }
296
931
  async getTips() {
297
932
  const { pending, proven } = await this.rollup.read.getTips();
@@ -305,11 +940,11 @@ export class RollupContract {
305
940
  BigInt(slot)
306
941
  ]);
307
942
  }
308
- getEntryQueueLength() {
309
- return this.rollup.read.getEntryQueueLength();
943
+ async getEntryQueueLength() {
944
+ return Number(await this.rollup.read.getEntryQueueLength());
310
945
  }
311
- getAvailableValidatorFlushes() {
312
- return this.rollup.read.getAvailableValidatorFlushes();
946
+ async getAvailableValidatorFlushes() {
947
+ return Number(await this.rollup.read.getAvailableValidatorFlushes());
313
948
  }
314
949
  async getNextFlushableEpoch() {
315
950
  return EpochNumber.fromBigInt(await this.rollup.read.getNextFlushableEpoch());
@@ -351,8 +986,9 @@ export class RollupContract {
351
986
  BigInt(slotNumber)
352
987
  ]));
353
988
  }
354
- getEpochProofPublicInputs(args) {
355
- return this.rollup.read.getEpochProofPublicInputs(args);
989
+ async getEpochProofPublicInputs(args) {
990
+ const result = await this.rollup.read.getEpochProofPublicInputs(args);
991
+ return result.map(Fr.fromString);
356
992
  }
357
993
  async validateHeader(args, account) {
358
994
  try {
@@ -376,9 +1012,8 @@ export class RollupContract {
376
1012
  * @return [slot, checkpointNumber, timeOfNextL1Slot] - If you can propose, the L2 slot number, checkpoint number and
377
1013
  * timestamp of the next L1 block
378
1014
  * @throws otherwise
379
- */ async canProposeAtNextEthBlock(archive, account, slotDuration, opts = {}) {
380
- const latestBlock = await this.client.getBlock();
381
- const timeOfNextL1Slot = latestBlock.timestamp + BigInt(slotDuration);
1015
+ */ async canProposeAt(archive, account, timestamp, stateOverride = []) {
1016
+ const timeOfNextL1Slot = timestamp;
382
1017
  const who = typeof account === 'string' ? account : account.address;
383
1018
  try {
384
1019
  const { result: [slot, checkpointNumber] } = await this.client.simulateContract({
@@ -391,7 +1026,7 @@ export class RollupContract {
391
1026
  who
392
1027
  ],
393
1028
  account,
394
- stateOverride: await this.makePendingCheckpointNumberOverride(opts.forcePendingCheckpointNumber)
1029
+ stateOverride
395
1030
  });
396
1031
  return {
397
1032
  slot: SlotNumber.fromBigInt(slot),
@@ -403,11 +1038,15 @@ export class RollupContract {
403
1038
  }
404
1039
  }
405
1040
  /**
406
- * Returns a state override that sets the pending checkpoint number to the specified value. Useful for simulations.
407
- * Requires querying the current state of the contract to get the current proven checkpoint number, as they are both
408
- * stored in the same slot. If the argument is undefined, it returns an empty override.
409
- */ async makePendingCheckpointNumberOverride(forcePendingCheckpointNumber) {
410
- if (forcePendingCheckpointNumber === undefined) {
1041
+ * Returns a state override that sets the pending and/or proven checkpoint numbers. Useful for simulations.
1042
+ * Both values share a single storage slot (pending in the upper 128 bits, proven in the lower 128 bits), so
1043
+ * a single combined override is emitted to avoid the second state-diff clobbering the first. The current live
1044
+ * value is read once to preserve any half not being overridden. Returns an empty override if neither is set.
1045
+ *
1046
+ * Throws if the resulting `proven > pending`, which would crash the simulation: `STFLib.canPruneAtTime` calls
1047
+ * `getEpochForCheckpoint(proven + 1)` whenever `pending != proven`, and that asserts `_n <= tips.pending`.
1048
+ */ async makeChainTipsOverride(override) {
1049
+ if (override.pending === undefined && override.proven === undefined) {
411
1050
  return [];
412
1051
  }
413
1052
  const slot = RollupContract.stfStorageSlot;
@@ -415,8 +1054,15 @@ export class RollupContract {
415
1054
  address: this.address,
416
1055
  slot
417
1056
  });
418
- const currentProvenCheckpointNumber = currentValue ? hexToBigInt(currentValue) & (1n << 128n) - 1n : 0n;
419
- const newValue = BigInt(forcePendingCheckpointNumber) << 128n | currentProvenCheckpointNumber;
1057
+ const currentRaw = currentValue ? hexToBigInt(currentValue) : 0n;
1058
+ const currentPending = currentRaw >> 128n;
1059
+ const currentProven = currentRaw & (1n << 128n) - 1n;
1060
+ const newPending = override.pending !== undefined ? BigInt(override.pending) : currentPending;
1061
+ const newProven = override.proven !== undefined ? BigInt(override.proven) : currentProven;
1062
+ if (newProven > newPending) {
1063
+ throw new Error(`Invalid chain tips override: proven (${newProven}) > pending (${newPending})`);
1064
+ }
1065
+ const newValue = newPending << 128n | newProven;
420
1066
  return [
421
1067
  {
422
1068
  address: this.address,
@@ -429,9 +1075,165 @@ export class RollupContract {
429
1075
  }
430
1076
  ];
431
1077
  }
1078
+ /**
1079
+ * Returns a state override that patches `tempCheckpointLogs[checkpointNumber]` with every field that
1080
+ * the L1 contract reads during `propose()` for the checkpoint that builds on top of it (proposer
1081
+ * pipelining simulation). Mirrors the writes done by `ProposeLib.addTempCheckpointLog`.
1082
+ *
1083
+ * `blobCommitmentsHash` and `attestationsHash` are intentionally not exposed here — the propose path
1084
+ * never asserts against them, so leaving them at storage zero is harmless.
1085
+ */ async makeTempCheckpointLogOverride(checkpointNumber, fields) {
1086
+ const constants = await this.getRollupConstants();
1087
+ const slotAt = (field)=>`0x${this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants).toString(16).padStart(64, '0')}`;
1088
+ const word = (v)=>`0x${v.toString(16).padStart(64, '0')}`;
1089
+ const stateDiff = [];
1090
+ if (fields.headerHash) {
1091
+ stateDiff.push({
1092
+ slot: slotAt(0),
1093
+ value: fields.headerHash.toString()
1094
+ });
1095
+ }
1096
+ if (fields.outHash) {
1097
+ stateDiff.push({
1098
+ slot: slotAt(2),
1099
+ value: fields.outHash.toString()
1100
+ });
1101
+ }
1102
+ if (fields.payloadDigest) {
1103
+ stateDiff.push({
1104
+ slot: slotAt(4),
1105
+ value: fields.payloadDigest.toString()
1106
+ });
1107
+ }
1108
+ if (fields.slotNumber !== undefined) {
1109
+ // CompressedSlot is uint32 on L1 (SafeCast.toUint32 reverts on overflow). Match that behavior here
1110
+ // so a malformed override surfaces immediately rather than silently truncating into a wrong slot.
1111
+ const slotNumber = BigInt(fields.slotNumber);
1112
+ if (slotNumber < 0n || slotNumber > 0xffffffffn) {
1113
+ throw new Error(`slotNumber ${slotNumber} does not fit in uint32`);
1114
+ }
1115
+ stateDiff.push({
1116
+ slot: slotAt(5),
1117
+ value: word(slotNumber)
1118
+ });
1119
+ }
1120
+ if (fields.feeHeader) {
1121
+ stateDiff.push({
1122
+ slot: slotAt(6),
1123
+ value: word(RollupContract.compressFeeHeader(fields.feeHeader))
1124
+ });
1125
+ }
1126
+ if (stateDiff.length === 0) {
1127
+ return [];
1128
+ }
1129
+ return [
1130
+ {
1131
+ address: this.address,
1132
+ stateDiff
1133
+ }
1134
+ ];
1135
+ }
1136
+ /**
1137
+ * Returns a state override that sets archives[checkpointNumber] to the given archive value.
1138
+ * Used when simulating a canProposeAtTime call where the local archive differs from L1
1139
+ * (e.g. pipelining where the parent checkpoint hasn't landed on L1 yet).
1140
+ */ makeArchiveOverride(checkpointNumber, archive) {
1141
+ const archivesMappingBase = hexToBigInt(RollupContract.stfStorageSlot) + 1n;
1142
+ const archiveSlot = hexToBigInt(keccak256(encodeAbiParameters([
1143
+ {
1144
+ type: 'uint256'
1145
+ },
1146
+ {
1147
+ type: 'uint256'
1148
+ }
1149
+ ], [
1150
+ BigInt(checkpointNumber),
1151
+ archivesMappingBase
1152
+ ])));
1153
+ return [
1154
+ {
1155
+ address: this.address,
1156
+ stateDiff: [
1157
+ {
1158
+ slot: `0x${archiveSlot.toString(16).padStart(64, '0')}`,
1159
+ value: archive.toString()
1160
+ }
1161
+ ]
1162
+ }
1163
+ ];
1164
+ }
1165
+ /** Merges multiple StateOverride arrays, combining stateDiff entries for the same address. */ static mergeStateOverrides(...overrides) {
1166
+ const byAddress = new Map();
1167
+ for (const override of overrides){
1168
+ for (const entry of override){
1169
+ const key = entry.address.toLowerCase();
1170
+ const existing = byAddress.get(key);
1171
+ if (existing) {
1172
+ existing.stateDiff.push(...entry.stateDiff ?? []);
1173
+ if (entry.balance !== undefined) {
1174
+ existing.balance = entry.balance;
1175
+ }
1176
+ } else {
1177
+ byAddress.set(key, {
1178
+ address: entry.address,
1179
+ balance: entry.balance,
1180
+ stateDiff: [
1181
+ ...entry.stateDiff ?? []
1182
+ ]
1183
+ });
1184
+ }
1185
+ }
1186
+ }
1187
+ return [
1188
+ ...byAddress.values()
1189
+ ];
1190
+ }
1191
+ /** Compresses a FeeHeader into a uint256 matching FeeHeaderLib.compress() in FeeStructs.sol. */ static compressFeeHeader(feeHeader) {
1192
+ const MASK_48_BITS = (1n << 48n) - 1n;
1193
+ const MASK_64_BITS = (1n << 64n) - 1n;
1194
+ const MASK_63_BITS = (1n << 63n) - 1n;
1195
+ let value = BigInt(feeHeader.manaUsed) & (1n << 32n) - 1n; // bits [0:31]
1196
+ value |= (feeHeader.excessMana < MASK_48_BITS ? feeHeader.excessMana : MASK_48_BITS) << 32n; // bits [32:79]
1197
+ value |= (BigInt(feeHeader.ethPerFeeAsset) & MASK_48_BITS) << 80n; // bits [80:127]
1198
+ value |= (feeHeader.congestionCost < MASK_64_BITS ? feeHeader.congestionCost : MASK_64_BITS) << 128n; // bits [128:191]
1199
+ value |= (feeHeader.proverCost < MASK_63_BITS ? feeHeader.proverCost : MASK_63_BITS) << 192n; // bits [192:254]
1200
+ value |= 1n << 255n; // preheat flag
1201
+ return value;
1202
+ }
1203
+ /** Computes the fee header for a child checkpoint given parent fee header and child data.
1204
+ * Must stay in sync with Solidity FeeLib.sol (computeNewEthPerFeeAsset, clampedAdd). */ static computeChildFeeHeader(parentFeeHeader, childManaUsed, feeAssetPriceModifier, manaTarget) {
1205
+ const MIN_ETH_PER_FEE_ASSET = 100n;
1206
+ const MAX_ETH_PER_FEE_ASSET = 100_000_000_000_000n; // 1e14, matches FeeLib.sol
1207
+ // excessMana = clampedAdd(parent.excessMana + parent.manaUsed, -manaTarget)
1208
+ const sum = parentFeeHeader.excessMana + parentFeeHeader.manaUsed;
1209
+ const excessMana = sum > manaTarget ? sum - manaTarget : 0n;
1210
+ // ethPerFeeAsset = computeNewEthPerFeeAsset(max(parent.ethPerFeeAsset, MIN), modifier)
1211
+ const parentPrice = parentFeeHeader.ethPerFeeAsset > MIN_ETH_PER_FEE_ASSET ? parentFeeHeader.ethPerFeeAsset : MIN_ETH_PER_FEE_ASSET;
1212
+ let newPrice;
1213
+ if (feeAssetPriceModifier >= 0n) {
1214
+ newPrice = parentPrice * (10_000n + feeAssetPriceModifier) / 10_000n;
1215
+ } else {
1216
+ const absMod = -feeAssetPriceModifier;
1217
+ newPrice = parentPrice * (10_000n - absMod) / 10_000n;
1218
+ }
1219
+ if (newPrice < MIN_ETH_PER_FEE_ASSET) {
1220
+ newPrice = MIN_ETH_PER_FEE_ASSET;
1221
+ }
1222
+ if (newPrice > MAX_ETH_PER_FEE_ASSET) {
1223
+ newPrice = MAX_ETH_PER_FEE_ASSET;
1224
+ }
1225
+ return {
1226
+ excessMana,
1227
+ manaUsed: childManaUsed,
1228
+ ethPerFeeAsset: newPrice,
1229
+ congestionCost: 0n,
1230
+ proverCost: 0n
1231
+ };
1232
+ }
432
1233
  /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */ buildInvalidateBadAttestationRequest(checkpointNumber, attestationsAndSigners, committee, invalidIndex) {
433
1234
  return {
434
1235
  to: this.address,
1236
+ abi: RollupAbi,
435
1237
  data: encodeFunctionData({
436
1238
  abi: RollupAbi,
437
1239
  functionName: 'invalidateBadAttestation',
@@ -447,6 +1249,7 @@ export class RollupContract {
447
1249
  /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */ buildInvalidateInsufficientAttestationsRequest(checkpointNumber, attestationsAndSigners, committee) {
448
1250
  return {
449
1251
  to: this.address,
1252
+ abi: RollupAbi,
450
1253
  data: encodeFunctionData({
451
1254
  abi: RollupAbi,
452
1255
  functionName: 'invalidateInsufficientAttestations',
@@ -468,11 +1271,25 @@ export class RollupContract {
468
1271
  prover
469
1272
  ]);
470
1273
  }
471
- getManaBaseFeeAt(timestamp, inFeeAsset) {
472
- return this.rollup.read.getManaBaseFeeAt([
1274
+ getManaMinFeeAt(timestamp, inFeeAsset, stateOverride) {
1275
+ return this.rollup.read.getManaMinFeeAt([
1276
+ timestamp,
1277
+ inFeeAsset
1278
+ ], {
1279
+ stateOverride
1280
+ });
1281
+ }
1282
+ async getManaMinFeeComponentsAt(timestamp, inFeeAsset) {
1283
+ const result = await this.rollup.read.getManaMinFeeComponentsAt([
473
1284
  timestamp,
474
1285
  inFeeAsset
475
1286
  ]);
1287
+ return {
1288
+ sequencerCost: result.sequencerCost,
1289
+ proverCost: result.proverCost,
1290
+ congestionCost: result.congestionCost,
1291
+ congestionMultiplier: result.congestionMultiplier
1292
+ };
476
1293
  }
477
1294
  async getSlotAt(timestamp) {
478
1295
  return SlotNumber.fromBigInt(await this.rollup.read.getSlotAt([
@@ -481,9 +1298,16 @@ export class RollupContract {
481
1298
  }
482
1299
  async status(checkpointNumber, options) {
483
1300
  await checkBlockTag(options?.blockNumber, this.client);
484
- return this.rollup.read.status([
1301
+ const result = await this.rollup.read.status([
485
1302
  BigInt(checkpointNumber)
486
1303
  ], options);
1304
+ return {
1305
+ provenCheckpointNumber: CheckpointNumber.fromBigInt(result[0]),
1306
+ provenArchive: Fr.fromString(result[1]),
1307
+ pendingCheckpointNumber: CheckpointNumber.fromBigInt(result[2]),
1308
+ pendingArchive: Fr.fromString(result[3]),
1309
+ archiveOfMyCheckpoint: Fr.fromString(result[4])
1310
+ };
487
1311
  }
488
1312
  async canPruneAtTime(timestamp, options) {
489
1313
  await checkBlockTag(options?.blockNumber, this.client);
@@ -491,13 +1315,13 @@ export class RollupContract {
491
1315
  timestamp
492
1316
  ], options);
493
1317
  }
494
- archive() {
495
- return this.rollup.read.archive();
1318
+ async archive() {
1319
+ return Fr.fromString(await this.rollup.read.archive());
496
1320
  }
497
- archiveAt(checkpointNumber) {
498
- return this.rollup.read.archiveAt([
1321
+ async archiveAt(checkpointNumber) {
1322
+ return Fr.fromString(await this.rollup.read.archiveAt([
499
1323
  BigInt(checkpointNumber)
500
- ]);
1324
+ ]));
501
1325
  }
502
1326
  getSequencerRewards(address) {
503
1327
  if (address instanceof EthAddress) {
@@ -516,49 +1340,85 @@ export class RollupContract {
516
1340
  prover
517
1341
  ]);
518
1342
  }
519
- async getAttesters() {
520
- const attesterSize = await this.getActiveAttesterCount();
1343
+ async getAttesters(timestamp) {
1344
+ // Pin every read to a single L1 block so the attester count and the chunked index reads
1345
+ // observe a consistent set. Without this, the count and each chunk default to `latest` and
1346
+ // can straddle a block boundary (or reorg), yielding an inconsistent or truncated set.
1347
+ const block = await this.client.getBlock();
1348
+ const blockNumber = block.number ?? undefined;
1349
+ const ts = timestamp ?? block.timestamp;
1350
+ const attesterSize = await this.getActiveAttesterCount({
1351
+ blockNumber
1352
+ });
521
1353
  const gse = new GSEContract(this.client, await this.getGSE());
522
- const ts = (await this.client.getBlock()).timestamp;
523
1354
  const indices = Array.from({
524
- length: Number(attesterSize)
1355
+ length: attesterSize
525
1356
  }, (_, i)=>BigInt(i));
526
1357
  const chunks = chunk(indices, 1000);
527
- return (await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)))).flat();
1358
+ const results = await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk, {
1359
+ blockNumber
1360
+ })));
1361
+ return results.flat().map((addr)=>EthAddress.fromString(addr));
528
1362
  }
529
- getAttesterView(address) {
1363
+ async getAttesterView(address) {
530
1364
  if (address instanceof EthAddress) {
531
1365
  address = address.toString();
532
1366
  }
533
- return this.rollup.read.getAttesterView([
1367
+ const result = await this.rollup.read.getAttesterView([
534
1368
  address
535
1369
  ]);
1370
+ return {
1371
+ status: result.status,
1372
+ effectiveBalance: result.effectiveBalance,
1373
+ exit: {
1374
+ withdrawalId: result.exit.withdrawalId,
1375
+ amount: result.exit.amount,
1376
+ exitableAt: result.exit.exitableAt,
1377
+ recipientOrWithdrawer: EthAddress.fromString(result.exit.recipientOrWithdrawer),
1378
+ isRecipient: result.exit.isRecipient,
1379
+ exists: result.exit.exists
1380
+ },
1381
+ config: {
1382
+ publicKey: {
1383
+ x: result.config.publicKey.x,
1384
+ y: result.config.publicKey.y
1385
+ },
1386
+ withdrawer: EthAddress.fromString(result.config.withdrawer)
1387
+ }
1388
+ };
536
1389
  }
537
- getStatus(address) {
1390
+ async getStatus(address) {
538
1391
  if (address instanceof EthAddress) {
539
1392
  address = address.toString();
540
1393
  }
541
- return this.rollup.read.getStatus([
1394
+ return await this.rollup.read.getStatus([
542
1395
  address
543
1396
  ]);
544
1397
  }
545
- getBlobCommitmentsHash(checkpointNumber) {
546
- return this.rollup.read.getBlobCommitmentsHash([
1398
+ async getBlobCommitmentsHash(checkpointNumber) {
1399
+ return Buffer32.fromString(await this.rollup.read.getBlobCommitmentsHash([
547
1400
  BigInt(checkpointNumber)
548
- ]);
1401
+ ]));
549
1402
  }
550
- getCurrentBlobCommitmentsHash() {
551
- return this.rollup.read.getCurrentBlobCommitmentsHash();
1403
+ async getCurrentBlobCommitmentsHash() {
1404
+ return Buffer32.fromString(await this.rollup.read.getCurrentBlobCommitmentsHash());
552
1405
  }
553
- getStakingAsset() {
554
- return this.rollup.read.getStakingAsset();
1406
+ async getStakingAsset() {
1407
+ return EthAddress.fromString(await this.rollup.read.getStakingAsset());
555
1408
  }
556
- getRewardConfig() {
557
- return this.rollup.read.getRewardConfig();
1409
+ async getRewardConfig() {
1410
+ const result = await this.rollup.read.getRewardConfig();
1411
+ return {
1412
+ rewardDistributor: EthAddress.fromString(result.rewardDistributor),
1413
+ sequencerBps: BigInt(result.sequencerBps),
1414
+ booster: EthAddress.fromString(result.booster),
1415
+ checkpointReward: result.checkpointReward
1416
+ };
558
1417
  }
559
1418
  setupEpoch(l1TxUtils) {
560
1419
  return l1TxUtils.sendAndMonitorTransaction({
561
1420
  to: this.address,
1421
+ abi: RollupAbi,
562
1422
  data: encodeFunctionData({
563
1423
  abi: RollupAbi,
564
1424
  functionName: 'setupEpoch',
@@ -569,6 +1429,7 @@ export class RollupContract {
569
1429
  vote(l1TxUtils, proposalId) {
570
1430
  return l1TxUtils.sendAndMonitorTransaction({
571
1431
  to: this.address,
1432
+ abi: RollupAbi,
572
1433
  data: encodeFunctionData({
573
1434
  abi: RollupAbi,
574
1435
  functionName: 'vote',
@@ -597,7 +1458,8 @@ export class RollupContract {
597
1458
  const args = log.args;
598
1459
  if (args.checkpointNumber !== undefined) {
599
1460
  callback({
600
- checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber)
1461
+ checkpointNumber: CheckpointNumber.fromBigInt(args.checkpointNumber),
1462
+ event: log
601
1463
  });
602
1464
  }
603
1465
  }
@@ -628,61 +1490,83 @@ export class RollupContract {
628
1490
  }
629
1491
  });
630
1492
  }
1493
+ /**
1494
+ * Fetches OwnershipTransferred events emitted on the L1 block this rollup was deployed on.
1495
+ * The Rollup inherits from Ownable and emits this event in its constructor, so the event
1496
+ * is guaranteed to exist on `l1StartBlock` for any correctly deployed rollup. Used as a
1497
+ * probe to detect RPC nodes that prune historical logs.
1498
+ */ async getOwnershipTransferredEventsAtDeploy() {
1499
+ const l1StartBlock = await this.getL1StartBlock();
1500
+ return await this.rollup.getEvents.OwnershipTransferred({}, {
1501
+ fromBlock: l1StartBlock,
1502
+ toBlock: l1StartBlock
1503
+ });
1504
+ }
1505
+ /** Fetches CheckpointProposed events within the given block range. */ async getCheckpointProposedEvents(fromBlock, toBlock) {
1506
+ const logs = await this.rollup.getEvents.CheckpointProposed({}, {
1507
+ fromBlock,
1508
+ toBlock
1509
+ });
1510
+ return logs.filter((log)=>log.blockNumber >= fromBlock && log.blockNumber <= toBlock).map((log)=>({
1511
+ l1BlockNumber: log.blockNumber,
1512
+ l1BlockHash: Buffer32.fromString(log.blockHash),
1513
+ l1TransactionHash: log.transactionHash,
1514
+ args: {
1515
+ checkpointNumber: CheckpointNumber.fromBigInt(log.args.checkpointNumber),
1516
+ archive: Fr.fromString(log.args.archive),
1517
+ versionedBlobHashes: log.args.versionedBlobHashes.map((h)=>Buffer.from(h.slice(2), 'hex')),
1518
+ attestationsHash: (()=>{
1519
+ if (!log.args.attestationsHash) {
1520
+ throw new Error(`CheckpointProposed event missing attestationsHash for checkpoint ${log.args.checkpointNumber}`);
1521
+ }
1522
+ return Buffer32.fromString(log.args.attestationsHash);
1523
+ })(),
1524
+ payloadDigest: (()=>{
1525
+ if (!log.args.payloadDigest) {
1526
+ throw new Error(`CheckpointProposed event missing payloadDigest for checkpoint ${log.args.checkpointNumber}`);
1527
+ }
1528
+ return Buffer32.fromString(log.args.payloadDigest);
1529
+ })()
1530
+ }
1531
+ }));
1532
+ }
1533
+ /** Packs pending and proven checkpoint numbers into the chain tips storage format. */ static packChainTips(pendingCheckpointNumber, provenCheckpointNumber) {
1534
+ return pendingCheckpointNumber << 128n | provenCheckpointNumber & (1n << 128n) - 1n;
1535
+ }
1536
+ /** Storage slot for the chain tips (offset 0 within the STF storage struct). */ static get chainTipsStorageSlot() {
1537
+ return BigInt(RollupContract.stfStorageSlot);
1538
+ }
1539
+ /**
1540
+ * Computes the storage slot for a field within a tempCheckpointLog entry.
1541
+ * @param checkpointNumber - The checkpoint number
1542
+ * @param field - The field within the CompressedTempCheckpointLog struct
1543
+ */ async getTempCheckpointLogStorageSlot(checkpointNumber, field) {
1544
+ const [epochDuration, proofSubmissionEpochs] = await Promise.all([
1545
+ this.getEpochDuration(),
1546
+ this.getProofSubmissionEpochs()
1547
+ ]);
1548
+ return this.computeTempCheckpointLogStorageSlot(checkpointNumber, field, {
1549
+ epochDuration,
1550
+ proofSubmissionEpochs
1551
+ });
1552
+ }
1553
+ computeTempCheckpointLogStorageSlot(checkpointNumber, field, constants) {
1554
+ const fieldOffset = BigInt(field);
1555
+ const { epochDuration, proofSubmissionEpochs } = constants;
1556
+ const roundaboutSize = BigInt(epochDuration) * (BigInt(proofSubmissionEpochs) + 1n) + 1n;
1557
+ const tempCheckpointLogsBase = BigInt(RollupContract.stfStorageSlot) + 2n;
1558
+ const circularIndex = BigInt(checkpointNumber) % roundaboutSize;
1559
+ const entryBase = BigInt(keccak256(encodeAbiParameters([
1560
+ {
1561
+ type: 'uint256'
1562
+ },
1563
+ {
1564
+ type: 'uint256'
1565
+ }
1566
+ ], [
1567
+ circularIndex,
1568
+ tempCheckpointLogsBase
1569
+ ])));
1570
+ return entryBase + fieldOffset;
1571
+ }
631
1572
  }
632
- _ts_decorate([
633
- memoize
634
- ], RollupContract.prototype, "getL1StartBlock", null);
635
- _ts_decorate([
636
- memoize
637
- ], RollupContract.prototype, "getL1GenesisTime", null);
638
- _ts_decorate([
639
- memoize
640
- ], RollupContract.prototype, "getProofSubmissionEpochs", null);
641
- _ts_decorate([
642
- memoize
643
- ], RollupContract.prototype, "getEpochDuration", null);
644
- _ts_decorate([
645
- memoize
646
- ], RollupContract.prototype, "getSlotDuration", null);
647
- _ts_decorate([
648
- memoize
649
- ], RollupContract.prototype, "getTargetCommitteeSize", null);
650
- _ts_decorate([
651
- memoize
652
- ], RollupContract.prototype, "getEjectionThreshold", null);
653
- _ts_decorate([
654
- memoize
655
- ], RollupContract.prototype, "getLocalEjectionThreshold", null);
656
- _ts_decorate([
657
- memoize
658
- ], RollupContract.prototype, "getLagInEpochsForValidatorSet", null);
659
- _ts_decorate([
660
- memoize
661
- ], RollupContract.prototype, "getLagInEpochsForRandao", null);
662
- _ts_decorate([
663
- memoize
664
- ], RollupContract.prototype, "getActivationThreshold", null);
665
- _ts_decorate([
666
- memoize
667
- ], RollupContract.prototype, "getExitDelay", null);
668
- _ts_decorate([
669
- memoize
670
- ], RollupContract.prototype, "getManaTarget", null);
671
- _ts_decorate([
672
- memoize
673
- ], RollupContract.prototype, "getProvingCostPerMana", null);
674
- _ts_decorate([
675
- memoize
676
- ], RollupContract.prototype, "getProvingCostPerManaInFeeAsset", null);
677
- _ts_decorate([
678
- memoize
679
- ], RollupContract.prototype, "getManaLimit", null);
680
- _ts_decorate([
681
- memoize
682
- ], RollupContract.prototype, "getVersion", null);
683
- _ts_decorate([
684
- memoize
685
- ], RollupContract.prototype, "getGenesisArchiveTreeRoot", null);
686
- _ts_decorate([
687
- memoize
688
- ], RollupContract.prototype, "getRollupConstants", null);