Context
ChainConnector in src/chain/connector.rs already wraps an alloy provider and exposes native-balance / nonce / block-number reads, but there is no helper for reading ERC-20 balances — agents using arka have to hand-roll a balanceOf(address) call every time. src/chains/arbitrum.rs already demonstrates how to do typed alloy sol! calls; we should expose a reusable ERC-20 reader on ChainConnector (and via AgentAccount when the settlement token is an ERC-20).
Scope
-
In src/chain/connector.rs, add:
pub async fn erc20_balance(&self, token: Address, holder: Address) -> Result<U256>
pub async fn erc20_decimals(&self, token: Address) -> Result<u8>
pub async fn erc20_symbol(&self, token: Address) -> Result<String>
Use alloy's sol! macro for the ABI (look at how src/chains/arbitrum.rs defines its contract interfaces).
-
Add a settlement_balance(&self, agent: Address) -> Result<U256> default method to the AgentAccount trait in src/agent/account.rs that reads the ERC-20 balance of the configured settlement token (USDC on Arbitrum). Default impl can unimplemented!() for InMemoryAgentAccount which has no on-chain token.
-
Add a unit test that deploys-by-ABI-call against a mocked provider, or — simpler — an integration test gated behind #[ignore] that hits Arbitrum mainnet USDC (0xaf88d065e77c8cC2239327C5EDb3A432268e5831) and asserts the call doesn't error. Ignored tests won't run in CI but serve as documentation.
Acceptance criteria
cargo test green (new tests included, network-dependent ones #[ignore]).
cargo clippy --all-targets -- -D warnings green.
- New methods have rustdoc comments explaining the decimals footgun (USDC = 6, DAI = 18).
examples/basic_agent.rs updated to print USDC balance using the new helper (or a new example examples/erc20_balance.rs).
Reference: see src/chains/arbitrum.rs for the sol! + IERC20 pattern and PR #4 for typed-client style.
Estimated effort
S (2–4 hours)
— kcolbchain / Abhishek Krishna
Context
ChainConnectorinsrc/chain/connector.rsalready wraps an alloy provider and exposes native-balance / nonce / block-number reads, but there is no helper for reading ERC-20 balances — agents usingarkahave to hand-roll abalanceOf(address)call every time.src/chains/arbitrum.rsalready demonstrates how to do typed alloysol!calls; we should expose a reusable ERC-20 reader onChainConnector(and viaAgentAccountwhen the settlement token is an ERC-20).Scope
In
src/chain/connector.rs, add:pub async fn erc20_balance(&self, token: Address, holder: Address) -> Result<U256>pub async fn erc20_decimals(&self, token: Address) -> Result<u8>pub async fn erc20_symbol(&self, token: Address) -> Result<String>Use alloy's
sol!macro for the ABI (look at howsrc/chains/arbitrum.rsdefines its contract interfaces).Add a
settlement_balance(&self, agent: Address) -> Result<U256>default method to theAgentAccounttrait insrc/agent/account.rsthat reads the ERC-20 balance of the configured settlement token (USDC on Arbitrum). Default impl canunimplemented!()forInMemoryAgentAccountwhich has no on-chain token.Add a unit test that deploys-by-ABI-call against a mocked provider, or — simpler — an integration test gated behind
#[ignore]that hits Arbitrum mainnet USDC (0xaf88d065e77c8cC2239327C5EDb3A432268e5831) and asserts the call doesn't error. Ignored tests won't run in CI but serve as documentation.Acceptance criteria
cargo testgreen (new tests included, network-dependent ones#[ignore]).cargo clippy --all-targets -- -D warningsgreen.examples/basic_agent.rsupdated to print USDC balance using the new helper (or a new exampleexamples/erc20_balance.rs).Reference: see
src/chains/arbitrum.rsfor thesol!+IERC20pattern and PR #4 for typed-client style.Estimated effort
S (2–4 hours)
— kcolbchain / Abhishek Krishna