Skip to content

feat(stellar): fetch live data in keyring listAccountAssets and getAccountBalances + read balance data from AssetsController + stop account sync while Asset migration is on - #331

Open
stanleyyconsensys wants to merge 69 commits into
mainfrom
dev/stellar/asset-migration
Open

stanleyyconsensys wants to merge 69 commits into
mainfrom
dev/stellar/asset-migration

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Keyring listAccountAssets and getAccountBalances read live holdings from AssetsController when the Stellar asset migration is on.

Account synchronization is skipped only while that migration is on. AssetsController owns fungible holdings in that mode, so the snap does not persist on-chain account snapshots or emit keyring balance events. When migration is off, account sync still runs against snap state.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@stanleyyconsensys
stanleyyconsensys requested review from a team as code owners September 21, 2026 06:38
@stanleyyconsensys
stanleyyconsensys marked this pull request as draft September 21, 2026 06:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

There are confirmed blocking issues that force migration behavior on unconditionally and bypass the intended migration guard when backfilling the catalog, plus a formatting issue likely to fail lint/format checks.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity · 2 Low severity

Open (4)
What changed in this PR

Adds initial “Core assets migration” plumbing for the Stellar snap so that (when a remote flag enables it) holdings and catalog metadata can be read from Core’s AssetsController instead of snap state, while still allowing fallback to existing snap persistence where needed.

Changes:

  • Introduces AssetsService + CoreAssetsAdapter and wires Core messenger/endowments to fetch account assets and asset metadata.
  • Updates on-chain account resolution/sync to optionally bind balances from Core assets and (optionally) overlay account ledger meta from Soroban RPC.
  • Extends network layer with getAccountLedgerMeta and adds additional validation helpers for Stellar int64-like values.
File Description
yarn.lock Adds Core migration-related dependencies for the Stellar snap workspace.
packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​utils.ts Makes minimum-balance calc use a named constant; adds helper to invert minimum reserve into subentry count.
packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​utils.test.ts Adds tests for subentryCountFromMinimumReserveStroops.
packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​OnChainAccountService.ts Adds Core-backed account resolution and skips snap-state sync when migration is enabled.
packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​OnChainAccountService.test.ts Adds tests for Core-backed account resolution and migration-enabled sync skip.
packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​__mocks__/​onChainAccount.fixtures.ts Wires AssetsService into on-chain account service test fixture.
packages/​stellar-wallet-snap/​src/​services/​network/​NetworkService.ts Adds getAccountLedgerMeta via Soroban RPC getAccountEntry.
packages/​stellar-wallet-snap/​src/​services/​network/​NetworkService.test.ts Adds unit tests for getAccountLedgerMeta success/error paths.
packages/​stellar-wallet-snap/​src/​services/​network/​api.ts Adds AccountLedgerMeta type for RPC-derived account fields.
packages/​stellar-wallet-snap/​src/​services/​assets/​utils.ts Adds migration-flag helper (currently with a blocking issue noted in comments).
packages/​stellar-wallet-snap/​src/​services/​assets/​index.ts Exposes new assets facade, adapter, parsing helpers, and migration util.
packages/​stellar-wallet-snap/​src/​services/​assets/​AssetsService.ts Adds Core AssetsController facade with parsing/validation of Core payloads.
packages/​stellar-wallet-snap/​src/​services/​assets/​AssetsService.test.ts Adds tests for catalog metadata parsing and account-asset validation behavior.
packages/​stellar-wallet-snap/​src/​services/​assets/​api.ts Defines superstruct validation for Core “Stellar-shaped” asset rows/metadata.
packages/​stellar-wallet-snap/​src/​services/​assets/​api.test.ts Adds tests for the Core asset validation/parsing helpers.
packages/​stellar-wallet-snap/​src/​services/​assets/​adapters/​CoreAssetsAdapter.ts Implements adapter over AssetsProvider calls (account assets + metadata).
packages/​stellar-wallet-snap/​src/​services/​assets/​__mocks__/​assetsService.fixtures.ts Adds AssetsService test fixture with mocked adapter + feature flag values.
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​utils.ts Allows overriding icon URL (e.g., from Core metadata image).
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​AssetMetadataService.ts Adds Core metadata lookup path + migration-enabled sync skip (with one bypass issue noted in comments).
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​AssetMetadataService.test.ts Adds tests for migration-enabled sync skip and Core-first metadata resolution.
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​__mocks__/​assets.fixtures.ts Wires AssetsService into asset-metadata service mock fixture.
packages/​stellar-wallet-snap/​src/​handlers/​keyring/​keyring.ts Updates call to resolveOnChainAccountByKeyringAccountId with account address.
packages/​stellar-wallet-snap/​src/​handlers/​clientRequest/​onAmountInput.test.ts Updates expectations for the new resolveOnChainAccountByKeyringAccountId signature.
packages/​stellar-wallet-snap/​src/​handlers/​accountResolver.ts Updates call to resolveOnChainAccountByKeyringAccountId with account address.
packages/​stellar-wallet-snap/​src/​handlers/​accountResolver.test.ts Updates expectations for the new resolveOnChainAccountByKeyringAccountId signature.
packages/​stellar-wallet-snap/​src/​context.ts Wires Core messenger providers + adapter/service and injects into dependent services.
packages/​stellar-wallet-snap/​src/​constants.ts Adds ACCOUNT_MINIMUM_BASE_RESERVE_UNIT constant for minimum-balance math.
packages/​stellar-wallet-snap/​src/​api/​integer.ts Fixes max-int comparison usage and adds ValidStellarInt64Struct.
packages/​stellar-wallet-snap/​src/​api/​integer.test.ts Adds tests for ValidStellarInt64Struct.
packages/​stellar-wallet-snap/​src/​api/​core-messenger.ts Defines types/actions namespace for Core messenger endowment (formatting issue noted in comments).
packages/​stellar-wallet-snap/​snap.manifest.json Adds endowment:messenger actions for feature flag + assets controller reads.
packages/​stellar-wallet-snap/​package.json Adds devDependencies needed for Core messenger + assets controller integration.
packages/​snap-networks-utils/​src/​providers/​assets/​AssetsProvider.ts Adds AssetsController getAssetMetadata action support.
packages/​snap-networks-utils/​src/​providers/​assets/​AssetsProvider.test.ts Adds test for AssetsProvider.getAssetMetadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/stellar-wallet-snap/src/services/assets/utils.ts Outdated
Comment thread packages/stellar-wallet-snap/src/services/asset-metadata/AssetMetadataService.ts Outdated
Comment thread packages/stellar-wallet-snap/src/api/core-messenger.ts Outdated
@socket-security

