@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,245 @@
|
|
|
1
|
+
import { median } from '@aztec/foundation/collection';
|
|
2
|
+
|
|
3
|
+
import { type GetFeeHistoryReturnType, formatGwei } from 'viem';
|
|
4
|
+
|
|
5
|
+
import type { ViemClient } from '../../types.js';
|
|
6
|
+
import { calculatePercentile, isBlobTransaction } from '../../utils.js';
|
|
7
|
+
import { WEI_CONST } from '../constants.js';
|
|
8
|
+
import {
|
|
9
|
+
HISTORICAL_BLOCK_COUNT,
|
|
10
|
+
type PriorityFeeStrategy,
|
|
11
|
+
type PriorityFeeStrategyContext,
|
|
12
|
+
type PriorityFeeStrategyResult,
|
|
13
|
+
} from './types.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Fetches historical blocks and calculates reward percentiles for blob transactions only.
|
|
17
|
+
* Returns data in the same format as getFeeHistory for easy drop-in replacement.
|
|
18
|
+
*
|
|
19
|
+
* @param client - Viem client to use for RPC calls
|
|
20
|
+
* @param blockCount - Number of historical blocks to fetch
|
|
21
|
+
* @param rewardPercentiles - Array of percentiles to calculate (e.g., [75] for 75th percentile)
|
|
22
|
+
* @returns Object with reward field containing percentile fees for each block, similar to getFeeHistory
|
|
23
|
+
* @throws Error if fetching blocks fails
|
|
24
|
+
*/
|
|
25
|
+
export async function getBlobPriorityFeeHistory(
|
|
26
|
+
client: ViemClient,
|
|
27
|
+
blockCount: number,
|
|
28
|
+
rewardPercentiles: number[],
|
|
29
|
+
): Promise<GetFeeHistoryReturnType> {
|
|
30
|
+
const latestBlockNumber = await client.getBlockNumber();
|
|
31
|
+
|
|
32
|
+
// Fetch multiple blocks in parallel
|
|
33
|
+
const blockPromises = Array.from({ length: blockCount }, (_, i) =>
|
|
34
|
+
client.getBlock({
|
|
35
|
+
blockNumber: latestBlockNumber - BigInt(i),
|
|
36
|
+
includeTransactions: true,
|
|
37
|
+
}),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const blocks = await Promise.all(blockPromises);
|
|
41
|
+
|
|
42
|
+
// Process each block to extract blob transaction fees and other data
|
|
43
|
+
const baseFeePerGas: bigint[] = [];
|
|
44
|
+
const gasUsedRatio: number[] = [];
|
|
45
|
+
const reward: bigint[][] = [];
|
|
46
|
+
|
|
47
|
+
for (const block of blocks) {
|
|
48
|
+
// Collect base fee per gas
|
|
49
|
+
baseFeePerGas.push(block.baseFeePerGas || 0n);
|
|
50
|
+
|
|
51
|
+
// Calculate gas used ratio
|
|
52
|
+
const gasUsed = block.gasUsed || 0n;
|
|
53
|
+
const gasLimit = block.gasLimit || 1n; // Avoid division by zero
|
|
54
|
+
gasUsedRatio.push(Number(gasUsed) / Number(gasLimit));
|
|
55
|
+
|
|
56
|
+
if (!block.transactions || block.transactions.length === 0) {
|
|
57
|
+
// No transactions in this block - return zeros for each percentile
|
|
58
|
+
reward.push(rewardPercentiles.map(() => 0n));
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Extract priority fees from blob transactions only
|
|
63
|
+
const blobFees = block.transactions
|
|
64
|
+
.map(tx => {
|
|
65
|
+
// Transaction can be just a hash string
|
|
66
|
+
if (typeof tx === 'string') {
|
|
67
|
+
return 0n;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!isBlobTransaction(tx)) {
|
|
71
|
+
return 0n;
|
|
72
|
+
}
|
|
73
|
+
return tx.maxPriorityFeePerGas || 0n;
|
|
74
|
+
})
|
|
75
|
+
.filter((fee: bigint) => fee > 0n);
|
|
76
|
+
|
|
77
|
+
if (blobFees.length === 0) {
|
|
78
|
+
// No blob transactions in this block - return zeros for each percentile
|
|
79
|
+
reward.push(rewardPercentiles.map(() => 0n));
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Calculate requested percentiles
|
|
84
|
+
const percentiles = rewardPercentiles.map(percentile => calculatePercentile(blobFees, percentile));
|
|
85
|
+
|
|
86
|
+
reward.push(percentiles);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Calculate oldest block number (the last block in our array)
|
|
90
|
+
const oldestBlock = latestBlockNumber - BigInt(blockCount - 1);
|
|
91
|
+
|
|
92
|
+
// Reverse arrays to match getFeeHistory behavior (oldest first)
|
|
93
|
+
return {
|
|
94
|
+
baseFeePerGas: baseFeePerGas.reverse(),
|
|
95
|
+
gasUsedRatio: gasUsedRatio.reverse(),
|
|
96
|
+
oldestBlock,
|
|
97
|
+
reward: reward.reverse(),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Similar to our current competitive priority fee strategy, but only considers blob transactions
|
|
103
|
+
* when calculating competitive priority fee for blob transactions.
|
|
104
|
+
* This strategy also has NO cap on the competitive fee if it's much higher than the network estimate.
|
|
105
|
+
* Analyzes p75 of pending transactions and 5-block fee history to determine a competitive priority fee.
|
|
106
|
+
* Falls back to network estimate if data is unavailable.
|
|
107
|
+
*/
|
|
108
|
+
export const P75BlobTxsOnlyPriorityFeeStrategy: PriorityFeeStrategy = {
|
|
109
|
+
name: 'Competitive (P75 + History) - Blob Txs Only',
|
|
110
|
+
id: 'p75_pending_txs_and_history_blob_txs_only',
|
|
111
|
+
|
|
112
|
+
async execute(client: ViemClient, context: PriorityFeeStrategyContext): Promise<PriorityFeeStrategyResult> {
|
|
113
|
+
const { isBlobTx, logger } = context;
|
|
114
|
+
|
|
115
|
+
// Fire all RPC calls in parallel
|
|
116
|
+
const [latestBlockResult, blobBaseFeeResult, networkEstimateResult, pendingBlockResult, feeHistoryResult] =
|
|
117
|
+
await Promise.allSettled([
|
|
118
|
+
client.getBlock({ blockTag: 'latest' }),
|
|
119
|
+
isBlobTx ? client.getBlobBaseFee() : Promise.resolve(undefined),
|
|
120
|
+
client.estimateMaxPriorityFeePerGas().catch(() => 0n),
|
|
121
|
+
client.getBlock({ blockTag: 'pending', includeTransactions: true }).catch(() => null),
|
|
122
|
+
isBlobTx
|
|
123
|
+
? getBlobPriorityFeeHistory(client, HISTORICAL_BLOCK_COUNT, [75])
|
|
124
|
+
: client
|
|
125
|
+
.getFeeHistory({
|
|
126
|
+
blockCount: HISTORICAL_BLOCK_COUNT,
|
|
127
|
+
rewardPercentiles: [75],
|
|
128
|
+
blockTag: 'latest',
|
|
129
|
+
})
|
|
130
|
+
.catch(() => null),
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
// Extract latest block (required)
|
|
134
|
+
if (latestBlockResult.status === 'rejected') {
|
|
135
|
+
throw new Error(`Failed to get latest block: ${latestBlockResult.reason}`);
|
|
136
|
+
}
|
|
137
|
+
const latestBlock = latestBlockResult.value;
|
|
138
|
+
|
|
139
|
+
// Extract blob base fee (only for blob txs)
|
|
140
|
+
let blobBaseFee: bigint | undefined;
|
|
141
|
+
if (isBlobTx) {
|
|
142
|
+
if (blobBaseFeeResult.status === 'fulfilled' && typeof blobBaseFeeResult.value === 'bigint') {
|
|
143
|
+
blobBaseFee = blobBaseFeeResult.value;
|
|
144
|
+
} else {
|
|
145
|
+
logger?.warn('Failed to get L1 blob base fee');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Extract network estimate
|
|
150
|
+
const networkEstimate =
|
|
151
|
+
networkEstimateResult.status === 'fulfilled' && typeof networkEstimateResult.value === 'bigint'
|
|
152
|
+
? networkEstimateResult.value
|
|
153
|
+
: 0n;
|
|
154
|
+
|
|
155
|
+
let competitiveFee = networkEstimate;
|
|
156
|
+
const debugInfo: Record<string, string | number> = {
|
|
157
|
+
networkEstimateGwei: formatGwei(networkEstimate),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Extract pending block
|
|
161
|
+
const pendingBlock = pendingBlockResult.status === 'fulfilled' ? pendingBlockResult.value : null;
|
|
162
|
+
|
|
163
|
+
// Analyze pending block transactions
|
|
164
|
+
if (pendingBlock?.transactions && pendingBlock.transactions.length > 0) {
|
|
165
|
+
const pendingFees = pendingBlock.transactions
|
|
166
|
+
.map(tx => {
|
|
167
|
+
if (typeof tx === 'string') {
|
|
168
|
+
return 0n;
|
|
169
|
+
}
|
|
170
|
+
if (isBlobTx) {
|
|
171
|
+
if (!isBlobTransaction(tx)) {
|
|
172
|
+
return 0n;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return tx.maxPriorityFeePerGas || 0n;
|
|
176
|
+
})
|
|
177
|
+
.filter((fee: bigint) => fee > 0n);
|
|
178
|
+
|
|
179
|
+
if (pendingFees.length > 0) {
|
|
180
|
+
const pendingCompetitiveFee = calculatePercentile(pendingFees, 75);
|
|
181
|
+
|
|
182
|
+
if (pendingCompetitiveFee > competitiveFee) {
|
|
183
|
+
competitiveFee = pendingCompetitiveFee;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
debugInfo.pendingTxCount = pendingFees.length;
|
|
187
|
+
debugInfo.pendingP75Gwei = formatGwei(pendingCompetitiveFee);
|
|
188
|
+
|
|
189
|
+
logger?.debug('Analyzed pending transactions for competitive pricing', {
|
|
190
|
+
pendingTxCount: pendingFees.length,
|
|
191
|
+
pendingP75: formatGwei(pendingCompetitiveFee),
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Extract fee history
|
|
197
|
+
const feeHistory = feeHistoryResult.status === 'fulfilled' ? feeHistoryResult.value : null;
|
|
198
|
+
|
|
199
|
+
// Analyze fee history
|
|
200
|
+
if (feeHistory?.reward && feeHistory.reward.length > 0) {
|
|
201
|
+
// Extract 75th percentile fees from each block
|
|
202
|
+
const percentile75Fees = feeHistory.reward.map(rewards => rewards[0] || 0n).filter(fee => fee > 0n);
|
|
203
|
+
|
|
204
|
+
if (percentile75Fees.length > 0) {
|
|
205
|
+
// Calculate median of the 75th percentile fees across blocks
|
|
206
|
+
const medianHistoricalFee = median(percentile75Fees) ?? 0n;
|
|
207
|
+
|
|
208
|
+
// Debug: Log suspicious fees from history
|
|
209
|
+
if (medianHistoricalFee > 100n * WEI_CONST) {
|
|
210
|
+
logger?.warn('Suspicious high fee in history', {
|
|
211
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
212
|
+
allP75Fees: percentile75Fees.map(f => formatGwei(f)),
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (medianHistoricalFee > competitiveFee) {
|
|
217
|
+
competitiveFee = medianHistoricalFee;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
debugInfo.historicalMedianGwei = formatGwei(medianHistoricalFee);
|
|
221
|
+
|
|
222
|
+
logger?.debug('Analyzed fee history for competitive pricing', {
|
|
223
|
+
historicalMedian: formatGwei(medianHistoricalFee),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Log final decision
|
|
229
|
+
if (competitiveFee > networkEstimate) {
|
|
230
|
+
logger?.debug('Using competitive fee from market analysis', {
|
|
231
|
+
networkEstimate: formatGwei(networkEstimate),
|
|
232
|
+
competitive: formatGwei(competitiveFee),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
debugInfo.finalFeeGwei = formatGwei(competitiveFee);
|
|
237
|
+
|
|
238
|
+
return {
|
|
239
|
+
priorityFee: competitiveFee,
|
|
240
|
+
latestBlock,
|
|
241
|
+
blobBaseFee,
|
|
242
|
+
debugInfo,
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
|
|
3
|
+
import type { Block } from 'viem';
|
|
4
|
+
|
|
5
|
+
import type { ViemClient } from '../../types.js';
|
|
6
|
+
import type { L1TxUtilsConfig } from '../config.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Historical block count for fee history queries
|
|
10
|
+
*/
|
|
11
|
+
export const HISTORICAL_BLOCK_COUNT = 5;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Result from a priority fee strategy calculation
|
|
15
|
+
*/
|
|
16
|
+
export interface PriorityFeeStrategyResult {
|
|
17
|
+
/** The calculated priority fee in wei */
|
|
18
|
+
priorityFee: bigint;
|
|
19
|
+
/** The latest block (fetched as part of the strategy) */
|
|
20
|
+
latestBlock: Block;
|
|
21
|
+
/** The blob base fee (only present for blob transactions) */
|
|
22
|
+
blobBaseFee?: bigint;
|
|
23
|
+
/** Optional debug info about how the fee was calculated */
|
|
24
|
+
debugInfo?: Record<string, string | number>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Context passed to the strategy function
|
|
29
|
+
*/
|
|
30
|
+
export interface PriorityFeeStrategyContext {
|
|
31
|
+
/** Gas configuration */
|
|
32
|
+
gasConfig: L1TxUtilsConfig;
|
|
33
|
+
/** Whether this is for a blob transaction */
|
|
34
|
+
isBlobTx: boolean;
|
|
35
|
+
/** Logger for debugging */
|
|
36
|
+
logger?: Logger;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A strategy for calculating the priority fee for L1 transactions.
|
|
41
|
+
* The function handles all RPC calls and returns
|
|
42
|
+
* the priority fee, along with any block data needed by the caller.
|
|
43
|
+
*/
|
|
44
|
+
export type PriorityFeeStrategy = {
|
|
45
|
+
/** Human-readable name for logging */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Unique identifier for metrics */
|
|
48
|
+
id: string;
|
|
49
|
+
/**
|
|
50
|
+
* Calculate the priority fee.
|
|
51
|
+
* @param client - The viem client to use for RPC calls
|
|
52
|
+
* @param context - Contains gas config, whether it's a blob tx, and logger
|
|
53
|
+
* @returns The calculated priority fee result including block data
|
|
54
|
+
*/
|
|
55
|
+
execute: (client: ViemClient, context: PriorityFeeStrategyContext) => Promise<PriorityFeeStrategyResult>;
|
|
56
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
|
|
5
|
+
import { type Hex, encodeFunctionData } from 'viem';
|
|
6
|
+
|
|
7
|
+
import type { EthSigner } from '../eth-signer/eth-signer.js';
|
|
8
|
+
import { FORWARDER_ABI } from '../forwarder_proxy.js';
|
|
9
|
+
import type { ExtendedViemWalletClient, ViemClient } from '../types.js';
|
|
10
|
+
import type { L1TxUtilsConfig } from './config.js';
|
|
11
|
+
import type { IL1TxMetrics, IL1TxStore } from './interfaces.js';
|
|
12
|
+
import { L1TxUtilsWithBlobs } from './l1_tx_utils_with_blobs.js';
|
|
13
|
+
import { createViemSigner } from './signer.js';
|
|
14
|
+
import type { L1BlobInputs, L1TxConfig, L1TxRequest, SigningCallback } from './types.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Extends L1TxUtilsWithBlobs to wrap all transactions through a forwarder contract.
|
|
18
|
+
* This is mainly used for testing the archiver's ability to decode transactions that go through proxies.
|
|
19
|
+
*/
|
|
20
|
+
export class ForwarderL1TxUtils extends L1TxUtilsWithBlobs {
|
|
21
|
+
constructor(
|
|
22
|
+
client: ViemClient | ExtendedViemWalletClient,
|
|
23
|
+
senderAddress: EthAddress,
|
|
24
|
+
signingCallback: SigningCallback,
|
|
25
|
+
logger: Logger | undefined,
|
|
26
|
+
dateProvider: DateProvider | undefined,
|
|
27
|
+
config: Partial<L1TxUtilsConfig>,
|
|
28
|
+
debugMaxGasLimit: boolean,
|
|
29
|
+
store: IL1TxStore | undefined,
|
|
30
|
+
metrics: IL1TxMetrics | undefined,
|
|
31
|
+
private readonly forwarderAddress: EthAddress,
|
|
32
|
+
) {
|
|
33
|
+
super(client, senderAddress, signingCallback, logger, dateProvider, config, debugMaxGasLimit, store, metrics);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Wraps the transaction request in a call to the forwarder contract.
|
|
38
|
+
*/
|
|
39
|
+
private wrapInForwarder(request: L1TxRequest): L1TxRequest {
|
|
40
|
+
const forwarderCalldata = encodeFunctionData({
|
|
41
|
+
abi: FORWARDER_ABI,
|
|
42
|
+
functionName: 'forward',
|
|
43
|
+
args: [request.to as Hex, request.data as Hex],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
to: this.forwarderAddress.toString() as Hex,
|
|
48
|
+
data: forwarderCalldata,
|
|
49
|
+
value: request.value,
|
|
50
|
+
abi: request.abi, // Preserve the original ABI for error decoding
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Override sendAndMonitorTransaction to wrap the request in a forwarder call.
|
|
56
|
+
*/
|
|
57
|
+
public override sendAndMonitorTransaction(request: L1TxRequest, gasConfig?: L1TxConfig, blobInputs?: L1BlobInputs) {
|
|
58
|
+
this.logger.debug(`Wrapping transaction to ${request.to} in forwarder at ${this.forwarderAddress.toString()}`);
|
|
59
|
+
const wrappedRequest = this.wrapInForwarder(request);
|
|
60
|
+
return super.sendAndMonitorTransaction(wrappedRequest, gasConfig, blobInputs);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createForwarderL1TxUtilsFromViemWallet(
|
|
65
|
+
client: ExtendedViemWalletClient,
|
|
66
|
+
forwarderAddress: EthAddress,
|
|
67
|
+
deps: {
|
|
68
|
+
logger?: Logger;
|
|
69
|
+
dateProvider?: DateProvider;
|
|
70
|
+
store?: IL1TxStore;
|
|
71
|
+
metrics?: IL1TxMetrics;
|
|
72
|
+
} = {},
|
|
73
|
+
config: Partial<L1TxUtilsConfig> = {},
|
|
74
|
+
debugMaxGasLimit: boolean = false,
|
|
75
|
+
) {
|
|
76
|
+
return new ForwarderL1TxUtils(
|
|
77
|
+
client,
|
|
78
|
+
EthAddress.fromString(client.account.address),
|
|
79
|
+
createViemSigner(client),
|
|
80
|
+
deps.logger,
|
|
81
|
+
deps.dateProvider,
|
|
82
|
+
config,
|
|
83
|
+
debugMaxGasLimit,
|
|
84
|
+
deps.store,
|
|
85
|
+
deps.metrics,
|
|
86
|
+
forwarderAddress,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createForwarderL1TxUtilsFromEthSigner(
|
|
91
|
+
client: ViemClient,
|
|
92
|
+
signer: EthSigner,
|
|
93
|
+
forwarderAddress: EthAddress,
|
|
94
|
+
deps: {
|
|
95
|
+
logger?: Logger;
|
|
96
|
+
dateProvider?: DateProvider;
|
|
97
|
+
store?: IL1TxStore;
|
|
98
|
+
metrics?: IL1TxMetrics;
|
|
99
|
+
} = {},
|
|
100
|
+
config: Partial<L1TxUtilsConfig> = {},
|
|
101
|
+
debugMaxGasLimit: boolean = false,
|
|
102
|
+
) {
|
|
103
|
+
const callback: SigningCallback = async (transaction, _signingAddress) => {
|
|
104
|
+
return (await signer.signTransaction(transaction)).toViemTransactionSignature();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return new ForwarderL1TxUtils(
|
|
108
|
+
client,
|
|
109
|
+
signer.address,
|
|
110
|
+
callback,
|
|
111
|
+
deps.logger,
|
|
112
|
+
deps.dateProvider,
|
|
113
|
+
config,
|
|
114
|
+
debugMaxGasLimit,
|
|
115
|
+
deps.store,
|
|
116
|
+
deps.metrics,
|
|
117
|
+
forwarderAddress,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './config.js';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './factory.js';
|
|
4
|
+
export * from './fee-strategies/index.js';
|
|
5
|
+
export * from './interfaces.js';
|
|
6
|
+
export * from './l1_fee_analyzer.js';
|
|
7
|
+
export * from './l1_tx_utils.js';
|
|
8
|
+
export * from './readonly_l1_tx_utils.js';
|
|
9
|
+
export * from './signer.js';
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
export * from './utils.js';
|
|
12
|
+
|
|
13
|
+
// Note: We intentionally do not export l1_tx_utils_with_blobs.js
|
|
14
|
+
// to avoid accidentally importing blob-lib dependency.
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { L1BlobInputs, L1TxState } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interface for L1 transaction state storage.
|
|
5
|
+
* Implementations handle persistence of transaction states across restarts.
|
|
6
|
+
*/
|
|
7
|
+
export interface IL1TxStore {
|
|
8
|
+
/**
|
|
9
|
+
* Gets the next available state ID for an account.
|
|
10
|
+
*/
|
|
11
|
+
consumeNextStateId(account: string): Promise<number>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Saves a single transaction state for a specific account.
|
|
15
|
+
* Does not save blob data (see saveBlobs).
|
|
16
|
+
* @param account - The sender account address
|
|
17
|
+
* @param state - Transaction state to save
|
|
18
|
+
*/
|
|
19
|
+
saveState(account: string, state: L1TxState): Promise<L1TxState>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Saves blobs for a given state.
|
|
23
|
+
* @param account - The sender account address
|
|
24
|
+
* @param stateId - The state ID
|
|
25
|
+
* @param blobInputs - Blob inputs to save
|
|
26
|
+
*/
|
|
27
|
+
saveBlobs(account: string, stateId: number, blobInputs: L1BlobInputs | undefined): Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Loads all transaction states for a specific account.
|
|
31
|
+
* @param account - The sender account address
|
|
32
|
+
* @returns Array of transaction states with their IDs
|
|
33
|
+
*/
|
|
34
|
+
loadStates(account: string): Promise<L1TxState[]>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Loads a single state by ID.
|
|
38
|
+
* @param account - The sender account address
|
|
39
|
+
* @param stateId - The state ID
|
|
40
|
+
* @returns The transaction state or undefined if not found
|
|
41
|
+
*/
|
|
42
|
+
loadState(account: string, stateId: number): Promise<L1TxState | undefined>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deletes a specific state and its associated blobs.
|
|
46
|
+
* @param account - The sender account address
|
|
47
|
+
* @param stateId - The state ID to delete
|
|
48
|
+
*/
|
|
49
|
+
deleteState(account: string, ...stateId: number[]): Promise<void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Clears all transaction states for a specific account.
|
|
53
|
+
* @param account - The sender account address
|
|
54
|
+
*/
|
|
55
|
+
clearStates(account: string): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets all accounts that have stored states.
|
|
59
|
+
* @returns Array of account addresses
|
|
60
|
+
*/
|
|
61
|
+
getAllAccounts(): Promise<string[]>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Closes the store.
|
|
65
|
+
*/
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Interface for L1 transaction metrics recording.
|
|
71
|
+
* Implementations handle tracking of transaction lifecycle and gas costs.
|
|
72
|
+
*/
|
|
73
|
+
export interface IL1TxMetrics {
|
|
74
|
+
/**
|
|
75
|
+
* Records metrics when a transaction is mined
|
|
76
|
+
* @param state - The L1 transaction state
|
|
77
|
+
* @param l1Timestamp - The current L1 timestamp
|
|
78
|
+
*/
|
|
79
|
+
recordMinedTx(state: L1TxState, l1Timestamp: Date): void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Records metrics when a transaction is dropped
|
|
83
|
+
* @param state - The L1 transaction state
|
|
84
|
+
*/
|
|
85
|
+
recordDroppedTx(state: L1TxState): void;
|
|
86
|
+
}
|