Skip to content

[pallet-revive] index pallet-assets transfers as ERC-20 Transfer logs#12306

Draft
0xRVE wants to merge 9 commits into
masterfrom
rve/61-support-indexing-assets-and-balances-transactions
Draft

[pallet-revive] index pallet-assets transfers as ERC-20 Transfer logs#12306
0xRVE wants to merge 9 commits into
masterfrom
rve/61-support-indexing-assets-and-balances-transactions

Conversation

@0xRVE

@0xRVE 0xRVE commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

eth-rpc: index pallet-assets transfers as ERC-20 logs

Closes paritytech/contract-issues#61.

What

eth-rpc now surfaces pallet-assets transfers (in addition to eth_transact). Each
assets::Transferred event becomes a canonical ERC-20 Transfer(address,address,uint256)
log at the asset's precompile address. (Foreign-asset transfers whose Location → index
mapping cannot be resolved are skipped — see below.)

Instances covered (defaults match Asset Hub Westend):

Instance Prefix
Assets (trust-backed) 0x0120
PoolAssets 0x0320
ForeignAssets 0x0220

Native balance is not indexed — it has no ERC-20 precompile, so there is no callable
token address to attribute transfers to.

How

  • Address (matches pallet-assets-precompiles): addr[0..4] = asset id (BE u32),
    addr[16..18] = instance prefix.
  • Log: topic0 = keccak256("Transfer(address,address,uint256)"); from/to mapped to
    H160 via the stateless AccountId32Mapper rule; data = amount as uint256.
  • Plain transfers (not eth_transact) get a synthesized transaction + receipt, so
    eth_getTransactionReceipt / eth_getLogs / eth_getBlock* all return coherent data.
    Synthetic tx hash = keccak256(substrate_block_hash ++ extrinsic_index_be32) — deterministic
    and reproducible (extraction runs at both index- and query-time). For foreign assets this
    reproducibility holds only while the Location → index mapping still exists (see below).
  • Transfers inside an eth_transact (contract → assets precompile) are merged into that
    transaction's receipt.
  • Foreign assets: the event carries an XCM Location, not the u32 index the address
    encodes, so the index is resolved from AssetsPrecompiles::ForeignAssetIdToAssetIndex via a
    cached raw storage read at the latest block. Reading at latest avoids pruned historical state;
    the trade-off is that a foreign asset destroyed after the transfer (its mapping is removed on
    destruction) can no longer be resolved, and such transfers are dropped at query time.

Events are decoded dynamically (by pallet/variant name) because eth-rpc's subxt metadata is
generated from the dev runtime, which has no pallet-assets.

Notes

  • Coverage starts at the indexer's first_evm_block; transfers in pre-EVM blocks are out of
    scope (the eth-rpc indexer is EVM-era by construction).
  • No DB/schema change — synthetic receipts use the existing insert path.
  • Asset extraction is independent of get_block_extrinsics, so a failed eth_receipt_data
    call cannot drop asset-only blocks.
  • A transient storage error while resolving a foreign index is not cached, so a one-off RPC
    failure cannot permanently drop an asset's transfers.

Testing

  • Unit tests: address scheme, ERC-20 topic/calldata encoding, event decode (u32 + foreign),
    Location→index storage-key layout, synthetic receipt/tx, and foreign-index cache not
    poisoned by a transient fetch error.
  • End-to-end on a local Westend Asset Hub fork: a real assets.transfer is returned as a
    correct ERC-20 Transfer log (address, topic0, from/to, amount) via eth_getLogs,
    eth_getTransactionReceipt, and eth_getTransactionByHash. The foreign Location→index
    storage key was validated against live forked state.

@0xRVE 0xRVE self-assigned this Jun 9, 2026
@0xRVE 0xRVE added T7-smart_contracts This PR/Issue is related to smart contracts. A5-run-CI Run CI on draft PR labels Jun 9, 2026
@0xRVE

0xRVE commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

/cmd prdoc --audience runtime_dev --bump minor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A5-run-CI Run CI on draft PR T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support indexing pallet-assets / balances transactions

1 participant