diff --git a/src/controllers/alchemyout.controller.ts b/src/controllers/alchemyout.controller.ts index 61e8e0c..dce732a 100644 --- a/src/controllers/alchemyout.controller.ts +++ b/src/controllers/alchemyout.controller.ts @@ -10,6 +10,7 @@ import { reportPayResult } from 'service/game.svr' import { PriceSvr } from 'service/price.svr' import { OrderCacheSvr } from 'service/ordercache.svr' import { GasSvr } from 'service/gas.svr' +import { parse } from 'dotenv' let errorRes = function (msg: string) { logger.info(`error res: ${msg}`) @@ -188,6 +189,13 @@ class AlchemyOutController extends BaseController { } record.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.usdtAdmount = usdtAmount await record.save() diff --git a/src/modules/PayRecord.ts b/src/modules/PayRecord.ts index 54779ed..8a2db73 100644 --- a/src/modules/PayRecord.ts +++ b/src/modules/PayRecord.ts @@ -54,9 +54,12 @@ export class PayRecordClass extends BaseModule { // 法币数量 @prop() public fiatAmount?: string - // 加密货币数量, 实际转账金额 + // 加密货币数量, @prop() public cryptoAmount?: string + // 实际转账金额 + @prop() + public cryptoSend?: string // 开始创建记录时, 估算的可获取加密货币数量 @prop() diff --git a/src/queue/transfer.queue.ts b/src/queue/transfer.queue.ts index 5e6725f..982bdef 100644 --- a/src/queue/transfer.queue.ts +++ b/src/queue/transfer.queue.ts @@ -58,7 +58,7 @@ export class TransferQueue { contract: address, to: task.address, from: wallet, - amount: task.cryptoAmount, + amount: task.cryptoSend, $inc: { version: 1 }, }, ) @@ -73,7 +73,7 @@ export class TransferQueue { type: 3, }, ] - if (token === 'agor') { + if (token === 'agor' || token === 'eth') { datas = [ { from: record.from,