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 3 commits
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
14 changes: 13 additions & 1 deletion parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use frame_support::{
traits::{fungibles::Inspect, tokens::BalanceConversion},
weights::{Weight, WeightToFee, WeightToFeePolynomial},
};
use sp_runtime::traits::Get;
use xcm::latest::prelude::*;
use xcm_executor::traits::ShouldExecute;
use xcm_executor::traits::{FilterAssetLocation, ShouldExecute};

//TODO: move DenyThenTry to polkadot's xcm module.
/// Deny executing the XCM if it matches any of the Deny filter regardless of anything else.
Expand Down Expand Up @@ -107,3 +108,14 @@ where
Ok(asset_amount)
}
}

/// Accepts an asset if it is a native asset from a particular `MultiLocation`.
pub struct ConcreteNativeAssetFrom<Location>(PhantomData<Location>);
impl<Location: Get<MultiLocation>> FilterAssetLocation for ConcreteNativeAssetFrom<Location> {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
log::trace!(target: "xcm::filter_asset_location",
"ConcreteNativeAsset asset: {:?}, origin: {:?}, location: {:?}",
asset, origin, Location::get());
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use frame_support::{
use pallet_xcm::XcmPassthrough;
use parachains_common::{
impls::ToStakingPot,
xcm_config::{DenyReserveTransferToRelayChain, DenyThenTry},
xcm_config::{ConcreteNativeAssetFrom, DenyReserveTransferToRelayChain, DenyThenTry},
};
use polkadot_parachain::primitives::Sibling;
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 = ConcreteNativeAssetFrom<DotLocation>; // <- should be enough to allow teleportation of DOT
chevdor marked this conversation as resolved.
Show resolved Hide resolved
ruseinov marked this conversation as resolved.
Show resolved Hide resolved
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
Expand Down