Skip to content

feat(Stellar): asset enrichment through snap data source#9422

Draft
khanti42 wants to merge 8 commits into
mainfrom
feat/asset-balance-enrichment-snap
Draft

feat(Stellar): asset enrichment through snap data source#9422
khanti42 wants to merge 8 commits into
mainfrom
feat/asset-balance-enrichment-snap

Conversation

@khanti42

@khanti42 khanti42 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Explanation

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

Comment on lines +306 to +322
if (assetsBalance) {
const response: DataResponse = { assetsBalance, updateMode: 'merge' };
for (const subscription of this.activeSubscriptions.values()) {
subscription.onAssetsUpdate(response)?.catch(console.error);
}
if (!assetsBalance) {
return;
}

const response: DataResponse = { assetsBalance, updateMode: 'merge' };
for (const subscription of this.activeSubscriptions.values()) {
subscription.onAssetsUpdate(response)?.catch(console.error);

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.

this should not change

* Handle snap balance updates from the keyring.
* Transforms the payload and publishes to AssetsController.
*
* Push updates carry amounts only. Per-asset snap enrichment (e.g. Stellar

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.

no need to add comment

}
}

if (

@stanleyyconsensys stanleyyconsensys Jul 8, 2026

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.

we should just add step 3 with Feature flag

}
}
results.assetsBalance ??= {};
const accountBalances = results.assetsBalance[accountId] ?? {};

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.

on step 3:

if stellar feature flag:

  • fetch enrichment
  • update the state (results.assetsBalance)

@stanleyyconsensys stanleyyconsensys changed the title chore: [STELLAR] asset enrichment through snap data source feat(Stellar): asset enrichment through snap data source Jul 8, 2026
* When false, SnapDataSource skips `getAccountAssetInfo` enrichment.
* Evaluated at call time. Defaults to () => false.
*/
assetEnrichmentEnabled?: () => boolean;

@stanleyyconsensys stanleyyconsensys Jul 8, 2026

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.

i think they prefer stellar focus, but up to them

and there are 2 way to get feature flag

  1. use messenger call directly from data source, so u dont need pass in , as we are temp solution, which i think is better (please check packages/network-controller/src/NetworkController.ts)
  2. pass in from client, like what u did

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.

Yep, if poss can we make this stellar specific? This is mostly generic, but let's keep it as a stellar flag

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.

@salimtb confirm we should pass feature flag from client side

change assetEnrichmentEnabled to isStellarEnabled

})
) {
// TODO(STELLAR): Remove this Snap-side accountAssetInfo enrichment path once the Accounts API returns account-asset enrichment directly.
await enrichAccountAssetInfo({

@stanleyyconsensys stanleyyconsensys Jul 8, 2026

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.

um..i feel just do:

  1. call snap
  2. modify data

that will be clear enough
putting into a function, may create complexity, but it also clean

i leave it to Asset team

Suggested change
await enrichAccountAssetInfo({
for (acc in accounts) {
const result = await callSNAP()
mergeResultIntoExistingBalanceData()
}

const next: Record<string, AssetBalance> = { ...previousBalances };
for (const [assetId, balance] of Object.entries(accountBalances)) {
next[assetId] = {
...(previousBalances[assetId] ?? { amount: '0' }),

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.

still have amt 0?


### Added

- Add optional `snapDataSourceConfig.assetEnrichmentEnabled` getter to `AssetsControllerOptions` so clients can enable or disable snap `getAccountAssetInfo` enrichment at runtime (defaults to disabled)

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.

Let's add the PR number and link.

Comment thread packages/assets-controller/package.json Outdated
{
"name": "@metamask/assets-controller",
"version": "10.0.1",
"version": "10.0.1-dev.8",

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.

Ah nice, didn't know you could do this for testing. Let's clean up

* When false, SnapDataSource skips `getAccountAssetInfo` enrichment.
* Evaluated at call time. Defaults to () => false.
*/
assetEnrichmentEnabled?: () => boolean;

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.

Yep, if poss can we make this stellar specific? This is mostly generic, but let's keep it as a stellar flag

* Optional per-asset fields from snap account-asset enrichment.
* Stellar classic assets use trustline fields; native XLM may include baseReserve.
*/
export type AccountAssetInfo = {

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.

To future proof this, thoughts on making this a discriminated typed union.

{
  type: "StellarAccountAssetInfo",
  ...
}

That way we have protection as other future network specific shapes are needed.

Likewise let's also "parse, don't validate" by using @metamask/superstruct to create structs that can parse the right shape (use as type assertion functions).

// standard (unenriched) balance shape. When the feature flag is enabled
// and there are eligible assets, apply accountAssetInfo enrichment once.
if (
this.#assetEnrichmentEnabled() &&

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.

Suggested change
this.#assetEnrichmentEnabled() &&
this.#isStellarEnabled() &&

Comment on lines +530 to +532
// Post-fetch enrichment stage: assetsBalance above already matches the
// standard (unenriched) balance shape. When the feature flag is enabled
// and there are eligible assets, apply accountAssetInfo enrichment once.

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.

Suggested change
// Post-fetch enrichment stage: assetsBalance above already matches the
// standard (unenriched) balance shape. When the feature flag is enabled
// and there are eligible assets, apply accountAssetInfo enrichment once.

/** Raw balance amount as string (e.g., "1000000000" for 1000 USDC) */
amount: string;
/** Optional per-asset info from snap account-asset enrichment (e.g. Stellar trustlines). */
accountAssetInfo?: AccountAssetInfo;

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.

change accountAssetInfo => metadata

/** Per-asset enrichment keyed by CAIP-19 asset id from snap getAccountAssetInfo. */
export type GetAccountAssetInfoResponse = Record<
Caip19AssetId,
AccountAssetInfo

@stanleyyconsensys stanleyyconsensys Jul 9, 2026

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.

Suggested change
AccountAssetInfo
Record<string, unknown>

client side using super struct to verify the data, when they use it

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.

3 participants