@aztec/ethereum 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (188) hide show
  1. package/dest/client.d.ts +16 -2
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +27 -7
  4. package/dest/config.d.ts +24 -32
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +63 -62
  7. package/dest/contracts/chain_state_override.d.ts +78 -0
  8. package/dest/contracts/chain_state_override.d.ts.map +1 -0
  9. package/dest/contracts/chain_state_override.js +137 -0
  10. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  11. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  12. package/dest/contracts/fee_asset_handler.js +11 -9
  13. package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
  14. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  15. package/dest/contracts/fee_asset_price_oracle.js +656 -0
  16. package/dest/contracts/governance.d.ts +110 -33
  17. package/dest/contracts/governance.d.ts.map +1 -1
  18. package/dest/contracts/governance.js +207 -16
  19. package/dest/contracts/governance_proposer.d.ts +33 -1
  20. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  21. package/dest/contracts/governance_proposer.js +438 -10
  22. package/dest/contracts/inbox.d.ts +22 -1
  23. package/dest/contracts/inbox.d.ts.map +1 -1
  24. package/dest/contracts/inbox.js +42 -2
  25. package/dest/contracts/index.d.ts +6 -3
  26. package/dest/contracts/index.d.ts.map +1 -1
  27. package/dest/contracts/index.js +5 -2
  28. package/dest/contracts/log.d.ts +13 -0
  29. package/dest/contracts/log.d.ts.map +1 -0
  30. package/dest/contracts/log.js +1 -0
  31. package/dest/contracts/multicall.d.ts +127 -12
  32. package/dest/contracts/multicall.d.ts.map +1 -1
  33. package/dest/contracts/multicall.js +201 -93
  34. package/dest/contracts/outbox.d.ts +58 -0
  35. package/dest/contracts/outbox.d.ts.map +1 -0
  36. package/dest/contracts/outbox.js +109 -0
  37. package/dest/contracts/registry.d.ts +3 -1
  38. package/dest/contracts/registry.d.ts.map +1 -1
  39. package/dest/contracts/registry.js +30 -1
  40. package/dest/contracts/rollup.d.ts +5409 -115
  41. package/dest/contracts/rollup.d.ts.map +1 -1
  42. package/dest/contracts/rollup.js +1027 -189
  43. package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +3 -4
  44. package/dest/contracts/slashing_proposer.d.ts.map +1 -0
  45. package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
  46. package/dest/deploy_aztec_l1_contracts.d.ts +20 -9
  47. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -1
  48. package/dest/deploy_aztec_l1_contracts.js +113 -37
  49. package/dest/deploy_l1_contract.js +3 -3
  50. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  51. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  52. package/dest/generated/l1-contracts-defaults.js +30 -0
  53. package/dest/l1_artifacts.d.ts +18360 -16454
  54. package/dest/l1_artifacts.d.ts.map +1 -1
  55. package/dest/l1_artifacts.js +9 -24
  56. package/dest/l1_contract_addresses.d.ts +61 -65
  57. package/dest/l1_contract_addresses.d.ts.map +1 -1
  58. package/dest/l1_contract_addresses.js +101 -82
  59. package/dest/l1_reader.d.ts +5 -5
  60. package/dest/l1_reader.d.ts.map +1 -1
  61. package/dest/l1_reader.js +9 -7
  62. package/dest/l1_tx_utils/config.d.ts +7 -1
  63. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  64. package/dest/l1_tx_utils/config.js +14 -1
  65. package/dest/l1_tx_utils/constants.d.ts +1 -1
  66. package/dest/l1_tx_utils/constants.js +2 -2
  67. package/dest/l1_tx_utils/factory.d.ts +18 -10
  68. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  69. package/dest/l1_tx_utils/factory.js +17 -7
  70. package/dest/l1_tx_utils/fee-strategies/index.d.ts +3 -2
  71. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -1
  72. package/dest/l1_tx_utils/fee-strategies/index.js +2 -1
  73. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +2 -12
  74. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -1
  75. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +36 -18
  76. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +2 -11
  77. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -1
  78. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +37 -19
  79. package/dest/l1_tx_utils/fee-strategies/types.d.ts +14 -27
  80. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -1
  81. package/dest/l1_tx_utils/fee-strategies/types.js +0 -21
  82. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +15 -15
  83. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -1
  84. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +9 -15
  85. package/dest/l1_tx_utils/index-blobs.d.ts +3 -3
  86. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -1
  87. package/dest/l1_tx_utils/index-blobs.js +2 -2
  88. package/dest/l1_tx_utils/index.d.ts +2 -1
  89. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  90. package/dest/l1_tx_utils/index.js +1 -0
  91. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +2 -2
  92. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -1
  93. package/dest/l1_tx_utils/l1_fee_analyzer.js +3 -3
  94. package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
  95. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  96. package/dest/l1_tx_utils/l1_tx_utils.js +101 -66
  97. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +1 -5
  98. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  99. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +25 -58
  100. package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
  101. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  102. package/dest/{test → l1_tx_utils}/tx_delayer.js +67 -37
  103. package/dest/publisher_manager.d.ts +21 -6
  104. package/dest/publisher_manager.d.ts.map +1 -1
  105. package/dest/publisher_manager.js +81 -7
  106. package/dest/queries.d.ts +14 -3
  107. package/dest/queries.d.ts.map +1 -1
  108. package/dest/queries.js +74 -7
  109. package/dest/test/chain_monitor.d.ts +23 -3
  110. package/dest/test/chain_monitor.d.ts.map +1 -1
  111. package/dest/test/chain_monitor.js +39 -4
  112. package/dest/test/eth_cheat_codes.d.ts +24 -4
  113. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  114. package/dest/test/eth_cheat_codes.js +17 -4
  115. package/dest/test/index.d.ts +1 -3
  116. package/dest/test/index.d.ts.map +1 -1
  117. package/dest/test/index.js +0 -2
  118. package/dest/test/rollup_cheat_codes.d.ts +34 -3
  119. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  120. package/dest/test/rollup_cheat_codes.js +75 -6
  121. package/dest/test/start_anvil.d.ts +23 -3
  122. package/dest/test/start_anvil.d.ts.map +1 -1
  123. package/dest/test/start_anvil.js +143 -29
  124. package/dest/test/upgrade_utils.js +2 -2
  125. package/dest/utils.d.ts +9 -1
  126. package/dest/utils.d.ts.map +1 -1
  127. package/dest/utils.js +81 -12
  128. package/package.json +9 -10
  129. package/src/client.ts +28 -2
  130. package/src/config.ts +81 -63
  131. package/src/contracts/README.md +157 -0
  132. package/src/contracts/chain_state_override.ts +200 -0
  133. package/src/contracts/fee_asset_handler.ts +10 -7
  134. package/src/contracts/fee_asset_price_oracle.ts +285 -0
  135. package/src/contracts/governance.ts +279 -13
  136. package/src/contracts/governance_proposer.ts +58 -2
  137. package/src/contracts/inbox.ts +62 -2
  138. package/src/contracts/index.ts +5 -2
  139. package/src/contracts/log.ts +13 -0
  140. package/src/contracts/multicall.ts +243 -102
  141. package/src/contracts/outbox.ts +128 -0
  142. package/src/contracts/registry.ts +31 -1
  143. package/src/contracts/rollup.ts +728 -148
  144. package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +16 -14
  145. package/src/deploy_aztec_l1_contracts.ts +137 -47
  146. package/src/deploy_l1_contract.ts +3 -3
  147. package/src/generated/l1-contracts-defaults.ts +32 -0
  148. package/src/l1_artifacts.ts +12 -35
  149. package/src/l1_contract_addresses.ts +120 -94
  150. package/src/l1_reader.ts +17 -10
  151. package/src/l1_tx_utils/config.ts +20 -0
  152. package/src/l1_tx_utils/constants.ts +2 -2
  153. package/src/l1_tx_utils/factory.ts +31 -31
  154. package/src/l1_tx_utils/fee-strategies/index.ts +1 -1
  155. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +46 -42
  156. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +49 -45
  157. package/src/l1_tx_utils/fee-strategies/types.ts +14 -46
  158. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +43 -54
  159. package/src/l1_tx_utils/index-blobs.ts +2 -2
  160. package/src/l1_tx_utils/index.ts +1 -0
  161. package/src/l1_tx_utils/l1_fee_analyzer.ts +2 -3
  162. package/src/l1_tx_utils/l1_tx_utils.ts +99 -48
  163. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +31 -66
  164. package/src/{test → l1_tx_utils}/tx_delayer.ts +93 -56
  165. package/src/publisher_manager.ts +107 -10
  166. package/src/queries.ts +81 -7
  167. package/src/test/chain_monitor.ts +66 -4
  168. package/src/test/eth_cheat_codes.ts +16 -4
  169. package/src/test/index.ts +0 -2
  170. package/src/test/rollup_cheat_codes.ts +82 -6
  171. package/src/test/start_anvil.ts +177 -29
  172. package/src/test/upgrade_utils.ts +2 -2
  173. package/src/utils.ts +88 -14
  174. package/dest/contracts/empire_slashing_proposer.d.ts +0 -67
  175. package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
  176. package/dest/contracts/empire_slashing_proposer.js +0 -209
  177. package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
  178. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  179. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  180. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  181. package/dest/test/delayed_tx_utils.d.ts +0 -13
  182. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  183. package/dest/test/delayed_tx_utils.js +0 -28
  184. package/dest/test/tx_delayer.d.ts +0 -36
  185. package/dest/test/tx_delayer.d.ts.map +0 -1
  186. package/src/contracts/empire_slashing_proposer.ts +0 -270
  187. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  188. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,15 +1,15 @@
