From 55235dfdffe8645b4f833162303601d151f3fd26 Mon Sep 17 00:00:00 2001 From: Antonio Date: Sat, 28 Sep 2024 17:21:43 +0200 Subject: [PATCH] fix: spiritnet config for the switch pallet (#742) --- runtimes/spiritnet/src/xcm_config.rs | 60 +++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/runtimes/spiritnet/src/xcm_config.rs b/runtimes/spiritnet/src/xcm_config.rs index b5de4ce14..20da61355 100644 --- a/runtimes/spiritnet/src/xcm_config.rs +++ b/runtimes/spiritnet/src/xcm_config.rs @@ -17,8 +17,9 @@ // If you feel like getting in touch with us, you can do so at info@botlabs.org use crate::{ - AccountId, AllPalletsWithSystem, Balances, MessageQueue, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, - RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Balances, CheckingAccount, Fungibles, KiltToEKiltSwitchPallet, MessageQueue, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, + WeightToFee, XcmpQueue, }; use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; @@ -27,6 +28,10 @@ use frame_support::{ traits::{Contains, EnqueueWithOrigin, Everything, Nothing, TransformOrigin}, }; use frame_system::EnsureRoot; +use pallet_asset_switch::xcm::{ + IsSwitchPairRemoteAsset, IsSwitchPairXcmFeeAsset, MatchesSwitchPairXcmFeeFungibleAsset, + SwitchPairRemoteAssetTransactor, UsingComponentsForSwitchPairRemoteAsset, UsingComponentsForXcmFeeAsset, +}; use pallet_xcm::XcmPassthrough; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; @@ -35,9 +40,9 @@ use sp_std::prelude::ToOwned; use xcm::v4::prelude::*; use xcm_builder::{ AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, - EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, NativeAsset, RelayChainAsNative, - SiblingParachainAsNative, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, + EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungiblesAdapter, NativeAsset, NoChecking, + RelayChainAsNative, SiblingParachainAsNative, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, }; use xcm_executor::{traits::WithOriginFilter, XcmExecutor}; @@ -163,15 +168,40 @@ impl Contains for SafeCallFilter { } } +parameter_types! { + pub TreasuryAccountId: AccountId = Treasury::account_id(); +} + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; // How we send Xcm messages. type XcmSender = XcmRouter; // How to withdraw and deposit an asset. - type AssetTransactor = LocalAssetTransactor; + // Until fixed, `LocalAssetTransactor` must be last since it returns an error if + // the operation does not go through, i.e., it cannot be chained with other + // transactors. + type AssetTransactor = ( + // Allow the asset from the other side of the pool to be "deposited" into the current system. + SwitchPairRemoteAssetTransactor, + // Allow the asset to pay for remote XCM fees to be deposited into the current system. + FungiblesAdapter< + Fungibles, + MatchesSwitchPairXcmFeeFungibleAsset, + LocationToAccountIdConverter, + AccountId, + NoChecking, + CheckingAccount, + >, + // Transactor for fungibles matching the "Here" location. + LocalAssetTransactor, + ); type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; + type IsReserve = ( + NativeAsset, + IsSwitchPairRemoteAsset, + IsSwitchPairXcmFeeAsset, + ); // Teleporting is disabled. type IsTeleporter = (); type UniversalLocation = UniversalLocation; @@ -183,8 +213,20 @@ impl xcm_executor::Config for XcmConfig { // How weight is transformed into fees. The fees are not taken out of the // Balances pallet here. Balances is only used if fees are dropped without being // used. In that case they are put into the treasury. - type Trader = - UsingComponents, HereLocation, AccountId, Balances, SendDustAndFeesToTreasury>; + + type Trader = ( + // Can pay for fees with the remote XCM asset fee (when sending it into this system). + UsingComponentsForXcmFeeAsset>, + // Can pay for the remote asset of the switch pair (when "depositing" it into this system). + UsingComponentsForSwitchPairRemoteAsset< + Runtime, + KiltToEKiltSwitchPallet, + WeightToFee, + TreasuryAccountId, + >, + // Can pay with the fungible that matches the "Here" location. + UsingComponents, HereLocation, AccountId, Balances, SendDustAndFeesToTreasury>, + ); type ResponseHandler = PolkadotXcm; // What happens with assets that are left in the register after the XCM message // was processed. PolkadotXcm has an AssetTrap that stores a hash of the asset