-
Notifications
You must be signed in to change notification settings - Fork 41
Asset-manager for foreign xcm related assets #1450
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d72367a
Integrate asset-manager with heiko runtime first
93e8e70
Add asset-manager
91d2929
Integation test with statemine and some fix accordingly
3353edf
Rename to xcm-gadget
b7f03e7
Fix for llint&fmt
171bc2c
Merge branch 'master' into asset-manager-para
837d450
Add more test
43cbb1e
Revamp local transact for foreign asset
9508db5
Add integration tests for cross-chain cases
6ce3888
Fix lint&Allow register exist asset&Remove weight hint check
7ae2fce
More test
c382134
Seperate xcm config&Refactor accordingly
6e09f6e
Integrate asset-manager with vanilla runtime
d28baae
Revamp transfer fee to non-reserve chain
7fd4876
Benchmark integration&fix
8a0dddd
Temporary remove from heiko&Use vanilla for integration test
aac1f86
Merge branch 'master' into asset-manager-para
6d25fe5
Integrate with kerria
c90314e
Merge branch 'master' into asset-manager-para
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| { | ||
| "relaychain": { | ||
| "bin": "../polkadot/target/release/polkadot", | ||
| "chain": "rococo-local", | ||
| "nodes": [ | ||
| { | ||
| "name": "alice", | ||
| "wsPort": 9944, | ||
| "rpcPort": 9933, | ||
| "port": 30333, | ||
| "basePath": "data/9944" | ||
| }, | ||
| { | ||
| "name": "bob", | ||
| "wsPort": 9945, | ||
| "rpcPort": 9934, | ||
| "port": 30334, | ||
| "basePath": "data/9945" | ||
| }, | ||
| { | ||
| "name": "charlie", | ||
| "wsPort": 9946, | ||
| "rpcPort": 9935, | ||
| "port": 30335, | ||
| "basePath": "data/9946" | ||
| }, | ||
| { | ||
| "name": "dave", | ||
| "wsPort": 9947, | ||
| "rpcPort": 9936, | ||
| "port": 30336, | ||
| "basePath": "data/9947" | ||
| } | ||
| ], | ||
| "genesis": { | ||
| "runtime": { | ||
| "runtime_genesis_config": { | ||
| "configuration": { | ||
| "config": { | ||
| "validation_upgrade_frequency": 1, | ||
| "validation_upgrade_delay": 10 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "parachains": [ | ||
| { | ||
| "bin": "../parallel/target/release/parallel", | ||
| "chain": "heiko-dev", | ||
| "nodes": [ | ||
| { | ||
| "wsPort": 9948, | ||
| "port": 30337, | ||
| "rpcPort": 9937, | ||
| "name": "alice", | ||
| "basePath": "data/9948", | ||
| "flags": [ | ||
| "--unsafe-ws-external", | ||
| "--unsafe-rpc-external", | ||
| "--rpc-external", | ||
| "--ws-external", | ||
| "--rpc-cors=all", | ||
| "--rpc-methods=Unsafe", | ||
| "--force-authoring", | ||
| "--", | ||
| "--execution=wasm", | ||
| "--state-cache-size", | ||
| "0" | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "bin": "../cumulus/target/release/polkadot-collator", | ||
| "chain": "statemine-local", | ||
| "nodes": [ | ||
| { | ||
| "wsPort": 9950, | ||
| "port": 30339, | ||
| "name": "alice", | ||
| "basePath": "data/9950", | ||
| "flags": [ | ||
| "--unsafe-ws-external", | ||
| "--unsafe-rpc-external", | ||
| "--rpc-external", | ||
| "--ws-external", | ||
| "--rpc-cors=all", | ||
| "--rpc-methods=Unsafe", | ||
| "--force-authoring", | ||
| "--", | ||
| "--execution=wasm" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "simpleParachains": [], | ||
| "hrmpChannels": [ | ||
| { | ||
| "sender": 1000, | ||
| "recipient": 2085, | ||
| "maxCapacity": 8, | ||
| "maxMessageSize": 512 | ||
| }, | ||
| { | ||
| "sender": 2085, | ||
| "recipient": 1000, | ||
| "maxCapacity": 8, | ||
| "maxMessageSize": 512 | ||
| } | ||
| ], | ||
| "types": {}, | ||
| "finalization": false | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| [package] | ||
| name = "pallet-asset-manager" | ||
| authors = [ "Parallel Team" ] | ||
| edition = "2021" | ||
| version = "0.1.0" | ||
|
|
||
| [dependencies] | ||
| log = { version = "0.4", default-features = false } | ||
| serde = { version = "1.0.124", optional = true } | ||
|
|
||
| # Primitives | ||
| parallel-primitives = { path = "../../primitives", default-features = false } | ||
|
|
||
| # Substrate | ||
| frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } | ||
|
This conversation was marked as resolved.
Outdated
|
||
| frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } | ||
| parity-scale-codec = { version = "2.0.0", default-features = false, features = [ "derive" ] } | ||
| scale-info = { version = "1.0", default-features = false, features = [ "derive" ] } | ||
| sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } | ||
| sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } | ||
| sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", default-features = false } | ||
|
|
||
| # Polkadot | ||
| xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.16", default-features = false } | ||
|
|
||
| # Benchmarks | ||
| frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16", optional = true, default-features = false } | ||
|
|
||
| [dev-dependencies] | ||
| pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } | ||
| sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.16" } | ||
|
|
||
| [features] | ||
| default = [ "std" ] | ||
| std = [ | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "parity-scale-codec/std", | ||
| "scale-info/std", | ||
| "serde", | ||
| "sp-io/std", | ||
| "sp-runtime/std", | ||
| "sp-std/std", | ||
| "xcm/std", | ||
| "parallel-primitives/std", | ||
| ] | ||
|
|
||
| runtime-benchmarks = [ | ||
| "frame-benchmarking", | ||
| ] | ||
| try-runtime = [ "frame-support/try-runtime" ] | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright 2021 Parallel Finance Developer. | ||
| // This file is part of Parallel Finance. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #![cfg(feature = "runtime-benchmarks")] | ||
| use crate::{Call, Config, Pallet}; | ||
| use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; | ||
| use frame_system::RawOrigin; | ||
| use xcm::latest::prelude::*; | ||
|
|
||
| benchmarks! { | ||
| // This where clause allows us to create assetTypes | ||
| where_clause { where T::AssetType: From<MultiLocation> } | ||
| register_asset { | ||
| // does not really matter what we register | ||
| let asset_type = T::AssetType::default(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| let asset_id: T::AssetId = asset_type.clone().into(); | ||
|
|
||
| }: _(RawOrigin::Root, asset_type.clone(), metadata, amount, true) | ||
| verify { | ||
| assert_eq!(Pallet::<T>::asset_id_type(asset_id), Some(asset_type)); | ||
| } | ||
|
|
||
| set_asset_units_per_second { | ||
| // We make it dependent on the number of existing assets already | ||
| let x in 5..100; | ||
| for i in 0..x { | ||
| let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?; | ||
| Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; | ||
| } | ||
|
|
||
| // does not really matter what we register, as long as it is different than the previous | ||
| let asset_type = T::AssetType::default(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| let asset_id: T::AssetId = asset_type.clone().into(); | ||
| Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?; | ||
|
|
||
| }: _(RawOrigin::Root, asset_type.clone(), 1, x) | ||
| verify { | ||
| assert!(Pallet::<T>::supported_fee_payment_assets().contains(&asset_type)); | ||
| assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type), Some(1)); | ||
| } | ||
|
|
||
| change_existing_asset_type { | ||
| // We make it dependent on the number of existing assets already | ||
| let x in 5..100; | ||
| for i in 0..x { | ||
| let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?; | ||
| Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; | ||
| } | ||
|
|
||
| let new_asset_type = T::AssetType::default(); | ||
| let asset_type_to_be_changed: T::AssetType = MultiLocation::new( | ||
| 0, | ||
| X1(GeneralIndex((x-1) as u128)) | ||
| ).into(); | ||
| let asset_id_to_be_changed = asset_type_to_be_changed.into(); | ||
|
|
||
| }: _(RawOrigin::Root, asset_id_to_be_changed, new_asset_type.clone(), x) | ||
| verify { | ||
| assert_eq!(Pallet::<T>::asset_id_type(asset_id_to_be_changed), Some(new_asset_type.clone())); | ||
| assert_eq!(Pallet::<T>::asset_type_units_per_second(&new_asset_type), Some(1)); | ||
| assert!(Pallet::<T>::supported_fee_payment_assets().contains(&new_asset_type)); | ||
| } | ||
|
|
||
| remove_supported_asset { | ||
| // We make it dependent on the number of existing assets already | ||
| let x in 5..100; | ||
| for i in 0..x { | ||
| let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?; | ||
| Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; | ||
| } | ||
| let asset_type_to_be_removed: T::AssetType = MultiLocation::new( | ||
| 0, | ||
| X1(GeneralIndex((x-1) as u128)) | ||
| ).into(); | ||
| // We try to remove the last asset type | ||
| }: _(RawOrigin::Root, asset_type_to_be_removed.clone(), x) | ||
| verify { | ||
| assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed)); | ||
| assert_eq!(Pallet::<T>::asset_type_units_per_second(asset_type_to_be_removed), None); | ||
| } | ||
|
|
||
| remove_existing_asset_type { | ||
| // We make it dependent on the number of existing assets already | ||
| // Worst case is we need to remove it from SupportedAAssetsFeePayment too | ||
| let x in 5..100; | ||
| for i in 0..x { | ||
| let asset_type: T::AssetType = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
| let metadata = T::AssetRegistrarMetadata::default(); | ||
| let amount = 1u32.into(); | ||
| Pallet::<T>::register_asset(RawOrigin::Root.into(), asset_type.clone(), metadata, amount, true)?; | ||
| Pallet::<T>::set_asset_units_per_second(RawOrigin::Root.into(), asset_type.clone(), 1, i)?; | ||
| } | ||
|
|
||
| let asset_type_to_be_removed: T::AssetType = MultiLocation::new( | ||
| 0, | ||
| X1(GeneralIndex((x-1) as u128)) | ||
| ).into(); | ||
| let asset_id: T::AssetId = asset_type_to_be_removed.clone().into(); | ||
| }: _(RawOrigin::Root, asset_id, x) | ||
| verify { | ||
| assert!(Pallet::<T>::asset_id_type(asset_id).is_none()); | ||
| assert!(Pallet::<T>::asset_type_units_per_second(&asset_type_to_be_removed).is_none()); | ||
| assert!(!Pallet::<T>::supported_fee_payment_assets().contains(&asset_type_to_be_removed)); | ||
|
|
||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::mock::Test; | ||
| use sp_io::TestExternalities; | ||
|
|
||
| pub fn new_test_ext() -> TestExternalities { | ||
| let t = frame_system::GenesisConfig::default() | ||
| .build_storage::<Test>() | ||
| .unwrap(); | ||
| TestExternalities::new(t) | ||
| } | ||
| } | ||
|
|
||
| impl_benchmark_test_suite!( | ||
| Pallet, | ||
| crate::benchmarks::tests::new_test_ext(), | ||
| crate::mock::Test | ||
| ); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.