Skip to content

Commit

Permalink
fix decimal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Nov 27, 2024
1 parent 782e7c5 commit 952b6b5
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type Hex,
type WalletClient,
type Chain,
formatUnits,
} from 'viem'

import {
Expand Down Expand Up @@ -135,7 +136,13 @@ export function normalizeBalanceDiffByDecimals(
balanceDiff: bigint,
tokenDecimals: number
): bigint {
return balanceDiff / BigInt(10 ** (18 - tokenDecimals))
// Convert to 18 decimals (ETH standard) for comparison
if (tokenDecimals === 18) return balanceDiff

// Convert to decimal string with proper precision
const formattedDiff = formatUnits(balanceDiff, 18)
// Parse back with target decimals
return parseUnits(formattedDiff, tokenDecimals)
}

export async function approveCustomFeeTokenWithViem({
Expand Down

0 comments on commit 952b6b5

Please sign in to comment.