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

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 (229) hide show
  1. package/dest/account.d.ts +2 -0
  2. package/dest/account.d.ts.map +1 -0
  3. package/dest/account.js +4 -0
  4. package/dest/client.d.ts +5 -3
  5. package/dest/client.d.ts.map +1 -1
  6. package/dest/client.js +16 -2
  7. package/dest/config.d.ts +107 -16
  8. package/dest/config.d.ts.map +1 -1
  9. package/dest/config.js +456 -22
  10. package/dest/contracts/empire_base.d.ts +21 -6
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/empire_base.js +75 -2
  13. package/dest/contracts/empire_slashing_proposer.d.ts +65 -0
  14. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
  15. package/dest/contracts/empire_slashing_proposer.js +194 -0
  16. package/dest/contracts/errors.d.ts +7 -0
  17. package/dest/contracts/errors.d.ts.map +1 -0
  18. package/dest/contracts/errors.js +12 -0
  19. package/dest/contracts/fee_asset_handler.d.ts +19 -0
  20. package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
  21. package/dest/contracts/fee_asset_handler.js +57 -0
  22. package/dest/contracts/fee_juice.d.ts +5 -6
  23. package/dest/contracts/fee_juice.d.ts.map +1 -1
  24. package/dest/contracts/fee_juice.js +27 -20
  25. package/dest/contracts/governance.d.ts +36 -25
  26. package/dest/contracts/governance.d.ts.map +1 -1
  27. package/dest/contracts/governance.js +87 -84
  28. package/dest/contracts/governance_proposer.d.ts +13 -11
  29. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  30. package/dest/contracts/governance_proposer.js +32 -18
  31. package/dest/contracts/gse.d.ts +32 -0
  32. package/dest/contracts/gse.d.ts.map +1 -0
  33. package/dest/contracts/gse.js +72 -0
  34. package/dest/contracts/inbox.d.ts +26 -0
  35. package/dest/contracts/inbox.d.ts.map +1 -0
  36. package/dest/contracts/inbox.js +45 -0
  37. package/dest/contracts/index.d.ts +8 -2
  38. package/dest/contracts/index.d.ts.map +1 -1
  39. package/dest/contracts/index.js +8 -2
  40. package/dest/contracts/multicall.d.ts +21 -0
  41. package/dest/contracts/multicall.d.ts.map +1 -0
  42. package/dest/contracts/multicall.js +156 -0
  43. package/dest/contracts/registry.d.ts +9 -4
  44. package/dest/contracts/registry.d.ts.map +1 -1
  45. package/dest/contracts/registry.js +44 -16
  46. package/dest/contracts/rollup.d.ts +202 -29
  47. package/dest/contracts/rollup.d.ts.map +1 -1
  48. package/dest/contracts/rollup.js +500 -55
  49. package/dest/contracts/slasher_contract.d.ts +44 -0
  50. package/dest/contracts/slasher_contract.d.ts.map +1 -0
  51. package/dest/contracts/slasher_contract.js +75 -0
  52. package/dest/contracts/tally_slashing_proposer.d.ts +138 -0
  53. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
  54. package/dest/contracts/tally_slashing_proposer.js +313 -0
  55. package/dest/contracts/utils.d.ts +3 -0
  56. package/dest/contracts/utils.d.ts.map +1 -0
  57. package/dest/contracts/utils.js +11 -0
  58. package/dest/deploy_l1_contracts.d.ts +128 -21112
  59. package/dest/deploy_l1_contracts.d.ts.map +1 -1
  60. package/dest/deploy_l1_contracts.js +1204 -418
  61. package/dest/eth-signer/eth-signer.d.ts +21 -0
  62. package/dest/eth-signer/eth-signer.d.ts.map +1 -0
  63. package/dest/eth-signer/eth-signer.js +5 -0
  64. package/dest/eth-signer/index.d.ts +2 -0
  65. package/dest/eth-signer/index.d.ts.map +1 -0
  66. package/dest/eth-signer/index.js +1 -0
  67. package/dest/index.d.ts +6 -2
  68. package/dest/index.d.ts.map +1 -1
  69. package/dest/index.js +6 -2
  70. package/dest/l1_artifacts.d.ts +76184 -0
  71. package/dest/l1_artifacts.d.ts.map +1 -0
  72. package/dest/l1_artifacts.js +166 -0
  73. package/dest/l1_contract_addresses.d.ts +21 -1
  74. package/dest/l1_contract_addresses.d.ts.map +1 -1
  75. package/dest/l1_contract_addresses.js +22 -18
  76. package/dest/l1_reader.d.ts +1 -1
  77. package/dest/l1_reader.d.ts.map +1 -1
  78. package/dest/l1_reader.js +8 -8
  79. package/dest/l1_tx_utils/config.d.ts +59 -0
  80. package/dest/l1_tx_utils/config.d.ts.map +1 -0
  81. package/dest/l1_tx_utils/config.js +73 -0
  82. package/dest/l1_tx_utils/constants.d.ts +6 -0
  83. package/dest/l1_tx_utils/constants.d.ts.map +1 -0
  84. package/dest/l1_tx_utils/constants.js +14 -0
  85. package/dest/l1_tx_utils/factory.d.ts +24 -0
  86. package/dest/l1_tx_utils/factory.d.ts.map +1 -0
  87. package/dest/l1_tx_utils/factory.js +12 -0
  88. package/dest/l1_tx_utils/index.d.ts +10 -0
  89. package/dest/l1_tx_utils/index.d.ts.map +1 -0
  90. package/dest/l1_tx_utils/index.js +10 -0
  91. package/dest/l1_tx_utils/interfaces.d.ts +76 -0
  92. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
  93. package/dest/l1_tx_utils/interfaces.js +4 -0
  94. package/dest/l1_tx_utils/l1_tx_utils.d.ts +95 -0
  95. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
  96. package/dest/l1_tx_utils/l1_tx_utils.js +610 -0
  97. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
  98. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
  99. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
  100. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +94 -0
  101. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
  102. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +431 -0
  103. package/dest/l1_tx_utils/signer.d.ts +4 -0
  104. package/dest/l1_tx_utils/signer.d.ts.map +1 -0
  105. package/dest/l1_tx_utils/signer.js +16 -0
  106. package/dest/l1_tx_utils/types.d.ts +67 -0
  107. package/dest/l1_tx_utils/types.d.ts.map +1 -0
  108. package/dest/l1_tx_utils/types.js +26 -0
  109. package/dest/l1_tx_utils/utils.d.ts +4 -0
  110. package/dest/l1_tx_utils/utils.d.ts.map +1 -0
  111. package/dest/l1_tx_utils/utils.js +14 -0
  112. package/dest/l1_types.d.ts +6 -0
  113. package/dest/l1_types.d.ts.map +1 -0
  114. package/dest/l1_types.js +1 -0
  115. package/dest/publisher_manager.d.ts +15 -0
  116. package/dest/publisher_manager.d.ts.map +1 -0
  117. package/dest/publisher_manager.js +88 -0
  118. package/dest/queries.d.ts +3 -1
  119. package/dest/queries.d.ts.map +1 -1
  120. package/dest/queries.js +51 -12
  121. package/dest/test/chain_monitor.d.ts +72 -0
  122. package/dest/test/chain_monitor.d.ts.map +1 -0
  123. package/dest/test/chain_monitor.js +216 -0
  124. package/dest/test/delayed_tx_utils.d.ts +7 -2
  125. package/dest/test/delayed_tx_utils.d.ts.map +1 -1
  126. package/dest/test/delayed_tx_utils.js +13 -6
  127. package/dest/{eth_cheat_codes.d.ts → test/eth_cheat_codes.d.ts} +87 -13
  128. package/dest/test/eth_cheat_codes.d.ts.map +1 -0
  129. package/dest/test/eth_cheat_codes.js +552 -0
  130. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  131. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  132. package/dest/test/eth_cheat_codes_with_state.js +1 -1
  133. package/dest/test/index.d.ts +3 -0
  134. package/dest/test/index.d.ts.map +1 -1
  135. package/dest/test/index.js +3 -0
  136. package/dest/test/rollup_cheat_codes.d.ts +86 -0
  137. package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
  138. package/dest/test/rollup_cheat_codes.js +268 -0
  139. package/dest/test/start_anvil.d.ts +5 -0
  140. package/dest/test/start_anvil.d.ts.map +1 -1
  141. package/dest/test/start_anvil.js +15 -7
  142. package/dest/test/tx_delayer.d.ts +17 -6
  143. package/dest/test/tx_delayer.d.ts.map +1 -1
  144. package/dest/test/tx_delayer.js +95 -19
  145. package/dest/test/upgrade_utils.d.ts +5 -4
  146. package/dest/test/upgrade_utils.d.ts.map +1 -1
  147. package/dest/test/upgrade_utils.js +23 -16
  148. package/dest/types.d.ts +6 -7
  149. package/dest/types.d.ts.map +1 -1
  150. package/dest/types.js +3 -1
  151. package/dest/utils.d.ts +1 -0
  152. package/dest/utils.d.ts.map +1 -1
  153. package/dest/utils.js +43 -88
  154. package/dest/zkPassportVerifierAddress.d.ts +15 -0
  155. package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
  156. package/dest/zkPassportVerifierAddress.js +11 -0
  157. package/package.json +24 -16
  158. package/src/account.ts +5 -0
  159. package/src/client.ts +42 -4
  160. package/src/config.ts +584 -31
  161. package/src/contracts/empire_base.ts +75 -6
  162. package/src/contracts/empire_slashing_proposer.ts +259 -0
  163. package/src/contracts/errors.ts +13 -0
  164. package/src/contracts/fee_asset_handler.ts +63 -0
  165. package/src/contracts/fee_juice.ts +29 -15
  166. package/src/contracts/governance.ts +80 -77
  167. package/src/contracts/governance_proposer.ts +60 -24
  168. package/src/contracts/gse.ts +88 -0
  169. package/src/contracts/inbox.ts +63 -0
  170. package/src/contracts/index.ts +8 -2
  171. package/src/contracts/multicall.ts +155 -0
  172. package/src/contracts/registry.ts +51 -26
  173. package/src/contracts/rollup.ts +585 -56
  174. package/src/contracts/slasher_contract.ts +89 -0
  175. package/src/contracts/tally_slashing_proposer.ts +315 -0
  176. package/src/contracts/utils.ts +14 -0
  177. package/src/deploy_l1_contracts.ts +1467 -566
  178. package/src/eth-signer/eth-signer.ts +25 -0
  179. package/src/eth-signer/index.ts +1 -0
  180. package/src/index.ts +6 -2
  181. package/src/l1_artifacts.ts +254 -0
  182. package/src/l1_contract_addresses.ts +32 -19
  183. package/src/l1_reader.ts +9 -9
  184. package/src/l1_tx_utils/README.md +177 -0
  185. package/src/l1_tx_utils/config.ts +140 -0
  186. package/src/l1_tx_utils/constants.ts +18 -0
  187. package/src/l1_tx_utils/factory.ts +64 -0
  188. package/src/l1_tx_utils/index.ts +12 -0
  189. package/src/l1_tx_utils/interfaces.ts +86 -0
  190. package/src/l1_tx_utils/l1_tx_utils.ts +718 -0
  191. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
  192. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +559 -0
  193. package/src/l1_tx_utils/signer.ts +28 -0
  194. package/src/l1_tx_utils/types.ts +85 -0
  195. package/src/l1_tx_utils/utils.ts +16 -0
  196. package/src/l1_types.ts +6 -0
  197. package/src/publisher_manager.ts +106 -0
  198. package/src/queries.ts +70 -15
  199. package/src/test/chain_monitor.ts +243 -0
  200. package/src/test/delayed_tx_utils.ts +34 -6
  201. package/src/test/eth_cheat_codes.ts +582 -0
  202. package/src/test/eth_cheat_codes_with_state.ts +1 -1
  203. package/src/test/index.ts +3 -0
  204. package/src/test/rollup_cheat_codes.ts +310 -0
  205. package/src/test/start_anvil.ts +20 -5
  206. package/src/test/tx_delayer.ts +127 -26
  207. package/src/test/upgrade_utils.ts +30 -21
  208. package/src/types.ts +10 -8
  209. package/src/utils.ts +49 -90
  210. package/src/zkPassportVerifierAddress.ts +15 -0
  211. package/dest/contracts/forwarder.d.ts +0 -24
  212. package/dest/contracts/forwarder.d.ts.map +0 -1
  213. package/dest/contracts/forwarder.js +0 -101
  214. package/dest/contracts/slashing_proposer.d.ts +0 -21
  215. package/dest/contracts/slashing_proposer.d.ts.map +0 -1
  216. package/dest/contracts/slashing_proposer.js +0 -47
  217. package/dest/eth_cheat_codes.d.ts.map +0 -1
  218. package/dest/eth_cheat_codes.js +0 -303
  219. package/dest/l1_tx_utils.d.ts +0 -192
  220. package/dest/l1_tx_utils.d.ts.map +0 -1
  221. package/dest/l1_tx_utils.js +0 -641
  222. package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
  223. package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
  224. package/dest/l1_tx_utils_with_blobs.js +0 -64
  225. package/src/contracts/forwarder.ts +0 -132
  226. package/src/contracts/slashing_proposer.ts +0 -51
  227. package/src/eth_cheat_codes.ts +0 -314
  228. package/src/l1_tx_utils.ts +0 -847
  229. package/src/l1_tx_utils_with_blobs.ts +0 -86
