feat: replace viem with manual ABI encoding#7839
Merged
Conversation
packages/assets-controller/src/data-sources/evm-rpc-services/clients/MulticallClient.ts
Outdated
Show resolved
Hide resolved
Contributor
Author
|
@metamaskbot publish-preview |
packages/assets-controller/src/data-sources/evm-rpc-services/clients/MulticallClient.ts
Outdated
Show resolved
Hide resolved
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
cryptodev-2s
reviewed
Feb 4, 2026
| - Add batch utilities (`divideIntoBatches`, `reduceInBatchesSerially`) for processing arrays in batches ([#7677](https://github.com/MetaMask/core/pull/7677)) | ||
| - Add `TokenDetector` service for detecting ERC-20 tokens with non-zero balances on a chain ([#7683](https://github.com/MetaMask/core/pull/7683)) | ||
| - Add `BalanceFetcher` service for fetching token balances for user's imported/detected tokens ([#7684](https://github.com/MetaMask/core/pull/7684)) | ||
| - Add `viem` dependency for ABI encoding/decoding in MulticallClient |
Contributor
There was a problem hiding this comment.
Why did we remove this changelog entry if this version is already released ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
The
MulticallClientin@metamask/assets-controllerpreviously usedviemfor ABI encoding and decoding of Multicall3 contract calls. This introduced a heavy dependency (~500KB+ bundled) for functionality that could be implemented with minimal code.This PR replaces
viemwith manual ABI encoding/decoding:leftPad32,encodeUint256,encodeAddress, etc.)balanceOf(address),getEthBalance(address), andaggregate3((address,bool,bytes)[])function callsaggregate3responses ((bool,bytes)[]) anduint256return valuesviemThis significantly reduces the package's dependency footprint while maintaining the same functionality.
References
Checklist
Note
Medium Risk
Changes the ABI encoding/decoding used for Multicall3 batching and balance parsing, which can impact token/native balance fetching if calldata or return-data handling differs. Test coverage was updated/expanded, but this still touches core RPC interaction paths.
Overview
Replaces
viemwith@ethersproject/abifor Multicall3 ABI work.MulticallClientnow usesethersInterface/defaultAbiCoderto encodebalanceOf,getEthBalance, andaggregate3, and to decodeaggregate3responses.Updates uint256 decoding to treat empty/short return data as zero, adjusts tests to build mock responses via
ethersencoding, and adds a round-trip test thatencodeAggregate3calldata can be decoded. Removesviemfrom@metamask/assets-controllerdependencies (and lockfile transitive deps) and notes the change in the changelog.Written by Cursor Bugbot for commit ae46ab6. This will update automatically on new commits. Configure here.