Skip to content

fix(withdrawal): normalize balance to USD before capping in VerifiedFiatCalculator#763

Merged
bmc08gt merged 1 commit into
code/cashfrom
fix/withdrawal-cross-currency-subtraction
May 22, 2026
Merged

fix(withdrawal): normalize balance to USD before capping in VerifiedFiatCalculator#763
bmc08gt merged 1 commit into
code/cashfrom
fix/withdrawal-cross-currency-subtraction

Conversation

@bmc08gt
Copy link
Copy Markdown
Collaborator

@bmc08gt bmc08gt commented May 22, 2026

When a user local currency is stronger than USD (e.g. GBP at fx=0.79), the balance in local currency quarks is smaller than the USD equivalent. The min() comparison picked the local-currency Fiat, corrupting underlyingTokenAmount with a non-USD currency code. This caused TransactionService.withdrawUsdf to throw "Cannot subtract different currencies" when subtracting the fee (correctly in USD) from the corrupted amount.

Convert balance to USD via convertingToUsdIfNeeded before the min() comparison so cappedValue always preserves the USD currency code.

Also adds withdrawal breadcrumb traces in TransactionController for both withdraw and withdrawUsdf paths, and two regression tests covering the cap fix and the full subtraction path.

Bugsnag: 6a0f534a8c3285d1a5b1aea3

@bmc08gt bmc08gt self-assigned this May 22, 2026
@github-actions github-actions Bot added type: fix Bug fix area: network gRPC, connectivity, API, exchange rates labels May 22, 2026
…iatCalculator

When a user local currency is stronger than USD (e.g. GBP at fx=0.79),
the balance in local currency quarks is smaller than the USD equivalent.
The min() comparison picked the local-currency Fiat, corrupting
underlyingTokenAmount with a non-USD currency code. This caused
TransactionService.withdrawUsdf to throw "Cannot subtract different
currencies" when subtracting the fee (correctly in USD) from the
corrupted amount.

Convert balance to USD via convertingToUsdIfNeeded before the min()
comparison so cappedValue always preserves the USD currency code.

Also adds withdrawal breadcrumb traces in TransactionController for
both withdraw and withdrawUsdf paths, and two regression tests covering
the cap fix and the full subtraction path.

Bugsnag: 6a0f534a8c3285d1a5b1aea3

Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
@bmc08gt bmc08gt force-pushed the fix/withdrawal-cross-currency-subtraction branch from 62a738a to f086666 Compare May 22, 2026 15:58
@bmc08gt bmc08gt merged commit d69acb6 into code/cash May 22, 2026
2 checks passed
@bmc08gt bmc08gt deleted the fix/withdrawal-cross-currency-subtraction branch May 22, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: network gRPC, connectivity, API, exchange rates type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant