Speed up getGas function via Promise.all & bump version to 1.2.2

This commit is contained in:
Theo 2023-08-25 07:52:23 -07:00
parent 4cdd5c7538
commit de369f405c
2 changed files with 4 additions and 6 deletions

@ -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",

@ -42,11 +42,9 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
* @returns {Promise<string>} Gas value in WEI (hex-format)
*/
async getGas(tx?: TransactionData, txType: TxType = 'other', speed: LegacyGasPriceKey = 'fast'): Promise<string> {
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();