@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.
- package/dest/account.d.ts +1 -1
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +10 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +13 -3
- package/dest/config.d.ts +24 -68
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +67 -380
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +9 -5
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +8 -4
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +39 -17
- package/dest/contracts/errors.d.ts +1 -1
- package/dest/contracts/errors.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/fee_juice.d.ts +1 -1
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/governance.d.ts +18 -16
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +14 -4
- package/dest/contracts/governance_proposer.d.ts +8 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +412 -11
- package/dest/contracts/gse.d.ts +1 -1
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/inbox.d.ts +24 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +36 -1
- package/dest/contracts/index.d.ts +4 -1
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +3 -0
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +2 -2
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +2 -1
- package/dest/contracts/outbox.d.ts +41 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +86 -0
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +208 -123
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +807 -188
- package/dest/contracts/slasher_contract.d.ts +1 -1
- package/dest/contracts/slasher_contract.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.d.ts +9 -7
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +11 -4
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +259 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +413 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +1 -1
- package/dest/eth-signer/index.d.ts +1 -1
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +7608 -2048
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +3 -3
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +3 -3
- package/dest/l1_reader.d.ts +5 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +12 -1
- package/dest/l1_tx_utils/config.d.ts +11 -5
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +43 -7
- package/dest/l1_tx_utils/constants.d.ts +8 -2
- package/dest/l1_tx_utils/constants.d.ts.map +1 -1
- package/dest/l1_tx_utils/constants.js +27 -2
- package/dest/l1_tx_utils/factory.d.ts +18 -10
- package/dest/l1_tx_utils/factory.d.ts.map +1 -1
- package/dest/l1_tx_utils/factory.js +17 -7
- package/dest/l1_tx_utils/fee-strategies/index.d.ts +10 -0
- package/dest/l1_tx_utils/fee-strategies/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/index.js +12 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts +8 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive.js +129 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts +23 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.js +191 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts +51 -0
- package/dest/l1_tx_utils/fee-strategies/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/fee-strategies/types.js +3 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts +41 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/forwarder_l1_tx_utils.js +42 -0
- package/dest/l1_tx_utils/index-blobs.d.ts +3 -0
- package/dest/l1_tx_utils/index-blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/index-blobs.js +2 -0
- package/dest/l1_tx_utils/index.d.ts +4 -1
- package/dest/l1_tx_utils/index.d.ts.map +1 -1
- package/dest/l1_tx_utils/index.js +3 -0
- package/dest/l1_tx_utils/interfaces.d.ts +2 -2
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts +233 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +506 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +18 -8
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +75 -46
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +19 -30
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +63 -167
- package/dest/l1_tx_utils/signer.d.ts +1 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +65 -36
- package/dest/l1_tx_utils/types.d.ts +1 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/utils.d.ts +1 -1
- package/dest/l1_types.d.ts +1 -1
- package/dest/publisher_manager.d.ts +3 -2
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +2 -2
- package/dest/queries.d.ts +2 -2
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +16 -6
- package/dest/test/chain_monitor.d.ts +47 -25
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +66 -38
- package/dest/test/eth_cheat_codes.d.ts +11 -3
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +11 -3
- package/dest/test/eth_cheat_codes_with_state.d.ts +1 -1
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- package/dest/test/index.d.ts +1 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -2
- package/dest/test/rollup_cheat_codes.d.ts +17 -13
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +62 -38
- package/dest/test/start_anvil.d.ts +18 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +129 -28
- package/dest/test/upgrade_utils.d.ts +1 -1
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +16 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +80 -12
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +34 -16
- package/src/client.ts +10 -2
- package/src/config.ts +86 -460
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +8 -5
- package/src/contracts/empire_slashing_proposer.ts +38 -32
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/governance.ts +13 -4
- package/src/contracts/governance_proposer.ts +26 -6
- package/src/contracts/inbox.ts +55 -3
- package/src/contracts/index.ts +3 -0
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +5 -2
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +485 -162
- package/src/contracts/tally_slashing_proposer.ts +15 -8
- package/src/deploy_aztec_l1_contracts.ts +650 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_contract_addresses.ts +22 -20
- package/src/l1_reader.ts +21 -1
- package/src/l1_tx_utils/config.ts +52 -11
- package/src/l1_tx_utils/constants.ts +13 -2
- package/src/l1_tx_utils/factory.ts +31 -31
- package/src/l1_tx_utils/fee-strategies/index.ts +22 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive.ts +163 -0
- package/src/l1_tx_utils/fee-strategies/p75_competitive_blob_txs_only.ts +245 -0
- package/src/l1_tx_utils/fee-strategies/types.ts +56 -0
- package/src/l1_tx_utils/forwarder_l1_tx_utils.ts +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +3 -0
- package/src/l1_tx_utils/interfaces.ts +1 -1
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +84 -36
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +77 -213
- package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +17 -6
- package/src/test/chain_monitor.ts +110 -51
- package/src/test/eth_cheat_codes.ts +9 -3
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +63 -43
- package/src/test/start_anvil.ts +156 -27
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +100 -15
- package/dest/deploy_l1_contracts.d.ts +0 -226
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1473
- package/dest/index.d.ts +0 -18
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -17
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +0 -26
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +0 -26
- package/dest/test/delayed_tx_utils.d.ts +0 -13
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -28
- package/dest/test/tx_delayer.d.ts +0 -36
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/src/deploy_l1_contracts.ts +0 -1849
- package/src/index.ts +0 -17
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +0 -77
- package/src/test/delayed_tx_utils.ts +0 -52
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ConfigMappingsType,
|
|
3
|
-
bigintConfigHelper,
|
|
4
3
|
booleanConfigHelper,
|
|
4
|
+
floatConfigHelper,
|
|
5
5
|
getConfigFromMappings,
|
|
6
6
|
getDefaultConfig,
|
|
7
7
|
numberConfigHelper,
|
|
8
|
+
optionalNumberConfigHelper,
|
|
8
9
|
} from '@aztec/foundation/config';
|
|
9
10
|
|
|
10
11
|
export interface L1TxUtilsConfig {
|
|
@@ -15,11 +16,11 @@ export interface L1TxUtilsConfig {
|
|
|
15
16
|
/**
|
|
16
17
|
* Maximum gas price in gwei
|
|
17
18
|
*/
|
|
18
|
-
maxGwei?:
|
|
19
|
+
maxGwei?: number;
|
|
19
20
|
/**
|
|
20
21
|
* Maximum blob fee per gas in gwei
|
|
21
22
|
*/
|
|
22
|
-
maxBlobGwei?:
|
|
23
|
+
maxBlobGwei?: number;
|
|
23
24
|
/**
|
|
24
25
|
* Priority fee bump percentage
|
|
25
26
|
*/
|
|
@@ -29,9 +30,9 @@ export interface L1TxUtilsConfig {
|
|
|
29
30
|
*/
|
|
30
31
|
priorityFeeRetryBumpPercentage?: number;
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
+
* Minimum priority fee per gas in Gwei. Acts as a floor for the computed priority fee.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
|
+
minimumPriorityFeePerGas?: number;
|
|
35
36
|
/**
|
|
36
37
|
* Maximum number of speed-up attempts
|
|
37
38
|
*/
|
|
@@ -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> = {
|
|
@@ -71,12 +78,14 @@ export const l1TxUtilsConfigMappings: ConfigMappingsType<L1TxUtilsConfig> = {
|
|
|
71
78
|
maxGwei: {
|
|
72
79
|
description: 'Maximum gas price in gwei to be used for transactions.',
|
|
73
80
|
env: 'L1_GAS_PRICE_MAX',
|
|
74
|
-
|
|
81
|
+
fallback: ['L1_FEE_PER_GAS_GWEI_MAX'],
|
|
82
|
+
...floatConfigHelper(2000),
|
|
75
83
|
},
|
|
76
84
|
maxBlobGwei: {
|
|
77
85
|
description: 'Maximum blob fee per gas in gwei',
|
|
78
86
|
env: 'L1_BLOB_FEE_PER_GAS_MAX',
|
|
79
|
-
|
|
87
|
+
fallback: ['L1_BLOB_FEE_PER_GAS_GWEI_MAX'],
|
|
88
|
+
...floatConfigHelper(3000),
|
|
80
89
|
},
|
|
81
90
|
priorityFeeBumpPercentage: {
|
|
82
91
|
description: 'How much to increase priority fee by each attempt (percentage)',
|
|
@@ -88,10 +97,22 @@ export const l1TxUtilsConfigMappings: ConfigMappingsType<L1TxUtilsConfig> = {
|
|
|
88
97
|
env: 'L1_PRIORITY_FEE_RETRY_BUMP_PERCENTAGE',
|
|
89
98
|
...numberConfigHelper(50),
|
|
90
99
|
},
|
|
91
|
-
|
|
92
|
-
description:
|
|
93
|
-
|
|
94
|
-
|
|
100
|
+
minimumPriorityFeePerGas: {
|
|
101
|
+
description:
|
|
102
|
+
'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.',
|
|
103
|
+
env: 'L1_MINIMUM_PRIORITY_FEE_PER_GAS_GWEI',
|
|
104
|
+
fallback: ['L1_FIXED_PRIORITY_FEE_PER_GAS', 'L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI'],
|
|
105
|
+
deprecatedFallback: [
|
|
106
|
+
{
|
|
107
|
+
env: 'L1_FIXED_PRIORITY_FEE_PER_GAS',
|
|
108
|
+
message: deprecatedFixedFeeMessage('L1_FIXED_PRIORITY_FEE_PER_GAS'),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
env: 'L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI',
|
|
112
|
+
message: deprecatedFixedFeeMessage('L1_FIXED_PRIORITY_FEE_PER_GAS_GWEI'),
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
...floatConfigHelper(0),
|
|
95
116
|
},
|
|
96
117
|
maxSpeedUpAttempts: {
|
|
97
118
|
description: 'Maximum number of speed-up attempts',
|
|
@@ -128,6 +149,19 @@ export const l1TxUtilsConfigMappings: ConfigMappingsType<L1TxUtilsConfig> = {
|
|
|
128
149
|
env: 'L1_TX_MONITOR_TX_UNSEEN_CONSIDERED_DROPPED_MS',
|
|
129
150
|
...numberConfigHelper(6 * 12 * 1000), // 6 L1 blocks
|
|
130
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
|
+
},
|
|
131
165
|
};
|
|
132
166
|
|
|
133
167
|
// We abuse the fact that all mappings above have a non null default value and force-type this to Required
|
|
@@ -138,3 +172,10 @@ export const defaultL1TxUtilsConfig = getDefaultConfig<L1TxUtilsConfig>(
|
|
|
138
172
|
export function getL1TxUtilsConfigEnvVars(): L1TxUtilsConfig {
|
|
139
173
|
return getConfigFromMappings(l1TxUtilsConfigMappings);
|
|
140
174
|
}
|
|
175
|
+
|
|
176
|
+
function deprecatedFixedFeeMessage(envVar: string): string {
|
|
177
|
+
return (
|
|
178
|
+
`Environment variable ${envVar} is deprecated. It is now used as a MINIMUM priority fee rather than a fixed value. ` +
|
|
179
|
+
'Please use L1_MINIMUM_PRIORITY_FEE_PER_GAS_GWEI instead. If network conditions require a higher fee, the higher fee will be used.'
|
|
180
|
+
);
|
|
181
|
+
}
|
|
@@ -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
|
-
//
|
|
7
|
-
export const
|
|
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
|
|
@@ -16,3 +16,14 @@ export const MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE = 100;
|
|
|
16
16
|
|
|
17
17
|
// Avg ethereum block time is ~12s
|
|
18
18
|
export const BLOCK_TIME_MS = 12_000;
|
|
19
|
+
|
|
20
|
+
// Gas per blob (EIP-4844)
|
|
21
|
+
export const GAS_PER_BLOB = 131072n;
|
|
22
|
+
|
|
23
|
+
// Blob capacity schedule based on Ethereum upgrades
|
|
24
|
+
export const BLOB_CAPACITY_SCHEDULE = [
|
|
25
|
+
{ timestamp: 1734357600, target: 14, max: 21 }, // BPO2: Dec 17, 2025
|
|
26
|
+
{ timestamp: 1733752800, target: 10, max: 15 }, // BPO1: Dec 9, 2025
|
|
27
|
+
{ timestamp: 1733234400, target: 6, max: 9 }, // Fusaka: Dec 3, 2025
|
|
28
|
+
{ timestamp: 0, target: 6, max: 9 }, // Pectra/earlier
|
|
29
|
+
];
|
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
39
|
-
|
|
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
|
|
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
|
-
|
|
56
|
-
|
|
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
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
|
|
2
|
+
import { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
|
|
3
|
+
import type { PriorityFeeStrategy } from './types.js';
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
HISTORICAL_BLOCK_COUNT,
|
|
7
|
+
type PriorityFeeStrategy,
|
|
8
|
+
type PriorityFeeStrategyContext,
|
|
9
|
+
type PriorityFeeStrategyResult,
|
|
10
|
+
} from './types.js';
|
|
11
|
+
|
|
12
|
+
export { P75AllTxsPriorityFeeStrategy } from './p75_competitive.js';
|
|
13
|
+
export { P75BlobTxsOnlyPriorityFeeStrategy } from './p75_competitive_blob_txs_only.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Default list of priority fee strategies to analyze.
|
|
17
|
+
* Add more strategies here for comparison.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_PRIORITY_FEE_STRATEGIES: PriorityFeeStrategy[] = [
|
|
20
|
+
P75AllTxsPriorityFeeStrategy,
|
|
21
|
+
P75BlobTxsOnlyPriorityFeeStrategy,
|
|
22
|
+
];
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { median } from '@aztec/foundation/collection';
|
|
2
|
+
|
|
3
|
+
import { formatGwei } from 'viem';
|
|
4
|
+
|
|
5
|
+
import type { ViemClient } from '../../types.js';
|
|
6
|
+
import { calculatePercentile } from '../../utils.js';
|
|
7
|
+
import { WEI_CONST } from '../constants.js';
|
|
8
|
+
import {
|
|
9
|
+
HISTORICAL_BLOCK_COUNT,
|
|
10
|
+
type PriorityFeeStrategy,
|
|
11
|
+
type PriorityFeeStrategyContext,
|
|
12
|
+
type PriorityFeeStrategyResult,
|
|
13
|
+
} from './types.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Our current competitive priority fee strategy.
|
|
17
|
+
* Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
|
|
18
|
+
* Falls back to network estimate if data is unavailable.
|
|
19
|
+
*/
|
|
20
|
+
export const P75AllTxsPriorityFeeStrategy: PriorityFeeStrategy = {
|
|
21
|
+
name: 'Competitive (P75 + History) - CURRENT',
|
|
22
|
+
id: 'p75_pending_txs_and_history_all_txs',
|
|
23
|
+
|
|
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
|
+
}
|
|
58
|
+
|
|
59
|
+
// Extract network estimate
|
|
60
|
+
const networkEstimate =
|
|
61
|
+
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
62
|
+
? networkEstimateResult.value
|
|
63
|
+
: 0n;
|
|
64
|
+
|
|
65
|
+
let competitiveFee = networkEstimate;
|
|
66
|
+
const debugInfo: Record<string, string | number> = {
|
|
67
|
+
networkEstimateGwei: formatGwei(networkEstimate),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Extract pending block
|
|
71
|
+
const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
|
|
72
|
+
|
|
73
|
+
// Analyze pending block transactions
|
|
74
|
+
if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
|
|
75
|
+
const pendingFees = pendingBlock.transactions
|
|
76
|
+
.map(tx => {
|
|
77
|
+
if (typeof tx === 'string') {
|
|
78
|
+
return 0n;
|
|
79
|
+
}
|
|
80
|
+
return tx.maxPriorityFeePerGas || 0n;
|
|
81
|
+
})
|
|
82
|
+
.filter((fee: bigint) => fee > 0n);
|
|
83
|
+
|
|
84
|
+
if (pendingFees.length > 0) {
|
|
85
|
+
// Use 75th percentile of pending fees to be competitive
|
|
86
|
+
const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
|
|
87
|
+
|
|
88
|
+
if (pendingCompetitiveFee > competitiveFee) {
|
|
89
|
+
competitiveFee = pendingCompetitiveFee;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
debugInfo.pendingTxCount = pendingFees.length;
|
|
93
|
+
debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
|
|
94
|
+
|
|
95
|
+
logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
96
|
+
pendingTxCount: pendingFees.length,
|
|
97
|
+
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Extract fee history
|
|
103
|
+
const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
|
|
104
|
+
|
|
105
|
+
// Analyze fee history
|
|
106
|
+
if (feeHistory?.reward && feeHistory.reward.length > 0) {
|
|
107
|
+
// Extract 75th percentile fees from each block
|
|
108
|
+
const percentile75Fees = feeHistory.reward.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
109
|
+
|
|
110
|
+
if (percentile75Fees.length > 0) {
|
|
111
|
+
// Calculate median of the 75th percentile fees across blocks
|
|
112
|
+
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
113
|
+
|
|
114
|
+
// Debug: Log suspicious fees from history
|
|
115
|
+
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
116
|
+
logger?.warn('Suspicious high fee in history', {
|
|
117
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
118
|
+
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (medianHistoricalFee > competitiveFee) {
|
|
123
|
+
competitiveFee = medianHistoricalFee;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
|
|
127
|
+
|
|
128
|
+
logger?.debug('Analyzed fee history for competitive pricing', {
|
|
129
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
|
|
135
|
+
const maxReasonableFee = networkEstimate * 100n;
|
|
136
|
+
if (competitiveFee > maxReasonableFee && networkEstimate > 0n) {
|
|
137
|
+
logger?.debug('Competitive fee exceeds sanity cap, using capped value', {
|
|
138
|
+
competitiveFee: formatGwei(competitiveFee),
|
|
139
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
140
|
+
cappedTo: formatGwei(maxReasonableFee),
|
|
141
|
+
});
|
|
142
|
+
competitiveFee = maxReasonableFee;
|
|
143
|
+
debugInfo.cappedToGwei = formatGwei(maxReasonableFee);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Log final decision
|
|
147
|
+
if (competitiveFee > networkEstimate) {
|
|
148
|
+
logger?.debug('Using competitive fee from market analysis', {
|
|
149
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
150
|
+
competitive: formatGwei(competitiveFee),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
debugInfo.finalFeeGwei = formatGwei(competitiveFee);
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
priorityFee: competitiveFee,
|
|
158
|
+
latestBlock,
|
|
159
|
+
blobBaseFee,
|
|
160
|
+
debugInfo,
|
|
161
|
+
};
|
|
162
|
+
},
|
|
163
|
+
};
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { median } from '@aztec/foundation/collection';
|
|
2
|
+
|
|
3
|
+
import { type GetFeeHistoryReturnType, formatGwei } from 'viem';
|
|
4
|
+
|
|
5
|
+
import type { ViemClient } from '../../types.js';
|
|
6
|
+
import { calculatePercentile, isBlobTransaction } from '../../utils.js';
|
|
7
|
+
import { WEI_CONST } from '../constants.js';
|
|
8
|
+
import {
|
|
9
|
+
HISTORICAL_BLOCK_COUNT,
|
|
10
|
+
type PriorityFeeStrategy,
|
|
11
|
+
type PriorityFeeStrategyContext,
|
|
12
|
+
type PriorityFeeStrategyResult,
|
|
13
|
+
} from './types.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetches historical blocks and calculates reward percentiles for blob transactions only.
|
|
17
|
+
* Returns data in the same format as getFeeHistory for easy drop-in replacement.
|
|
18
|
+
*
|
|
19
|
+
* @param client - Viem client to use for RPC calls
|
|
20
|
+
* @param blockCount - Number of historical blocks to fetch
|
|
21
|
+
* @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
|
|
22
|
+
* @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
|
|
23
|
+
* @throws Error if fetching blocks fails
|
|
24
|
+
*/
|
|
25
|
+
export async function getBlobPriorityFeeHistory(
|
|
26
|
+
client: ViemClient,
|
|
27
|
+
blockCount: number,
|
|
28
|
+
rewardPercentiles: number[],
|
|
29
|
+
): Promise<GetFeeHistoryReturnType> {
|
|
30
|
+
const latestBlockNumber = await client.getBlockNumber();
|
|
31
|
+
|
|
32
|
+
// Fetch multiple blocks in parallel
|
|
33
|
+
const blockPromises = Array.from({ length: blockCount }, (_, i) =>
|
|
34
|
+
client.getBlock({
|
|
35
|
+
blockNumber: latestBlockNumber - BigInt(i),
|
|
36
|
+
includeTransactions: true,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const blocks = await Promise.all(blockPromises);
|
|
41
|
+
|
|
42
|
+
// Process each block to extract blob transaction fees and other data
|
|
43
|
+
const baseFeePerGas: bigint[] = [];
|
|
44
|
+
const gasUsedRatio: number[] = [];
|
|
45
|
+
const reward: bigint[][] = [];
|
|
46
|
+
|
|
47
|
+
for (const block of blocks) {
|
|
48
|
+
// Collect base fee per gas
|
|
49
|
+
baseFeePerGas.push(block.baseFeePerGas || 0n);
|
|
50
|
+
|
|
51
|
+
// Calculate gas used ratio
|
|
52
|
+
const gasUsed = block.gasUsed || 0n;
|
|
53
|
+
const gasLimit = block.gasLimit || 1n; // Avoid division by zero
|
|
54
|
+
gasUsedRatio.push(Number(gasUsed) / Number(gasLimit));
|
|
55
|
+
|
|
56
|
+
if (!block.transactions || block.transactions.length === 0) {
|
|
57
|
+
// No transactions in this block - return zeros for each percentile
|
|
58
|
+
reward.push(rewardPercentiles.map(() => 0n));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Extract priority fees from blob transactions only
|
|
63
|
+
const blobFees = block.transactions
|
|
64
|
+
.map(tx => {
|
|
65
|
+
// Transaction can be just a hash string
|
|
66
|
+
if (typeof tx === 'string') {
|
|
67
|
+
return 0n;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!isBlobTransaction(tx)) {
|
|
71
|
+
return 0n;
|
|
72
|
+
}
|
|
73
|
+
return tx.maxPriorityFeePerGas || 0n;
|
|
74
|
+
})
|
|
75
|
+
.filter((fee: bigint) => fee > 0n);
|
|
76
|
+
|
|
77
|
+
if (blobFees.length === 0) {
|
|
78
|
+
// No blob transactions in this block - return zeros for each percentile
|
|
79
|
+
reward.push(rewardPercentiles.map(() => 0n));
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Calculate requested percentiles
|
|
84
|
+
const percentiles = rewardPercentiles.map(percentile => calculatePercentile(blobFees, percentile));
|
|
85
|
+
|
|
86
|
+
reward.push(percentiles);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Calculate oldest block number (the last block in our array)
|
|
90
|
+
const oldestBlock = latestBlockNumber - BigInt(blockCount - 1);
|
|
91
|
+
|
|
92
|
+
// Reverse arrays to match getFeeHistory behavior (oldest first)
|
|
93
|
+
return {
|
|
94
|
+
baseFeePerGas: baseFeePerGas.reverse(),
|
|
95
|
+
gasUsedRatio: gasUsedRatio.reverse(),
|
|
96
|
+
oldestBlock,
|
|
97
|
+
reward: reward.reverse(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Similar to our current competitive priority fee strategy, but only considers blob transactions
|
|
103
|
+
* when calculating competitive priority fee for blob transactions.
|
|
104
|
+
* This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
|
|
105
|
+
* Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
|
|
106
|
+
* Falls back to network estimate if data is unavailable.
|
|
107
|
+
*/
|
|
108
|
+
export const P75BlobTxsOnlyPriorityFeeStrategy: PriorityFeeStrategy = {
|
|
109
|
+
name: 'Competitive (P75 + History) - Blob Txs Only',
|
|
110
|
+
id: 'p75_pending_txs_and_history_blob_txs_only',
|
|
111
|
+
|
|
112
|
+
async execute(client: ViemClient, context: PriorityFeeStrategyContext): Promise<PriorityFeeStrategyResult> {
|
|
113
|
+
const { isBlobTx, logger } = context;
|
|
114
|
+
|
|
115
|
+
// Fire all RPC calls in parallel
|
|
116
|
+
const [latestBlockResult, blobBaseFeeResult, networkEstimateResult, pendingBlockResult, feeHistoryResult] =
|
|
117
|
+
await Promise.allSettled([
|
|
118
|
+
client.getBlock({ blockTag: 'latest' }),
|
|
119
|
+
isBlobTx ? client.getBlobBaseFee() : Promise.resolve(undefined),
|
|
120
|
+
client.estimateMaxPriorityFeePerGas().catch(() => 0n),
|
|
121
|
+
client.getBlock({ blockTag: 'pending', includeTransactions: true }).catch(() => null),
|
|
122
|
+
isBlobTx
|
|
123
|
+
? getBlobPriorityFeeHistory(client, HISTORICAL_BLOCK_COUNT, [75])
|
|
124
|
+
: client
|
|
125
|
+
.getFeeHistory({
|
|
126
|
+
blockCount: HISTORICAL_BLOCK_COUNT,
|
|
127
|
+
rewardPercentiles: [75],
|
|
128
|
+
blockTag: 'latest',
|
|
129
|
+
})
|
|
130
|
+
.catch(() => null),
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
// Extract latest block (required)
|
|
134
|
+
if (latestBlockResult.status === 'rejected') {
|
|
135
|
+
throw new Error(`Failed to get latest block: ${latestBlockResult.reason}`);
|
|
136
|
+
}
|
|
137
|
+
const latestBlock = latestBlockResult.value;
|
|
138
|
+
|
|
139
|
+
// Extract blob base fee (only for blob txs)
|
|
140
|
+
let blobBaseFee: bigint | undefined;
|
|
141
|
+
if (isBlobTx) {
|
|
142
|
+
if (blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
143
|
+
blobBaseFee = blobBaseFeeResult.value;
|
|
144
|
+
} else {
|
|
145
|
+
logger?.warn('Failed to get L1 blob base fee');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Extract network estimate
|
|
150
|
+
const networkEstimate =
|
|
151
|
+
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
152
|
+
? networkEstimateResult.value
|
|
153
|
+
: 0n;
|
|
154
|
+
|
|
155
|
+
let competitiveFee = networkEstimate;
|
|
156
|
+
const debugInfo: Record<string, string | number> = {
|
|
157
|
+
networkEstimateGwei: formatGwei(networkEstimate),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Extract pending block
|
|
161
|
+
const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
|
|
162
|
+
|
|
163
|
+
// Analyze pending block transactions
|
|
164
|
+
if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
|
|
165
|
+
const pendingFees = pendingBlock.transactions
|
|
166
|
+
.map(tx => {
|
|
167
|
+
if (typeof tx === 'string') {
|
|
168
|
+
return 0n;
|
|
169
|
+
}
|
|
170
|
+
if (isBlobTx) {
|
|
171
|
+
if (!isBlobTransaction(tx)) {
|
|
172
|
+
return 0n;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return tx.maxPriorityFeePerGas || 0n;
|
|
176
|
+
})
|
|
177
|
+
.filter((fee: bigint) => fee > 0n);
|
|
178
|
+
|
|
179
|
+
if (pendingFees.length > 0) {
|
|
180
|
+
const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
|
|
181
|
+
|
|
182
|
+
if (pendingCompetitiveFee > competitiveFee) {
|
|
183
|
+
competitiveFee = pendingCompetitiveFee;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
debugInfo.pendingTxCount = pendingFees.length;
|
|
187
|
+
debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
|
|
188
|
+
|
|
189
|
+
logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
190
|
+
pendingTxCount: pendingFees.length,
|
|
191
|
+
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Extract fee history
|
|
197
|
+
const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
|
|
198
|
+
|
|
199
|
+
// Analyze fee history
|
|
200
|
+
if (feeHistory?.reward && feeHistory.reward.length > 0) {
|
|
201
|
+
// Extract 75th percentile fees from each block
|
|
202
|
+
const percentile75Fees = feeHistory.reward.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
203
|
+
|
|
204
|
+
if (percentile75Fees.length > 0) {
|
|
205
|
+
// Calculate median of the 75th percentile fees across blocks
|
|
206
|
+
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
207
|
+
|
|
208
|
+
// Debug: Log suspicious fees from history
|
|
209
|
+
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
210
|
+
logger?.debug('Suspicious high fee in history', {
|
|
211
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
212
|
+
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (medianHistoricalFee > competitiveFee) {
|
|
217
|
+
competitiveFee = medianHistoricalFee;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
|
|
221
|
+
|
|
222
|
+
logger?.debug('Analyzed fee history for competitive pricing', {
|
|
223
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Log final decision
|
|
229
|
+
if (competitiveFee > networkEstimate) {
|
|
230
|
+
logger?.debug('Using competitive fee from market analysis', {
|
|
231
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
232
|
+
competitive: formatGwei(competitiveFee),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
debugInfo.finalFeeGwei = formatGwei(competitiveFee);
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
priorityFee: competitiveFee,
|
|
240
|
+
latestBlock,
|
|
241
|
+
blobBaseFee,
|
|
242
|
+
debugInfo,
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
};
|