core icon indicating copy to clipboard operation
core copied to clipboard

feat: Update token balances controller for multichain

Open bergeron opened this issue 4 months ago • 0 comments

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 field tokenBalances, as a mapping from account address -> chain id -> token address -> balance.

  • BREAKING: The TokenBalancesController now extends StaticIntervalPollingController, and the new polling API startPolling 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

bergeron avatar Oct 10 '24 16:10 bergeron