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

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