Skip to content

Commit

Permalink
bugfix:token amount decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Sep 18, 2023
1 parent d2f14ee commit 2bd6dec
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apollo/src/lnbridgev20/lnbridgev20.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export class Lnbridgev20Service implements OnModuleInit {
recipient: record.receiver,
sendToken: firstPendingRecord.sendToken,
recvToken: firstPendingRecord.recvToken,
sendAmount: record.amount,
recvAmount: '0',
sendAmount: firstPendingRecord.sendAmount,
recvAmount: firstPendingRecord.recvAmount,
startTime: Number(record.timestamp),
endTime: 0,
result: 0,
Expand Down Expand Up @@ -242,6 +242,9 @@ export class Lnbridgev20Service implements OnModuleInit {
continue;
}
const toToken = toSymbol.symbol;

const decimalsDiff = fromSymbol.decimals - toSymbol.decimals;
const sendAmount = decimalsDiff > 0 ? BigInt(record.amount) * BigInt(10 ** decimalsDiff) : BigInt(record.amount) / BigInt(10 ** -decimalsDiff);

await this.aggregationService.createHistoryRecord({
id: this.genID(transfer, record.id),
Expand All @@ -256,8 +259,8 @@ export class Lnbridgev20Service implements OnModuleInit {
recipient: record.receiver,
sendToken: fromToken,
recvToken: toToken,
sendAmount: record.amount,
recvAmount: '0',
sendAmount: sendAmount.toString(),
recvAmount: record.amount,
startTime: Number(record.timestamp),
endTime: 0,
result: RecordStatus.pending,
Expand Down Expand Up @@ -343,7 +346,6 @@ export class Lnbridgev20Service implements OnModuleInit {
responseTxHash: relayRecord.transactionHash,
endTxHash: relayRecord.transactionHash,
endTime: Number(relayRecord.timestamp), // we use this time to check slash time
recvAmount: record.sendAmount,
};

await this.aggregationService.updateHistoryRecord({
Expand Down

0 comments on commit 2bd6dec

Please sign in to comment.