From 9799a86817764ed8516c42ee6884d374ccf9a074 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Tue, 18 Jul 2023 19:07:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=85=E5=80=BC=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E6=89=A3=E9=99=A4networkFee=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E8=BD=AC=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/alchemyout.controller.ts | 8 ++++++++ src/modules/PayRecord.ts | 5 ++++- src/queue/transfer.queue.ts | 4 ++-- 3 files changed, 14 insertions(+), 3 deletions(-) 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,