Skip to content

Commit ad3a6bf

Browse files
authored
Merge pull request #58 from Dnreikronos/fix/bigint-token-arithmetic
fix: replace floating-point math with BN arithmetic for token amounts
2 parents 8c23198 + 574dc93 commit ad3a6bf

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

backend/src/services/solana.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,16 @@ export const executePayment = async (params: {
106106
tokenProgramId
107107
);
108108

109-
const amountInSmallestUnit =
110-
params.amount * Math.pow(10, params.tokenDecimals);
109+
const amountInSmallestUnit = new anchor.BN(params.amount)
110+
.mul(new anchor.BN(10).pow(new anchor.BN(params.tokenDecimals)));
111111

112112
// Strip hyphens from UUID to match PDA seed derivation
113113
const seedId = params.subscriptionId.replace(/-/g, "");
114114

115115
const tx = await (program.methods as any)
116116
.chargeSubscription(
117117
seedId,
118-
new anchor.BN(amountInSmallestUnit)
118+
amountInSmallestUnit
119119
)
120120
.accounts({
121121
delegateApproval: delegateApprovalPDA,

0 commit comments

Comments
 (0)