From de369f405c6838d3622362ce6d83c9039ab4acc7 Mon Sep 17 00:00:00 2001 From: Theo Date: Fri, 25 Aug 2023 07:52:23 -0700 Subject: [PATCH] Speed up getGas function via Promise.all & bump version to 1.2.2 --- package.json | 2 +- src/feeOracle.ts | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 12affa6..505f10b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tornado/tornado-oracles", - "version": "1.2.1", + "version": "1.2.2", "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 2dfa716..2d6978d 100644 --- a/src/feeOracle.ts +++ b/src/feeOracle.ts @@ -42,11 +42,9 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle { * @returns {Promise} Gas value in WEI (hex-format) */ async getGas(tx?: TransactionData, txType: TxType = 'other', speed: LegacyGasPriceKey = 'fast'): Promise { - const gasPrice = await this.getGasPrice(txType, speed); - let gas = BigNumber.from(0); - gas = gas.add(gasPrice); - if (tx) tx = Object.assign(tx, { gasPrice }); - gas = gas.mul(await this.getGasLimit(tx, txType)); + const [gasPrice, gasLimit] = await Promise.all([this.getGasPrice(txType, speed), this.getGasLimit(tx, txType)]); + let gas = BigNumber.from(gasPrice).mul(gasLimit); + if (tx) tx = Object.assign(tx, { gasPrice, gasLimit }); if (this.chainId === ChainId.OPTIMISM) gas = gas.add(await this.fetchL1OptimismFee(tx)); return gas.toHexString();