Skip to content

feat: add balance metadata for snap datasource [DO NOT MERGE]#9564

Open
stanleyyconsensys wants to merge 1 commit into
mainfrom
feat/asset-ctrl-balance-metadata
Open

feat: add balance metadata for snap datasource [DO NOT MERGE]#9564
stanleyyconsensys wants to merge 1 commit into
mainfrom
feat/asset-ctrl-balance-metadata

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Jul 21, 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

Note

Low Risk
Additive, optional fields on balance mapping with no auth or persistence changes; behavior unchanged when metadata is absent.

Overview
Snap balance metadata is threaded through SnapDataSource so optional fields from the keyring are not dropped when balances reach the assets pipeline.

The AccountsController:accountBalancesUpdated payload type gains optional metadata on each balance entry. When handling that event, #handleSnapBalancesUpdated copies metadata onto each AssetBalance when present. The same optional field is read from getAccountBalances during fetch and included in merged assetsBalance responses.

Reviewed by Cursor Bugbot for commit 2dd2694. Bugbot is set up for automated code reviews on this repo. Configure here.

@stanleyyconsensys
stanleyyconsensys requested a review from a team as a code owner July 21, 2026 04:34
[assetId: string]: {
amount: string;
unit: string;
metadata?: Record<string, Json>;

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.

add metadata into snap balance update event payload type

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.

Do we want type enforced payloads?

E.g. a typed descriminated union?

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.

Or maybe we can enforce a schema for runtime validation & parsing?

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.

i think in future
some snap may still using SNAP path to sync data, those data will not able to predict

adding validation may also adding a complexity on how snap ship data to controller

and it require bump up to controller when the data sharp change..., so i will suggest leave it as this (should align with keyring API)

accountAssets ??= {};
accountAssets[assetId as Caip19AssetId] = {
amount: balance.amount,
...(balance.metadata ? { metadata: balance.metadata } : {}),

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.

when persist balance data via event, we persist metadata together if any

type AssetBalance already ready to store metadata


// Step 2: Get balances for those specific assets
const balances: Record<CaipAssetType, Balance> =
const balances: Record<CaipAssetType, Balance & { metadata?: Json }> =

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.

mock keyring type

if (accountBalances) {
(accountBalances as Record<string, unknown>)[assetId] = {
amount: balance.amount,
...(balance.metadata ? { metadata: balance.metadata } : {}),

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.

when persist balance data via keyring API get balance, we persist metadata together if any

@Prithpal-Sooriya Prithpal-Sooriya 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.

Nice mock impl!

@stanleyyconsensys stanleyyconsensys changed the title feat: add balance metadata for snap datasource feat: add balance metadata for snap datasource [DO NOT MERGE] Jul 21, 2026
@stanleyyconsensys stanleyyconsensys self-assigned this Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants