@aztec/ethereum 0.0.0-test.0 → 0.0.1-commit.001888fc
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 +2 -0
- package/dest/account.d.ts.map +1 -0
- package/dest/account.js +4 -0
- package/dest/chain.d.ts +1 -1
- package/dest/client.d.ts +14 -4
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +27 -3
- package/dest/config.d.ts +70 -23
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +155 -34
- package/dest/constants.d.ts +1 -1
- package/dest/contracts/empire_base.d.ts +27 -8
- package/dest/contracts/empire_base.d.ts.map +1 -1
- package/dest/contracts/empire_base.js +75 -2
- package/dest/contracts/empire_slashing_proposer.d.ts +69 -0
- package/dest/contracts/empire_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/empire_slashing_proposer.js +216 -0
- package/dest/contracts/errors.d.ts +7 -0
- package/dest/contracts/errors.d.ts.map +1 -0
- package/dest/contracts/errors.js +12 -0
- package/dest/contracts/fee_asset_handler.d.ts +20 -0
- package/dest/contracts/fee_asset_handler.d.ts.map +1 -0
- package/dest/contracts/fee_asset_handler.js +59 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts +101 -0
- package/dest/contracts/fee_asset_price_oracle.d.ts.map +1 -0
- package/dest/contracts/fee_asset_price_oracle.js +651 -0
- package/dest/contracts/fee_juice.d.ts +6 -7
- package/dest/contracts/fee_juice.d.ts.map +1 -1
- package/dest/contracts/fee_juice.js +27 -20
- package/dest/contracts/governance.d.ts +45 -32
- package/dest/contracts/governance.d.ts.map +1 -1
- package/dest/contracts/governance.js +98 -85
- package/dest/contracts/governance_proposer.d.ts +19 -13
- package/dest/contracts/governance_proposer.d.ts.map +1 -1
- package/dest/contracts/governance_proposer.js +441 -26
- package/dest/contracts/gse.d.ts +32 -0
- package/dest/contracts/gse.d.ts.map +1 -0
- package/dest/contracts/gse.js +72 -0
- package/dest/contracts/inbox.d.ts +47 -0
- package/dest/contracts/inbox.d.ts.map +1 -0
- package/dest/contracts/inbox.js +80 -0
- package/dest/contracts/index.d.ts +12 -3
- package/dest/contracts/index.d.ts.map +1 -1
- package/dest/contracts/index.js +11 -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 +21 -0
- package/dest/contracts/multicall.d.ts.map +1 -0
- package/dest/contracts/multicall.js +157 -0
- package/dest/contracts/outbox.d.ts +41 -0
- package/dest/contracts/outbox.d.ts.map +1 -0
- package/dest/contracts/outbox.js +86 -0
- package/dest/contracts/registry.d.ts +12 -5
- package/dest/contracts/registry.d.ts.map +1 -1
- package/dest/contracts/registry.js +74 -17
- package/dest/contracts/rollup.d.ts +311 -53
- package/dest/contracts/rollup.d.ts.map +1 -1
- package/dest/contracts/rollup.js +1180 -116
- package/dest/contracts/slasher_contract.d.ts +44 -0
- package/dest/contracts/slasher_contract.d.ts.map +1 -0
- package/dest/contracts/slasher_contract.js +75 -0
- package/dest/contracts/tally_slashing_proposer.d.ts +140 -0
- package/dest/contracts/tally_slashing_proposer.d.ts.map +1 -0
- package/dest/contracts/tally_slashing_proposer.js +320 -0
- package/dest/contracts/utils.d.ts +3 -0
- package/dest/contracts/utils.d.ts.map +1 -0
- package/dest/contracts/utils.js +11 -0
- package/dest/deploy_aztec_l1_contracts.d.ts +259 -0
- package/dest/deploy_aztec_l1_contracts.d.ts.map +1 -0
- package/dest/deploy_aztec_l1_contracts.js +413 -0
- package/dest/deploy_l1_contract.d.ts +68 -0
- package/dest/deploy_l1_contract.d.ts.map +1 -0
- package/dest/deploy_l1_contract.js +312 -0
- package/dest/eth-signer/eth-signer.d.ts +21 -0
- package/dest/eth-signer/eth-signer.d.ts.map +1 -0
- package/dest/eth-signer/eth-signer.js +5 -0
- package/dest/eth-signer/index.d.ts +2 -0
- package/dest/eth-signer/index.d.ts.map +1 -0
- package/dest/eth-signer/index.js +1 -0
- package/dest/forwarder_proxy.d.ts +32 -0
- package/dest/forwarder_proxy.d.ts.map +1 -0
- package/dest/forwarder_proxy.js +93 -0
- package/dest/generated/l1-contracts-defaults.d.ts +30 -0
- package/dest/generated/l1-contracts-defaults.d.ts.map +1 -0
- package/dest/generated/l1-contracts-defaults.js +30 -0
- package/dest/l1_artifacts.d.ts +81744 -0
- package/dest/l1_artifacts.d.ts.map +1 -0
- package/dest/l1_artifacts.js +166 -0
- package/dest/l1_contract_addresses.d.ts +24 -4
- package/dest/l1_contract_addresses.d.ts.map +1 -1
- package/dest/l1_contract_addresses.js +25 -21
- package/dest/l1_reader.d.ts +6 -2
- package/dest/l1_reader.d.ts.map +1 -1
- package/dest/l1_reader.js +20 -9
- package/dest/l1_tx_utils/config.d.ts +65 -0
- package/dest/l1_tx_utils/config.d.ts.map +1 -0
- package/dest/l1_tx_utils/config.js +109 -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 +32 -0
- package/dest/l1_tx_utils/factory.d.ts.map +1 -0
- package/dest/l1_tx_utils/factory.js +22 -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 +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 +13 -0
- package/dest/l1_tx_utils/index.d.ts.map +1 -0
- package/dest/l1_tx_utils/index.js +13 -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 +105 -0
- package/dest/l1_tx_utils/l1_tx_utils.d.ts.map +1 -0
- package/dest/l1_tx_utils/l1_tx_utils.js +639 -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 +327 -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/tx_delayer.d.ts +56 -0
- package/dest/l1_tx_utils/tx_delayer.d.ts.map +1 -0
- package/dest/l1_tx_utils/tx_delayer.js +221 -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 +6 -0
- package/dest/l1_types.d.ts.map +1 -0
- package/dest/l1_types.js +1 -0
- package/dest/publisher_manager.d.ts +16 -0
- package/dest/publisher_manager.d.ts.map +1 -0
- package/dest/publisher_manager.js +88 -0
- package/dest/queries.d.ts +5 -3
- package/dest/queries.d.ts.map +1 -1
- package/dest/queries.js +61 -12
- package/dest/test/chain_monitor.d.ts +94 -0
- package/dest/test/chain_monitor.d.ts.map +1 -0
- package/dest/test/chain_monitor.js +244 -0
- package/dest/test/eth_cheat_codes.d.ts +229 -0
- package/dest/test/eth_cheat_codes.d.ts.map +1 -0
- package/dest/test/eth_cheat_codes.js +560 -0
- package/dest/test/eth_cheat_codes_with_state.d.ts +2 -2
- package/dest/test/eth_cheat_codes_with_state.d.ts.map +1 -1
- package/dest/test/eth_cheat_codes_with_state.js +1 -1
- package/dest/test/index.d.ts +4 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +3 -2
- package/dest/test/rollup_cheat_codes.d.ts +90 -0
- package/dest/test/rollup_cheat_codes.d.ts.map +1 -0
- package/dest/test/rollup_cheat_codes.js +292 -0
- package/dest/test/start_anvil.d.ts +23 -2
- package/dest/test/start_anvil.d.ts.map +1 -1
- package/dest/test/start_anvil.js +133 -24
- package/dest/test/upgrade_utils.d.ts +6 -5
- package/dest/test/upgrade_utils.d.ts.map +1 -1
- package/dest/test/upgrade_utils.js +23 -16
- package/dest/types.d.ts +62 -8
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -1
- package/dest/utils.d.ts +17 -3
- package/dest/utils.d.ts.map +1 -1
- package/dest/utils.js +111 -88
- package/dest/zkPassportVerifierAddress.d.ts +15 -0
- package/dest/zkPassportVerifierAddress.d.ts.map +1 -0
- package/dest/zkPassportVerifierAddress.js +11 -0
- package/package.json +51 -25
- package/src/account.ts +5 -0
- package/src/client.ts +51 -5
- package/src/config.ts +222 -43
- package/src/contracts/README.md +157 -0
- package/src/contracts/empire_base.ts +79 -7
- package/src/contracts/empire_slashing_proposer.ts +265 -0
- package/src/contracts/errors.ts +13 -0
- package/src/contracts/fee_asset_handler.ts +66 -0
- package/src/contracts/fee_asset_price_oracle.ts +280 -0
- package/src/contracts/fee_juice.ts +29 -15
- package/src/contracts/governance.ts +90 -78
- package/src/contracts/governance_proposer.ts +81 -25
- package/src/contracts/gse.ts +88 -0
- package/src/contracts/inbox.ts +115 -0
- package/src/contracts/index.ts +11 -2
- package/src/contracts/log.ts +13 -0
- package/src/contracts/multicall.ts +158 -0
- package/src/contracts/outbox.ts +98 -0
- package/src/contracts/registry.ts +81 -26
- package/src/contracts/rollup.ts +940 -89
- package/src/contracts/slasher_contract.ts +89 -0
- package/src/contracts/tally_slashing_proposer.ts +322 -0
- package/src/contracts/utils.ts +14 -0
- package/src/deploy_aztec_l1_contracts.ts +650 -0
- package/src/deploy_l1_contract.ts +362 -0
- package/src/eth-signer/eth-signer.ts +25 -0
- package/src/eth-signer/index.ts +1 -0
- package/src/forwarder_proxy.ts +108 -0
- package/src/generated/l1-contracts-defaults.ts +32 -0
- package/src/l1_artifacts.ts +254 -0
- package/src/l1_contract_addresses.ts +49 -34
- package/src/l1_reader.ts +30 -10
- package/src/l1_tx_utils/README.md +177 -0
- package/src/l1_tx_utils/config.ts +181 -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 +108 -0
- package/src/l1_tx_utils/index-blobs.ts +2 -0
- package/src/l1_tx_utils/index.ts +15 -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 +766 -0
- package/src/l1_tx_utils/readonly_l1_tx_utils.ts +423 -0
- package/src/l1_tx_utils/signer.ts +28 -0
- package/src/l1_tx_utils/tx_delayer.ts +294 -0
- package/src/l1_tx_utils/types.ts +85 -0
- package/src/l1_tx_utils/utils.ts +16 -0
- package/src/l1_types.ts +6 -0
- package/src/publisher_manager.ts +108 -0
- package/src/queries.ts +82 -16
- package/src/test/chain_monitor.ts +302 -0
- package/src/test/eth_cheat_codes.ts +588 -0
- package/src/test/eth_cheat_codes_with_state.ts +1 -1
- package/src/test/index.ts +3 -2
- package/src/test/rollup_cheat_codes.ts +330 -0
- package/src/test/start_anvil.ts +166 -22
- package/src/test/upgrade_utils.ts +30 -21
- package/src/types.ts +71 -7
- package/src/utils.ts +137 -93
- package/src/zkPassportVerifierAddress.ts +15 -0
- package/dest/contracts/forwarder.d.ts +0 -24
- package/dest/contracts/forwarder.d.ts.map +0 -1
- package/dest/contracts/forwarder.js +0 -101
- package/dest/contracts/slashing_proposer.d.ts +0 -21
- package/dest/contracts/slashing_proposer.d.ts.map +0 -1
- package/dest/contracts/slashing_proposer.js +0 -47
- package/dest/deploy_l1_contracts.d.ts +0 -21210
- package/dest/deploy_l1_contracts.d.ts.map +0 -1
- package/dest/deploy_l1_contracts.js +0 -687
- package/dest/eth_cheat_codes.d.ts +0 -147
- package/dest/eth_cheat_codes.d.ts.map +0 -1
- package/dest/eth_cheat_codes.js +0 -303
- package/dest/index.d.ts +0 -14
- package/dest/index.d.ts.map +0 -1
- package/dest/index.js +0 -13
- package/dest/l1_tx_utils.d.ts +0 -192
- package/dest/l1_tx_utils.d.ts.map +0 -1
- package/dest/l1_tx_utils.js +0 -641
- package/dest/l1_tx_utils_with_blobs.d.ts +0 -12
- package/dest/l1_tx_utils_with_blobs.d.ts.map +0 -1
- package/dest/l1_tx_utils_with_blobs.js +0 -64
- package/dest/test/delayed_tx_utils.d.ts +0 -8
- package/dest/test/delayed_tx_utils.d.ts.map +0 -1
- package/dest/test/delayed_tx_utils.js +0 -21
- package/dest/test/tx_delayer.d.ts +0 -25
- package/dest/test/tx_delayer.d.ts.map +0 -1
- package/dest/test/tx_delayer.js +0 -116
- package/src/contracts/forwarder.ts +0 -132
- package/src/contracts/slashing_proposer.ts +0 -51
- package/src/deploy_l1_contracts.ts +0 -948
- package/src/eth_cheat_codes.ts +0 -314
- package/src/index.ts +0 -13
- package/src/l1_tx_utils.ts +0 -847
- package/src/l1_tx_utils_with_blobs.ts +0 -86
- package/src/test/delayed_tx_utils.ts +0 -24
- package/src/test/tx_delayer.ts +0 -163
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import { getKeys, merge, pick, times } from '@aztec/foundation/collection';
|
|
2
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { makeBackoff, retry } from '@aztec/foundation/retry';
|
|
5
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
6
|
+
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
|
|
7
|
+
|
|
8
|
+
import pickBy from 'lodash.pickby';
|
|
9
|
+
import {
|
|
10
|
+
type Abi,
|
|
11
|
+
type Account,
|
|
12
|
+
type BaseError,
|
|
13
|
+
type BlockOverrides,
|
|
14
|
+
type ContractFunctionExecutionError,
|
|
15
|
+
type GetCodeReturnType,
|
|
16
|
+
type Hex,
|
|
17
|
+
MethodNotFoundRpcError,
|
|
18
|
+
MethodNotSupportedRpcError,
|
|
19
|
+
type StateOverride,
|
|
20
|
+
decodeErrorResult,
|
|
21
|
+
formatGwei,
|
|
22
|
+
getContractError,
|
|
23
|
+
hexToBytes,
|
|
24
|
+
} from 'viem';
|
|
25
|
+
|
|
26
|
+
import type { ViemClient } from '../types.js';
|
|
27
|
+
import { type L1TxUtilsConfig, defaultL1TxUtilsConfig, l1TxUtilsConfigMappings } from './config.js';
|
|
28
|
+
import {
|
|
29
|
+
BLOCK_TIME_MS,
|
|
30
|
+
MAX_L1_TX_LIMIT,
|
|
31
|
+
MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE,
|
|
32
|
+
MIN_REPLACEMENT_BUMP_PERCENTAGE,
|
|
33
|
+
WEI_CONST,
|
|
34
|
+
} from './constants.js';
|
|
35
|
+
import { P75AllTxsPriorityFeeStrategy, type PriorityFeeStrategy } from './fee-strategies/index.js';
|
|
36
|
+
import type { GasPrice, L1BlobInputs, L1TxRequest, TransactionStats } from './types.js';
|
|
37
|
+
import { getCalldataGasUsage, tryGetCustomErrorNameContractFunction } from './utils.js';
|
|
38
|
+
|
|
39
|
+
// Change this to the current strategy we want to use
|
|
40
|
+
const CurrentStrategy: PriorityFeeStrategy = P75AllTxsPriorityFeeStrategy;
|
|
41
|
+
|
|
42
|
+
export class ReadOnlyL1TxUtils {
|
|
43
|
+
public config: Required<L1TxUtilsConfig>;
|
|
44
|
+
protected interrupted = false;
|
|
45
|
+
|
|
46
|
+
constructor(
|
|
47
|
+
public client: ViemClient,
|
|
48
|
+
protected logger: Logger = createLogger('ethereum:readonly-l1-utils'),
|
|
49
|
+
public readonly dateProvider: DateProvider,
|
|
50
|
+
config?: Partial<L1TxUtilsConfig>,
|
|
51
|
+
protected debugMaxGasLimit: boolean = false,
|
|
52
|
+
) {
|
|
53
|
+
this.config = merge(defaultL1TxUtilsConfig, pick(config || {}, ...getKeys(l1TxUtilsConfigMappings)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public interrupt() {
|
|
57
|
+
this.interrupted = true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public restart() {
|
|
61
|
+
this.interrupted = false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getBlock() {
|
|
65
|
+
return this.client.getBlock();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public getBlockNumber() {
|
|
69
|
+
return this.client.getBlockNumber();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public getCode(address: EthAddress): Promise<GetCodeReturnType> {
|
|
73
|
+
return this.client.getCode({ address: address.toString() });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Gets the current gas price with bounds checking
|
|
78
|
+
*/
|
|
79
|
+
public async getGasPrice(
|
|
80
|
+
gasConfigOverrides?: L1TxUtilsConfig,
|
|
81
|
+
isBlobTx: boolean = false,
|
|
82
|
+
attempt: number = 0,
|
|
83
|
+
previousGasPrice?: typeof attempt extends 0 ? never : GasPrice,
|
|
84
|
+
): Promise<GasPrice> {
|
|
85
|
+
const gasConfig = merge(this.config, gasConfigOverrides);
|
|
86
|
+
|
|
87
|
+
// Execute strategy - it handles all RPC calls internally and returns everything we need
|
|
88
|
+
const strategyResult = await retry(
|
|
89
|
+
() =>
|
|
90
|
+
CurrentStrategy.execute(this.client, {
|
|
91
|
+
gasConfig,
|
|
92
|
+
isBlobTx,
|
|
93
|
+
logger: this.logger,
|
|
94
|
+
}),
|
|
95
|
+
'Executing priority fee strategy',
|
|
96
|
+
makeBackoff(times(2, () => 0)),
|
|
97
|
+
this.logger,
|
|
98
|
+
true,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const { latestBlock, blobBaseFee, priorityFee: strategyPriorityFee } = strategyResult;
|
|
102
|
+
|
|
103
|
+
// Extract base fee from latest block
|
|
104
|
+
const baseFee = latestBlock.baseFeePerGas ?? 0n;
|
|
105
|
+
|
|
106
|
+
// Handle blob base fee
|
|
107
|
+
if (isBlobTx && blobBaseFee === undefined) {
|
|
108
|
+
this.logger?.warn('Failed to get L1 blob base fee', attempt);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let priorityFee = strategyPriorityFee;
|
|
112
|
+
|
|
113
|
+
// Apply minimum priority fee floor if configured
|
|
114
|
+
if (gasConfig.minimumPriorityFeePerGas) {
|
|
115
|
+
const minimumPriorityFee = BigInt(Math.trunc(gasConfig.minimumPriorityFeePerGas * Number(WEI_CONST)));
|
|
116
|
+
if (priorityFee < minimumPriorityFee) {
|
|
117
|
+
this.logger?.debug('Applying minimum priority fee floor', {
|
|
118
|
+
calculatedPriorityFee: formatGwei(priorityFee),
|
|
119
|
+
minimumPriorityFeePerGas: gasConfig.minimumPriorityFeePerGas,
|
|
120
|
+
appliedFee: formatGwei(minimumPriorityFee),
|
|
121
|
+
});
|
|
122
|
+
priorityFee = minimumPriorityFee;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
let maxFeePerGas = baseFee;
|
|
126
|
+
|
|
127
|
+
let maxFeePerBlobGas = blobBaseFee ?? 0n;
|
|
128
|
+
|
|
129
|
+
// Bump base fee so it's valid for next blocks if it stalls
|
|
130
|
+
const numBlocks = Math.ceil(gasConfig.stallTimeMs! / BLOCK_TIME_MS);
|
|
131
|
+
for (let i = 0; i < numBlocks; i++) {
|
|
132
|
+
// each block can go up 12.5% from previous baseFee
|
|
133
|
+
// ceil, (a+b-1)/b, to avoid truncation at small values (e.g. 1 wei blob base fee)
|
|
134
|
+
maxFeePerGas = (maxFeePerGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
135
|
+
// same for blob gas fee
|
|
136
|
+
maxFeePerBlobGas = (maxFeePerBlobGas * (1_000n + 125n) + 999n) / 1_000n;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (attempt > 0) {
|
|
140
|
+
const configBump =
|
|
141
|
+
gasConfig.priorityFeeRetryBumpPercentage ?? defaultL1TxUtilsConfig.priorityFeeRetryBumpPercentage!;
|
|
142
|
+
|
|
143
|
+
// if this is a blob tx, we have to use the blob bump percentage
|
|
144
|
+
const minBumpPercentage = isBlobTx ? MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE : MIN_REPLACEMENT_BUMP_PERCENTAGE;
|
|
145
|
+
|
|
146
|
+
const bumpPercentage = configBump > minBumpPercentage ? configBump : minBumpPercentage;
|
|
147
|
+
// Calculate minimum required fees based on previous attempt
|
|
148
|
+
// multiply by 100 & divide by 100 to maintain some precision
|
|
149
|
+
const minPriorityFee =
|
|
150
|
+
(previousGasPrice!.maxPriorityFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
151
|
+
const minMaxFee = (previousGasPrice!.maxFeePerGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
152
|
+
|
|
153
|
+
// Apply bump percentage to competitive fee
|
|
154
|
+
const competitivePriorityFee = (priorityFee * (100_00n + BigInt(configBump * 1_00))) / 100_00n;
|
|
155
|
+
|
|
156
|
+
this.logger?.debug(`Speed-up attempt ${attempt}: using competitive fee strategy`, {
|
|
157
|
+
networkEstimate: formatGwei(priorityFee),
|
|
158
|
+
competitiveFee: formatGwei(competitivePriorityFee),
|
|
159
|
+
minRequired: formatGwei(minPriorityFee),
|
|
160
|
+
bumpPercentage: configBump,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Use maximum between competitive fee and minimum required bump
|
|
164
|
+
const finalPriorityFee = competitivePriorityFee > minPriorityFee ? competitivePriorityFee : minPriorityFee;
|
|
165
|
+
const feeSource = finalPriorityFee === competitivePriorityFee ? 'competitive' : 'minimum-bump';
|
|
166
|
+
|
|
167
|
+
priorityFee = finalPriorityFee;
|
|
168
|
+
// Add the final priority fee to maxFeePerGas
|
|
169
|
+
maxFeePerGas += finalPriorityFee;
|
|
170
|
+
maxFeePerGas = maxFeePerGas > minMaxFee ? maxFeePerGas : minMaxFee;
|
|
171
|
+
|
|
172
|
+
this.logger?.debug(`Speed-up fee decision: using ${feeSource} fee`, {
|
|
173
|
+
finalPriorityFee: formatGwei(finalPriorityFee),
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
// First attempt: apply configured bump percentage to competitive fee
|
|
177
|
+
// multiply by 100 & divide by 100 to maintain some precision
|
|
178
|
+
priorityFee = (priorityFee * (100_00n + BigInt((gasConfig.priorityFeeBumpPercentage || 0) * 1_00))) / 100_00n;
|
|
179
|
+
this.logger?.debug('Initial transaction: using competitive fee from market analysis', {
|
|
180
|
+
networkEstimate: formatGwei(priorityFee),
|
|
181
|
+
});
|
|
182
|
+
maxFeePerGas += priorityFee;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// maxGwei and maxBlobGwei are hard limits
|
|
186
|
+
const effectiveMaxGwei = BigInt(Math.trunc(gasConfig.maxGwei! * Number(WEI_CONST)));
|
|
187
|
+
const effectiveMaxBlobGwei = BigInt(Math.trunc(gasConfig.maxBlobGwei! * Number(WEI_CONST)));
|
|
188
|
+
|
|
189
|
+
// Ensure we don't exceed maxGwei
|
|
190
|
+
if (effectiveMaxGwei > 0n) {
|
|
191
|
+
maxFeePerGas = maxFeePerGas > effectiveMaxGwei ? effectiveMaxGwei : maxFeePerGas;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Ensure we don't exceed maxBlobGwei
|
|
195
|
+
if (maxFeePerBlobGas && effectiveMaxBlobGwei > 0n) {
|
|
196
|
+
maxFeePerBlobGas = maxFeePerBlobGas > effectiveMaxBlobGwei ? effectiveMaxBlobGwei : maxFeePerBlobGas;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Ensure priority fee doesn't exceed max fee
|
|
200
|
+
const maxPriorityFeePerGas = priorityFee > maxFeePerGas ? maxFeePerGas : priorityFee;
|
|
201
|
+
|
|
202
|
+
if (attempt > 0 && previousGasPrice?.maxFeePerBlobGas) {
|
|
203
|
+
const bumpPercentage =
|
|
204
|
+
gasConfig.priorityFeeRetryBumpPercentage! > MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE
|
|
205
|
+
? gasConfig.priorityFeeRetryBumpPercentage!
|
|
206
|
+
: MIN_BLOB_REPLACEMENT_BUMP_PERCENTAGE;
|
|
207
|
+
|
|
208
|
+
// calculate min blob fee based on previous attempt
|
|
209
|
+
const minBlobFee = (previousGasPrice.maxFeePerBlobGas * (100_00n + BigInt(bumpPercentage * 1_00))) / 100_00n;
|
|
210
|
+
|
|
211
|
+
// use max between current network values and min required values
|
|
212
|
+
maxFeePerBlobGas = maxFeePerBlobGas > minBlobFee ? maxFeePerBlobGas : minBlobFee;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
this.logger?.trace(
|
|
216
|
+
`Computed L1 gas price max fee ${formatGwei(maxFeePerGas)} and max priority fee ${formatGwei(maxPriorityFeePerGas)}`,
|
|
217
|
+
{
|
|
218
|
+
attempt,
|
|
219
|
+
baseFee: formatGwei(baseFee),
|
|
220
|
+
maxFeePerGas: formatGwei(maxFeePerGas),
|
|
221
|
+
maxPriorityFeePerGas: formatGwei(maxPriorityFeePerGas),
|
|
222
|
+
blobBaseFee: formatGwei(blobBaseFee ?? 0n),
|
|
223
|
+
maxFeePerBlobGas: formatGwei(maxFeePerBlobGas),
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
maxFeePerGas,
|
|
229
|
+
maxPriorityFeePerGas,
|
|
230
|
+
...(maxFeePerBlobGas && { maxFeePerBlobGas: maxFeePerBlobGas }),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Estimates gas and adds buffer
|
|
236
|
+
*/
|
|
237
|
+
public async estimateGas(
|
|
238
|
+
account: Account | Hex,
|
|
239
|
+
request: L1TxRequest,
|
|
240
|
+
_gasConfig?: L1TxUtilsConfig,
|
|
241
|
+
_blobInputs?: L1BlobInputs,
|
|
242
|
+
): Promise<bigint> {
|
|
243
|
+
const gasConfig = { ...this.config, ..._gasConfig };
|
|
244
|
+
let initialEstimate = 0n;
|
|
245
|
+
if (_blobInputs) {
|
|
246
|
+
// @note requests with blobs also require maxFeePerBlobGas to be set.
|
|
247
|
+
// Use 2x buffer for maxFeePerBlobGas to avoid stale fees and to pass EIP-4844 validation (even if it is a gas estimation call).
|
|
248
|
+
// 1. maxFeePerBlobGas >= blobBaseFee
|
|
249
|
+
// 2. account balance >= gas * maxFeePerGas + maxFeePerBlobGas * blobCount + value
|
|
250
|
+
const gasPrice = await this.getGasPrice(gasConfig, true, 0);
|
|
251
|
+
initialEstimate = await this.client.estimateGas({
|
|
252
|
+
account,
|
|
253
|
+
...request,
|
|
254
|
+
..._blobInputs,
|
|
255
|
+
maxFeePerBlobGas: gasPrice.maxFeePerBlobGas! * 2n,
|
|
256
|
+
gas: MAX_L1_TX_LIMIT,
|
|
257
|
+
blockTag: 'latest',
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
this.logger?.trace(`Estimated gas for blob tx: ${initialEstimate}`);
|
|
261
|
+
} else {
|
|
262
|
+
initialEstimate = await this.client.estimateGas({
|
|
263
|
+
account,
|
|
264
|
+
...request,
|
|
265
|
+
gas: MAX_L1_TX_LIMIT,
|
|
266
|
+
blockTag: 'latest',
|
|
267
|
+
});
|
|
268
|
+
this.logger?.trace(`Estimated gas for non-blob tx: ${initialEstimate}`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Add buffer based on either fixed amount or percentage
|
|
272
|
+
const withBuffer = this.bumpGasLimit(initialEstimate, gasConfig);
|
|
273
|
+
|
|
274
|
+
return withBuffer;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async getTransactionStats(txHash: string): Promise<TransactionStats | undefined> {
|
|
278
|
+
const tx = await this.client.getTransaction({ hash: txHash as Hex });
|
|
279
|
+
if (!tx) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
const calldata = hexToBytes(tx.input);
|
|
283
|
+
return {
|
|
284
|
+
sender: tx.from.toString(),
|
|
285
|
+
transactionHash: tx.hash,
|
|
286
|
+
calldataSize: calldata.length,
|
|
287
|
+
calldataGas: getCalldataGasUsage(calldata),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public async tryGetErrorFromRevertedTx(
|
|
292
|
+
data: Hex,
|
|
293
|
+
args: {
|
|
294
|
+
args: readonly any[];
|
|
295
|
+
functionName: string;
|
|
296
|
+
abi: Abi;
|
|
297
|
+
address: Hex;
|
|
298
|
+
},
|
|
299
|
+
blobInputs: (L1BlobInputs & { maxFeePerBlobGas: bigint }) | undefined,
|
|
300
|
+
stateOverride: StateOverride = [],
|
|
301
|
+
) {
|
|
302
|
+
try {
|
|
303
|
+
await this.client.simulateContract({
|
|
304
|
+
...args,
|
|
305
|
+
account: this.client.account,
|
|
306
|
+
stateOverride,
|
|
307
|
+
});
|
|
308
|
+
this.logger?.trace('Simulated blob tx', { blobInputs });
|
|
309
|
+
// If the above passes, we have a blob error. We cannot simulate blob txs, and failed txs no longer throw errors.
|
|
310
|
+
// Strangely, the only way to throw the revert reason as an error and provide blobs is prepareTransactionRequest.
|
|
311
|
+
// See: https://github.com/wevm/viem/issues/2075
|
|
312
|
+
// This throws a EstimateGasExecutionError with the custom error information:
|
|
313
|
+
const request = blobInputs
|
|
314
|
+
? {
|
|
315
|
+
account: this.client.account,
|
|
316
|
+
to: args.address,
|
|
317
|
+
data,
|
|
318
|
+
blobs: blobInputs.blobs,
|
|
319
|
+
kzg: blobInputs.kzg,
|
|
320
|
+
maxFeePerBlobGas: blobInputs.maxFeePerBlobGas,
|
|
321
|
+
}
|
|
322
|
+
: {
|
|
323
|
+
account: this.client.account,
|
|
324
|
+
to: args.address,
|
|
325
|
+
data,
|
|
326
|
+
};
|
|
327
|
+
this.logger?.trace('Preparing tx', { request });
|
|
328
|
+
await this.client.prepareTransactionRequest(request);
|
|
329
|
+
this.logger?.trace('Prepared tx');
|
|
330
|
+
return undefined;
|
|
331
|
+
} catch (simulationErr: any) {
|
|
332
|
+
// If we don't have a ContractFunctionExecutionError, we have a blob related error => use getContractError to get the error msg.
|
|
333
|
+
const contractErr =
|
|
334
|
+
simulationErr.name === 'ContractFunctionExecutionError'
|
|
335
|
+
? simulationErr
|
|
336
|
+
: getContractError(simulationErr as BaseError, {
|
|
337
|
+
args: [],
|
|
338
|
+
abi: args.abi,
|
|
339
|
+
functionName: args.functionName,
|
|
340
|
+
address: args.address,
|
|
341
|
+
});
|
|
342
|
+
if (contractErr.name === 'ContractFunctionExecutionError') {
|
|
343
|
+
const execErr = contractErr as ContractFunctionExecutionError;
|
|
344
|
+
return tryGetCustomErrorNameContractFunction(execErr);
|
|
345
|
+
}
|
|
346
|
+
this.logger?.error(`Error getting error from simulation`, simulationErr);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
public async simulate(
|
|
351
|
+
request: L1TxRequest & { gas?: bigint; from?: Hex },
|
|
352
|
+
blockOverrides: BlockOverrides<bigint, number> = {},
|
|
353
|
+
stateOverrides: StateOverride = [],
|
|
354
|
+
abi: Abi = RollupAbi,
|
|
355
|
+
_gasConfig?: L1TxUtilsConfig & { fallbackGasEstimate?: bigint },
|
|
356
|
+
): Promise<{ gasUsed: bigint; result: `0x${string}` }> {
|
|
357
|
+
const gasConfig = { ...this.config, ..._gasConfig };
|
|
358
|
+
|
|
359
|
+
const call: any = {
|
|
360
|
+
to: request.to!,
|
|
361
|
+
data: request.data,
|
|
362
|
+
...(request.from && { from: request.from }),
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
return await this._simulate(call, blockOverrides, stateOverrides, gasConfig, abi);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
protected async _simulate(
|
|
369
|
+
call: any,
|
|
370
|
+
blockOverrides: BlockOverrides<bigint, number> = {},
|
|
371
|
+
stateOverrides: StateOverride = [],
|
|
372
|
+
gasConfig: L1TxUtilsConfig & { fallbackGasEstimate?: bigint },
|
|
373
|
+
abi: Abi,
|
|
374
|
+
) {
|
|
375
|
+
try {
|
|
376
|
+
const result = await this.client.simulateBlocks({
|
|
377
|
+
validation: false,
|
|
378
|
+
blocks: [
|
|
379
|
+
{
|
|
380
|
+
blockOverrides,
|
|
381
|
+
stateOverrides,
|
|
382
|
+
calls: [call],
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
if (result[0].calls[0].status === 'failure') {
|
|
388
|
+
this.logger?.error('L1 transaction simulation failed', result[0].calls[0].error);
|
|
389
|
+
const decodedError = decodeErrorResult({ abi, data: result[0].calls[0].data });
|
|
390
|
+
|
|
391
|
+
throw new Error(
|
|
392
|
+
`L1 transaction simulation failed with error ${decodedError.errorName}(${decodedError.args?.join(',')})`,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
this.logger?.debug(`L1 transaction simulation succeeded`, { ...result[0].calls[0] });
|
|
396
|
+
return { gasUsed: result[0].gasUsed, result: result[0].calls[0].data as `0x${string}` };
|
|
397
|
+
} catch (err) {
|
|
398
|
+
if (err instanceof MethodNotFoundRpcError || err instanceof MethodNotSupportedRpcError) {
|
|
399
|
+
if (gasConfig.fallbackGasEstimate) {
|
|
400
|
+
this.logger?.warn(
|
|
401
|
+
`Node does not support eth_simulateV1 API. Using fallback gas estimate: ${gasConfig.fallbackGasEstimate}`,
|
|
402
|
+
);
|
|
403
|
+
return { gasUsed: gasConfig.fallbackGasEstimate, result: '0x' as `0x${string}` };
|
|
404
|
+
}
|
|
405
|
+
this.logger?.error('Node does not support eth_simulateV1 API');
|
|
406
|
+
}
|
|
407
|
+
throw err;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
public bumpGasLimit(gasLimit: bigint, _gasConfig?: L1TxUtilsConfig): bigint {
|
|
412
|
+
const gasConfig = { ...this.config, ..._gasConfig };
|
|
413
|
+
const bumpedGasLimit = gasLimit + (gasLimit * BigInt((gasConfig?.gasLimitBufferPercentage || 0) * 1_00)) / 100_00n;
|
|
414
|
+
|
|
415
|
+
const cleanGasConfig = pickBy(gasConfig, (_, key) => key in l1TxUtilsConfigMappings);
|
|
416
|
+
this.logger?.trace(`Bumping gas limit from ${gasLimit} to ${bumpedGasLimit}`, {
|
|
417
|
+
gasLimit,
|
|
418
|
+
gasConfig: cleanGasConfig,
|
|
419
|
+
bumpedGasLimit,
|
|
420
|
+
});
|
|
421
|
+
return bumpedGasLimit;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
+
import type { ViemTransactionSignature } from '@aztec/foundation/eth-signature';
|
|
3
|
+
|
|
4
|
+
import { type TransactionSerializable, type WalletClient, parseTransaction } from 'viem';
|
|
5
|
+
|
|
6
|
+
import type { SigningCallback } from './types.js';
|
|
7
|
+
|
|
8
|
+
export function createViemSigner(client: WalletClient) {
|
|
9
|
+
const signer: SigningCallback = async (
|
|
10
|
+
tx: TransactionSerializable,
|
|
11
|
+
_address: EthAddress,
|
|
12
|
+
): Promise<ViemTransactionSignature> => {
|
|
13
|
+
const signedTx = await client.signTransaction(tx as any);
|
|
14
|
+
|
|
15
|
+
const parsed = parseTransaction(signedTx);
|
|
16
|
+
|
|
17
|
+
if (!parsed.r || !parsed.s || (parsed.yParity !== 0 && parsed.yParity !== 1)) {
|
|
18
|
+
throw new Error('Failed to extract signature from viem signed transaction');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
r: parsed.r,
|
|
23
|
+
s: parsed.s,
|
|
24
|
+
yParity: parsed.yParity,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
return signer;
|
|
28
|
+
}
|