From 8532bf69459ab0cd4b7133a77a2045ed55e4af7e Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 10 Dec 2025 12:22:32 -0800 Subject: [PATCH] fix(blockchain): use amountFormatted to rebuild TokenAmount from DB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously used amount (raw) with hardcoded 18 decimals, which caused incorrect formatting for USDT (6 decimals). Now uses amountFormatted which is already correctly formatted during deposit detection. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../persistence/mappers/deposit-transaction.mapper.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/services/blockchain-service/src/infrastructure/persistence/mappers/deposit-transaction.mapper.ts b/backend/services/blockchain-service/src/infrastructure/persistence/mappers/deposit-transaction.mapper.ts index dab37f55..3f0a1d35 100644 --- a/backend/services/blockchain-service/src/infrastructure/persistence/mappers/deposit-transaction.mapper.ts +++ b/backend/services/blockchain-service/src/infrastructure/persistence/mappers/deposit-transaction.mapper.ts @@ -17,6 +17,11 @@ export class DepositTransactionMapper { throw new Error(`DepositTransaction ${prisma.id} missing accountSequence or userId`); } + // 使用 amountFormatted 重建 TokenAmount + // amountFormatted 已经是正确的人类可读格式(如 1000000.00000000) + // 用 decimals=8 与 toFixed(8) 保持一致,确保 toFixed(8) 返回相同的值 + const amount = TokenAmount.fromFormatted(prisma.amountFormatted.toString(), 8); + const props: DepositTransactionProps = { id: prisma.id, chainType: ChainType.create(prisma.chainType), @@ -24,7 +29,7 @@ export class DepositTransactionMapper { fromAddress: EvmAddress.fromUnchecked(prisma.fromAddress), toAddress: EvmAddress.fromUnchecked(prisma.toAddress), tokenContract: EvmAddress.fromUnchecked(prisma.tokenContract), - amount: TokenAmount.fromDecimal(prisma.amount, 18), + amount, blockNumber: BlockNumber.create(prisma.blockNumber), blockTimestamp: prisma.blockTimestamp, logIndex: prisma.logIndex,