@aztec/ethereum 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/dest/account.d.ts +1 -1
  2. package/dest/chain.d.ts +1 -1
  3. package/dest/client.d.ts +10 -2
  4. package/dest/client.d.ts.map +1 -1
  5. package/dest/client.js +13 -3
  6. package/dest/config.d.ts +24 -68
  7. package/dest/config.d.ts.map +1 -1
  8. package/dest/config.js +67 -380
  9. package/dest/constants.d.ts +1 -1
  10. package/dest/contracts/empire_base.d.ts +9 -5
  11. package/dest/contracts/empire_base.d.ts.map +1 -1
  12. package/dest/contracts/empire_base.js +1 -1
  13. package/dest/contracts/empire_slashing_proposer.d.ts +8 -4
  14. package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
  15. package/dest/contracts/empire_slashing_proposer.js +39 -17
  16. package/dest/contracts/errors.d.ts +1 -1
  17. package/dest/contracts/errors.d.ts.map +1 -1
  18. package/dest/contracts/fee_asset_handler.d.ts +6 -5
  19. package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
  20. package/dest/contracts/fee_asset_handler.js +11 -9
  21. package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
  22. package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
  23. package/dest/contracts/fee_asset_price_oracle.js +651 -0
  24. package/dest/contracts/fee_juice.d.ts +1 -1
  25. package/dest/contracts/fee_juice.d.ts.map +1 -1
  26. package/dest/contracts/governance.d.ts +18 -16
  27. package/dest/contracts/governance.d.ts.map +1 -1
  28. package/dest/contracts/governance.js +14 -4
  29. package/dest/contracts/governance_proposer.d.ts +8 -4
  30. package/dest/contracts/governance_proposer.d.ts.map +1 -1
  31. package/dest/contracts/governance_proposer.js +412 -11
  32. package/dest/contracts/gse.d.ts +1 -1
  33. package/dest/contracts/gse.d.ts.map +1 -1
  34. package/dest/contracts/inbox.d.ts +24 -3
  35. package/dest/contracts/inbox.d.ts.map +1 -1
  36. package/dest/contracts/inbox.js +36 -1
  37. package/dest/contracts/index.d.ts +4 -1
  38. package/dest/contracts/index.d.ts.map +1 -1
  39. package/dest/contracts/index.js +3 -0
  40. package/dest/contracts/log.d.ts +13 -0
  41. package/dest/contracts/log.d.ts.map +1 -0
  42. package/dest/contracts/log.js +1 -0
  43. package/dest/contracts/multicall.d.ts +2 -2
  44. package/dest/contracts/multicall.d.ts.map +1 -1
  45. package/dest/contracts/multicall.js +2 -1
  46. package/dest/contracts/outbox.d.ts +41 -0
  47. package/dest/contracts/outbox.d.ts.map +1 -0
  48. package/dest/contracts/outbox.js +86 -0
  49. package/dest/contracts/registry.d.ts +3 -1
  50. package/dest/contracts/registry.d.ts.map +1 -1
  51. package/dest/contracts/registry.js +30 -1
  52. package/dest/contracts/rollup.d.ts +208 -123
  53. package/dest/contracts/rollup.d.ts.map +1 -1
  54. package/dest/contracts/rollup.js +807 -188
  55. package/dest/contracts/slasher_contract.d.ts +1 -1
  56. package/dest/contracts/slasher_contract.d.ts.map +1 -1
  57. package/dest/contracts/tally_slashing_proposer.d.ts +9 -7
  58. package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
  59. package/dest/contracts/tally_slashing_proposer.js +11 -4
  60. package/dest/contracts/utils.d.ts +1 -1
  61. package/dest/deploy_aztec_l1_contracts.d.ts +259 -0
  62. package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
  63. package/dest/deploy_aztec_l1_contracts.js +413 -0
  64. package/dest/deploy_l1_contract.d.ts +68 -0
  65. package/dest/deploy_l1_contract.d.ts.map +1 -0
  66. package/dest/deploy_l1_contract.js +312 -0
  67. package/dest/eth-signer/eth-signer.d.ts +1 -1
  68. package/dest/eth-signer/index.d.ts +1 -1
  69. package/dest/forwarder_proxy.d.ts +32 -0
  70. package/dest/forwarder_proxy.d.ts.map +1 -0
  71. package/dest/forwarder_proxy.js +93 -0
  72. package/dest/generated/l1-contracts-defaults.d.ts +30 -0
  73. package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
  74. package/dest/generated/l1-contracts-defaults.js +30 -0
  75. package/dest/l1_artifacts.d.ts +7608 -2048
  76. package/dest/l1_artifacts.d.ts.map +1 -1
  77. package/dest/l1_contract_addresses.d.ts +3 -3
  78. package/dest/l1_contract_addresses.d.ts.map +1 -1
  79. package/dest/l1_contract_addresses.js +3 -3
  80. package/dest/l1_reader.d.ts +5 -1
  81. package/dest/l1_reader.d.ts.map +1 -1
  82. package/dest/l1_reader.js +12 -1
  83. package/dest/l1_tx_utils/config.d.ts +11 -5
  84. package/dest/l1_tx_utils/config.d.ts.map +1 -1
  85. package/dest/l1_tx_utils/config.js +43 -7
  86. package/dest/l1_tx_utils/constants.d.ts +8 -2
  87. package/dest/l1_tx_utils/constants.d.ts.map +1 -1
  88. package/dest/l1_tx_utils/constants.js +27 -2
  89. package/dest/l1_tx_utils/factory.d.ts +18 -10
  90. package/dest/l1_tx_utils/factory.d.ts.map +1 -1
  91. package/dest/l1_tx_utils/factory.js +17 -7
  92. package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
  93. package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
  94. package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
  95. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
  96. package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
  97. package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
  98. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
  99. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
  100. package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
  101. package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
  102. package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
  103. package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
  104. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
  105. package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
  106. package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
  107. package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
  108. package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
  109. package/dest/l1_tx_utils/index-blobs.js +2 -0
  110. package/dest/l1_tx_utils/index.d.ts +4 -1
  111. package/dest/l1_tx_utils/index.d.ts.map +1 -1
  112. package/dest/l1_tx_utils/index.js +3 -0
  113. package/dest/l1_tx_utils/interfaces.d.ts +2 -2
  114. package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
  115. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
  116. package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
  117. package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
  118. package/dest/l1_tx_utils/l1_tx_utils.d.ts +18 -8
  119. package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
  120. package/dest/l1_tx_utils/l1_tx_utils.js +75 -46
  121. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
  122. package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
  123. package/dest/l1_tx_utils/readonly_l1_tx_utils.js +63 -167
  124. package/dest/l1_tx_utils/signer.d.ts +1 -1
  125. package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
  126. package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
  127. package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
  128. package/dest/l1_tx_utils/types.d.ts +1 -1
  129. package/dest/l1_tx_utils/types.d.ts.map +1 -1
  130. package/dest/l1_tx_utils/utils.d.ts +1 -1
  131. package/dest/l1_types.d.ts +1 -1
  132. package/dest/publisher_manager.d.ts +3 -2
  133. package/dest/publisher_manager.d.ts.map +1 -1
  134. package/dest/publisher_manager.js +2 -2
  135. package/dest/queries.d.ts +2 -2
  136. package/dest/queries.d.ts.map +1 -1
  137. package/dest/queries.js +16 -6
  138. package/dest/test/chain_monitor.d.ts +47 -25
  139. package/dest/test/chain_monitor.d.ts.map +1 -1
  140. package/dest/test/chain_monitor.js +66 -38
  141. package/dest/test/eth_cheat_codes.d.ts +11 -3
  142. package/dest/test/eth_cheat_codes.d.ts.map +1 -1
  143. package/dest/test/eth_cheat_codes.js +11 -3
  144. package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
  145. package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
  146. package/dest/test/index.d.ts +1 -3
  147. package/dest/test/index.d.ts.map +1 -1
  148. package/dest/test/index.js +0 -2
  149. package/dest/test/rollup_cheat_codes.d.ts +17 -13
  150. package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
  151. package/dest/test/rollup_cheat_codes.js +62 -38
  152. package/dest/test/start_anvil.d.ts +18 -2
  153. package/dest/test/start_anvil.d.ts.map +1 -1
  154. package/dest/test/start_anvil.js +129 -28
  155. package/dest/test/upgrade_utils.d.ts +1 -1
  156. package/dest/test/upgrade_utils.js +2 -2
  157. package/dest/types.d.ts +57 -2
  158. package/dest/types.d.ts.map +1 -1
  159. package/dest/utils.d.ts +16 -3
  160. package/dest/utils.d.ts.map +1 -1
  161. package/dest/utils.js +80 -12
  162. package/dest/zkPassportVerifierAddress.d.ts +1 -1
  163. package/package.json +34 -16
  164. package/src/client.ts +10 -2
  165. package/src/config.ts +86 -460
  166. package/src/contracts/README.md +157 -0
  167. package/src/contracts/empire_base.ts +8 -5
  168. package/src/contracts/empire_slashing_proposer.ts +38 -32
  169. package/src/contracts/fee_asset_handler.ts +10 -7
  170. package/src/contracts/fee_asset_price_oracle.ts +280 -0
  171. package/src/contracts/governance.ts +13 -4
  172. package/src/contracts/governance_proposer.ts +26 -6
  173. package/src/contracts/inbox.ts +55 -3
  174. package/src/contracts/index.ts +3 -0
  175. package/src/contracts/log.ts +13 -0
  176. package/src/contracts/multicall.ts +5 -2
  177. package/src/contracts/outbox.ts +98 -0
  178. package/src/contracts/registry.ts +31 -1
  179. package/src/contracts/rollup.ts +485 -162
  180. package/src/contracts/tally_slashing_proposer.ts +15 -8
  181. package/src/deploy_aztec_l1_contracts.ts +650 -0
  182. package/src/deploy_l1_contract.ts +362 -0
  183. package/src/forwarder_proxy.ts +108 -0
  184. package/src/generated/l1-contracts-defaults.ts +32 -0
  185. package/src/l1_contract_addresses.ts +22 -20
  186. package/src/l1_reader.ts +21 -1
  187. package/src/l1_tx_utils/config.ts +52 -11
  188. package/src/l1_tx_utils/constants.ts +13 -2
  189. package/src/l1_tx_utils/factory.ts +31 -31
  190. package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
  191. package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
  192. package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
  193. package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
  194. package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
  195. package/src/l1_tx_utils/index-blobs.ts +2 -0
  196. package/src/l1_tx_utils/index.ts +3 -0
  197. package/src/l1_tx_utils/interfaces.ts +1 -1
  198. package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
  199. package/src/l1_tx_utils/l1_tx_utils.ts +84 -36
  200. package/src/l1_tx_utils/readonly_l1_tx_utils.ts +77 -213
  201. package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
  202. package/src/publisher_manager.ts +4 -2
  203. package/src/queries.ts +17 -6
  204. package/src/test/chain_monitor.ts +110 -51
  205. package/src/test/eth_cheat_codes.ts +9 -3
  206. package/src/test/index.ts +0 -2
  207. package/src/test/rollup_cheat_codes.ts +63 -43
  208. package/src/test/start_anvil.ts +156 -27
  209. package/src/test/upgrade_utils.ts +2 -2
  210. package/src/types.ts +62 -0
  211. package/src/utils.ts +100 -15
  212. package/dest/deploy_l1_contracts.d.ts +0 -226
  213. package/dest/deploy_l1_contracts.d.ts.map +0 -1
  214. package/dest/deploy_l1_contracts.js +0 -1473
  215. package/dest/index.d.ts +0 -18
  216. package/dest/index.d.ts.map +0 -1
  217. package/dest/index.js +0 -17
  218. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
  219. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
  220. package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
  221. package/dest/test/delayed_tx_utils.d.ts +0 -13
  222. package/dest/test/delayed_tx_utils.d.ts.map +0 -1
  223. package/dest/test/delayed_tx_utils.js +0 -28
  224. package/dest/test/tx_delayer.d.ts +0 -36
  225. package/dest/test/tx_delayer.d.ts.map +0 -1
  226. package/src/deploy_l1_contracts.ts +0 -1849
  227. package/src/index.ts +0 -17
  228. package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
  229. package/src/test/delayed_tx_utils.ts +0 -52
