Skip to main content

Module erc20

Module erc20 

Source
Expand description

Generic ERC-20 Transfer decoder (generic core).

Erc20TransferDecoder turns a standard ERC-20 Transfer(from, to, value) log into two relative balance updates — a SlotDelta::Sub on the sender’s balance slot and a SlotDelta::Add on the recipient’s — so the cache tracks balances from the event stream without ever reading the resulting absolute balances. It is the log-driven form of the Phase 3 reactive-balance case.

§Balance-slot derivation

An ERC-20 balanceOf is a mapping(address => uint256) at some base slot. The decoder hashes the owner into that mapping the canonical Solidity way: keccak256(abi.encode(owner, balance_slot)). The base slot is configurable per token (with_token) with a default fallback (new), since different tokens place balanceOf at different slots.

§Mint / burn legs

A mint (from == 0) or burn (to == 0) has no real holder on the zero-address leg, so that leg is skipped — only the non-zero side emits a delta. Cold balances follow the Phase 3 contract: the SlotDelta is skipped at apply time and surfaced in StateDiff::skipped (the caller seeds the balance, or the next read lazily fetches it). The decoder ignores the StateView — it is stateless.

Structs§

Erc20TransferDecoder
Decodes ERC-20 Transfer logs into relative balance SlotDelta updates.