Send Soroban token transfer amounts to `/simulate-token-transfer` as strings

Open Beginner friendly
#3,088 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
api, frontend

Research direction

Start in extension/src/popup/components/send/SendAmount/hooks/useSimulateTxData.tsx at the /simulate-token-transfer request and check the request type in @shared/api/internal.ts. Send the parsed base-unit amount as an integer string, then review the simulate-token-transfer stubs in extension/e2e-tests for numeric amount assertions. Done when sending 1.5 units of an 18-decimal token posts "1500000000000000000" and the simulated transfer carries that amount.

Written by the indexing model from the issue text.

Description

enhancement

Affects sends of high-decimal Soroban tokens today. It also blocks the backend from rejecting unsafe numeric amounts (stellar/freighter-backend#331).

TL;DR: The send flow converts the base-unit amount to a JS number before posting it to /simulate-token-transfer. Anything above Number.MAX_SAFE_INTEGER (~9.007e15) gets rounded in the browser, so the backend builds the transfer from a different amount than the user entered. For an 18-decimal token, that's any send over ~0.009 tokens. Send the amount as an integer string instead. The backend already accepts strings up to the i128 max.


Details

Where:

  • extension/src/popup/components/send/SendAmount/hooks/useSimulateTxData.tsx:566 sends amount: parsedAmount.toNumber()
  • @shared/api/internal.ts types params.amount as number

Fix:

  1. Send parsedAmount.toFixed() (toFixed() with no argument never switches to exponential notation).
  2. Change the request type to amount: string.
  3. Update the simulate-token-transfer stubs in extension/e2e-tests if any assert on a numeric amount.

Mobile already does this (BigNumber(amount).shiftedBy(decimals).toFixed(0) in transactionService.ts), so no counterpart is needed.

Related, optional: extension/src/popup/helpers/sorobanSwap.ts:146, :253 and :257 also call .toNumber() on parsed amounts for Soroswap quotes and swap args. That's a different endpoint, but the precision loss is the same.

Acceptance: a send of 1.5 units of an 18-decimal token posts "1500000000000000000", and the simulated transfer carries that exact amount.

Once this release has rolled out, the backend can reject non-safe numeric amounts: stellar/freighter-backend#331 (https://github.com/stellar/freighter-backend/pull/331#discussion_r4542794041).

Dominant language
TypeScript
Stars
122
Forks
62
Avg merge
4d 19h
Merged PRs (30d)
41

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/freighter

All issues in stellar/freighter

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.