Skip to content

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Jan 20, 2026

Explanation

This PR introduces foundational infrastructure for a new RPC-based data source in the assets-controller package. The current architecture relies on centralized APIs for fetching token balances, which can be a bottleneck and single point of failure. This change adds the ability to fetch data directly from the blockchain via RPC calls.

Key additions:

  1. MulticallClient - A client that batches multiple ERC-20 balanceOf calls into a single RPC request using the Multicall3 contract. This significantly reduces the number of RPC calls needed when checking balances for many tokens. The client:

    • Supports 200+ chains where Multicall3 is deployed
    • Automatically falls back to individual RPC calls on unsupported chains
    • Handles both native token (ETH) and ERC-20 token balance fetching
    • Processes requests in configurable batch sizes to avoid RPC limits
  2. Batch utilities - Generic helper functions (divideIntoBatches, reduceInBatchesSerially) for processing large arrays in smaller chunks, useful for rate-limiting and memory management.

  3. Type definitions - Core types (Address, ChainId, Provider, etc.) that establish the foundation for the RPC datasource layer.

References

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 communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Establishes RPC-based balance fetching with efficient batching and strong test coverage.

  • Add MulticallClient using Multicall3 aggregate3 and getEthBalance to batch ERC‑20/native balanceOf calls; configurable maxCallsPerBatch, chain address map, and automatic fallback to individual RPC calls
  • Refactor encoding/decoding to viem (encodeFunctionData, decodeFunctionResult) and export helpers encodeAggregate3/decodeAggregate3Response
  • Add batch utilities: divideIntoBatches, reduceInBatchesSerially
  • Add RPC datasource types (Address, ChainId, Provider, etc.) and index exports
  • Tests: comprehensive unit tests for MulticallClient, ABI helpers, and batch utils
  • Deps: add viem; update changelog

Written by Cursor Bugbot for commit fe79249. This will update automatically on new commits. Configure here.

@salimtb salimtb marked this pull request as ready for review January 20, 2026 15:56
@salimtb salimtb requested review from a team as code owners January 20, 2026 15:56
cursor[bot]

This comment was marked as outdated.

@socket-security
Copy link

socket-security bot commented Jan 20, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​noble/​curves@​1.9.2 ⏵ 1.9.7100 +110010086100
Addedviem@​2.44.49910010097100

View full report

@socket-security
Copy link

socket-security bot commented Jan 20, 2026

Caution

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Block Medium
Network access: npm ox in module globalThis["fetch"]

Module: globalThis["fetch"]

Location: Package overview

From: ?npm/[email protected]npm/[email protected]

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Block Medium
Network access: npm viem in module globalThis["fetch"]

Module: globalThis["fetch"]

Location: Package overview

From: packages/assets-controller/package.jsonnpm/[email protected]

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm viem is 100.0% likely to have a medium risk anomaly

Notes: The code implements a cross-chain deposit flow with proper validations, artifact reads, and on-chain interactions. There is no evidence of hidden backdoors, data exfiltration, or malware. The main security considerations relate to token approval logic and correct configuration of flags to avoid granting excessive allowances. Overall, the module appears legitimate for a bridge deposit flow, with moderate risk primarily around configuration of approvals and correct handling of gas/fees.

Confidence: 1.00

Severity: 0.60

From: packages/assets-controller/package.jsonnpm/[email protected]

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Ignoring alerts on:

View full report

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@salimtb
Copy link
Contributor Author

salimtb commented Jan 20, 2026

@SocketSecurity ignore npm/@scure/[email protected]

This is a well-trusted cryptographic library by @paulmillr for BIP39 mnemonic generation. The network access alert refers to an optional fetch for wordlist loading, which is not used in our implementation - we only use viem for ABI encoding/decoding via encodeFunctionData and decodeFunctionResult.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

@salimtb salimtb force-pushed the feat/create-utility-func branch from ef60fe4 to fe79249 Compare January 20, 2026 20:40
@paulmillr
Copy link

@salimtb scure bip39 does not use any fetch inside, what’s going on here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants