From 57c24e21eb14b214d277d43236c62f96573b422b Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 28 Aug 2023 03:41:50 -0700 Subject: [PATCH] Add parameters to modify gas price bump percent and gas limit bump percent in getGas and getGasParams functions --- src/feeOracle.ts | 24 +++++++++++++++++++----- src/types.ts | 16 ++++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/feeOracle.ts b/src/feeOracle.ts index f0c29d3..6e04d64 100644 --- a/src/feeOracle.ts +++ b/src/feeOracle.ts @@ -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} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee' */ async getGasParams( tx?: TransactionData, txType: TxType = 'other', + bumpGasLimitPercent?: number, + bumpGasPricePercent?: number, speed: LegacyGasPriceKey = 'fast', ): Promise { 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} Gas value in WEI (hex-format) */ async getGas( tx?: TransactionData, txType: TxType = 'other', + bumpGasLimitPercent?: number, + bumpGasPricePercent?: number, speed: LegacyGasPriceKey = 'fast', ): Promise { - 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} Estimated gas price info in WEI (hexed) - legacy object with gasPrice property or * EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties */ diff --git a/src/types.ts b/src/types.ts index fc77731..3457859 100644 --- a/src/types.ts +++ b/src/types.ts @@ -35,8 +35,20 @@ export interface TransactionData { } export interface ITornadoFeeOracle { - getGasParams: (tx?: TransactionData, txType?: TxType, speed?: LegacyGasPriceKey) => Promise; - getGas: (tx?: TransactionData, type?: TxType) => Promise; + getGasParams: ( + tx?: TransactionData, + txType?: TxType, + bumpGasLimitPercent?: number, + bumpGasPricePercent?: number, + speed?: LegacyGasPriceKey, + ) => Promise; + getGas: ( + tx?: TransactionData, + type?: TxType, + bumpGasLimitPercent?: number, + bumpGasPricePercent?: number, + speed?: LegacyGasPriceKey, + ) => Promise; getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise; getGasPrice: ( type?: TxType,