From 0aa15627f4d949133835e7104d2546fc86408157 Mon Sep 17 00:00:00 2001 From: Theo Date: Mon, 21 Aug 2023 09:30:24 -0700 Subject: [PATCH] Add fallback from feeOracleV5 to V4 in getGasLimit method, if no tx object provided & bump package version to 0.3.0 --- package.json | 4 ++-- src/feeOracleV5.ts | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c2e8427..29acfe1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/feeOracleV5.ts b/src/feeOracleV5.ts index ccbd2b5..b1b748a 100644 --- a/src/feeOracleV5.ts +++ b/src/feeOracleV5.ts @@ -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 { - 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