Skip to content

[PERF] Build Assembly Multi-Token Balance Query Loop #690

Description

@mijinummi

Labels: medium-difficulty, yul, tokens, gasguard
Difficulty: Medium
Module: contracts/utils/


🧠 Concept

Develop a view helper that queries balance states for multiple ERC-20 tokens across multiple accounts within a single static assembly call loop.

⚠️ Problem

Querying token balances individually over standard high-level interfaces incurs substantial call setup and return data decoding overhead per token.

📁 Implementation Scope

  • contracts/utils/BatchBalanceChecker.sol
  • test/utils/BatchBalanceChecker.test.ts

🛠️ Requirements

  1. Construct balanceOf(address) selector in memory once.
  2. Iterate through target tokens and accounts using low-level staticcall.
  3. Pack balance outputs directly into an assembly-allocated memory buffer.

🎯 Acceptance Criteria

  • Queries batch token balances with minimal gas overhead.
  • Handles reverts or non-contract target addresses without halting the loop.

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions