Skip to content

Comments

Fixes/BNB USDC Fix#477

Merged
vignesha22 merged 1 commit intostagingfrom
fix/BSC_USDC_Decimals
Dec 11, 2025
Merged

Fixes/BNB USDC Fix#477
vignesha22 merged 1 commit intostagingfrom
fix/BSC_USDC_Decimals

Conversation

@vignesha22
Copy link
Contributor

@vignesha22 vignesha22 commented Dec 11, 2025

Description

  • fixed hardcoding of USDC decimals on pnl
  • restricted the USDC amount to 6 on preview buy

How Has This Been Tested?

  • Tested Locally

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • Bug Fixes
    • Improved token amount display precision with truncated decimals for cleaner UI presentation and better readability.
    • Enhanced profit/loss calculations to dynamically account for chain-specific USDC decimal configurations. Now properly normalizes amounts based on the blockchain network to ensure accurate calculations across different chains.

✏️ Tip: You can customize this high-level summary in your review settings.

@vignesha22 vignesha22 requested a review from RanaBug December 11, 2025 12:05
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2025

Walkthrough

This PR introduces decimal handling improvements across two areas: a new truncateDecimals utility function for token display formatting in the PayingToken component, and refactored USDC decimal handling in PnL calculations that replaces fixed 6-decimal assumptions with chain-specific decimals.

Changes

Cohort / File(s) Summary
Decimal Display Formatting
src/apps/pulse/components/Buy/PayingToken.tsx
Imported truncateDecimals utility and applied it to format payingToken.totalRaw display to 6 decimal places.
Utility Functions
src/apps/pulse/utils/number.ts
Added new exported truncateDecimals(value, decimals) function that truncates fractional part to specified decimal places without rounding.
PnL Decimal Handling
src/utils/pnl.ts
Added getUSDCDecimalsByChainId(chainId) helper and refactored three code paths (getRelayValidatedTrades, calculatePnLFromRelay main and fallback) to use chain-specific USDC decimals instead of hard-coded 1e6 divisor; defaults to 6 decimals if chain not found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • New utility function is straightforward with clear behavior (no rounding, simple truncation)
  • Integration in PayingToken component is a direct application of the utility
  • PnL refactoring follows a consistent pattern across three code paths with well-defined fallback behavior
  • All changes are localized with minimal interconnection complexity

Possibly related PRs

Suggested reviewers

  • IAmKio
  • RanaBug

Poem

🐰 A rabbit hops through decimals with care,
Truncating and formatting with flair,
No more ones and sixes so fixed,
Each chain gets decimals that truly mix,
Token displays now perfectly fair! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Fixes/BNB USDC Fix' is partially related to the changeset. It mentions USDC and an issue being fixed, which aligns with the main changes addressing USDC decimals on BNB/BSC, but it is overly vague with redundant wording ('Fixes' and 'Fix') and lacks specificity about what the fix entails. Revise the title to be more specific and clear, such as 'Fix hardcoded USDC decimals for chain-specific handling' or 'Use chain-specific USDC decimals instead of hardcoded value'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description includes all required template sections: Description (with two specific points), How Has This Been Tested (marked as 'Tested Locally'), and Types of changes (Bug fix selected). The description is mostly complete and addresses the core changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/BSC_USDC_Decimals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vignesha22 vignesha22 requested review from IAmKio and aldin4u December 11, 2025 12:05
@cloudflare-workers-and-pages
Copy link

Deploying pillarx-debug with  Cloudflare Pages  Cloudflare Pages

Latest commit: f59b4d7
Status: ✅  Deploy successful!
Preview URL: https://3a8b2aa7.pillarx-debug.pages.dev
Branch Preview URL: https://fix-bsc-usdc-decimals.pillarx-debug.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: f59b4d7
Status: ✅  Deploy successful!
Preview URL: https://b1e16f52.x-e62.pages.dev
Branch Preview URL: https://fix-bsc-usdc-decimals.x-e62.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/utils/pnl.ts (1)

21-30: Chain‑aware USDC decimals look correct; consider minor cleanups

The new getUSDCDecimalsByChainId helper and its use in both PnL paths correctly derive a USDC divisor from allStableCurrencies, fixing the BNB (18‑decimals) case while defaulting to 6 where unknown. This aligns well with the goal of removing hard‑coded 1e6 assumptions.

