feat(wallet): design and implement multi-asset balance model for accounts (Closes #166)#230
Merged
El-swaggerito merged 1 commit intoJul 23, 2026
Conversation
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #166
Adds a comprehensive, strongly typed Multi-Asset Balance Model to the SDK for representing accounts that hold native XLM as well as arbitrary issued credit assets (e.g. USDC, EURT, custom project tokens).
Simple balance models (like a single
nativeBalancestring) fail to scale for multi-asset mobile and web wallets. Moreover, Stellar accounts encumber balances for protocol base reserves (.0\text{ XLM} + 0.5\text{ XLM} \times \text{subentries}$), DEX selling liabilities, and issuer authorization constraints. This feature introduces a multi-asset balance structure with availability, reserve breakdowns, and status taxonomies.Changes Included
1. Types (
src/types/balance.ts&src/types/index.ts)MultiAssetBalance: Overall account balance object containingpublicKey,accountState,native,issuedAssets,unknownAssets, andtotalAssetCount.NativeAssetBalanceItem: Distinct model for native XLM withtotalBalance,availableBalance,reservedBalance,sellingLiabilities,subentryCount, andstate.IssuedAssetBalanceItem: Distinct model for issued assets withassetCode,issuer,totalBalance,availableBalance,reservedBalance,limit,isAuthorized, andstate.UnknownAssetBalanceItem: Model for unparseable or unverified asset entries.AssetBalanceState: Status discriminant (available,reserved,unauthorized,unavailable,unknown).AccountBalanceState: Account status discriminant (funded,unfunded,unavailable,unknown).2. Implementation (
src/wallet/multi-asset.ts&src/wallet/index.ts)calculateNativeReserves(subentryCount): Pure function calculating minimum protocol XLM reserves based on subentries.parseMultiAssetBalance(publicKey, horizonAccountData, accountState): Pure parser mapping raw Horizon account objects into theMultiAssetBalancemodel.getMultiAssetBalance(publicKey, config?): Horizon query returning full multi-asset model (returns clean unfunded model on 404).safeGetMultiAssetBalance(publicKey, config?): Non-throwing wrapper returningPocketPayResult<MultiAssetBalance>.formatAssetBalanceDisplay(item, decimals?): Formatting utility for mobile/web UI consumers.findAssetInMultiBalance(multiBalance, assetCode, issuer?): Search helper for locating specific asset entries.3. Documentation (
docs/multi-asset-balance-model.md&README.md)docs/multi-asset-balance-model.mddetailing model architecture, native vs issued representation, base reserve formulas, state taxonomy, and code examples for UI consumers.README.mddocumentation links.4. Tests (
tests/multi-asset-balance.test.ts)Verification
npm run verify(tsc --noEmit, circular dependency check, vitest suite, build). All 553 unit tests pass cleanly.