Defi controller v2#9503
Conversation
|
@metamaskbot publish-preview |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ 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 2a8139a. Configure here.
| )) { | ||
| state.allDeFiPositionsV2[accountId] = positions; | ||
| } | ||
| }); |
There was a problem hiding this comment.
DeFi state not fully refreshed
Medium Severity
After a successful fetch, allDeFiPositionsV2 only updates account keys returned by groupDeFiPositionsV6, so queried accounts missing from the API response keep old positions. Early returns when the group has no DeFi-capable accounts leave prior group data in persisted state.
Reviewed by Cursor Bugbot for commit 2a8139a. Configure here.
| return { | ||
| networks: [...new Set(networks)] as CaipChainId[], | ||
| internalAccountIdByCaip, | ||
| }; |
There was a problem hiding this comment.
Networks list not always complete
Medium Severity
buildDeFiBalancesQuery builds the networks request parameter from EVM-only or Solana-only subsets based on which account types appear in the group, instead of always sending the full DEFI_SUPPORTED_NETWORKS list.
Reviewed by Cursor Bugbot for commit 2a8139a. Configure here.
| balance.metadata !== undefined && | ||
| (balance.metadata as Partial<V6BalanceMetadata>).protocolId !== undefined | ||
| ); | ||
| } |
There was a problem hiding this comment.
Position types not validated
Medium Severity
DeFi rows are accepted when only protocolId is present; positionType is not checked against exported DEFI_POSITION_TYPES, and liability handling hardcodes only lending instead of using that canonical list.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 2a8139a. Configure here.
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |


Explanation
References
Checklist
Note
Medium Risk
New portfolio-facing fetch path and valuation rules (e.g. lending liabilities), but additive alongside the legacy controller with broad unit tests and no auth changes.
Overview
Introduces
DeFiPositionsControllerV2, which loads DeFi positions for the selected account group viafetchV6MultiAccountBalances, maps per-chain CAIP-10 responses back to internal account IDs, and persistsallDeFiPositionsV2as protocol groups the DeFi tab can read without extra shaping.Supporting pieces include
buildDeFiBalancesQuery(EVM all-chains + Solana CAIP IDs, supported network list, EVM case normalization),groupDeFiPositionsV6(chain/protocol grouping, detail sections byprotocolName, icon stack,lendingsubtracted from aggregatedmarketValue), messengerfetchDeFiPositionswith per-account throttling and retry on failure, and a standalonedefi-visualizer.htmlfor manual API inspection.@metamask/core-backendnow exportsV6_DEFI_POSITION_TYPES/V6DeFiPositionTypeand typesV6BalanceMetadata.positionTypeaccordingly. Public exports fromassets-controllerscover the controller, state defaults, action types, and helpers. LegacyDeFiPositionsControlleris unchanged; the V2 state key avoids collisions when both run in one client.Reviewed by Cursor Bugbot for commit 2a8139a. Bugbot is set up for automated code reviews on this repo. Configure here.