Skip to content

implement IERC20Metadata for pallet-assets-precompiles#10971

Merged
0xRVE merged 9 commits intoparitytech:masterfrom
seunlanlege:seun/pallet-assets-ierc20-metadata
Feb 9, 2026
Merged

implement IERC20Metadata for pallet-assets-precompiles#10971
0xRVE merged 9 commits intoparitytech:masterfrom
seunlanlege:seun/pallet-assets-ierc20-metadata

Conversation

@seunlanlege
Copy link
Copy Markdown
Contributor

Summary

Implements the missing ERC20 metadata functions (name, symbol, decimals) for the pallet-assets precompile to provide full ERC20 compatibility. These functions were missing from the original implementation and are essential for proper EVM wallet and tooling integration.

Changes

Solidity Interface

  • substrate/primitives/ethereum-standards/src/IERC20.sol
    • Added name() external view returns (string memory)
    • Added symbol() external view returns (string memory)
    • Added decimals() external view returns (uint8)

Precompile Implementation

  • substrate/frame/assets/precompiles/src/lib.rs
    • Implemented name() - reads metadata from pallet-assets storage and returns UTF-8 string
    • Implemented symbol() - reads metadata from pallet-assets storage and returns UTF-8 string
    • Implemented decimals() - reads metadata from pallet-assets storage and returns uint8 value
    • All functions charge appropriate gas using dedicated weight functions
    • Proper error handling for missing metadata and invalid UTF-8 encoding

Benchmarks

  • substrate/frame/assets/src/benchmarking.rs
    • Added get_name benchmark - measures metadata read for name field
    • Added get_symbol benchmark - measures metadata read for symbol field
    • Added get_decimals benchmark - measures metadata read for decimals field

Weight Functions

  • substrate/frame/assets/src/weights.rs
    • Added get_name() -> Weight to WeightInfo trait
    • Added get_symbol() -> Weight to WeightInfo trait
    • Added get_decimals() -> Weight to WeightInfo trait
    • Implemented for both SubstrateWeight<T> and () (fallback)
    • Each function: 1 storage read from Assets::Metadata (~12-12.5ms, 2615 bytes proof size)

Closes #8658

Comment thread prdoc/pr_10971.prdoc
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to be renamed to 10971.prdoc

@seunlanlege seunlanlege force-pushed the seun/pallet-assets-ierc20-metadata branch from 40722eb to f536ea0 Compare February 4, 2026 14:10
@seunlanlege
Copy link
Copy Markdown
Contributor Author

seunlanlege commented Feb 4, 2026

cc @0xRVE @xermicus

@pgherveou pgherveou requested a review from xermicus February 4, 2026 15:32
@pgherveou pgherveou added the T7-smart_contracts This PR/Issue is related to smart contracts. label Feb 4, 2026
@pgherveou
Copy link
Copy Markdown
Contributor

@seunlanlege
Copy link
Copy Markdown
Contributor Author

https://github.com/paritytech/polkadot-sdk/actions/runs/21674695442/job/62491853047?pr=10971 let's copy the weight over there too

Weights are already on this branch no?

@pgherveou
Copy link
Copy Markdown
Contributor

https://github.com/paritytech/polkadot-sdk/actions/runs/21674695442/job/62491853047?pr=10971 let's copy the weight over there too

Weights are already on this branch no?

CI complains with this

error[E0046]: not all trait items implemented, missing: `migration_v2_foreign_asset_set_reserve_weight`, `get_name`, `get_symbol`, `get_decimals`
  --> cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/pallet_assets_foreign.rs:53:1
   |
53 | impl<T: frame_system::Config> pallet_assets::WeightInfo for WeightInfo<T> {
   | ^^^^^^^^^^^^^^^^

@0xRVE 0xRVE added this pull request to the merge queue Feb 9, 2026
@0xRVE 0xRVE removed this pull request from the merge queue due to a manual request Feb 9, 2026
assert_eq!(Reserves::<T, I>::get(id)[0], reserve);
}

get_name {
Copy link
Copy Markdown
Contributor

@pgherveou pgherveou Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are identical we should probably only have one and just call it for both methods in the precompile
@0xRVE can you do that in a follow up, so we can merge this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@0xRVE 0xRVE added this pull request to the merge queue Feb 9, 2026
Merged via the queue into paritytech:master with commit ba0839d Feb 9, 2026
251 of 255 checks passed
github-merge-queue Bot pushed a commit that referenced this pull request Feb 13, 2026
…a benchmark (#11037)

## Summary

Consolidates the three identical `get_name`, `get_symbol`, and
`get_decimals` benchmarks into a single `get_metadata` benchmark. This
addresses the follow-up from #10971 where it was noted that these
benchmarks perform the same operation (`Pallet::get_metadata()`).

## Changes

### Benchmarks
- **`substrate/frame/assets/src/benchmarking.rs`**
- Replaced `get_name`, `get_symbol`, `get_decimals` with single
`get_metadata` benchmark
- Updated verification to check all three metadata fields (name, symbol,
decimals)

### Weight Functions
- **`substrate/frame/assets/src/weights.rs`**
- Replaced `get_name()`, `get_symbol()`, `get_decimals()` with single
`get_metadata()` in `WeightInfo` trait
  - Updated implementations for `SubstrateWeight<T>` and `()`

### Precompile
- **`substrate/frame/assets/precompiles/src/lib.rs`**
- Updated `name()`, `symbol()`, and `decimals()` methods to all charge
`get_metadata()` weight

### Cumulus Runtimes
Updated weight implementations in:
- `asset-hub-rococo`: `pallet_assets_foreign.rs`,
`pallet_assets_local.rs`, `pallet_assets_pool.rs`
- `asset-hub-westend`: `pallet_assets_foreign.rs`,
`pallet_assets_local.rs`, `pallet_assets_pool.rs`

## Rationale

All three original benchmarks were measuring the exact same operation -
a single metadata storage read. Consolidating them:
1. Reduces code duplication
2. Simplifies the `WeightInfo` trait
3. Accurately reflects that `name()`, `symbol()`, and `decimals()` have
identical costs

Closes follow-up from
#10971 (comment)

---------

Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Implement IERC20Metadata for pallet-assets precompile

4 participants