@aztec/ethereum 0.0.0-test.0

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 (118) hide show
  1. package/README.md +3 -0
  2. package/dest/chain.d.ts +25 -0
  3. package/dest/chain.d.ts.map +1 -0
  4. package/dest/chain.js +53 -0
  5. package/dest/client.d.ts +16 -0
  6. package/dest/client.d.ts.map +1 -0
  7. package/dest/client.js +31 -0
  8. package/dest/config.d.ts +39 -0
  9. package/dest/config.d.ts.map +1 -0
  10. package/dest/config.js +70 -0
  11. package/dest/constants.d.ts +4 -0
  12. package/dest/constants.d.ts.map +1 -0
  13. package/dest/constants.js +2 -0
  14. package/dest/contracts/empire_base.d.ts +13 -0
  15. package/dest/contracts/empire_base.d.ts.map +1 -0
  16. package/dest/contracts/empire_base.js +11 -0
  17. package/dest/contracts/fee_juice.d.ts +15 -0
  18. package/dest/contracts/fee_juice.d.ts.map +1 -0
  19. package/dest/contracts/fee_juice.js +52 -0
  20. package/dest/contracts/forwarder.d.ts +24 -0
  21. package/dest/contracts/forwarder.d.ts.map +1 -0
  22. package/dest/contracts/forwarder.js +101 -0
  23. package/dest/contracts/governance.d.ts +79 -0
  24. package/dest/contracts/governance.d.ts.map +1 -0
  25. package/dest/contracts/governance.js +247 -0
  26. package/dest/contracts/governance_proposer.d.ts +28 -0
  27. package/dest/contracts/governance_proposer.d.ts.map +1 -0
  28. package/dest/contracts/governance_proposer.js +82 -0
  29. package/dest/contracts/index.d.ts +9 -0
  30. package/dest/contracts/index.d.ts.map +1 -0
  31. package/dest/contracts/index.js +8 -0
  32. package/dest/contracts/registry.d.ts +24 -0
  33. package/dest/contracts/registry.d.ts.map +1 -0
  34. package/dest/contracts/registry.js +85 -0
  35. package/dest/contracts/rollup.d.ts +92 -0
  36. package/dest/contracts/rollup.d.ts.map +1 -0
  37. package/dest/contracts/rollup.js +234 -0
  38. package/dest/contracts/slashing_proposer.d.ts +21 -0
  39. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  40. package/dest/contracts/slashing_proposer.js +47 -0
  41. package/dest/deploy_l1_contracts.d.ts +21210 -0
  42. package/dest/deploy_l1_contracts.d.ts.map +1 -0
  43. package/dest/deploy_l1_contracts.js +687 -0
  44. package/dest/eth_cheat_codes.d.ts +147 -0
  45. package/dest/eth_cheat_codes.d.ts.map +1 -0
  46. package/dest/eth_cheat_codes.js +303 -0
  47. package/dest/index.d.ts +14 -0
  48. package/dest/index.d.ts.map +1 -0
  49. package/dest/index.js +13 -0
  50. package/dest/l1_contract_addresses.d.ts +57 -0
  51. package/dest/l1_contract_addresses.d.ts.map +1 -0
  52. package/dest/l1_contract_addresses.js +97 -0
  53. package/dest/l1_reader.d.ts +16 -0
  54. package/dest/l1_reader.d.ts.map +1 -0
  55. package/dest/l1_reader.js +27 -0
  56. package/dest/l1_tx_utils.d.ts +192 -0
  57. package/dest/l1_tx_utils.d.ts.map +1 -0
  58. package/dest/l1_tx_utils.js +641 -0
  59. package/dest/l1_tx_utils_with_blobs.d.ts +12 -0
  60. package/dest/l1_tx_utils_with_blobs.d.ts.map +1 -0
  61. package/dest/l1_tx_utils_with_blobs.js +64 -0
  62. package/dest/queries.d.ts +12 -0
  63. package/dest/queries.d.ts.map +1 -0
  64. package/dest/queries.js +35 -0
  65. package/dest/test/delayed_tx_utils.d.ts +8 -0
  66. package/dest/test/delayed_tx_utils.d.ts.map +1 -0
  67. package/dest/test/delayed_tx_utils.js +21 -0
  68. package/dest/test/eth_cheat_codes_with_state.d.ts +18 -0
  69. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -0
  70. package/dest/test/eth_cheat_codes_with_state.js +34 -0
  71. package/dest/test/index.d.ts +6 -0
  72. package/dest/test/index.d.ts.map +1 -0
  73. package/dest/test/index.js +5 -0
  74. package/dest/test/start_anvil.d.ts +12 -0
  75. package/dest/test/start_anvil.d.ts.map +1 -0
  76. package/dest/test/start_anvil.js +46 -0
  77. package/dest/test/tx_delayer.d.ts +25 -0
  78. package/dest/test/tx_delayer.d.ts.map +1 -0
  79. package/dest/test/tx_delayer.js +116 -0
  80. package/dest/test/upgrade_utils.d.ts +11 -0
  81. package/dest/test/upgrade_utils.d.ts.map +1 -0
  82. package/dest/test/upgrade_utils.js +104 -0
  83. package/dest/types.d.ts +14 -0
  84. package/dest/types.d.ts.map +1 -0
  85. package/dest/types.js +1 -0
  86. package/dest/utils.d.ts +24 -0
  87. package/dest/utils.d.ts.map +1 -0
  88. package/dest/utils.js +209 -0
  89. package/package.json +98 -0
  90. package/src/chain.ts +71 -0
  91. package/src/client.ts +58 -0
  92. package/src/config.ts +103 -0
  93. package/src/constants.ts +4 -0
  94. package/src/contracts/empire_base.ts +19 -0
  95. package/src/contracts/fee_juice.ts +43 -0
  96. package/src/contracts/forwarder.ts +132 -0
  97. package/src/contracts/governance.ts +285 -0
  98. package/src/contracts/governance_proposer.ts +82 -0
  99. package/src/contracts/index.ts +8 -0
  100. package/src/contracts/registry.ts +106 -0
  101. package/src/contracts/rollup.ts +274 -0
  102. package/src/contracts/slashing_proposer.ts +51 -0
  103. package/src/deploy_l1_contracts.ts +948 -0
  104. package/src/eth_cheat_codes.ts +314 -0
  105. package/src/index.ts +13 -0
  106. package/src/l1_contract_addresses.ts +109 -0
  107. package/src/l1_reader.ts +42 -0
  108. package/src/l1_tx_utils.ts +847 -0
  109. package/src/l1_tx_utils_with_blobs.ts +86 -0
  110. package/src/queries.ts +58 -0
  111. package/src/test/delayed_tx_utils.ts +24 -0
  112. package/src/test/eth_cheat_codes_with_state.ts +38 -0
  113. package/src/test/index.ts +5 -0
  114. package/src/test/start_anvil.ts +52 -0
  115. package/src/test/tx_delayer.ts +163 -0
  116. package/src/test/upgrade_utils.ts +100 -0
  117. package/src/types.ts +33 -0
  118. package/src/utils.ts +276 -0
