Skip to content

fix(svm): convert SPL/Jupiter amounts without float drift - #1609

Open
ninglinLiu wants to merge 1 commit into
coinbase:mainfrom
ninglinLiu:fix/spl-fractional-amount-bigint
Open

ninglinLiu wants to merge 1 commit into
coinbase:mainfrom
ninglinLiu:fix/spl-fractional-amount-bigint

Conversation

@ninglinLiu

Copy link
Copy Markdown

Summary

Fixes #1574.

SplActionProvider.transfer and JupiterActionProvider.swap scaled human amounts with amount * 10 ** decimals. Binary floats cannot represent many decimal fractions, so values like 2.01 at 6 decimals become 2009999.9999999998 — BigInt(...) throws on SPL transfers, and Jupiter receives a non-integer amount.

Adds toTokenBaseUnits (via decimal.js, already a dependency) and uses it in both action providers.

Test plan

  • pnpm exec jest --testPathPattern=utils.test — covers 2.01 → 2010000n
  • pnpm exec jest --testPathPattern=splActionProvider.test (src suite green)

Fractional amounts like 2.01 USDC produced non-integer floats via
`amount * 10 ** decimals`, so BigInt threw and Jupiter quotes got a
fractional amount. Route both through toTokenBaseUnits (decimal.js).

Fixes coinbase#1574

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

SPL transfer and Jupiter swap fail for fractional amounts like 2.01

1 participant