Skip to content

Commit

Permalink
XcmExecutorUtils pallet to container chains templates (#427)
Browse files Browse the repository at this point in the history
* XcmExecutorUtils in container chains

* fmt

* TS tests & AllNative default policy

* fmt

* Cleanup

* Update dancekit rev

* Update lock

* Common container chains tests

* Updated dancekit rev
  • Loading branch information
fgamundi authored Feb 27, 2024
1 parent 4b33601 commit c33e54b
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 128 deletions.
36 changes: 28 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dp-chain-state-snapshot = { git = "https://github.com/moondance-labs/dancekit",
dp-collator-assignment = { git = "https://github.com/moondance-labs/dancekit", branch = "tanssi-polkadot-v1.6.0", default-features = false }
dp-core = { git = "https://github.com/moondance-labs/dancekit", branch = "tanssi-polkadot-v1.6.0", default-features = false }
pallet-cc-authorities-noting = { git = "https://github.com/moondance-labs/dancekit", branch = "tanssi-polkadot-v1.6.0", default-features = false }
pallet-xcm-executor-utils = { git = "https://github.com/moondance-labs/dancekit", branch = "tanssi-polkadot-v1.6.0", default-features = false }
test-relay-sproof-builder = { git = "https://github.com/moondance-labs/dancekit", branch = "tanssi-polkadot-v1.6.0", default-features = false }

# Dancekit (client)
Expand Down
6 changes: 6 additions & 0 deletions container-chains/templates/frontier/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pallet-maintenance-mode = { workspace = true, features = [ "xcm-support" ] }
pallet-migrations = { workspace = true }
xcm-primitives = { workspace = true }

# Dancekit
pallet-xcm-executor-utils = { workspace = true }

# Substrate
frame-executive = { workspace = true }
frame-support = { workspace = true }
Expand Down Expand Up @@ -178,6 +181,7 @@ std = [
"pallet-tx-pause/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm-executor-utils/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down Expand Up @@ -247,6 +251,7 @@ runtime-benchmarks = [
"pallet-tx-pause/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm-executor-utils/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down Expand Up @@ -293,6 +298,7 @@ try-runtime = [
"pallet-transaction-payment/try-runtime",
"pallet-tx-pause/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm-executor-utils/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions container-chains/templates/frontier/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ construct_runtime!(
ForeignAssets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 75,
ForeignAssetsCreator: pallet_foreign_asset_creator::{Pallet, Call, Storage, Event<T>} = 76,
AssetRate: pallet_asset_rate::{Pallet, Call, Storage, Event<T>} = 77,
XcmExecutorUtils: pallet_xcm_executor_utils::{Pallet, Call, Storage, Event<T>} = 78,

RootTesting: pallet_root_testing = 100,
AsyncBacking: pallet_async_backing::{Pallet, Storage} = 110,
Expand Down
80 changes: 20 additions & 60 deletions container-chains/templates/frontier/runtime/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ use {
frame_system::EnsureRoot,
pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion,
pallet_xcm::XcmPassthrough,
pallet_xcm_executor_utils::{
filters::{IsReserveFilter, IsTeleportFilter},
DefaultTrustPolicy,
},
parachains_common::{
message_queue::{NarrowOriginToSibling, ParaIdToSibling},
xcm_config::AssetFeeAsExistentialDepositMultiplier,
Expand Down Expand Up @@ -177,8 +181,8 @@ impl staging_xcm_executor::Config for XcmConfig {
type XcmSender = XcmRouter;
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAssetReserve;
type IsTeleporter = ();
type IsReserve = IsReserveFilter<Runtime>;
type IsTeleporter = IsTeleportFilter<Runtime>;
type UniversalLocation = UniversalLocation;
type Barrier = XcmBarrier;
type Weigher = XcmWeigher;
Expand Down Expand Up @@ -394,6 +398,20 @@ impl pallet_asset_rate::Config for Runtime {
type BenchmarkHelper = ForeignAssetBenchmarkHelper;
}

parameter_types! {
pub const TrustPolicyMaxAssets: u32 = 1000;
pub const AllNativeTrustPolicy: DefaultTrustPolicy = DefaultTrustPolicy::AllNative;
}
impl pallet_xcm_executor_utils::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type TrustPolicyMaxAssets = TrustPolicyMaxAssets;
type ReserveDefaultTrustPolicy = AllNativeTrustPolicy;
type SetReserveTrustOrigin = EnsureRoot<AccountId>;
type TeleportDefaultTrustPolicy = AllNativeTrustPolicy;
type SetTeleportTrustOrigin = EnsureRoot<AccountId>;
type WeightInfo = pallet_xcm_executor_utils::weights::SubstrateWeight<Runtime>;
}

use {
crate::ForeignAssets,
staging_xcm_builder::{FungiblesAdapter, NoChecking},
Expand All @@ -419,61 +437,3 @@ pub type ForeignFungiblesTransactor = FungiblesAdapter<
/// Multiplier used for dedicated `TakeFirstAssetTrader` with `ForeignAssets` instance.
pub type AssetRateAsMultiplier =
AssetFeeAsExistentialDepositMultiplier<Runtime, WeightToFee, AssetRate, ForeignAssetsInstance>;
// TODO: this should probably move to somewhere in the polkadot-sdk repo
pub struct NativeAssetReserve;
impl frame_support::traits::ContainsPair<MultiAsset, MultiLocation> for NativeAssetReserve {
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::contains", "NativeAssetReserve asset: {:?}, origin: {:?}", asset, origin);
let reserve = if let Concrete(location) = &asset.id {
if location.parents == 0 && !matches!(location.first_interior(), Some(Parachain(_))) {
Some(MultiLocation::here())
} else {
location.chain_part()
}
} else {
None
};

if let Some(ref reserve) = reserve {
if reserve == origin {
return true;
}
}
false
}
}

pub trait Parse {
/// Returns the "chain" location part. It could be parent, sibling
/// parachain, or child parachain.
fn chain_part(&self) -> Option<MultiLocation>;
/// Returns "non-chain" location part.
fn non_chain_part(&self) -> Option<MultiLocation>;
}

impl Parse for MultiLocation {
fn chain_part(&self) -> Option<MultiLocation> {
match (self.parents, self.first_interior()) {
// sibling parachain
(1, Some(Parachain(id))) => Some(MultiLocation::new(1, X1(Parachain(*id)))),
// parent
(1, _) => Some(MultiLocation::parent()),
// children parachain
(0, Some(Parachain(id))) => Some(MultiLocation::new(0, X1(Parachain(*id)))),
_ => None,
}
}

fn non_chain_part(&self) -> Option<MultiLocation> {
let mut junctions = *self.interior();
while matches!(junctions.first(), Some(Parachain(_))) {
let _ = junctions.take_first();
}

if junctions != Here {
Some(MultiLocation::new(0, junctions))
} else {
None
}
}
}
6 changes: 6 additions & 0 deletions container-chains/templates/simple/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pallet-maintenance-mode = { workspace = true, features = [ "xcm-support" ] }
pallet-migrations = { workspace = true }
xcm-primitives = { workspace = true }

# Dancekit
pallet-xcm-executor-utils = { workspace = true }

# Substrate
frame-executive = { workspace = true }
frame-support = { workspace = true }
Expand Down Expand Up @@ -137,6 +140,7 @@ std = [
"pallet-tx-pause/std",
"pallet-utility/std",
"pallet-xcm-benchmarks?/std",
"pallet-xcm-executor-utils/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down Expand Up @@ -201,6 +205,7 @@ runtime-benchmarks = [
"pallet-tx-pause/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm-benchmarks/runtime-benchmarks",
"pallet-xcm-executor-utils/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down Expand Up @@ -243,6 +248,7 @@ try-runtime = [
"pallet-transaction-payment/try-runtime",
"pallet-tx-pause/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm-executor-utils/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions container-chains/templates/simple/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ construct_runtime!(
ForeignAssets: pallet_assets::<Instance1>::{Pallet, Call, Storage, Event<T>} = 75,
ForeignAssetsCreator: pallet_foreign_asset_creator::{Pallet, Call, Storage, Event<T>} = 76,
AssetRate: pallet_asset_rate::{Pallet, Call, Storage, Event<T>} = 77,
XcmExecutorUtils: pallet_xcm_executor_utils::{Pallet, Call, Storage, Event<T>} = 78,

RootTesting: pallet_root_testing = 100,
AsyncBacking: pallet_async_backing::{Pallet, Storage} = 110,
Expand Down
Loading

0 comments on commit c33e54b

Please sign in to comment.