core
core copied to clipboard
feat: Update token balances controller for multichain
Explanation
Updates the TokenBalancesController
to be used across chains.
-
It now extends
StaticIntervalPollingController
so the new token based polling patterns can be used. -
The state now stores erc20 balances across all chains and accounts. It used to only store them for the current chain and current account.
-
erc20 balances are now fetched with a single RPC multicall across all accounts + tokens (on the ~250 chains that support the multicall3 contract). Instead of doing a
balanceOf
request for each token like before.
References
Changelog
@metamask/assets-controllers
-
BREAKING: The
TokenBalancesController
state is now across all chains and accounts under the fieldtokenBalances
, as a mapping from account address -> chain id -> token address -> balance. -
BREAKING: The
TokenBalancesController
now extendsStaticIntervalPollingController
, and the new polling APIstartPolling
must be used to initiate polling.
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 highlighted breaking changes using the "BREAKING" category above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes