-
Notifications
You must be signed in to change notification settings - Fork 10
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
foreign asset creator pallet #15
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4c98e03
foreign asset creator pallet
girazoki 16a621d
add maybe equivalence
girazoki bf1c7e7
lock
girazoki 13a6a0e
Merge remote-tracking branch 'origin/main' into girazoki-simplified-f…
girazoki 0963735
Add benchmarks
girazoki 02a1cb2
benchmarks
girazoki c80451b
at least 16 bit unsigned
girazoki ea84a15
update
girazoki 46ca74d
add benchmarks
girazoki da746f1
add weights·
girazoki 9516693
fix tests
girazoki 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 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 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,49 @@ | ||
[package] | ||
name = "pallet-foreign-asset-creator" | ||
authors = { workspace = true } | ||
edition = "2021" | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
log = { workspace = true } | ||
serde = { workspace = true, optional = true } | ||
|
||
# Substrate | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
parity-scale-codec = { workspace = true, features = [ "derive" ] } | ||
scale-info = { workspace = true, features = [ "derive" ] } | ||
sp-arithmetic = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
# Polkadot | ||
staging-xcm = { workspace = true, optional = true } | ||
|
||
# Benchmarks | ||
frame-benchmarking = { workspace = true, optional = true } | ||
|
||
[dev-dependencies] | ||
pallet-balances = { workspace = true, features = [ "std" ] } | ||
pallet-assets = { workspace = true, features = [ "std" ] } | ||
sp-core = { workspace = true, features = [ "std" ] } | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"serde", | ||
"sp-arithmetic/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"staging-xcm/std" | ||
] | ||
|
||
runtime-benchmarks = [ "frame-benchmarking", "staging-xcm"] | ||
try-runtime = [ "frame-support/try-runtime" ] | ||
This file contains 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,141 @@ | ||
// Copyright Moonsong Labs | ||
// This file is part of Moonkit. | ||
|
||
// Moonkit is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonkit is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonkit. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use crate::{AssetId, Call, Config, Pallet}; | ||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite}; | ||
use frame_system::RawOrigin; | ||
use sp_arithmetic::traits::AtLeast16BitUnsigned; | ||
use staging_xcm::latest::prelude::*; | ||
benchmarks! { | ||
// This where clause allows us to create ForeignAssetTypes | ||
where_clause { where T::ForeignAsset: From<MultiLocation>, AssetId<T>: AtLeast16BitUnsigned } | ||
create_foreign_asset { | ||
const USER_SEED: u32 = 1; | ||
let manager = account("manager", 0, USER_SEED); | ||
let foreign_asset = T::ForeignAsset::default(); | ||
let amount = 1u32.into(); | ||
let asset_id: AssetId<T> = 1u16.into(); | ||
|
||
}: _(RawOrigin::Root, foreign_asset.clone(), asset_id.clone(), manager, true, amount) | ||
verify { | ||
assert_eq!(Pallet::<T>::foreign_asset_for_id(asset_id), Some(foreign_asset)); | ||
} | ||
|
||
change_existing_asset_type { | ||
// We make it dependent on the number of existing assets already | ||
let x in 5..100; | ||
const USER_SEED: u32 = 1; | ||
let manager: T::AccountId = account("manager", 0, USER_SEED); | ||
|
||
for i in 0..x { | ||
let foreign_asset: T::ForeignAsset = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
let asset_id: AssetId<T> = (i as u16).into(); | ||
let amount = 1u32.into(); | ||
Pallet::<T>::create_foreign_asset( | ||
RawOrigin::Root.into(), | ||
foreign_asset.clone(), | ||
asset_id.clone(), | ||
manager.clone(), | ||
true, | ||
amount, | ||
)?; | ||
} | ||
|
||
let new_foreign_asset = T::ForeignAsset::default(); | ||
let asset_type_to_be_changed: T::ForeignAsset = MultiLocation::new( | ||
0, | ||
X1(GeneralIndex((x-1) as u128)) | ||
).into(); | ||
let asset_id_to_be_changed: AssetId<T> = ((x-1) as u16).into(); | ||
}: _(RawOrigin::Root, asset_id_to_be_changed.clone(), new_foreign_asset.clone()) | ||
verify { | ||
assert_eq!(Pallet::<T>::foreign_asset_for_id(asset_id_to_be_changed), Some(new_foreign_asset.clone())); | ||
} | ||
|
||
remove_existing_asset_type { | ||
// We make it dependent on the number of existing assets already | ||
let x in 5..100; | ||
const USER_SEED: u32 = 1; | ||
let manager: T::AccountId = account("manager", 0, USER_SEED); | ||
|
||
for i in 0..x { | ||
let foreign_asset: T::ForeignAsset = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
let asset_id: AssetId<T> = (i as u16).into(); | ||
let amount = 1u32.into(); | ||
Pallet::<T>::create_foreign_asset( | ||
RawOrigin::Root.into(), | ||
foreign_asset.clone(), | ||
asset_id.clone(), | ||
manager.clone(), | ||
true, | ||
amount, | ||
)?; | ||
} | ||
|
||
let asset_id_to_be_removed: AssetId<T> = ((x-1) as u16).into(); | ||
}: _(RawOrigin::Root, asset_id_to_be_removed.clone()) | ||
verify { | ||
assert!(Pallet::<T>::foreign_asset_for_id(asset_id_to_be_removed).is_none()); | ||
} | ||
|
||
destroy_foreign_asset { | ||
// We make it dependent on the number of existing assets already | ||
let x in 5..100; | ||
const USER_SEED: u32 = 1; | ||
let manager: T::AccountId = account("manager", 0, USER_SEED); | ||
|
||
for i in 0..x { | ||
let foreign_asset: T::ForeignAsset = MultiLocation::new(0, X1(GeneralIndex(i as u128))).into(); | ||
let asset_id: AssetId<T> = (i as u16).into(); | ||
let amount = 1u32.into(); | ||
Pallet::<T>::create_foreign_asset( | ||
RawOrigin::Root.into(), | ||
foreign_asset.clone(), | ||
asset_id.clone(), | ||
manager.clone(), | ||
true, | ||
amount, | ||
)?; | ||
} | ||
|
||
let asset_id_to_be_destroyed: AssetId<T> = ((x-1) as u16).into(); | ||
}: _(RawOrigin::Root, asset_id_to_be_destroyed.clone()) | ||
verify { | ||
assert!(Pallet::<T>::foreign_asset_for_id(asset_id_to_be_destroyed).is_none()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::mock::Test; | ||
use sp_io::TestExternalities; | ||
use sp_runtime::BuildStorage; | ||
|
||
pub fn new_test_ext() -> TestExternalities { | ||
let t = frame_system::GenesisConfig::<Test>::default() | ||
.build_storage() | ||
.unwrap(); | ||
TestExternalities::new(t) | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
Pallet, | ||
crate::benchmarks::tests::new_test_ext(), | ||
crate::mock::Test | ||
); |
Oops, something went wrong.
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.
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.
Now try-runtime is a separate binary, so we don't need this rust feature anymore