Commit 281cb40
authored
feat: replace viem with manual ABI encoding (#7839)
## Explanation
The `MulticallClient` in `@metamask/assets-controller` previously used
`viem` for 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 `viem` with manual ABI encoding/decoding:
- Added low-level hex manipulation helpers (`leftPad32`,
`encodeUint256`, `encodeAddress`, etc.)
- Implemented manual encoding for `balanceOf(address)`,
`getEthBalance(address)`, and `aggregate3((address,bool,bytes)[])`
function calls
- Implemented manual decoding for `aggregate3` responses
(`(bool,bytes)[]`) and `uint256` return values
- Updated test helpers to also use manual encoding instead of `viem`
This significantly reduces the package's dependency footprint while
maintaining the same functionality.
## References
- Continues work from #7677 (MulticallClient introduction)
- Related to #7831 (isEnabled feature in same package)
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
<!-- CURSOR_SUMMARY -->
---
> [!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 `viem` with `@ethersproject/abi` for Multicall3 ABI work.**
`MulticallClient` now uses `ethers` `Interface`/`defaultAbiCoder` to
encode `balanceOf`, `getEthBalance`, and `aggregate3`, and to decode
`aggregate3` responses.
>
> Updates uint256 decoding to treat empty/short return data as zero,
adjusts tests to build mock responses via `ethers` encoding, and adds a
round-trip test that `encodeAggregate3` calldata can be decoded. Removes
`viem` from `@metamask/assets-controller` dependencies (and lockfile
transitive deps) and notes the change in the changelog.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ae46ab6. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 372d21e commit 281cb40
File tree
5 files changed
+96
-190
lines changed- packages/assets-controller
- src/data-sources/evm-rpc-services/clients
5 files changed
+96
-190
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | | - | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
Lines changed: 55 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | | - | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 56 | + | |
| 57 | + | |
60 | 58 | | |
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
72 | 70 | | |
73 | 71 | | |
74 | 72 | | |
| |||
687 | 685 | | |
688 | 686 | | |
689 | 687 | | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
690 | 729 | | |
691 | 730 | | |
692 | 731 | | |
| |||
Lines changed: 33 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | | - | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
| 57 | + | |
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
363 | 368 | | |
364 | 369 | | |
365 | 370 | | |
366 | | - | |
| 371 | + | |
367 | 372 | | |
368 | 373 | | |
369 | 374 | | |
| |||
373 | 378 | | |
374 | 379 | | |
375 | 380 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
381 | 384 | | |
382 | 385 | | |
383 | 386 | | |
| |||
387 | 390 | | |
388 | 391 | | |
389 | 392 | | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
395 | 396 | | |
396 | 397 | | |
397 | 398 | | |
| |||
403 | 404 | | |
404 | 405 | | |
405 | 406 | | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
417 | 414 | | |
418 | 415 | | |
419 | 416 | | |
| |||
428 | 425 | | |
429 | 426 | | |
430 | 427 | | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
439 | 432 | | |
440 | | - | |
| 433 | + | |
441 | 434 | | |
442 | 435 | | |
443 | 436 | | |
| |||
446 | 439 | | |
447 | 440 | | |
448 | 441 | | |
449 | | - | |
| 442 | + | |
450 | 443 | | |
451 | 444 | | |
452 | 445 | | |
| |||
457 | 450 | | |
458 | 451 | | |
459 | 452 | | |
460 | | - | |
461 | | - | |
| 453 | + | |
| 454 | + | |
462 | 455 | | |
463 | 456 | | |
464 | | - | |
465 | | - | |
466 | | - | |
| 457 | + | |
| 458 | + | |
467 | 459 | | |
468 | 460 | | |
469 | 461 | | |
| |||
0 commit comments