1
- import type { ConfigMappingsType } from '@aztec/foundation/config';
1
+ import type { ConfigMapping, ConfigMappingsType } from '@aztec/foundation/config';
2
2
  import { EthAddress } from '@aztec/foundation/eth-address';
3
- import { schemas, zodFor } from '@aztec/foundation/schemas';
3
+ import { schemas } from '@aztec/foundation/schemas';
4
4
 
5
5
  import { z } from 'zod';
6
6
 
7
7
  /**
8
- * The names of the current L1 contract addresses.
8
+ * Required L1 contract address keys.
9
9
  * NOTE: When changing this list, make sure to update CLI & CI scripts accordingly.
10
10
  * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
11
11
  */
12
- export const L1ContractsNames = [
12
+ const REQUIRED_L1_CONTRACT_ADDRESS_KEYS = [
13
13
  'rollupAddress',
14
14
  'registryAddress',
15
15
  'inboxAddress',
@@ -23,102 +23,128 @@ export const L1ContractsNames = [
23
23
  'stakingAssetAddress',
24
24
  ] as const;
25
25
 
26
+ /** Optional L1 contract address keys — present only in some deployments. */
27
+ export const OPTIONAL_L1_CONTRACT_ADDRESS_KEYS = [
28
+ 'feeAssetHandlerAddress',
29
+ 'stakingAssetHandlerAddress',
30
+ 'zkPassportVerifierAddress',
31
+ 'gseAddress',
32
+ 'dateGatedRelayerAddress',
33
+ ] as const;
34
+
35
+ type RequiredContractKey = (typeof REQUIRED_L1_CONTRACT_ADDRESS_KEYS)[number];
36
+ type OptionalContractKey = (typeof OPTIONAL_L1_CONTRACT_ADDRESS_KEYS)[number];
37
+
26
38
  /** Provides the directory of current L1 contract addresses */
27
39
  export type L1ContractAddresses = {
28
- [K in (typeof L1ContractsNames)[number]]: EthAddress;
40
+ [K in RequiredContractKey]: EthAddress;
29
41
  } & {
30
- slashFactoryAddress?: EthAddress | undefined;
31
- feeAssetHandlerAddress?: EthAddress | undefined;
32
- stakingAssetHandlerAddress?: EthAddress | undefined;
33
- zkPassportVerifierAddress?: EthAddress | undefined;
34
- gseAddress?: EthAddress | undefined;
35
- dateGatedRelayerAddress?: EthAddress | undefined;
42
+ [K in OptionalContractKey]?: EthAddress;
36
43
  };
37
44
 
38
- export const L1ContractAddressesSchema = zodFor<L1ContractAddresses>()(
39
- z.object({
40
- rollupAddress: schemas.EthAddress,
41
- registryAddress: schemas.EthAddress,
42
- inboxAddress: schemas.EthAddress,
43
- outboxAddress: schemas.EthAddress,
44
- feeJuiceAddress: schemas.EthAddress,
45
- stakingAssetAddress: schemas.EthAddress,
46
- feeJuicePortalAddress: schemas.EthAddress,
47
- coinIssuerAddress: schemas.EthAddress,
48
- rewardDistributorAddress: schemas.EthAddress,
49
- governanceProposerAddress: schemas.EthAddress,
50
- governanceAddress: schemas.EthAddress,
51
- slashFactoryAddress: schemas.EthAddress.optional(),
52
- feeAssetHandlerAddress: schemas.EthAddress.optional(),
53
- stakingAssetHandlerAddress: schemas.EthAddress.optional(),
54
- zkPassportVerifierAddress: schemas.EthAddress.optional(),
55
- gseAddress: schemas.EthAddress.optional(),
56
- dateGatedRelayerAddress: schemas.EthAddress.optional(),
57
- }),
58
- );
45
+ /**
46
+ * Names of required L1 contract addresses.
47
+ * NOTE: When changing the set of contracts, update CLI & CI scripts accordingly.
48
+ * For reference: https://github.com/AztecProtocol/aztec-packages/pull/5553
49
+ */
50
+ export const L1ContractsNames = REQUIRED_L1_CONTRACT_ADDRESS_KEYS;
59
51
 
60
52
  const parseEnv = (val: string) => EthAddress.fromString(val);
53
+ const addrEnv = (description: string, env?: ConfigMapping<EthAddress>['env']): ConfigMapping<EthAddress> => ({
54
+ description,
55
+ parseEnv,
56
+ ...(env && { env }),
57
+ });
61
58
 
62
- export const l1ContractAddressesMapping: ConfigMappingsType<
63
- Omit<L1ContractAddresses, 'gseAddress' | 'zkPassportVerifierAddress' | 'dateGatedRelayerAddress'>
64
- > = {
65
- registryAddress: {
66
- env: 'REGISTRY_CONTRACT_ADDRESS',
67
- description: 'The deployed L1 registry contract address.',
68
- parseEnv,
69
- },
70
- slashFactoryAddress: {
71
- env: 'SLASH_FACTORY_CONTRACT_ADDRESS',
72
- description: 'The deployed L1 slashFactory contract address',
73
- parseEnv,
74
- },
75
- feeAssetHandlerAddress: {
76
- env: 'FEE_ASSET_HANDLER_CONTRACT_ADDRESS',
77
- description: 'The deployed L1 feeAssetHandler contract address',
78
- parseEnv,
79
- },
80
- rollupAddress: {
81
- description: 'The deployed L1 rollup contract address.',
82
- parseEnv,
83
- },
84
- inboxAddress: {
85
- description: 'The deployed L1 inbox contract address.',
86
- parseEnv,
87
- },
88
- outboxAddress: {
89
- description: 'The deployed L1 outbox contract address.',
90
- parseEnv,
91
- },
92
- feeJuiceAddress: {
93
- description: 'The deployed L1 Fee Juice contract address.',
94
- parseEnv,
95
- },
96
- stakingAssetAddress: {
97
- description: 'The deployed L1 staking asset contract address.',
98
- parseEnv,
99
- },
100
- feeJuicePortalAddress: {
101
- description: 'The deployed L1 Fee Juice portal contract address.',
102
- parseEnv,
103
- },
104
- coinIssuerAddress: {
105
- description: 'The deployed L1 coinIssuer contract address',
106
- parseEnv,
107
- },
108
- rewardDistributorAddress: {
109
- description: 'The deployed L1 rewardDistributor contract address',
110
- parseEnv,
111
- },
112
- governanceProposerAddress: {
113
- description: 'The deployed L1 governanceProposer contract address',
114
- parseEnv,
115
- },
116
- governanceAddress: {
117
- description: 'The deployed L1 governance contract address',
118
- parseEnv,
119
- },
120
- stakingAssetHandlerAddress: {
121
- description: 'The deployed L1 stakingAssetHandler contract address',
122
- parseEnv,
123
- },
59
+ /**
60
+ * Config mapping for all L1 contract addresses.
61
+ * This is the single source of truth for which contract addresses exist and how to parse them.
62
+ */
63
+ export const l1ContractAddressesMapping: ConfigMappingsType<L1ContractAddresses> = {
64
+ rollupAddress: addrEnv('The deployed L1 rollup contract address.'),
65
+ registryAddress: addrEnv('The deployed L1 registry contract address.', 'REGISTRY_CONTRACT_ADDRESS'),
66
+ inboxAddress: addrEnv('The deployed L1 inbox contract address.'),
67
+ outboxAddress: addrEnv('The deployed L1 outbox contract address.'),
68
+ feeJuiceAddress: addrEnv('The deployed L1 Fee Juice contract address.'),
69
+ feeJuicePortalAddress: addrEnv('The deployed L1 Fee Juice portal contract address.'),
70
+ coinIssuerAddress: addrEnv('The deployed L1 coinIssuer contract address'),
71
+ rewardDistributorAddress: addrEnv('The deployed L1 rewardDistributor contract address'),
72
+ governanceProposerAddress: addrEnv('The deployed L1 governanceProposer contract address'),
73
+ governanceAddress: addrEnv('The deployed L1 governance contract address'),
74
+ stakingAssetAddress: addrEnv('The deployed L1 staking asset contract address.'),
75
+ feeAssetHandlerAddress: addrEnv(
76
+ 'The deployed L1 feeAssetHandler contract address',
77
+ 'FEE_ASSET_HANDLER_CONTRACT_ADDRESS',
78
+ ),
79
+ stakingAssetHandlerAddress: addrEnv('The deployed L1 stakingAssetHandler contract address'),
80
+ zkPassportVerifierAddress: addrEnv('The deployed L1 ZK passport verifier contract address'),
81
+ gseAddress: addrEnv('The deployed L1 GSE contract address'),
82
+ dateGatedRelayerAddress: addrEnv('The deployed L1 date-gated relayer contract address'),
124
83
  };
84
+
85
+ /** Keys present in {@link l1ContractAddressesMapping}. */
86
+ export type L1ContractAddressMappingKey = keyof typeof l1ContractAddressesMapping;
87
+
88
+ type RequiredAddressShape = { [K in RequiredContractKey]: typeof schemas.EthAddress };
89
+ type OptionalAddressShape = { [K in OptionalContractKey]: ReturnType<typeof schemas.EthAddress.optional> };
90
+
91
+ export const L1ContractAddressesSchema = z.object({
92
+ ...(Object.fromEntries(REQUIRED_L1_CONTRACT_ADDRESS_KEYS.map(k => [k, schemas.EthAddress])) as RequiredAddressShape),
93
+ ...(Object.fromEntries(
94
+ OPTIONAL_L1_CONTRACT_ADDRESS_KEYS.map(k => [k, schemas.EthAddress.optional()]),
95
+ ) as OptionalAddressShape),
96
+ });
97
+
98
+ /**
99
+ * Selects entries from {@link l1ContractAddressesMapping} so composed configs can reuse the same
100
+ * env vars, descriptions, and parsers without duplicating definitions.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const mappings = {
105
+ * ...pickL1ContractAddressMappings('rollupAddress'),
106
+ * nodeId: { ... },
107
+ * };
108
+ * ```
109
+ */
110
+ export function pickL1ContractAddressMappings<const K extends readonly L1ContractAddressMappingKey[]>(
111
+ ...keys: K
112
+ ): Pick<typeof l1ContractAddressesMapping, K[number]> {
113
+ return Object.fromEntries(keys.map(key => [key, l1ContractAddressesMapping[key]] as const)) as Pick<
114
+ typeof l1ContractAddressesMapping,
115
+ K[number]
116
+ >;
117
+ }
118
+
119
+ /**
120
+ * Like {@link pickL1ContractAddressMappings}, but returns a fragment of {@link L1ContractAddressesSchema}'s shape for
121
+ * spreading into `z.object({ ...pickL1ContractAddressesSchemaShape('rollupAddress'), localField: z... })`.
122
+ */
123
+ export function pickL1ContractAddressesSchema<const K extends readonly L1ContractAddressMappingKey[]>(
124
+ ...keys: K
125
+ ): Pick<typeof L1ContractAddressesSchema.shape, K[number]> {
126
+ return Object.fromEntries(keys.map(key => [key, L1ContractAddressesSchema.shape[key]])) as Pick<
127
+ typeof L1ContractAddressesSchema.shape,
128
+ K[number]
129
+ >;
130
+ }
131
+
132
+ /** Builds an {@link L1ContractAddresses} object from config that stores those fields at the top level. */
133
+ export function pickL1ContractAddresses<T extends L1ContractAddresses>(config: T): L1ContractAddresses {
134
+ const result: Partial<L1ContractAddresses> = {};
135
+ for (const key of REQUIRED_L1_CONTRACT_ADDRESS_KEYS) {
136
+ result[key] = config[key];
137
+ }
138
+ for (const key of OPTIONAL_L1_CONTRACT_ADDRESS_KEYS) {
139
+ const v = config[key];
140
+ if (v !== undefined) {
141
+ result[key] = v;
142
+ }
143
+ }
144
+ return result as L1ContractAddresses;
145
+ }
146
+
147
+ export function randomL1ContractAddresses(includeOptional: boolean = false): L1ContractAddresses {
148
+ const keys = includeOptional ? [...L1ContractsNames, ...OPTIONAL_L1_CONTRACT_ADDRESS_KEYS] : L1ContractsNames;
149
+ return Object.fromEntries(keys.map(name => [name, EthAddress.random()])) as L1ContractAddresses;
150
+ }
package/src/l1_reader.ts CHANGED
@@ -1,29 +1,30 @@
1
- import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
1
+ import {
2
+ type ConfigMappingsType,
3
+ getConfigFromMappings,
4
+ numberConfigHelper,
5
+ optionalNumberConfigHelper,
6
+ } from '@aztec/foundation/config';
2
7
 
3
8
  import { type L1ContractAddresses, l1ContractAddressesMapping } from './l1_contract_addresses.js';
4
9
 
5
10
  /** Configuration of the L1GlobalReader. */
6
- export interface L1ReaderConfig {
11
+ export type L1ReaderConfig = {
7
12
  /** List of URLs of Ethereum RPC nodes that services will connect to (comma separated). */
8
13
  l1RpcUrls: string[];
9
14
  /** The RPC Url of the ethereum debug host for trace and debug methods. */
10
15
  l1DebugRpcUrls: string[];
11
16
  /** The chain ID of the ethereum host. */
12
17
  l1ChainId: number;
13
- /** The deployed l1 contract addresses */
14
- l1Contracts: L1ContractAddresses;
15
18
  /** The polling interval viem uses in ms */
16
19
  viemPollingIntervalMS: number;
17
- }
20
+ /** Timeout for HTTP requests to the L1 RPC node in ms. */
21
+ l1HttpTimeoutMS?: number;
22
+ } & L1ContractAddresses;
18
23
 
19
24
  export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
20
- l1Contracts: {
21
- description: 'The deployed L1 contract addresses',
22
- nested: l1ContractAddressesMapping,
23
- },
24
25
  l1ChainId: {
25
26
  env: 'L1_CHAIN_ID',
26
- parseEnv: (val: string) => +val,
27
+ ...optionalNumberConfigHelper(),
27
28
  description: 'The chain ID of the ethereum host.',
28
29
  },
29
30
  l1RpcUrls: {
@@ -43,6 +44,12 @@ export const l1ReaderConfigMappings: ConfigMappingsType<L1ReaderConfig> = {
43
44
  description: 'The polling interval viem uses in ms',
44
45
  ...numberConfigHelper(1_000),
45
46
  },
47
+ l1HttpTimeoutMS: {
48
+ env: 'ETHEREUM_HTTP_TIMEOUT_MS',
49
+ description: 'Timeout for HTTP requests to the L1 RPC node in ms.',
50
+ ...optionalNumberConfigHelper(),
51
+ },
52
+ ...l1ContractAddressesMapping,
46
53
  };
47
54
 
48
55
  export function getL1ReaderConfigFromEnv(): L1ReaderConfig {
@@ -5,6 +5,7 @@ import {
5
5
  getConfigFromMappings,
6
6
  getDefaultConfig,
7
7
  numberConfigHelper,
8
+ optionalNumberConfigHelper,
8
9
  } from '@aztec/foundation/config';
9
10
 
10
11
  export interface L1TxUtilsConfig {
@@ -60,6 +61,12 @@ export interface L1TxUtilsConfig {
60
61
  * How long a tx nonce can be unseen in the mempool before considering it dropped
61
62
  */
62
63
  txUnseenConsideredDroppedMs?: number;
64
+ /** Enable tx delayer. When true, wraps the viem client to intercept and delay txs. Test-only. */
65
+ enableDelayer?: boolean;
66
+ /** Max seconds into an L1 slot for tx inclusion. Txs sent later are deferred to next slot. Only used when enableDelayer is true. */
67
+ txDelayerMaxInclusionTimeIntoSlot?: number;
68
+ /** How many seconds an L1 slot lasts. */
69
+ ethereumSlotDuration?: number;
63
70
  }
64
71
 
65
72
  export const l1TxUtilsConfigMappings: ConfigMappingsType<L1TxUtilsConfig> = {
@@ -142,6 +149,19 @@ export const l1TxUtilsConfigMappings: ConfigMappingsType<L1TxUtilsConfig> = {
142
149
  env: 'L1_TX_MONITOR_TX_UNSEEN_CONSIDERED_DROPPED_MS',
143
150
  ...numberConfigHelper(6 * 12 * 1000), // 6 L1 blocks
144
151
  },
152
+ enableDelayer: {
153
+ description: 'Enable tx delayer for testing.',
154
+ ...booleanConfigHelper(false),
155
+ },
156
+ txDelayerMaxInclusionTimeIntoSlot: {
157
+ description: 'Max seconds into L1 slot for tx inclusion when delayer is enabled.',
158
+ ...optionalNumberConfigHelper(),
159
+ },
160
+ ethereumSlotDuration: {
161
+ env: 'ETHEREUM_SLOT_DURATION',
162
+ description: 'How many seconds an L1 slot lasts.',
163
+ ...numberConfigHelper(12),
164
+ },
145
165
  };
146
166
 
147
167
  // We abuse the fact that all mappings above have a non null default value and force-type this to Required
@@ -3,8 +3,8 @@
3
3
  // 1_000_000_000_000_000_000 Wei = 1 ETH
4
4
  export const WEI_CONST = 1_000_000_000n;
5
5
 
6
- // @note using this large gas limit to avoid the issue of `gas limit too low` when estimating gas in reth
7
- export const LARGE_GAS_LIMIT = 12_000_000n;
6
+ // EIP-7825: protocol-level cap on tx gas limit (2^24). Clients reject above this.
7
+ export const MAX_L1_TX_LIMIT = 16_777_216n;
8
8
 
9
9
  // setting a minimum bump percentage to 10% due to geth's implementation
10
10
  // https://github.com/ethereum/go-ethereum/blob/e3d61e6db028c412f74bc4d4c7e117a9e29d0de0/core/txpool/legacypool/list.go#L298
@@ -1,64 +1,64 @@
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
1
2
  import { EthAddress } from '@aztec/foundation/eth-address';
2
3
  import type { Logger } from '@aztec/foundation/log';
3
4
  import { DateProvider } from '@aztec/foundation/timer';
4
5
 
5
- import type { TransactionSerializable } from 'viem';
6
-
7
6
  import type { EthSigner } from '../eth-signer/eth-signer.js';
8
7
  import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
9
8
  import type { L1TxUtilsConfig } from './config.js';
10
9
  import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
11
10
  import { L1TxUtils } from './l1_tx_utils.js';
12
11
  import { createViemSigner } from './signer.js';
12
+ import { Delayer } from './tx_delayer.js';
13
13
  import type { SigningCallback } from './types.js';
14
14
 
15
- export function createL1TxUtilsFromViemWallet(
16
- client: ExtendedViemWalletClient,
17
- deps?: {
18
- logger?: Logger;
19
- dateProvider?: DateProvider;
20
- store?: IL1TxStore;
21
- metrics?: IL1TxMetrics;
22
- },
23
- config?: Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean },
24
- ): L1TxUtils {
25
- return new L1TxUtils(
15
+ /** Source of signing capability: either a wallet client or a separate client + signer. */
16
+ export type L1SignerSource = ExtendedViemWalletClient | { client: ViemClient; signer: EthSigner };
17
+
18
+ export function resolveSignerSource(source: L1SignerSource): {
19
+ client: ViemClient;
20
+ address: EthAddress;
21
+ signingCallback: SigningCallback;
22
+ } {
23
+ if ('account' in source && source.account) {
24
+ return {
25
+ client: source as ExtendedViemWalletClient,
26
+ address: EthAddress.fromString((source as ExtendedViemWalletClient).account.address),
27
+ signingCallback: createViemSigner(source as ExtendedViemWalletClient),
28
+ };
29
+ }
30
+ const { client, signer } = source as { client: ViemClient; signer: EthSigner };
31
+ return {
26
32
  client,
27
- EthAddress.fromString(client.account.address),
28
- createViemSigner(client),
29
- deps?.logger,
30
- deps?.dateProvider,
31
- config,
32
- config?.debugMaxGasLimit ?? false,
33
- deps?.store,
34
- deps?.metrics,
35
- );
33
+ address: signer.address,
34
+ signingCallback: async (tx, _addr) => (await signer.signTransaction(tx)).toViemTransactionSignature(),
35
+ };
36
36
  }
37
37
 
38
- export function createL1TxUtilsFromEthSigner(
39
- client: ViemClient,
40
- signer: EthSigner,
38
+ export function createL1TxUtils(
39
+ source: L1SignerSource,
41
40
  deps?: {
42
41
  logger?: Logger;
43
42
  dateProvider?: DateProvider;
44
43
  store?: IL1TxStore;
45
44
  metrics?: IL1TxMetrics;
45
+ kzg?: BlobKzgInstance;
46
+ delayer?: Delayer;
46
47
  },
47
48
  config?: Partial<L1TxUtilsConfig> & { debugMaxGasLimit?: boolean },
48
49
  ): L1TxUtils {
49
- const callback: SigningCallback = async (transaction: TransactionSerializable, _signingAddress) => {
50
- return (await signer.signTransaction(transaction)).toViemTransactionSignature();
51
- };
52
-
50
+ const { client, address, signingCallback } = resolveSignerSource(source);
53
51
  return new L1TxUtils(
54
52
  client,
55
- signer.address,
56
- callback,
53
+ address,
54
+ signingCallback,
57
55
  deps?.logger,
58
56
  deps?.dateProvider,
59
57
  config,
60
58
  config?.debugMaxGasLimit ?? false,
61
59
  deps?.store,
62
60
  deps?.metrics,
61
+ deps?.kzg,
62
+ deps?.delayer,
63
63
  );
64
64
  }
@@ -4,13 +4,13 @@ import type { PriorityFeeStrategy } from './types.js';
4
4
 
5
5
  export {
6
6
  HISTORICAL_BLOCK_COUNT,
7
- executeStrategy,
8
7
  type PriorityFeeStrategy,
9
8
  type PriorityFeeStrategyContext,
10
9
  type PriorityFeeStrategyResult,
11
10
  } from './types.js';
12
11
 
13
12
  export { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
13
+ export { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
14
14
 
15
15
  /**
16
16
  * Default list of priority fee strategies to analyze.
@@ -12,50 +12,54 @@ import {
12
12
  type PriorityFeeStrategyResult,
13
13
  } from './types.js';
14
14
 
15
- /**
16
- * Type for the promises required by the competitive strategy
17
- */
18
- type P75AllTxsStrategyPromises = {
19
- networkEstimate: Promise<bigint>;
20
- pendingBlock: Promise<Awaited<ReturnType<ViemClient['getBlock']>> | null>;
21
- feeHistory: Promise<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>;
22
- };
23
-
24
15
  /**
25
16
  * Our current competitive priority fee strategy.
26
17
  * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
27
18
  * Falls back to network estimate if data is unavailable.
28
19
  */
29
- export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategyPromises> = {
20
+ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy = {
30
21
  name: 'Competitive (P75 + History) - CURRENT',
31
22
  id: 'p75_pending_txs_and_history_all_txs',
32
23
 
33
- getRequiredPromises(client: ViemClient): P75AllTxsStrategyPromises {
34
- return {
35
- networkEstimate: client.estimateMaxPriorityFeePerGas().catch(() => 0n),
36
- pendingBlock: client.getBlock({ blockTag: 'pending', includeTransactions: true }).catch(() => null),
37
- feeHistory: client
38
- .getFeeHistory({
39
- blockCount: HISTORICAL_BLOCK_COUNT,
40
- rewardPercentiles: [75],
41
- blockTag: 'latest',
42
- })
43
- .catch(() => null),
44
- };
45
- },
46
-
47
- calculate(
48
- results: {
49
- [K in keyof P75AllTxsStrategyPromises]: PromiseSettledResult<Awaited<P75AllTxsStrategyPromises[K]>>;
50
- },
51
- context: PriorityFeeStrategyContext,
52
- ): PriorityFeeStrategyResult {
53
- const { logger } = context;
24
+ async execute(client: ViemClient, context: PriorityFeeStrategyContext): Promise<PriorityFeeStrategyResult> {
25
+ const { isBlobTx, logger } = context;
26
+
27
+ // Fire all RPC calls in parallel
28
+ const [latestBlockResult, blobBaseFeeResult, networkEstimateResult, pendingBlockResult, feeHistoryResult] =
29
+ await Promise.allSettled([
30
+ client.getBlock({ blockTag: 'latest' }),
31
+ isBlobTx ? client.getBlobBaseFee() : Promise.resolve(undefined),
32
+ client.estimateMaxPriorityFeePerGas().catch(() => 0n),
33
+ client.getBlock({ blockTag: 'pending', includeTransactions: true }).catch(() => null),
34
+ client
35
+ .getFeeHistory({
36
+ blockCount: HISTORICAL_BLOCK_COUNT,
37
+ rewardPercentiles: [75],
38
+ blockTag: 'latest',
39
+ })
40
+ .catch(() => null),
41
+ ]);
42
+
43
+ // Extract latest block
44
+ if (latestBlockResult.status === 'rejected') {
45
+ throw new Error(`Failed to get latest block: ${latestBlockResult.reason}`);
46
+ }
47
+ const latestBlock = latestBlockResult.value;
48
+
49
+ // Extract blob base fee (only for blob txs)
50
+ let blobBaseFee: bigint | undefined;
51
+ if (isBlobTx) {
52
+ if (blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
53
+ blobBaseFee = blobBaseFeeResult.value;
54
+ } else {
55
+ logger?.warn('Failed to get L1 blob base fee');
56
+ }
57
+ }
54
58
 
55
- // Extract network estimate from settled result
59
+ // Extract network estimate
56
60
  const networkEstimate =
57
- results.networkEstimate.status === 'fulfilled' && typeof results.networkEstimate.value === 'bigint'
58
- ? results.networkEstimate.value
61
+ networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
62
+ ? networkEstimateResult.value
59
63
  : 0n;
60
64
 
61
65
  let competitiveFee = networkEstimate;
@@ -63,8 +67,8 @@ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategy
63
67
  networkEstimateGwei: formatGwei(networkEstimate),
64
68
  };
65
69
 
66
- // Extract pending block from settled result
67
- const pendingBlock = results.pendingBlock.status === 'fulfilled' ? results.pendingBlock.value : null;
70
+ // Extract pending block
71
+ const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
68
72
 
69
73
  // Analyze pending block transactions
70
74
  if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
@@ -73,9 +77,7 @@ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategy
73
77
  if (typeof tx === 'string') {
74
78
  return 0n;
75
79
  }
76
- const fee = tx.maxPriorityFeePerGas || 0n;
77
-
78
- return fee;
80
+ return tx.maxPriorityFeePerGas || 0n;
79
81
  })
80
82
  .filter((fee: bigint) => fee > 0n);
81
83
 
@@ -97,8 +99,8 @@ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategy
97
99
  }
98
100
  }
99
101
 
100
- // Extract fee history from settled result
101
- const feeHistory = results.feeHistory.status === 'fulfilled' ? results.feeHistory.value : null;
102
+ // Extract fee history
103
+ const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
102
104
 
103
105
  // Analyze fee history
104
106
  if (feeHistory?.reward && feeHistory.reward.length > 0) {
@@ -132,7 +134,7 @@ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategy
132
134
  // Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
133
135
  const maxReasonableFee = networkEstimate * 100n;
134
136
  if (competitiveFee > maxReasonableFee && networkEstimate > 0n) {
135
- logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
137
+ logger?.debug('Competitive fee exceeds sanity cap, using capped value', {
136
138
  competitiveFee: formatGwei(competitiveFee),
137
139
  networkEstimate: formatGwei(networkEstimate),
138
140
  cappedTo: formatGwei(maxReasonableFee),
@@ -153,6 +155,8 @@ export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy<P75AllTxsStrategy
153
155
 
154
156
  return {
155
157
  priorityFee: competitiveFee,
158
+ latestBlock,
159
+ blobBaseFee,
156
160
  debugInfo,
157
161
  };
158
162
  },