Skip to content

fix(staking-cli): truncate balance display instead of rounding up#34

Merged
arein merged 1 commit into
mainfrom
fix/balance-display-truncation
Mar 5, 2026
Merged

fix(staking-cli): truncate balance display instead of rounding up#34
arein merged 1 commit into
mainfrom
fix/balance-display-truncation

Conversation

@arein
Copy link
Copy Markdown
Contributor

@arein arein commented Mar 5, 2026

Summary

  • Fix formatWCT rounding bug: Truncates to 2 decimal places instead of rounding, so the displayed balance is never higher than the actual on-chain balance (e.g. shows 112.88 instead of 112.89 for 112.887964... WCT)
  • Add pre-flight balance check in stake: Checks on-chain balance before sending the approve tx, preventing wasted gas when the requested amount exceeds the actual balance
  • Add truncation tests: Covers the exact bug scenario and a .999 edge case

Fixes: balance display rounds up, causing stake with displayed full balance to always revert with ERC20InsufficientBalance.

Test plan

  • All 27 staking-cli tests pass (including 2 new truncation tests)
  • Manual test: run balance and verify displayed value is ≤ actual on-chain balance
  • Manual test: run stake with amount exceeding balance and verify early error (no approve tx sent)

🤖 Generated with Claude Code

formatWCT used toLocaleString rounding, which could display a value
higher than the actual on-chain balance (e.g. 112.89 instead of
112.88). Users copying the displayed balance into `stake` would get
ERC20InsufficientBalance reverts. Now truncates to 2 decimal places.

Also adds a pre-flight balance check in `stake` before the approve tx
to avoid wasting gas when the amount exceeds the actual balance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@arein arein merged commit 6c8ed5f into main Mar 5, 2026
4 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 5, 2026
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.

1 participant