@aztec/ethereum 0.0.1-commit.d3ec352c → 0.0.1-commit.d58ff9d0
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.d.ts +25 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +60 -4
- package/dest/config.d.ts +45 -73
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +114 -386
- package/dest/contracts/chain_state_override.d.ts +78 -0
- package/dest/contracts/chain_state_override.d.ts.map +1 -0
- package/dest/contracts/chain_state_override.js +137 -0
- package/dest/contracts/empire_base.d.ts +2 -1
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.d.ts +6 -5
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- package/dest/contracts/fee_asset_handler.js +11 -9
- package/dest/contracts/fee_asset_price_oracle.d.ts +105 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +656 -0
- package/dest/contracts/governance.d.ts +110 -33
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +207 -16
- package/dest/contracts/governance_proposer.d.ts +34 -1
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +447 -10
- package/dest/contracts/gse.d.ts +4 -2
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/gse.js +2 -2
- package/dest/contracts/inbox.d.ts +24 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +42 -2
- package/dest/contracts/index.d.ts +6 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +5 -2
- package/dest/contracts/log.d.ts +13 -0
- package/dest/contracts/log.d.ts.map +1 -0
- package/dest/contracts/log.js +1 -0
- package/dest/contracts/multicall.d.ts +130 -13
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +203 -93
- package/dest/contracts/outbox.d.ts +64 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +113 -0
- package/dest/contracts/registry.d.ts +3 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +30 -1
- package/dest/contracts/rollup.d.ts +5571 -102
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1076 -192
- package/dest/contracts/{tally_slashing_proposer.d.ts → slashing_proposer.d.ts} +5 -5
- package/dest/contracts/slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/{tally_slashing_proposer.js → slashing_proposer.js} +18 -13
- package/dest/deploy_aztec_l1_contracts.d.ts +267 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +424 -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/foundry_binary.d.ts +13 -0
- package/dest/foundry_binary.d.ts.map +1 -0
- package/dest/foundry_binary.js +52 -0
- package/dest/l1_artifacts.d.ts +19674 -16606
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +9 -24
- package/dest/l1_contract_addresses.d.ts +61 -65
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +99 -80
- package/dest/l1_reader.d.ts +7 -5
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +15 -7
- package/dest/l1_tx_utils/config.d.ts +9 -3
- package/dest/l1_tx_utils/config.d.ts.map +1 -1
- package/dest/l1_tx_utils/config.js +34 -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 +252 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_fee_analyzer.js +568 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts +26 -7
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -1
- package/dest/l1_tx_utils/l1_tx_utils.js +202 -92
- 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 +63 -165
- package/dest/l1_tx_utils/tx_delayer.d.ts +58 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/{test → l1_tx_utils}/tx_delayer.js +70 -39
- package/dest/l1_tx_utils/types.d.ts +27 -1
- package/dest/l1_tx_utils/types.d.ts.map +1 -1
- package/dest/l1_tx_utils/types.js +10 -0
- package/dest/publisher_manager.d.ts +34 -7
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +119 -8
- package/dest/queries.d.ts +14 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +80 -7
- package/dest/test/blob_kzg_warmup.d.ts +19 -0
- package/dest/test/blob_kzg_warmup.d.ts.map +1 -0
- package/dest/test/blob_kzg_warmup.js +64 -0
- package/dest/test/chain_monitor.d.ts +55 -4
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +105 -5
- package/dest/test/eth_cheat_codes.d.ts +49 -6
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +93 -43
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +1 -2
- package/dest/test/rollup_cheat_codes.d.ts +64 -4
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +109 -8
- package/dest/test/start_anvil.d.ts +24 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +182 -32
- package/dest/test/upgrade_utils.js +2 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +24 -4
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +112 -16
- package/package.json +31 -15
- package/src/client.ts +66 -2
- package/src/config.ts +153 -469
- package/src/contracts/README.md +157 -0
- package/src/contracts/chain_state_override.ts +200 -0
- package/src/contracts/empire_base.ts +1 -1
- package/src/contracts/fee_asset_handler.ts +10 -7
- package/src/contracts/fee_asset_price_oracle.ts +285 -0
- package/src/contracts/governance.ts +279 -13
- package/src/contracts/governance_proposer.ts +64 -3
- package/src/contracts/gse.ts +7 -2
- package/src/contracts/inbox.ts +64 -4
- package/src/contracts/index.ts +5 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +247 -103
- package/src/contracts/outbox.ts +132 -0
- package/src/contracts/registry.ts +31 -1
- package/src/contracts/rollup.ts +789 -154
- package/src/contracts/{tally_slashing_proposer.ts → slashing_proposer.ts} +18 -14
- package/src/deploy_aztec_l1_contracts.ts +664 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/foundry_binary.ts +57 -0
- package/src/l1_artifacts.ts +12 -35
- package/src/l1_contract_addresses.ts +120 -92
- package/src/l1_reader.ts +25 -10
- package/src/l1_tx_utils/config.ts +47 -9
- 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 +875 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +194 -72
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +77 -211
- package/src/{test → l1_tx_utils}/tx_delayer.ts +97 -58
- package/src/l1_tx_utils/types.ts +32 -0
- package/src/publisher_manager.ts +145 -12
- package/src/queries.ts +87 -7
- package/src/test/blob_kzg_warmup.ts +65 -0
- package/src/test/chain_monitor.ts +150 -4
- package/src/test/eth_cheat_codes.ts +84 -47
- package/src/test/index.ts +1 -2
- package/src/test/rollup_cheat_codes.ts +136 -8
- package/src/test/start_anvil.ts +213 -31
- package/src/test/upgrade_utils.ts +2 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +128 -19
- package/dest/contracts/empire_slashing_proposer.d.ts +0 -66
- package/dest/contracts/empire_slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/empire_slashing_proposer.js +0 -200
- package/dest/contracts/tally_slashing_proposer.d.ts.map +0 -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/contracts/empire_slashing_proposer.ts +0 -265
- 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
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { getKeys,
|
|
1
|
+
import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
4
5
|
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
+
import { getErrorCause } from '@aztec/foundation/types';
|
|
5
7
|
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
6
8
|
|
|
7
9
|
import pickBy from 'lodash.pickby';
|
|
@@ -11,6 +13,7 @@ import {
|
|
|
11
13
|
type BaseError,
|
|
12
14
|
type BlockOverrides,
|
|
13
15
|
type ContractFunctionExecutionError,
|
|
16
|
+
type GetCodeReturnType,
|
|
14
17
|
type Hex,
|
|
15
18
|
MethodNotFoundRpcError,
|
|
16
19
|
MethodNotSupportedRpcError,
|
|
@@ -25,15 +28,17 @@ import type { ViemClient } from '../types.js';
|
|
|
25
28
|
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
26
29
|
import {
|
|
27
30
|
BLOCK_TIME_MS,
|
|
28
|
-
|
|
31
|
+
MAX_L1_TX_LIMIT,
|
|
29
32
|
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
30
33
|
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
31
34
|
WEI_CONST,
|
|
32
35
|
} from './constants.js';
|
|
36
|
+
import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
|
|
33
37
|
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
34
38
|
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
// Change this to the current strategy we want to use
|
|
41
|
+
const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
|
|
37
42
|
|
|
38
43
|
export class ReadOnlyL1TxUtils {
|
|
39
44
|
public config: Required<L1TxUtilsConfig>;
|
|
@@ -65,122 +70,8 @@ export class ReadOnlyL1TxUtils {
|
|
|
65
70
|
return this.client.getBlockNumber();
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* Falls back to network estimate if data is unavailable or fails.
|
|
71
|
-
* @param networkEstimateResult - Result from estimateMaxPriorityFeePerGas RPC call
|
|
72
|
-
* @param pendingBlockResult - Result from getBlock with pending tag RPC call
|
|
73
|
-
* @param feeHistoryResult - Result from getFeeHistory RPC call
|
|
74
|
-
* @returns A competitive priority fee based on pending txs and recent block history
|
|
75
|
-
*/
|
|
76
|
-
protected getCompetitivePriorityFee(
|
|
77
|
-
networkEstimateResult: PromiseSettledResult<bigint | null>,
|
|
78
|
-
pendingBlockResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getBlock']>> | null>,
|
|
79
|
-
feeHistoryResult: PromiseSettledResult<Awaited<ReturnType<ViemClient['getFeeHistory']>> | null>,
|
|
80
|
-
): bigint {
|
|
81
|
-
const networkEstimate =
|
|
82
|
-
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
83
|
-
? networkEstimateResult.value
|
|
84
|
-
: 0n;
|
|
85
|
-
let competitiveFee = networkEstimate;
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
pendingBlockResult.status === 'fulfilled' &&
|
|
89
|
-
pendingBlockResult.value !== null &&
|
|
90
|
-
pendingBlockResult.value.transactions &&
|
|
91
|
-
pendingBlockResult.value.transactions.length > 0
|
|
92
|
-
) {
|
|
93
|
-
const pendingBlock = pendingBlockResult.value;
|
|
94
|
-
// Extract priority fees from pending transactions
|
|
95
|
-
const pendingFees = pendingBlock.transactions
|
|
96
|
-
.map(tx => {
|
|
97
|
-
// Transaction can be just a hash string, so we need to check if it's an object
|
|
98
|
-
if (typeof tx === 'string') {
|
|
99
|
-
return 0n;
|
|
100
|
-
}
|
|
101
|
-
const fee = tx.maxPriorityFeePerGas || 0n;
|
|
102
|
-
// Debug: Log suspicious fees
|
|
103
|
-
if (fee > 100n * WEI_CONST) {
|
|
104
|
-
this.logger?.warn('Suspicious high priority fee in pending tx', {
|
|
105
|
-
txHash: tx.hash,
|
|
106
|
-
maxPriorityFeePerGas: formatGwei(fee),
|
|
107
|
-
maxFeePerGas: formatGwei(tx.maxFeePerGas || 0n),
|
|
108
|
-
maxFeePerBlobGas: tx.maxFeePerBlobGas ? formatGwei(tx.maxFeePerBlobGas) : 'N/A',
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return fee;
|
|
112
|
-
})
|
|
113
|
-
.filter((fee: bigint) => fee > 0n);
|
|
114
|
-
|
|
115
|
-
if (pendingFees.length > 0) {
|
|
116
|
-
// Use 75th percentile of pending fees to be competitive
|
|
117
|
-
const sortedPendingFees = [...pendingFees].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
118
|
-
const percentile75Index = Math.floor((sortedPendingFees.length - 1) * 0.75);
|
|
119
|
-
const pendingCompetitiveFee = sortedPendingFees[percentile75Index];
|
|
120
|
-
|
|
121
|
-
if (pendingCompetitiveFee > competitiveFee) {
|
|
122
|
-
competitiveFee = pendingCompetitiveFee;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
126
|
-
pendingTxCount: pendingFees.length,
|
|
127
|
-
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (
|
|
132
|
-
feeHistoryResult.status === 'fulfilled' &&
|
|
133
|
-
feeHistoryResult.value !== null &&
|
|
134
|
-
feeHistoryResult.value.reward &&
|
|
135
|
-
feeHistoryResult.value.reward.length > 0
|
|
136
|
-
) {
|
|
137
|
-
const feeHistory = feeHistoryResult.value;
|
|
138
|
-
// Extract 75th percentile fees from each block
|
|
139
|
-
const percentile75Fees = feeHistory.reward!.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
140
|
-
|
|
141
|
-
if (percentile75Fees.length > 0) {
|
|
142
|
-
// Calculate median of the 75th percentile fees across blocks
|
|
143
|
-
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
144
|
-
|
|
145
|
-
// Debug: Log suspicious fees from history
|
|
146
|
-
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
147
|
-
this.logger?.warn('Suspicious high fee in history', {
|
|
148
|
-
historicalMedian: formatGwei(medianHistoricalFee),
|
|
149
|
-
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (medianHistoricalFee > competitiveFee) {
|
|
154
|
-
competitiveFee = medianHistoricalFee;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.logger?.debug('Analyzed fee history for competitive pricing', {
|
|
158
|
-
historicalMedian: formatGwei(medianHistoricalFee),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Sanity check: cap competitive fee at 100x network estimate to avoid using unrealistic fees
|
|
164
|
-
// (e.g., Anvil returns inflated historical fees that don't reflect actual network conditions)
|
|
165
|
-
const maxReasonableFee = networkEstimate * 100n;
|
|
166
|
-
if (competitiveFee > maxReasonableFee) {
|
|
167
|
-
this.logger?.warn('Competitive fee exceeds sanity cap, using capped value', {
|
|
168
|
-
competitiveFee: formatGwei(competitiveFee),
|
|
169
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
170
|
-
cappedTo: formatGwei(maxReasonableFee),
|
|
171
|
-
});
|
|
172
|
-
competitiveFee = maxReasonableFee;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Log final decision
|
|
176
|
-
if (competitiveFee > networkEstimate) {
|
|
177
|
-
this.logger?.debug('Using competitive fee from market analysis', {
|
|
178
|
-
networkEstimate: formatGwei(networkEstimate),
|
|
179
|
-
competitive: formatGwei(competitiveFee),
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return competitiveFee;
|
|
73
|
+
public getCode(address: EthAddress): Promise<GetCodeReturnType> {
|
|
74
|
+
return this.client.getCode({ address: address.toString() });
|
|
184
75
|
}
|
|
185
76
|
|
|
186
77
|
/**
|
|
@@ -194,76 +85,56 @@ export class ReadOnlyL1TxUtils {
|
|
|
194
85
|
): Promise<GasPrice> {
|
|
195
86
|
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
196
87
|
|
|
197
|
-
//
|
|
198
|
-
const
|
|
199
|
-
() =>
|
|
200
|
-
|
|
88
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
89
|
+
const strategyResult = await retry(
|
|
90
|
+
() =>
|
|
91
|
+
CurrentStrategy.execute(this.client, {
|
|
92
|
+
gasConfig,
|
|
93
|
+
isBlobTx,
|
|
94
|
+
logger: this.logger,
|
|
95
|
+
}),
|
|
96
|
+
'Executing priority fee strategy',
|
|
97
|
+
makeBackoff(times(2, () => 0)),
|
|
98
|
+
this.logger,
|
|
99
|
+
true,
|
|
201
100
|
);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
211
|
-
const feeHistoryPromise = gasConfig.fixedPriorityFeePerGas
|
|
212
|
-
? null
|
|
213
|
-
: this.tryTwice(
|
|
214
|
-
() => this.client.getFeeHistory({ blockCount: HISTORICAL_BLOCK_COUNT, rewardPercentiles: [75] }),
|
|
215
|
-
'Getting fee history',
|
|
216
|
-
);
|
|
217
|
-
const blobBaseFeePromise = isBlobTx
|
|
218
|
-
? this.tryTwice(() => this.client.getBlobBaseFee(), 'Getting blob base fee')
|
|
219
|
-
: null;
|
|
220
|
-
|
|
221
|
-
const [latestBlockResult, networkEstimateResult, pendingBlockResult, feeHistoryResult, blobBaseFeeResult] =
|
|
222
|
-
await Promise.allSettled([
|
|
223
|
-
latestBlockPromise,
|
|
224
|
-
networkEstimatePromise ?? Promise.resolve(0n),
|
|
225
|
-
pendingBlockPromise ?? Promise.resolve(null),
|
|
226
|
-
feeHistoryPromise ?? Promise.resolve(null),
|
|
227
|
-
blobBaseFeePromise ?? Promise.resolve(0n),
|
|
228
|
-
]);
|
|
229
|
-
|
|
230
|
-
// Extract results
|
|
231
|
-
const baseFee =
|
|
232
|
-
latestBlockResult.status === 'fulfilled' &&
|
|
233
|
-
typeof latestBlockResult.value === 'object' &&
|
|
234
|
-
latestBlockResult.value.baseFeePerGas
|
|
235
|
-
? latestBlockResult.value.baseFeePerGas
|
|
236
|
-
: 0n;
|
|
237
|
-
|
|
238
|
-
// Get blob base fee if available
|
|
239
|
-
let blobBaseFee = 0n;
|
|
240
|
-
if (isBlobTx && blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
241
|
-
blobBaseFee = blobBaseFeeResult.value;
|
|
242
|
-
} else if (isBlobTx) {
|
|
101
|
+
|
|
102
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
103
|
+
|
|
104
|
+
// Extract base fee from latest block
|
|
105
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
106
|
+
|
|
107
|
+
// Handle blob base fee
|
|
108
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
243
109
|
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
244
110
|
}
|
|
245
111
|
|
|
246
|
-
let priorityFee
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
112
|
+
let priorityFee = strategyPriorityFee;
|
|
113
|
+
|
|
114
|
+
// Apply minimum priority fee floor if configured
|
|
115
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
116
|
+
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
117
|
+
if (priorityFee < minimumPriorityFee) {
|
|
118
|
+
this.logger?.debug('Applying minimum priority fee floor', {
|
|
119
|
+
calculatedPriorityFee: formatGwei(priorityFee),
|
|
120
|
+
minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
|
|
121
|
+
appliedFee: formatGwei(minimumPriorityFee),
|
|
122
|
+
});
|
|
123
|
+
priorityFee = minimumPriorityFee;
|
|
124
|
+
}
|
|
255
125
|
}
|
|
256
126
|
let maxFeePerGas = baseFee;
|
|
257
127
|
|
|
258
|
-
let maxFeePerBlobGas = blobBaseFee;
|
|
128
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
259
129
|
|
|
260
130
|
// Bump base fee so it's valid for next blocks if it stalls
|
|
261
131
|
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
262
132
|
for (let i = 0; i < numBlocks; i++) {
|
|
263
133
|
// each block can go up 12.5% from previous baseFee
|
|
264
|
-
|
|
134
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
135
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
265
136
|
// same for blob gas fee
|
|
266
|
-
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n)) / 1_000n;
|
|
137
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
267
138
|
}
|
|
268
139
|
|
|
269
140
|
if (attempt > 0) {
|
|
@@ -280,18 +151,15 @@ export class ReadOnlyL1TxUtils {
|
|
|
280
151
|
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
281
152
|
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
282
153
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
// Apply bump percentage to competitive fee
|
|
286
|
-
competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
154
|
+
// Apply bump percentage to competitive fee
|
|
155
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
287
156
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
157
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
158
|
+
networkEstimate: formatGwei(priorityFee),
|
|
159
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
160
|
+
minRequired: formatGwei(minPriorityFee),
|
|
161
|
+
bumpPercentage: configBump,
|
|
162
|
+
});
|
|
295
163
|
|
|
296
164
|
// Use maximum between competitive fee and minimum required bump
|
|
297
165
|
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
@@ -302,20 +170,16 @@ export class ReadOnlyL1TxUtils {
|
|
|
302
170
|
maxFeePerGas += finalPriorityFee;
|
|
303
171
|
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
304
172
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
});
|
|
309
|
-
}
|
|
173
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
174
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
175
|
+
});
|
|
310
176
|
} else {
|
|
311
177
|
// First attempt: apply configured bump percentage to competitive fee
|
|
312
178
|
// multiply by 100 & divide by 100 to maintain some precision
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
});
|
|
318
|
-
}
|
|
179
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
180
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
181
|
+
networkEstimate: formatGwei(priorityFee),
|
|
182
|
+
});
|
|
319
183
|
maxFeePerGas += priorityFee;
|
|
320
184
|
}
|
|
321
185
|
|
|
@@ -356,7 +220,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
356
220
|
baseFee: formatGwei(baseFee),
|
|
357
221
|
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
358
222
|
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
359
|
-
blobBaseFee: formatGwei(blobBaseFee),
|
|
223
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
360
224
|
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
361
225
|
},
|
|
362
226
|
);
|
|
@@ -380,19 +244,28 @@ export class ReadOnlyL1TxUtils {
|
|
|
380
244
|
const gasConfig = { ...this.config, ..._gasConfig };
|
|
381
245
|
let initialEstimate = 0n;
|
|
382
246
|
if (_blobInputs) {
|
|
383
|
-
// @note requests with blobs also require maxFeePerBlobGas to be set
|
|
247
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
248
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
249
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
250
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
384
251
|
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
385
252
|
initialEstimate = await this.client.estimateGas({
|
|
386
253
|
account,
|
|
387
254
|
...request,
|
|
388
255
|
..._blobInputs,
|
|
389
|
-
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas
|
|
390
|
-
gas:
|
|
256
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
257
|
+
gas: MAX_L1_TX_LIMIT,
|
|
258
|
+
blockTag: 'latest',
|
|
391
259
|
});
|
|
392
260
|
|
|
393
261
|
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
394
262
|
} else {
|
|
395
|
-
initialEstimate = await this.client.estimateGas({
|
|
263
|
+
initialEstimate = await this.client.estimateGas({
|
|
264
|
+
account,
|
|
265
|
+
...request,
|
|
266
|
+
gas: MAX_L1_TX_LIMIT,
|
|
267
|
+
blockTag: 'latest',
|
|
268
|
+
});
|
|
396
269
|
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
397
270
|
}
|
|
398
271
|
|
|
@@ -523,7 +396,7 @@ export class ReadOnlyL1TxUtils {
|
|
|
523
396
|
this.logger?.debug(`L1 transaction simulation succeeded`, { ...result[0].calls[0] });
|
|
524
397
|
return { gasUsed: result[0].gasUsed, result: result[0].calls[0].data as `0x${string}` };
|
|
525
398
|
} catch (err) {
|
|
526
|
-
if (err
|
|
399
|
+
if (getErrorCause(err, MethodNotFoundRpcError) || getErrorCause(err, MethodNotSupportedRpcError)) {
|
|
527
400
|
if (gasConfig.fallbackGasEstimate) {
|
|
528
401
|
this.logger?.warn(
|
|
529
402
|
`Node does not support eth_simulateV1 API. Using fallback gas estimate: ${gasConfig.fallbackGasEstimate}`,
|
|
@@ -548,11 +421,4 @@ export class ReadOnlyL1TxUtils {
|
|
|
548
421
|
});
|
|
549
422
|
return bumpedGasLimit;
|
|
550
423
|
}
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* Helper function to retry RPC calls twice
|
|
554
|
-
*/
|
|
555
|
-
private tryTwice<T>(fn: () => Promise<T>, description: string): Promise<T> {
|
|
556
|
-
return retry<T>(fn, description, makeBackoff(times(2, () => 0)), this.logger, true);
|
|
557
|
-
}
|
|
558
424
|
}
|
|
@@ -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,107 @@ 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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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:
|
|
85
|
+
| { l1Timestamp: bigint; timeoutSeconds?: number }
|
|
86
|
+
| { l1BlockNumber: bigint; timeoutSeconds?: number }
|
|
87
|
+
| { indefinitely: true }
|
|
88
|
+
| undefined = undefined;
|
|
89
|
+
public sentTxHashes: Hex[] = [];
|
|
90
|
+
public cancelledTxs: Hex[] = [];
|
|
92
91
|
|
|
93
|
-
class DelayerImpl implements Delayer {
|
|
94
|
-
private logger = createLogger('ethereum:tx_delayer');
|
|
95
92
|
constructor(
|
|
96
93
|
public dateProvider: DateProvider,
|
|
97
94
|
opts: { ethereumSlotDuration: bigint | number },
|
|
95
|
+
bindings: LoggerBindings,
|
|
98
96
|
) {
|
|
99
97
|
this.ethereumSlotDuration = BigInt(opts.ethereumSlotDuration);
|
|
98
|
+
this.logger = createLogger('ethereum:tx_delayer', bindings);
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
public cancelledTxs: Hex[] = [];
|
|
101
|
+
/** Returns the logger instance used by this delayer. */
|
|
102
|
+
getLogger(): Logger {
|
|
103
|
+
return this.logger;
|
|
104
|
+
}
|
|
107
105
|
|
|
106
|
+
/** Returns the hashes of all effectively sent txs. */
|
|
108
107
|
getSentTxHashes() {
|
|
109
108
|
return this.sentTxHashes;
|
|
110
109
|
}
|
|
111
110
|
|
|
111
|
+
/** Returns the raw hex for all cancelled txs. */
|
|
112
112
|
getCancelledTxs(): Hex[] {
|
|
113
113
|
return this.cancelledTxs;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
/** Delays the next tx to be sent so it lands on the given L1 block number. */
|
|
117
|
+
pauseNextTxUntilBlock(l1BlockNumber: number | bigint, timeoutSeconds?: number) {
|
|
118
|
+
this.nextWait = { l1BlockNumber: BigInt(l1BlockNumber), timeoutSeconds };
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
|
|
121
|
+
/** Delays the next tx to be sent so it lands on the given timestamp. */
|
|
122
|
+
pauseNextTxUntilTimestamp(l1Timestamp: number | bigint, timeoutSeconds?: number) {
|
|
123
|
+
this.nextWait = { l1Timestamp: BigInt(l1Timestamp), timeoutSeconds };
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
/** Delays the next tx to be sent indefinitely. */
|
|
124
127
|
cancelNextTx() {
|
|
125
128
|
this.nextWait = { indefinitely: true };
|
|
126
129
|
}
|
|
127
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Sets max inclusion time into slot. If more than this many seconds have passed
|
|
133
|
+
* since the last L1 block was mined, then any tx will not be mined in the current
|
|
134
|
+
* L1 slot but will be deferred for the next one.
|
|
135
|
+
*/
|
|
128
136
|
setMaxInclusionTimeIntoSlot(seconds: number | undefined) {
|
|
129
137
|
this.maxInclusionTimeIntoSlot = seconds;
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
|
|
133
141
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* TODO(#10824): This doesn't play along well with blob txs for some reason.
|
|
142
|
+
* Creates a new Delayer instance. Exposed so callers can create a single shared delayer
|
|
143
|
+
* and pass it to multiple `wrapClientWithDelayer` calls.
|
|
137
144
|
*/
|
|
138
|
-
export function
|
|
139
|
-
client: T,
|
|
145
|
+
export function createDelayer(
|
|
140
146
|
dateProvider: DateProvider,
|
|
141
147
|
opts: { ethereumSlotDuration: bigint | number },
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
bindings: LoggerBindings,
|
|
149
|
+
): Delayer {
|
|
150
|
+
return new Delayer(dateProvider, opts, bindings);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Tries to recover the sender address from a serialized signed transaction. */
|
|
154
|
+
async function tryRecoverSender(serializedTransaction: Hex): Promise<string | undefined> {
|
|
155
|
+
try {
|
|
156
|
+
return await recoverTransactionAddress({
|
|
157
|
+
serializedTransaction: serializedTransaction as TransactionSerialized,
|
|
158
|
+
});
|
|
159
|
+
} catch {
|
|
160
|
+
return undefined;
|
|
145
161
|
}
|
|
146
|
-
|
|
147
|
-
const delayer = new DelayerImpl(dateProvider, opts);
|
|
162
|
+
}
|
|
148
163
|
|
|
149
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Wraps a viem client with tx delaying logic. Returns the wrapped client.
|
|
166
|
+
* The delayer intercepts sendRawTransaction calls and delays them based on the delayer's state.
|
|
167
|
+
*/
|
|
168
|
+
export function wrapClientWithDelayer<T extends ViemClient>(client: T, delayer: Delayer): T {
|
|
169
|
+
const logger = delayer.getLogger();
|
|
170
|
+
|
|
171
|
+
// Cast to ExtendedViemWalletClient for the extend chain since it has sendRawTransaction.
|
|
172
|
+
// The sendRawTransaction override is applied to all clients regardless of type.
|
|
173
|
+
const withRawTx = (client as unknown as ExtendedViemWalletClient)
|
|
150
174
|
// Tweak sendRawTransaction so it uses the delay defined in the delayer.
|
|
151
175
|
// Note that this will only work with local accounts (ie accounts for which we have the private key).
|
|
152
176
|
// Transactions signed by the node will not be delayed since they use sendTransaction directly,
|
|
@@ -158,6 +182,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
158
182
|
|
|
159
183
|
const { serializedTransaction } = args[0];
|
|
160
184
|
const publicClient = client as unknown as PublicClient;
|
|
185
|
+
const sender = await tryRecoverSender(serializedTransaction);
|
|
161
186
|
|
|
162
187
|
if (delayer.nextWait !== undefined) {
|
|
163
188
|
// Check if we have been instructed to delay the next tx.
|
|
@@ -169,7 +194,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
169
194
|
|
|
170
195
|
// Cancel tx outright if instructed
|
|
171
196
|
if ('indefinitely' in waitUntil && waitUntil.indefinitely) {
|
|
172
|
-
logger.info(`Cancelling tx ${txHash}
|
|
197
|
+
logger.info(`Cancelling tx ${txHash}`, { sender });
|
|
173
198
|
delayer.cancelledTxs.push(serializedTransaction);
|
|
174
199
|
return Promise.resolve(txHash);
|
|
175
200
|
}
|
|
@@ -177,12 +202,18 @@ export function withDelayer<T extends ViemClient>(
|
|
|
177
202
|
// Or wait until the desired block number or timestamp
|
|
178
203
|
wait =
|
|
179
204
|
'l1BlockNumber' in waitUntil
|
|
180
|
-
? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger)
|
|
205
|
+
? waitUntilBlock(publicClient, waitUntil.l1BlockNumber - 1n, logger, waitUntil.timeoutSeconds)
|
|
181
206
|
: 'l1Timestamp' in waitUntil
|
|
182
|
-
? waitUntilL1Timestamp(
|
|
207
|
+
? waitUntilL1Timestamp(
|
|
208
|
+
publicClient,
|
|
209
|
+
waitUntil.l1Timestamp - delayer.ethereumSlotDuration,
|
|
210
|
+
logger,
|
|
211
|
+
waitUntil.timeoutSeconds,
|
|
212
|
+
)
|
|
183
213
|
: undefined;
|
|
184
214
|
|
|
185
215
|
logger.info(`Delaying tx ${txHash} until ${inspect(waitUntil)}`, {
|
|
216
|
+
sender,
|
|
186
217
|
argsLen: args.length,
|
|
187
218
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
188
219
|
});
|
|
@@ -194,6 +225,7 @@ export function withDelayer<T extends ViemClient>(
|
|
|
194
225
|
|
|
195
226
|
txHash = computeTxHash(serializedTransaction);
|
|
196
227
|
const logData = {
|
|
228
|
+
sender,
|
|
197
229
|
...omit(parseTransaction(serializedTransaction), 'data', 'sidecars'),
|
|
198
230
|
lastBlockTimestamp,
|
|
199
231
|
now,
|
|
@@ -223,28 +255,35 @@ export function withDelayer<T extends ViemClient>(
|
|
|
223
255
|
computedTxHash: txHash,
|
|
224
256
|
});
|
|
225
257
|
}
|
|
226
|
-
logger.info(`Sent previously delayed tx ${clientTxHash}
|
|
258
|
+
logger.info(`Sent previously delayed tx ${clientTxHash}`, { sender });
|
|
227
259
|
delayer.sentTxHashes.push(clientTxHash);
|
|
228
260
|
})
|
|
229
261
|
.catch(err => logger.error(`Error sending tx after delay`, err));
|
|
230
262
|
return Promise.resolve(txHash!);
|
|
231
263
|
} else {
|
|
232
264
|
const txHash = await client.sendRawTransaction(...args);
|
|
233
|
-
logger.
|
|
265
|
+
logger.debug(`Sent tx immediately ${txHash}`, { sender });
|
|
234
266
|
delayer.sentTxHashes.push(txHash);
|
|
235
267
|
return txHash;
|
|
236
268
|
}
|
|
237
269
|
},
|
|
238
|
-
}))
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
// Only re-bind wallet actions (sendTransaction, writeContract, deployContract) for wallet clients.
|
|
273
|
+
// This is needed for tests that use wallet actions directly rather than sendRawTransaction.
|
|
274
|
+
const isWalletClient = 'account' in client && client.account !== undefined;
|
|
275
|
+
const extended = isWalletClient
|
|
276
|
+
? withRawTx
|
|
277
|
+
// Re-extend with sendTransaction so it uses the modified sendRawTransaction.
|
|
278
|
+
.extend(client => ({ sendTransaction: walletActions(client).sendTransaction }))
|
|
279
|
+
// And with the actions that depend on the modified sendTransaction
|
|
280
|
+
.extend(client => ({
|
|
281
|
+
writeContract: walletActions(client).writeContract,
|
|
282
|
+
deployContract: walletActions(client).deployContract,
|
|
283
|
+
}))
|
|
284
|
+
: withRawTx;
|
|
246
285
|
|
|
247
|
-
return
|
|
286
|
+
return extended as T;
|
|
248
287
|
}
|
|
249
288
|
|
|
250
289
|
/**
|