@aztec/ethereum 0.0.1-fake-c83136db25 → 0.0.2-commit.217f559981
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 +1 -1
- package/dest/client.js +6 -2
- package/dest/config.d.ts +22 -68
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +61 -348
- 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 +1 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/rollup.d.ts +195 -123
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +755 -187
- 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 +11884 -1956
- 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 +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 +11 -5
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +45 -9
- 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 -6
- 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 +19 -17
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +69 -40
- 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 +27 -24
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +33 -36
- 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 +4 -1
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +3 -2
- 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 +64 -0
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/package.json +34 -14
- package/src/client.ts +2 -2
- package/src/config.ts +74 -424
- 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/rollup.ts +432 -167
- 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 +8 -0
- package/src/l1_tx_utils/config.ts +54 -13
- 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 +92 -45
- 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 +51 -49
- 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 +5 -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 -226
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1460
- 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 -1838
- 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';
|
|
@@ -27,9 +28,10 @@ import { jsonRpc } from 'viem/nonce';
|
|
|
27
28
|
import type { ViemClient } from '../types.js';
|
|
28
29
|
import { formatViemError } from '../utils.js';
|
|
29
30
|
import { type L1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
30
|
-
import {
|
|
31
|
+
import { MAX_L1_TX_LIMIT } from './constants.js';
|
|
31
32
|
import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
|
|
32
33
|
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
34
|
+
import { Delayer, createDelayer, wrapClientWithDelayer } from './tx_delayer.js';
|
|
33
35
|
import {
|
|
34
36
|
DroppedTransactionError,
|
|
35
37
|
type L1BlobInputs,
|
|
@@ -47,6 +49,10 @@ const MAX_L1_TX_STATES = 32;
|
|
|
47
49
|
export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
48
50
|
protected nonceManager: NonceManager;
|
|
49
51
|
protected txs: L1TxState[] = [];
|
|
52
|
+
/** Tx delayer for testing. Only set when enableDelayer config is true. */
|
|
53
|
+
public delayer?: Delayer;
|
|
54
|
+
/** KZG instance for blob operations. */
|
|
55
|
+
protected kzg?: BlobKzgInstance;
|
|
50
56
|
|
|
51
57
|
constructor(
|
|
52
58
|
public override client: ViemClient,
|
|
@@ -58,9 +64,26 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
58
64
|
debugMaxGasLimit: boolean = false,
|
|
59
65
|
protected store?: IL1TxStore,
|
|
60
66
|
protected metrics?: IL1TxMetrics,
|
|
67
|
+
kzg?: BlobKzgInstance,
|
|
68
|
+
delayer?: Delayer,
|
|
61
69
|
) {
|
|
62
70
|
super(client, logger, dateProvider, config, debugMaxGasLimit);
|
|
63
71
|
this.nonceManager = createNonceManager({ source: jsonRpc() });
|
|
72
|
+
this.kzg = kzg;
|
|
73
|
+
|
|
74
|
+
// Set up delayer: use provided one or create new
|
|
75
|
+
if (config?.enableDelayer && config?.ethereumSlotDuration) {
|
|
76
|
+
this.delayer =
|
|
77
|
+
delayer ?? this.createDelayer({ ethereumSlotDuration: config.ethereumSlotDuration }, logger.getBindings());
|
|
78
|
+
this.client = wrapClientWithDelayer(this.client, this.delayer);
|
|
79
|
+
if (config.txDelayerMaxInclusionTimeIntoSlot !== undefined) {
|
|
80
|
+
this.delayer.setMaxInclusionTimeIntoSlot(config.txDelayerMaxInclusionTimeIntoSlot);
|
|
81
|
+
}
|
|
82
|
+
} else if (delayer) {
|
|
83
|
+
// Delayer provided but enableDelayer not set — just store it without wrapping
|
|
84
|
+
logger.warn('Delayer provided but enableDelayer config is not set; delayer will not be used');
|
|
85
|
+
this.delayer = delayer;
|
|
86
|
+
}
|
|
64
87
|
}
|
|
65
88
|
|
|
66
89
|
public get state() {
|
|
@@ -130,12 +153,32 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
130
153
|
return;
|
|
131
154
|
}
|
|
132
155
|
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
|
|
156
|
+
// Clean up excess states if we have more than MAX_L1_TX_STATES
|
|
157
|
+
if (loadedStates.length > MAX_L1_TX_STATES) {
|
|
158
|
+
this.logger.warn(
|
|
159
|
+
`Found ${loadedStates.length} tx states for account ${account}, pruning to most recent ${MAX_L1_TX_STATES}`,
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
// Keep only the most recent MAX_L1_TX_STATES
|
|
163
|
+
const statesToKeep = loadedStates.slice(-MAX_L1_TX_STATES);
|
|
164
|
+
const statesToDelete = loadedStates.slice(0, -MAX_L1_TX_STATES);
|
|
165
|
+
|
|
166
|
+
// Batch delete old states in a transaction for efficiency
|
|
167
|
+
const idsToDelete = statesToDelete.map(s => s.id);
|
|
168
|
+
await this.store.deleteState(account, ...idsToDelete);
|
|
169
|
+
|
|
170
|
+
this.txs = statesToKeep;
|
|
171
|
+
this.logger.info(
|
|
172
|
+
`Cleaned up ${statesToDelete.length} old tx states, kept ${statesToKeep.length} for account ${account}`,
|
|
173
|
+
);
|
|
174
|
+
} else {
|
|
175
|
+
// Convert loaded states (which have id) to the txs format
|
|
176
|
+
this.txs = loadedStates;
|
|
177
|
+
this.logger.info(`Rehydrated ${loadedStates.length} tx states for account ${account}`);
|
|
178
|
+
}
|
|
136
179
|
|
|
137
180
|
// Find all pending states and resume monitoring
|
|
138
|
-
const pendingStates =
|
|
181
|
+
const pendingStates = this.txs.filter(state => !TerminalTxUtilsState.includes(state.status));
|
|
139
182
|
if (pendingStates.length === 0) {
|
|
140
183
|
return;
|
|
141
184
|
}
|
|
@@ -187,7 +230,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
187
230
|
|
|
188
231
|
let gasLimit: bigint;
|
|
189
232
|
if (this.debugMaxGasLimit) {
|
|
190
|
-
gasLimit =
|
|
233
|
+
gasLimit = MAX_L1_TX_LIMIT;
|
|
191
234
|
} else if (gasConfig.gasLimit) {
|
|
192
235
|
gasLimit = gasConfig.gasLimit;
|
|
193
236
|
} else {
|
|
@@ -201,6 +244,16 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
201
244
|
throw new InterruptError(`Transaction sending is interrupted`);
|
|
202
245
|
}
|
|
203
246
|
|
|
247
|
+
// Check timeout before consuming nonce to avoid leaking a nonce that was never sent.
|
|
248
|
+
// A leaked nonce creates a gap (e.g. nonce 107 consumed but unsent), so all subsequent
|
|
249
|
+
// transactions (108, 109, ...) can never be mined since the chain expects 107 first.
|
|
250
|
+
const now = new Date(await this.getL1Timestamp());
|
|
251
|
+
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
252
|
+
throw new TimeoutError(
|
|
253
|
+
`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
204
257
|
const nonce = await this.nonceManager.consume({
|
|
205
258
|
client: this.client,
|
|
206
259
|
address: account,
|
|
@@ -210,13 +263,6 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
210
263
|
const baseState = { request, gasLimit, blobInputs, gasPrice, nonce };
|
|
211
264
|
const txData = this.makeTxData(baseState, { isCancelTx: false });
|
|
212
265
|
|
|
213
|
-
const now = new Date(await this.getL1Timestamp());
|
|
214
|
-
if (gasConfig.txTimeoutAt && now > gasConfig.txTimeoutAt) {
|
|
215
|
-
throw new TimeoutError(
|
|
216
|
-
`Transaction timed out before sending (now ${now.toISOString()} > timeoutAt ${gasConfig.txTimeoutAt.toISOString()})`,
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
266
|
// Send the new tx
|
|
221
267
|
const signedRequest = await this.prepareSignedTransaction(txData);
|
|
222
268
|
const txHash = await this.client.sendRawTransaction({ serializedTransaction: signedRequest });
|
|
@@ -263,7 +309,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
263
309
|
return { txHash, state: l1TxState };
|
|
264
310
|
} catch (err: any) {
|
|
265
311
|
const viemError = formatViemError(err, request.abi);
|
|
266
|
-
this.logger.error(`Failed to send L1 transaction`, viemError, {
|
|
312
|
+
this.logger.error(`Failed to send L1 transaction: ${viemError.message}`, viemError, {
|
|
267
313
|
request: pick(request, 'to', 'value'),
|
|
268
314
|
});
|
|
269
315
|
throw viemError;
|
|
@@ -611,12 +657,12 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
611
657
|
from: request.from ?? this.getSenderAddress().toString(),
|
|
612
658
|
maxFeePerGas: gasPrice.maxFeePerGas,
|
|
613
659
|
maxPriorityFeePerGas: gasPrice.maxPriorityFeePerGas,
|
|
614
|
-
gas: request.gas ??
|
|
660
|
+
gas: request.gas ?? MAX_L1_TX_LIMIT,
|
|
615
661
|
};
|
|
616
662
|
|
|
617
663
|
if (!request.gas && !gasConfig.ignoreBlockGasLimit) {
|
|
618
|
-
//
|
|
619
|
-
blockOverrides.gasLimit =
|
|
664
|
+
// MAX_L1_TX_LIMIT is set as call.gas, ensure block gasLimit is sufficient
|
|
665
|
+
blockOverrides.gasLimit = MAX_L1_TX_LIMIT;
|
|
620
666
|
}
|
|
621
667
|
|
|
622
668
|
return this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
@@ -711,8 +757,17 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
|
711
757
|
return Number(timestamp) * 1000;
|
|
712
758
|
}
|
|
713
759
|
|
|
714
|
-
/** Makes empty blob inputs for the cancellation tx.
|
|
715
|
-
protected makeEmptyBlobInputs(
|
|
716
|
-
|
|
760
|
+
/** Makes empty blob inputs for the cancellation tx. */
|
|
761
|
+
protected makeEmptyBlobInputs(maxFeePerBlobGas: bigint): Required<L1BlobInputs> {
|
|
762
|
+
if (!this.kzg) {
|
|
763
|
+
throw new Error('Cannot make empty blob inputs for cancellation without kzg');
|
|
764
|
+
}
|
|
765
|
+
const blobData = new Uint8Array(131072).fill(0);
|
|
766
|
+
return { blobs: [blobData], kzg: this.kzg, maxFeePerBlobGas };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/** Creates a new delayer instance. */
|
|
770
|
+
protected createDelayer(opts: { ethereumSlotDuration: bigint | number }, bindings: LoggerBindings): Delayer {
|
|
771
|
+
return createDelayer(this.dateProvider, opts, bindings);
|
|
717
772
|
}
|
|
718
773
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
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,14 +27,18 @@ 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
|
|
|
39
|
+
// Change this to the current strategy we want to use
|
|
40
|
+
const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
|
|
41
|
+
|
|
36
42
|
export class ReadOnlyL1TxUtils {
|
|
37
43
|
public config: Required<L1TxUtilsConfig>;
|
|
38
44
|
protected interrupted = false;
|
|
@@ -63,6 +69,10 @@ export class ReadOnlyL1TxUtils {
|
|
|
63
69
|
return this.client.getBlockNumber();
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
public getCode(address: EthAddress): Promise<GetCodeReturnType> {
|
|
73
|
+
return this.client.getCode({ address: address.toString() });
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
/**
|
|
67
77
|
* Gets the current gas price with bounds checking
|
|
68
78
|
*/
|
|
@@ -73,39 +83,48 @@ export class ReadOnlyL1TxUtils {
|
|
|
73
83
|
previousGasPrice?: typeof attempt extends 0 ? never : GasPrice,
|
|
74
84
|
): Promise<GasPrice> {
|
|
75
85
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
|
|
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,
|
|
99
|
+
);
|
|
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) {
|
|
108
|
+
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
let priorityFee
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
}
|
|
105
124
|
}
|
|
106
125
|
let maxFeePerGas = baseFee;
|
|
107
126
|
|
|
108
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
127
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
109
128
|
|
|
110
129
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
111
130
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
@@ -115,6 +134,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
115
134
|
// same for blob gas fee
|
|
116
135
|
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
117
136
|
}
|
|
137
|
+
|
|
118
138
|
if (attempt > 0) {
|
|
119
139
|
const configBump =
|
|
120
140
|
gasConfig.priorityFeeRetryBumpPercentage ?? defaultL1TxUtilsConfig.priorityFeeRetryBumpPercentage!;
|
|
@@ -129,29 +149,50 @@ export class ReadOnlyL1TxUtils {
|
|
|
129
149
|
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
130
150
|
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
131
151
|
|
|
132
|
-
//
|
|
133
|
-
|
|
152
|
+
// Apply bump percentage to competitive fee
|
|
153
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
154
|
+
|
|
155
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
156
|
+
networkEstimate: formatGwei(priorityFee),
|
|
157
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
158
|
+
minRequired: formatGwei(minPriorityFee),
|
|
159
|
+
bumpPercentage: configBump,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Use maximum between competitive fee and minimum required bump
|
|
163
|
+
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
164
|
+
const feeSource = finalPriorityFee === competitivePriorityFee ? 'competitive' : 'minimum-bump';
|
|
134
165
|
|
|
135
|
-
|
|
136
|
-
|
|
166
|
+
priorityFee = finalPriorityFee;
|
|
167
|
+
// Add the final priority fee to maxFeePerGas
|
|
168
|
+
maxFeePerGas += finalPriorityFee;
|
|
137
169
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
170
|
+
|
|
171
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
172
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
173
|
+
});
|
|
138
174
|
} else {
|
|
139
|
-
//
|
|
175
|
+
// First attempt: apply configured bump percentage to competitive fee
|
|
140
176
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
177
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
178
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
179
|
+
networkEstimate: formatGwei(priorityFee),
|
|
180
|
+
});
|
|
144
181
|
maxFeePerGas += priorityFee;
|
|
145
182
|
}
|
|
146
183
|
|
|
184
|
+
// maxGwei and maxBlobGwei are hard limits
|
|
185
|
+
const effectiveMaxGwei = BigInt(Math.trunc(gasConfig.maxGwei! * Number(WEI_CONST)));
|
|
186
|
+
const effectiveMaxBlobGwei = BigInt(Math.trunc(gasConfig.maxBlobGwei! * Number(WEI_CONST)));
|
|
187
|
+
|
|
147
188
|
// Ensure we don't exceed maxGwei
|
|
148
|
-
|
|
149
|
-
|
|
189
|
+
if (effectiveMaxGwei > 0n) {
|
|
190
|
+
maxFeePerGas = maxFeePerGas > effectiveMaxGwei ? effectiveMaxGwei : maxFeePerGas;
|
|
191
|
+
}
|
|
150
192
|
|
|
151
193
|
// Ensure we don't exceed maxBlobGwei
|
|
152
|
-
if (maxFeePerBlobGas) {
|
|
153
|
-
|
|
154
|
-
maxFeePerBlobGas = maxFeePerBlobGas > maxBlobGweiInWei ? maxBlobGweiInWei : maxFeePerBlobGas;
|
|
194
|
+
if (maxFeePerBlobGas && effectiveMaxBlobGwei > 0n) {
|
|
195
|
+
maxFeePerBlobGas = maxFeePerBlobGas > effectiveMaxBlobGwei ? effectiveMaxBlobGwei : maxFeePerBlobGas;
|
|
155
196
|
}
|
|
156
197
|
|
|
157
198
|
// Ensure priority fee doesn't exceed max fee
|
|
@@ -177,7 +218,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
177
218
|
baseFee: formatGwei(baseFee),
|
|
178
219
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
179
220
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
180
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
221
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
181
222
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
182
223
|
},
|
|
183
224
|
);
|
|
@@ -208,12 +249,18 @@ export class ReadOnlyL1TxUtils {
|
|
|
208
249
|
...request,
|
|
209
250
|
..._blobInputs,
|
|
210
251
|
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas!,
|
|
211
|
-
gas:
|
|
252
|
+
gas: MAX_L1_TX_LIMIT,
|
|
253
|
+
blockTag: 'latest',
|
|
212
254
|
});
|
|
213
255
|
|
|
214
256
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
215
257
|
} else {
|
|
216
|
-
initialEstimate = await this.client.estimateGas({
|
|
258
|
+
initialEstimate = await this.client.estimateGas({
|
|
259
|
+
account,
|
|
260
|
+
...request,
|
|
261
|
+
gas: MAX_L1_TX_LIMIT,
|
|
262
|
+
blockTag: 'latest',
|
|
263
|
+
});
|
|
217
264
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
218
265
|
}
|
|
219
266
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { omit } from '@aztec/foundation/collection';
|
|
2
|
-
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
4
|
import type { DateProvider } from '@aztec/foundation/timer';
|
|
5
5
|
|
|
@@ -9,14 +9,18 @@ import {
|
|
|
9
9
|
type Hex,
|
|
10
10
|
type PublicClient,
|
|
11
11
|
type TransactionSerializableEIP4844,
|
|
12
|
+
type TransactionSerialized,
|
|
12
13
|
keccak256,
|
|
13
14
|
parseTransaction,
|
|
14
15
|
publicActions,
|
|
16
|
+
recoverTransactionAddress,
|
|
15
17
|
serializeTransaction,
|
|
16
18
|
walletActions,
|
|
17
19
|
} from 'viem';
|
|
18
20
|
|
|
19
|
-
import {
|
|
21
|
+
import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
|
|
22
|
+
|
|
23
|
+
const MAX_WAIT_TIME_SECONDS = 180;
|
|
20
24
|
|
|
21
25
|
export function waitUntilBlock<T extends Client>(
|
|
22
26
|
client: T,
|
|
@@ -36,7 +40,7 @@ export function waitUntilBlock<T extends Client>(
|
|
|
36
40
|
return currentBlockNumber >= BigInt(blockNumber);
|
|
37
41
|
},
|
|
38
42
|
`Wait until L1 block ${blockNumber}`,
|
|
39
|
-
timeout ??
|
|
43
|
+
timeout ?? MAX_WAIT_TIME_SECONDS,
|
|
40
44
|
0.1,
|
|
41
45
|
);
|
|
42
46
|
}
|
|
@@ -66,87 +70,103 @@ export function waitUntilL1Timestamp<T extends Client>(
|
|
|
66
70
|
return currentTs >= BigInt(timestamp);
|
|
67
71
|
},
|
|
68
72
|
`Wait until L1 timestamp ${timestamp}`,
|
|
69
|
-
timeout ??
|
|
73
|
+
timeout ?? MAX_WAIT_TIME_SECONDS,
|
|
70
74
|
0.1,
|
|
71
75
|
);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/** Delays the next tx to be sent indefinitely. */
|
|
84
|
-
cancelNextTx(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
87
|
-
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
88
|
-
* L1 slot but will be deferred for the next one.
|
|
89
|
-
*/
|
|
90
|
-
setMaxInclusionTimeIntoSlot(seconds: number | bigint | undefined): void;
|
|
91
|
-
}
|
|
78
|
+
/** Manages tx delaying for testing, intercepting sendRawTransaction calls to delay or cancel them. */
|
|
79
|
+
export class Delayer {
|
|
80
|
+
private logger: Logger;
|
|
81
|
+
|
|
82
|
+
public maxInclusionTimeIntoSlot: number | undefined = undefined;
|
|
83
|
+
public ethereumSlotDuration: bigint;
|
|
84
|
+
public nextWait: { l1Timestamp: bigint } | { l1BlockNumber: bigint } | { indefinitely: true } | undefined = undefined;
|
|
85
|
+
public sentTxHashes: Hex[] = [];
|
|
86
|
+
public cancelledTxs: Hex[] = [];
|
|
92
87
|
|
|
93
|
-
class DelayerImpl implements Delayer {
|
|
94
|
-
private logger = createLogger('ethereum:tx_delayer');
|
|
95
88
|
constructor(
|
|
96
89
|
public dateProvider: DateProvider,
|
|
97
90
|
opts: { ethereumSlotDuration: bigint | number },
|
|
91
|
+
bindings: LoggerBindings,
|
|
98
92
|
) {
|
|
99
93
|
this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
|
|
94
|
+
this.logger = createLogger('ethereum:tx_delayer', bindings);
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
public cancelledTxs: Hex[] = [];
|
|
97
|
+
/** Returns the logger instance used by this delayer. */
|
|
98
|
+
getLogger(): Logger {
|
|
99
|
+
return this.logger;
|
|
100
|
+
}
|
|
107
101
|
|
|
102
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
108
103
|
getSentTxHashes() {
|
|
109
104
|
return this.sentTxHashes;
|
|
110
105
|
}
|
|
111
106
|
|
|
107
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
112
108
|
getCancelledTxs(): Hex[] {
|
|
113
109
|
return this.cancelledTxs;
|
|
114
110
|
}
|
|
115
111
|
|
|
112
|
+
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
116
113
|
pauseNextTxUntilBlock(l1BlockNumber: number | bigint) {
|
|
117
114
|
this.nextWait = { l1BlockNumber: BigInt(l1BlockNumber) };
|
|
118
115
|
}
|
|
119
116
|
|
|
117
|
+
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
120
118
|
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint) {
|
|
121
119
|
this.nextWait = { l1Timestamp: BigInt(l1Timestamp) };
|
|
122
120
|
}
|
|
123
121
|
|
|
122
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
124
123
|
cancelNextTx() {
|
|
125
124
|
this.nextWait = { indefinitely: true };
|
|
126
125
|
}
|
|
127
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
129
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
130
|
+
* L1 slot but will be deferred for the next one.
|
|
131
|
+
*/
|
|
128
132
|
setMaxInclusionTimeIntoSlot(seconds: number | undefined) {
|
|
129
133
|
this.maxInclusionTimeIntoSlot = seconds;
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* TODO(#10824): This doesn't play along well with blob txs for some reason.
|
|
138
|
+
* Creates a new Delayer instance. Exposed so callers can create a single shared delayer
|
|
139
|
+
* and pass it to multiple `wrapClientWithDelayer` calls.
|
|
137
140
|
*/
|
|
138
|
-
export function
|
|
139
|
-
client: T,
|
|
141
|
+
export function createDelayer(
|
|
140
142
|
dateProvider: DateProvider,
|
|
141
143
|
opts: { ethereumSlotDuration: bigint | number },
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
bindings: LoggerBindings,
|
|
145
|
+
): Delayer {
|
|
146
|
+
return new Delayer(dateProvider, opts, bindings);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Tries to recover the sender address from a serialized signed transaction. */
|
|
150
|
+
async function tryRecoverSender(serializedTransaction: Hex): Promise<string | undefined> {
|
|
151
|
+
try {
|
|
152
|
+
return await recoverTransactionAddress({
|
|
153
|
+
serializedTransaction: serializedTransaction as TransactionSerialized,
|
|
154
|
+
});
|
|
155
|
+
} catch {
|
|
156
|
+
return undefined;
|
|
145
157
|
}
|
|
146
|
-
|
|
147
|
-
const delayer = new DelayerImpl(dateProvider, opts);
|
|
158
|
+
}
|
|
148
159
|
|
|
149
|
-
|
|
160
|
+
/**
|
|
161
|
+
* Wraps a viem client with tx delaying logic. Returns the wrapped client.
|
|
162
|
+
* The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
|
|
163
|
+
*/
|
|
164
|
+
export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T {
|
|
165
|
+
const logger = delayer.getLogger();
|
|
166
|
+
|
|
167
|
+
// Cast to ExtendedViemWalletClient for the extend chain since it has sendRawTransaction.
|
|
168
|
+
// The sendRawTransaction override is applied to all clients regardless of type.
|
|
169
|
+
const withRawTx = (client as unknown as ExtendedViemWalletClient)
|
|
150
170
|
// Tweak sendRawTransaction so it uses the delay defined in the delayer.
|
|
151
171
|
// Note that this will only work with local accounts (ie accounts for which we have the private key).
|
|
152
172
|
// Transactions signed by the node will not be delayed since they use sendTransaction directly,
|
|
@@ -158,6 +178,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
158
178
|
|
|
159
179
|
const { serializedTransaction } = args[0];
|
|
160
180
|
const publicClient = client as unknown as PublicClient;
|
|
181
|
+
const sender = await tryRecoverSender(serializedTransaction);
|
|
161
182
|
|
|
162
183
|
if (delayer.nextWait !== undefined) {
|
|
163
184
|
// Check if we have been instructed to delay the next tx.
|
|
@@ -169,7 +190,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
169
190
|
|
|
170
191
|
// Cancel tx outright if instructed
|
|
171
192
|
if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
|
|
172
|
-
logger.info(`Cancelling tx ${txHash}
|
|
193
|
+
logger.info(`Cancelling tx ${txHash}`, { sender });
|
|
173
194
|
delayer.cancelledTxs.push(serializedTransaction);
|
|
174
195
|
return Promise.resolve(txHash);
|
|
175
196
|
}
|
|
@@ -183,6 +204,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
183
204
|
: undefined;
|
|
184
205
|
|
|
185
206
|
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
|
|
207
|
+
sender,
|
|
186
208
|
argsLen: args.length,
|
|
187
209
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
188
210
|
});
|
|
@@ -194,6 +216,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
194
216
|
|
|
195
217
|
txHash = computeTxHash(serializedTransaction);
|
|
196
218
|
const logData = {
|
|
219
|
+
sender,
|
|
197
220
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
198
221
|
lastBlockTimestamp,
|
|
199
222
|
now,
|
|
@@ -223,28 +246,35 @@ export function withDelayer<T extends ViemClient>(
|
|
|
223
246
|
computedTxHash: txHash,
|
|
224
247
|
});
|
|
225
248
|
}
|
|
226
|
-
logger.info(`Sent previously delayed tx ${clientTxHash}
|
|
249
|
+
logger.info(`Sent previously delayed tx ${clientTxHash}`, { sender });
|
|
227
250
|
delayer.sentTxHashes.push(clientTxHash);
|
|
228
251
|
})
|
|
229
252
|
.catch(err => logger.error(`Error sending tx after delay`, err));
|
|
230
253
|
return Promise.resolve(txHash!);
|
|
231
254
|
} else {
|
|
232
255
|
const txHash = await client.sendRawTransaction(...args);
|
|
233
|
-
logger.
|
|
256
|
+
logger.debug(`Sent tx immediately ${txHash}`, { sender });
|
|
234
257
|
delayer.sentTxHashes.push(txHash);
|
|
235
258
|
return txHash;
|
|
236
259
|
}
|
|
237
260
|
},
|
|
238
|
-
}))
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
261
|
+
}));
|
|
262
|
+
|
|
263
|
+
// Only re-bind wallet actions (sendTransaction, writeContract, deployContract) for wallet clients.
|
|
264
|
+
// This is needed for tests that use wallet actions directly rather than sendRawTransaction.
|
|
265
|
+
const isWalletClient = 'account' in client && client.account !== undefined;
|
|
266
|
+
const extended = isWalletClient
|
|
267
|
+
? withRawTx
|
|
268
|
+
// Re-extend with sendTransaction so it uses the modified sendRawTransaction.
|
|
269
|
+
.extend(client => ({ sendTransaction: walletActions(client).sendTransaction }))
|
|
270
|
+
// And with the actions that depend on the modified sendTransaction
|
|
271
|
+
.extend(client => ({
|
|
272
|
+
writeContract: walletActions(client).writeContract,
|
|
273
|
+
deployContract: walletActions(client).deployContract,
|
|
274
|
+
}))
|
|
275
|
+
: withRawTx;
|
|
246
276
|
|
|
247
|
-
return
|
|
277
|
+
return extended as T;
|
|
248
278
|
}
|
|
249
279
|
|
|
250
280
|
/**
|