Skip to content

Commit

Permalink
Fix xcm configuration (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 authored Oct 24, 2024
1 parent 1e95060 commit 5ddc4ba
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
27 changes: 23 additions & 4 deletions modules/ismp/pallets/asset-gateway/src/xcm_utilities.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use crate::{AssetIds, Config, Pallet};
use alloc::vec::Vec;
use codec::Encode;
use core::marker::PhantomData;
use frame_support::traits::fungibles::{self, Mutate};
use frame_support::traits::{
fungibles::{self, Mutate},
Contains,
};
use ismp::host::StateMachine;
use sp_core::{Get, H160};
use sp_runtime::traits::MaybeEquivalence;
use staging_xcm::v4::{
Asset, Error as XcmError, Junction, Junctions, Location, NetworkId, Result as XcmResult,
XcmContext,
Asset, Error as XcmError, Fungibility::Fungible, Junction, Junctions, Location, NetworkId,
Result as XcmResult, XcmContext,
};
use staging_xcm_builder::{AssetChecking, FungiblesMutateAdapter};
use staging_xcm_executor::{
traits::{ConvertLocation, Error as MatchError, MatchesFungibles, TransactAsset},
AssetsInHolding,
};

pub struct WrappedNetworkId(pub NetworkId);

impl TryFrom<WrappedNetworkId> for StateMachine {
Expand Down Expand Up @@ -101,6 +104,22 @@ where
AssetIds::<T>::get(converted)
}
}

pub struct ReserveTransferFilter;

impl Contains<(Location, Vec<Asset>)> for ReserveTransferFilter {
fn contains(t: &(Location, Vec<Asset>)) -> bool {
let native = Location::parent();
t.1.iter().all(|asset| {
if let Asset { id: asset_id, fun: Fungible(_) } = asset {
asset_id.0 == native
} else {
false
}
})
}
}

pub struct HyperbridgeAssetTransactor<T, Matcher, AccountIdConverter, CheckAsset, CheckingAccount>(
PhantomData<(T, Matcher, AccountIdConverter, CheckAsset, CheckingAccount)>,
);
Expand Down
4 changes: 2 additions & 2 deletions modules/ismp/pallets/testsuite/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_system::EnsureRoot;
use pallet_assets::BenchmarkHelper;
use pallet_xcm::XcmPassthrough;
use pallet_xcm_gateway::{
xcm_utilities::{ConvertAssetId, HyperbridgeAssetTransactor},
xcm_utilities::{ConvertAssetId, HyperbridgeAssetTransactor, ReserveTransferFilter},
AssetGatewayParams,
};
use polkadot_parachain_primitives::primitives::{DmpMessageHandler, Sibling};
Expand Down Expand Up @@ -332,7 +332,7 @@ impl pallet_xcm::Config for Test {
type XcmExecuteFilter = Everything;
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
type XcmReserveTransferFilter = ReserveTransferFilter;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/gargantua/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("gargantua"),
impl_name: create_runtime_str!("gargantua"),
authoring_version: 1,
spec_version: 1160,
spec_version: 1170,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
8 changes: 5 additions & 3 deletions parachain/runtimes/gargantua/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use staging_xcm_builder::{
};
use staging_xcm_executor::XcmExecutor;

use pallet_xcm_gateway::xcm_utilities::{ConvertAssetId, HyperbridgeAssetTransactor};
use pallet_xcm_gateway::xcm_utilities::{
ConvertAssetId, HyperbridgeAssetTransactor, ReserveTransferFilter,
};

parameter_types! {
pub const RelayLocation: Location = Location::parent();
Expand Down Expand Up @@ -182,12 +184,12 @@ impl pallet_xcm::Config for Runtime {
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecuteFilter = Everything;
// ^ Disable dispatchable execute on the XCM pallet.
// Needs to be `Everything` for local testing.
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing;
type XcmReserveTransferFilter = ReserveTransferFilter;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
Expand Down
2 changes: 1 addition & 1 deletion parachain/runtimes/nexus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("nexus"),
impl_name: create_runtime_str!("nexus"),
authoring_version: 1,
spec_version: 1000,
spec_version: 1100,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
8 changes: 5 additions & 3 deletions parachain/runtimes/nexus/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use staging_xcm_builder::{
};
use staging_xcm_executor::XcmExecutor;

use pallet_xcm_gateway::xcm_utilities::{ConvertAssetId, HyperbridgeAssetTransactor};
use pallet_xcm_gateway::xcm_utilities::{
ConvertAssetId, HyperbridgeAssetTransactor, ReserveTransferFilter,
};

parameter_types! {
pub const RelayLocation: Location = Location::parent();
Expand Down Expand Up @@ -182,12 +184,12 @@ impl pallet_xcm::Config for Runtime {
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecuteFilter = Everything;
// ^ Disable dispatchable execute on the XCM pallet.
// Needs to be `Everything` for local testing.
type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Everything;
type XcmReserveTransferFilter = Nothing;
type XcmReserveTransferFilter = ReserveTransferFilter;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type UniversalLocation = UniversalLocation;
type RuntimeOrigin = RuntimeOrigin;
Expand Down

0 comments on commit 5ddc4ba

Please sign in to comment.