@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,8 +1,9 @@
|
|
|
1
|
+
import type { BlobKzgInstance } from '@aztec/blob-lib/types';
|
|
1
2
|
import { maxBigint } from '@aztec/foundation/bigint';
|
|
2
3
|
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
4
|
import { InterruptError, TimeoutError } from '@aztec/foundation/error';
|
|
4
5
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
5
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
6
7
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
7
8
|
import { sleep } from '@aztec/foundation/sleep';
|
|
8
9
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
@@ -13,23 +14,21 @@ import {
|
|
|
13
14
|
type Abi,
|
|
14
15
|
type BlockOverrides,
|
|
15
16
|
type Hex,
|
|
16
|
-
type NonceManager,
|
|
17
17
|
type PrepareTransactionRequestRequest,
|
|
18
18
|
type StateOverride,
|
|
19
19
|
type TransactionReceipt,
|
|
20
20
|
type TransactionSerializable,
|
|
21
|
-
createNonceManager,
|
|
22
21
|
formatGwei,
|
|
23
22
|
serializeTransaction,
|
|
24
23
|
} from 'viem';
|
|
25
|
-
import { jsonRpc } from 'viem/nonce';
|
|
26
24
|
|
|
27
25
|
import type { ViemClient } from '../types.js';
|
|
28
26
|
import { formatViemError } from '../utils.js';
|
|
29
27
|
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
30
|
-
import {
|
|
28
|
+
import { MAX_L1_TX_LIMIT } from './constants.js';
|
|
31
29
|
import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
|
|
32
30
|
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
31
|
+
import { Delayer, createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
|
|
33
32
|
import {
|
|
34
33
|
DroppedTransactionError,
|
|
35
34
|
type L1BlobInputs,
|
|
@@ -45,8 +44,13 @@ import {
|
|
|
45
44
|
const MAX_L1_TX_STATES = 32;
|
|
46
45
|
|
|
47
46
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
48
|
-
protected nonceManager: NonceManager;
|
|
49
47
|
protected txs: L1TxState[] = [];
|
|
48
|
+
/** Last nonce successfully sent to the chain. Used as a lower bound when a fallback RPC node returns a stale count. */
|
|
49
|
+
private lastSentNonce: number | undefined;
|
|
50
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
51
|
+
public delayer?: Delayer;
|
|
52
|
+
/** KZG instance for blob operations. */
|
|
53
|
+
protected kzg?: BlobKzgInstance;
|
|
50
54
|
|
|
51
55
|
constructor(
|
|
52
56
|
public override client: ViemClient,
|
|
@@ -58,9 +62,25 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
58
62
|
debugMaxGasLimit: boolean = false,
|
|
59
63
|
protected store?: IL1TxStore,
|
|
60
64
|
protected metrics?: IL1TxMetrics,
|
|
65
|
+
kzg?: BlobKzgInstance,
|
|
66
|
+
delayer?: Delayer,
|
|
61
67
|
) {
|
|
62
68
|
super(client, logger, dateProvider, config, debugMaxGasLimit);
|
|
63
|
-
this.
|
|
69
|
+
this.kzg = kzg;
|
|
70
|
+
|
|
71
|
+
// Set up delayer: use provided one or create new
|
|
72
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
73
|
+
this.delayer =
|
|
74
|
+
delayer ?? this.createDelayer({ ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings());
|
|
75
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
76
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
77
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
78
|
+
}
|
|
79
|
+
} else if (delayer) {
|
|
80
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
81
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
82
|
+
this.delayer = delayer;
|
|
83
|
+
}
|
|
64
84
|
}
|
|
65
85
|
|
|
66
86
|
public get state() {
|
|
@@ -87,6 +107,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
87
107
|
this.metrics?.recordMinedTx(l1TxState, new Date(l1Timestamp));
|
|
88
108
|
} else if (newState === TxUtilsState.NOT_MINED) {
|
|
89
109
|
this.metrics?.recordDroppedTx(l1TxState);
|
|
110
|
+
// The tx was dropped: the chain nonce reverted to l1TxState.nonce, so our lower bound is
|
|
111
|
+
// no longer valid. Clear it so the next send fetches the real nonce from the chain.
|
|
112
|
+
if (this.lastSentNonce === l1TxState.nonce) {
|
|
113
|
+
this.lastSentNonce = undefined;
|
|
114
|
+
}
|
|
90
115
|
}
|
|
91
116
|
|
|
92
117
|
// Update state in the store
|
|
@@ -130,12 +155,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
130
155
|
return;
|
|
131
156
|
}
|
|
132
157
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
158
|
+
// Clean up excess states if we have more than MAX_L1_TX_STATES
|
|
159
|
+
if (loadedStates.length > MAX_L1_TX_STATES) {
|
|
160
|
+
this.logger.warn(
|
|
161
|
+
`Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Keep only the most recent MAX_L1_TX_STATES
|
|
165
|
+
const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
|
|
166
|
+
const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
|
|
167
|
+
|
|
168
|
+
// Batch delete old states in a transaction for efficiency
|
|
169
|
+
const idsToDelete = statesToDelete.map(s => s.id);
|
|
170
|
+
await this.store.deleteState(account, ...idsToDelete);
|
|
171
|
+
|
|
172
|
+
this.txs = statesToKeep;
|
|
173
|
+
this.logger.info(
|
|
174
|
+
`Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`,
|
|
175
|
+
);
|
|
176
|
+
} else {
|
|
177
|
+
// Convert loaded states (which have id) to the txs format
|
|
178
|
+
this.txs = loadedStates;
|
|
179
|
+
this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
|
|
180
|
+
}
|
|
136
181
|
|
|
137
182
|
// Find all pending states and resume monitoring
|
|
138
|
-
const pendingStates =
|
|
183
|
+
const pendingStates = this.txs.filter(state => !TerminalTxUtilsState.includes(state.status));
|
|
139
184
|
if (pendingStates.length === 0) {
|
|
140
185
|
return;
|
|
141
186
|
}
|
|
@@ -187,7 +232,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
187
232
|
|
|
188
233
|
let gasLimit: bigint;
|
|
189
234
|
if (this.debugMaxGasLimit) {
|
|
190
|
-
gasLimit =
|
|
235
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
191
236
|
} else if (gasConfig.gasLimit) {
|
|
192
237
|
gasLimit = gasConfig.gasLimit;
|
|
193
238
|
} else {
|
|
@@ -201,15 +246,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
201
246
|
throw new InterruptError(`Transaction sending is interrupted`);
|
|
202
247
|
}
|
|
203
248
|
|
|
204
|
-
const nonce = await this.nonceManager.consume({
|
|
205
|
-
client: this.client,
|
|
206
|
-
address: account,
|
|
207
|
-
chainId: this.client.chain.id,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
211
|
-
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
212
|
-
|
|
213
249
|
const now = new Date(await this.getL1Timestamp());
|
|
214
250
|
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
215
251
|
throw new TimeoutError(
|
|
@@ -217,9 +253,20 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
217
253
|
);
|
|
218
254
|
}
|
|
219
255
|
|
|
256
|
+
const chainNonce = await this.client.getTransactionCount({ address: account, blockTag: 'pending' });
|
|
257
|
+
// If a fallback RPC node returns a stale count (lower than what we last sent), use our
|
|
258
|
+
// local lower bound to avoid sending a duplicate of an already-pending transaction.
|
|
259
|
+
const nonce =
|
|
260
|
+
this.lastSentNonce !== undefined && chainNonce <= this.lastSentNonce ? this.lastSentNonce + 1 : chainNonce;
|
|
261
|
+
|
|
262
|
+
const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
263
|
+
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
264
|
+
|
|
220
265
|
// Send the new tx
|
|
221
266
|
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
222
267
|
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
268
|
+
// Update after tx is sent successfully
|
|
269
|
+
this.lastSentNonce = nonce;
|
|
223
270
|
|
|
224
271
|
// Create the new state for monitoring
|
|
225
272
|
const l1TxState: L1TxState = {
|
|
@@ -263,7 +310,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
263
310
|
return { txHash, state: l1TxState };
|
|
264
311
|
} catch (err: any) {
|
|
265
312
|
const viemError = formatViemError(err, request.abi);
|
|
266
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
313
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
267
314
|
request: pick(request, 'to', 'value'),
|
|
268
315
|
});
|
|
269
316
|
throw viemError;
|
|
@@ -403,7 +450,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
403
450
|
{ nonce, account, pendingNonce, timePassed },
|
|
404
451
|
);
|
|
405
452
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
406
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
407
453
|
throw new DroppedTransactionError(nonce, account);
|
|
408
454
|
}
|
|
409
455
|
|
|
@@ -495,12 +541,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
495
541
|
|
|
496
542
|
// Oh no, the transaction has timed out!
|
|
497
543
|
if (isCancelTx || !gasConfig.cancelTxOnTimeout) {
|
|
498
|
-
// If this was already a cancellation tx, or we are configured to not cancel txs, we just mark it as NOT_MINED
|
|
499
|
-
// and reset the nonce manager, so the next tx that comes along can reuse the nonce if/when this tx gets dropped.
|
|
500
|
-
// This is the nastiest scenario for us, since the new tx could acquire the next nonce, but then this tx is dropped,
|
|
501
|
-
// and the new tx would never get mined. Eventually, the new tx would also drop.
|
|
502
544
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
503
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
504
545
|
} else {
|
|
505
546
|
// Otherwise we fire the cancellation without awaiting to avoid blocking the caller,
|
|
506
547
|
// and monitor it in the background so we can speed it up as needed.
|
|
@@ -611,12 +652,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
611
652
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
612
653
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
613
654
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
614
|
-
gas: request.gas ??
|
|
655
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT,
|
|
615
656
|
};
|
|
616
657
|
|
|
617
658
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
618
|
-
//
|
|
619
|
-
blockOverrides.gasLimit =
|
|
659
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
660
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
620
661
|
}
|
|
621
662
|
|
|
622
663
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
@@ -639,7 +680,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
639
680
|
{ nonce, account },
|
|
640
681
|
);
|
|
641
682
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
642
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
643
683
|
return;
|
|
644
684
|
}
|
|
645
685
|
|
|
@@ -651,7 +691,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
651
691
|
{ nonce, account, currentNonce },
|
|
652
692
|
);
|
|
653
693
|
await this.updateState(state, TxUtilsState.NOT_MINED);
|
|
654
|
-
this.nonceManager.reset({ address: account, chainId: this.client.chain.id });
|
|
655
694
|
return;
|
|
656
695
|
}
|
|
657
696
|
|
|
@@ -711,8 +750,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
711
750
|
return Number(timestamp) * 1000;
|
|
712
751
|
}
|
|
713
752
|
|
|
714
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
715
|
-
protected makeEmptyBlobInputs(
|
|
716
|
-
|
|
753
|
+
/** Makes empty blob inputs for the cancellation tx. */
|
|
754
|
+
protected makeEmptyBlobInputs(maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
|
|
755
|
+
if (!this.kzg) {
|
|
756
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
757
|
+
}
|
|
758
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
759
|
+
return { blobs: [blobData], kzg: this.kzg, maxFeePerBlobGas };
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/** Creates a new delayer instance. */
|
|
763
|
+
protected createDelayer(opts: { ethereumSlotDuration: bigint | number }, bindings: LoggerBindings): Delayer {
|
|
764
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
717
765
|
}
|
|
718
766
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
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';
|
|
@@ -11,6 +12,7 @@ import {
|
|
|
11
12
|
type BaseError,
|
|
12
13
|
type BlockOverrides,
|
|
13
14
|
type ContractFunctionExecutionError,
|
|
15
|
+
type GetCodeReturnType,
|
|
14
16
|
type Hex,
|
|
15
17
|
MethodNotFoundRpcError,
|
|
16
18
|
MethodNotSupportedRpcError,
|
|
@@ -25,15 +27,17 @@ import type { ViemClient } from '../types.js';
|
|
|
25
27
|
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
26
28
|
import {
|
|
27
29
|
BLOCK_TIME_MS,
|
|
28
|
-
|
|
30
|
+
MAX_L1_TX_LIMIT,
|
|
29
31
|
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
30
32
|
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
31
33
|
WEI_CONST,
|
|
32
34
|
} from './constants.js';
|
|
35
|
+
import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
|
|
33
36
|
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
34
37
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
// Change this to the current strategy we want to use
|
|
40
|
+
const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
|
|
37
41
|
|
|
38
42
|
export class ReadOnlyL1TxUtils {
|
|
39
43
|
public config: Required<L1TxUtilsConfig>;
|
|
@@ -65,122 +69,8 @@ export class ReadOnlyL1TxUtils {
|
|
|
65
69
|
return this.client.getBlockNumber();
|
|
66
70
|
}
|
|
67
71
|
|
|
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;
|
|
72
|
+
public getCode(address: EthAddress): Promise<GetCodeReturnType> {
|
|
73
|
+
return this.client.getCode({ address: address.toString() });
|
|
184
74
|
}
|
|
185
75
|
|
|
186
76
|
/**
|
|
@@ -194,77 +84,56 @@ export class ReadOnlyL1TxUtils {
|
|
|
194
84
|
): Promise<GasPrice> {
|
|
195
85
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
196
86
|
|
|
197
|
-
//
|
|
198
|
-
const
|
|
199
|
-
() =>
|
|
200
|
-
|
|
87
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
88
|
+
const strategyResult = await retry(
|
|
89
|
+
() =>
|
|
90
|
+
CurrentStrategy.execute(this.client, {
|
|
91
|
+
gasConfig,
|
|
92
|
+
isBlobTx,
|
|
93
|
+
logger: this.logger,
|
|
94
|
+
}),
|
|
95
|
+
'Executing priority fee strategy',
|
|
96
|
+
makeBackoff(times(2, () => 0)),
|
|
97
|
+
this.logger,
|
|
98
|
+
true,
|
|
201
99
|
);
|
|
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) {
|
|
100
|
+
|
|
101
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
102
|
+
|
|
103
|
+
// Extract base fee from latest block
|
|
104
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
105
|
+
|
|
106
|
+
// Handle blob base fee
|
|
107
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
243
108
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
244
109
|
}
|
|
245
110
|
|
|
246
|
-
let priorityFee
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
111
|
+
let priorityFee = strategyPriorityFee;
|
|
112
|
+
|
|
113
|
+
// Apply minimum priority fee floor if configured
|
|
114
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
115
|
+
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
116
|
+
if (priorityFee < minimumPriorityFee) {
|
|
117
|
+
this.logger?.debug('Applying minimum priority fee floor', {
|
|
118
|
+
calculatedPriorityFee: formatGwei(priorityFee),
|
|
119
|
+
minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
|
|
120
|
+
appliedFee: formatGwei(minimumPriorityFee),
|
|
121
|
+
});
|
|
122
|
+
priorityFee = minimumPriorityFee;
|
|
123
|
+
}
|
|
256
124
|
}
|
|
257
125
|
let maxFeePerGas = baseFee;
|
|
258
126
|
|
|
259
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
127
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
260
128
|
|
|
261
129
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
262
130
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
263
131
|
for (let i = 0; i < numBlocks; i++) {
|
|
264
132
|
// each block can go up 12.5% from previous baseFee
|
|
265
|
-
|
|
133
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
134
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
266
135
|
// same for blob gas fee
|
|
267
|
-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
136
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
268
137
|
}
|
|
269
138
|
|
|
270
139
|
if (attempt > 0) {
|
|
@@ -281,18 +150,15 @@ export class ReadOnlyL1TxUtils {
|
|
|
281
150
|
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
282
151
|
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
283
152
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
// Apply bump percentage to competitive fee
|
|
287
|
-
competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
153
|
+
// Apply bump percentage to competitive fee
|
|
154
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
288
155
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
156
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
157
|
+
networkEstimate: formatGwei(priorityFee),
|
|
158
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
159
|
+
minRequired: formatGwei(minPriorityFee),
|
|
160
|
+
bumpPercentage: configBump,
|
|
161
|
+
});
|
|
296
162
|
|
|
297
163
|
// Use maximum between competitive fee and minimum required bump
|
|
298
164
|
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
@@ -303,26 +169,22 @@ export class ReadOnlyL1TxUtils {
|
|
|
303
169
|
maxFeePerGas += finalPriorityFee;
|
|
304
170
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
305
171
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
});
|
|
310
|
-
}
|
|
172
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
173
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
174
|
+
});
|
|
311
175
|
} else {
|
|
312
176
|
// First attempt: apply configured bump percentage to competitive fee
|
|
313
177
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
});
|
|
319
|
-
}
|
|
178
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
179
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
180
|
+
networkEstimate: formatGwei(priorityFee),
|
|
181
|
+
});
|
|
320
182
|
maxFeePerGas += priorityFee;
|
|
321
183
|
}
|
|
322
184
|
|
|
323
185
|
// maxGwei and maxBlobGwei are hard limits
|
|
324
|
-
const effectiveMaxGwei = gasConfig.maxGwei! * WEI_CONST;
|
|
325
|
-
const effectiveMaxBlobGwei = gasConfig.maxBlobGwei! * WEI_CONST;
|
|
186
|
+
const effectiveMaxGwei = BigInt(Math.trunc(gasConfig.maxGwei! * Number(WEI_CONST)));
|
|
187
|
+
const effectiveMaxBlobGwei = BigInt(Math.trunc(gasConfig.maxBlobGwei! * Number(WEI_CONST)));
|
|
326
188
|
|
|
327
189
|
// Ensure we don't exceed maxGwei
|
|
328
190
|
if (effectiveMaxGwei > 0n) {
|
|
@@ -357,7 +219,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
357
219
|
baseFee: formatGwei(baseFee),
|
|
358
220
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
359
221
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
360
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
222
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
361
223
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
362
224
|
},
|
|
363
225
|
);
|
|
@@ -381,19 +243,28 @@ export class ReadOnlyL1TxUtils {
|
|
|
381
243
|
const gasConfig = { ...this.config, ..._gasConfig };
|
|
382
244
|
let initialEstimate = 0n;
|
|
383
245
|
if (_blobInputs) {
|
|
384
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
246
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
247
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
248
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
249
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
385
250
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
386
251
|
initialEstimate = await this.client.estimateGas({
|
|
387
252
|
account,
|
|
388
253
|
...request,
|
|
389
254
|
..._blobInputs,
|
|
390
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas
|
|
391
|
-
gas:
|
|
255
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
256
|
+
gas: MAX_L1_TX_LIMIT,
|
|
257
|
+
blockTag: 'latest',
|
|
392
258
|
});
|
|
393
259
|
|
|
394
260
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
395
261
|
} else {
|
|
396
|
-
initialEstimate = await this.client.estimateGas({
|
|
262
|
+
initialEstimate = await this.client.estimateGas({
|
|
263
|
+
account,
|
|
264
|
+
...request,
|
|
265
|
+
gas: MAX_L1_TX_LIMIT,
|
|
266
|
+
blockTag: 'latest',
|
|
267
|
+
});
|
|
397
268
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
398
269
|
}
|
|
399
270
|
|
|
@@ -549,11 +420,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
549
420
|
});
|
|
550
421
|
return bumpedGasLimit;
|
|
551
422
|
}
|
|
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
423
|
}
|