-
Notifications
You must be signed in to change notification settings - Fork 1.2k
implement IERC20Metadata for pallet-assets-precompiles
#10971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4991ceb
267527d
8c5695f
fa523a1
4e9c437
708b920
f536ea0
aff1d6f
49c2c07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| title: "Implement IERC20Metadata for pallet-assets precompiles" | ||
|
|
||
| doc: | ||
| - audience: Runtime Dev | ||
| description: | | ||
| Implements the missing ERC20 metadata functions (`name`, `symbol`, `decimals`) for the | ||
| pallet-assets precompile to provide full ERC20 compatibility. These functions are essential | ||
| for proper EVM wallet and tooling integration. | ||
|
|
||
| The precompile implementation reads metadata from pallet-assets storage and returns properly | ||
| formatted values with appropriate gas charging using dedicated weight functions. All functions | ||
| include proper error handling for missing metadata and invalid UTF-8 encoding. | ||
|
|
||
| Benchmarks have been added to measure the weight of metadata reads, and corresponding weight | ||
| functions have been implemented in the WeightInfo trait. | ||
|
|
||
| The IERC20.sol interface file has been reorganized to clearly separate and document methods | ||
| from the base IERC20 interface and the IERC20Metadata extension, with links to the original | ||
| OpenZeppelin contracts for better maintainability. | ||
|
|
||
| crates: | ||
| - name: ethereum-standards | ||
| bump: minor | ||
| - name: pallet-assets-precompiles | ||
| bump: minor | ||
| - name: pallet-assets | ||
| bump: minor |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -641,5 +641,50 @@ benchmarks_instance_pallet! { | |
| assert_eq!(Reserves::<T, I>::get(id)[0], reserve); | ||
| } | ||
|
|
||
| get_name { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
| let (asset_id, caller, _) = create_default_asset::<T, I>(true); | ||
| T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value()); | ||
| let name_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let symbol_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let origin = SystemOrigin::Signed(caller).into(); | ||
| Assets::<T, I>::set_metadata(origin, asset_id.clone(), name_bytes.clone(), symbol_bytes, 12)?; | ||
| }: { | ||
| let _ = Pallet::<T, I>::get_metadata(asset_id.clone().into()); | ||
| } verify { | ||
| let metadata = Pallet::<T, I>::get_metadata(asset_id.into()); | ||
| assert!(metadata.is_some()); | ||
| assert_eq!(metadata.unwrap().name.to_vec(), name_bytes); | ||
| } | ||
|
|
||
| get_symbol { | ||
| let (asset_id, caller, _) = create_default_asset::<T, I>(true); | ||
| T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value()); | ||
| let name_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let symbol_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let origin = SystemOrigin::Signed(caller).into(); | ||
| Assets::<T, I>::set_metadata(origin, asset_id.clone(), name_bytes, symbol_bytes.clone(), 12)?; | ||
| }: { | ||
| let _ = Pallet::<T, I>::get_metadata(asset_id.clone().into()); | ||
| } verify { | ||
| let metadata = Pallet::<T, I>::get_metadata(asset_id.into()); | ||
| assert!(metadata.is_some()); | ||
| assert_eq!(metadata.unwrap().symbol.to_vec(), symbol_bytes); | ||
| } | ||
|
|
||
| get_decimals { | ||
| let (asset_id, caller, _) = create_default_asset::<T, I>(true); | ||
| T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value()); | ||
| let name_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let symbol_bytes = vec![0u8; T::StringLimit::get() as usize]; | ||
| let origin = SystemOrigin::Signed(caller).into(); | ||
| Assets::<T, I>::set_metadata(origin, asset_id.clone(), name_bytes, symbol_bytes, 12)?; | ||
| }: { | ||
| let _ = Pallet::<T, I>::get_metadata(asset_id.clone().into()); | ||
| } verify { | ||
| let metadata = Pallet::<T, I>::get_metadata(asset_id.into()); | ||
| assert!(metadata.is_some()); | ||
| assert_eq!(metadata.unwrap().decimals, 12); | ||
| } | ||
|
|
||
| impl_benchmark_test_suite!(Assets, crate::mock::new_test_ext(), crate::mock::Test) | ||
| } | ||
There was a problem hiding this comment.
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