Skip to content

feat: balance checker added#571

Open
0xHarbs wants to merge 2 commits intodevfrom
feat/balance-checker
Open

feat: balance checker added#571
0xHarbs wants to merge 2 commits intodevfrom
feat/balance-checker

Conversation

@0xHarbs
Copy link
Collaborator

@0xHarbs 0xHarbs commented Mar 10, 2026

🤖 Linear

Adding balance checker to the monorepo.

Copilot AI review requested due to automatic review settings March 10, 2026 11:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Solidity utility contract under packages/contracts to query ERC20 balances (single + batch) and also returns the native (ETH) balance in the batch variant.

Changes:

  • Introduces BalanceChecker contract with a single-token balance getter.
  • Adds an overloaded batch balance getter that also appends native balance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return IERC20(_token).balanceOf(_account);
}

function getTokenBalance(address[] memory _token, address _account) external view returns (uint256[] memory) {
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

These two overloaded getTokenBalance functions can be awkward for off-chain consumers (ethers/web3) because calling an overloaded function often requires using the fully-qualified signature string. If this contract is intended for broad external consumption, consider renaming the array version to something like getTokenBalances (and/or clarifying whether native balance is included).

Suggested change
function getTokenBalance(address[] memory _token, address _account) external view returns (uint256[] memory) {
function getTokenBalances(address[] memory _token, address _account) external view returns (uint256[] memory) {

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +13
function getTokenBalance(address _token, address _account) external view returns (uint256) {
return IERC20(_token).balanceOf(_account);
}

function getTokenBalance(address[] memory _token, address _account) external view returns (uint256[] memory) {
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

A new intent contract is introduced without corresponding unit tests. The packages/contracts/test/unit/intent/ suite has coverage for other intent contracts; adding tests for both the single-token and multi-token/native-balance behaviors would help prevent regressions and clarify the intended return shape.

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +20
uint256[] memory balances = new uint256[](_token.length + 1);
for (uint256 i = 0; i < _token.length; i++) {
balances[i] = IERC20(_token[i]).balanceOf(_account);
}
balances[_token.length] = _account.balance;
return balances;
}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The array overload of getTokenBalance allocates tokens.length + 1 and appends the native (ETH) balance at the end. Given the function name/signature, this is easy for callers to misinterpret and can lead to off-by-one mistakes (output length no longer matches the input token list). Consider renaming and/or changing the API so the return shape clearly reflects whether native balance is included and in what position.

Suggested change
uint256[] memory balances = new uint256[](_token.length + 1);
for (uint256 i = 0; i < _token.length; i++) {
balances[i] = IERC20(_token[i]).balanceOf(_account);
}
balances[_token.length] = _account.balance;
return balances;
}
uint256[] memory balances = new uint256[](_token.length);
for (uint256 i = 0; i < _token.length; i++) {
balances[i] = IERC20(_token[i]).balanceOf(_account);
}
return balances;
}
function getNativeBalance(address _account) external view returns (uint256) {
return _account.balance;
}

Copilot uses AI. Check for mistakes.
return IERC20(_token).balanceOf(_account);
}

function getTokenBalance(address[] memory _token, address _account) external view returns (uint256[] memory) {
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

getTokenBalance(address[] ...) takes the token array as memory even though the function is external. Using calldata here avoids an unnecessary copy and is the common pattern used elsewhere in this package for external array inputs.

Suggested change
function getTokenBalance(address[] memory _token, address _account) external view returns (uint256[] memory) {
function getTokenBalance(address[] calldata _token, address _account) external view returns (uint256[] memory) {

Copilot uses AI. Check for mistakes.
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

contract BalanceChecker {
constructor() {}
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Empty constructor is redundant here (no state initialization) and can be removed to reduce bytecode size and avoid implying there is construction logic.

Suggested change
constructor() {}

Copilot uses AI. Check for mistakes.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

Import formatting is inconsistent with the rest of the Solidity codebase, which uses no spaces inside the curly braces (e.g. import {IERC20} ...). This file currently uses import { IERC20 } ...; consider matching the existing style to keep forge fmt / lint output consistent.

Suggested change
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

Copilot uses AI. Check for mistakes.
@0xHarbs 0xHarbs changed the title feat: balance checked added feat: balance checker added Mar 10, 2026
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