From 157619d3768316f744e595bc1a68f980eb8e5156 Mon Sep 17 00:00:00 2001 From: Greg Zaitsev Date: Thu, 03 Jun 2021 15:00:41 +0000 Subject: [PATCH] wip parachains --- --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -1,66 +1,19 @@ +################################################################################ +# Package + [package] -authors = ['UseTech Professional '] +authors = ['Unique Network '] +build = 'build.rs' +description = 'Substrate node nft' edition = '2018' -homepage = 'https://substrate.io' +homepage = 'https://unique.network' license = 'All Rights Reserved' name = 'nft-runtime' -repository = 'https://github.com/usetech-llc/nft_parachain/' +repository = 'https://github.com/usetech-llc/nft_private/' version = '3.0.0' [package.metadata.docs.rs] targets = ['x86_64-unknown-linux-gnu'] - -[build-dependencies] -substrate-wasm-builder = '4.0.0' - -# alias "parity-scale-code" to "codec" -[dependencies.codec] -default-features = false -features = ['derive'] -package = 'parity-scale-codec' -version = '2.0.0' - -[dependencies] -hex-literal = { optional = true, version = '0.3.1' } -serde = { features = ['derive'], optional = true, version = '1.0.119' } - -# local dependencies -pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' } -pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' } - -# Substrate dependencies -frame-benchmarking = { default-features = false, optional = true, version = '3.0.0' } -frame-executive = { default-features = false, version = '3.0.0' } -frame-support = { default-features = false, version = '3.0.0' } -frame-system = { default-features = false, version = '3.0.0' } -frame-system-benchmarking = { default-features = false, optional = true, version = '3.0.0' } -frame-system-rpc-runtime-api = { default-features = false, version = '3.0.0' } -pallet-aura = { default-features = false, version = '3.0.0' } -pallet-balances = { default-features = false, version = '3.0.0' } -pallet-contracts = { default-features = false, version = '3.0.0' } -pallet-contracts-primitives = { default-features = false, version = '3.0.0' } -pallet-contracts-rpc-runtime-api = { default-features = false, version = '3.0.0' } -pallet-grandpa = { default-features = false, version = '3.0.0' } -pallet-randomness-collective-flip = { default-features = false, version = '3.0.0' } -pallet-sudo = { default-features = false, version = '3.0.0' } -pallet-timestamp = { default-features = false, version = '3.0.0' } -pallet-transaction-payment = { default-features = false, version = '3.0.0' } -pallet-transaction-payment-rpc-runtime-api = { default-features = false, version = '3.0.0' } -pallet-treasury = { default-features = false, version = "3.0.0" } -pallet-vesting = { default-features = false, version = "3.0.0" } -sp-arithmetic = { default-features = false, version = '3.0.0' } -sp-api = { default-features = false, version = '3.0.0' } -sp-block-builder = { default-features = false, version = '3.0.0' } -sp-consensus-aura = { default-features = false, version = '0.9.0' } -sp-core = { default-features = false, version = '3.0.0' } -sp-inherents = { default-features = false, version = '3.0.0' } -sp-offchain = { default-features = false, version = '3.0.0' } -sp-runtime = { default-features = false, version = '3.0.0' } -sp-session = { default-features = false, version = '3.0.0' } -sp-std = { default-features = false, version = '3.0.0' } -sp-transaction-pool = { default-features = false, version = '3.0.0' } -sp-version = { default-features = false, version = '3.0.0' } -smallvec = "1.4.1" [features] default = ['std'] @@ -78,17 +31,19 @@ ] std = [ 'codec/std', - 'serde', + 'cumulus-pallet-parachain-system/std', + 'cumulus-pallet-xcm/std', + 'cumulus-pallet-xcmp-queue/std', + 'cumulus-primitives-core/std', + 'cumulus-primitives-utility/std', 'frame-executive/std', 'frame-support/std', 'frame-system/std', 'frame-system-rpc-runtime-api/std', - 'pallet-aura/std', 'pallet-balances/std', 'pallet-contracts/std', 'pallet-contracts-primitives/std', 'pallet-contracts-rpc-runtime-api/std', - 'pallet-grandpa/std', 'pallet-randomness-collective-flip/std', 'pallet-sudo/std', 'pallet-timestamp/std', @@ -96,19 +51,297 @@ 'pallet-transaction-payment-rpc-runtime-api/std', 'pallet-treasury/std', 'pallet-vesting/std', - - 'pallet-inflation/std', - 'pallet-nft/std', + 'serde', 'sp-api/std', 'sp-block-builder/std', - 'sp-consensus-aura/std', 'sp-core/std', 'sp-inherents/std', + 'sp-io/std', 'sp-offchain/std', 'sp-runtime/std', 'sp-session/std', 'sp-std/std', 'sp-transaction-pool/std', 'sp-version/std', + 'xcm/std', + 'xcm-builder/std', + 'xcm-executor/std', + 'pallet-inflation/std', + 'pallet-nft/std', ] + +################################################################################ +# Substrate Dependencies + +[dependencies.codec] +default-features = false +features = ['derive'] +package = 'parity-scale-codec' +version = '2.0.0' + +[dependencies.frame-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.frame-executive] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.frame-support] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.frame-system] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.frame-system-benchmarking] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +optional = true +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.frame-system-rpc-runtime-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.hex-literal] +optional = true +version = '0.3.1' + +[dependencies.serde] +features = ['derive'] +optional = true +version = '1.0.119' + +[dependencies.pallet-balances] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +# Contracts specific packages +[dependencies.pallet-contracts] +git = 'https://github.com/paritytech/substrate.git' +default-features = false +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-contracts-primitives] +git = 'https://github.com/paritytech/substrate.git' +default-features = false +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-contracts-rpc-runtime-api] +git = 'https://github.com/paritytech/substrate.git' +default-features = false +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-randomness-collective-flip] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-sudo] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-timestamp] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-transaction-payment] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-transaction-payment-rpc-runtime-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-treasury] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.pallet-vesting] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-arithmetic] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-api] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-block-builder] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-core] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-inherents] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-io] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-offchain] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-runtime] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-session] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-std] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-transaction-pool] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.sp-version] +default-features = false +git = 'https://github.com/paritytech/substrate.git' +branch = 'rococo-v1' +version = '3.0.0' + +[dependencies.smallvec] +version = '1.4.1' + +################################################################################ +# Cumulus dependencies + +[dependencies.parachain-info] +default-features = false +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +version = '0.1.0' + +[dependencies.cumulus-pallet-parachain-system] +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +default-features = false + +[dependencies.cumulus-primitives-core] +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +default-features = false + +[dependencies.cumulus-pallet-xcm] +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +default-features = false + +[dependencies.cumulus-pallet-xcmp-queue] +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +default-features = false + +[dependencies.cumulus-primitives-utility] +git = 'https://github.com/paritytech/cumulus.git' +branch = 'rococo-v1' +default-features = false + +################################################################################ +# Polkadot dependencies + +[dependencies.polkadot-parachain] +git = 'https://github.com/paritytech/polkadot' +branch = 'rococo-v1' +default-features = false + +[dependencies.xcm] +git = 'https://github.com/paritytech/polkadot' +branch = 'rococo-v1' +default-features = false + +[dependencies.xcm-builder] +git = 'https://github.com/paritytech/polkadot' +branch = 'rococo-v1' +default-features = false + +[dependencies.xcm-executor] +git = 'https://github.com/paritytech/polkadot' +branch = 'rococo-v1' +default-features = false + +[dependencies.pallet-xcm] +git = 'https://github.com/paritytech/polkadot' +branch = 'rococo-v1' +default-features = false + + +################################################################################ +# Build Dependencies + +[build-dependencies] +substrate-wasm-builder = '4.0.0' + + +################################################################################ +# local dependencies + +pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' } +pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' } + --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -13,22 +13,23 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use pallet_grandpa::fg_primitives; -use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList}; use sp_api::impl_runtime_apis; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{ crypto::KeyTypeId, crypto::Public, OpaqueMetadata }; use sp_runtime::{ + BuildStorage, Permill, Perbill, Percent, ModuleId, create_runtime_str, generic, impl_opaque_keys, traits::{ - Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, + AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto, IdentifyAccount, IdentityLookup, NumberFor, Verify, AccountIdConversion, }, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, MultiSignature, }; + +use sp_std::prelude::*; + #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -42,12 +43,11 @@ parameter_types, StorageValue, traits::{ - Currency, ExistenceRequirement, Get, KeyOwnerProofSystem, OnUnbalanced, Randomness, - LockIdentifier, + All, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier, OnUnbalanced, Randomness }, weights::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, - DispatchClass, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, Weight, + DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight, WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients }, }; @@ -64,6 +64,19 @@ pub use pallet_timestamp::Call as TimestampCall; +// Polkadot imports +use polkadot_parachain::primitives::Sibling; +use xcm::v0::{Junction, MultiLocation, NetworkId}; +use xcm_builder::{ + AccountId32Aliases, CurrencyAdapter, LocationInverter, ParentIsDefault, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SovereignSignedViaLocation, FixedRateOfConcreteFungible, EnsureXcmOrigin, + AllowTopLevelPaidExecutionFrom, TakeWeightCredit, FixedWeightBounds, IsConcrete, NativeAsset, + AllowUnpaidExecutionFrom, ParentAsSuperuser, +}; +use xcm_executor::{Config, XcmExecutor}; + + mod chain_extension; use crate::chain_extension::{ NFTExtension, Imbalance }; @@ -139,10 +152,7 @@ pub type BlockId = generic::BlockId; impl_opaque_keys! { - pub struct SessionKeys { - pub aura: Aura, - pub grandpa: Grandpa, - } + pub struct SessionKeys {} } } @@ -166,6 +176,12 @@ pub const HOURS: BlockNumber = MINUTES * 60; pub const DAYS: BlockNumber = HOURS * 24; +#[derive(codec::Encode, codec::Decode)] +pub enum XCMPMessage { + /// Transfer tokens to the given account from the Parachain account. + TransferToken(XAccountId, XBalance), +} + /// The version information used to identify this runtime when compiled natively. #[cfg(feature = "std")] pub fn native_version() -> NativeVersion { @@ -173,45 +189,8 @@ runtime_version: VERSION, can_author_with: Default::default(), } -} - -/// Provides a membership set with only the configured aura users -pub struct ValiudatorsOnly(PhantomData); -impl frame_support::traits::Contains for ValiudatorsOnly { - fn contains(t: &AccountId) -> bool { - let arr: [u8; 32] = *t.as_ref(); - let raw_key: Vec = Vec::from(arr); - - match pallet_aura::Module::::authorities().iter().find(|auth| auth.to_raw_vec() == raw_key) { - Some(_) => true, - None => false, - } - } - fn sorted_members() -> Vec { - let mut members: Vec = Vec::new(); - for auth in pallet_aura::Module::::authorities() { - let mut arr: [u8; 32] = Default::default(); - let bor_arr = auth.clone().to_raw_vec(); - let slice = bor_arr.as_slice(); - arr.copy_from_slice(slice); - members.push(AccountId::from(arr)); - } - members - } - fn count() -> usize { - pallet_aura::Module::::authorities().len() - } } -impl frame_support::traits::ContainsLengthBound for ValiudatorsOnly { - fn min_len() -> usize { - 1 - } - fn max_len() -> usize { - 100 - } -} - type NegativeImbalance = >::NegativeImbalance; pub struct DealWithFees; @@ -283,73 +262,52 @@ } impl system::Config for Runtime { + /// The data to be stored in an account. + type AccountData = pallet_balances::AccountData; + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; /// The basic call filter to use in dispatchable. type BaseCallFilter = (); - /// The identifier used to distinguish between accounts. - type AccountId = AccountId; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = BlockHashCount; + /// The maximum length of a block (in bytes). + type BlockLength = RuntimeBlockLength; + /// The index type for blocks. + type BlockNumber = BlockNumber; + /// The weight of the overhead invoked on the block import process, independent of the + /// extrinsics included in that block. + type BlockWeights = RuntimeBlockWeights; /// The aggregated dispatch type that is available for extrinsics. type Call = Call; - /// The lookup mechanism to get account ID from whatever is passed in dispatchers. - type Lookup = IdentityLookup; - /// The index type for storing how many extrinsics an account has signed. - type Index = Index; - /// The index type for blocks. - type BlockNumber = BlockNumber; + /// The weight of database operations that the runtime can invoke. + type DbWeight = RocksDbWeight; + /// The ubiquitous event type. + type Event = Event; /// The type for hashing blocks and tries. type Hash = Hash; - /// The hashing algorithm used. + /// The hashing algorithm used. type Hashing = BlakeTwo256; /// The header type. type Header = generic::Header; - /// The ubiquitous event type. - type Event = Event; + /// The index type for storing how many extrinsics an account has signed. + type Index = Index; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// What to do if an account is fully reaped from the system. + type OnKilledAccount = (); + /// What to do if a new account is created. + type OnNewAccount = (); + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; /// The ubiquitous origin type. type Origin = Origin; - /// Maximum number of block number to block hash mappings to keep (oldest pruned first). - type BlockHashCount = BlockHashCount; - /// The weight of database operations that the runtime can invoke. - type DbWeight = RocksDbWeight; - /// The weight of the overhead invoked on the block import process, independent of the - /// extrinsics included in that block. - type BlockWeights = RuntimeBlockWeights; - /// Version of the runtime. - type Version = Version; /// This type is being generated by `construct_runtime!`. type PalletInfo = PalletInfo; - /// What to do if a new account is created. - type OnNewAccount = (); - /// What to do if an account is fully reaped from the system. - type OnKilledAccount = (); - /// The data to be stored in an account. - type AccountData = pallet_balances::AccountData; + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = SS58Prefix; /// Weight information for the extrinsics of this pallet. type SystemWeightInfo = system::weights::SubstrateWeight; - - type BlockLength = RuntimeBlockLength; - type SS58Prefix = SS58Prefix; -} - -impl pallet_aura::Config for Runtime { - type AuthorityId = AuraId; -} - -impl pallet_grandpa::Config for Runtime { - type Event = Event; - type Call = Call; - - type KeyOwnerProofSystem = (); - - type KeyOwnerProof = - >::Proof; - - type KeyOwnerIdentification = >::IdentificationTuple; - - type HandleEquivocation = (); - - type WeightInfo = (); + /// Version of the runtime. + type Version = Version; } parameter_types! { @@ -379,7 +337,7 @@ type DustRemoval = Treasury; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; - type WeightInfo = (); + type WeightInfo = pallet_balances::weights::SubstrateWeight; } pub const MICROUNIQUE: Balance = 1_000_000_000; @@ -440,7 +398,7 @@ type MaxCodeSize = MaxCodeSize; } -parameter_types! { +parame ter_types! { pub const TransactionByteFee: Balance = 501 * MICROUNIQUE; // Targeting 0.1 Unique per NFT transfer } @@ -521,6 +479,147 @@ } parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4; +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type Event = Event; + type OnValidationData = (); + type SelfParaId = parachain_info::Module; + type DownwardMessageHandlers = cumulus_primitives_utility::UnqueuedDmpAsParent< + MaxDownwardMessageWeight, + XcmExecutor, + Call, + >; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = XcmpQueue; + type ReservedXcmpWeight = ReservedXcmpWeight; +} + +impl parachain_info::Config for Runtime {} + +parameter_types! { + pub const RococoLocation: MultiLocation = MultiLocation::X1(Junction::Parent); + pub const RococoNetwork: NetworkId = NetworkId::Polkadot; + pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into(); + pub Ancestry: MultiLocation = Junction::Parachain { + id: ParachainInfo::parachain_id().into() + }.into(); +} + +/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsDefault, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, +); + +/// Means for transacting assets on this chain. +pub type LocalAssetTransactor = CurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, +>; + +/// 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. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `Origin::Signed` origin of the same 32-byte value. + SignedAccountId32AsNative, +); + +parameter_types! { + pub UnitWeightCost: Weight = 1_000; +} + +parameter_types! { + // 1_000_000_000_000 => 1 unit of asset for 1 unit of Weight. + // TODO: Should take the actual weight price. This is just 1_000 ROC per second of weight. + pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::X1(Junction::Parent), 1_000); + pub AllowUnpaidFrom: Vec = vec![ MultiLocation::X1(Junction::Parent) ]; +} + +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom>, + AllowUnpaidExecutionFrom>, // <- Parent gets free execution +); + + +pub struct XcmConfig; +impl Config for XcmConfig { + type Call = Call; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = NativeAsset; // <- should be enough to allow teleportation of ROC + type LocationInverter = LocationInverter; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfConcreteFungible; + type ResponseHandler = (); // Don't handle responses for now. +} + +parameter_types! { + pub const MaxDownwardMessageWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 10; +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = (); + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = ( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +); + +impl pallet_xcm::Config for Runtime { + type Event = Event; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecutor = XcmExecutor; +} + +impl cumulus_pallet_xcm::Config for Runtime {} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type Event = Event; + type XcmExecutor = XcmExecutor; + type ChannelInfo = ParachainSystem; +} + +parameter_types! { pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account(); pub const CollectionCreationPrice: Balance = 100 * UNIQUE; } @@ -555,19 +654,23 @@ NodeBlock = opaque::Block, UncheckedExtrinsic = UncheckedExtrinsic { - System: system::{Module, Call, Config, Storage, Event}, - RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, Contracts: pallet_contracts::{Module, Call, Config, Storage, Event}, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Origin}, + ParachainInfo: parachain_info::{Pallet, Storage, Config}, + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event}, + PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, + Sudo: pallet_sudo::{Module, Call, Config, Storage, Event}, + System: system::{Module, Call, Config, Storage, Event}, Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, - Aura: pallet_aura::{Module, Config }, - Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event}, - Balances: pallet_balances::{Module, Call, Storage, Config, Event}, TransactionPayment: pallet_transaction_payment::{Module, Storage}, - Sudo: pallet_sudo::{Module, Call, Config, Storage, Event}, - Inflation: pallet_inflation::{Module, Call, Storage}, - Nft: pallet_nft::{Module, Call, Config, Storage, Event}, Treasury: pallet_treasury::{Module, Call, Storage, Config, Event}, Vesting: pallet_vesting::{Module, Call, Config, Storage, Event}, + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event}, + + Inflation: pallet_inflation::{Module, Call, Storage}, + Nft: pallet_nft::{Module, Call, Config, Storage, Event}, } ); @@ -600,34 +703,6 @@ frame_executive::Executive, Runtime, AllModules>; impl_runtime_apis! { - - impl pallet_contracts_rpc_runtime_api::ContractsApi - for Runtime - { - fn call( - origin: AccountId, - dest: AccountId, - value: Balance, - gas_limit: u64, - input_data: Vec, - ) -> pallet_contracts_primitives::ContractExecResult { - Contracts::bare_call(origin, dest, value, gas_limit, input_data) - } - - fn get_storage( - address: AccountId, - key: [u8; 32], - ) -> pallet_contracts_primitives::GetStorageResult { - Contracts::get_storage(address, key) - } - - fn rent_projection( - address: AccountId, - ) -> pallet_contracts_primitives::RentProjectionResult { - Contracts::rent_projection(address) - } - } - impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { VERSION @@ -688,16 +763,6 @@ } } - impl sp_consensus_aura::AuraApi for Runtime { - fn slot_duration() -> u64 { - Aura::slot_duration() - } - - fn authorities() -> Vec { - Aura::authorities() - } - } - impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { opaque::SessionKeys::generate(seed) @@ -710,32 +775,6 @@ } } - impl fg_primitives::GrandpaApi for Runtime { - fn grandpa_authorities() -> GrandpaAuthorityList { - Grandpa::grandpa_authorities() - } - - fn submit_report_equivocation_unsigned_extrinsic( - _equivocation_proof: fg_primitives::EquivocationProof< - ::Hash, - NumberFor, - >, - _key_owner_proof: fg_primitives::OpaqueKeyOwnershipProof, - ) -> Option<()> { - None - } - - fn generate_key_ownership_proof( - _set_id: fg_primitives::SetId, - _authority_id: GrandpaId, - ) -> Option { - // NOTE: this is the only implementation possible since we've - // defined our key owner proof type as a bottom type (i.e. a type - // with no values). - None - } - } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { fn account_nonce(account: AccountId) -> Index { System::account_nonce(account) @@ -751,6 +790,33 @@ } } + impl pallet_contracts_rpc_runtime_api::ContractsApi + for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: u64, + input_data: Vec, + ) -> pallet_contracts_primitives::ContractExecResult { + Contracts::bare_call(origin, dest, value, gas_limit, input_data) + } + + fn get_storage( + address: AccountId, + key: [u8; 32], + ) -> pallet_contracts_primitives::GetStorageResult { + Contracts::get_storage(address, key) + } + + fn rent_projection( + address: AccountId, + ) -> pallet_contracts_primitives::RentProjectionResult { + Contracts::rent_projection(address) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark( -- gitstuff