@aztec/ethereum 0.0.1-commit.24de95ac → 0.0.1-commit.2606882
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 +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -4
- package/dest/config.d.ts +29 -73
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +70 -387
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/empire_base.d.ts +7 -5
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +1 -1
- 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 +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -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 +113 -36
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- package/dest/contracts/governance_proposer.d.ts +38 -4
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +455 -12
- 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 +42 -2
- package/dest/contracts/index.d.ts +6 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +5 -2
- 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 +127 -12
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +201 -93
- package/dest/contracts/outbox.d.ts +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -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 +5432 -131
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1114 -231
- 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 → slashing_proposer.d.ts} +11 -10
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +21 -16
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +256 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +411 -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 +19816 -16730
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +99 -80
- package/dest/l1_reader.d.ts +7 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +15 -7
- 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 +26 -8
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +118 -70
- 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 +65 -168
- package/dest/l1_tx_utils/signer.d.ts +1 -1
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
- 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 +21 -6
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +81 -7
- package/dest/queries.d.ts +14 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +78 -9
- package/dest/test/chain_monitor.d.ts +48 -25
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +71 -38
- package/dest/test/eth_cheat_codes.d.ts +22 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +28 -7
- 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 +46 -14
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +118 -42
- package/dest/test/start_anvil.d.ts +25 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +143 -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 +24 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +112 -16
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +35 -17
- package/src/client.ts +66 -2
- package/src/config.ts +91 -469
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +6 -5
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +279 -13
- package/src/contracts/governance_proposer.ts +74 -7
- package/src/contracts/inbox.ts +64 -4
- package/src/contracts/index.ts +5 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +243 -102
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +819 -192
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +26 -21
- package/src/deploy_aztec_l1_contracts.ts +646 -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_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -92
- package/src/l1_reader.ts +25 -10
- 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 +123 -52
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +79 -214
- package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
- package/src/publisher_manager.ts +107 -10
- package/src/queries.ts +87 -10
- package/src/test/chain_monitor.ts +115 -51
- package/src/test/eth_cheat_codes.ts +25 -7
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +123 -45
- package/src/test/start_anvil.ts +179 -27
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +128 -19
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -65
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -194
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -1
- 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/contracts/empire_slashing_proposer.ts +0 -259
- 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,7 +1,9 @@
|
|
|
1
|
-
import { getKeys,
|
|
1
|
+
import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
4
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
5
7
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
6
8
|
|
|
7
9
|
import pickBy from 'lodash.pickby';
|
|
@@ -11,6 +13,7 @@ import {
|
|
|
11
13
|
type BaseError,
|
|
12
14
|
type BlockOverrides,
|
|
13
15
|
type ContractFunctionExecutionError,
|
|
16
|
+
type GetCodeReturnType,
|
|
14
17
|
type Hex,
|
|
15
18
|
MethodNotFoundRpcError,
|
|
16
19
|
MethodNotSupportedRpcError,
|
|
@@ -25,15 +28,17 @@ import type { ViemClient } from '../types.js';
|
|
|
25
28
|
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
26
29
|
import {
|
|
27
30
|
BLOCK_TIME_MS,
|
|
28
|
-
|
|
31
|
+
MAX_L1_TX_LIMIT,
|
|
29
32
|
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
30
33
|
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
31
34
|
WEI_CONST,
|
|
32
35
|
} from './constants.js';
|
|
36
|
+
import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
|
|
33
37
|
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
34
38
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
// Change this to the current strategy we want to use
|
|
41
|
+
const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
|
|
37
42
|
|
|
38
43
|
export class ReadOnlyL1TxUtils {
|
|
39
44
|
public config: Required<L1TxUtilsConfig>;
|
|
@@ -65,122 +70,8 @@ export class ReadOnlyL1TxUtils {
|
|
|
65
70
|
return this.client.getBlockNumber();
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* Falls back to network estimate if data is unavailable or fails.
|
|
71
|
-
* @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
|
|
72
|
-
* @param pendingBlockResult - Result from getBlock with pending tag RPC call
|
|
73
|
-
* @param feeHistoryResult - Result from getFeeHistory RPC call
|
|
74
|
-
* @returns A competitive priority fee based on pending txs and recent block history
|
|
75
|
-
*/
|
|
76
|
-
protected getCompetitivePriorityFee(
|
|
77
|
-
networkEstimateResult: PromiseSettledResult<bigint | null>,
|
|
78
|
-
pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>,
|
|
79
|
-
feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>,
|
|
80
|
-
): bigint {
|
|
81
|
-
const networkEstimate =
|
|
82
|
-
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
83
|
-
? networkEstimateResult.value
|
|
84
|
-
: 0n;
|
|
85
|
-
let competitiveFee = networkEstimate;
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
pendingBlockResult.status === 'fulfilled' &&
|
|
89
|
-
pendingBlockResult.value !== null &&
|
|
90
|
-
pendingBlockResult.value.transactions &&
|
|
91
|
-
pendingBlockResult.value.transactions.length > 0
|
|
92
|
-
) {
|
|
93
|
-
const pendingBlock = pendingBlockResult.value;
|
|
94
|
-
// Extract priority fees from pending transactions
|
|
95
|
-
const pendingFees = pendingBlock.transactions
|
|
96
|
-
.map(tx => {
|
|
97
|
-
// Transaction can be just a hash string, so we need to check if it's an object
|
|
98
|
-
if (typeof tx === 'string') {
|
|
99
|
-
return 0n;
|
|
100
|
-
}
|
|
101
|
-
const fee = tx.maxPriorityFeePerGas || 0n;
|
|
102
|
-
// Debug: Log suspicious fees
|
|
103
|
-
if (fee > 100n * WEI_CONST) {
|
|
104
|
-
this.logger?.warn('Suspicious high priority fee in pending tx', {
|
|
105
|
-
txHash: tx.hash,
|
|
106
|
-
maxPriorityFeePerGas: formatGwei(fee),
|
|
107
|
-
maxFeePerGas: formatGwei(tx.maxFeePerGas || 0n),
|
|
108
|
-
maxFeePerBlobGas: tx.maxFeePerBlobGas ? formatGwei(tx.maxFeePerBlobGas) : 'N/A',
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return fee;
|
|
112
|
-
})
|
|
113
|
-
.filter((fee: bigint) => fee > 0n);
|
|
114
|
-
|
|
115
|
-
if (pendingFees.length > 0) {
|
|
116
|
-
// Use 75th percentile of pending fees to be competitive
|
|
117
|
-
const sortedPendingFees = [...pendingFees].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
118
|
-
const percentile75Index = Math.floor((sortedPendingFees.length - 1) * 0.75);
|
|
119
|
-
const pendingCompetitiveFee = sortedPendingFees[percentile75Index];
|
|
120
|
-
|
|
121
|
-
if (pendingCompetitiveFee > competitiveFee) {
|
|
122
|
-
competitiveFee = pendingCompetitiveFee;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
126
|
-
pendingTxCount: pendingFees.length,
|
|
127
|
-
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (
|
|
132
|
-
feeHistoryResult.status === 'fulfilled' &&
|
|
133
|
-
feeHistoryResult.value !== null &&
|
|
134
|
-
feeHistoryResult.value.reward &&
|
|
135
|
-
feeHistoryResult.value.reward.length > 0
|
|
136
|
-
) {
|
|
137
|
-
const feeHistory = feeHistoryResult.value;
|
|
138
|
-
// Extract 75th percentile fees from each block
|
|
139
|
-
const percentile75Fees = feeHistory.reward!.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
140
|
-
|
|
141
|
-
if (percentile75Fees.length > 0) {
|
|
142
|
-
// Calculate median of the 75th percentile fees across blocks
|
|
143
|
-
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
144
|
-
|
|
145
|
-
// Debug: Log suspicious fees from history
|
|
146
|
-
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
147
|
-
this.logger?.warn('Suspicious high fee in history', {
|
|
148
|
-
historicalMedian: formatGwei(medianHistoricalFee),
|
|
149
|
-
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (medianHistoricalFee > competitiveFee) {
|
|
154
|
-
competitiveFee = medianHistoricalFee;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.logger?.debug('Analyzed fee history for competitive pricing', {
|
|
158
|
-
historicalMedian: formatGwei(medianHistoricalFee),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
|
|
164
|
-
// (e.g., Anvil returns inflated historical fees that don't reflect actual network conditions)
|
|
165
|
-
const maxReasonableFee = networkEstimate * 100n;
|
|
166
|
-
if (competitiveFee > maxReasonableFee) {
|
|
167
|
-
this.logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
|
|
168
|
-
competitiveFee: formatGwei(competitiveFee),
|
|
169
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
170
|
-
cappedTo: formatGwei(maxReasonableFee),
|
|
171
|
-
});
|
|
172
|
-
competitiveFee = maxReasonableFee;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Log final decision
|
|
176
|
-
if (competitiveFee > networkEstimate) {
|
|
177
|
-
this.logger?.debug('Using competitive fee from market analysis', {
|
|
178
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
179
|
-
competitive: formatGwei(competitiveFee),
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return competitiveFee;
|
|
73
|
+
public getCode(address: EthAddress): Promise<GetCodeReturnType> {
|
|
74
|
+
return this.client.getCode({ address: address.toString() });
|
|
184
75
|
}
|
|
185
76
|
|
|
186
77
|
/**
|
|
@@ -194,77 +85,56 @@ export class ReadOnlyL1TxUtils {
|
|
|
194
85
|
): Promise<GasPrice> {
|
|
195
86
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
196
87
|
|
|
197
|
-
//
|
|
198
|
-
const
|
|
199
|
-
() =>
|
|
200
|
-
|
|
88
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
89
|
+
const strategyResult = await retry(
|
|
90
|
+
() =>
|
|
91
|
+
CurrentStrategy.execute(this.client, {
|
|
92
|
+
gasConfig,
|
|
93
|
+
isBlobTx,
|
|
94
|
+
logger: this.logger,
|
|
95
|
+
}),
|
|
96
|
+
'Executing priority fee strategy',
|
|
97
|
+
makeBackoff(times(2, () => 0)),
|
|
98
|
+
this.logger,
|
|
99
|
+
true,
|
|
201
100
|
);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
211
|
-
const feeHistoryPromise = gasConfig.fixedPriorityFeePerGas
|
|
212
|
-
? null
|
|
213
|
-
: this.tryTwice(
|
|
214
|
-
() => this.client.getFeeHistory({ blockCount: HISTORICAL_BLOCK_COUNT, rewardPercentiles: [75] }),
|
|
215
|
-
'Getting fee history',
|
|
216
|
-
);
|
|
217
|
-
const blobBaseFeePromise = isBlobTx
|
|
218
|
-
? this.tryTwice(() => this.client.getBlobBaseFee(), 'Getting blob base fee')
|
|
219
|
-
: null;
|
|
220
|
-
|
|
221
|
-
const [latestBlockResult, networkEstimateResult, pendingBlockResult, feeHistoryResult, blobBaseFeeResult] =
|
|
222
|
-
await Promise.allSettled([
|
|
223
|
-
latestBlockPromise,
|
|
224
|
-
networkEstimatePromise ?? Promise.resolve(0n),
|
|
225
|
-
pendingBlockPromise ?? Promise.resolve(null),
|
|
226
|
-
feeHistoryPromise ?? Promise.resolve(null),
|
|
227
|
-
blobBaseFeePromise ?? Promise.resolve(0n),
|
|
228
|
-
]);
|
|
229
|
-
|
|
230
|
-
// Extract results
|
|
231
|
-
const baseFee =
|
|
232
|
-
latestBlockResult.status === 'fulfilled' &&
|
|
233
|
-
typeof latestBlockResult.value === 'object' &&
|
|
234
|
-
latestBlockResult.value.baseFeePerGas
|
|
235
|
-
? latestBlockResult.value.baseFeePerGas
|
|
236
|
-
: 0n;
|
|
237
|
-
|
|
238
|
-
// Get blob base fee if available
|
|
239
|
-
let blobBaseFee = 0n;
|
|
240
|
-
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
241
|
-
blobBaseFee = blobBaseFeeResult.value;
|
|
242
|
-
} else if (isBlobTx) {
|
|
101
|
+
|
|
102
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
103
|
+
|
|
104
|
+
// Extract base fee from latest block
|
|
105
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
106
|
+
|
|
107
|
+
// Handle blob base fee
|
|
108
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
243
109
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
244
110
|
}
|
|
245
111
|
|
|
246
|
-
let priorityFee
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
112
|
+
let priorityFee = strategyPriorityFee;
|
|
113
|
+
|
|
114
|
+
// Apply minimum priority fee floor if configured
|
|
115
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
116
|
+
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
117
|
+
if (priorityFee < minimumPriorityFee) {
|
|
118
|
+
this.logger?.debug('Applying minimum priority fee floor', {
|
|
119
|
+
calculatedPriorityFee: formatGwei(priorityFee),
|
|
120
|
+
minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
|
|
121
|
+
appliedFee: formatGwei(minimumPriorityFee),
|
|
122
|
+
});
|
|
123
|
+
priorityFee = minimumPriorityFee;
|
|
124
|
+
}
|
|
256
125
|
}
|
|
257
126
|
let maxFeePerGas = baseFee;
|
|
258
127
|
|
|
259
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
128
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
260
129
|
|
|
261
130
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
262
131
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
263
132
|
for (let i = 0; i < numBlocks; i++) {
|
|
264
133
|
// each block can go up 12.5% from previous baseFee
|
|
265
|
-
|
|
134
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
135
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
266
136
|
// same for blob gas fee
|
|
267
|
-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
137
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
268
138
|
}
|
|
269
139
|
|
|
270
140
|
if (attempt > 0) {
|
|
@@ -281,18 +151,15 @@ export class ReadOnlyL1TxUtils {
|
|
|
281
151
|
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
282
152
|
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
283
153
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// Apply bump percentage to competitive fee
|
|
287
|
-
competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
154
|
+
// Apply bump percentage to competitive fee
|
|
155
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
288
156
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
157
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
158
|
+
networkEstimate: formatGwei(priorityFee),
|
|
159
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
160
|
+
minRequired: formatGwei(minPriorityFee),
|
|
161
|
+
bumpPercentage: configBump,
|
|
162
|
+
});
|
|
296
163
|
|
|
297
164
|
// Use maximum between competitive fee and minimum required bump
|
|
298
165
|
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
@@ -303,26 +170,22 @@ export class ReadOnlyL1TxUtils {
|
|
|
303
170
|
maxFeePerGas += finalPriorityFee;
|
|
304
171
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
305
172
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
}
|
|
173
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
174
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
175
|
+
});
|
|
311
176
|
} else {
|
|
312
177
|
// First attempt: apply configured bump percentage to competitive fee
|
|
313
178
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
});
|
|
319
|
-
}
|
|
179
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
180
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
181
|
+
networkEstimate: formatGwei(priorityFee),
|
|
182
|
+
});
|
|
320
183
|
maxFeePerGas += priorityFee;
|
|
321
184
|
}
|
|
322
185
|
|
|
323
186
|
// maxGwei and maxBlobGwei are hard limits
|
|
324
|
-
const effectiveMaxGwei = gasConfig.maxGwei! * WEI_CONST;
|
|
325
|
-
const effectiveMaxBlobGwei = gasConfig.maxBlobGwei! * WEI_CONST;
|
|
187
|
+
const effectiveMaxGwei = BigInt(Math.trunc(gasConfig.maxGwei! * Number(WEI_CONST)));
|
|
188
|
+
const effectiveMaxBlobGwei = BigInt(Math.trunc(gasConfig.maxBlobGwei! * Number(WEI_CONST)));
|
|
326
189
|
|
|
327
190
|
// Ensure we don't exceed maxGwei
|
|
328
191
|
if (effectiveMaxGwei > 0n) {
|
|
@@ -357,7 +220,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
357
220
|
baseFee: formatGwei(baseFee),
|
|
358
221
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
359
222
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
360
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
223
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
361
224
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
362
225
|
},
|
|
363
226
|
);
|
|
@@ -381,19 +244,28 @@ export class ReadOnlyL1TxUtils {
|
|
|
381
244
|
const gasConfig = { ...this.config, ..._gasConfig };
|
|
382
245
|
let initialEstimate = 0n;
|
|
383
246
|
if (_blobInputs) {
|
|
384
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
247
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
248
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
249
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
250
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
385
251
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
386
252
|
initialEstimate = await this.client.estimateGas({
|
|
387
253
|
account,
|
|
388
254
|
...request,
|
|
389
255
|
..._blobInputs,
|
|
390
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas
|
|
391
|
-
gas:
|
|
256
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
257
|
+
gas: MAX_L1_TX_LIMIT,
|
|
258
|
+
blockTag: 'latest',
|
|
392
259
|
});
|
|
393
260
|
|
|
394
261
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
395
262
|
} else {
|
|
396
|
-
initialEstimate = await this.client.estimateGas({
|
|
263
|
+
initialEstimate = await this.client.estimateGas({
|
|
264
|
+
account,
|
|
265
|
+
...request,
|
|
266
|
+
gas: MAX_L1_TX_LIMIT,
|
|
267
|
+
blockTag: 'latest',
|
|
268
|
+
});
|
|
397
269
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
398
270
|
}
|
|
399
271
|
|
|
@@ -524,7 +396,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
524
396
|
this.logger?.debug(`L1 transaction simulation succeeded`, { ...result[0].calls[0] });
|
|
525
397
|
return { gasUsed: result[0].gasUsed, result: result[0].calls[0].data as `0x${string}` };
|
|
526
398
|
} catch (err) {
|
|
527
|
-
if (err
|
|
399
|
+
if (getErrorCause(err, MethodNotFoundRpcError) || getErrorCause(err, MethodNotSupportedRpcError)) {
|
|
528
400
|
if (gasConfig.fallbackGasEstimate) {
|
|
529
401
|
this.logger?.warn(
|
|
530
402
|
`Node does not support eth_simulateV1 API. Using fallback gas estimate: ${gasConfig.fallbackGasEstimate}`,
|
|
@@ -549,11 +421,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
549
421
|
});
|
|
550
422
|
return bumpedGasLimit;
|
|
551
423
|
}
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Helper function to retry RPC calls twice
|
|
555
|
-
*/
|
|
556
|
-
private tryTwice<T>(fn: () => Promise<T>, description: string): Promise<T> {
|
|
557
|
-
return retry<T>(fn, description, makeBackoff(times(2, () => 0)), this.logger, true);
|
|
558
|
-
}
|
|
559
424
|
}
|