Skip to content

Commit

Permalink
Revert "Xcm setup (#17)" (#28)
Browse files Browse the repository at this point in the history
This reverts commit da16e0b.
  • Loading branch information
Szegoo authored Mar 8, 2024
1 parent da16e0b commit 2123283
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 162 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", default
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" }
pallet-uniques = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" }

sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" }
sc-chain-spec = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.6.0" }
Expand Down
4 changes: 0 additions & 4 deletions runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-uniques = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
Expand Down Expand Up @@ -108,7 +107,6 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-uniques/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down Expand Up @@ -151,7 +149,6 @@ runtime-benchmarks = [
"pallet-parachain-template/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-uniques/std",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down Expand Up @@ -181,7 +178,6 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-uniques/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
Expand Down
50 changes: 4 additions & 46 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything,
},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
Expand All @@ -45,7 +43,7 @@ use frame_support::{
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot, EnsureSigned,
EnsureRoot,
};
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -188,12 +186,6 @@ const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64,
);

pub const fn deposit(items: u32, bytes: u32) -> Balance {
// map to 1/10 of what the kusama relay chain charges (v9020)
// TODO: don't use westend:
parachains_common::westend::currency::deposit(items, bytes) / 10
}

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Expand Down Expand Up @@ -456,38 +448,6 @@ impl pallet_collator_selection::Config for Runtime {
type WeightInfo = ();
}

type CollectionId = u32;
type ItemId = u128;

parameter_types! {
pub const UniquesCollectionDeposit: Balance = 10 * M4X;
pub const UniquesItemDeposit: Balance = 1 * M4X;
pub const UniquesMetadataDepositBase: Balance = deposit(1, 129);
pub const UniquesAttributeDepositBase: Balance = deposit(1, 0);
pub const UniquesDepositPerByte: Balance = deposit(0, 1);
}

impl pallet_uniques::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CollectionId = CollectionId;
type ItemId = ItemId;
type Currency = Balances;
type ForceOrigin = EnsureRoot<AccountId>;
type CollectionDeposit = UniquesCollectionDeposit;
type ItemDeposit = UniquesItemDeposit;
type MetadataDepositBase = UniquesMetadataDepositBase;
type AttributeDepositBase = UniquesAttributeDepositBase;
type DepositPerByte = UniquesDepositPerByte;
type StringLimit = ConstU32<128>;
type KeyLimit = ConstU32<32>;
type ValueLimit = ConstU32<64>;
type WeightInfo = ();
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type Locker = ();
}

/// Configure the pallet template in pallets/template.
impl pallet_parachain_template::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -523,9 +483,8 @@ construct_runtime!(
CumulusXcm: cumulus_pallet_xcm = 32,
MessageQueue: pallet_message_queue = 33,

// Main stage.
Uniques: pallet_uniques = 50,
TemplatePallet: pallet_parachain_template = 51,
// Template
TemplatePallet: pallet_parachain_template = 50,
}
);

Expand All @@ -539,7 +498,6 @@ mod benches {
[pallet_sudo, Sudo]
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_uniques, Uniques]
);
}

Expand Down
113 changes: 18 additions & 95 deletions runtime/regionx/src/xcm_config.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
use super::{
AccountId, AllPalletsWithSystem, Balances, CollectionId, ItemId, ParachainInfo,
ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Uniques,
WeightToFee, XcmpQueue,
AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm,
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
};
use core::marker::PhantomData;
use frame_support::{
match_types, parameter_types,
traits::{ConstU32, Everything, Get, Nothing},
traits::{ConstU32, Everything, Nothing},
weights::Weight,
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use polkadot_parachain_primitives::primitives::Sibling;
use polkadot_runtime_common::impls::ToAuthor;
use sp_runtime::traits::MaybeEquivalence;
use xcm::latest::prelude::*;
#[allow(deprecated)]
use xcm_builder::CurrencyAdapter;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom,
AllowUnpaidExecutionFrom, ConvertedConcreteId, DenyReserveTransferToRelayChain, DenyThenTry,
EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NoChecking, NonFungiblesAdapter,
ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin,
FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WithComputedOrigin, WithUniqueTopic,
};
use xcm_executor::{traits::JustTry, XcmExecutor};
use xcm_executor::XcmExecutor;

