This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
378 additions
and
128 deletions.
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
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
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
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
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,35 @@ | ||
[package] | ||
name = "pallet-benchmarks" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive", ] } | ||
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } | ||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } | ||
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.37" } | ||
frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" } | ||
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" } | ||
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" } | ||
|
||
xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } | ||
xcm-executor = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.37" } | ||
|
||
[dev-dependencies] | ||
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"frame-benchmarking/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
"xcm-executor/std" | ||
] | ||
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] |
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,33 @@ | ||
use frame_benchmarking::benchmarks; | ||
use sp_runtime::SaturatedConversion; | ||
use xcm::prelude::AssetId as XcmAssetId; | ||
|
||
use crate::*; | ||
|
||
benchmarks! { | ||
drop_assets_fungible { | ||
let origin = MultiLocation::default(); | ||
let asset_id = 1; | ||
let location = Parachain(asset_id).into(); | ||
T::register_asset(asset_id.into(), location.clone()); | ||
let asset = MultiAsset { id: XcmAssetId::Concrete(location), fun: Fungibility::Fungible(100) }; | ||
} : { | ||
T::DropAssets::drop_assets(&origin, asset.into()); | ||
} | ||
|
||
drop_assets_native { | ||
let origin = MultiLocation::default(); | ||
let location = MultiLocation { parents: 0, interior: Here }; | ||
let amount = T::ExistentialDeposit::get().saturated_into(); | ||
let asset = MultiAsset { id: XcmAssetId::Concrete(location), fun: Fungibility::Fungible(amount) }; | ||
} : { | ||
T::DropAssets::drop_assets(&origin, asset.into()); | ||
} | ||
|
||
drop_assets_default { | ||
let origin = MultiLocation::default(); | ||
let asset = MultiAsset { id: XcmAssetId::Abstract(Default::default()), fun: Fungibility::Fungible(0) }; | ||
} : { | ||
T::DropAssets::drop_assets(&origin, asset.into()); | ||
} | ||
} |
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,43 @@ | ||
//! Pallet for benchmarking. | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use codec::Codec; | ||
use frame_support::{pallet_prelude::*, traits::tokens::AssetId}; | ||
use sp_runtime::traits::AtLeast32BitUnsigned; | ||
use xcm::prelude::*; | ||
use xcm_executor::traits::DropAssets; | ||
|
||
pub use pallet::*; | ||
pub use weights::*; | ||
|
||
#[cfg(feature = "runtime-benchmarks")] | ||
pub mod benchmarking; | ||
pub mod weights; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use super::*; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
/// Identifier for the class of asset. | ||
type AssetId: AssetId + From<u32>; | ||
|
||
/// The balance of an account. | ||
type Balance: Parameter + Member + AtLeast32BitUnsigned + Codec + TypeInfo; | ||
|
||
/// The minimum amount required to keep an account open. | ||
#[pallet::constant] | ||
type ExistentialDeposit: Get<Self::Balance>; | ||
|
||
/// Handler for when some non-empty `Assets` value should be dropped. | ||
type DropAssets: DropAssets; | ||
|
||
/// Handler to register an asset. | ||
fn register_asset(asset_id: Self::AssetId, location: MultiLocation); | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
} |
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,7 @@ | ||
use frame_support::weights::Weight; | ||
|
||
pub trait WeightInfo { | ||
fn drop_assets_fungible() -> Weight; | ||
fn drop_assets_native() -> Weight; | ||
fn drop_assets_default() -> Weight; | ||
} |
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
Oops, something went wrong.