|
|
|
|
@@ -46,17 +46,21 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|
|
|
|
* Estimate gas price, gas limit and l1Fee for sidechain (if exists)
|
|
|
|
|
* @param {TransactionData} [tx] Transaction data in web3 / ethers format
|
|
|
|
|
* @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other'
|
|
|
|
|
* @param {number} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
|
|
|
|
|
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely used)
|
|
|
|
|
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
|
|
|
|
|
* @returns {Promise<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee'
|
|
|
|
|
*/
|
|
|
|
|
async getGasParams(
|
|
|
|
|
tx?: TransactionData,
|
|
|
|
|
txType: TxType = 'other',
|
|
|
|
|
bumpGasLimitPercent?: number,
|
|
|
|
|
bumpGasPricePercent?: number,
|
|
|
|
|
speed: LegacyGasPriceKey = 'fast',
|
|
|
|
|
): Promise<GetGasParamsRes> {
|
|
|
|
|
const [gasPrice, gasLimit, l1Fee] = await Promise.all([
|
|
|
|
|
this.getGasPrice(txType, speed),
|
|
|
|
|
this.getGasLimit(tx, txType),
|
|
|
|
|
this.getGasPrice(txType, speed, bumpGasPricePercent),
|
|
|
|
|
this.getGasLimit(tx, txType, bumpGasLimitPercent),
|
|
|
|
|
this.fetchL1OptimismFee(tx),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
@@ -67,15 +71,25 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|
|
|
|
* Estimates next block gas for signed, unsigned or incomplete Tornado transaction
|
|
|
|
|
* @param {TransactionData} [tx] Transaction data in web3 / ethers format
|
|
|
|
|
* @param {TxType} [txType=other] Tornado transaction type: withdrawal by user, withdrawal by relayer or 'other'
|
|
|
|
|
* @param {number} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
|
|
|
|
|
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely used)
|
|
|
|
|
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
|
|
|
|
|
* @returns {Promise<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format)
|
|
|
|
|
*/
|
|
|
|
|
async getGas(
|
|
|
|
|
tx?: TransactionData,
|
|
|
|
|
txType: TxType = 'other',
|
|
|
|
|
bumpGasLimitPercent?: number,
|
|
|
|
|
bumpGasPricePercent?: number,
|
|
|
|
|
speed: LegacyGasPriceKey = 'fast',
|
|
|
|
|
): Promise<HexadecimalStringifiedNumber> {
|
|
|
|
|
const { gasPrice, gasLimit, l1Fee } = await this.getGasParams(tx, txType, speed);
|
|
|
|
|
const { gasPrice, gasLimit, l1Fee } = await this.getGasParams(
|
|
|
|
|
tx,
|
|
|
|
|
txType,
|
|
|
|
|
bumpGasLimitPercent,
|
|
|
|
|
bumpGasPricePercent,
|
|
|
|
|
speed,
|
|
|
|
|
);
|
|
|
|
|
const gas = BigNumber.from(gasPrice).mul(gasLimit).add(l1Fee);
|
|
|
|
|
|
|
|
|
|
return gas.toHexString();
|
|
|
|
|
@@ -84,8 +98,8 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|
|
|
|
/**
|
|
|
|
|
* Estimate next block gas price
|
|
|
|
|
* @param {TxType} type Tornado transaction type (to select correct default bump percent)
|
|
|
|
|
* @param {LegacyGasPriceKey} speed Preferred transaction speed, if uses legacy gas (before EIP-1559)
|
|
|
|
|
* @param {number} bumpPercent Gas bump percent to prioritize transaction
|
|
|
|
|
* @param {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
|
|
|
|
|
* @param {number} [bumpPercent=0] Gas bump percent to prioritize transaction
|
|
|
|
|
* @returns {Promise<GasPriceParams>} Estimated gas price info in WEI (hexed) - legacy object with gasPrice property or
|
|
|
|
|
* EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties
|
|
|
|
|
*/
|
|
|
|
|
@@ -111,7 +125,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|
|
|
|
async getGasPrice(
|
|
|
|
|
type: TxType = 'other',
|
|
|
|
|
speed: LegacyGasPriceKey = 'fast',
|
|
|
|
|
bumpPercent: number = 0,
|
|
|
|
|
bumpPercent?: number,
|
|
|
|
|
): Promise<HexadecimalStringifiedNumber> {
|
|
|
|
|
const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent);
|
|
|
|
|
return calculateGasPriceInWei(gasPriceParams).toHexString();
|
|
|
|
|
|