Skip to content

feat: end-to-end multi-token (SEP-41) deposit support (Closes #255) - #256

Open
waterWang wants to merge 1 commit into
JointSave-org:mainfrom
waterWang:feat/multi-token-deposit
Open

feat: end-to-end multi-token (SEP-41) deposit support (Closes #255)#256
waterWang wants to merge 1 commit into
JointSave-org:mainfrom
waterWang:feat/multi-token-deposit

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Implements end-to-end multi-token (SEP-41) deposit support for pools, per issue #255. The contract already exposes set_supported_tokens / get_supported_tokens; this PR wires the token-aware amount maths and activity recording that the deposit flow was missing.

What changed

frontend/lib/deposit-token.ts — new dependency-free pure-logic module (mirroring deposit-calendar.ts / batch-deposit.ts) shared by the deposit UI and API:

  • normalizeDecimals / humanToBaseUnits / baseUnitsToHuman / trimHumanAmount — exact human ↔ base-units (stroops) conversion per asset decimals, immune to floating-point error ("0.07" @ 7 decimals → exactly 700000)
  • validateTokenSelection — checks a chosen token against the pool's supported set (empty list = unrestricted), with clear per-pool errors
  • checkSufficientBalance — validates a human amount against an on-chain base-units balance in the correct unit
  • computeDepositFee — treasury + relayer bps fee computed in the settlement token's own unit

frontend/lib/deposit-token.test.ts — 14 unit tests covering decimals conversion, token selection, balance checks and fee maths.

frontend/app/api/pools/deposit/route.ts — token-aware deposit route:

  • Accepts optional tokenSymbol, tokenDecimals, tokenAmount
  • Validates that tokenAmount has at most the asset's supported precision (rejects e.g. 8 decimals for a 7-decimal asset)
  • Records token_amount (token-denominated) alongside amount so deposit history can be broken out by currency
  • Describes the activity row with the token symbol for non-XLM currencies

frontend/components/group/group-actions.tsx — passes the pool's tokenSymbol through to the deposit logging route.

frontend/package.jsontest:unit includes the new deposit-token.test.ts.

Verification

  • 126/126 unit tests pass (14 new + existing suites)
  • batch-deposit.test.tsx 12/12, group-actions.test.tsx 8/8 pass
  • tsc --noEmit — no new errors from changed files (73 pre-existing unrelated errors untouched)
  • ESLint clean on all changed files; Prettier formatted

Closes #255

- lib/deposit-token.ts: pure decimals/amount math, token-selection
  validation, balance checks and fee computation (shared by UI + API)
- unit tests: 14 cases covering conversion, selection, balance, fees
- /api/pools/deposit: accept tokenSymbol/tokenDecimals/tokenAmount and
  record token-denominated amounts with per-asset precision validation
- group-actions: pass pool token into deposit activity logging
@Sendi0011

Copy link
Copy Markdown
Contributor

Coordination: duplicates #257 (both close #255)

Nice implementation — the integer-exact SEP-41 amount maths and the shared deposit-token.ts module are well done. However, this PR and PR #257 both close issue #255 (multi-token SEP-41 deposits) and modify the same core files (app/api/pools/deposit/route.ts, group-actions.tsx, lib/deposit-token.ts, lib/deposit-token.test.ts).

PR #257 is currently the more complete of the two (it adds the supported_tokens DB migration, token-settings UI, tx-retry, and pending-transactions wiring) and is mergeable-clean, while this PR shows dirty (conflicts). To avoid a merge conflict and a double-implementation of the same feature, please coordinate: either rebase and reconcile against #257, or close this PR in favour of #257 (its deposit-token maths can be reused).

No issues with the code itself — happy to approve if this is the one we keep, but only one of the two can merge.

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.

[Feature] End-to-end multi-token (SEP-41) deposit support for pools

2 participants