@aztec/ethereum 4.0.0-nightly.20250907 → 4.0.0-nightly.20260107
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 +2 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +6 -2
- package/dest/config.d.ts +18 -46
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +40 -285
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +8 -6
- 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 -6
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/empire_slashing_proposer.js +18 -3
- 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 +4 -4
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -1
- 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 +16 -16
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +7 -3
- package/dest/contracts/governance_proposer.d.ts +7 -6
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +400 -12
- package/dest/contracts/gse.d.ts +1 -1
- package/dest/contracts/gse.d.ts.map +1 -1
- package/dest/contracts/inbox.d.ts +7 -3
- package/dest/contracts/inbox.d.ts.map +1 -1
- package/dest/contracts/inbox.js +4 -0
- package/dest/contracts/index.d.ts +1 -1
- package/dest/contracts/multicall.d.ts +5 -7
- package/dest/contracts/multicall.d.ts.map +1 -1
- package/dest/contracts/multicall.js +6 -4
- package/dest/contracts/registry.d.ts +1 -1
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/rollup.d.ts +168 -117
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +712 -241
- package/dest/contracts/slasher_contract.d.ts +11 -1
- package/dest/contracts/slasher_contract.d.ts.map +1 -1
- package/dest/contracts/slasher_contract.js +18 -0
- package/dest/contracts/tally_slashing_proposer.d.ts +15 -7
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -1
- package/dest/contracts/tally_slashing_proposer.js +15 -5
- package/dest/contracts/utils.d.ts +1 -1
- package/dest/deploy_aztec_l1_contracts.d.ts +247 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +336 -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/l1_artifacts.d.ts +17698 -6245
- package/dest/l1_artifacts.d.ts.map +1 -1
- package/dest/l1_artifacts.js +10 -5
- package/dest/l1_contract_addresses.d.ts +8 -4
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +5 -4
- package/dest/l1_reader.d.ts +4 -2
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +7 -1
- package/dest/l1_tx_utils/config.d.ts +59 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +96 -0
- package/dest/l1_tx_utils/constants.d.ts +12 -0
- package/dest/l1_tx_utils/constants.d.ts.map +1 -0
- package/dest/l1_tx_utils/constants.js +39 -0
- package/dest/l1_tx_utils/factory.d.ts +24 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +12 -0
- 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 +48 -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 +12 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +12 -0
- package/dest/l1_tx_utils/interfaces.d.ts +76 -0
- package/dest/l1_tx_utils/interfaces.d.ts.map +1 -0
- package/dest/l1_tx_utils/interfaces.js +4 -0
- 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 +94 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +623 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts +26 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils_with_blobs.js +26 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts +83 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/readonly_l1_tx_utils.js +323 -0
- package/dest/l1_tx_utils/signer.d.ts +4 -0
- package/dest/l1_tx_utils/signer.d.ts.map +1 -0
- package/dest/l1_tx_utils/signer.js +16 -0
- package/dest/l1_tx_utils/types.d.ts +67 -0
- package/dest/l1_tx_utils/types.d.ts.map +1 -0
- package/dest/l1_tx_utils/types.js +26 -0
- package/dest/l1_tx_utils/utils.d.ts +4 -0
- package/dest/l1_tx_utils/utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/utils.js +14 -0
- package/dest/l1_types.d.ts +1 -1
- package/dest/publisher_manager.d.ts +8 -3
- package/dest/publisher_manager.d.ts.map +1 -1
- package/dest/publisher_manager.js +36 -8
- package/dest/queries.d.ts +1 -1
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +20 -14
- package/dest/test/chain_monitor.d.ts +29 -22
- package/dest/test/chain_monitor.d.ts.map +1 -1
- package/dest/test/chain_monitor.js +81 -38
- package/dest/test/delayed_tx_utils.d.ts +3 -3
- package/dest/test/delayed_tx_utils.d.ts.map +1 -1
- package/dest/test/delayed_tx_utils.js +2 -2
- package/dest/test/eth_cheat_codes.d.ts +36 -14
- package/dest/test/eth_cheat_codes.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes.js +126 -31
- 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 -1
- package/dest/test/rollup_cheat_codes.d.ts +23 -20
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -1
- package/dest/test/rollup_cheat_codes.js +82 -43
- 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 +2 -1
- package/dest/test/tx_delayer.d.ts +1 -1
- package/dest/test/tx_delayer.d.ts.map +1 -1
- package/dest/test/tx_delayer.js +4 -3
- package/dest/test/upgrade_utils.d.ts +1 -1
- package/dest/test/upgrade_utils.d.ts.map +1 -1
- package/dest/test/upgrade_utils.js +3 -2
- package/dest/types.d.ts +57 -2
- package/dest/types.d.ts.map +1 -1
- package/dest/utils.d.ts +15 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +28 -161
- package/dest/zkPassportVerifierAddress.d.ts +1 -1
- package/dest/zkPassportVerifierAddress.js +1 -1
- package/package.json +33 -14
- package/src/client.ts +3 -3
- package/src/config.ts +49 -358
- package/src/contracts/empire_base.ts +7 -6
- package/src/contracts/empire_slashing_proposer.ts +23 -8
- package/src/contracts/fee_asset_handler.ts +1 -1
- package/src/contracts/governance.ts +3 -3
- package/src/contracts/governance_proposer.ts +19 -9
- package/src/contracts/inbox.ts +7 -2
- package/src/contracts/multicall.ts +12 -10
- package/src/contracts/rollup.ts +373 -235
- package/src/contracts/slasher_contract.ts +22 -0
- package/src/contracts/tally_slashing_proposer.ts +21 -9
- package/src/deploy_aztec_l1_contracts.ts +557 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/l1_artifacts.ts +14 -6
- package/src/l1_contract_addresses.ts +24 -20
- package/src/l1_reader.ts +10 -2
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +161 -0
- package/src/l1_tx_utils/constants.ts +29 -0
- package/src/l1_tx_utils/factory.ts +64 -0
- 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 +119 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +14 -0
- package/src/l1_tx_utils/interfaces.ts +86 -0
- package/src/l1_tx_utils/l1_fee_analyzer.ts +803 -0
- package/src/l1_tx_utils/l1_tx_utils.ts +738 -0
- package/src/l1_tx_utils/l1_tx_utils_with_blobs.ts +77 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +419 -0
- package/src/l1_tx_utils/signer.ts +28 -0
- package/src/l1_tx_utils/types.ts +85 -0
- package/src/l1_tx_utils/utils.ts +16 -0
- package/src/publisher_manager.ts +51 -9
- package/src/queries.ts +24 -10
- package/src/test/chain_monitor.ts +102 -44
- package/src/test/delayed_tx_utils.ts +2 -2
- package/src/test/eth_cheat_codes.ts +150 -31
- package/src/test/rollup_cheat_codes.ts +95 -53
- package/src/test/start_anvil.ts +4 -0
- package/src/test/tx_delayer.ts +5 -3
- package/src/test/upgrade_utils.ts +3 -2
- package/src/types.ts +62 -0
- package/src/utils.ts +41 -184
- package/src/zkPassportVerifierAddress.ts +1 -1
- package/dest/deploy_l1_contracts.d.ts +0 -211
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -1267
- 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.d.ts +0 -250
- package/dest/l1_tx_utils.d.ts.map +0 -1
- package/dest/l1_tx_utils.js +0 -826
- package/dest/l1_tx_utils_with_blobs.d.ts +0 -19
- package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils_with_blobs.js +0 -85
- package/src/deploy_l1_contracts.ts +0 -1596
- package/src/index.ts +0 -17
- package/src/l1_tx_utils.ts +0 -1105
- package/src/l1_tx_utils_with_blobs.ts +0 -144
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import { formatGwei } from 'viem';
|
|
5
|
+
import { calculatePercentile, isBlobTransaction } from '../utils.js';
|
|
6
|
+
import { BLOB_CAPACITY_SCHEDULE, GAS_PER_BLOB, WEI_CONST } from './constants.js';
|
|
7
|
+
import { DEFAULT_PRIORITY_FEE_STRATEGIES } from './fee-strategies/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Gets the maximum blob capacity for a given block timestamp
|
|
10
|
+
*/ function getMaxBlobCapacity(blockTimestamp) {
|
|
11
|
+
const timestamp = Number(blockTimestamp);
|
|
12
|
+
// Find the applicable schedule entry (sorted by timestamp descending)
|
|
13
|
+
for (const schedule of BLOB_CAPACITY_SCHEDULE){
|
|
14
|
+
if (timestamp >= schedule.timestamp) {
|
|
15
|
+
return schedule.max;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
// Fallback (should never hit)
|
|
19
|
+
return BLOB_CAPACITY_SCHEDULE[BLOB_CAPACITY_SCHEDULE.length - 1].max;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Processes a list of transactions to extract blob transaction info and priority fees.
|
|
23
|
+
* Handles both pending and mined transactions.
|
|
24
|
+
* Note: Only works with blocks fetched with includeTransactions: true
|
|
25
|
+
*/ function processTransactions(transactions) {
|
|
26
|
+
const blobTxs = [];
|
|
27
|
+
const allPriorityFees = [];
|
|
28
|
+
const blobPriorityFees = [];
|
|
29
|
+
let totalBlobCount = 0;
|
|
30
|
+
if (!transactions) {
|
|
31
|
+
return {
|
|
32
|
+
blobTxs,
|
|
33
|
+
allPriorityFees,
|
|
34
|
+
blobPriorityFees,
|
|
35
|
+
totalBlobCount
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
for (const tx of transactions){
|
|
39
|
+
const priorityFee = tx.maxPriorityFeePerGas || 0n;
|
|
40
|
+
if (priorityFee > 0n) {
|
|
41
|
+
allPriorityFees.push(priorityFee);
|
|
42
|
+
}
|
|
43
|
+
// Check if this is a blob transaction
|
|
44
|
+
if (isBlobTransaction(tx)) {
|
|
45
|
+
const blobCount = tx.blobVersionedHashes.length;
|
|
46
|
+
totalBlobCount += blobCount;
|
|
47
|
+
if (priorityFee > 0n) {
|
|
48
|
+
blobPriorityFees.push(priorityFee);
|
|
49
|
+
}
|
|
50
|
+
blobTxs.push({
|
|
51
|
+
hash: tx.hash,
|
|
52
|
+
maxPriorityFeePerGas: priorityFee,
|
|
53
|
+
maxFeePerGas: tx.maxFeePerGas || 0n,
|
|
54
|
+
maxFeePerBlobGas: tx.maxFeePerBlobGas,
|
|
55
|
+
blobCount,
|
|
56
|
+
gas: tx.gas
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
blobTxs,
|
|
62
|
+
allPriorityFees,
|
|
63
|
+
blobPriorityFees,
|
|
64
|
+
totalBlobCount
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Analyzes L1 transaction fees in fisherman mode.
|
|
69
|
+
* Captures pending block state, records gas calculations, and compares to what gets included.
|
|
70
|
+
* Supports multiple priority fee calculation strategies for comparison.
|
|
71
|
+
*/ export class L1FeeAnalyzer {
|
|
72
|
+
client;
|
|
73
|
+
dateProvider;
|
|
74
|
+
logger;
|
|
75
|
+
maxCompletedAnalyses;
|
|
76
|
+
gasConfig;
|
|
77
|
+
pendingAnalyses;
|
|
78
|
+
pendingCallbacks;
|
|
79
|
+
completedAnalyses;
|
|
80
|
+
analysisCounter;
|
|
81
|
+
strategies;
|
|
82
|
+
constructor(client, dateProvider = new DateProvider(), logger = createLogger('ethereum:l1-fee-analyzer'), maxCompletedAnalyses = 100, strategies = DEFAULT_PRIORITY_FEE_STRATEGIES, gasConfig = {}){
|
|
83
|
+
this.client = client;
|
|
84
|
+
this.dateProvider = dateProvider;
|
|
85
|
+
this.logger = logger;
|
|
86
|
+
this.maxCompletedAnalyses = maxCompletedAnalyses;
|
|
87
|
+
this.gasConfig = gasConfig;
|
|
88
|
+
this.pendingAnalyses = new Map();
|
|
89
|
+
this.pendingCallbacks = new Map();
|
|
90
|
+
this.completedAnalyses = [];
|
|
91
|
+
this.analysisCounter = 0;
|
|
92
|
+
this.strategies = strategies;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Executes all configured strategies and returns their results.
|
|
96
|
+
* Each strategy handles its own RPC calls internally.
|
|
97
|
+
* @param isBlobTx - Whether this is a blob transaction
|
|
98
|
+
* @returns Array of strategy results
|
|
99
|
+
*/ async executeAllStrategies(isBlobTx) {
|
|
100
|
+
const results = [];
|
|
101
|
+
const context = {
|
|
102
|
+
gasConfig: this.gasConfig,
|
|
103
|
+
isBlobTx,
|
|
104
|
+
logger: this.logger
|
|
105
|
+
};
|
|
106
|
+
for (const strategy of this.strategies){
|
|
107
|
+
try {
|
|
108
|
+
const result = await strategy.execute(this.client, context);
|
|
109
|
+
results.push({
|
|
110
|
+
strategyId: strategy.id,
|
|
111
|
+
strategyName: strategy.name,
|
|
112
|
+
calculatedPriorityFee: result.priorityFee,
|
|
113
|
+
debugInfo: result.debugInfo
|
|
114
|
+
});
|
|
115
|
+
this.logger.debug(`Strategy "${strategy.name}" calculated priority fee`, {
|
|
116
|
+
strategyId: strategy.id,
|
|
117
|
+
priorityFee: formatGwei(result.priorityFee),
|
|
118
|
+
...result.debugInfo
|
|
119
|
+
});
|
|
120
|
+
} catch (err) {
|
|
121
|
+
this.logger.error(`Error calculating priority fee for strategy "${strategy.name}"`, err, {
|
|
122
|
+
strategyId: strategy.id
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return results;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Captures a snapshot of the current pending block state
|
|
130
|
+
*/ async capturePendingSnapshot() {
|
|
131
|
+
const timestamp = this.dateProvider.now();
|
|
132
|
+
// Fetch data in parallel
|
|
133
|
+
const [latestBlock, pendingBlock, blobBaseFee] = await Promise.all([
|
|
134
|
+
this.client.getBlock({
|
|
135
|
+
blockTag: 'latest'
|
|
136
|
+
}),
|
|
137
|
+
this.client.getBlock({
|
|
138
|
+
blockTag: 'pending',
|
|
139
|
+
includeTransactions: true
|
|
140
|
+
}).catch(()=>null),
|
|
141
|
+
this.client.getBlobBaseFee().catch(()=>0n)
|
|
142
|
+
]);
|
|
143
|
+
const baseFeePerGas = latestBlock.baseFeePerGas || 0n;
|
|
144
|
+
const latestBlockNumber = latestBlock.number;
|
|
145
|
+
// Extract blob transaction info from pending block
|
|
146
|
+
const { blobTxs: pendingBlobTxs, allPriorityFees: allPendingPriorityFees, blobPriorityFees: pendingBlobPriorityFees, totalBlobCount: pendingBlobCount } = processTransactions(pendingBlock?.transactions);
|
|
147
|
+
// Calculate 75th percentile priority fees
|
|
148
|
+
const pendingP75PriorityFee = calculatePercentile(allPendingPriorityFees, 75);
|
|
149
|
+
const pendingBlobP75PriorityFee = calculatePercentile(pendingBlobPriorityFees, 75);
|
|
150
|
+
const pendingTxCount = pendingBlock?.transactions?.length || 0;
|
|
151
|
+
return {
|
|
152
|
+
timestamp,
|
|
153
|
+
latestBlockNumber,
|
|
154
|
+
baseFeePerGas,
|
|
155
|
+
blobBaseFee,
|
|
156
|
+
pendingTxCount,
|
|
157
|
+
pendingBlobTxCount: pendingBlobTxs.length,
|
|
158
|
+
pendingBlobCount,
|
|
159
|
+
pendingBlobTxs,
|
|
160
|
+
pendingP75PriorityFee,
|
|
161
|
+
pendingBlobP75PriorityFee
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Starts a fee analysis for a transaction bundle
|
|
166
|
+
* @param l2SlotNumber - The L2 slot this analysis is for
|
|
167
|
+
* @param gasLimit - The estimated gas limit
|
|
168
|
+
* @param requests - The transaction requests being analyzed
|
|
169
|
+
* @param blobInputs - Blob inputs if this is a blob transaction
|
|
170
|
+
* @param onComplete - Optional callback to invoke when analysis completes
|
|
171
|
+
* @returns The analysis ID for tracking
|
|
172
|
+
*/ async startAnalysis(l2SlotNumber, gasLimit, requests, blobInputs, onComplete) {
|
|
173
|
+
const id = `fee-analysis-${++this.analysisCounter}-${Date.now()}`;
|
|
174
|
+
const blobCount = blobInputs?.blobs?.length || 0;
|
|
175
|
+
const isBlobTx = blobCount > 0;
|
|
176
|
+
// Execute all strategies and capture pending snapshot in parallel
|
|
177
|
+
const [pendingSnapshot, strategyResults] = await Promise.all([
|
|
178
|
+
this.capturePendingSnapshot(),
|
|
179
|
+
this.executeAllStrategies(isBlobTx)
|
|
180
|
+
]);
|
|
181
|
+
const analysis = {
|
|
182
|
+
id,
|
|
183
|
+
l2SlotNumber,
|
|
184
|
+
pendingSnapshot,
|
|
185
|
+
computedPrices: {
|
|
186
|
+
gasLimit,
|
|
187
|
+
blobCount,
|
|
188
|
+
strategyResults
|
|
189
|
+
},
|
|
190
|
+
txInfo: {
|
|
191
|
+
requestCount: requests.length,
|
|
192
|
+
hasBlobData: isBlobTx,
|
|
193
|
+
totalEstimatedGas: gasLimit
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
this.pendingAnalyses.set(id, analysis);
|
|
197
|
+
if (onComplete) {
|
|
198
|
+
this.pendingCallbacks.set(id, onComplete);
|
|
199
|
+
}
|
|
200
|
+
// Log strategy calculations
|
|
201
|
+
const strategyLogInfo = strategyResults.reduce((acc, s)=>{
|
|
202
|
+
acc[`strategy_${s.strategyId}`] = formatGwei(s.calculatedPriorityFee);
|
|
203
|
+
return acc;
|
|
204
|
+
}, {});
|
|
205
|
+
this.logger.debug('Started fee analysis with strategy calculations', {
|
|
206
|
+
id,
|
|
207
|
+
l2SlotNumber: l2SlotNumber.toString(),
|
|
208
|
+
pendingBlobTxCount: pendingSnapshot.pendingBlobTxCount,
|
|
209
|
+
pendingBlobCount: pendingSnapshot.pendingBlobCount,
|
|
210
|
+
pendingBlobP75: formatGwei(pendingSnapshot.pendingBlobP75PriorityFee),
|
|
211
|
+
strategiesAnalyzed: strategyResults.length,
|
|
212
|
+
...strategyLogInfo
|
|
213
|
+
});
|
|
214
|
+
// Start watching for the next block
|
|
215
|
+
void this.watchForNextBlock(id, pendingSnapshot.latestBlockNumber);
|
|
216
|
+
return id;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Watches for the next block to be mined and completes the analysis
|
|
220
|
+
*/ async watchForNextBlock(analysisId, startBlockNumber) {
|
|
221
|
+
const analysis = this.pendingAnalyses.get(analysisId);
|
|
222
|
+
if (!analysis) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
// wait for next block
|
|
227
|
+
await retryUntil(async ()=>{
|
|
228
|
+
const currentBlockNumber = await this.client.getBlockNumber();
|
|
229
|
+
if (currentBlockNumber > startBlockNumber) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}, 'Wait for next block', 13_000, 0.5);
|
|
234
|
+
const minedBlock = await this.client.getBlock({
|
|
235
|
+
includeTransactions: true
|
|
236
|
+
});
|
|
237
|
+
this.completeAnalysis(analysisId, minedBlock);
|
|
238
|
+
} catch (err) {
|
|
239
|
+
this.logger.error('Error waiting for next block in fee analysis', err, {
|
|
240
|
+
analysisId
|
|
241
|
+
});
|
|
242
|
+
} finally{
|
|
243
|
+
this.pendingAnalyses.delete(analysisId);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Completes the analysis once the next block is mined
|
|
248
|
+
*/ completeAnalysis(analysisId, minedBlock) {
|
|
249
|
+
const analysis = this.pendingAnalyses.get(analysisId);
|
|
250
|
+
if (!analysis) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
// Extract blob transaction info from mined block
|
|
254
|
+
const { blobTxs: includedBlobTxs, allPriorityFees: includedPriorityFees, blobPriorityFees: includedBlobPriorityFees, totalBlobCount: includedBlobCount } = processTransactions(minedBlock.transactions);
|
|
255
|
+
// Get minimum included fees
|
|
256
|
+
const minIncludedPriorityFee = includedPriorityFees.length > 0 ? this.minBigInt(includedPriorityFees) : 0n;
|
|
257
|
+
const minIncludedBlobPriorityFee = includedBlobPriorityFees.length > 0 ? this.minBigInt(includedBlobPriorityFees) : 0n;
|
|
258
|
+
// Populate mined block info
|
|
259
|
+
analysis.minedBlock = {
|
|
260
|
+
blockNumber: minedBlock.number,
|
|
261
|
+
blockHash: minedBlock.hash,
|
|
262
|
+
blockTimestamp: minedBlock.timestamp,
|
|
263
|
+
baseFeePerGas: minedBlock.baseFeePerGas || 0n,
|
|
264
|
+
blobGasUsed: minedBlock.blobGasUsed || 0n,
|
|
265
|
+
txCount: minedBlock.transactions?.length || 0,
|
|
266
|
+
includedBlobTxCount: includedBlobTxs.length,
|
|
267
|
+
includedBlobCount,
|
|
268
|
+
includedBlobTxs,
|
|
269
|
+
minIncludedPriorityFee,
|
|
270
|
+
minIncludedBlobPriorityFee
|
|
271
|
+
};
|
|
272
|
+
// Calculate time before block mined
|
|
273
|
+
const blockTimestampMs = Number(minedBlock.timestamp) * 1000;
|
|
274
|
+
const timeBeforeBlockMs = blockTimestampMs - analysis.pendingSnapshot.timestamp;
|
|
275
|
+
// Calculate how many blobs were actually in the mined block
|
|
276
|
+
const blobsInBlock = minedBlock.blobGasUsed > 0n ? Number(minedBlock.blobGasUsed / GAS_PER_BLOB) : 0;
|
|
277
|
+
const maxBlobCapacity = getMaxBlobCapacity(minedBlock.timestamp);
|
|
278
|
+
const blockBlobsFull = blobsInBlock >= maxBlobCapacity;
|
|
279
|
+
// Count how many pending blob txs actually got included
|
|
280
|
+
const pendingBlobHashes = new Set(analysis.pendingSnapshot.pendingBlobTxs.map((tx)=>tx.hash));
|
|
281
|
+
const includedBlobHashes = new Set(includedBlobTxs.map((tx)=>tx.hash));
|
|
282
|
+
const pendingBlobTxsIncludedCount = [
|
|
283
|
+
...pendingBlobHashes
|
|
284
|
+
].filter((h)=>includedBlobHashes.has(h)).length;
|
|
285
|
+
const pendingBlobTxsExcludedCount = analysis.pendingSnapshot.pendingBlobTxCount - pendingBlobTxsIncludedCount;
|
|
286
|
+
analysis.analysis = {
|
|
287
|
+
timeBeforeBlockMs,
|
|
288
|
+
pendingBlobTxsIncludedCount,
|
|
289
|
+
pendingBlobTxsExcludedCount,
|
|
290
|
+
blobsInBlock,
|
|
291
|
+
maxBlobCapacity,
|
|
292
|
+
blockBlobsFull
|
|
293
|
+
};
|
|
294
|
+
// Evaluate each strategy against the mined block
|
|
295
|
+
const isBlobTx = analysis.computedPrices.blobCount > 0;
|
|
296
|
+
const minPriorityFeeToCompare = isBlobTx ? minIncludedBlobPriorityFee : minIncludedPriorityFee;
|
|
297
|
+
const gasLimit = analysis.computedPrices.gasLimit;
|
|
298
|
+
if (analysis.computedPrices.strategyResults) {
|
|
299
|
+
for (const strategyResult of analysis.computedPrices.strategyResults){
|
|
300
|
+
const strategyPriorityFee = strategyResult.calculatedPriorityFee;
|
|
301
|
+
const strategyPriorityFeeDelta = strategyPriorityFee - minPriorityFeeToCompare;
|
|
302
|
+
// Determine if this strategy would have resulted in inclusion
|
|
303
|
+
let strategyWouldBeIncluded = true;
|
|
304
|
+
let strategyExclusionReason;
|
|
305
|
+
if (isBlobTx) {
|
|
306
|
+
// For blob txs, only consider priority fee if blob space was full
|
|
307
|
+
if (includedBlobPriorityFees.length > 0 && strategyPriorityFee < minIncludedBlobPriorityFee && blockBlobsFull) {
|
|
308
|
+
strategyWouldBeIncluded = false;
|
|
309
|
+
strategyExclusionReason = 'priority_fee_too_low';
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
// For non-blob txs, use the old logic
|
|
313
|
+
if (includedPriorityFees.length > 0 && strategyPriorityFee < minIncludedPriorityFee) {
|
|
314
|
+
strategyWouldBeIncluded = false;
|
|
315
|
+
strategyExclusionReason = 'priority_fee_too_low';
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// Calculate estimated cost in ETH for this strategy
|
|
319
|
+
// Cost = gasLimit * (baseFee + priorityFee)
|
|
320
|
+
const baseFee = analysis.minedBlock.baseFeePerGas;
|
|
321
|
+
// Execution cost: gasLimit * (baseFee + priorityFee)
|
|
322
|
+
const executionCostWei = gasLimit * (baseFee + strategyPriorityFee);
|
|
323
|
+
const estimatedCostEth = Number(executionCostWei) / 1e18;
|
|
324
|
+
// Calculate minimum cost needed for inclusion
|
|
325
|
+
const minExecutionCostWei = gasLimit * (baseFee + minPriorityFeeToCompare);
|
|
326
|
+
const minCostEth = Number(minExecutionCostWei) / 1e18;
|
|
327
|
+
// Overpayment is the difference
|
|
328
|
+
const estimatedOverpaymentEth = estimatedCostEth - minCostEth;
|
|
329
|
+
// Update the strategy result with analysis data
|
|
330
|
+
strategyResult.wouldBeIncluded = strategyWouldBeIncluded;
|
|
331
|
+
strategyResult.exclusionReason = strategyExclusionReason;
|
|
332
|
+
strategyResult.priorityFeeDelta = strategyPriorityFeeDelta;
|
|
333
|
+
strategyResult.estimatedCostEth = estimatedCostEth;
|
|
334
|
+
strategyResult.estimatedOverpaymentEth = estimatedOverpaymentEth;
|
|
335
|
+
// Log per-strategy results
|
|
336
|
+
this.logger.info(`Strategy "${strategyResult.strategyName}" analysis`, {
|
|
337
|
+
id: analysisId,
|
|
338
|
+
strategyId: strategyResult.strategyId,
|
|
339
|
+
strategyName: strategyResult.strategyName,
|
|
340
|
+
calculatedPriorityFee: formatGwei(strategyPriorityFee),
|
|
341
|
+
minIncludedPriorityFee: formatGwei(minPriorityFeeToCompare),
|
|
342
|
+
priorityFeeDelta: formatGwei(strategyPriorityFeeDelta),
|
|
343
|
+
wouldBeIncluded: strategyWouldBeIncluded,
|
|
344
|
+
exclusionReason: strategyExclusionReason,
|
|
345
|
+
estimatedCostEth: estimatedCostEth.toFixed(6),
|
|
346
|
+
estimatedOverpaymentEth: estimatedOverpaymentEth.toFixed(6)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// Create cost ranking
|
|
350
|
+
const costRanking = analysis.computedPrices.strategyResults.map((s)=>({
|
|
351
|
+
strategyId: s.strategyId,
|
|
352
|
+
strategyName: s.strategyName,
|
|
353
|
+
estimatedCostEth: s.estimatedCostEth,
|
|
354
|
+
wouldBeIncluded: s.wouldBeIncluded
|
|
355
|
+
})).sort((a, b)=>a.estimatedCostEth - b.estimatedCostEth);
|
|
356
|
+
analysis.analysis.costRanking = costRanking;
|
|
357
|
+
// Log cost ranking summary
|
|
358
|
+
this.logger.info('Strategy cost ranking', {
|
|
359
|
+
id: analysisId,
|
|
360
|
+
cheapestStrategy: costRanking[0]?.strategyName,
|
|
361
|
+
cheapestCost: costRanking[0]?.estimatedCostEth.toFixed(6),
|
|
362
|
+
cheapestWouldBeIncluded: costRanking[0]?.wouldBeIncluded,
|
|
363
|
+
mostExpensiveStrategy: costRanking[costRanking.length - 1]?.strategyName,
|
|
364
|
+
mostExpensiveCost: costRanking[costRanking.length - 1]?.estimatedCostEth.toFixed(6),
|
|
365
|
+
mostExpensiveWouldBeIncluded: costRanking[costRanking.length - 1]?.wouldBeIncluded,
|
|
366
|
+
costSpread: costRanking.length > 1 ? (costRanking[costRanking.length - 1].estimatedCostEth - costRanking[0].estimatedCostEth).toFixed(6) : '0'
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
// Log the overall results
|
|
370
|
+
this.logger.info('Fee analysis completed', {
|
|
371
|
+
id: analysisId,
|
|
372
|
+
l2SlotNumber: analysis.l2SlotNumber.toString(),
|
|
373
|
+
timeBeforeBlockMs,
|
|
374
|
+
pendingBlobTxCount: analysis.pendingSnapshot.pendingBlobTxCount,
|
|
375
|
+
includedBlobTxCount: analysis.minedBlock.includedBlobTxCount,
|
|
376
|
+
pendingBlobTxsIncludedCount,
|
|
377
|
+
pendingBlobTxsExcludedCount,
|
|
378
|
+
blobsInBlock,
|
|
379
|
+
maxBlobCapacity,
|
|
380
|
+
blockBlobsFull,
|
|
381
|
+
minIncludedPriorityFee: formatGwei(minIncludedPriorityFee),
|
|
382
|
+
minIncludedBlobPriorityFee: formatGwei(minIncludedBlobPriorityFee),
|
|
383
|
+
strategiesAnalyzed: analysis.computedPrices.strategyResults?.length ?? 0
|
|
384
|
+
});
|
|
385
|
+
// Move to completed analyses
|
|
386
|
+
this.pendingAnalyses.delete(analysisId);
|
|
387
|
+
this.completedAnalyses.push(analysis);
|
|
388
|
+
// Trim old completed analyses if needed
|
|
389
|
+
while(this.completedAnalyses.length > this.maxCompletedAnalyses){
|
|
390
|
+
this.completedAnalyses.shift();
|
|
391
|
+
}
|
|
392
|
+
// Invoke the callback for this specific analysis
|
|
393
|
+
const callback = this.pendingCallbacks.get(analysisId);
|
|
394
|
+
if (callback) {
|
|
395
|
+
try {
|
|
396
|
+
callback(analysis);
|
|
397
|
+
} catch (err) {
|
|
398
|
+
this.logger.error('Error in analysis complete callback', err);
|
|
399
|
+
}
|
|
400
|
+
this.pendingCallbacks.delete(analysisId);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Gets a specific analysis result by ID
|
|
405
|
+
*/ getAnalysis(id) {
|
|
406
|
+
return this.pendingAnalyses.get(id) || this.completedAnalyses.find((a)=>a.id === id);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Gets all completed analyses
|
|
410
|
+
*/ getCompletedAnalyses() {
|
|
411
|
+
return [
|
|
412
|
+
...this.completedAnalyses
|
|
413
|
+
];
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Gets statistics about all completed analyses
|
|
417
|
+
*/ getAnalysisStats() {
|
|
418
|
+
const completed = this.completedAnalyses.filter((a)=>a.analysis);
|
|
419
|
+
if (completed.length === 0) {
|
|
420
|
+
return {
|
|
421
|
+
totalAnalyses: 0,
|
|
422
|
+
avgTimeBeforeBlockMs: 0,
|
|
423
|
+
avgBlobsInBlock: 0,
|
|
424
|
+
blocksBlobsFull: 0
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
const avgTimeBeforeBlockMs = completed.reduce((sum, a)=>sum + a.analysis.timeBeforeBlockMs, 0) / completed.length;
|
|
428
|
+
const avgBlobsInBlock = completed.reduce((sum, a)=>sum + a.analysis.blobsInBlock, 0) / completed.length;
|
|
429
|
+
const blocksBlobsFull = completed.filter((a)=>a.analysis.blockBlobsFull).length;
|
|
430
|
+
return {
|
|
431
|
+
totalAnalyses: completed.length,
|
|
432
|
+
avgTimeBeforeBlockMs,
|
|
433
|
+
avgBlobsInBlock,
|
|
434
|
+
blocksBlobsFull
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Gets comparative statistics for all strategies across completed analyses
|
|
439
|
+
*/ getStrategyComparison() {
|
|
440
|
+
const completed = this.completedAnalyses.filter((a)=>a.analysis);
|
|
441
|
+
if (completed.length === 0) {
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
// Collect data by strategy ID
|
|
445
|
+
const strategyData = new Map();
|
|
446
|
+
for (const analysis of completed){
|
|
447
|
+
if (!analysis.computedPrices.strategyResults) {
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
for (const strategyResult of analysis.computedPrices.strategyResults){
|
|
451
|
+
if (!strategyData.has(strategyResult.strategyId)) {
|
|
452
|
+
strategyData.set(strategyResult.strategyId, {
|
|
453
|
+
strategyName: strategyResult.strategyName,
|
|
454
|
+
analyses: 0,
|
|
455
|
+
inclusions: 0,
|
|
456
|
+
totalCostEth: 0,
|
|
457
|
+
totalOverpaymentEth: 0,
|
|
458
|
+
totalPriorityFeeDelta: 0
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
const data = strategyData.get(strategyResult.strategyId);
|
|
462
|
+
data.analyses++;
|
|
463
|
+
if (strategyResult.wouldBeIncluded) {
|
|
464
|
+
data.inclusions++;
|
|
465
|
+
}
|
|
466
|
+
if (strategyResult.estimatedCostEth !== undefined) {
|
|
467
|
+
data.totalCostEth += strategyResult.estimatedCostEth;
|
|
468
|
+
}
|
|
469
|
+
if (strategyResult.estimatedOverpaymentEth !== undefined) {
|
|
470
|
+
data.totalOverpaymentEth += strategyResult.estimatedOverpaymentEth;
|
|
471
|
+
}
|
|
472
|
+
if (strategyResult.priorityFeeDelta !== undefined) {
|
|
473
|
+
data.totalPriorityFeeDelta += Number(strategyResult.priorityFeeDelta);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// Convert to output format
|
|
478
|
+
const results = Array.from(strategyData.entries()).map(([strategyId, data])=>({
|
|
479
|
+
strategyId,
|
|
480
|
+
strategyName: data.strategyName,
|
|
481
|
+
totalAnalyses: data.analyses,
|
|
482
|
+
inclusionCount: data.inclusions,
|
|
483
|
+
inclusionRate: data.analyses > 0 ? data.inclusions / data.analyses : 0,
|
|
484
|
+
avgEstimatedCostEth: data.analyses > 0 ? data.totalCostEth / data.analyses : 0,
|
|
485
|
+
totalEstimatedCostEth: data.totalCostEth,
|
|
486
|
+
avgOverpaymentEth: data.analyses > 0 ? data.totalOverpaymentEth / data.analyses : 0,
|
|
487
|
+
totalOverpaymentEth: data.totalOverpaymentEth,
|
|
488
|
+
avgPriorityFeeDeltaGwei: data.analyses > 0 ? data.totalPriorityFeeDelta / data.analyses / Number(WEI_CONST) : 0
|
|
489
|
+
}));
|
|
490
|
+
// Sort by inclusion rate descending, then by avg cost ascending
|
|
491
|
+
return results.sort((a, b)=>{
|
|
492
|
+
if (Math.abs(a.inclusionRate - b.inclusionRate) > 0.01) {
|
|
493
|
+
return b.inclusionRate - a.inclusionRate;
|
|
494
|
+
}
|
|
495
|
+
return a.avgEstimatedCostEth - b.avgEstimatedCostEth;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Gets the minimum value from an array of bigints
|
|
500
|
+
*/ minBigInt(values) {
|
|
501
|
+
if (values.length === 0) {
|
|
502
|
+
return 0n;
|
|
503
|
+
}
|
|
504
|
+
return values.reduce((min, val)=>val < min ? val : min, values[0]);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import { type Abi, type BlockOverrides, type Hex, type NonceManager, type PrepareTransactionRequestRequest, type StateOverride, type TransactionReceipt } from 'viem';
|
|
5
|
+
import type { ViemClient } from '../types.js';
|
|
6
|
+
import { type L1TxUtilsConfig } from './config.js';
|
|
7
|
+
import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
|
|
8
|
+
import { ReadOnlyL1TxUtils } from './readonly_l1_tx_utils.js';
|
|
9
|
+
import { type L1BlobInputs, type L1TxConfig, type L1TxRequest, type L1TxState, type SigningCallback, TxUtilsState } from './types.js';
|
|
10
|
+
export declare class L1TxUtils extends ReadOnlyL1TxUtils {
|
|
11
|
+
client: ViemClient;
|
|
12
|
+
address: EthAddress;
|
|
13
|
+
protected signer: SigningCallback;
|
|
14
|
+
protected store?: IL1TxStore | undefined;
|
|
15
|
+
protected metrics?: IL1TxMetrics | undefined;
|
|
16
|
+
protected nonceManager: NonceManager;
|
|
17
|
+
protected txs: L1TxState[];
|
|
18
|
+
constructor(client: ViemClient, address: EthAddress, signer: SigningCallback, logger?: Logger, dateProvider?: DateProvider, config?: Partial<L1TxUtilsConfig>, debugMaxGasLimit?: boolean, store?: IL1TxStore | undefined, metrics?: IL1TxMetrics | undefined);
|
|
19
|
+
get state(): TxUtilsState;
|
|
20
|
+
get lastMinedAtBlockNumber(): bigint | undefined;
|
|
21
|
+
protected updateState(l1TxState: L1TxState, newState: TxUtilsState.MINED, l1Timestamp: number): Promise<void>;
|
|
22
|
+
protected updateState(l1TxState: L1TxState, newState: TxUtilsState, l1Timestamp?: undefined): Promise<void>;
|
|
23
|
+
updateConfig(newConfig: Partial<L1TxUtilsConfig>): void;
|
|
24
|
+
getSenderAddress(): EthAddress;
|
|
25
|
+
getSenderBalance(): Promise<bigint>;
|
|
26
|
+
/**
|
|
27
|
+
* Rehydrates transaction states from the store and resumes monitoring for pending transactions.
|
|
28
|
+
* This should be called on startup to restore state and resume monitoring of any in-flight transactions.
|
|
29
|
+
*/
|
|
30
|
+
loadStateAndResumeMonitoring(): Promise<void>;
|
|
31
|
+
private signTransaction;
|
|
32
|
+
protected prepareSignedTransaction(txData: PrepareTransactionRequestRequest): Promise<`0x${string}`>;
|
|
33
|
+
/**
|
|
34
|
+
* Sends a transaction with gas estimation and pricing
|
|
35
|
+
* @param request - The transaction request (to, data, value)
|
|
36
|
+
* @param gasConfig - Optional gas configuration
|
|
37
|
+
* @returns The transaction hash and parameters used
|
|
38
|
+
*/
|
|
39
|
+
sendTransaction(request: L1TxRequest, gasConfigOverrides?: L1TxConfig, blobInputs?: L1BlobInputs, stateChange?: TxUtilsState): Promise<{
|
|
40
|
+
txHash: Hex;
|
|
41
|
+
state: L1TxState;
|
|
42
|
+
}>;
|
|
43
|
+
private tryGetTxReceipt;
|
|
44
|
+
/**
|
|
45
|
+
* Returns whether a given tx should be considered as timed out and no longer monitored.
|
|
46
|
+
* Relies on the txTimeout setting for user txs, and on the txCancellationTimeout for cancel txs.
|
|
47
|
+
* @remarks We check against the latestBlockTimestamp as opposed to the current time to avoid a race condition where
|
|
48
|
+
* the tx is mined in a block with the same timestamp as txTimeoutAt, but our execution node has not yet processed it,
|
|
49
|
+
* or the loop here has not yet checked the tx before that timeout.
|
|
50
|
+
*/
|
|
51
|
+
private isTxTimedOut;
|
|
52
|
+
/**
|
|
53
|
+
* Monitors a transaction until completion, handling speed-ups if needed
|
|
54
|
+
*/
|
|
55
|
+
protected monitorTransaction(state: L1TxState): Promise<TransactionReceipt>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates tx data to be signed by viem signTransaction method, using the state as input.
|
|
58
|
+
* If isCancelTx is true, creates a 0-value tx to self with 21k gas and no data instead,
|
|
59
|
+
* and an empty blob input if the original tx also had blobs.
|
|
60
|
+
*/
|
|
61
|
+
private makeTxData;
|
|
62
|
+
/** Returns when all monitor loops have stopped. */
|
|
63
|
+
waitMonitoringStopped(timeoutSeconds?: number): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Sends a transaction and monitors it until completion
|
|
66
|
+
* @param request - The transaction request (to, data, value)
|
|
67
|
+
* @param gasConfig - Optional gas configuration
|
|
68
|
+
* @returns The receipt of the successful transaction
|
|
69
|
+
*/
|
|
70
|
+
sendAndMonitorTransaction(request: L1TxRequest, gasConfig?: L1TxConfig, blobInputs?: L1BlobInputs): Promise<{
|
|
71
|
+
receipt: TransactionReceipt;
|
|
72
|
+
state: L1TxState;
|
|
73
|
+
}>;
|
|
74
|
+
simulate(request: L1TxRequest & {
|
|
75
|
+
gas?: bigint;
|
|
76
|
+
from?: Hex;
|
|
77
|
+
}, _blockOverrides?: BlockOverrides<bigint, number>, stateOverrides?: StateOverride, abi?: Abi, _gasConfig?: L1TxUtilsConfig & {
|
|
78
|
+
fallbackGasEstimate?: bigint;
|
|
79
|
+
ignoreBlockGasLimit?: boolean;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
gasUsed: bigint;
|
|
82
|
+
result: `0x${string}`;
|
|
83
|
+
}>;
|
|
84
|
+
/**
|
|
85
|
+
* Attempts to cancel a transaction by sending a 0-value tx to self with same nonce but higher gas prices
|
|
86
|
+
* Only sends the cancellation if the original tx is still pending, not if it was dropped
|
|
87
|
+
* @returns The hash of the cancellation transaction
|
|
88
|
+
*/
|
|
89
|
+
protected attemptTxCancellation(state: L1TxState): Promise<void>;
|
|
90
|
+
private getL1Timestamp;
|
|
91
|
+
/** Makes empty blob inputs for the cancellation tx. To be overridden in L1TxUtilsWithBlobs. */
|
|
92
|
+
protected makeEmptyBlobInputs(_maxFeePerBlobGas: bigint): Required<L1BlobInputs>;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJma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