@@ -1,4 +1,4 @@
1
- import { bigintConfigHelper, booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper } from '@aztec/foundation/config';
1
+ import { booleanConfigHelper, floatConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
2
2
  export const l1TxUtilsConfigMappings = {
3
3
  gasLimitBufferPercentage: {
4
4
  description: 'How much to increase calculated gas limit by (percentage)',
@@ -8,12 +8,18 @@ export const l1TxUtilsConfigMappings = {
8
8
  maxGwei: {
9
9
  description: 'Maximum gas price in gwei to be used for transactions.',
10
10
  env: 'L1_GAS_PRICE_MAX',
11
- ...bigintConfigHelper(2000n)
11
+ fallback: [
12
+ 'L1_FEE_PER_GAS_GWEI_MAX'
13
+ ],
14
+ ...floatConfigHelper(2000)
12
15
  },
13
16
  maxBlobGwei: {
14
17
  description: 'Maximum blob fee per gas in gwei',
15
18
  env: 'L1_BLOB_FEE_PER_GAS_MAX',
16
- ...bigintConfigHelper(3000n)
19
+ fallback: [
20
+ 'L1_BLOB_FEE_PER_GAS_GWEI_MAX'
21
+ ],
22
+ ...floatConfigHelper(3000)
17
23
  },
18
24
  priorityFeeBumpPercentage: {
19
25
  description: 'How much to increase priority fee by each attempt (percentage)',
@@ -25,10 +31,24 @@ export const l1TxUtilsConfigMappings = {
25
31
  env: 'L1_PRIORITY_FEE_RETRY_BUMP_PERCENTAGE',
26
32
  ...numberConfigHelper(50)
27
33
  },
28
- fixedPriorityFeePerGas: {
29
- description: 'Fixed priority fee per gas in Gwei. Overrides any priority fee bump percentage',
30
- env: 'L1_FIXED_PRIORITY_FEE_PER_GAS',
31
- ...numberConfigHelper(0)
34
+ minimumPriorityFeePerGas: {
35
+ description: 'Minimum priority fee per gas in Gwei. Acts as a floor for the computed priority fee. If network conditions require a higher fee, the higher fee will be used.',
36
+ env: 'L1_MINIMUM_PRIORITY_FEE_PER_GAS_GWEI',
37
+ fallback: [
38
+ 'L1_FIXED_PRIORITY_FEE_PER_GAS',
39
+ 'L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI'
40
+ ],
41
+ deprecatedFallback: [
42
+ {
43
+ env: 'L1_FIXED_PRIORITY_FEE_PER_GAS',
44
+ message: deprecatedFixedFeeMessage('L1_FIXED_PRIORITY_FEE_PER_GAS')
45
+ },
46
+ {
47
+ env: 'L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI',
48
+ message: deprecatedFixedFeeMessage('L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI')
49
+ }
50
+ ],
51
+ ...floatConfigHelper(0)
32
52
  },
33
53
  maxSpeedUpAttempts: {
34
54
  description: 'Maximum number of speed-up attempts',
@@ -64,6 +84,19 @@ export const l1TxUtilsConfigMappings = {
64
84
  description: 'How long a tx nonce can be unseen in the mempool before considering it dropped',
65
85
  env: 'L1_TX_MONITOR_TX_UNSEEN_CONSIDERED_DROPPED_MS',
66
86
  ...numberConfigHelper(6 * 12 * 1000)
87
+ },
88
+ enableDelayer: {
89
+ description: 'Enable tx delayer for testing.',
90
+ ...booleanConfigHelper(false)
91
+ },
92
+ txDelayerMaxInclusionTimeIntoSlot: {
93
+ description: 'Max seconds into L1 slot for tx inclusion when delayer is enabled.',
94
+ ...optionalNumberConfigHelper()
95
+ },
96
+ ethereumSlotDuration: {
97
+ env: 'ETHEREUM_SLOT_DURATION',
98
+ description: 'How many seconds an L1 slot lasts.',
99
+ ...numberConfigHelper(12)
67
100
  }
68
101
  };
69
102
  // We abuse the fact that all mappings above have a non null default value and force-type this to Required
@@ -71,3 +104,6 @@ export const defaultL1TxUtilsConfig = getDefaultConfig(l1TxUtilsConfigMappings);
71
104
  export function getL1TxUtilsConfigEnvVars() {
72
105
  return getConfigFromMappings(l1TxUtilsConfigMappings);
73
106
  }
107
+ function deprecatedFixedFeeMessage(envVar) {
108
+ return `Environment variable ${envVar} is deprecated. It is now used as a MINIMUM priority fee rather than a fixed value. ` + 'Please use L1_MINIMUM_PRIORITY_FEE_PER_GAS_GWEI instead. If network conditions require a higher fee, the higher fee will be used.';
109
+ }
@@ -1,6 +1,12 @@
1
1
  export declare const WEI_CONST = 1000000000n;
2
- export declare const LARGE_GAS_LIMIT = 12000000n;
2
+ export declare const MAX_L1_TX_LIMIT = 16777216n;
3
3
  export declare const MIN_REPLACEMENT_BUMP_PERCENTAGE = 10;
4
4
  export declare const MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE = 100;
5
5
  export declare const BLOCK_TIME_MS = 12000;
6
- //# sourceMappingURL=constants.d.ts.map
6
+ export declare const GAS_PER_BLOB = 131072n;
7
+ export declare const BLOB_CAPACITY_SCHEDULE: {
8
+ timestamp: number;
9
+ target: number;
10
+ max: number;
11
+ }[];
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uc3RhbnRzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbDFfdHhfdXRpbHMvY29uc3RhbnRzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUdBLGVBQU8sTUFBTSxTQUFTLGNBQWlCLENBQUM7QUFHeEMsZUFBTyxNQUFNLGVBQWUsWUFBYyxDQUFDO0FBSTNDLGVBQU8sTUFBTSwrQkFBK0IsS0FBSyxDQUFDO0FBSWxELGVBQU8sTUFBTSxvQ0FBb0MsTUFBTSxDQUFDO0FBR3hELGVBQU8sTUFBTSxhQUFhLFFBQVMsQ0FBQztBQUdwQyxlQUFPLE1BQU0sWUFBWSxVQUFVLENBQUM7QUFHcEMsZUFBTyxNQUFNLHNCQUFzQjs7OztHQUtsQyxDQUFDIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,cAAiB,CAAC;AAGxC,eAAO,MAAM,eAAe,YAAc,CAAC;AAI3C,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAIlD,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAGxD,eAAO,MAAM,aAAa,QAAS,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/l1_tx_utils/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,cAAiB,CAAC;AAGxC,eAAO,MAAM,eAAe,YAAc,CAAC;AAI3C,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAIlD,eAAO,MAAM,oCAAoC,MAAM,CAAC;AAGxD,eAAO,MAAM,aAAa,QAAS,CAAC;AAGpC,eAAO,MAAM,YAAY,UAAU,CAAC;AAGpC,eAAO,MAAM,sBAAsB;;;;GAKlC,CAAC"}
@@ -2,8 +2,8 @@
2
2
  // 1_000_000_000 Wei = 1 Gwei
3
3
  // 1_000_000_000_000_000_000 Wei = 1 ETH
4
4
  export const WEI_CONST = 1_000_000_000n;
5
- // @note using this large gas limit to avoid the issue of `gas limit too low` when estimating gas in reth
6
- export const LARGE_GAS_LIMIT = 12_000_000n;
5
+ // EIP-7825: protocol-level cap on tx gas limit (2^24). Clients reject above this.
6
+ export const MAX_L1_TX_LIMIT = 16_777_216n;
7
7
  // setting a minimum bump percentage to 10% due to geth's implementation
8
8
  // https://github.com/ethereum/go-ethereum/blob/e3d61e6db028c412f74bc4d4c7e117a9e29d0de0/core/txpool/legacypool/list.go#L298
9
9
  export const MIN_REPLACEMENT_BUMP_PERCENTAGE = 10;
@@ -12,3 +12,28 @@ export const MIN_REPLACEMENT_BUMP_PERCENTAGE = 10;
12
12
  export const MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE = 100;
13
13
  // Avg ethereum block time is ~12s
14
14
  export const BLOCK_TIME_MS = 12_000;
15
+ // Gas per blob (EIP-4844)
16
+ export const GAS_PER_BLOB = 131072n;
17
+ // Blob capacity schedule based on Ethereum upgrades
18
+ export const BLOB_CAPACITY_SCHEDULE = [
19
+ {
20
+ timestamp: 1734357600,
21
+ target: 14,
22
+ max: 21
23
+ },
24
+ {
25
+ timestamp: 1733752800,
26
+ target: 10,
27
+ max: 15
28
+ },
29
+ {
30
+ timestamp: 1733234400,
31
+ target: 6,
32
+ max: 9
33
+ },
34
+ {
35
+ timestamp: 0,
36
+ target: 6,
37
+ max: 9
38
+ }
39
+ ];
@@ -1,3 +1,5 @@
1
+ import type { BlobKzgInstance } from '@aztec/blob-lib/types';
2
+ import { EthAddress } from '@aztec/foundation/eth-address';
1
3
  import type { Logger } from '@aztec/foundation/log';
2
4
  import { DateProvider } from '@aztec/foundation/timer';
3
5
  import type { EthSigner } from '../eth-signer/eth-signer.js';
@@ -5,20 +7,26 @@ import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
5
7
  import type { L1TxUtilsConfig } from './config.js';
6
8
  import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
7
9
  import { L1TxUtils } from './l1_tx_utils.js';
8
- export declare function createL1TxUtilsFromViemWallet(client: ExtendedViemWalletClient, deps?: {
10
+ import { Delayer } from './tx_delayer.js';
11
+ import type { SigningCallback } from './types.js';
12
+ /** Source of signing capability: either a wallet client or a separate client + signer. */
13
+ export type L1SignerSource = ExtendedViemWalletClient | {
14
+ client: ViemClient;
15
+ signer: EthSigner;
16
+ };
17
+ export declare function resolveSignerSource(source: L1SignerSource): {
18
+ client: ViemClient;
19
+ address: EthAddress;
20
+ signingCallback: SigningCallback;
21
+ };
22
+ export declare function createL1TxUtils(source: L1SignerSource, deps?: {
9
23
  logger?: Logger;
10
24
  dateProvider?: DateProvider;
11
25
  store?: IL1TxStore;
12
26
  metrics?: IL1TxMetrics;
27
+ kzg?: BlobKzgInstance;
28
+ delayer?: Delayer;
13
29
  }, config?: Partial<L1TxUtilsConfig> & {
14
30
  debugMaxGasLimit?: boolean;
15
31
  }): L1TxUtils;
16
- export declare function createL1TxUtilsFromEthSigner(client: ViemClient, signer: EthSigner, deps?: {
17
- logger?: Logger;
18
- dateProvider?: DateProvider;
19
- store?: IL1TxStore;
20
- metrics?: IL1TxMetrics;
21
- }, config?: Partial<L1TxUtilsConfig> & {
22
- debugMaxGasLimit?: boolean;
23
- }): L1TxUtils;
24
- //# sourceMappingURL=factory.d.ts.map
32
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2wxX3R4X3V0aWxzL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFDN0QsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLE1BQU0sRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBQ3BELE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSx5QkFBeUIsQ0FBQztBQUV2RCxPQUFPLEtBQUssRUFBRS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ACtB,IAAI,CAAC,EAAE;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,EACD,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,GACjE,SAAS,CAeX"}
@@ -1,12 +1,22 @@
1
1
  import { EthAddress } from '@aztec/foundation/eth-address';
2
2
  import { L1TxUtils } from './l1_tx_utils.js';
3
3
  import { createViemSigner } from './signer.js';
4
- export function createL1TxUtilsFromViemWallet(client, deps, config) {
5
- return new L1TxUtils(client, EthAddress.fromString(client.account.address), createViemSigner(client), deps?.logger, deps?.dateProvider, config, config?.debugMaxGasLimit ?? false, deps?.store, deps?.metrics);
6
- }
7
- export function createL1TxUtilsFromEthSigner(client, signer, deps, config) {
8
- const callback = async (transaction, _signingAddress)=>{
9
- return (await signer.signTransaction(transaction)).toViemTransactionSignature();
4
+ export function resolveSignerSource(source) {
5
+ if ('account' in source && source.account) {
6
+ return {
7
+ client: source,
8
+ address: EthAddress.fromString(source.account.address),
9
+ signingCallback: createViemSigner(source)
10
+ };
11
+ }
12
+ const { client, signer } = source;
13
+ return {
14
+ client,
15
+ address: signer.address,
16
+ signingCallback: async (tx, _addr)=>(await signer.signTransaction(tx)).toViemTransactionSignature()
10
17
  };
11
- return new L1TxUtils(client, signer.address, callback, deps?.logger, deps?.dateProvider, config, config?.debugMaxGasLimit ?? false, deps?.store, deps?.metrics);
18
+ }
19
+ export function createL1TxUtils(source, deps, config) {
20
+ const { client, address, signingCallback } = resolveSignerSource(source);
21
+ return new L1TxUtils(client, address, signingCallback, deps?.logger, deps?.dateProvider, config, config?.debugMaxGasLimit ?? false, deps?.store, deps?.metrics, deps?.kzg, deps?.delayer);
12
22
  }
@@ -0,0 +1,10 @@
1
+ import type { PriorityFeeStrategy } from './types.js';
2
+ export { HISTORICAL_BLOCK_COUNT, type PriorityFeeStrategy, type PriorityFeeStrategyContext, type PriorityFeeStrategyResult, } from './types.js';
3
+ export { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
4
+ export { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
5
+ /**
6
+ * Default list of priority fee strategies to analyze.
7
+ * Add more strategies here for comparison.
8
+ */
9
+ export declare const DEFAULT_PRIORITY_FEE_STRATEGIES: PriorityFeeStrategy[];
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9sMV90eF91dGlscy9mZWUtc3RyYXRlZ2llcy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssRUFBRSxtQkFBbUIsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUV0RCxPQUFPLEVBQ0wsc0JBQXNCLEVBQ3RCLEtBQUssbUJBQW1CLEVBQ3hCLEtBQUssMEJBQTBCLEVBQy9CLEtBQUsseUJBQXlCLEdBQy9CLE1BQU0sWUFBWSxDQUFDO0FBRXBCLE9BQU8sRUFBRSw0QkFBNEIsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ3BFLE9BQU8sRUFBRSxpQ0FBaUMsRUFBRSxNQUFNLG9DQUFvQyxDQUFDO0FBRXZGOzs7R0FHRztBQUNILGVBQU8sTUFBTSwrQkFBK0IsRUFBRSxtQkFBbUIsRUFHaEUsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/l1_tx_utils/fee-strategies/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EACL,sBAAsB,EACtB,KAAK,mBAAmB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,GAC/B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,mBAAmB,EAGhE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
2
+ import { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
3
+ export { HISTORICAL_BLOCK_COUNT } from './types.js';
4
+ export { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
5
+ export { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
6
+ /**
7
+ * Default list of priority fee strategies to analyze.
8
+ * Add more strategies here for comparison.
9
+ */ export const DEFAULT_PRIORITY_FEE_STRATEGIES = [
10
+ P75AllTxsPriorityFeeStrategy,
11
+ P75BlobTxsOnlyPriorityFeeStrategy
12
+ ];
@@ -0,0 +1,8 @@
1
+ import { type PriorityFeeStrategy } from './types.js';
2
+ /**
3
+ * Our current competitive priority fee strategy.
4
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
5
+ * Falls back to network estimate if data is unavailable.
6
+ */
7
+ export declare const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy;
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicDc1X2NvbXBldGl0aXZlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbDFfdHhfdXRpbHMvZmVlLXN0cmF0ZWdpZXMvcDc1X2NvbXBldGl0aXZlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQU9BLE9BQU8sRUFFTCxLQUFLLG1CQUFtQixFQUd6QixNQUFNLFlBQVksQ0FBQztBQUVwQjs7OztHQUlHO0FBQ0gsZUFBTyxNQUFNLDRCQUE0QixFQUFFLG1CQStJMUMsQ0FBQyJ9
@@ -0,0 +1 @@
1
+ {"version":3,"file":"p75_competitive.d.ts","sourceRoot":"","sources":["../../../src/l1_tx_utils/fee-strategies/p75_competitive.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,mBAAmB,EAGzB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,EAAE,mBA+I1C,CAAC"}
@@ -0,0 +1,129 @@
1
+ import { median } from '@aztec/foundation/collection';
2
+ import { formatGwei } from 'viem';
3
+ import { calculatePercentile } from '../../utils.js';
4
+ import { WEI_CONST } from '../constants.js';
5
+ import { HISTORICAL_BLOCK_COUNT } from './types.js';
6
+ /**
7
+ * Our current competitive priority fee strategy.
8
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
9
+ * Falls back to network estimate if data is unavailable.
10
+ */ export const P75AllTxsPriorityFeeStrategy = {
11
+ name: 'Competitive (P75 + History) - CURRENT',
12
+ id: 'p75_pending_txs_and_history_all_txs',
13
+ async execute (client, context) {
14
+ const { isBlobTx, logger } = context;
15
+ // Fire all RPC calls in parallel
16
+ const [latestBlockResult, blobBaseFeeResult, networkEstimateResult, pendingBlockResult, feeHistoryResult] = await Promise.allSettled([
17
+ client.getBlock({
18
+ blockTag: 'latest'
19
+ }),
20
+ isBlobTx ? client.getBlobBaseFee() : Promise.resolve(undefined),
21
+ client.estimateMaxPriorityFeePerGas().catch(()=>0n),
22
+ client.getBlock({
23
+ blockTag: 'pending',
24
+ includeTransactions: true
25
+ }).catch(()=>null),
26
+ client.getFeeHistory({
27
+ blockCount: HISTORICAL_BLOCK_COUNT,
28
+ rewardPercentiles: [
29
+ 75
30
+ ],
31
+ blockTag: 'latest'
32
+ }).catch(()=>null)
33
+ ]);
34
+ // Extract latest block
35
+ if (latestBlockResult.status === 'rejected') {
36
+ throw new Error(`Failed to get latest block: ${latestBlockResult.reason}`);
37
+ }
38
+ const latestBlock = latestBlockResult.value;
39
+ // Extract blob base fee (only for blob txs)
40
+ let blobBaseFee;
41
+ if (isBlobTx) {
42
+ if (blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
43
+ blobBaseFee = blobBaseFeeResult.value;
44
+ } else {
45
+ logger?.warn('Failed to get L1 blob base fee');
46
+ }
47
+ }
48
+ // Extract network estimate
49
+ const networkEstimate = networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint' ? networkEstimateResult.value : 0n;
50
+ let competitiveFee = networkEstimate;
51
+ const debugInfo = {
52
+ networkEstimateGwei: formatGwei(networkEstimate)
53
+ };
54
+ // Extract pending block
55
+ const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
56
+ // Analyze pending block transactions
57
+ if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
58
+ const pendingFees = pendingBlock.transactions.map((tx)=>{
59
+ if (typeof tx === 'string') {
60
+ return 0n;
61
+ }
62
+ return tx.maxPriorityFeePerGas || 0n;
63
+ }).filter((fee)=>fee > 0n);
64
+ if (pendingFees.length > 0) {
65
+ // Use 75th percentile of pending fees to be competitive
66
+ const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
67
+ if (pendingCompetitiveFee > competitiveFee) {
68
+ competitiveFee = pendingCompetitiveFee;
69
+ }
70
+ debugInfo.pendingTxCount = pendingFees.length;
71
+ debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
72
+ logger?.debug('Analyzed pending transactions for competitive pricing', {
73
+ pendingTxCount: pendingFees.length,
74
+ pendingP75: formatGwei(pendingCompetitiveFee)
75
+ });
76
+ }
77
+ }
78
+ // Extract fee history
79
+ const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
80
+ // Analyze fee history
81
+ if (feeHistory?.reward && feeHistory.reward.length > 0) {
82
+ // Extract 75th percentile fees from each block
83
+ const percentile75Fees = feeHistory.reward.map((rewards)=>rewards[0] || 0n).filter((fee)=>fee > 0n);
84
+ if (percentile75Fees.length > 0) {
85
+ // Calculate median of the 75th percentile fees across blocks
86
+ const medianHistoricalFee = median(percentile75Fees) ?? 0n;
87
+ // Debug: Log suspicious fees from history
88
+ if (medianHistoricalFee > 100n * WEI_CONST) {
89
+ logger?.warn('Suspicious high fee in history', {
90
+ historicalMedian: formatGwei(medianHistoricalFee),
91
+ allP75Fees: percentile75Fees.map((f)=>formatGwei(f))
92
+ });
93
+ }
94
+ if (medianHistoricalFee > competitiveFee) {
95
+ competitiveFee = medianHistoricalFee;
96
+ }
97
+ debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
98
+ logger?.debug('Analyzed fee history for competitive pricing', {
99
+ historicalMedian: formatGwei(medianHistoricalFee)
100
+ });
101
+ }
102
+ }
103
+ // Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
104
+ const maxReasonableFee = networkEstimate * 100n;
105
+ if (competitiveFee > maxReasonableFee && networkEstimate > 0n) {
106
+ logger?.debug('Competitive fee exceeds sanity cap, using capped value', {
107
+ competitiveFee: formatGwei(competitiveFee),
108
+ networkEstimate: formatGwei(networkEstimate),
109
+ cappedTo: formatGwei(maxReasonableFee)
110
+ });
111
+ competitiveFee = maxReasonableFee;
112
+ debugInfo.cappedToGwei = formatGwei(maxReasonableFee);
113
+ }
114
+ // Log final decision
115
+ if (competitiveFee > networkEstimate) {
116
+ logger?.debug('Using competitive fee from market analysis', {
117
+ networkEstimate: formatGwei(networkEstimate),
118
+ competitive: formatGwei(competitiveFee)
119
+ });
120
+ }
121
+ debugInfo.finalFeeGwei = formatGwei(competitiveFee);
122
+ return {
123
+ priorityFee: competitiveFee,
124
+ latestBlock,
125
+ blobBaseFee,
126
+ debugInfo
127
+ };
128
+ }
129
+ };
@@ -0,0 +1,23 @@
1
+ import { type GetFeeHistoryReturnType } from 'viem';
2
+ import type { ViemClient } from '../../types.js';
3
+ import { type PriorityFeeStrategy } from './types.js';
4
+ /**
5
+ * Fetches historical blocks and calculates reward percentiles for blob transactions only.
6
+ * Returns data in the same format as getFeeHistory for easy drop-in replacement.
7
+ *
8
+ * @param client - Viem client to use for RPC calls
9
+ * @param blockCount - Number of historical blocks to fetch
10
+ * @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
11
+ * @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
12
+ * @throws Error if fetching blocks fails
13
+ */
14
+ export declare function getBlobPriorityFeeHistory(client: ViemClient, blockCount: number, rewardPercentiles: number[]): Promise<GetFeeHistoryReturnType>;
15
+ /**
16
+ * Similar to our current competitive priority fee strategy, but only considers blob transactions
17
+ * when calculating competitive priority fee for blob transactions.
18
+ * This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
19
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
20
+ * Falls back to network estimate if data is unavailable.
21
+ */
22
+ export declare const P75BlobTxsOnlyPriorityFeeStrategy: PriorityFeeStrategy;
23
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicDc1X2NvbXBldGl0aXZlX2Jsb2JfdHhzX29ubHkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9sMV90eF91dGlscy9mZWUtc3RyYXRlZ2llcy9wNzVfY29tcGV0aXRpdmVfYmxvYl90eHNfb25seS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsS0FBSyx1QkFBdUIsRUFBYyxNQUFNLE1BQU0sQ0FBQztBQUVoRSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSxnQkFBZ0IsQ0FBQztBQUdqRCxPQUFPLEVBRUwsS0FBSyxtQkFBbUIsRUFHekIsTUFBTSxZQUFZLENBQUM7QUFFcEI7Ozs7Ozs7OztHQVNHO0FBQ0gsd0JBQXNCLHlCQUF5QixDQUM3QyxNQUFNLEVBQUUsVUFBVSxFQUNsQixVQUFVLEVBQUUsTUFBTSxFQUNsQixpQkFBaUIsRUFBRSxNQUFNLEVBQUUsR0FDMUIsT0FBTyxDQUFDLHVCQUF1QixDQUFDLENBc0VsQztBQUVEOzs7Ozs7R0FNRztBQUNILGVBQU8sTUFBTSxpQ0FBaUMsRUFBRSxtQkF5SS9DLENBQUMifQ==
@@ -0,0 +1 @@
1
+ {"version":3,"file":"p75_competitive_blob_txs_only.d.ts","sourceRoot":"","sources":["../../../src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,uBAAuB,EAAc,MAAM,MAAM,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAEL,KAAK,mBAAmB,EAGzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,UAAU,EAClB,UAAU,EAAE,MAAM,EAClB,iBAAiB,EAAE,MAAM,EAAE,GAC1B,OAAO,CAAC,uBAAuB,CAAC,CAsElC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,mBAyI/C,CAAC"}
@@ -0,0 +1,191 @@
1
+ import { median } from '@aztec/foundation/collection';
2
+ import { formatGwei } from 'viem';
3
+ import { calculatePercentile, isBlobTransaction } from '../../utils.js';
4
+ import { WEI_CONST } from '../constants.js';
5
+ import { HISTORICAL_BLOCK_COUNT } from './types.js';
6
+ /**
7
+ * Fetches historical blocks and calculates reward percentiles for blob transactions only.
8
+ * Returns data in the same format as getFeeHistory for easy drop-in replacement.
9
+ *
10
+ * @param client - Viem client to use for RPC calls
11
+ * @param blockCount - Number of historical blocks to fetch
12
+ * @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
13
+ * @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
14
+ * @throws Error if fetching blocks fails
15
+ */ export async function getBlobPriorityFeeHistory(client, blockCount, rewardPercentiles) {
16
+ const latestBlockNumber = await client.getBlockNumber();
17
+ // Fetch multiple blocks in parallel
18
+ const blockPromises = Array.from({
19
+ length: blockCount
20
+ }, (_, i)=>client.getBlock({
21
+ blockNumber: latestBlockNumber - BigInt(i),
22
+ includeTransactions: true
23
+ }));
24
+ const blocks = await Promise.all(blockPromises);
25
+ // Process each block to extract blob transaction fees and other data
26
+ const baseFeePerGas = [];
27
+ const gasUsedRatio = [];
28
+ const reward = [];
29
+ for (const block of blocks){
30
+ // Collect base fee per gas
31
+ baseFeePerGas.push(block.baseFeePerGas || 0n);
32
+ // Calculate gas used ratio
33
+ const gasUsed = block.gasUsed || 0n;
34
+ const gasLimit = block.gasLimit || 1n; // Avoid division by zero
35
+ gasUsedRatio.push(Number(gasUsed) / Number(gasLimit));
36
+ if (!block.transactions || block.transactions.length === 0) {
37
+ // No transactions in this block - return zeros for each percentile
38
+ reward.push(rewardPercentiles.map(()=>0n));
39
+ continue;
40
+ }
41
+ // Extract priority fees from blob transactions only
42
+ const blobFees = block.transactions.map((tx)=>{
43
+ // Transaction can be just a hash string
44
+ if (typeof tx === 'string') {
45
+ return 0n;
46
+ }
47
+ if (!isBlobTransaction(tx)) {
48
+ return 0n;
49
+ }
50
+ return tx.maxPriorityFeePerGas || 0n;
51
+ }).filter((fee)=>fee > 0n);
52
+ if (blobFees.length === 0) {
53
+ // No blob transactions in this block - return zeros for each percentile
54
+ reward.push(rewardPercentiles.map(()=>0n));
55
+ continue;
56
+ }
57
+ // Calculate requested percentiles
58
+ const percentiles = rewardPercentiles.map((percentile)=>calculatePercentile(blobFees, percentile));
59
+ reward.push(percentiles);
60
+ }
61
+ // Calculate oldest block number (the last block in our array)
62
+ const oldestBlock = latestBlockNumber - BigInt(blockCount - 1);
63
+ // Reverse arrays to match getFeeHistory behavior (oldest first)
64
+ return {
65
+ baseFeePerGas: baseFeePerGas.reverse(),
66
+ gasUsedRatio: gasUsedRatio.reverse(),
67
+ oldestBlock,
68
+ reward: reward.reverse()
69
+ };
70
+ }
71
+ /**
72
+ * Similar to our current competitive priority fee strategy, but only considers blob transactions
73
+ * when calculating competitive priority fee for blob transactions.
74
+ * This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
75
+ * Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
76
+ * Falls back to network estimate if data is unavailable.
77
+ */ export const P75BlobTxsOnlyPriorityFeeStrategy = {
78
+ name: 'Competitive (P75 + History) - Blob Txs Only',
79
+ id: 'p75_pending_txs_and_history_blob_txs_only',
80
+ async execute (client, context) {
81
+ const { isBlobTx, logger } = context;
82
+ // Fire all RPC calls in parallel
83
+ const [latestBlockResult, blobBaseFeeResult, networkEstimateResult, pendingBlockResult, feeHistoryResult] = await Promise.allSettled([
84
+ client.getBlock({
85
+ blockTag: 'latest'
86
+ }),
87
+ isBlobTx ? client.getBlobBaseFee() : Promise.resolve(undefined),
88
+ client.estimateMaxPriorityFeePerGas().catch(()=>0n),
89
+ client.getBlock({
90
+ blockTag: 'pending',
91
+ includeTransactions: true
92
+ }).catch(()=>null),
93
+ isBlobTx ? getBlobPriorityFeeHistory(client, HISTORICAL_BLOCK_COUNT, [
94
+ 75
95
+ ]) : client.getFeeHistory({
96
+ blockCount: HISTORICAL_BLOCK_COUNT,
97
+ rewardPercentiles: [
98
+ 75
99
+ ],
100
+ blockTag: 'latest'
101
+ }).catch(()=>null)
102
+ ]);
103
+ // Extract latest block (required)
104
+ if (latestBlockResult.status === 'rejected') {
105
+ throw new Error(`Failed to get latest block: ${latestBlockResult.reason}`);
106
+ }
107
+ const latestBlock = latestBlockResult.value;
108
+ // Extract blob base fee (only for blob txs)
109
+ let blobBaseFee;
110
+ if (isBlobTx) {
111
+ if (blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
112
+ blobBaseFee = blobBaseFeeResult.value;
113
+ } else {
114
+ logger?.warn('Failed to get L1 blob base fee');
115
+ }
116
+ }
117
+ // Extract network estimate
118
+ const networkEstimate = networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint' ? networkEstimateResult.value : 0n;
119
+ let competitiveFee = networkEstimate;
120
+ const debugInfo = {
121
+ networkEstimateGwei: formatGwei(networkEstimate)
122
+ };
123
+ // Extract pending block
124
+ const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
125
+ // Analyze pending block transactions
126
+ if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
127
+ const pendingFees = pendingBlock.transactions.map((tx)=>{
128
+ if (typeof tx === 'string') {
129
+ return 0n;
130
+ }
131
+ if (isBlobTx) {
132
+ if (!isBlobTransaction(tx)) {
133
+ return 0n;
134
+ }
135
+ }
136
+ return tx.maxPriorityFeePerGas || 0n;
137
+ }).filter((fee)=>fee > 0n);
138
+ if (pendingFees.length > 0) {
139
+ const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
140
+ if (pendingCompetitiveFee > competitiveFee) {
141
+ competitiveFee = pendingCompetitiveFee;
142
+ }
143
+ debugInfo.pendingTxCount = pendingFees.length;
144
+ debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
145
+ logger?.debug('Analyzed pending transactions for competitive pricing', {
146
+ pendingTxCount: pendingFees.length,
147
+ pendingP75: formatGwei(pendingCompetitiveFee)
148
+ });
149
+ }
150
+ }
151
+ // Extract fee history
152
+ const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
153
+ // Analyze fee history
154
+ if (feeHistory?.reward && feeHistory.reward.length > 0) {
155
+ // Extract 75th percentile fees from each block
156
+ const percentile75Fees = feeHistory.reward.map((rewards)=>rewards[0] || 0n).filter((fee)=>fee > 0n);
157
+ if (percentile75Fees.length > 0) {
158
+ // Calculate median of the 75th percentile fees across blocks
159
+ const medianHistoricalFee = median(percentile75Fees) ?? 0n;
160
+ // Debug: Log suspicious fees from history
161
+ if (medianHistoricalFee > 100n * WEI_CONST) {
162
+ logger?.debug('Suspicious high fee in history', {
163
+ historicalMedian: formatGwei(medianHistoricalFee),
164
+ allP75Fees: percentile75Fees.map((f)=>formatGwei(f))
165
+ });
166
+ }
167
+ if (medianHistoricalFee > competitiveFee) {
168
+ competitiveFee = medianHistoricalFee;
169
+ }
170
+ debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
171
+ logger?.debug('Analyzed fee history for competitive pricing', {
172
+ historicalMedian: formatGwei(medianHistoricalFee)
173
+ });
174
+ }
175
+ }
176
+ // Log final decision
177
+ if (competitiveFee > networkEstimate) {
178
+ logger?.debug('Using competitive fee from market analysis', {
179
+ networkEstimate: formatGwei(networkEstimate),
180
+ competitive: formatGwei(competitiveFee)
181
+ });
182
+ }
183
+ debugInfo.finalFeeGwei = formatGwei(competitiveFee);
184
+ return {
185
+ priorityFee: competitiveFee,
186
+ latestBlock,
187
+ blobBaseFee,
188
+ debugInfo
189
+ };
190
+ }
191
+ };