[pallet-revive] index pallet-assets transfers as ERC-20 Transfer logs#12306
Draft
0xRVE wants to merge 9 commits into
Draft
[pallet-revive] index pallet-assets transfers as ERC-20 Transfer logs#123060xRVE wants to merge 9 commits into
0xRVE wants to merge 9 commits into
Conversation
Contributor
Author
|
/cmd prdoc --audience runtime_dev --bump minor |
…time_dev --bump minor'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
eth-rpc: index pallet-assets transfers as ERC-20 logs
Closes paritytech/contract-issues#61.
What
eth-rpc now surfaces
pallet-assetstransfers (in addition toeth_transact). Eachassets::Transferredevent becomes a canonical ERC-20Transfer(address,address,uint256)log at the asset's precompile address. (Foreign-asset transfers whose
Location → indexmapping cannot be resolved are skipped — see below.)
Instances covered (defaults match Asset Hub Westend):
Assets(trust-backed)0x0120PoolAssets0x0320ForeignAssets0x0220Native balance is not indexed — it has no ERC-20 precompile, so there is no callable
token address to attribute transfers to.
How
pallet-assets-precompiles):addr[0..4]= asset id (BEu32),addr[16..18]= instance prefix.topic0 = keccak256("Transfer(address,address,uint256)");from/tomapped toH160via the statelessAccountId32Mapperrule;data= amount asuint256.eth_transact) get a synthesized transaction + receipt, soeth_getTransactionReceipt/eth_getLogs/eth_getBlock*all return coherent data.Synthetic tx hash =
keccak256(substrate_block_hash ++ extrinsic_index_be32)— deterministicand reproducible (extraction runs at both index- and query-time). For foreign assets this
reproducibility holds only while the
Location → indexmapping still exists (see below).eth_transact(contract → assets precompile) are merged into thattransaction's receipt.
Location, not theu32index the addressencodes, so the index is resolved from
AssetsPrecompiles::ForeignAssetIdToAssetIndexvia acached 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
first_evm_block; transfers in pre-EVM blocks are out ofscope (the eth-rpc indexer is EVM-era by construction).
get_block_extrinsics, so a failedeth_receipt_datacall cannot drop asset-only blocks.
failure cannot permanently drop an asset's transfers.
Testing
Location→indexstorage-key layout, synthetic receipt/tx, and foreign-index cache notpoisoned by a transient fetch error.
assets.transferis returned as acorrect ERC-20
Transferlog (address,topic0,from/to, amount) viaeth_getLogs,eth_getTransactionReceipt, andeth_getTransactionByHash. The foreignLocation→indexstorage key was validated against live forked state.