@aztec/ethereum 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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/client.js +6 -2
- package/dest/config.d.ts +19 -68
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +55 -380
- package/dest/contracts/empire_base.d.ts +4 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.d.ts +4 -1
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +31 -15
- 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/governance.d.ts +3 -1
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +14 -4
- package/dest/contracts/governance_proposer.d.ts +4 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +404 -9
- 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 +1 -1
- 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/rollup.d.ts +177 -96
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +707 -144
- package/dest/contracts/tally_slashing_proposer.d.ts +3 -2
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +8 -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/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 +5975 -1575
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_contract_addresses.d.ts +1 -1
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +3 -3
- package/dest/l1_reader.d.ts +3 -1
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +6 -0
- package/dest/l1_tx_utils/config.d.ts +9 -3
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +31 -4
- 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 +15 -5
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +64 -17
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +4 -15
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +53 -160
- 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/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 +12 -4
- package/dest/test/chain_monitor.d.ts +15 -13
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +7 -9
- package/dest/test/eth_cheat_codes.d.ts +13 -1
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +4 -2
- 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 +9 -6
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +32 -6
- package/dest/test/start_anvil.d.ts +3 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +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 +64 -0
- package/package.json +33 -14
- package/src/client.ts +2 -2
- package/src/config.ts +65 -459
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +3 -1
- package/src/contracts/empire_slashing_proposer.ts +28 -28
- 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 +16 -2
- 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/rollup.ts +390 -118
- package/src/contracts/tally_slashing_proposer.ts +7 -1
- 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 +8 -0
- package/src/l1_tx_utils/config.ts +44 -6
- 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 +76 -21
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +67 -206
- package/src/{test → l1_tx_utils}/tx_delayer.ts +82 -52
- package/src/publisher_manager.ts +4 -2
- package/src/queries.ts +11 -3
- package/src/test/chain_monitor.ts +18 -16
- package/src/test/eth_cheat_codes.ts +2 -2
- package/src/test/index.ts +0 -2
- package/src/test/rollup_cheat_codes.ts +32 -9
- package/src/test/start_anvil.ts +3 -1
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +83 -1
- package/dest/deploy_l1_contracts.d.ts +0 -673
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1491
- 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 -1869
- 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
|
@@ -11,8 +11,9 @@ import { createNonceManager, formatGwei, serializeTransaction } from 'viem';
|
|
|
11
11
|
import { jsonRpc } from 'viem/nonce';
|
|
12
12
|
import { formatViemError } from '../utils.js';
|
|
13
13
|
import { l1TxUtilsConfigMappings } from './config.js';
|
|
14
|
-
import {
|
|
14
|
+
import { MAX_L1_TX_LIMIT } from './constants.js';
|
|
15
15
|
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
16
|
+
import { createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
|
|
16
17
|
import { DroppedTransactionError, TerminalTxUtilsState, TxUtilsState, UnknownMinedTxError } from './types.js';
|
|
17
18
|
const MAX_L1_TX_STATES = 32;
|
|
18
19
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
@@ -23,11 +24,28 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
23
24
|
metrics;
|
|
24
25
|
nonceManager;
|
|
25
26
|
txs;
|
|
26
|
-
|
|
27
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */ delayer;
|
|
28
|
+
/** KZG instance for blob operations. */ kzg;
|
|
29
|
+
constructor(client, address, signer, logger = createLogger('ethereum:publisher'), dateProvider = new DateProvider(), config, debugMaxGasLimit = false, store, metrics, kzg, delayer){
|
|
27
30
|
super(client, logger, dateProvider, config, debugMaxGasLimit), this.client = client, this.address = address, this.signer = signer, this.store = store, this.metrics = metrics, this.txs = [];
|
|
28
31
|
this.nonceManager = createNonceManager({
|
|
29
32
|
source: jsonRpc()
|
|
30
33
|
});
|
|
34
|
+
this.kzg = kzg;
|
|
35
|
+
// Set up delayer: use provided one or create new
|
|
36
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
37
|
+
this.delayer = delayer ?? this.createDelayer({
|
|
38
|
+
ethereumSlotDuration: config.ethereumSlotDuration
|
|
39
|
+
}, logger.getBindings());
|
|
40
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
41
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
42
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
43
|
+
}
|
|
44
|
+
} else if (delayer) {
|
|
45
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
46
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
47
|
+
this.delayer = delayer;
|
|
48
|
+
}
|
|
31
49
|
}
|
|
32
50
|
get state() {
|
|
33
51
|
return this.txs.at(-1)?.status ?? TxUtilsState.IDLE;
|
|
@@ -75,11 +93,24 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
75
93
|
this.logger.debug(`No states to rehydrate for account ${account}`);
|
|
76
94
|
return;
|
|
77
95
|
}
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
// Clean up excess states if we have more than MAX_L1_TX_STATES
|
|
97
|
+
if (loadedStates.length > MAX_L1_TX_STATES) {
|
|
98
|
+
this.logger.warn(`Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`);
|
|
99
|
+
// Keep only the most recent MAX_L1_TX_STATES
|
|
100
|
+
const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
|
|
101
|
+
const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
|
|
102
|
+
// Batch delete old states in a transaction for efficiency
|
|
103
|
+
const idsToDelete = statesToDelete.map((s)=>s.id);
|
|
104
|
+
await this.store.deleteState(account, ...idsToDelete);
|
|
105
|
+
this.txs = statesToKeep;
|
|
106
|
+
this.logger.info(`Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`);
|
|
107
|
+
} else {
|
|
108
|
+
// Convert loaded states (which have id) to the txs format
|
|
109
|
+
this.txs = loadedStates;
|
|
110
|
+
this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
|
|
111
|
+
}
|
|
81
112
|
// Find all pending states and resume monitoring
|
|
82
|
-
const pendingStates =
|
|
113
|
+
const pendingStates = this.txs.filter((state)=>!TerminalTxUtilsState.includes(state.status));
|
|
83
114
|
if (pendingStates.length === 0) {
|
|
84
115
|
return;
|
|
85
116
|
}
|
|
@@ -121,7 +152,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
121
152
|
const account = this.getSenderAddress().toString();
|
|
122
153
|
let gasLimit;
|
|
123
154
|
if (this.debugMaxGasLimit) {
|
|
124
|
-
gasLimit =
|
|
155
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
125
156
|
} else if (gasConfig.gasLimit) {
|
|
126
157
|
gasLimit = gasConfig.gasLimit;
|
|
127
158
|
} else {
|
|
@@ -135,6 +166,13 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
135
166
|
if (this.interrupted) {
|
|
136
167
|
throw new InterruptError(`Transaction sending is interrupted`);
|
|
137
168
|
}
|
|
169
|
+
// Check timeout before consuming nonce to avoid leaking a nonce that was never sent.
|
|
170
|
+
// A leaked nonce creates a gap (e.g. nonce 107 consumed but unsent), so all subsequent
|
|
171
|
+
// transactions (108, 109, ...) can never be mined since the chain expects 107 first.
|
|
172
|
+
const now = new Date(await this.getL1Timestamp());
|
|
173
|
+
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
174
|
+
throw new TimeoutError(`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`);
|
|
175
|
+
}
|
|
138
176
|
const nonce = await this.nonceManager.consume({
|
|
139
177
|
client: this.client,
|
|
140
178
|
address: account,
|
|
@@ -150,10 +188,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
150
188
|
const txData = this.makeTxData(baseState, {
|
|
151
189
|
isCancelTx: false
|
|
152
190
|
});
|
|
153
|
-
const now = new Date(await this.getL1Timestamp());
|
|
154
|
-
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
155
|
-
throw new TimeoutError(`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`);
|
|
156
|
-
}
|
|
157
191
|
// Send the new tx
|
|
158
192
|
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
159
193
|
const txHash = await this.client.sendRawTransaction({
|
|
@@ -204,7 +238,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
204
238
|
};
|
|
205
239
|
} catch (err) {
|
|
206
240
|
const viemError = formatViemError(err, request.abi);
|
|
207
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
241
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
208
242
|
request: pick(request, 'to', 'value')
|
|
209
243
|
});
|
|
210
244
|
throw viemError;
|
|
@@ -509,11 +543,11 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
509
543
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
510
544
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
511
545
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
512
|
-
gas: request.gas ??
|
|
546
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT
|
|
513
547
|
};
|
|
514
548
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
515
|
-
//
|
|
516
|
-
blockOverrides.gasLimit =
|
|
549
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
550
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
517
551
|
}
|
|
518
552
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
519
553
|
}
|
|
@@ -604,7 +638,20 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
604
638
|
});
|
|
605
639
|
return Number(timestamp) * 1000;
|
|
606
640
|
}
|
|
607
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
608
|
-
|
|
641
|
+
/** Makes empty blob inputs for the cancellation tx. */ makeEmptyBlobInputs(maxFeePerBlobGas) {
|
|
642
|
+
if (!this.kzg) {
|
|
643
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
644
|
+
}
|
|
645
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
646
|
+
return {
|
|
647
|
+
blobs: [
|
|
648
|
+
blobData
|
|
649
|
+
],
|
|
650
|
+
kzg: this.kzg,
|
|
651
|
+
maxFeePerBlobGas
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
/** Creates a new delayer instance. */ createDelayer(opts, bindings) {
|
|
655
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
609
656
|
}
|
|
610
657
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
1
2
|
import { type Logger } from '@aztec/foundation/log';
|
|
2
3
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import { type Abi, type Account, type BlockOverrides, type Hex, type StateOverride } from 'viem';
|
|
4
|
+
import { type Abi, type Account, type BlockOverrides, type GetCodeReturnType, type Hex, type StateOverride } from 'viem';
|
|
4
5
|
import type { ViemClient } from '../types.js';
|
|
5
6
|
import { type L1TxUtilsConfig } from './config.js';
|
|
6
7
|
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
@@ -44,15 +45,7 @@ export declare class ReadOnlyL1TxUtils {
|
|
|
44
45
|
transactions: `0x${string}`[];
|
|
45
46
|
}>;
|
|
46
47
|
getBlockNumber(): Promise<bigint>;
|
|
47
|
-
|
|
48
|
-
* Analyzes pending transactions and recent fee history to determine a competitive priority fee.
|
|
49
|
-
* Falls back to network estimate if data is unavailable or fails.
|
|
50
|
-
* @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
|
|
51
|
-
* @param pendingBlockResult - Result from getBlock with pending tag RPC call
|
|
52
|
-
* @param feeHistoryResult - Result from getFeeHistory RPC call
|
|
53
|
-
* @returns A competitive priority fee based on pending txs and recent block history
|
|
54
|
-
*/
|
|
55
|
-
protected getCompetitivePriorityFee(networkEstimateResult: PromiseSettledResult<bigint | null>, pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>, feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>): bigint;
|
|
48
|
+
getCode(address: EthAddress): Promise<GetCodeReturnType>;
|
|
56
49
|
/**
|
|
57
50
|
* Gets the current gas price with bounds checking
|
|
58
51
|
*/
|
|
@@ -86,9 +79,5 @@ export declare class ReadOnlyL1TxUtils {
|
|
|
86
79
|
result: `0x${string}`;
|
|
87
80
|
}>;
|
|
88
81
|
bumpGasLimit(gasLimit: bigint, _gasConfig?: L1TxUtilsConfig): bigint;
|
|
89
|
-
/**
|
|
90
|
-
* Helper function to retry RPC calls twice
|
|
91
|
-
*/
|
|
92
|
-
private tryTwice;
|
|
93
82
|
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
83
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVhZG9ubHlfbDFfdHhfdXRpbHMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sMV90eF91dGlscy9yZWFkb25seV9sMV90eF91dGlsc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ACnD,cAAc,GAAE,cAAc,CAAC,MAAM,EAAE,MAAM,CAAM,EACnD,cAAc,GAAE,aAAkB,EAClC,GAAG,GAAE,GAAe,EACpB,UAAU,CAAC,EAAE,eAAe,GAAG;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9D,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,KAAK,MAAM,EAAE,CAAA;KAAE,CAAC,CAUrD;IAED,UAAgB,SAAS,CACvB,IAAI,EAAE,GAAG,EACT,cAAc,4CAAqC,EACnD,cAAc,2BAAoB,EAClC,SAAS,EAAE,eAAe,GAAG;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,EAC7D,GAAG,EAAE,GAAG;;;OAoCT;IAEM,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,MAAM,CAW1E;CACF"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { getKeys,
|
|
1
|
+
import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
|
|
2
2
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
4
4
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
5
5
|
import pickBy from 'lodash.pickby';
|
|
6
6
|
import { MethodNotFoundRpcError, MethodNotSupportedRpcError, decodeErrorResult, formatGwei, getContractError, hexToBytes } from 'viem';
|
|
7
7
|
import { defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
8
|
-
import { BLOCK_TIME_MS,
|
|
8
|
+
import { BLOCK_TIME_MS, MAX_L1_TX_LIMIT, MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE, MIN_REPLACEMENT_BUMP_PERCENTAGE, WEI_CONST } from './constants.js';
|
|
9
|
+
import { P75AllTxsPriorityFeeStrategy } from './fee-strategies/index.js';
|
|
9
10
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
10
|
-
|
|
11
|
+
// Change this to the current strategy we want to use
|
|
12
|
+
const CurrentStrategy = P75AllTxsPriorityFeeStrategy;
|
|
11
13
|
export class ReadOnlyL1TxUtils {
|
|
12
14
|
client;
|
|
13
15
|
logger;
|
|
@@ -35,142 +37,43 @@ export class ReadOnlyL1TxUtils {
|
|
|
35
37
|
getBlockNumber() {
|
|
36
38
|
return this.client.getBlockNumber();
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* @param pendingBlockResult - Result from getBlock with pending tag RPC call
|
|
43
|
-
* @param feeHistoryResult - Result from getFeeHistory RPC call
|
|
44
|
-
* @returns A competitive priority fee based on pending txs and recent block history
|
|
45
|
-
*/ getCompetitivePriorityFee(networkEstimateResult, pendingBlockResult, feeHistoryResult) {
|
|
46
|
-
const networkEstimate = networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint' ? networkEstimateResult.value : 0n;
|
|
47
|
-
let competitiveFee = networkEstimate;
|
|
48
|
-
if (pendingBlockResult.status === 'fulfilled' && pendingBlockResult.value !== null && pendingBlockResult.value.transactions && pendingBlockResult.value.transactions.length > 0) {
|
|
49
|
-
const pendingBlock = pendingBlockResult.value;
|
|
50
|
-
// Extract priority fees from pending transactions
|
|
51
|
-
const pendingFees = pendingBlock.transactions.map((tx)=>{
|
|
52
|
-
// Transaction can be just a hash string, so we need to check if it's an object
|
|
53
|
-
if (typeof tx === 'string') {
|
|
54
|
-
return 0n;
|
|
55
|
-
}
|
|
56
|
-
const fee = tx.maxPriorityFeePerGas || 0n;
|
|
57
|
-
// Debug: Log suspicious fees
|
|
58
|
-
if (fee > 100n * WEI_CONST) {
|
|
59
|
-
this.logger?.warn('Suspicious high priority fee in pending tx', {
|
|
60
|
-
txHash: tx.hash,
|
|
61
|
-
maxPriorityFeePerGas: formatGwei(fee),
|
|
62
|
-
maxFeePerGas: formatGwei(tx.maxFeePerGas || 0n),
|
|
63
|
-
maxFeePerBlobGas: tx.maxFeePerBlobGas ? formatGwei(tx.maxFeePerBlobGas) : 'N/A'
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return fee;
|
|
67
|
-
}).filter((fee)=>fee > 0n);
|
|
68
|
-
if (pendingFees.length > 0) {
|
|
69
|
-
// Use 75th percentile of pending fees to be competitive
|
|
70
|
-
const sortedPendingFees = [
|
|
71
|
-
...pendingFees
|
|
72
|
-
].sort((a, b)=>a < b ? -1 : a > b ? 1 : 0);
|
|
73
|
-
const percentile75Index = Math.floor((sortedPendingFees.length - 1) * 0.75);
|
|
74
|
-
const pendingCompetitiveFee = sortedPendingFees[percentile75Index];
|
|
75
|
-
if (pendingCompetitiveFee > competitiveFee) {
|
|
76
|
-
competitiveFee = pendingCompetitiveFee;
|
|
77
|
-
}
|
|
78
|
-
this.logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
79
|
-
pendingTxCount: pendingFees.length,
|
|
80
|
-
pendingP75: formatGwei(pendingCompetitiveFee)
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (feeHistoryResult.status === 'fulfilled' && feeHistoryResult.value !== null && feeHistoryResult.value.reward && feeHistoryResult.value.reward.length > 0) {
|
|
85
|
-
const feeHistory = feeHistoryResult.value;
|
|
86
|
-
// Extract 75th percentile fees from each block
|
|
87
|
-
const percentile75Fees = feeHistory.reward.map((rewards)=>rewards[0] || 0n).filter((fee)=>fee > 0n);
|
|
88
|
-
if (percentile75Fees.length > 0) {
|
|
89
|
-
// Calculate median of the 75th percentile fees across blocks
|
|
90
|
-
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
91
|
-
// Debug: Log suspicious fees from history
|
|
92
|
-
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
93
|
-
this.logger?.warn('Suspicious high fee in history', {
|
|
94
|
-
historicalMedian: formatGwei(medianHistoricalFee),
|
|
95
|
-
allP75Fees: percentile75Fees.map((f)=>formatGwei(f))
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (medianHistoricalFee > competitiveFee) {
|
|
99
|
-
competitiveFee = medianHistoricalFee;
|
|
100
|
-
}
|
|
101
|
-
this.logger?.debug('Analyzed fee history for competitive pricing', {
|
|
102
|
-
historicalMedian: formatGwei(medianHistoricalFee)
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
|
|
107
|
-
// (e.g., Anvil returns inflated historical fees that don't reflect actual network conditions)
|
|
108
|
-
const maxReasonableFee = networkEstimate * 100n;
|
|
109
|
-
if (competitiveFee > maxReasonableFee) {
|
|
110
|
-
this.logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
|
|
111
|
-
competitiveFee: formatGwei(competitiveFee),
|
|
112
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
113
|
-
cappedTo: formatGwei(maxReasonableFee)
|
|
114
|
-
});
|
|
115
|
-
competitiveFee = maxReasonableFee;
|
|
116
|
-
}
|
|
117
|
-
// Log final decision
|
|
118
|
-
if (competitiveFee > networkEstimate) {
|
|
119
|
-
this.logger?.debug('Using competitive fee from market analysis', {
|
|
120
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
121
|
-
competitive: formatGwei(competitiveFee)
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
return competitiveFee;
|
|
40
|
+
getCode(address) {
|
|
41
|
+
return this.client.getCode({
|
|
42
|
+
address: address.toString()
|
|
43
|
+
});
|
|
125
44
|
}
|
|
126
45
|
/**
|
|
127
46
|
* Gets the current gas price with bounds checking
|
|
128
47
|
*/ async getGasPrice(gasConfigOverrides, isBlobTx = false, attempt = 0, previousGasPrice) {
|
|
129
48
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
130
|
-
//
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
rewardPercentiles: [
|
|
142
|
-
75
|
|
143
|
-
]
|
|
144
|
-
}), 'Getting fee history');
|
|
145
|
-
const blobBaseFeePromise = isBlobTx ? this.tryTwice(()=>this.client.getBlobBaseFee(), 'Getting blob base fee') : null;
|
|
146
|
-
const [latestBlockResult, networkEstimateResult, pendingBlockResult, feeHistoryResult, blobBaseFeeResult] = await Promise.allSettled([
|
|
147
|
-
latestBlockPromise,
|
|
148
|
-
networkEstimatePromise ?? Promise.resolve(0n),
|
|
149
|
-
pendingBlockPromise ?? Promise.resolve(null),
|
|
150
|
-
feeHistoryPromise ?? Promise.resolve(null),
|
|
151
|
-
blobBaseFeePromise ?? Promise.resolve(0n)
|
|
152
|
-
]);
|
|
153
|
-
// Extract results
|
|
154
|
-
const baseFee = latestBlockResult.status === 'fulfilled' && typeof latestBlockResult.value === 'object' && latestBlockResult.value.baseFeePerGas ? latestBlockResult.value.baseFeePerGas : 0n;
|
|
155
|
-
// Get blob base fee if available
|
|
156
|
-
let blobBaseFee = 0n;
|
|
157
|
-
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
158
|
-
blobBaseFee = blobBaseFeeResult.value;
|
|
159
|
-
} else if (isBlobTx) {
|
|
49
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
50
|
+
const strategyResult = await retry(()=>CurrentStrategy.execute(this.client, {
|
|
51
|
+
gasConfig,
|
|
52
|
+
isBlobTx,
|
|
53
|
+
logger: this.logger
|
|
54
|
+
}), 'Executing priority fee strategy', makeBackoff(times(2, ()=>0)), this.logger, true);
|
|
55
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
56
|
+
// Extract base fee from latest block
|
|
57
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
58
|
+
// Handle blob base fee
|
|
59
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
160
60
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
161
61
|
}
|
|
162
|
-
let priorityFee;
|
|
163
|
-
if
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
62
|
+
let priorityFee = strategyPriorityFee;
|
|
63
|
+
// Apply minimum priority fee floor if configured
|
|
64
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
65
|
+
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
66
|
+
if (priorityFee < minimumPriorityFee) {
|
|
67
|
+
this.logger?.debug('Applying minimum priority fee floor', {
|
|
68
|
+
calculatedPriorityFee: formatGwei(priorityFee),
|
|
69
|
+
minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
|
|
70
|
+
appliedFee: formatGwei(minimumPriorityFee)
|
|
71
|
+
});
|
|
72
|
+
priorityFee = minimumPriorityFee;
|
|
73
|
+
}
|
|
171
74
|
}
|
|
172
75
|
let maxFeePerGas = baseFee;
|
|
173
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
76
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
174
77
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
175
78
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs / BLOCK_TIME_MS);
|
|
176
79
|
for(let i = 0; i < numBlocks; i++){
|
|
@@ -188,17 +91,14 @@ export class ReadOnlyL1TxUtils {
|
|
|
188
91
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
189
92
|
const minPriorityFee = previousGasPrice.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00)) / 100_00n;
|
|
190
93
|
const minMaxFee = previousGasPrice.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00)) / 100_00n;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
bumpPercentage: configBump
|
|
200
|
-
});
|
|
201
|
-
}
|
|
94
|
+
// Apply bump percentage to competitive fee
|
|
95
|
+
const competitivePriorityFee = priorityFee * (100_00n + BigInt(configBump * 1_00)) / 100_00n;
|
|
96
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
97
|
+
networkEstimate: formatGwei(priorityFee),
|
|
98
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
99
|
+
minRequired: formatGwei(minPriorityFee),
|
|
100
|
+
bumpPercentage: configBump
|
|
101
|
+
});
|
|
202
102
|
// Use maximum between competitive fee and minimum required bump
|
|
203
103
|
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
204
104
|
const feeSource = finalPriorityFee === competitivePriorityFee ? 'competitive' : 'minimum-bump';
|
|
@@ -206,20 +106,16 @@ export class ReadOnlyL1TxUtils {
|
|
|
206
106
|
// Add the final priority fee to maxFeePerGas
|
|
207
107
|
maxFeePerGas += finalPriorityFee;
|
|
208
108
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
});
|
|
213
|
-
}
|
|
109
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
110
|
+
finalPriorityFee: formatGwei(finalPriorityFee)
|
|
111
|
+
});
|
|
214
112
|
} else {
|
|
215
113
|
// First attempt: apply configured bump percentage to competitive fee
|
|
216
114
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
}
|
|
115
|
+
priorityFee = priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00)) / 100_00n;
|
|
116
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
117
|
+
networkEstimate: formatGwei(priorityFee)
|
|
118
|
+
});
|
|
223
119
|
maxFeePerGas += priorityFee;
|
|
224
120
|
}
|
|
225
121
|
// maxGwei and maxBlobGwei are hard limits
|
|
@@ -247,7 +143,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
247
143
|
baseFee: formatGwei(baseFee),
|
|
248
144
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
249
145
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
250
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
146
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
251
147
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas)
|
|
252
148
|
});
|
|
253
149
|
return {
|
|
@@ -274,14 +170,16 @@ export class ReadOnlyL1TxUtils {
|
|
|
274
170
|
...request,
|
|
275
171
|
..._blobInputs,
|
|
276
172
|
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas,
|
|
277
|
-
gas:
|
|
173
|
+
gas: MAX_L1_TX_LIMIT,
|
|
174
|
+
blockTag: 'latest'
|
|
278
175
|
});
|
|
279
176
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
280
177
|
} else {
|
|
281
178
|
initialEstimate = await this.client.estimateGas({
|
|
282
179
|
account,
|
|
283
180
|
...request,
|
|
284
|
-
gas:
|
|
181
|
+
gas: MAX_L1_TX_LIMIT,
|
|
182
|
+
blockTag: 'latest'
|
|
285
183
|
});
|
|
286
184
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
287
185
|
}
|
|
@@ -422,9 +320,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
422
320
|
});
|
|
423
321
|
return bumpedGasLimit;
|
|
424
322
|
}
|
|
425
|
-
/**
|
|
426
|
-
* Helper function to retry RPC calls twice
|
|
427
|
-
*/ tryTwice(fn, description) {
|
|
428
|
-
return retry(fn, description, makeBackoff(times(2, ()=>0)), this.logger, true);
|
|
429
|
-
}
|
|
430
323
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
|
|
2
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
+
import { type Client, type Hex } from 'viem';
|
|
4
|
+
import type { ViemClient } from '../types.js';
|
|
5
|
+
export declare function waitUntilBlock<T extends Client>(client: T, blockNumber: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
6
|
+
export declare function waitUntilL1Timestamp<T extends Client>(client: T, timestamp: number | bigint, logger?: Logger, timeout?: number): Promise<boolean>;
|
|
7
|
+
/** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */
|
|
8
|
+
export declare class Delayer {
|
|
9
|
+
dateProvider: DateProvider;
|
|
10
|
+
private logger;
|
|
11
|
+
maxInclusionTimeIntoSlot: number | undefined;
|
|
12
|
+
ethereumSlotDuration: bigint;
|
|
13
|
+
nextWait: {
|
|
14
|
+
l1Timestamp: bigint;
|
|
15
|
+
} | {
|
|
16
|
+
l1BlockNumber: bigint;
|
|
17
|
+
} | {
|
|
18
|
+
indefinitely: true;
|
|
19
|
+
} | undefined;
|
|
20
|
+
sentTxHashes: Hex[];
|
|
21
|
+
cancelledTxs: Hex[];
|
|
22
|
+
constructor(dateProvider: DateProvider, opts: {
|
|
23
|
+
ethereumSlotDuration: bigint | number;
|
|
24
|
+
}, bindings: LoggerBindings);
|
|
25
|
+
/** Returns the logger instance used by this delayer. */
|
|
26
|
+
getLogger(): Logger;
|
|
27
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
28
|
+
getSentTxHashes(): `0x${string}`[];
|
|
29
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
30
|
+
getCancelledTxs(): Hex[];
|
|
31
|
+
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
32
|
+
pauseNextTxUntilBlock(l1BlockNumber: number | bigint): void;
|
|
33
|
+
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
34
|
+
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint): void;
|
|
35
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
36
|
+
cancelNextTx(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
39
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
40
|
+
* L1 slot but will be deferred for the next one.
|
|
41
|
+
*/
|
|
42
|
+
setMaxInclusionTimeIntoSlot(seconds: number | undefined): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new Delayer instance. Exposed so callers can create a single shared delayer
|
|
46
|
+
* and pass it to multiple `wrapClientWithDelayer` calls.
|
|
47
|
+
*/
|
|
48
|
+
export declare function createDelayer(dateProvider: DateProvider, opts: {
|
|
49
|
+
ethereumSlotDuration: bigint | number;
|
|
50
|
+
}, bindings: LoggerBindings): Delayer;
|
|
51
|
+
/**
|
|
52
|
+
* Wraps a viem client with tx delaying logic. Returns the wrapped client.
|
|
53
|
+
* The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
|
|
54
|
+
*/
|
|
55
|
+
export declare function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T;
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfZGVsYXllci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2wxX3R4X3V0aWxzL3R4X2RlbGF5ZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxFQUFFLEtBQUssTUFBTSxFQUFFLEtBQUssY0FBYyxFQUFnQixNQUFNLHVCQUF1QixDQUFDO0FBRXZGLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBRzVELE9BQU8sRUFDTCxLQ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