parameter_types! {
pub const RelayLocation: MultiLocation = MultiLocation::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub const CoretimeParaId: u32 = 1005;
pub const CoretimeParaLocation: MultiLocation =
MultiLocation { parents: 1, interior: X1(Parachain(CoretimeParaId::get())) };
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}
Expand All @@ -50,7 +42,6 @@ pub type LocationToAccountId = (
);

/// Means for transacting assets on this chain.
#[allow(deprecated)]
pub type LocalAssetTransactor = CurrencyAdapter<
// Use this currency:
Balances,
Expand All @@ -64,79 +55,6 @@ pub type LocalAssetTransactor = CurrencyAdapter<
(),
>;

// TODO: this shouldn't be defined here.
pub struct AsPrefixedPalletInstance<Prefix, AssetId, ConvertAssetId, L = MultiLocation>(
PhantomData<(Prefix, AssetId, ConvertAssetId, L)>,
);
impl<
Prefix: Get<L>,
AssetId: Clone,
ConvertAssetId: MaybeEquivalence<u8, AssetId>,
L: TryInto<MultiLocation> + TryFrom<MultiLocation> + Clone,
> MaybeEquivalence<L, AssetId> for AsPrefixedPalletInstance<Prefix, AssetId, ConvertAssetId, L>
{
fn convert(id: &L) -> Option<AssetId> {
let prefix = Prefix::get();
let latest_prefix: MultiLocation = prefix.try_into().ok()?;
let latest_id: MultiLocation = (*id).clone().try_into().ok()?;
if latest_prefix.parent_count() != latest_id.parent_count() ||
latest_prefix
.interior()
.iter()
.enumerate()
.any(|(index, junction)| latest_id.interior().at(index) != Some(junction))
{
return None
}
match latest_id.interior().at(latest_prefix.interior().len()) {
Some(Junction::PalletInstance(id)) => ConvertAssetId::convert(&id),
_ => None,
}
}
fn convert_back(what: &AssetId) -> Option<L> {
let location = Prefix::get();
let mut latest_location: MultiLocation = location.try_into().ok()?;
let id = ConvertAssetId::convert_back(what)?;
latest_location.push_interior(Junction::PalletInstance(id)).ok()?;
latest_location.try_into().ok()
}
}

pub struct RegionIdConverter;
impl MaybeEquivalence<AssetInstance, ItemId> for RegionIdConverter {
fn convert(a: &AssetInstance) -> Option<ItemId> {
match a {
AssetInstance::Index(i) => Some(*i),
_ => None,
}
}
fn convert_back(i: &ItemId) -> Option<AssetInstance> {
Some(AssetInstance::Index(*i))
}
}

pub type CoretimeRegionsTransactor = NonFungiblesAdapter<
// Use this nonfungibles implementation:
Uniques,
// Type that attempts to convert the `MultiAsset` into a registered uniques item.
ConvertedConcreteId<
CollectionId,
ItemId,
AsPrefixedPalletInstance<CoretimeParaLocation, CollectionId, JustTry>,
RegionIdConverter,
>,
// Convert an XCM MultiLocation into a local account id:
LocationToAccountId,
// This chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We don't track any teleports of `Assets`.
NoChecking,
// No teleports.
(),
>;

pub type AssetTransactors = (LocalAssetTransactor, CoretimeRegionsTransactor);

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
/// biases the kind of local `Origin` it will become.
Expand Down Expand Up @@ -179,7 +97,6 @@ pub type Barrier = TrailingSetTopicAsId<
TakeWeightCredit,
WithComputedOrigin<
(
AllowUnpaidExecutionFrom<Everything>,
AllowTopLevelPaidExecutionFrom<Everything>,
AllowExplicitUnpaidExecutionFrom<ParentOrParentsExecutivePlurality>,
// ^^^ Parent and its exec plurality get free execution
Expand All @@ -196,10 +113,9 @@ impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
type XcmSender = XcmRouter;
// How to withdraw and deposit an asset.
type AssetTransactor = AssetTransactors;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToTransactDispatchOrigin;
// TODO: FIXME
type IsReserve = Everything;
type IsReserve = NativeAsset;
type IsTeleporter = (); // Teleporting is disabled.
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
Expand Down Expand Up @@ -234,6 +150,11 @@ pub type XcmRouter = WithUniqueTopic<(
XcmpQueue,
)>;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand All @@ -259,6 +180,8 @@ impl pallet_xcm::Config for Runtime {
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = pallet_xcm::TestWeightInfo;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down

0 comments on commit 2123283

Please sign in to comment.