mirror of
https://github.com/tornadocash/tornado-relayer.git
synced 2025-08-15 17:40:18 -04:00
proper gas calculation
This commit is contained in:
parent
5352bd5a55
commit
db35a0cbcc
4 changed files with 46 additions and 31 deletions
23
utils.js
23
utils.js
|
@ -1,5 +1,5 @@
|
|||
const fetch = require('node-fetch')
|
||||
const { isHexStrict, hexToNumberString } = require('web3-utils')
|
||||
const { isHexStrict, hexToNumberString, toBN, toWei } = require('web3-utils')
|
||||
const { gasOracleUrls, ethdaiAddress, mixers } = require('./config')
|
||||
const oracleABI = require('./abis/ETHDAIOracle.json')
|
||||
|
||||
|
@ -97,4 +97,23 @@ function sleep(ms) {
|
|||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
module.exports = { fetchGasPrice, isValidProof, isValidArgs, sleep, fetchDAIprice, isKnownContract }
|
||||
function isEnoughFee({ gas, gasPrices, currency, refund, ethPriceInDai, fee }) {
|
||||
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(gas))
|
||||
let desiredFee
|
||||
switch (currency) {
|
||||
case 'eth': {
|
||||
desiredFee = expense
|
||||
break
|
||||
}
|
||||
case 'dai': {
|
||||
desiredFee = expense.add(refund).mul(toBN(ethPriceInDai)).div(toBN(10 ** 18))
|
||||
break
|
||||
}
|
||||
}
|
||||
if (fee.lt(desiredFee)) {
|
||||
return { isEnough: false, reason: 'Not enough fee' }
|
||||
}
|
||||
return { isEnough: true }
|
||||
}
|
||||
|
||||
module.exports = { fetchGasPrice, isValidProof, isValidArgs, sleep, fetchDAIprice, isKnownContract, isEnoughFee }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue