Skip to content
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

Only teleport native asset #855

Merged
merged 10 commits into from
Oct 29, 2024
19 changes: 17 additions & 2 deletions runtime/laos/src/configs/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{
types::ToAuthor, AccountId, AllPalletsWithSystem, Balances, ParachainInfo, PolkadotXcm,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Vec,
};
use core::marker::PhantomData;
use frame_support::{
Expand Down Expand Up @@ -219,6 +219,21 @@ pub type XcmRouter = xcm_builder::WithUniqueTopic<(
crate::XcmpQueue,
)>;

//Filter all teleports that aren't the native asset
pub struct OnlyTeleportNative;
impl Contains<(Location, Vec<Asset>)> for OnlyTeleportNative {
fn contains(t: &(Location, Vec<Asset>)) -> bool {
t.1.iter().all(|asset| {
log::trace!(target: "xcm::OnlyTeleportNative", "Asset to be teleported: {:?}", asset);
if let Asset { id: asset_id, fun: Fungible(_) } = asset {
asset_id.0 == HereLocation::get()
} else {
false
}
})
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// Determines which origins are allowed to send XCM messages.
Expand All @@ -228,7 +243,7 @@ impl pallet_xcm::Config for Runtime {
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmTeleportFilter = OnlyTeleportNative;
// Allows all reserve asset transfers.
type XcmReserveTransferFilter = Everything;
tsenovilla marked this conversation as resolved.
Show resolved Hide resolved
// Calculates the weight of XCM messages.
Expand Down
19 changes: 16 additions & 3 deletions xcm-simulator/src/laosish/configs/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,29 @@ impl xcm_executor::Config for XcmConfig {
pub type LocalOriginToLocation = SignedToAccountId20<RuntimeOrigin, AccountId, RelayNetwork>;
pub type XcmRouter = EnsureDecodableXcm<crate::ParachainXcmRouter<MsgQueue>>;

//Filter all teleports that aren't the native asset
pub struct OnlyTeleportNative;
impl Contains<(Location, Vec<Asset>)> for OnlyTeleportNative {
fn contains(t: &(Location, Vec<Asset>)) -> bool {
t.1.iter().all(|asset| {
log::trace!(target: "xcm::OnlyTeleportNative", "Asset to be teleported: {:?}", asset);
if let Asset { id: asset_id, fun: Fungible(_) } = asset {
asset_id.0 == HereLocation::get()
} else {
false
}
})
}
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecutor = XcmExecutor<XcmConfig>;
// it is safe to have `Everything` as `IsTeleporter` performs an additional check on the
// parachain
type XcmTeleportFilter = Everything;
type XcmTeleportFilter = OnlyTeleportNative;
type XcmReserveTransferFilter = Everything;
tsenovilla marked this conversation as resolved.
Show resolved Hide resolved
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
Expand Down
Loading