diff --git a/package.json b/package.json index 30bb7ce..6c11dff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tornado/tornado-oracles", - "version": "1.4.2", + "version": "2.0.0", "description": "Gas oracle for Tornado-specific transactions", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/src/feeOracle.ts b/src/feeOracle.ts index cc41cba..aa8e2d8 100644 --- a/src/feeOracle.ts +++ b/src/feeOracle.ts @@ -48,7 +48,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle { * @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) + * @param {LegacyGasPriceKey} [speed] Preferred transaction speed, if uses legacy gas (before EIP-1559) * @returns {Promise} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee' */ async getGasParams( @@ -56,10 +56,10 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle { txType: TxType = 'other', bumpGasLimitPercent?: number, bumpGasPricePercent?: number, - speed: LegacyGasPriceKey = 'fast', + speed?: LegacyGasPriceKey, ): Promise { const [gasPrice, gasLimit, l1Fee] = await Promise.all([ - this.getGasPrice(txType, speed, bumpGasPricePercent), + this.getGasPrice(speed, bumpGasPricePercent), this.getGasLimit(tx, txType, bumpGasLimitPercent), this.fetchL1OptimismFee(tx), ]); @@ -73,7 +73,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle { * @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) + * @param {LegacyGasPriceKey} [speed] Preferred transaction speed, if uses legacy gas (before EIP-1559) * @returns {Promise} Gas value in WEI (hex-format) */ async getGas( @@ -81,7 +81,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle { txType: TxType = 'other', bumpGasLimitPercent?: number, bumpGasPricePercent?: number, - speed: LegacyGasPriceKey = 'fast', + speed?: LegacyGasPriceKey, ): Promise { const { gasPrice, gasLimit, l1Fee } = await this.getGasParams( tx, @@ -97,17 +97,14 @@ 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=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559) + * @param {LegacyGasPriceKey} [speed] 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 */ - async getGasPriceParams( - type: TxType = 'other', - speed: LegacyGasPriceKey = 'fast', - bumpPercent: number = 0, - ): Promise { + async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent: number = 0): Promise { + // Use instant for BSC, because on this chain "fast" and "instant" differs more than third and "fast" transaction can take hours + if (!speed) speed = this.chainId === ChainId.BSC ? 'instant' : 'fast'; try { return await this.oracle.getTxGasParams({ legacySpeed: speed, bumpPercent }); } catch (e) { @@ -117,17 +114,12 @@ 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 * @returns {Promise} Gas price in WEI (hex string) */ - async getGasPrice( - type: TxType = 'other', - speed: LegacyGasPriceKey = 'fast', - bumpPercent?: number, - ): Promise { - const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent); + async getGasPrice(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise { + const gasPriceParams = await this.getGasPriceParams(speed, bumpPercent); return calculateGasPriceInWei(gasPriceParams).toHexString(); } diff --git a/src/feeOracleV5.ts b/src/feeOracleV5.ts index 9b29a72..3bff8f6 100644 --- a/src/feeOracleV5.ts +++ b/src/feeOracleV5.ts @@ -49,16 +49,12 @@ export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeO } } - async getGasPriceParams( - type: TxType = 'other', - speed: LegacyGasPriceKey = 'fast', - bumpPercent?: number, - ): Promise { + async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise { // Only if bump percent didn't provided (if user provides 0, no need to recalculate) if (bumpPercent === undefined) { switch (this.chainId) { case ChainId.GOERLI: - bumpPercent = type === 'user_withdrawal' ? 100 : 50; + bumpPercent = 100; break; case ChainId.POLYGON: case ChainId.AVAX: @@ -70,6 +66,6 @@ export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeO } } - return super.getGasPriceParams(type, speed, bumpPercent); + return super.getGasPriceParams(speed, bumpPercent); } } diff --git a/src/types.ts b/src/types.ts index 3457859..5f7f089 100644 --- a/src/types.ts +++ b/src/types.ts @@ -49,12 +49,8 @@ export interface ITornadoFeeOracle { bumpGasPricePercent?: number, speed?: LegacyGasPriceKey, ) => Promise; - getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise; - getGasPrice: ( - type?: TxType, - speed?: LegacyGasPriceKey, - bumpPercent?: number, - ) => Promise; + getGasPriceParams: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise; + getGasPrice: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise; getGasLimit: (tx?: TransactionData, type?: TxType, bumpPercent?: number) => Promise; fetchL1OptimismFee: (tx?: TransactionData) => Promise; calculateRefundInETH: (tokenSymbol: InstanceTokenSymbol) => Promise;