Add fallback from feeOracleV5 to V4 in getGasLimit method, if no tx object provided & bump package version to 0.3.0

This commit is contained in:
Theo 2023-08-21 09:30:24 -07:00
parent 96616d8cf4
commit 0aa15627f4
2 changed files with 8 additions and 3 deletions

@ -1,6 +1,6 @@
{
"name": "@tornado/tornado-oracles",
"version": "0.2.3",
"version": "0.3.0",
"description": "Gas oracle for Tornado-specific transactions",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
@ -30,12 +30,12 @@
"dependencies": {
"@tornado/gas-price-oracle": "^0.5.3",
"@tornado/tornado-config": "^2.0.0",
"@types/node": "^20.5.1",
"bignumber.js": "^9.1.1",
"ethers": "5.7"
},
"devDependencies": {
"@typechain/ethers-v5": "^11.1.1",
"@types/node": "^20.4.10",
"nodemon": "^3.0.1",
"prettier": "^3.0.1",
"ts-node": "^10.9.1",

@ -4,8 +4,11 @@ import { ITornadoFeeOracle, GasPrice, TransactionData, TxType, LegacyGasPrices,
import { GasPriceOracle } from '@tornado/gas-price-oracle';
import { BigNumber } from 'ethers';
import { bump } from './utils';
import { TornadoFeeOracleV4 } from './feeOracleV4';
export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeOracle {
private fallbackFeeOracle: TornadoFeeOracleV4;
public constructor(chainId: number, rpcUrl: string, defaultGasPrices?: LegacyGasPrices) {
const oracleConfig = {
chainId,
@ -18,10 +21,12 @@ export class TornadoFeeOracleV5 extends TornadoFeeOracle implements ITornadoFeeO
const gasPriceOracle = new GasPriceOracle(oracleConfig);
super(chainId, rpcUrl, gasPriceOracle);
this.fallbackFeeOracle = new TornadoFeeOracleV4(chainId, rpcUrl, defaultGasPrices);
}
async getGasLimit(tx?: TransactionData, type: TxType = 'other', bumpPercent: number = 20): Promise<BigNumber> {
if (!tx) return BigNumber.from(21_000);
if (!tx || Object.keys(tx).length === 0) return this.fallbackFeeOracle.getGasLimit(tx, type, bumpPercent);
/* Relayer gas limit must be lower so that fluctuations in gas price cannot lead to the fact that
* the relayer will actually pay for gas more than the money allocated for this by the user