Skip to content

[PR #33] balanceOfUnderlying triggers accrueInterest on every scan — use balanceOf * exchangeRateStored #97

@obchain

Description

@obchain

PR: #33 (feat/08-venus-adapter)
File: crates/charon-protocols/src/venus.rs
Lines: 84, 266-271

Problem: balanceOfUnderlying is external returns (non-view) in ABI line 84. Calls accrueInterest() internally before computing result. Adapter invokes it at line 266 inside fetch_position_inner on every (borrower, vToken) pair via eth_call. Although eth_call does not persist state, node simulates a state-mutating transaction for every call, inflating RPC cost and node CPU. Some archive nodes and rate-limiting proxies route non-view eth_calls differently and may reject or throttle them. ABI comment at 65-67 acknowledges the issue but does not fix it.

Impact: Increased RPC latency and resource usage per scan cycle. 50 borrowers x 8 markets = 400 simulated state-mutating calls per block. Archive nodes enforcing view-only eth_call semantics return errors; fetch_position_inner falls through warn! path, silently drops collateral data for every position.

Fix:

let v_balance = vt.balanceOf(borrower).call().await?.r#_0;
let rate = vt.exchangeRateStored().call().await?.r#_0;
let one_e18 = U256::from(10u64).pow(U256::from(18u64));
let supply = v_balance.saturating_mul(rate) / one_e18;

Both are pure view (ABI lines 74, 87). Remove balanceOfUnderlying from ABI block entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p0-blockerBlocks the critical path

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions