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
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

1 participant