Bump library version to 2.0.0:

- Fix BSC gas price estimation: use 'instant' price for gas instead of 'fast', because 'fast' is about 1 GWEI, and 'instant' about 3 GWEI, and 'fast' transaction can take more than 2-3 hours to execute
	- Remove unnecessary parameter type in all functions that used to get gas price(-s)
This commit is contained in:
Theo 2023-08-28 09:51:21 -07:00
parent 90471e0073
commit 0d3ea02015
4 changed files with 17 additions and 33 deletions

@ -1,6 +1,6 @@
{ {
"name": "@tornado/tornado-oracles", "name": "@tornado/tornado-oracles",
"version": "1.4.2", "version": "2.0.0",
"description": "Gas oracle for Tornado-specific transactions", "description": "Gas oracle for Tornado-specific transactions",
"main": "./lib/index.js", "main": "./lib/index.js",
"types": "./lib/index.d.ts", "types": "./lib/index.d.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 {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} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely 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<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee' * @returns {Promise<GetGasParamsRes>} Object with fields 'gasPrice', 'gasLimit' and 'l1Fee'
*/ */
async getGasParams( async getGasParams(
@ -56,10 +56,10 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
txType: TxType = 'other', txType: TxType = 'other',
bumpGasLimitPercent?: number, bumpGasLimitPercent?: number,
bumpGasPricePercent?: number, bumpGasPricePercent?: number,
speed: LegacyGasPriceKey = 'fast', speed?: LegacyGasPriceKey,
): Promise<GetGasParamsRes> { ): Promise<GetGasParamsRes> {
const [gasPrice, gasLimit, l1Fee] = await Promise.all([ const [gasPrice, gasLimit, l1Fee] = await Promise.all([
this.getGasPrice(txType, speed, bumpGasPricePercent), this.getGasPrice(speed, bumpGasPricePercent),
this.getGasLimit(tx, txType, bumpGasLimitPercent), this.getGasLimit(tx, txType, bumpGasLimitPercent),
this.fetchL1OptimismFee(tx), 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 {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} [bumpGasLimitPercent] Gas limit bump percent to prioritize transaction (recenlty used)
* @param {number} [bumpGasPricePercent] Gas price bump percent to prioritize transaction (rarely 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<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format) * @returns {Promise<HexadecimalStringifiedNumber>} Gas value in WEI (hex-format)
*/ */
async getGas( async getGas(
@ -81,7 +81,7 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
txType: TxType = 'other', txType: TxType = 'other',
bumpGasLimitPercent?: number, bumpGasLimitPercent?: number,
bumpGasPricePercent?: number, bumpGasPricePercent?: number,
speed: LegacyGasPriceKey = 'fast', speed?: LegacyGasPriceKey,
): Promise<HexadecimalStringifiedNumber> { ): Promise<HexadecimalStringifiedNumber> {
const { gasPrice, gasLimit, l1Fee } = await this.getGasParams( const { gasPrice, gasLimit, l1Fee } = await this.getGasParams(
tx, tx,
@ -97,17 +97,14 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
/** /**
* Estimate next block gas price * 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 {LegacyGasPriceKey} [speed=fast] Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @param {number} [bumpPercent=0] Gas bump percent to prioritize transaction * @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 * @returns {Promise<GasPriceParams>} Estimated gas price info in WEI (hexed) - legacy object with gasPrice property or
* EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties * EIP-1559 object with maxFeePerGas and maxPriorityFeePerGas properties
*/ */
async getGasPriceParams( async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent: number = 0): Promise<GasPriceParams> {
type: TxType = 'other', // Use instant for BSC, because on this chain "fast" and "instant" differs more than third and "fast" transaction can take hours
speed: LegacyGasPriceKey = 'fast', if (!speed) speed = this.chainId === ChainId.BSC ? 'instant' : 'fast';
bumpPercent: number = 0,
): Promise<GasPriceParams> {
try { try {
return await this.oracle.getTxGasParams({ legacySpeed: speed, bumpPercent }); return await this.oracle.getTxGasParams({ legacySpeed: speed, bumpPercent });
} catch (e) { } catch (e) {
@ -117,17 +114,12 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
/** /**
* Estimate next block gas price * 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 {LegacyGasPriceKey} speed Preferred transaction speed, if uses legacy gas (before EIP-1559)
* @param {number} bumpPercent Gas bump percent to prioritize transaction * @param {number} bumpPercent Gas bump percent to prioritize transaction
* @returns {Promise<HexadecimalStringifiedNumber>} Gas price in WEI (hex string) * @returns {Promise<HexadecimalStringifiedNumber>} Gas price in WEI (hex string)
*/ */
async getGasPrice( async getGasPrice(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise<HexadecimalStringifiedNumber> {
type: TxType = 'other', const gasPriceParams = await this.getGasPriceParams(speed, bumpPercent);
speed: LegacyGasPriceKey = 'fast',
bumpPercent?: number,
): Promise<HexadecimalStringifiedNumber> {
const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent);
return calculateGasPriceInWei(gasPriceParams).toHexString(); return calculateGasPriceInWei(gasPriceParams).toHexString();
} }

@ -49,16 +49,12 @@ export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeO
} }
} }
async getGasPriceParams( async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise<GasPriceParams> {
type: TxType = 'other',
speed: LegacyGasPriceKey = 'fast',
bumpPercent?: number,
): Promise<GasPriceParams> {
// Only if bump percent didn't provided (if user provides 0, no need to recalculate) // Only if bump percent didn't provided (if user provides 0, no need to recalculate)
if (bumpPercent === undefined) { if (bumpPercent === undefined) {
switch (this.chainId) { switch (this.chainId) {
case ChainId.GOERLI: case ChainId.GOERLI:
bumpPercent = type === 'user_withdrawal' ? 100 : 50; bumpPercent = 100;
break; break;
case ChainId.POLYGON: case ChainId.POLYGON:
case ChainId.AVAX: 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);
} }
} }

@ -49,12 +49,8 @@ export interface ITornadoFeeOracle {
bumpGasPricePercent?: number, bumpGasPricePercent?: number,
speed?: LegacyGasPriceKey, speed?: LegacyGasPriceKey,
) => Promise<HexadecimalStringifiedNumber>; ) => Promise<HexadecimalStringifiedNumber>;
getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>; getGasPriceParams: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>;
getGasPrice: ( getGasPrice: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<HexadecimalStringifiedNumber>;
type?: TxType,
speed?: LegacyGasPriceKey,
bumpPercent?: number,
) => Promise<HexadecimalStringifiedNumber>;
getGasLimit: (tx?: TransactionData, type?: TxType, bumpPercent?: number) => Promise<number>; getGasLimit: (tx?: TransactionData, type?: TxType, bumpPercent?: number) => Promise<number>;
fetchL1OptimismFee: (tx?: TransactionData) => Promise<HexadecimalStringifiedNumber>; fetchL1OptimismFee: (tx?: TransactionData) => Promise<HexadecimalStringifiedNumber>;
calculateRefundInETH: (tokenSymbol: InstanceTokenSymbol) => Promise<HexadecimalStringifiedNumber>; calculateRefundInETH: (tokenSymbol: InstanceTokenSymbol) => Promise<HexadecimalStringifiedNumber>;