Skip to content

Commit

Permalink
use orderOfMagnitude instead of log10
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed Jun 12, 2024
1 parent 1a8f515 commit 3ece47a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/__swaps__/utils/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ import {
divWorklet,
equalWorklet,
floorWorklet,
log10Worklet,
lessThanOrEqualToWorklet,
mulWorklet,
powWorklet,
roundWorklet,
toFixedWorklet,
greaterThanOrEqualToWorklet,
sumWorklet,
orderOfMagnitudeWorklet,
} from '../safe-math/SafeMath';

// /---- 🎨 Color functions 🎨 ----/ //
Expand Down Expand Up @@ -171,7 +170,7 @@ export const findNiceIncrement = (availableBalance: string | number) => {
const exactIncrement = divWorklet(availableBalance, 100);

// Calculate the order of magnitude of the exact increment
const orderOfMagnitude = floorWorklet(log10Worklet(exactIncrement));
const orderOfMagnitude = orderOfMagnitudeWorklet(exactIncrement);

const baseIncrement = powWorklet(10, orderOfMagnitude);

Expand Down Expand Up @@ -232,7 +231,7 @@ export function trimTrailingZeros(value: string) {
export function precisionBasedOffMagnitude(amount: number | string, isStablecoin = false): number {
'worklet';

const magnitude = -Number(floorWorklet(sumWorklet(log10Worklet(amount), 0)));
const magnitude = orderOfMagnitudeWorklet(amount);
// don't let stablecoins go beneath 2nd order
if (magnitude < -2 && isStablecoin) {
return -STABLECOIN_MINIMUM_SIGNIFICANT_DECIMALS;
Expand Down

0 comments on commit 3ece47a

Please sign in to comment.