Defi controller v2#9503
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
| 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', | ||
| 'eip155:999', | ||
| 'eip155:5042', | ||
| ]; |
There was a problem hiding this comment.
There is no API that we can hit to get this list.
It's the intersection between what accounts API supports and zerion supports.
Definitely not ideal if we want to dynamically support new chains.
There was a problem hiding this comment.
The goal of this file is to create the query string parameters that need to be passed to accounts api, as well as a mapping between the internal accountIds used in state and the CAIP-10 account ids that the request and response from accounts-api deals with.
There was a problem hiding this comment.
I don't think we want to lose this visualizer. It has been very helpful to inspect the response from the API.
There was a problem hiding this comment.
I wonder if we want to exclude this from the library build via the tsconfig.build.json?
"exclude": ["**/devtools/"]
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a8f2b54. Configure here.
| // staleTime: 0 makes TanStack treat the cache as stale for this call. | ||
| ...(options?.forceRefresh ? { staleTime: 0 } : {}), | ||
| }, | ||
| ); |
There was a problem hiding this comment.
Throttling is managed at apiClient level (Tanstack) using the parameters (key).
We can still force a fetch with forceRefresh.
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |


Explanation
Export new DeFiPositionsControllerV2 and supporting types.
It fetches from accounts api v6 endpoint for a single account group and it does so only by demand.
Extension preview PR: MetaMask/metamask-extension#44392
Mobile preview PR: MetaMask/metamask-mobile#33488
Extension.DeFi.Demo.mp4
Mobile.DeFi.Demo.mp4
References
Related to https://consensyssoftware.atlassian.net/browse/ASSETS-3600
Checklist
Note
Medium Risk
New persisted wallet/DeFi state and external API integration affect balance UX, but it is gated by
isEnabled, isolated from the legacy controller key, and covered by extensive unit tests.Overview
Introduces
DeFiPositionsControllerV2, a parallel DeFi positions controller that loads data on demand from the Accounts API v6 multiaccount balances endpoint (viaApiPlatformClient), instead of the legacy controller’s flow. Clients callfetchDeFiPositions(messenger action supported); there are no automatic event subscriptions yet.Fetched positions are normalized with
groupDeFiPositionsV6and persisted underallDeFiPositionsV2, keyed by internal account ID, in a shape meant for the DeFi tab and details UI (protocol groups per chain, sections, market values with lending treated as liabilities).buildDeFiBalancesQuerybuilds CAIP account IDs and supported EVM/Solana networks from the selected account group;mergePositionsForAccountsmerges per-account state for group-level surfaces.Behavior details: no-ops when disabled or when the group has no EVM/Solana accounts; respects
processingDefiPositionsby keeping prior state for still-indexing accounts; merges updates per account without wiping unrelated accounts;forceRefreshbypasses TanStack Query cache (staleTime: 0); failed fetches leave existing state. Types and helpers are exported from the package; changelog updated. A dev-only HTML visualizer is included for inspecting v6 DeFi responses.Reviewed by Cursor Bugbot for commit 7144a63. Bugbot is set up for automated code reviews on this repo. Configure here.