fee calculation fix

This commit is contained in:
Alexey 2020-10-15 20:20:00 +03:00
parent 7264299e03
commit b15b368551

@ -138,6 +138,8 @@ async function checkTornadoFee({ args, contract }) {
async function checkMiningFee({ args }) { async function checkMiningFee({ args }) {
const { fast } = await gasPriceOracle.gasPrices() const { fast } = await gasPriceOracle.gasPrices()
const ethPrice = await redis.hget('prices', 'torn') const ethPrice = await redis.hget('prices', 'torn')
const isMiningReward = currentJob.data.type === jobType.MINING_REWARD
const providedFee = isMiningReward ? toBN(args.fee) : toBN(args.extData.fee)
const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[currentJob.data.type])) const expense = toBN(toWei(fast.toString(), 'gwei')).mul(toBN(gasLimits[currentJob.data.type]))
const expenseInTorn = expense.mul(toBN(1e18)).div(toBN(ethPrice)) const expenseInTorn = expense.mul(toBN(1e18)).div(toBN(ethPrice))
@ -146,18 +148,17 @@ async function checkMiningFee({ args }) {
const poolWeight = await swap.methods.poolWeight().call() const poolWeight = await swap.methods.poolWeight().call()
const expenseInPoints = Utils.reverseTornadoFormula({ balance, tokens: expenseInTorn, poolWeight }) const expenseInPoints = Utils.reverseTornadoFormula({ balance, tokens: expenseInTorn, poolWeight })
/* eslint-disable */ /* eslint-disable */
const serviceFeePercent = const serviceFeePercent = isMiningReward
currentJob.data.type === jobType.MINING_REWARD ? toBN(0)
? toBN(0) : toBN(args.amount)
: toBN(args.amount) .sub(providedFee) // args.amount includes fee
.mul(toBN(miningServiceFee * 1e10)) .mul(toBN(miningServiceFee * 1e10))
.div(toBN(1e10 * 100)) .div(toBN(1e10 * 100))
/* eslint-enable */ /* eslint-enable */
const desiredFee = expenseInPoints.add(serviceFeePercent) // in points const desiredFee = expenseInPoints.add(serviceFeePercent) // in points
const providedFee = currentJob.data.type === jobType.MINING_REWARD ? args.fee : args.extData.fee
console.log( console.log(
'sent fee, desired fee, serviceFeePercent', 'user provided fee, desired fee, serviceFeePercent',
toBN(providedFee).toString(), providedFee.toString(),
desiredFee.toString(), desiredFee.toString(),
serviceFeePercent.toString(), serviceFeePercent.toString(),
) )