@@ -6,14 +6,27 @@ function _ts_decorate(decorators, target, key, desc) {
6
6
  }
7
7
  import { memoize } from '@aztec/foundation/decorators';
8
8
  import { EthAddress } from '@aztec/foundation/eth-address';
9
- import { RollupAbi, RollupStorage, SlasherAbi } from '@aztec/l1-artifacts';
10
- import { getAddress, getContract } from 'viem';
9
+ import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
10
+ import { RollupStorage } from '@aztec/l1-artifacts/RollupStorage';
11
+ import chunk from 'lodash.chunk';
12
+ import { encodeFunctionData, getContract, hexToBigInt, keccak256 } from 'viem';
11
13
  import { getPublicClient } from '../client.js';
12
14
  import { formatViemError } from '../utils.js';
13
- import { SlashingProposerContract } from './slashing_proposer.js';
15
+ import { EmpireSlashingProposerContract } from './empire_slashing_proposer.js';
16
+ import { GSEContract } from './gse.js';
17
+ import { SlasherContract } from './slasher_contract.js';
18
+ import { TallySlashingProposerContract } from './tally_slashing_proposer.js';
19
+ import { checkBlockTag } from './utils.js';
20
+ export var SlashingProposerType = /*#__PURE__*/ function(SlashingProposerType) {
21
+ SlashingProposerType[SlashingProposerType["None"] = 0] = "None";
22
+ SlashingProposerType[SlashingProposerType["Tally"] = 1] = "Tally";
23
+ SlashingProposerType[SlashingProposerType["Empire"] = 2] = "Empire";
24
+ return SlashingProposerType;
25
+ }({});
14
26
  export class RollupContract {
15
27
  client;
16
28
  rollup;
29
+ static cachedStfStorageSlot;
17
30
  static get checkBlobStorageSlot() {
18
31
  const asString = RollupStorage.find((storage)=>storage.label === 'checkBlob')?.slot;
19
32
  if (asString === undefined) {
@@ -21,9 +34,12 @@ export class RollupContract {
21
34
  }
22
35
  return BigInt(asString);
23
36
  }
37
+ static get stfStorageSlot() {
38
+ return RollupContract.cachedStfStorageSlot ??= keccak256(Buffer.from('aztec.stf.storage', 'utf-8'));
39
+ }
24
40
  static getFromL1ContractsValues(deployL1ContractsValues) {
25
- const { publicClient, l1ContractAddresses: { rollupAddress } } = deployL1ContractsValues;
26
- return new RollupContract(publicClient, rollupAddress.toString());
41
+ const { l1Client, l1ContractAddresses: { rollupAddress } } = deployL1ContractsValues;
42
+ return new RollupContract(l1Client, rollupAddress.toString());
27
43
  }
28
44
  static getFromConfig(config) {
29
45
  const client = getPublicClient(config);
@@ -41,18 +57,49 @@ export class RollupContract {
41
57
  client
42
58
  });
43
59
  }
60
+ getGSE() {
61
+ return this.rollup.read.getGSE();
62
+ }
44
63
  get address() {
45
64
  return this.rollup.address;
46
65
  }
66
+ getContract() {
67
+ return this.rollup;
68
+ }
47
69
  async getSlashingProposer() {
48
- const slasherAddress = await this.rollup.read.getSlasher();
49
- const slasher = getContract({
50
- address: slasherAddress,
51
- abi: SlasherAbi,
70
+ const slasher = await this.getSlasherContract();
71
+ if (!slasher) {
72
+ return undefined;
73
+ }
74
+ const proposerAddress = await slasher.getProposer();
75
+ const proposerAbi = [
76
+ {
77
+ type: 'function',
78
+ name: 'SLASHING_PROPOSER_TYPE',
79
+ inputs: [],
80
+ outputs: [
81
+ {
82
+ name: '',
83
+ type: 'uint8',
84
+ internalType: 'enum SlasherFlavor'
85
+ }
86
+ ],
87
+ stateMutability: 'view'
88
+ }
89
+ ];
90
+ const proposer = getContract({
91
+ address: proposerAddress.toString(),
92
+ abi: proposerAbi,
52
93
  client: this.client
53
94
  });
54
- const proposerAddress = await slasher.read.PROPOSER();
55
- return new SlashingProposerContract(this.client, proposerAddress);
95
+ const proposerType = await proposer.read.SLASHING_PROPOSER_TYPE();
96
+ if (proposerType === 1..valueOf()) {
97
+ return new TallySlashingProposerContract(this.client, proposerAddress);
98
+ } else if (proposerType === 2..valueOf()) {
99
+ return new EmpireSlashingProposerContract(this.client, proposerAddress);
100
+ } else {
101
+ throw new Error(`Unknown slashing proposer type: ${proposerType}`);
102
+ }
56
103
  }
57
104
  getL1StartBlock() {
58
105
  return this.rollup.read.L1_BLOCK_AT_GENESIS();
@@ -60,8 +107,8 @@ export class RollupContract {
60
107
  getL1GenesisTime() {
61
108
  return this.rollup.read.getGenesisTime();
62
109
  }
63
- getProofSubmissionWindow() {
64
- return this.rollup.read.getProofSubmissionWindow();
110
+ getProofSubmissionEpochs() {
111
+ return this.rollup.read.getProofSubmissionEpochs();
65
112
  }
66
113
  getEpochDuration() {
67
114
  return this.rollup.read.getEpochDuration();
@@ -72,17 +119,88 @@ export class RollupContract {
72
119
  getTargetCommitteeSize() {
73
120
  return this.rollup.read.getTargetCommitteeSize();
74
121
  }
75
- getMinimumStake() {
76
- return this.rollup.read.getMinimumStake();
122
+ getEjectionThreshold() {
123
+ return this.rollup.read.getEjectionThreshold();
124
+ }
125
+ getLocalEjectionThreshold() {
126
+ return this.rollup.read.getLocalEjectionThreshold();
127
+ }
128
+ getLagInEpochs() {
129
+ return this.rollup.read.getLagInEpochs();
130
+ }
131
+ getActivationThreshold() {
132
+ return this.rollup.read.getActivationThreshold();
133
+ }
134
+ getExitDelay() {
135
+ return this.rollup.read.getExitDelay();
136
+ }
137
+ getManaTarget() {
138
+ return this.rollup.read.getManaTarget();
139
+ }
140
+ getProvingCostPerMana() {
141
+ return this.rollup.read.getProvingCostPerManaInEth();
142
+ }
143
+ getProvingCostPerManaInFeeAsset() {
144
+ return this.rollup.read.getProvingCostPerManaInFeeAsset();
145
+ }
146
+ getManaLimit() {
147
+ return this.rollup.read.getManaLimit();
148
+ }
149
+ getVersion() {
150
+ return this.rollup.read.getVersion();
151
+ }
152
+ async getGenesisArchiveTreeRoot() {
153
+ return await this.rollup.read.archiveAt([
154
+ 0n
155
+ ]);
156
+ }
157
+ /**
158
+ * Returns rollup constants used for epoch queries.
159
+ * Return type is `L1RollupConstants` which is defined in stdlib,
160
+ * so we cant reference it until we move this contract to that package.
161
+ */ async getRollupConstants() {
162
+ const [l1StartBlock, l1GenesisTime, slotDuration, epochDuration, proofSubmissionEpochs] = await Promise.all([
163
+ this.getL1StartBlock(),
164
+ this.getL1GenesisTime(),
165
+ this.getSlotDuration(),
166
+ this.getEpochDuration(),
167
+ this.getProofSubmissionEpochs()
168
+ ]);
169
+ return {
170
+ l1StartBlock,
171
+ l1GenesisTime,
172
+ slotDuration: Number(slotDuration),
173
+ epochDuration: Number(epochDuration),
174
+ proofSubmissionEpochs: Number(proofSubmissionEpochs)
175
+ };
176
+ }
177
+ getSlasherAddress() {
178
+ return this.rollup.read.getSlasher();
179
+ }
180
+ /**
181
+ * Returns a SlasherContract instance for interacting with the slasher contract.
182
+ */ async getSlasherContract() {
183
+ const slasherAddress = EthAddress.fromString(await this.getSlasherAddress());
184
+ if (slasherAddress.isZero()) {
185
+ return undefined;
186
+ }
187
+ return new SlasherContract(this.client, slasherAddress);
188
+ }
189
+ getOwner() {
190
+ return this.rollup.read.owner();
191
+ }
192
+ getActiveAttesterCount() {
193
+ return this.rollup.read.getActiveAttesterCount();
77
194
  }
78
195
  async getSlashingProposerAddress() {
79
- const slasherAddress = await this.rollup.read.getSlasher();
80
- const slasher = getContract({
81
- address: getAddress(slasherAddress.toString()),
82
- abi: SlasherAbi,
83
- client: this.client
84
- });
85
- return EthAddress.fromString(await slasher.read.PROPOSER());
196
+ const slasher = await this.getSlasherContract();
197
+ if (!slasher) {
198
+ return EthAddress.ZERO;
199
+ }
200
+ return await slasher.getProposer();
201
+ }
202
+ getBlockReward() {
203
+ return this.rollup.read.getBlockReward();
86
204
  }
87
205
  getBlockNumber() {
88
206
  return this.rollup.read.getPendingBlockNumber();
@@ -93,11 +211,32 @@ export class RollupContract {
93
211
  getSlotNumber() {
94
212
  return this.rollup.read.getCurrentSlot();
95
213
  }
96
- getCommitteeAt(timestamp) {
97
- return this.rollup.read.getCommitteeAt([
214
+ getL1FeesAt(timestamp) {
215
+ return this.rollup.read.getL1FeesAt([
98
216
  timestamp
99
217
  ]);
100
218
  }
219
+ getFeeAssetPerEth() {
220
+ return this.rollup.read.getFeeAssetPerEth();
221
+ }
222
+ async getCommitteeAt(timestamp) {
223
+ const { result } = await this.client.simulateContract({
224
+ address: this.address,
225
+ abi: RollupAbi,
226
+ functionName: 'getCommitteeAt',
227
+ args: [
228
+ timestamp
229
+ ]
230
+ }).catch((e)=>{
231
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
232
+ return {
233
+ result: undefined
234
+ };
235
+ }
236
+ throw e;
237
+ });
238
+ return result;
239
+ }
101
240
  getSampleSeedAt(timestamp) {
102
241
  return this.rollup.read.getSampleSeedAt([
103
242
  timestamp
@@ -106,20 +245,48 @@ export class RollupContract {
106
245
  getCurrentSampleSeed() {
107
246
  return this.rollup.read.getCurrentSampleSeed();
108
247
  }
109
- getCurrentEpochCommittee() {
110
- return this.rollup.read.getCurrentEpochCommittee();
248
+ getCurrentEpoch() {
249
+ return this.rollup.read.getCurrentEpoch();
111
250
  }
112
- getCurrentProposer() {
113
- return this.rollup.read.getCurrentProposer();
251
+ async getCurrentEpochCommittee() {
252
+ const { result } = await this.client.simulateContract({
253
+ address: this.address,
254
+ abi: RollupAbi,
255
+ functionName: 'getCurrentEpochCommittee',
256
+ args: []
257
+ }).catch((e)=>{
258
+ if (e instanceof Error && e.message.includes('ValidatorSelection__InsufficientValidatorSetSize')) {
259
+ return {
260
+ result: undefined
261
+ };
262
+ }
263
+ throw e;
264
+ });
265
+ return result;
114
266
  }
115
- getProposerAt(timestamp) {
116
- return this.rollup.read.getProposerAt([
117
- timestamp
118
- ]);
267
+ async getCurrentProposer() {
268
+ const { result } = await this.client.simulateContract({
269
+ address: this.address,
270
+ abi: RollupAbi,
271
+ functionName: 'getCurrentProposer',
272
+ args: []
273
+ });
274
+ return result;
275
+ }
276
+ async getProposerAt(timestamp) {
277
+ const { result } = await this.client.simulateContract({
278
+ address: this.address,
279
+ abi: RollupAbi,
280
+ functionName: 'getProposerAt',
281
+ args: [
282
+ timestamp
283
+ ]
284
+ });
285
+ return result;
119
286
  }
120
287
  getBlock(blockNumber) {
121
288
  return this.rollup.read.getBlock([
122
- blockNumber
289
+ BigInt(blockNumber)
123
290
  ]);
124
291
  }
125
292
  getTips() {
@@ -130,20 +297,32 @@ export class RollupContract {
130
297
  slot
131
298
  ]);
132
299
  }
133
- async getEpochNumber(blockNumber) {
134
- blockNumber ??= await this.getBlockNumber();
300
+ getEntryQueueLength() {
301
+ return this.rollup.read.getEntryQueueLength();
302
+ }
303
+ getAvailableValidatorFlushes() {
304
+ return this.rollup.read.getAvailableValidatorFlushes();
305
+ }
306
+ getNextFlushableEpoch() {
307
+ return this.rollup.read.getNextFlushableEpoch();
308
+ }
309
+ getCurrentEpochNumber() {
310
+ return this.rollup.read.getCurrentEpoch();
311
+ }
312
+ getEpochNumberForBlock(blockNumber) {
135
313
  return this.rollup.read.getEpochForBlock([
136
314
  BigInt(blockNumber)
137
315
  ]);
138
316
  }
139
317
  async getRollupAddresses() {
140
- const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress] = (await Promise.all([
318
+ const [inboxAddress, outboxAddress, feeJuicePortalAddress, rewardDistributorAddress, feeJuiceAddress, stakingAssetAddress, gseAddress] = (await Promise.all([
141
319
  this.rollup.read.getInbox(),
142
320
  this.rollup.read.getOutbox(),
143
321
  this.rollup.read.getFeeAssetPortal(),
144
322
  this.rollup.read.getRewardDistributor(),
145
323
  this.rollup.read.getFeeAsset(),
146
- this.rollup.read.getStakingAsset()
324
+ this.rollup.read.getStakingAsset(),
325
+ this.rollup.read.getGSE()
147
326
  ])).map(EthAddress.fromString);
148
327
  return {
149
328
  rollupAddress: EthAddress.fromString(this.address),
@@ -152,9 +331,13 @@ export class RollupContract {
152
331
  feeJuicePortalAddress,
153
332
  feeJuiceAddress,
154
333
  stakingAssetAddress,
155
- rewardDistributorAddress
334
+ rewardDistributorAddress,
335
+ gseAddress
156
336
  };
157
337
  }
338
+ async getFeeJuicePortal() {
339
+ return EthAddress.fromString(await this.rollup.read.getFeeAssetPortal());
340
+ }
158
341
  async getEpochNumberForSlotNumber(slotNumber) {
159
342
  return await this.rollup.read.getEpochAtSlot([
160
343
  slotNumber
@@ -165,7 +348,11 @@ export class RollupContract {
165
348
  }
166
349
  async validateHeader(args, account) {
167
350
  try {
168
- await this.rollup.read.validateHeader(args, {
351
+ await this.client.simulateContract({
352
+ address: this.address,
353
+ abi: RollupAbi,
354
+ functionName: 'validateHeaderWithAttestations',
355
+ args,
169
356
  account
170
357
  });
171
358
  } catch (error) {
@@ -180,37 +367,262 @@ export class RollupContract {
180
367
  * @param archive - The archive that we expect to be current state
181
368
  * @return [slot, blockNumber] - If you can propose, the L2 slot number and L2 block number of the next Ethereum block,
182
369
  * @throws otherwise
183
- */ async canProposeAtNextEthBlock(archive, account, slotDuration) {
370
+ */ async canProposeAtNextEthBlock(archive, account, slotDuration, opts = {}) {
184
371
  if (typeof slotDuration === 'number') {
185
372
  slotDuration = BigInt(slotDuration);
186
373
  }
187
- const timeOfNextL1Slot = (await this.client.getBlock()).timestamp + slotDuration;
374
+ const latestBlock = await this.client.getBlock();
375
+ const timeOfNextL1Slot = latestBlock.timestamp + slotDuration;
376
+ const who = typeof account === 'string' ? account : account.address;
188
377
  try {
189
- const [slot, blockNumber] = await this.rollup.read.canProposeAtTime([
190
- timeOfNextL1Slot,
191
- `0x${archive.toString('hex')}`
192
- ], {
193
- account
378
+ const { result: [slot, blockNumber] } = await this.client.simulateContract({
379
+ address: this.address,
380
+ abi: RollupAbi,
381
+ functionName: 'canProposeAtTime',
382
+ args: [
383
+ timeOfNextL1Slot,
384
+ `0x${archive.toString('hex')}`,
385
+ who
386
+ ],
387
+ account,
388
+ stateOverride: await this.makePendingBlockNumberOverride(opts.forcePendingBlockNumber)
194
389
  });
195
- return [
390
+ return {
196
391
  slot,
197
- blockNumber
198
- ];
392
+ blockNumber,
393
+ timeOfNextL1Slot
394
+ };
199
395
  } catch (err) {
200
396
  throw formatViemError(err);
201
397
  }
202
398
  }
399
+ /**
400
+ * Returns a state override that sets the pending block number to the specified value. Useful for simulations.
401
+ * Requires querying the current state of the contract to get the current proven block number, as they are both
402
+ * stored in the same slot. If the argument is undefined, it returns an empty override.
403
+ */ async makePendingBlockNumberOverride(forcePendingBlockNumber) {
404
+ if (forcePendingBlockNumber === undefined) {
405
+ return [];
406
+ }
407
+ const slot = RollupContract.stfStorageSlot;
408
+ const currentValue = await this.client.getStorageAt({
409
+ address: this.address,
410
+ slot
411
+ });
412
+ const currentProvenBlockNumber = currentValue ? hexToBigInt(currentValue) & (1n << 128n) - 1n : 0n;
413
+ const newValue = BigInt(forcePendingBlockNumber) << 128n | currentProvenBlockNumber;
414
+ return [
415
+ {
416
+ address: this.address,
417
+ stateDiff: [
418
+ {
419
+ slot,
420
+ value: `0x${newValue.toString(16).padStart(64, '0')}`
421
+ }
422
+ ]
423
+ }
424
+ ];
425
+ }
426
+ /** Creates a request to Rollup#invalidateBadAttestation to be simulated or sent */ buildInvalidateBadAttestationRequest(blockNumber, attestationsAndSigners, committee, invalidIndex) {
427
+ return {
428
+ to: this.address,
429
+ data: encodeFunctionData({
430
+ abi: RollupAbi,
431
+ functionName: 'invalidateBadAttestation',
432
+ args: [
433
+ BigInt(blockNumber),
434
+ attestationsAndSigners,
435
+ committee.map((addr)=>addr.toString()),
436
+ BigInt(invalidIndex)
437
+ ]
438
+ })
439
+ };
440
+ }
441
+ /** Creates a request to Rollup#invalidateInsufficientAttestations to be simulated or sent */ buildInvalidateInsufficientAttestationsRequest(blockNumber, attestationsAndSigners, committee) {
442
+ return {
443
+ to: this.address,
444
+ data: encodeFunctionData({
445
+ abi: RollupAbi,
446
+ functionName: 'invalidateInsufficientAttestations',
447
+ args: [
448
+ BigInt(blockNumber),
449
+ attestationsAndSigners,
450
+ committee.map((addr)=>addr.toString())
451
+ ]
452
+ })
453
+ };
454
+ }
203
455
  /** Calls getHasSubmitted directly. Returns whether the given prover has submitted a proof with the given length for the given epoch. */ getHasSubmittedProof(epochNumber, numberOfBlocksInEpoch, prover) {
456
+ if (prover instanceof EthAddress) {
457
+ prover = prover.toString();
458
+ }
204
459
  return this.rollup.read.getHasSubmitted([
205
460
  BigInt(epochNumber),
206
461
  BigInt(numberOfBlocksInEpoch),
207
- prover.toString()
462
+ prover
463
+ ]);
464
+ }
465
+ getManaBaseFeeAt(timestamp, inFeeAsset) {
466
+ return this.rollup.read.getManaBaseFeeAt([
467
+ timestamp,
468
+ inFeeAsset
469
+ ]);
470
+ }
471
+ getSlotAt(timestamp) {
472
+ return this.rollup.read.getSlotAt([
473
+ timestamp
208
474
  ]);
209
475
  }
476
+ async status(blockNumber, options) {
477
+ await checkBlockTag(options?.blockNumber, this.client);
478
+ return this.rollup.read.status([
479
+ blockNumber
480
+ ], options);
481
+ }
482
+ async canPruneAtTime(timestamp, options) {
483
+ await checkBlockTag(options?.blockNumber, this.client);
484
+ return this.rollup.read.canPruneAtTime([
485
+ timestamp
486
+ ], options);
487
+ }
488
+ archive() {
489
+ return this.rollup.read.archive();
490
+ }
491
+ archiveAt(blockNumber) {
492
+ return this.rollup.read.archiveAt([
493
+ blockNumber
494
+ ]);
495
+ }
496
+ getSequencerRewards(address) {
497
+ if (address instanceof EthAddress) {
498
+ address = address.toString();
499
+ }
500
+ return this.rollup.read.getSequencerRewards([
501
+ address
502
+ ]);
503
+ }
504
+ getSpecificProverRewardsForEpoch(epoch, prover) {
505
+ if (prover instanceof EthAddress) {
506
+ prover = prover.toString();
507
+ }
508
+ return this.rollup.read.getSpecificProverRewardsForEpoch([
509
+ epoch,
510
+ prover
511
+ ]);
512
+ }
513
+ async getAttesters() {
514
+ const attesterSize = await this.getActiveAttesterCount();
515
+ const gse = new GSEContract(this.client, await this.getGSE());
516
+ const ts = (await this.client.getBlock()).timestamp;
517
+ const indices = Array.from({
518
+ length: Number(attesterSize)
519
+ }, (_, i)=>BigInt(i));
520
+ const chunks = chunk(indices, 1000);
521
+ return (await Promise.all(chunks.map((chunk)=>gse.getAttestersFromIndicesAtTime(this.address, ts, chunk)))).flat();
522
+ }
523
+ getAttesterView(address) {
524
+ if (address instanceof EthAddress) {
525
+ address = address.toString();
526
+ }
527
+ return this.rollup.read.getAttesterView([
528
+ address
529
+ ]);
530
+ }
531
+ getStatus(address) {
532
+ if (address instanceof EthAddress) {
533
+ address = address.toString();
534
+ }
535
+ return this.rollup.read.getStatus([
536
+ address
537
+ ]);
538
+ }
539
+ getBlobCommitmentsHash(blockNumber) {
540
+ return this.rollup.read.getBlobCommitmentsHash([
541
+ blockNumber
542
+ ]);
543
+ }
544
+ getCurrentBlobCommitmentsHash() {
545
+ return this.rollup.read.getCurrentBlobCommitmentsHash();
546
+ }
547
+ getStakingAsset() {
548
+ return this.rollup.read.getStakingAsset();
549
+ }
550
+ getRewardConfig() {
551
+ return this.rollup.read.getRewardConfig();
552
+ }
553
+ setupEpoch(l1TxUtils) {
554
+ return l1TxUtils.sendAndMonitorTransaction({
555
+ to: this.address,
556
+ data: encodeFunctionData({
557
+ abi: RollupAbi,
558
+ functionName: 'setupEpoch',
559
+ args: []
560
+ })
561
+ });
562
+ }
563
+ vote(l1TxUtils, proposalId) {
564
+ return l1TxUtils.sendAndMonitorTransaction({
565
+ to: this.address,
566
+ data: encodeFunctionData({
567
+ abi: RollupAbi,
568
+ functionName: 'vote',
569
+ args: [
570
+ proposalId
571
+ ]
572
+ })
573
+ });
574
+ }
575
+ listenToSlasherChanged(callback) {
576
+ return this.rollup.watchEvent.SlasherUpdated({}, {
577
+ onLogs: (logs)=>{
578
+ for (const log of logs){
579
+ const args = log.args;
580
+ if (args.oldSlasher && args.newSlasher) {
581
+ callback(args);
582
+ }
583
+ }
584
+ }
585
+ });
586
+ }
587
+ listenToBlockInvalidated(callback) {
588
+ return this.rollup.watchEvent.BlockInvalidated({}, {
589
+ onLogs: (logs)=>{
590
+ for (const log of logs){
591
+ const args = log.args;
592
+ if (args.blockNumber !== undefined) {
593
+ callback({
594
+ blockNumber: args.blockNumber
595
+ });
596
+ }
597
+ }
598
+ }
599
+ });
600
+ }
601
+ async getSlashEvents(l1BlockHash) {
602
+ const events = await this.rollup.getEvents.Slashed({}, {
603
+ blockHash: l1BlockHash,
604
+ strict: true
605
+ });
606
+ return events.map((event)=>({
607
+ amount: event.args.amount,
608
+ attester: EthAddress.fromString(event.args.attester)
609
+ }));
610
+ }
611
+ listenToSlash(callback) {
612
+ return this.rollup.watchEvent.Slashed({}, {
613
+ strict: true,
614
+ onLogs: (logs)=>{
615
+ for (const log of logs){
616
+ const args = log.args;
617
+ callback({
618
+ amount: args.amount,
619
+ attester: EthAddress.fromString(args.attester)
620
+ });
621
+ }
622
+ }
623
+ });
624
+ }
210
625
  }
211
- _ts_decorate([
212
- memoize
213
- ], RollupContract.prototype, "getSlashingProposer", null);
214
626
  _ts_decorate([
215
627
  memoize
216
628
  ], RollupContract.prototype, "getL1StartBlock", null);
@@ -219,7 +631,7 @@ _ts_decorate([
219
631
  ], RollupContract.prototype, "getL1GenesisTime", null);
220
632
  _ts_decorate([
221
633
  memoize
222
- ], RollupContract.prototype, "getProofSubmissionWindow", null);
634
+ ], RollupContract.prototype, "getProofSubmissionEpochs", null);
223
635
  _ts_decorate([
224
636
  memoize
225
637
  ], RollupContract.prototype, "getEpochDuration", null);
@@ -231,4 +643,37 @@ _ts_decorate([
231
643
  ], RollupContract.prototype, "getTargetCommitteeSize", null);
232
644
  _ts_decorate([
233
645
  memoize
234
- ], RollupContract.prototype, "getMinimumStake", null);
646
+ ], RollupContract.prototype, "getEjectionThreshold", null);
647
+ _ts_decorate([
648
+ memoize
649
+ ], RollupContract.prototype, "getLocalEjectionThreshold", null);
650
+ _ts_decorate([
651
+ memoize
652
+ ], RollupContract.prototype, "getLagInEpochs", null);
653
+ _ts_decorate([
654
+ memoize
655
+ ], RollupContract.prototype, "getActivationThreshold", null);
656
+ _ts_decorate([
657
+ memoize
658
+ ], RollupContract.prototype, "getExitDelay", null);
659
+ _ts_decorate([
660
+ memoize
661
+ ], RollupContract.prototype, "getManaTarget", null);
662
+ _ts_decorate([
663
+ memoize
664
+ ], RollupContract.prototype, "getProvingCostPerMana", null);
665
+ _ts_decorate([
666
+ memoize
667
+ ], RollupContract.prototype, "getProvingCostPerManaInFeeAsset", null);
668
+ _ts_decorate([
669
+ memoize
670
+ ], RollupContract.prototype, "getManaLimit", null);
671
+ _ts_decorate([
672
+ memoize
673
+ ], RollupContract.prototype, "getVersion", null);
674
+ _ts_decorate([
675
+ memoize
676
+ ], RollupContract.prototype, "getGenesisArchiveTreeRoot", null);
677
+ _ts_decorate([
678
+ memoize
679
+ ], RollupContract.prototype, "getRollupConstants", null);