Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[Feature] Limit collectives teleports to DOT #1579

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions pallets/xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "0.1.0"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
serde = { version = "1.0.144", optional = true, features = ["derive"] }
log = "0.4.17"

sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand All @@ -16,6 +17,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", default-featu
frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }

xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" }

cumulus-primitives-core = { path = "../../primitives/core", default-features = false }

Expand Down
18 changes: 15 additions & 3 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ use codec::{Decode, DecodeLimit, Encode};
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId,
};
use frame_support::dispatch::Weight;
use frame_support::{dispatch::Weight, traits::Get};
pub use pallet::*;
use scale_info::TypeInfo;
use sp_runtime::{traits::BadOrigin, RuntimeDebug};
use sp_std::{convert::TryFrom, prelude::*};
use sp_std::{convert::TryFrom, marker::PhantomData, prelude::*};
use xcm::{
latest::{ExecuteXcm, Outcome, Parent, Xcm},
latest::{AssetId::Concrete, ExecuteXcm, MultiAsset, MultiLocation, Outcome, Parent, Xcm},
VersionedXcm, MAX_XCM_DECODE_DEPTH,
};
use xcm_executor::traits::FilterAssetLocation;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -190,3 +191,14 @@ where
_ => Err(BadOrigin),
}
}

/// Accepts an asset if it is a native asset of a particular type.
pub struct ConcreteNativeAsset<AssetId>(PhantomData<AssetId>);
ruseinov marked this conversation as resolved.
Show resolved Hide resolved
impl<AssetId: Get<MultiLocation>> FilterAssetLocation for ConcreteNativeAsset<AssetId> {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::filter_asset_location",
"ConcreteNativeAsset asset: {:?}, origin: {:?}, id: {:?}",
asset, origin, AssetId::get());
matches!(asset.id, Concrete(ref id) if id == origin && origin == &AssetId::get())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,
FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
FixedWeightBounds, IsConcrete, LocationInverter, ParentAsSuperuser, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
UsingComponents,
};
Expand Down Expand Up @@ -140,7 +140,7 @@ impl xcm_executor::Config for XcmConfig {
// Collectives does not recognize a reserve location for any asset. Users must teleport DOT
// where allowed (e.g. with the Relay Chain).
type IsReserve = ();
type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of DOT
type IsTeleporter = cumulus_pallet_xcm::ConcreteNativeAsset<DotLocation>; // <- should be enough to allow teleportation of DOT
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
Expand Down