socket-security Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical and moderate issues remain in network scoping, cache defaults, balance preservation, synchronization gating, and balance-limit normalization.

5 open issues

Review effort: Lite

Comment thread packages/stellar-wallet-snap/src/config.ts
Comment thread packages/stellar-wallet-snap/src/handlers/keyring/keyring.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Resolve the stale SEP-41 catalog refresh and uncached balance lookup issues, and correct the changelog wording.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Correct migration guard behavior in PR description

packages/​stellar-wallet-snap/​src/​services/​on-chain-account/​OnChainAccountService.ts:493

The PR title says account synchronization stops while Asset migration is off, but this guard skips synchronization only when isMigrationEnabled() is true; the surrounding implementation and tests describe the opposite behavior. Please correct the title/description if migration-on is intended, or revisit the guard if migration-off is the requirement.

5 resolved since last review

Review effort: Lite

@stanleyyconsensys stanleyyconsensys changed the title feat(stellar): fetch live data in keyring listAccountAssets and getAccountBalances + read balance data from AssetsController + stop account sync while Asset migration is off feat(stellar): fetch live data in keyring listAccountAssets and getAccountBalances + read balance data from AssetsController + stop account sync while Asset migration is on Oct 23, 2026
@stanleyyconsensys
stanleyyconsensys requested a lite review from Copilot October 23, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Resolve the two moderate cache and stale-catalog issues; also correct the changelog typo.

No open issues 🎉

Review effort: Lite

): Promise<Sep41StellarAssetMetadata[]> {
try {
return await this.#assetMetadataService.fetchSep41AssetsOrSyncOnce(scope);
await this.#assetMetadataService.synchronizeIfStale(scope);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the same as b4, just split into 2 method to more explicit

* @param scope - The chain ID to look up.
* @returns A Promise that resolves to all persisted SEP-41 assets for the given chain ID.
*/
async getPersistedSep41AssetsMetadata(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to getAssetsByScopeAndType

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: nice one!

Updated changelog to clarify asset balance reading conditions and included SEP-41 balances.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

This branch was successfully deployed

1 active (outdated) deployment
default-branch — 0988a17d Deployed Oct 22, 2026 by stanleyyconsensys via Determine whether this PR is a release PR #1903
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.

5 participants