check mining fee
This commit is contained in:
parent
97e7a4376c
commit
ae3044b6e9
@ -157,6 +157,7 @@ let config = {
|
|||||||
tornadoServiceFee: Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE),
|
tornadoServiceFee: Number(process.env.REGULAR_TORNADO_WITHDRAW_FEE),
|
||||||
miningServiceFee: Number(process.env.MINING_SERVICE_FEE),
|
miningServiceFee: Number(process.env.MINING_SERVICE_FEE),
|
||||||
rewardAccount: '0x03Ebd0748Aa4D1457cF479cce56309641e0a98F5',
|
rewardAccount: '0x03Ebd0748Aa4D1457cF479cce56309641e0a98F5',
|
||||||
|
tornEthPrice: '7000000000000000',
|
||||||
gasLimits: {
|
gasLimits: {
|
||||||
[jobType.TORNADO_WITHDRAW]: 350000,
|
[jobType.TORNADO_WITHDRAW]: 350000,
|
||||||
[jobType.MINING_REWARD]: 800000,
|
[jobType.MINING_REWARD]: 800000,
|
||||||
|
@ -23,6 +23,7 @@ const {
|
|||||||
instances,
|
instances,
|
||||||
tornadoServiceFee,
|
tornadoServiceFee,
|
||||||
miningServiceFee,
|
miningServiceFee,
|
||||||
|
tornEthPrice,
|
||||||
} = require('../config')
|
} = require('../config')
|
||||||
const { TxManager } = require('tx-manager')
|
const { TxManager } = require('tx-manager')
|
||||||
const { Controller } = require('tornado-cash-anonymity-mining')
|
const { Controller } = require('tornado-cash-anonymity-mining')
|
||||||
@ -135,8 +136,26 @@ async function checkMiningFee({ args }) {
|
|||||||
const swap = new web3.eth.Contract(swapABI, swapAddress)
|
const swap = new web3.eth.Contract(swapABI, swapAddress)
|
||||||
const TornAmount = await swap.methods.getExpectedReturn(args.fee).call()
|
const TornAmount = await swap.methods.getExpectedReturn(args.fee).call()
|
||||||
console.log('TornAmount', TornAmount)
|
console.log('TornAmount', TornAmount)
|
||||||
|
const { fast } = await gasPriceOracle.gasPrices()
|
||||||
|
|
||||||
// todo: use desired torn/eth rate and compute the same way as in tornado
|
const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[args.type]))
|
||||||
|
const feePercent =
|
||||||
|
args.type === jobType.MINING_REWARD
|
||||||
|
? 0
|
||||||
|
: toBN(args.amount)
|
||||||
|
.mul(toBN(miningServiceFee * 1e10))
|
||||||
|
.div(toBN(1e10 * 100))
|
||||||
|
let desiredFee = expense.mul(toBN(1e18)).div(toBN(tornEthPrice)).add(feePercent)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
'sent fee, desired fee, feePercent',
|
||||||
|
fromWei(args.fee.toString()),
|
||||||
|
fromWei(desiredFee.toString()),
|
||||||
|
fromWei(feePercent.toString()),
|
||||||
|
)
|
||||||
|
if (args.fee.lt(desiredFee)) {
|
||||||
|
throw new Error('Provided fee is not enough. Probably it is a Gas Price spike, try to resubmit.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTxObject({ data }) {
|
function getTxObject({ data }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user