修改充值流程,扣除networkFee后再转账

This commit is contained in:
CounterFire2023 2023-07-18 19:07:58 +08:00
parent 508574b816
commit 9799a86817
3 changed files with 14 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import { reportPayResult } from 'service/game.svr'
import { PriceSvr } from 'service/price.svr' import { PriceSvr } from 'service/price.svr'
import { OrderCacheSvr } from 'service/ordercache.svr' import { OrderCacheSvr } from 'service/ordercache.svr'
import { GasSvr } from 'service/gas.svr' import { GasSvr } from 'service/gas.svr'
import { parse } from 'dotenv'
let errorRes = function (msg: string) { let errorRes = function (msg: string) {
logger.info(`error res: ${msg}`) logger.info(`error res: ${msg}`)
@ -188,6 +189,13 @@ class AlchemyOutController extends BaseController {
} }
record.cryptoAmount = record.cryptoAmount =
record.network.toLowerCase() === 'agor' && record.crypto.toLowerCase() === 'agor' ? '0.001' : cryptoAmount record.network.toLowerCase() === 'agor' && record.crypto.toLowerCase() === 'agor' ? '0.001' : cryptoAmount
let gas = await new GasSvr().estimateGas({ crypto, network: 'ARBITRUM' })
gas = gas * 0.0000000001
// 20230718 沟通, cryptoAmount包含了gas费, 需要减去后再发送
let networkFee = gas
let price = await new PriceSvr().fetchPrice({ crypto: 'ETH', network: 'ARBITRUM', fiat: 'USD' })
networkFee = (networkFee * parseFloat(price)) / parseFloat(cryptoPrice)
record.cryptoSend = (parseFloat(cryptoAmount) - networkFee).toFixed(10)
record.cryptoPrice = cryptoPrice record.cryptoPrice = cryptoPrice
record.usdtAdmount = usdtAmount record.usdtAdmount = usdtAmount
await record.save() await record.save()

View File

@ -54,9 +54,12 @@ export class PayRecordClass extends BaseModule {
// 法币数量 // 法币数量
@prop() @prop()
public fiatAmount?: string public fiatAmount?: string
// 加密货币数量, 实际转账金额 // 加密货币数量,
@prop() @prop()
public cryptoAmount?: string public cryptoAmount?: string
// 实际转账金额
@prop()
public cryptoSend?: string
// 开始创建记录时, 估算的可获取加密货币数量 // 开始创建记录时, 估算的可获取加密货币数量
@prop() @prop()

View File

@ -58,7 +58,7 @@ export class TransferQueue {
contract: address, contract: address,
to: task.address, to: task.address,
from: wallet, from: wallet,
amount: task.cryptoAmount, amount: task.cryptoSend,
$inc: { version: 1 }, $inc: { version: 1 },
}, },
) )
@ -73,7 +73,7 @@ export class TransferQueue {
type: 3, type: 3,
}, },
] ]
if (token === 'agor') { if (token === 'agor' || token === 'eth') {
datas = [ datas = [
{ {
from: record.from, from: record.from,