Skip to content

Commit

Permalink
Merge pull request #235 from metaDAOproject/fix/converting-twice
Browse files Browse the repository at this point in the history
fix: do not need to convert many times
  • Loading branch information
R-K-H authored Aug 17, 2024
2 parents d015124 + 9d19d43 commit cf71eef
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ async function calculateUserPerformance(
}

const baseTokenDecimals = base_tokens?.decimals ?? -1;
const quoteTokenDecimals = quote_tokens?.decimals ?? -1;
const quoteTokenDecimals = quote_tokens?.decimals ?? 6; // NOTE: Safe for now
if (!baseTokenDecimals && !quoteTokenDecimals) {
return current;
}
Expand All @@ -717,16 +717,13 @@ async function calculateUserPerformance(
);

// Amount or notional
const amount = PriceMath.getChainAmount(
Number(next.quotePrice).valueOf() * size,
quoteTokenDecimals // By default this should be 6
);
const amount = Number(next.quotePrice).valueOf() * size

if (next.side === "BID") {
totals.tokensBought = totals.tokensBought + (Number(next.filledBaseAmount) / 10 ** baseTokenDecimals);
totals.tokensBought = totals.tokensBought + size;
totals.volumeBought = totals.volumeBought + amount;
} else if (next.side === "ASK") {
totals.tokensSold = totals.tokensSold + (Number(next.filledBaseAmount) / 10 ** baseTokenDecimals);
totals.tokensSold = totals.tokensSold + size;
totals.volumeSold = totals.volumeSold + amount;
}

Expand Down

0 comments on commit cf71eef

Please sign in to comment.