fix: tx gas price

This commit is contained in:
Danil Kovtonyuk 2021-06-17 16:18:22 +03:00
parent 9747c1a397
commit 9b49cab775

@ -1,6 +1,6 @@
const Web3 = require('web3') const Web3 = require('web3')
const { GasPriceOracle } = require('gas-price-oracle') const { GasPriceOracle } = require('gas-price-oracle')
const { toBN, toWei, fromWei } = require('web3-utils') const { toBN, toWei, fromWei, toHex } = require('web3-utils')
const proxyLightABI = require('../abis/proxyLightABI.json') const proxyLightABI = require('../abis/proxyLightABI.json')
const { queue } = require('./queue') const { queue } = require('./queue')
@ -8,7 +8,7 @@ const { getInstance, fromDecimals } = require('./utils')
const { jobType, status } = require('./constants') const { jobType, status } = require('./constants')
const { const {
netId, netId,
gasPrices, gasPrices: GAS_PRICES,
gasLimits, gasLimits,
instances, instances,
privateKey, privateKey,
@ -34,7 +34,7 @@ function start() {
if (networksWithOracle.includes(netId)) { if (networksWithOracle.includes(netId)) {
gasPriceOracleConfig = { gasPriceOracleConfig = {
chainId: netId, chainId: netId,
defaultFallbackGasPrices: gasPrices, defaultFallbackGasPrices: GAS_PRICES,
} }
gasPriceOracle = new GasPriceOracle(gasPriceOracleConfig) gasPriceOracle = new GasPriceOracle(gasPriceOracleConfig)
} }
@ -53,16 +53,22 @@ function start() {
} }
} }
async function getGasPrices() {
let gasPrices = GAS_PRICES
if (gasPriceOracle) {
gasPrices = await gasPriceOracle.gasPrices()
}
return gasPrices
}
async function checkTornadoFee({ args, contract }) { async function checkTornadoFee({ args, contract }) {
const { currency, amount } = getInstance(contract) const { currency, amount } = getInstance(contract)
const { decimals } = instances[currency] const { decimals } = instances[currency]
const fee = toBN(args[4]) const fee = toBN(args[4])
let { fast } = gasPrices
if (gasPriceOracle) { const { fast } = await getGasPrices()
// eslint-disable-next-line no-extra-semi
;({ fast } = await gasPriceOracle.gasPrices())
}
const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[jobType.TORNADO_WITHDRAW])) const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[jobType.TORNADO_WITHDRAW]))
const feePercent = toBN(fromDecimals(amount, decimals)) const feePercent = toBN(fromDecimals(amount, decimals))
@ -81,17 +87,24 @@ async function checkTornadoFee({ args, contract }) {
} }
} }
function getTxObject({ data }) { async function getTxObject({ data }) {
const contract = new web3.eth.Contract(proxyLightABI, proxyLight) const contract = new web3.eth.Contract(proxyLightABI, proxyLight)
const calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI() const calldata = contract.methods.withdraw(data.contract, data.proof, ...data.args).encodeABI()
return { const tx = {
value: data.args[5], value: data.args[5],
to: contract._address, to: contract._address,
data: calldata, data: calldata,
gasLimit: gasLimits[jobType.TORNADO_WITHDRAW], gasLimit: gasLimits[jobType.TORNADO_WITHDRAW],
} }
if (!gasPriceOracle) {
const { fast } = await getGasPrices()
tx.gasPrice = toHex(toWei(fast.toString(), 'gwei'))
}
return tx
} }
async function processJob(job) { async function processJob(job) {