Two small follow‑ups you might consider (non‑blocking):

  • You can lean on the existing array type instead of manual structs to avoid duplicate typing, e.g. const usdcToken = allStableCurrencies.find((c) => c.chainId === chainId); and then use usdcToken?.decimals ?? 6.
  • In getRelayValidatedTrades, usdcDivisor is recomputed inside the innermost loop even though token.chainId is constant per call; you could hoist const usdcDivisor = 10 ** getUSDCDecimalsByChainId(token.chainId); once per trade for slightly cleaner code.

Also applies to: 346-352, 451-456

src/apps/pulse/components/Buy/PayingToken.tsx (1)

7-7: Truncation applies to all paying tokens, not just USDC

Using truncateDecimals(payingToken.totalRaw, 6) achieves the “max 6 decimals” behavior, but it now affects every paying token rendered by this component. The PR description calls out “USDC amount” specifically, so if this component can show non‑USDC pay tokens, you may want to gate this logic on symbol to avoid unintentionally changing formatting for other assets. Based on learnings, the float usage itself is consistent with existing patterns.

Example tweak if you want USDC‑only truncation:

-        <div className="text-[13px] font-normal text-white">
-          {truncateDecimals(payingToken.totalRaw, 6)}
-        </div>
+        <div className="text-[13px] font-normal text-white">
+          {payingToken.symbol === 'USDC'
+            ? truncateDecimals(payingToken.totalRaw, 6)
+            : payingToken.totalRaw}
+        </div>

Also applies to: 89-89

src/apps/pulse/utils/number.ts (1)

55-68: truncateDecimals implementation matches truncation requirement; minor edge cases optional

The implementation does what you need for the current usage: it takes a number/string, truncates the fractional part to decimals digits without rounding, and leaves integers unchanged. This is consistent with the Pulse app’s accepted float‑based handling.

If you ever plan to reuse this more broadly, a couple of minor hardening tweaks (optional) could be:

  • Normalize decimals <= 0 to return just the integer part (currently decimals = 0 yields "123." for "123.456").
  • Optionally guard against non‑finite numbers (NaN/Infinity) if those can leak in.

For the current decimals = 6 usage, it’s fine as‑is.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9f381 and f59b4d7.

📒 Files selected for processing (3)
  • src/apps/pulse/components/Buy/PayingToken.tsx (2 hunks)
  • src/apps/pulse/utils/number.ts (1 hunks)
  • src/utils/pnl.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: IAmKio
Repo: pillarwallet/x PR: 351
File: src/apps/pulse/utils/intent.ts:44-53
Timestamp: 2025-08-12T07:42:24.656Z
Learning: In the Pulse app's intent utilities (src/apps/pulse/utils/intent.ts), the team has chosen to use floating-point arithmetic for token amount calculations despite potential precision issues, accepting JavaScript's decimal place limitations as a valid trade-off for their use case.
📚 Learning: 2025-08-12T07:42:24.656Z
Learnt from: IAmKio
Repo: pillarwallet/x PR: 351
File: src/apps/pulse/utils/intent.ts:44-53
Timestamp: 2025-08-12T07:42:24.656Z
Learning: In the Pulse app's intent utilities (src/apps/pulse/utils/intent.ts), the team has chosen to use floating-point arithmetic for token amount calculations despite potential precision issues, accepting JavaScript's decimal place limitations as a valid trade-off for their use case.

Applied to files:

  • src/apps/pulse/utils/number.ts
  • src/utils/pnl.ts
  • src/apps/pulse/components/Buy/PayingToken.tsx
📚 Learning: 2025-09-09T12:40:15.629Z
Learnt from: RanaBug
Repo: pillarwallet/x PR: 391
File: src/apps/pulse/components/Sell/Sell.tsx:113-130
Timestamp: 2025-09-09T12:40:15.629Z
Learning: In the Pulse app Sell component, when a user changes/switches tokens, the input amount automatically resets to 0, which means liquidity validation state doesn't become stale when tokens change.

Applied to files:

  • src/utils/pnl.ts
  • src/apps/pulse/components/Buy/PayingToken.tsx
🧬 Code graph analysis (2)
src/utils/pnl.ts (1)
src/apps/pulse/constants/tokens.ts (1)
  • allStableCurrencies (3-39)
src/apps/pulse/components/Buy/PayingToken.tsx (1)
src/apps/pulse/utils/number.ts (1)
  • truncateDecimals (55-68)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: unit-tests
  • GitHub Check: lint
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages: pillarx-debug

@vignesha22 vignesha22 merged commit b5c1627 into staging Dec 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants