Skip to content

Commit

Permalink
fix: spiritnet config for the switch pallet (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 authored Sep 28, 2024
1 parent 5ef8542 commit cc71ba5
Showing 1 changed file with 51 additions and 9 deletions.
60 changes: 51 additions & 9 deletions runtimes/spiritnet/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -27,6 +28,10 @@ use frame_support::{
traits::{Contains, 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;
Expand All @@ -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};

Expand Down Expand Up @@ -163,15 +168,40 @@ impl Contains<RuntimeCall> 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<Balances, RelayNetworkId>;
// 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<LocationToAccountIdConverter, Runtime, KiltToEKiltSwitchPallet>,
// Allow the asset to pay for remote XCM fees to be deposited into the current system.
FungiblesAdapter<
Fungibles,
MatchesSwitchPairXcmFeeFungibleAsset<Runtime, KiltToEKiltSwitchPallet>,
LocationToAccountIdConverter,
AccountId,
NoChecking,
CheckingAccount,
>,
// Transactor for fungibles matching the "Here" location.
LocalAssetTransactor<Balances, RelayNetworkId>,
);
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = NativeAsset;
type IsReserve = (
NativeAsset,
IsSwitchPairRemoteAsset<Runtime, KiltToEKiltSwitchPallet>,
IsSwitchPairXcmFeeAsset<Runtime, KiltToEKiltSwitchPallet>,
);
// Teleporting is disabled.
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
Expand All @@ -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<WeightToFee<Runtime>, HereLocation, AccountId, Balances, SendDustAndFeesToTreasury<Runtime>>;

type Trader = (
// Can pay for fees with the remote XCM asset fee (when sending it into this system).
UsingComponentsForXcmFeeAsset<Runtime, KiltToEKiltSwitchPallet, WeightToFee<Runtime>>,
// Can pay for the remote asset of the switch pair (when "depositing" it into this system).
UsingComponentsForSwitchPairRemoteAsset<
Runtime,
KiltToEKiltSwitchPallet,
WeightToFee<Runtime>,
TreasuryAccountId,
>,
// Can pay with the fungible that matches the "Here" location.
UsingComponents<WeightToFee<Runtime>, HereLocation, AccountId, Balances, SendDustAndFeesToTreasury<Runtime>>,
);
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
Expand Down

0 comments on commit cc71ba5

Please sign in to comment.