From 3d7a9b5f93f58437ab6b6f5b53b44472937e4a09 Mon Sep 17 00:00:00 2001 From: Danil Kovtonyuk Date: Tue, 29 Jun 2021 00:48:01 +0300 Subject: [PATCH] fix: get gas prices --- src/worker.js | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/worker.js b/src/worker.js index 4d25ddb..0ba72ed 100644 --- a/src/worker.js +++ b/src/worker.js @@ -28,17 +28,13 @@ function start() { try { web3 = new Web3(httpRpcUrl) const { CONFIRMATIONS, MAX_GAS_PRICE } = process.env - let gasPriceOracleConfig = {} - - const networksWithOracle = [56, 137] - if (networksWithOracle.includes(netId)) { - gasPriceOracleConfig = { - chainId: netId, - defaultFallbackGasPrices: GAS_PRICES, - } - gasPriceOracle = new GasPriceOracle(gasPriceOracleConfig) + const gasPriceOracleConfig = { + chainId: netId, + defaultFallbackGasPrices: GAS_PRICES, } + gasPriceOracle = new GasPriceOracle(gasPriceOracleConfig) + txManager = new TxManager({ privateKey, rpcUrl: httpRpcUrl, @@ -54,13 +50,12 @@ function start() { } async function getGasPrices() { - let gasPrices = GAS_PRICES - - if (gasPriceOracle) { - gasPrices = await gasPriceOracle.gasPrices() + const networksWithOracle = [56, 137] + if (networksWithOracle.includes(netId)) { + return await gasPriceOracle.gasPrices() } - return gasPrices + return GAS_PRICES } async function checkTornadoFee({ args, contract }) { @@ -92,19 +87,15 @@ async function getTxObject({ data }) { const calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI() - const tx = { + const { fast } = await getGasPrices() + + return { value: data.args[5], to: contract._address, data: calldata, gasLimit: gasLimits[jobType.TORNADO_WITHDRAW], + gasPrice: toHex(toWei(fast.toString(), 'gwei')), } - - if (!gasPriceOracle) { - const { fast } = await getGasPrices() - tx.gasPrice = toHex(toWei(fast.toString(), 'gwei')) - } - - return tx } async function processJob(job) {