Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use crate::xcm_config::StakingPot;
use crate::xcm_config::{GovernanceLocation, StakingPot};
use ::ismp::{
consensus::{ConsensusClientId, StateMachineHeight, StateMachineId},
host::StateMachine,
Expand All @@ -79,7 +79,10 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Everything},
traits::{
tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
Everything,
},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
Expand All @@ -91,6 +94,7 @@ use frame_system::{
EnsureRoot,
};
use pallet_ismp::offchain::{Leaf, Proof, ProofKeys};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use sp_core::H256;
use sp_mmr_primitives::INDEXING_PREFIX;
pub use sp_runtime::{MultiAddress, Perbill, Permill};
Expand Down Expand Up @@ -500,8 +504,11 @@ parameter_types! {
pub const StakingAdminBodyId: BodyId = BodyId::Defense;
}

/// We allow root to execute privileged collator selection operations.
pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
/// We allow Root and the `StakingAdmin` to execute privileged collator selection operations.
pub type CollatorSelectionUpdateOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureXcm<IsVoiceOfBody<GovernanceLocation, StakingAdminBodyId>>,
>;

impl pallet_collator_selection::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down
64 changes: 54 additions & 10 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ use super::{
};
use frame_support::{
parameter_types,
traits::{ConstU32, Contains, Everything, Nothing},
traits::{tokens::imbalance::ResolveTo, ConstU32, Contains, Equals, Everything, Nothing},
PalletId,
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use parachains_common::xcm_config::{
AllSiblingSystemParachains, ConcreteAssetFromSystem, RelayOrOtherSystemParachains,
};
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use polkadot_sdk::*;
use sp_runtime::traits::AccountIdConversion;
use staging_xcm as xcm;
Expand All @@ -37,13 +39,19 @@ use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, FixedWeightBounds,
FrameTransactionalProcessor, FungibleAdapter, IsConcrete, NativeAsset, NonFungibleAdapter,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32,
SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents,
WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents,
};
use xcm_executor::XcmExecutor;
use xcm_executor::{traits::ConvertLocation, XcmExecutor};

// Pallet Id on Kusama.
pub const TREASURY_PALLET_INDEX: u8 = 18;
pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"py/trsry");

parameter_types! {
pub const RootLocation: Location = Location::here();
pub const RelayLocation: Location = Location::parent();
pub BrokerPalletLocation: Location = Location::new(
1,
Expand All @@ -58,6 +66,7 @@ parameter_types! {
Wild(All), // We can trust system parachains.
CoretimeChainLocation::get()
);
pub const GovernanceLocation: Location = Location::parent();
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
pub StakingPot: AccountId = CollatorSelection::account_id();
Expand Down Expand Up @@ -173,6 +182,24 @@ pub type Barrier = TrailingSetTopicAsId<
>,
>;

parameter_types! {
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(TREASURY_PALLET_INDEX)).into();
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
// Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location
// conversion is not `None`.
pub RelayTreasuryPalletAccount: AccountId =
LocationToAccountId::convert_location(&RelayTreasuryLocation::get())
.unwrap_or(TreasuryAccount::get());
}

/// Locations that will not be charged fees in the executor, neither for execution nor delivery.
/// We only waive fees for system functions, which these locations represent.
pub type WaivedLocations = (
Equals<RootLocation>,
RelayOrOtherSystemParachains<AllSiblingSystemParachains, Runtime>,
Equals<RelayTreasuryLocation>,
);

pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand All @@ -182,12 +209,17 @@ impl xcm_executor::Config for XcmConfig {
type AssetTransactor = AssetTransactors;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
type IsReserve = TrustedReserves;
type IsTeleporter = (); // Teleporting is disabled.
type IsTeleporter = ConcreteAssetFromSystem<RelayLocation>;
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;
type Trader =
UsingComponents<WeightToFee, RelayLocation, AccountId, Balances, ToAuthor<Runtime>>;
type Trader = UsingComponents<
WeightToFee,
RelayLocation,
AccountId,
Balances,
ResolveTo<StakingPot, Balances>,
>;
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetClaims = PolkadotXcm;
Expand All @@ -196,7 +228,10 @@ impl xcm_executor::Config for XcmConfig {
type MaxAssetsIntoHolding = MaxAssetsIntoHolding;
type AssetLocker = ();
type AssetExchanger = ();
type FeeManager = ();
type FeeManager = XcmFeeManagerFromComponents<
WaivedLocations,
SendXcmFeeToAccount<Self::AssetTransactor, RelayTreasuryPalletAccount>,
>;
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;
Expand Down Expand Up @@ -254,3 +289,12 @@ impl cumulus_pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type XcmExecutor = XcmExecutor<XcmConfig>;
}

#[cfg(test)]
#[test]
fn treasury_pallet_account_not_none() {
assert_eq!(
RelayTreasuryPalletAccount::get(),
LocationToAccountId::convert_location(&RelayTreasuryLocation::get()).unwrap()
)
}
Loading