Speed up getGas function via Promise.all & bump version to 1.2.2
This commit is contained in:
parent
4cdd5c7538
commit
de369f405c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tornado/tornado-oracles",
|
"name": "@tornado/tornado-oracles",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "Gas oracle for Tornado-specific transactions",
|
"description": "Gas oracle for Tornado-specific transactions",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"types": "./lib/index.d.ts",
|
"types": "./lib/index.d.ts",
|
||||||
|
@ -42,11 +42,9 @@ export abstract class TornadoFeeOracle implements ITornadoFeeOracle {
|
|||||||
* @returns {Promise<string>} Gas value in WEI (hex-format)
|
* @returns {Promise<string>} Gas value in WEI (hex-format)
|
||||||
*/
|
*/
|
||||||
async getGas(tx?: TransactionData, txType: TxType = 'other', speed: LegacyGasPriceKey = 'fast'): Promise<string> {
|
async getGas(tx?: TransactionData, txType: TxType = 'other', speed: LegacyGasPriceKey = 'fast'): Promise<string> {
|
||||||
const gasPrice = await this.getGasPrice(txType, speed);
|
const [gasPrice, gasLimit] = await Promise.all([this.getGasPrice(txType, speed), this.getGasLimit(tx, txType)]);
|
||||||
let gas = BigNumber.from(0);
|
let gas = BigNumber.from(gasPrice).mul(gasLimit);
|
||||||
gas = gas.add(gasPrice);
|
if (tx) tx = Object.assign(tx, { gasPrice, gasLimit });
|
||||||
if (tx) tx = Object.assign(tx, { gasPrice });
|
|
||||||
gas = gas.mul(await this.getGasLimit(tx, txType));
|
|
||||||
if (this.chainId === ChainId.OPTIMISM) gas = gas.add(await this.fetchL1OptimismFee(tx));
|
if (this.chainId === ChainId.OPTIMISM) gas = gas.add(await this.fetchL1OptimismFee(tx));
|
||||||
|
|
||||||
return gas.toHexString();
|
return gas.toHexString();
|
||||||
|
Loading…
Reference in New Issue
Block a user