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:
parent
90471e0073
commit
0d3ea02015
@ -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",
|
||||
|
@ -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<GetGasParamsRes>} 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<GetGasParamsRes> {
|
||||
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<HexadecimalStringifiedNumber>} 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<HexadecimalStringifiedNumber> {
|
||||
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<GasPriceParams>} 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<GasPriceParams> {
|
||||
async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent: number = 0): Promise<GasPriceParams> {
|
||||
// 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<HexadecimalStringifiedNumber>} Gas price in WEI (hex string)
|
||||
*/
|
||||
async getGasPrice(
|
||||
type: TxType = 'other',
|
||||
speed: LegacyGasPriceKey = 'fast',
|
||||
bumpPercent?: number,
|
||||
): Promise<HexadecimalStringifiedNumber> {
|
||||
const gasPriceParams = await this.getGasPriceParams(type, speed, bumpPercent);
|
||||
async getGasPrice(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise<HexadecimalStringifiedNumber> {
|
||||
const gasPriceParams = await this.getGasPriceParams(speed, bumpPercent);
|
||||
return calculateGasPriceInWei(gasPriceParams).toHexString();
|
||||
}
|
||||
|
||||
|
@ -49,16 +49,12 @@ export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeO
|
||||
}
|
||||
}
|
||||
|
||||
async getGasPriceParams(
|
||||
type: TxType = 'other',
|
||||
speed: LegacyGasPriceKey = 'fast',
|
||||
bumpPercent?: number,
|
||||
): Promise<GasPriceParams> {
|
||||
async getGasPriceParams(speed?: LegacyGasPriceKey, bumpPercent?: number): Promise<GasPriceParams> {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@ -49,12 +49,8 @@ export interface ITornadoFeeOracle {
|
||||
bumpGasPricePercent?: number,
|
||||
speed?: LegacyGasPriceKey,
|
||||
) => Promise<HexadecimalStringifiedNumber>;
|
||||
getGasPriceParams: (type?: TxType, speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>;
|
||||
getGasPrice: (
|
||||
type?: TxType,
|
||||
speed?: LegacyGasPriceKey,
|
||||
bumpPercent?: number,
|
||||
) => Promise<HexadecimalStringifiedNumber>;
|
||||
getGasPriceParams: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<GasPriceParams>;
|
||||
getGasPrice: (speed?: LegacyGasPriceKey, bumpPercent?: number) => Promise<HexadecimalStringifiedNumber>;
|
||||
getGasLimit: (tx?: TransactionData, type?: TxType, bumpPercent?: number) => Promise<number>;
|
||||
fetchL1OptimismFee: (tx?: TransactionData) => Promise<HexadecimalStringifiedNumber>;
|
||||
calculateRefundInETH: (tokenSymbol: InstanceTokenSymbol) => Promise<HexadecimalStringifiedNumber>;
|
||||
|
Loading…
Reference in New Issue
Block a user