@@ -0,0 +1,64 @@
1
+ import { Blob } from '@aztec/blob-lib';
2
+ import { formatGwei } from 'viem';
3
+ import { L1TxUtils } from './l1_tx_utils.js';
4
+ export class L1TxUtilsWithBlobs extends L1TxUtils {
5
+ /**
6
+ * Attempts to cancel a transaction by sending a 0-value tx to self with same nonce but higher gas prices
7
+ * @param nonce - The nonce of the transaction to cancel
8
+ * @param previousGasPrice - The gas price of the previous transaction
9
+ * @param attempts - The number of attempts to cancel the transaction
10
+ * @returns The hash of the cancellation transaction
11
+ */ async attemptTxCancellation(nonce, isBlobTx = false, previousGasPrice, attempts = 0) {
12
+ const account = this.walletClient.account;
13
+ // Get gas price with higher priority fee for cancellation
14
+ const cancelGasPrice = await this.getGasPrice({
15
+ ...this.config,
16
+ // Use high bump for cancellation to ensure it replaces the original tx
17
+ priorityFeeRetryBumpPercentage: 150
18
+ }, isBlobTx, attempts + 1, previousGasPrice);
19
+ this.logger?.debug(`Attempting to cancel transaction with nonce ${nonce}`, {
20
+ maxFeePerGas: formatGwei(cancelGasPrice.maxFeePerGas),
21
+ maxPriorityFeePerGas: formatGwei(cancelGasPrice.maxPriorityFeePerGas)
22
+ });
23
+ const request = {
24
+ to: account.address,
25
+ value: 0n
26
+ };
27
+ // Send 0-value tx to self with higher gas price
28
+ if (!isBlobTx) {
29
+ const cancelTxHash = await this.walletClient.sendTransaction({
30
+ ...request,
31
+ nonce,
32
+ gas: 21_000n,
33
+ maxFeePerGas: cancelGasPrice.maxFeePerGas,
34
+ maxPriorityFeePerGas: cancelGasPrice.maxPriorityFeePerGas
35
+ });
36
+ const receipt = await this.monitorTransaction(request, cancelTxHash, {
37
+ gasLimit: 21_000n
38
+ }, undefined, undefined, true);
39
+ return receipt.transactionHash;
40
+ } else {
41
+ const blobData = new Uint8Array(131072).fill(0);
42
+ const kzg = Blob.getViemKzgInstance();
43
+ const blobInputs = {
44
+ blobs: [
45
+ blobData
46
+ ],
47
+ kzg,
48
+ maxFeePerBlobGas: cancelGasPrice.maxFeePerBlobGas
49
+ };
50
+ const cancelTxHash = await this.walletClient.sendTransaction({
51
+ ...request,
52
+ ...blobInputs,
53
+ nonce,
54
+ gas: 21_000n,
55
+ maxFeePerGas: cancelGasPrice.maxFeePerGas,
56
+ maxPriorityFeePerGas: cancelGasPrice.maxPriorityFeePerGas
57
+ });
58
+ const receipt = await this.monitorTransaction(request, cancelTxHash, {
59
+ gasLimit: 21_000n
60
+ }, undefined, blobInputs, true);
61
+ return receipt.transactionHash;
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,12 @@
1
+ import type { EthAddress } from '@aztec/foundation/eth-address';
2
+ import type { L1ContractsConfig } from './config.js';
3
+ import type { ViemPublicClient } from './types.js';
4
+ /** Reads the L1ContractsConfig from L1 contracts. */
5
+ export declare function getL1ContractsConfig(publicClient: ViemPublicClient, addresses: {
6
+ governanceAddress: EthAddress;
7
+ rollupAddress?: EthAddress;
8
+ }): Promise<Omit<L1ContractsConfig, 'ethereumSlotDuration'> & {
9
+ l1StartBlock: bigint;
10
+ l1GenesisTime: bigint;
11
+ }>;
12
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,qDAAqD;AACrD,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,gBAAgB,EAC9B,SAAS,EAAE;IAAE,iBAAiB,EAAE,UAAU,CAAC;IAAC,aAAa,CAAC,EAAE,UAAU,CAAA;CAAE,GACvE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,GAAG;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC,CA8C5G"}
@@ -0,0 +1,35 @@
1
+ import { GovernanceContract } from './contracts/governance.js';
2
+ import { RollupContract } from './contracts/rollup.js';
3
+ /** Reads the L1ContractsConfig from L1 contracts. */ export async function getL1ContractsConfig(publicClient, addresses) {
4
+ const governance = new GovernanceContract(addresses.governanceAddress.toString(), publicClient, undefined);
5
+ const governanceProposer = await governance.getProposer();
6
+ const rollupAddress = addresses.rollupAddress ?? (await governance.getGovernanceAddresses()).rollupAddress;
7
+ const rollup = new RollupContract(publicClient, rollupAddress.toString());
8
+ const slasherProposer = await rollup.getSlashingProposer();
9
+ const [l1StartBlock, l1GenesisTime, aztecEpochDuration, aztecProofSubmissionWindow, aztecSlotDuration, aztecTargetCommitteeSize, minimumStake, governanceProposerQuorum, governanceProposerRoundSize, slashingQuorum, slashingRoundSize] = await Promise.all([
10
+ rollup.getL1StartBlock(),
11
+ rollup.getL1GenesisTime(),
12
+ rollup.getEpochDuration(),
13
+ rollup.getProofSubmissionWindow(),
14
+ rollup.getSlotDuration(),
15
+ rollup.getTargetCommitteeSize(),
16
+ rollup.getMinimumStake(),
17
+ governanceProposer.getQuorumSize(),
18
+ governanceProposer.getRoundSize(),
19
+ slasherProposer.getQuorumSize(),
20
+ slasherProposer.getRoundSize()
21
+ ]);
22
+ return {
23
+ l1StartBlock,
24
+ l1GenesisTime,
25
+ aztecEpochDuration: Number(aztecEpochDuration),
26
+ aztecProofSubmissionWindow: Number(aztecProofSubmissionWindow),
27
+ aztecSlotDuration: Number(aztecSlotDuration),
28
+ aztecTargetCommitteeSize: Number(aztecTargetCommitteeSize),
29
+ governanceProposerQuorum: Number(governanceProposerQuorum),
30
+ governanceProposerRoundSize: Number(governanceProposerRoundSize),
31
+ minimumStake,
32
+ slashingQuorum: Number(slashingQuorum),
33
+ slashingRoundSize: Number(slashingRoundSize)
34
+ };
35
+ }
@@ -0,0 +1,8 @@
1
+ import { L1TxUtilsWithBlobs } from '../l1_tx_utils_with_blobs.js';
2
+ import { type Delayer } from './tx_delayer.js';
3
+ export declare class DelayedTxUtils extends L1TxUtilsWithBlobs {
4
+ delayer: Delayer | undefined;
5
+ static fromL1TxUtils(l1TxUtils: L1TxUtilsWithBlobs, ethereumSlotDuration: number): DelayedTxUtils;
6
+ enableDelayer(ethereumSlotDuration: number): void;
7
+ }
8
+ //# sourceMappingURL=delayed_tx_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delayed_tx_utils.d.ts","sourceRoot":"","sources":["../../src/test/delayed_tx_utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,KAAK,OAAO,EAAe,MAAM,iBAAiB,CAAC;AAE5D,qBAAa,cAAe,SAAQ,kBAAkB;IAC7C,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;WAEtB,aAAa,CAAC,SAAS,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM;IAUhF,aAAa,CAAC,oBAAoB,EAAE,MAAM;CAOlD"}
@@ -0,0 +1,21 @@
1
+ import { L1TxUtilsWithBlobs } from '../l1_tx_utils_with_blobs.js';
2
+ import { withDelayer } from './tx_delayer.js';
3
+ export class DelayedTxUtils extends L1TxUtilsWithBlobs {
4
+ delayer;
5
+ static fromL1TxUtils(l1TxUtils, ethereumSlotDuration) {
6
+ const { client, delayer } = withDelayer(l1TxUtils.walletClient, {
7
+ ethereumSlotDuration
8
+ });
9
+ const casted = l1TxUtils;
10
+ casted.delayer = delayer;
11
+ casted.walletClient = client;
12
+ return casted;
13
+ }
14
+ enableDelayer(ethereumSlotDuration) {
15
+ const { client, delayer } = withDelayer(this.walletClient, {
16
+ ethereumSlotDuration
17
+ });
18
+ this.delayer = delayer;
19
+ this.walletClient = client;
20
+ }
21
+ }
@@ -0,0 +1,18 @@
1
+ import { EthCheatCodes } from '../eth_cheat_codes.js';
2
+ /**
3
+ * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
4
+ * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
5
+ */
6
+ export declare class EthCheatCodesWithState extends EthCheatCodes {
7
+ /**
8
+ * Dumps the current chain state to a file.
9
+ * @param fileName - The file name to dump state into
10
+ */
11
+ dumpChainState(fileName: string): Promise<void>;
12
+ /**
13
+ * Loads the chain state from a file.
14
+ * @param fileName - The file name to load state from
15
+ */
16
+ loadChainState(fileName: string): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=eth_cheat_codes_with_state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth_cheat_codes_with_state.d.ts","sourceRoot":"","sources":["../../src/test/eth_cheat_codes_with_state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,aAAa;IACvD;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW5D;;;OAGG;IACU,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7D"}
@@ -0,0 +1,34 @@
1
+ import fs from 'fs';
2
+ import { EthCheatCodes } from '../eth_cheat_codes.js';
3
+ /**
4
+ * A class that provides utility functions for interacting with ethereum (L1) dumping/loading state to/from a file.
5
+ * It is separated to avoid importing fs in the main EthCheatCodes class, which might be used in the browser.
6
+ */ export class EthCheatCodesWithState extends EthCheatCodes {
7
+ /**
8
+ * Dumps the current chain state to a file.
9
+ * @param fileName - The file name to dump state into
10
+ */ async dumpChainState(fileName) {
11
+ let res;
12
+ try {
13
+ res = await this.rpcCall('hardhat_dumpState', []);
14
+ } catch (e) {
15
+ throw new Error(`Error dumping state: ${e}`);
16
+ }
17
+ fs.writeFileSync(`${fileName}.json`, res, 'utf8');
18
+ this.logger.verbose(`Dumped state to ${fileName}`);
19
+ }
20
+ /**
21
+ * Loads the chain state from a file.
22
+ * @param fileName - The file name to load state from
23
+ */ async loadChainState(fileName) {
24
+ const data = JSON.parse(fs.readFileSync(`${fileName}.json`, 'utf8'));
25
+ try {
26
+ await this.rpcCall('hardhat_loadState', [
27
+ data
28
+ ]);
29
+ } catch (e) {
30
+ throw new Error(`Error loading state: ${e}`);
31
+ }
32
+ this.logger.verbose(`Loaded state from ${fileName}`);
33
+ }
34
+ }
@@ -0,0 +1,6 @@
1
+ export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes_with_state.js';
3
+ export * from './start_anvil.js';
4
+ export * from './tx_delayer.js';
5
+ export * from './upgrade_utils.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './delayed_tx_utils.js';
2
+ export * from './eth_cheat_codes_with_state.js';
3
+ export * from './start_anvil.js';
4
+ export * from './tx_delayer.js';
5
+ export * from './upgrade_utils.js';
@@ -0,0 +1,12 @@
1
+ import { type Anvil } from '@viem/anvil';
2
+ /**
3
+ * Ensures there's a running Anvil instance and returns the RPC URL.
4
+ */
5
+ export declare function startAnvil(opts?: {
6
+ l1BlockTime?: number;
7
+ }): Promise<{
8
+ anvil: Anvil;
9
+ rpcUrl: string;
10
+ stop: () => Promise<void>;
11
+ }>;
12
+ //# sourceMappingURL=start_anvil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start_anvil.d.ts","sourceRoot":"","sources":["../../src/test/start_anvil.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,KAAK,EAAe,MAAM,aAAa,CAAC;AAGtD;;GAEG;AACH,wBAAsB,UAAU,CAC9B,IAAI,GAAE;IACJ,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,OAAO,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC,CAsCtE"}
@@ -0,0 +1,46 @@
1
+ import { makeBackoff, retry } from '@aztec/foundation/retry';
2
+ import { fileURLToPath } from '@aztec/foundation/url';
3
+ import { createAnvil } from '@viem/anvil';
4
+ import { dirname, resolve } from 'path';
5
+ /**
6
+ * Ensures there's a running Anvil instance and returns the RPC URL.
7
+ */ export async function startAnvil(opts = {}) {
8
+ const anvilBinary = resolve(dirname(fileURLToPath(import.meta.url)), '../../', 'scripts/anvil_kill_wrapper.sh');
9
+ let port;
10
+ // Start anvil.
11
+ // We go via a wrapper script to ensure if the parent dies, anvil dies.
12
+ const anvil = await retry(async ()=>{
13
+ const anvil = createAnvil({
14
+ anvilBinary,
15
+ port: 0,
16
+ blockTime: opts.l1BlockTime,
17
+ stopTimeout: 1000
18
+ });
19
+ // Listen to the anvil output to get the port.
20
+ const removeHandler = anvil.on('message', (message)=>{
21
+ if (port === undefined && message.includes('Listening on')) {
22
+ port = parseInt(message.match(/Listening on ([^:]+):(\d+)/)[2]);
23
+ }
24
+ });
25
+ await anvil.start();
26
+ removeHandler();
27
+ return anvil;
28
+ }, 'Start anvil', makeBackoff([
29
+ 5,
30
+ 5,
31
+ 5
32
+ ]));
33
+ if (!port) {
34
+ throw new Error('Failed to start anvil');
35
+ }
36
+ // Monkeypatch the anvil instance to include the actually assigned port
37
+ Object.defineProperty(anvil, 'port', {
38
+ value: port,
39
+ writable: false
40
+ });
41
+ return {
42
+ anvil,
43
+ stop: ()=>anvil.stop(),
44
+ rpcUrl: `http://127.0.0.1:${port}`
45
+ };
46
+ }
@@ -0,0 +1,25 @@
1
+ import { type Logger } from '@aztec/foundation/log';
2
+ import { type Client, type Hex } from 'viem';
3
+ import type { ViemWalletClient } from '../types.js';
4
+ export declare function waitUntilBlock<T extends Client>(client: T, blockNumber: number | bigint, logger?: Logger): Promise<boolean>;
5
+ export declare function waitUntilL1Timestamp<T extends Client>(client: T, timestamp: number | bigint, logger?: Logger): Promise<boolean>;
6
+ export interface Delayer {
7
+ /** Returns the list of all txs (not just the delayed ones) sent through the attached client. */
8
+ getTxs(): Hex[];
9
+ /** Delays the next tx to be sent so it lands on the given L1 block number. */
10
+ pauseNextTxUntilBlock(l1BlockNumber: number | bigint | undefined): void;
11
+ /** Delays the next tx to be sent so it lands on the given timestamp. */
12
+ pauseNextTxUntilTimestamp(l1Timestamp: number | bigint | undefined): void;
13
+ }
14
+ /**
15
+ * Returns a new client (without modifying the one passed in) with an injected tx delayer.
16
+ * The delayer can be used to hold off the next tx to be sent until a given block number.
17
+ * TODO(#10824): This doesn't play along well with blob txs for some reason.
18
+ */
19
+ export declare function withDelayer<T extends ViemWalletClient>(client: T, opts: {
20
+ ethereumSlotDuration: bigint | number;
21
+ }): {
22
+ client: T;
23
+ delayer: Delayer;
24
+ };
25
+ //# sourceMappingURL=tx_delayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx_delayer.d.ts","sourceRoot":"","sources":["../../src/test/tx_delayer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAIlE,OAAO,EACL,KAAK,MAAM,EACX,KAAK,GAAG,EAMT,MAAM,MAAM,CAAC;AAEd,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,oBAgBxG;AAED,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,oBAuB5G;AAED,MAAM,WAAW,OAAO;IACtB,gGAAgG;IAChG,MAAM,IAAI,GAAG,EAAE,CAAC;IAChB,8EAA8E;IAC9E,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACxE,wEAAwE;IACxE,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;CAC3E;AAwBD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,gBAAgB,EACpD,MAAM,EAAE,CAAC,EACT,IAAI,EAAE;IAAE,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CA+DjC"}
@@ -0,0 +1,116 @@
1
+ import { omit } from '@aztec/foundation/collection';
2
+ import { createLogger } from '@aztec/foundation/log';
3
+ import { retryUntil } from '@aztec/foundation/retry';
4
+ import { inspect } from 'util';
5
+ import { keccak256, parseTransaction, publicActions, walletActions } from 'viem';
6
+ export function waitUntilBlock(client, blockNumber, logger) {
7
+ const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
8
+ return retryUntil(async ()=>{
9
+ const currentBlockNumber = await publicClient.getBlockNumber({
10
+ cacheTime: 0
11
+ });
12
+ logger?.debug(`Block number is ${currentBlockNumber} (waiting until ${blockNumber})`);
13
+ return currentBlockNumber >= BigInt(blockNumber);
14
+ }, `Wait until L1 block ${blockNumber}`, 120, 0.1);
15
+ }
16
+ export function waitUntilL1Timestamp(client, timestamp, logger) {
17
+ const publicClient = 'getBlockNumber' in client && typeof client.getBlockNumber === 'function' ? client : client.extend(publicActions);
18
+ let lastBlock = undefined;
19
+ return retryUntil(async ()=>{
20
+ const currentBlockNumber = await publicClient.getBlockNumber({
21
+ cacheTime: 0
22
+ });
23
+ if (currentBlockNumber === lastBlock) {
24
+ return false;
25
+ }
26
+ lastBlock = currentBlockNumber;
27
+ const currentBlock = await publicClient.getBlock({
28
+ includeTransactions: false,
29
+ blockNumber: currentBlockNumber
30
+ });
31
+ const currentTs = currentBlock.timestamp;
32
+ logger?.debug(`Block timstamp is ${currentTs} (waiting until ${timestamp})`);
33
+ return currentTs >= BigInt(timestamp);
34
+ }, `Wait until L1 timestamp ${timestamp}`, 120, 0.1);
35
+ }
36
+ class DelayerImpl {
37
+ constructor(opts){
38
+ this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
39
+ }
40
+ ethereumSlotDuration;
41
+ nextWait = undefined;
42
+ txs = [];
43
+ getTxs() {
44
+ return this.txs;
45
+ }
46
+ pauseNextTxUntilBlock(l1BlockNumber) {
47
+ this.nextWait = {
48
+ l1BlockNumber: BigInt(l1BlockNumber)
49
+ };
50
+ }
51
+ pauseNextTxUntilTimestamp(l1Timestamp) {
52
+ this.nextWait = {
53
+ l1Timestamp: BigInt(l1Timestamp)
54
+ };
55
+ }
56
+ }
57
+ /**
58
+ * Returns a new client (without modifying the one passed in) with an injected tx delayer.
59
+ * The delayer can be used to hold off the next tx to be sent until a given block number.
60
+ * TODO(#10824): This doesn't play along well with blob txs for some reason.
61
+ */ export function withDelayer(client, opts) {
62
+ const logger = createLogger('ethereum:tx_delayer');
63
+ const delayer = new DelayerImpl(opts);
64
+ const extended = client// Tweak sendRawTransaction so it uses the delay defined in the delayer.
65
+ // Note that this will only work with local accounts (ie accounts for which we have the private key).
66
+ // Transactions signed by the node will not be delayed since they use sendTransaction directly,
67
+ // but we do not use them in our codebase at all.
68
+ .extend((client)=>({
69
+ async sendRawTransaction (...args) {
70
+ if (delayer.nextWait !== undefined) {
71
+ const waitUntil = delayer.nextWait;
72
+ delayer.nextWait = undefined;
73
+ const publicClient = client;
74
+ const wait = 'l1BlockNumber' in waitUntil ? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger) : waitUntilL1Timestamp(publicClient, waitUntil.l1Timestamp - delayer.ethereumSlotDuration, logger);
75
+ // Compute the tx hash manually so we emulate sendRawTransaction response
76
+ const { serializedTransaction } = args[0];
77
+ const txHash = keccak256(serializedTransaction);
78
+ logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
79
+ argsLen: args.length,
80
+ ...omit(parseTransaction(serializedTransaction), 'data', 'sidecars')
81
+ });
82
+ // Do not await here so we can return the tx hash immediately as if it had been sent on the spot.
83
+ // Instead, delay it so it lands on the desired block number or timestamp, assuming anvil will
84
+ // mine it immediately.
85
+ void wait.then(async ()=>{
86
+ const clientTxHash = await client.sendRawTransaction(...args);
87
+ if (clientTxHash !== txHash) {
88
+ logger.error(`Tx hash returned by the client does not match computed one`, {
89
+ clientTxHash,
90
+ computedTxHash: txHash
91
+ });
92
+ }
93
+ logger.info(`Sent previously delayed tx ${clientTxHash} to land on ${inspect(waitUntil)}`);
94
+ delayer.txs.push(clientTxHash);
95
+ }).catch((err)=>logger.error(`Error sending tx after delay`, err));
96
+ return Promise.resolve(txHash);
97
+ } else {
98
+ const txHash = await client.sendRawTransaction(...args);
99
+ logger.verbose(`Sent tx immediately ${txHash}`);
100
+ delayer.txs.push(txHash);
101
+ return txHash;
102
+ }
103
+ }
104
+ }))// Re-extend with sendTransaction so it uses the modified sendRawTransaction.
105
+ .extend((client)=>({
106
+ sendTransaction: walletActions(client).sendTransaction
107
+ }))// And with the actions that depend on the modified sendTransaction
108
+ .extend((client)=>({
109
+ writeContract: walletActions(client).writeContract,
110
+ deployContract: walletActions(client).deployContract
111
+ }));
112
+ return {
113
+ client: extended,
114
+ delayer
115
+ };
116
+ }
@@ -0,0 +1,11 @@
1
+ import type { Logger } from '@aztec/foundation/log';
2
+ import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
3
+ import { type GetContractReturnType, type PrivateKeyAccount } from 'viem';
4
+ import type { L1ContractAddresses } from '../l1_contract_addresses.js';
5
+ import type { L1Clients } from '../types.js';
6
+ export declare function executeGovernanceProposal(proposalId: bigint, governance: GetContractReturnType<typeof GovernanceAbi, L1Clients['publicClient']>, voteAmount: bigint, privateKey: PrivateKeyAccount, publicClient: L1Clients['publicClient'], walletClient: L1Clients['walletClient'], rpcUrls: string[], logger: Logger): Promise<void>;
7
+ export declare function createGovernanceProposal(payloadAddress: `0x${string}`, addresses: L1ContractAddresses, privateKey: PrivateKeyAccount, publicClient: L1Clients['publicClient'], logger: Logger): Promise<{
8
+ governance: GetContractReturnType<typeof GovernanceAbi, L1Clients['publicClient']>;
9
+ voteAmount: bigint;
10
+ }>;
11
+ //# sourceMappingURL=upgrade_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade_utils.d.ts","sourceRoot":"","sources":["../../src/test/upgrade_utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,iBAAiB,EAAe,MAAM,MAAM,CAAC;AAGvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,wBAAsB,yBAAyB,CAC7C,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,qBAAqB,CAAC,OAAO,aAAa,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC,EAClF,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,EACvC,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,EACvC,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,iBAoCf;AAED,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,KAAK,MAAM,EAAE,EAC7B,SAAS,EAAE,mBAAmB,EAC9B,UAAU,EAAE,iBAAiB,EAC7B,YAAY,EAAE,SAAS,CAAC,cAAc,CAAC,EACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,UAAU,EAAE,qBAAqB,CAAC,OAAO,aAAa,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAqCrH"}
@@ -0,0 +1,104 @@
1
+ import { TestERC20Abi as FeeJuiceAbi } from '@aztec/l1-artifacts';
2
+ import { GovernanceAbi } from '@aztec/l1-artifacts/GovernanceAbi';
3
+ import { getContract } from 'viem';
4
+ import { EthCheatCodes } from '../eth_cheat_codes.js';
5
+ export async function executeGovernanceProposal(proposalId, governance, voteAmount, privateKey, publicClient, walletClient, rpcUrls, logger) {
6
+ const proposal = await governance.read.getProposal([
7
+ proposalId
8
+ ]);
9
+ const waitL1Block = async ()=>{
10
+ await publicClient.waitForTransactionReceipt({
11
+ hash: await walletClient.sendTransaction({
12
+ to: privateKey.address,
13
+ value: 1n,
14
+ account: privateKey
15
+ })
16
+ });
17
+ };
18
+ const cheatCodes = new EthCheatCodes(rpcUrls, logger);
19
+ const timeToActive = proposal.creation + proposal.config.votingDelay;
20
+ logger.info(`Warping to ${timeToActive + 1n}`);
21
+ await cheatCodes.warp(Number(timeToActive + 1n));
22
+ logger.info(`Warped to ${timeToActive + 1n}`);
23
+ await waitL1Block();
24
+ logger.info(`Voting`);
25
+ const voteTx = await governance.write.vote([
26
+ proposalId,
27
+ voteAmount,
28
+ true
29
+ ], {
30
+ account: privateKey
31
+ });
32
+ await publicClient.waitForTransactionReceipt({
33
+ hash: voteTx
34
+ });
35
+ logger.info(`Voted`);
36
+ const timeToExecutable = timeToActive + proposal.config.votingDuration + proposal.config.executionDelay + 1n;
37
+ logger.info(`Warping to ${timeToExecutable}`);
38
+ await cheatCodes.warp(Number(timeToExecutable));
39
+ logger.info(`Warped to ${timeToExecutable}`);
40
+ await waitL1Block();
41
+ const executeTx = await governance.write.execute([
42
+ proposalId
43
+ ], {
44
+ account: privateKey
45
+ });
46
+ await publicClient.waitForTransactionReceipt({
47
+ hash: executeTx
48
+ });
49
+ logger.info(`Executed proposal`);
50
+ }
51
+ export async function createGovernanceProposal(payloadAddress, addresses, privateKey, publicClient, logger) {
52
+ const token = getContract({
53
+ address: addresses.feeJuiceAddress.toString(),
54
+ abi: FeeJuiceAbi,
55
+ client: publicClient
56
+ });
57
+ const governance = getContract({
58
+ address: addresses.governanceAddress.toString(),
59
+ abi: GovernanceAbi,
60
+ client: publicClient
61
+ });
62
+ const lockAmount = 10000n * 10n ** 18n;
63
+ const voteAmount = 10000n * 10n ** 18n;
64
+ const mintTx = await token.write.mint([
65
+ privateKey.address,
66
+ lockAmount + voteAmount
67
+ ], {
68
+ account: privateKey
69
+ });
70
+ await publicClient.waitForTransactionReceipt({
71
+ hash: mintTx
72
+ });
73
+ logger.info(`Minted tokens`);
74
+ const approveTx = await token.write.approve([
75
+ addresses.governanceAddress.toString(),
76
+ lockAmount + voteAmount
77
+ ], {
78
+ account: privateKey
79
+ });
80
+ await publicClient.waitForTransactionReceipt({
81
+ hash: approveTx
82
+ });
83
+ logger.info(`Approved tokens`);
84
+ const depositTx = await governance.write.deposit([
85
+ privateKey.address,
86
+ lockAmount + voteAmount
87
+ ], {
88
+ account: privateKey
89
+ });
90
+ await publicClient.waitForTransactionReceipt({
91
+ hash: depositTx
92
+ });
93
+ logger.info(`Deposited tokens`);
94
+ await governance.write.proposeWithLock([
95
+ payloadAddress,
96
+ privateKey.address
97
+ ], {
98
+ account: privateKey
99
+ });
100
+ return {
101
+ governance,
102
+ voteAmount
103
+ };
104
+ }
@@ -0,0 +1,14 @@
1
+ import type { Account, Chain, Client, FallbackTransport, HttpTransport, PublicActions, PublicClient, PublicRpcSchema, WalletActions, WalletClient, WalletRpcSchema } from 'viem';
2
+ /** Type for a viem public client */
3
+ export type ViemPublicClient = PublicClient<FallbackTransport<HttpTransport[]>, Chain>;
4
+ export type SimpleViemWalletClient = WalletClient<FallbackTransport<HttpTransport[]>, Chain, Account>;
5
+ export type ExtendedViemWalletClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, Account, [
6
+ ...PublicRpcSchema,
7
+ ...WalletRpcSchema
8
+ ], PublicActions<FallbackTransport<readonly HttpTransport[]>, Chain> & WalletActions<Chain, Account>>;
9
+ export type ViemWalletClient = SimpleViemWalletClient | ExtendedViemWalletClient;
10
+ export type L1Clients = {
11
+ publicClient: ViemPublicClient;
12
+ walletClient: ExtendedViemWalletClient;
13
+ };
14
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,KAAK,EACL,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,aAAa,EACb,YAAY,EACZ,eAAe,EAChB,MAAM,MAAM,CAAC;AAEd,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAEvF,MAAM,MAAM,sBAAsB,GAAG,YAAY,CAAC,iBAAiB,CAAC,aAAa,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AAEtG,MAAM,MAAM,wBAAwB,GAAG,MAAM,CAC3C,iBAAiB,CAAC,SAAS,aAAa,EAAE,CAAC,EAC3C,KAAK,EACL,OAAO,EACP;IAAC,GAAG,eAAe;IAAE,GAAG,eAAe;CAAC,EACxC,aAAa,CAAC,iBAAiB,CAAC,SAAS,aAAa,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAClG,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,wBAAwB,CAAC;AAEjF,MAAM,MAAM,SAAS,GAAG;IACtB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,wBAAwB,CAAC;CACxC,CAAC"}
package/dest/types.js ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,24 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { Logger } from '@aztec/foundation/log';
3
+ import { type Abi, type ContractEventName, type DecodeEventLogReturnType, type Hex, type Log } from 'viem';
4
+ export interface L2Claim {
5
+ claimSecret: Fr;
6
+ claimAmount: Fr;
7
+ messageHash: Hex;
8
+ messageLeafIndex: bigint;
9
+ }
10
+ export declare class FormattedViemError extends Error {
11
+ metaMessages?: any[];
12
+ constructor(message: string, metaMessages?: any[]);
13
+ }
14
+ export declare function extractEvent<const TAbi extends Abi | readonly unknown[], TEventName extends ContractEventName<TAbi>, TEventType = DecodeEventLogReturnType<TAbi, TEventName, Hex[], undefined, true>>(logs: Log[], address: Hex, abi: TAbi, eventName: TEventName, filter?: (log: TEventType) => boolean, logger?: Logger): TEventType;
15
+ export declare function prettyLogViemErrorMsg(err: any): any;
16
+ /**
17
+ * Formats a Viem error into a FormattedViemError instance.
18
+ * @param error - The error to format.
19
+ * @param abi - The ABI to use for decoding.
20
+ * @returns A FormattedViemError instance.
21
+ */
22
+ export declare function formatViemError(error: any, abi?: Abi): FormattedViemError;
23
+ export declare function tryGetCustomErrorName(err: any): string | undefined;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EACL,KAAK,GAAG,EAER,KAAK,iBAAiB,EAEtB,KAAK,wBAAwB,EAC7B,KAAK,GAAG,EACR,KAAK,GAAG,EAGT,MAAM,MAAM,CAAC;AAEd,MAAM,WAAW,OAAO;IACtB,WAAW,EAAE,EAAE,CAAC;IAChB,WAAW,EAAE,EAAE,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC;gBAET,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,GAAG,EAAE;CAKlD;AAED,wBAAgB,YAAY,CAC1B,KAAK,CAAC,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EAC3C,UAAU,SAAS,iBAAiB,CAAC,IAAI,CAAC,EAC1C,UAAU,GAAG,wBAAwB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,EAE/E,IAAI,EAAE,GAAG,EAAE,EACX,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,UAAU,EACrB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,OAAO,EACrC,MAAM,CAAC,EAAE,MAAM,GACd,UAAU,CAMZ;AA+BD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,OAW7C;AA0BD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,GAAE,GAAe,GAAG,kBAAkB,CAwIpF;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,sBAa7C"}