/substreams-evm-extended:balance-state-packagefrom substreams-evm-extended
How to add or change a protocol balance-state package (one RPC-free map_events emitting evm.balance_state.v1) in substreams-evm-extended, with the fail-closed rules, fixture and test conventions, README template and review checklist used by the existing aave, compound-v2, compound-v3, lido and erc4626 packages.
Ships in substreams-evm-extended. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A protocol whose observable balanceOf depends on shared state (an index, an
exchange rate, packed totals) or whose ERC-20 amount is not the stored basis.
The map emits the inputs (holder basis + global words + bindings); the
consumer evaluates them at a canonical clock. Never
emit a computed balance and never replace evm.balances.v1 Balance.amount.
compound-v3/balance-state or lido/balance-state)<protocol>/balance-state/
Cargo.toml # deps: substreams, substreams-ethereum, proto, evm-persist, evm-epochs, hex, serde, serde_json, sha2, tiny-keccak
substreams.yaml # module map_events, output proto:evm.balance_state.v1.Events, default params bind nothing
Makefile, .gitignore
src/lib.rs # parse(), validate_block(), project(); handler gated #[cfg(target_arch = "wasm32")]
src/tests.rs # synthetic tests (see checklist)
tests/fixtures/<chain>-<market>-epoch(s).json
README.md
Register the crate in the root Cargo.toml members, run cargo test once
unlocked so Cargo.lock updates, then keep --locked green.
#[serde(deny_unknown_fields)]: chain_id,
producer_versions, heartbeat_blocks, and a list of markets/epochs with
epoch, model_id, source_pin, activation_block, implementation
pointer (slot + address) when the contract is a proxy, the balance mapping
slot, the scalar/packed word slots, other_slots, other_mapping_slots
and, where the source uses unstructured storage, other_slot_names hashed
at parse time. Reject overlapping slots, missing pins and producer versions
other than 4 and 5. Use evm_epochs::schedule for complete per-market
schedules: positive IDs strictly increase by unique activation position;
input order and gaps in IDs are allowed. Each interval includes its start
and excludes the next activation. A successor resets both carryover flags,
including heartbeats. The complete raw parameter digest identifies the
stream; changing the schedule requires a new qualified stream/checkpoint.evm_persist::collect_block into a Sink
that collects storage writes (and native balance changes or code changes
when needed). Never read Call.storage_changes directly.(address, key) in ordinal order: strictly increasing
ordinals (ambiguous otherwise), old == previous new (discontinuous
otherwise), keep first old / last new, first_ordinal, ordinal,
change_count, last write's transaction/call provenance. Include address,
key and ordinals in the error messages.keccak_preimages from every call whose address is
the contract or that writes the contract's storage (delegatecall frames
have Call.address == implementation); verify keccak(value) == key; a
holder key is a 64-byte preimage with 12 zero bytes and the balance slot as
base; use mapping_has_base for nested mappings and struct-word offsets.HolderBasis for every reduced write to a verified holder key;
GlobalState for every decoded field of a written word (the proto says one
row per decoded field; do not filter unchanged fields without a documented
decision); ModelEpoch BOUND at activation_block and REAFFIRMED on
the heartbeat with dependencies and qualified constants; INVALIDATED rows
with evidence for every pointer write (including equal/restored values)
and code change; exactly one BlockClock. The earliest invalidation is
exclusive. Validate the preceding decoded prefix, but omit holder and
stored/derived end-of-block rows for epochs invalidated or scheduled to
retire in this block. Preserve declarations and valid log evidence.
Unobserved successor values stay unknown until fresh observations or an
independently qualified checkpoint initialize them.Block.ver, malformed
persisted records, invalid preimages, and any persisted write to the
contract that is not a configured word, a verified holder key, a pointer or
a reviewed slot / mapping member. Dependencies' unrelated storage is ignored.Reentrancy guards and version flags are written even when balances are not:
Comet keccak256("comet.reentrancy.guard"), cToken _notEntered (slot 0),
Aragon aragonOS.reentrancyGuard.mutex. evm-persist routes writes whose old
and new values are equal through storage_noop: include them in physical
continuity checks and pointer invalidation evidence. Ordinary noops do not
initialize observations. The sequence 0→1 then 1→0 contains two changed
writes that reduce to old == new and must be reviewed. Read the pinned source for every
nonReentrant, whenNotPaused, nonce and counter write.
source_pin; slots as 32-byte hex;
placeholders (implementation, activation_block: 1) must be called out in
the README as unverified.docs/storage-layout-provenance.md), fail-closed rules (table), validation
commands, what the tests cover and what remains live-gated, issue link.README.md package list and the package table in
docs/handoff.md.old_value: vec![]), full withdrawal to "0"previous_value, value, change_count,
first_ordinal, ordinal, transaction_hash of the last writeambiguous) and discontinuity; ordinal 0status: 0 refused; system-call scopeCall.address == implementation, writes on the proxyvalidate_block refusal (detail level, header, hashes, number,
timestamp, tx status)storage_contract; heartbeat REAFFIRMEDcargo fmt --all -- --check
cargo test --locked --workspace --lib --bins --tests
cargo clippy --locked --workspace --all-targets -- -D warnings # rustdoc lints count
cargo clippy --locked --workspace --target wasm32-unknown-unknown -- -D warnings
cargo check --locked --workspace --target wasm32-unknown-unknown
RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps --workspace
CI also runs rustdoc for wasm32 (ci.yml).
"" vs "0", previous values, scales, enums, key
conventions, storage_contract vs market, ModelEpoch/Dependency fields,
clock counts, sort order, README tables vs code.docs/history/review-findings-<date>.md.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub pinax-network/substreams-evm-balances --plugin substreams-evm-extended4 skills in this plugin
/pinned-source-researchHow to bind a contract to a pinned source offline for substreams-evm-extended: which files to fetch, what to extract (declaration order, packing, constants, keccak-named and ERC-7201 slots, formulas, rounding, events), how to write source_pin strings and where to store the notes./roadmap-issue-workflowHow roadmap issues in pinax-network/substreams-evm-extended move from acceptance list to merged PR and status comment: reading the issue, doing the offline part, commit and PR conventions, CI constraints, polling checks and merging without auto-merge, and when an issue may be closed./storage-layout-verificationHow to upgrade a balance-state fixture's inferred storage slots to compiler-verified layouts offline with solc --storage-layout (or an AST walk for solc 0.4.x), store the layout as evidence and pin fixture slots to it with a Rust test.