difftreelog
cargo fmt
in: master
18 files changed
common-types/src/lib.rsdiffbeforeafterboth--- a/common-types/src/lib.rs
+++ b/common-types/src/lib.rs
@@ -17,8 +17,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use sp_runtime::{
- generic,
- traits::{Verify, IdentifyAccount}, MultiSignature,
+ generic,
+ traits::{Verify, IdentifyAccount},
+ MultiSignature,
};
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
@@ -26,33 +27,29 @@
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
pub mod opaque {
- pub use sp_runtime::{
- generic,
- traits::BlakeTwo256,
- OpaqueExtrinsic as UncheckedExtrinsic
- };
+ pub use sp_runtime::{generic, traits::BlakeTwo256, OpaqueExtrinsic as UncheckedExtrinsic};
pub use super::{BlockNumber, Signature, AccountId, Balance, Index, Hash, AuraId};
- /// Opaque block header type.
- pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
+ /// Opaque block header type.
+ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
- /// Opaque block type.
- pub type Block = generic::Block<Header, UncheckedExtrinsic>;
+ /// Opaque block type.
+ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
- pub trait RuntimeInstance {
- type CrossAccountId: pallet_evm::account::CrossAccountId<sp_runtime::AccountId32>
- + Send
- + Sync
- + 'static;
+ pub trait RuntimeInstance {
+ type CrossAccountId: pallet_evm::account::CrossAccountId<sp_runtime::AccountId32>
+ + Send
+ + Sync
+ + 'static;
- type TransactionConverter: fp_rpc::ConvertTransaction<UncheckedExtrinsic>
- + Send
- + Sync
- + 'static;
+ type TransactionConverter: fp_rpc::ConvertTransaction<UncheckedExtrinsic>
+ + Send
+ + Sync
+ + 'static;
- fn get_transaction_converter() -> Self::TransactionConverter;
- }
+ fn get_transaction_converter() -> Self::TransactionConverter;
+ }
}
pub type SessionHandlers = ();
node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -40,9 +40,7 @@
use sc_service::TransactionPool;
use std::{collections::BTreeMap, sync::Arc};
-use common_types::opaque::{
- Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance,
-};
+use common_types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};
// RMRK
use up_data_structs::{
runtime/common/config/ethereum.rsdiffbeforeafterboth--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -1,28 +1,18 @@
use sp_core::{U256, H160};
use frame_support::{
- weights::{Weight, constants::WEIGHT_PER_SECOND},
- traits::{FindAuthor},
- parameter_types, ConsensusEngineId,
+ weights::{Weight, constants::WEIGHT_PER_SECOND},
+ traits::{FindAuthor},
+ parameter_types, ConsensusEngineId,
};
use sp_runtime::{RuntimeAppPublic, Perbill};
use crate::{
- runtime_common::{
- constants::*,
- dispatch::CollectionDispatchT,
- ethereum::sponsoring::EvmSponsorshipHandler,
- config::sponsoring::DefaultSponsoringRateLimit,
- DealWithFees,
- },
- Runtime,
- Aura,
- Balances,
- Event,
- ChainId,
+ runtime_common::{
+ constants::*, dispatch::CollectionDispatchT, ethereum::sponsoring::EvmSponsorshipHandler,
+ config::sponsoring::DefaultSponsoringRateLimit, DealWithFees,
+ },
+ Runtime, Aura, Balances, Event, ChainId,
};
-use pallet_evm::{
- EnsureAddressTruncated,
- HashedAddressMapping,
-};
+use pallet_evm::{EnsureAddressTruncated, HashedAddressMapping};
pub type CrossAccountId = pallet_evm::account::BasicCrossAccountId<Runtime>;
@@ -116,7 +106,7 @@
}
parameter_types! {
- // 0x842899ECF380553E8a4de75bF534cdf6fBF64049
+ // 0x842899ECF380553E8a4de75bF534cdf6fBF64049
pub const HelpersContractAddress: H160 = H160([
0x84, 0x28, 0x99, 0xec, 0xf3, 0x80, 0x55, 0x3e, 0x8a, 0x4d, 0xe7, 0x5b, 0xf5, 0x34, 0xcd, 0xf6, 0xfb, 0xf6, 0x40, 0x49,
]);
runtime/common/config/mod.rsdiffbeforeafterboth--- a/runtime/common/config/mod.rs
+++ b/runtime/common/config/mod.rs
@@ -14,10 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-pub mod substrate;
pub mod ethereum;
-pub mod sponsoring;
+pub mod orml;
pub mod pallets;
pub mod parachain;
+pub mod sponsoring;
+pub mod substrate;
pub mod xcm;
-pub mod orml;
runtime/common/config/orml.rsdiffbeforeafterboth--- a/runtime/common/config/orml.rs
+++ b/runtime/common/config/orml.rs
@@ -16,10 +16,7 @@
use frame_support::parameter_types;
use frame_system::EnsureSigned;
-use crate::{
- runtime_common::constants::*,
- Runtime, Event, RelayChainBlockNumberProvider,
-};
+use crate::{runtime_common::constants::*, Runtime, Event, RelayChainBlockNumberProvider};
use common_types::{AccountId, Balance};
parameter_types! {
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -17,24 +17,18 @@
use frame_support::parameter_types;
use sp_runtime::traits::AccountIdConversion;
use crate::{
- runtime_common::{
- constants::*,
- dispatch::CollectionDispatchT,
- config::{
- substrate::TreasuryModuleId,
- ethereum::EvmCollectionHelpersAddress,
- },
- weights::CommonWeights,
- RelayChainBlockNumberProvider,
- },
- Runtime,
- Event,
- Call,
- Balances,
+ runtime_common::{
+ constants::*,
+ dispatch::CollectionDispatchT,
+ config::{substrate::TreasuryModuleId, ethereum::EvmCollectionHelpersAddress},
+ weights::CommonWeights,
+ RelayChainBlockNumberProvider,
+ },
+ Runtime, Event, Call, Balances,
};
use common_types::{AccountId, Balance, BlockNumber};
use up_data_structs::{
- mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
+ mapping::{EvmTokenAddressMapping, CrossTokenAddressMapping},
};
#[cfg(feature = "rmrk")]
runtime/common/config/pallets/scheduler.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/scheduler.rs
+++ b/runtime/common/config/pallets/scheduler.rs
@@ -14,20 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{
- traits::PrivilegeCmp,
- weights::Weight,
- parameter_types
-};
+use frame_support::{traits::PrivilegeCmp, weights::Weight, parameter_types};
use frame_system::EnsureSigned;
use sp_runtime::Perbill;
use sp_std::cmp::Ordering;
use crate::{
- runtime_common::{
- scheduler::SchedulerPaymentExecutor,
- config::substrate::RuntimeBlockWeights,
- },
- Runtime, Call, Event, Origin, OriginCaller, Balances
+ runtime_common::{scheduler::SchedulerPaymentExecutor, config::substrate::RuntimeBlockWeights},
+ Runtime, Call, Event, Origin, OriginCaller, Balances,
};
use common_types::AccountId;
@@ -36,7 +29,7 @@
RuntimeBlockWeights::get().max_block;
pub const MaxScheduledPerBlock: u32 = 50;
- pub const NoPreimagePostponement: Option<u32> = Some(10);
+ pub const NoPreimagePostponement: Option<u32> = Some(10);
pub const Preimage: Option<u32> = Some(10);
}
runtime/common/config/parachain.rsdiffbeforeafterboth--- a/runtime/common/config/parachain.rs
+++ b/runtime/common/config/parachain.rs
@@ -14,17 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use frame_support::{
- weights::Weight,
- parameter_types,
-};
-use crate::{
- runtime_common::constants::*,
- Runtime,
- Event,
- XcmpQueue,
- DmpQueue,
-};
+use frame_support::{weights::Weight, parameter_types};
+use crate::{runtime_common::constants::*, Runtime, Event, XcmpQueue, DmpQueue};
parameter_types! {
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT / 4;
runtime/common/config/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/config/sponsoring.rs
+++ b/runtime/common/config/sponsoring.rs
@@ -16,16 +16,13 @@
use frame_support::parameter_types;
use crate::{
- runtime_common::{
- constants::*,
- sponsoring::UniqueSponsorshipHandler,
- },
- Runtime,
+ runtime_common::{constants::*, sponsoring::UniqueSponsorshipHandler},
+ Runtime,
};
use common_types::BlockNumber;
parameter_types! {
- pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;
+ pub const DefaultSponsoringRateLimit: BlockNumber = 1 * DAYS;
}
type SponsorshipHandler = (
runtime/common/config/substrate.rsdiffbeforeafterboth--- a/runtime/common/config/substrate.rs
+++ b/runtime/common/config/substrate.rs
@@ -18,11 +18,10 @@
traits::{Everything, ConstU32},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
- DispatchClass, WeightToFeePolynomial, WeightToFeeCoefficients,
- ConstantMultiplier, WeightToFeeCoefficient,
+ DispatchClass, WeightToFeePolynomial, WeightToFeeCoefficients, ConstantMultiplier,
+ WeightToFeeCoefficient,
},
- parameter_types,
- PalletId,
+ parameter_types, PalletId,
};
use sp_runtime::{
generic,
@@ -36,20 +35,8 @@
use sp_arithmetic::traits::{BaseArithmetic, Unsigned};
use smallvec::smallvec;
use crate::{
- runtime_common::{
- DealWithFees,
- constants::*,
- },
- Runtime,
- Event,
- Call,
- Origin,
- PalletInfo,
- System,
- Balances,
- Treasury,
- SS58Prefix,
- Version,
+ runtime_common::{DealWithFees, constants::*},
+ Runtime, Event, Call, Origin, PalletInfo, System, Balances, Treasury, SS58Prefix, Version,
};
use common_types::*;
runtime/common/config/xcm.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18 traits::{19 tokens::currency::Currency as CurrencyT,20 OnUnbalanced as OnUnbalancedT,21 Get, Everything22 },23 weights::{Weight, WeightToFeePolynomial, WeightToFee},24 parameter_types, match_types,25};26use frame_system::EnsureRoot;27use sp_runtime::{28 traits::{29 Saturating, CheckedConversion, Zero,30 },31 SaturatedConversion,32};33use pallet_xcm::XcmPassthrough;34use polkadot_parachain::primitives::Sibling;35use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};36use xcm::latest::{37 AssetId::{Concrete},38 Fungibility::Fungible as XcmFungible,39 MultiAsset,40 Error as XcmError,41};42use xcm_executor::traits::{MatchesFungible, WeightTrader};43use xcm_builder::{44 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,45 FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative,46 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,47 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, ParentIsPreset,48};49use xcm_executor::{Config, XcmExecutor, Assets};50use sp_std::marker::PhantomData;51use crate::{52 runtime_common::{53 constants::*,54 config::substrate::LinearFee55 },56 Runtime,57 Call,58 Event,59 Origin,60 Balances,61 ParachainInfo,62 ParachainSystem,63 PolkadotXcm,64 XcmpQueue,65};66use common_types::{AccountId, Balance};6768parameter_types! {69 pub const RelayLocation: MultiLocation = MultiLocation::parent();70 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;71 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();72 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();73}7475/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used76/// when determining ownership of accounts for asset transacting and when attempting to use XCM77/// `Transact` in order to determine the dispatch Origin.78pub type LocationToAccountId = (79 // The parent (Relay-chain) origin converts to the default `AccountId`.80 ParentIsPreset<AccountId>,81 // Sibling parachain origins convert to AccountId via the `ParaId::into`.82 SiblingParachainConvertsVia<Sibling, AccountId>,83 // Straight up local `AccountId32` origins just alias directly to `AccountId`.84 AccountId32Aliases<RelayNetwork, AccountId>,85);8687pub struct OnlySelfCurrency;88impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {89 fn matches_fungible(a: &MultiAsset) -> Option<B> {90 match (&a.id, &a.fun) {91 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),92 _ => None,93 }94 }95}9697/// Means for transacting assets on this chain.98pub type LocalAssetTransactor = CurrencyAdapter<99 // Use this currency:100 Balances,101 // Use this currency when it is a fungible asset matching the given location or name:102 OnlySelfCurrency,103 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:104 LocationToAccountId,105 // Our chain's account ID type (we can't get away without mentioning it explicitly):106 AccountId,107 // We don't track any teleports.108 (),109>;110111/// No local origins on this chain are allowed to dispatch XCM sends/executions.112pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);113114/// The means for routing XCM messages which are not for local execution into the right message115/// queues.116pub type XcmRouter = (117 // Two routers - use UMP to communicate with the relay chain:118 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,119 // ..and XCMP to communicate with the sibling chains.120 XcmpQueue,121);122123/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,124/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can125/// biases the kind of local `Origin` it will become.126pub type XcmOriginToTransactDispatchOrigin = (127 // Sovereign account converter; this attempts to derive an `AccountId` from the origin location128 // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for129 // foreign chains who want to have a local sovereign account on this chain which they control.130 SovereignSignedViaLocation<LocationToAccountId, Origin>,131 // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when132 // recognised.133 RelayChainAsNative<RelayOrigin, Origin>,134 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when135 // recognised.136 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,137 // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a138 // transaction from the Root origin.139 ParentAsSuperuser<Origin>,140 // Native signed account converter; this just converts an `AccountId32` origin into a normal141 // `Origin::Signed` origin of the same 32-byte value.142 SignedAccountId32AsNative<RelayNetwork, Origin>,143 // Xcm origins can be represented natively under the Xcm pallet's Xcm origin.144 XcmPassthrough<Origin>,145);146147parameter_types! {148 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.149 pub UnitWeightCost: Weight = 1_000_000;150 // 1200 UNIQUEs buy 1 second of weight.151 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);152 pub const MaxInstructions: u32 = 100;153}154155match_types! {156 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {157 MultiLocation { parents: 1, interior: Here } |158 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }159 };160}161162pub type Barrier = (163 TakeWeightCredit,164 AllowTopLevelPaidExecutionFrom<Everything>,165 // ^^^ Parent & its unit plurality gets free execution166);167168pub struct UsingOnlySelfCurrencyComponents<169 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,170 AssetId: Get<MultiLocation>,171 AccountId,172 Currency: CurrencyT<AccountId>,173 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,174>(175 Weight,176 Currency::Balance,177 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,178);179impl<180 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,181 AssetId: Get<MultiLocation>,182 AccountId,183 Currency: CurrencyT<AccountId>,184 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,185 > WeightTrader186 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>187{188 fn new() -> Self {189 Self(0, Zero::zero(), PhantomData)190 }191192 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {193 let amount = WeightToFee::weight_to_fee(&weight);194 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;195196 // location to this parachain through relay chain197 let option1: xcm::v1::AssetId = Concrete(MultiLocation {198 parents: 1,199 interior: X1(Parachain(ParachainInfo::parachain_id().into())),200 });201 // direct location202 let option2: xcm::v1::AssetId = Concrete(MultiLocation {203 parents: 0,204 interior: Here,205 });206207 let required = if payment.fungible.contains_key(&option1) {208 (option1, u128_amount).into()209 } else if payment.fungible.contains_key(&option2) {210 (option2, u128_amount).into()211 } else {212 (Concrete(MultiLocation::default()), u128_amount).into()213 };214215 let unused = payment216 .checked_sub(required)217 .map_err(|_| XcmError::TooExpensive)?;218 self.0 = self.0.saturating_add(weight);219 self.1 = self.1.saturating_add(amount);220 Ok(unused)221 }222223 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {224 let weight = weight.min(self.0);225 let amount = WeightToFee::weight_to_fee(&weight);226 self.0 -= weight;227 self.1 = self.1.saturating_sub(amount);228 let amount: u128 = amount.saturated_into();229 if amount > 0 {230 Some((AssetId::get(), amount).into())231 } else {232 None233 }234 }235}236impl<237 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,238 AssetId: Get<MultiLocation>,239 AccountId,240 Currency: CurrencyT<AccountId>,241 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,242 > Drop243 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>244{245 fn drop(&mut self) {246 OnUnbalanced::on_unbalanced(Currency::issue(self.1));247 }248}249250pub struct XcmConfig;251impl Config for XcmConfig {252 type Call = Call;253 type XcmSender = XcmRouter;254 // How to withdraw and deposit an asset.255 type AssetTransactor = LocalAssetTransactor;256 type OriginConverter = XcmOriginToTransactDispatchOrigin;257 type IsReserve = NativeAsset;258 type IsTeleporter = (); // Teleportation is disabled259 type LocationInverter = LocationInverter<Ancestry>;260 type Barrier = Barrier;261 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;262 type Trader =263 UsingOnlySelfCurrencyComponents<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;264 type ResponseHandler = (); // Don't handle responses for now.265 type SubscriptionService = PolkadotXcm;266267 type AssetTrap = PolkadotXcm;268 type AssetClaims = PolkadotXcm;269}270271impl pallet_xcm::Config for Runtime {272 type Event = Event;273 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;274 type XcmRouter = XcmRouter;275 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;276 type XcmExecuteFilter = Everything;277 type XcmExecutor = XcmExecutor<XcmConfig>;278 type XcmTeleportFilter = Everything;279 type XcmReserveTransferFilter = Everything;280 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;281 type LocationInverter = LocationInverter<Ancestry>;282 type Origin = Origin;283 type Call = Call;284 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;285 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;286}287288impl cumulus_pallet_xcm::Config for Runtime {289 type Event = Event;290 type XcmExecutor = XcmExecutor<XcmConfig>;291}292293impl cumulus_pallet_xcmp_queue::Config for Runtime {294 type WeightInfo = ();295 type Event = Event;296 type XcmExecutor = XcmExecutor<XcmConfig>;297 type ChannelInfo = ParachainSystem;298 type VersionWrapper = ();299 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;300 type ControllerOrigin = EnsureRoot<AccountId>;301 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;302}303304impl cumulus_pallet_dmp_queue::Config for Runtime {305 type Event = Event;306 type XcmExecutor = XcmExecutor<XcmConfig>;307 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;308}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use frame_support::{18 traits::{19 tokens::currency::Currency as CurrencyT, OnUnbalanced as OnUnbalancedT, Get, Everything,20 },21 weights::{Weight, WeightToFeePolynomial, WeightToFee},22 parameter_types, match_types,23};24use frame_system::EnsureRoot;25use sp_runtime::{26 traits::{Saturating, CheckedConversion, Zero},27 SaturatedConversion,28};29use pallet_xcm::XcmPassthrough;30use polkadot_parachain::primitives::Sibling;31use xcm::v1::{BodyId, Junction::*, MultiLocation, NetworkId, Junctions::*};32use xcm::latest::{33 AssetId::{Concrete},34 Fungibility::Fungible as XcmFungible,35 MultiAsset, Error as XcmError,36};37use xcm_executor::traits::{MatchesFungible, WeightTrader};38use xcm_builder::{39 AccountId32Aliases, AllowTopLevelPaidExecutionFrom, CurrencyAdapter, EnsureXcmOrigin,40 FixedWeightBounds, LocationInverter, NativeAsset, ParentAsSuperuser, RelayChainAsNative,41 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,42 SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, ParentIsPreset,43};44use xcm_executor::{Config, XcmExecutor, Assets};45use sp_std::marker::PhantomData;46use crate::{47 runtime_common::{constants::*, config::substrate::LinearFee},48 Runtime, Call, Event, Origin, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, XcmpQueue,49};50use common_types::{AccountId, Balance};5152parameter_types! {53 pub const RelayLocation: MultiLocation = MultiLocation::parent();54 pub const RelayNetwork: NetworkId = NetworkId::Polkadot;55 pub RelayOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();56 pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();57}5859/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used60/// when determining ownership of accounts for asset transacting and when attempting to use XCM61/// `Transact` in order to determine the dispatch Origin.62pub type LocationToAccountId = (63 // The parent (Relay-chain) origin converts to the default `AccountId`.64 ParentIsPreset<AccountId>,65 // Sibling parachain origins convert to AccountId via the `ParaId::into`.66 SiblingParachainConvertsVia<Sibling, AccountId>,67 // Straight up local `AccountId32` origins just alias directly to `AccountId`.68 AccountId32Aliases<RelayNetwork, AccountId>,69);7071pub struct OnlySelfCurrency;72impl<B: TryFrom<u128>> MatchesFungible<B> for OnlySelfCurrency {73 fn matches_fungible(a: &MultiAsset) -> Option<B> {74 match (&a.id, &a.fun) {75 (Concrete(_), XcmFungible(ref amount)) => CheckedConversion::checked_from(*amount),76 _ => None,77 }78 }79}8081/// Means for transacting assets on this chain.82pub type LocalAssetTransactor = CurrencyAdapter<83 // Use this currency:84 Balances,85 // Use this currency when it is a fungible asset matching the given location or name:86 OnlySelfCurrency,87 // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:88 LocationToAccountId,89 // Our chain's account ID type (we can't get away without mentioning it explicitly):90 AccountId,91 // We don't track any teleports.92 (),93>;9495/// No local origins on this chain are allowed to dispatch XCM sends/executions.96pub type LocalOriginToLocation = (SignedToAccountId32<Origin, AccountId, RelayNetwork>,);9798/// The means for routing XCM messages which are not for local execution into the right message99/// queues.100pub type XcmRouter = (101 // Two routers - use UMP to communicate with the relay chain:102 cumulus_primitives_utility::ParentAsUmp<ParachainSystem, ()>,103 // ..and XCMP to communicate with the sibling chains.104 XcmpQueue,105);106107/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,108/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can109/// biases the kind of local `Origin` it will become.110pub type XcmOriginToTransactDispatchOrigin = (111 // Sovereign account converter; this attempts to derive an `AccountId` from the origin location112 // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for113 // foreign chains who want to have a local sovereign account on this chain which they control.114 SovereignSignedViaLocation<LocationToAccountId, Origin>,115 // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when116 // recognised.117 RelayChainAsNative<RelayOrigin, Origin>,118 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when119 // recognised.120 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, Origin>,121 // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a122 // transaction from the Root origin.123 ParentAsSuperuser<Origin>,124 // Native signed account converter; this just converts an `AccountId32` origin into a normal125 // `Origin::Signed` origin of the same 32-byte value.126 SignedAccountId32AsNative<RelayNetwork, Origin>,127 // Xcm origins can be represented natively under the Xcm pallet's Xcm origin.128 XcmPassthrough<Origin>,129);130131parameter_types! {132 // One XCM operation is 1_000_000 weight - almost certainly a conservative estimate.133 pub UnitWeightCost: Weight = 1_000_000;134 // 1200 UNIQUEs buy 1 second of weight.135 pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), 1_200 * UNIQUE);136 pub const MaxInstructions: u32 = 100;137}138139match_types! {140 pub type ParentOrParentsUnitPlurality: impl Contains<MultiLocation> = {141 MultiLocation { parents: 1, interior: Here } |142 MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Unit, .. }) }143 };144}145146pub type Barrier = (147 TakeWeightCredit,148 AllowTopLevelPaidExecutionFrom<Everything>,149 // ^^^ Parent & its unit plurality gets free execution150);151152pub struct UsingOnlySelfCurrencyComponents<153 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,154 AssetId: Get<MultiLocation>,155 AccountId,156 Currency: CurrencyT<AccountId>,157 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,158>(159 Weight,160 Currency::Balance,161 PhantomData<(WeightToFee, AssetId, AccountId, Currency, OnUnbalanced)>,162);163impl<164 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,165 AssetId: Get<MultiLocation>,166 AccountId,167 Currency: CurrencyT<AccountId>,168 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,169 > WeightTrader170 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>171{172 fn new() -> Self {173 Self(0, Zero::zero(), PhantomData)174 }175176 fn buy_weight(&mut self, weight: Weight, payment: Assets) -> Result<Assets, XcmError> {177 let amount = WeightToFee::weight_to_fee(&weight);178 let u128_amount: u128 = amount.try_into().map_err(|_| XcmError::Overflow)?;179180 // location to this parachain through relay chain181 let option1: xcm::v1::AssetId = Concrete(MultiLocation {182 parents: 1,183 interior: X1(Parachain(ParachainInfo::parachain_id().into())),184 });185 // direct location186 let option2: xcm::v1::AssetId = Concrete(MultiLocation {187 parents: 0,188 interior: Here,189 });190191 let required = if payment.fungible.contains_key(&option1) {192 (option1, u128_amount).into()193 } else if payment.fungible.contains_key(&option2) {194 (option2, u128_amount).into()195 } else {196 (Concrete(MultiLocation::default()), u128_amount).into()197 };198199 let unused = payment200 .checked_sub(required)201 .map_err(|_| XcmError::TooExpensive)?;202 self.0 = self.0.saturating_add(weight);203 self.1 = self.1.saturating_add(amount);204 Ok(unused)205 }206207 fn refund_weight(&mut self, weight: Weight) -> Option<MultiAsset> {208 let weight = weight.min(self.0);209 let amount = WeightToFee::weight_to_fee(&weight);210 self.0 -= weight;211 self.1 = self.1.saturating_sub(amount);212 let amount: u128 = amount.saturated_into();213 if amount > 0 {214 Some((AssetId::get(), amount).into())215 } else {216 None217 }218 }219}220impl<221 WeightToFee: WeightToFeePolynomial<Balance = Currency::Balance>,222 AssetId: Get<MultiLocation>,223 AccountId,224 Currency: CurrencyT<AccountId>,225 OnUnbalanced: OnUnbalancedT<Currency::NegativeImbalance>,226 > Drop227 for UsingOnlySelfCurrencyComponents<WeightToFee, AssetId, AccountId, Currency, OnUnbalanced>228{229 fn drop(&mut self) {230 OnUnbalanced::on_unbalanced(Currency::issue(self.1));231 }232}233234pub struct XcmConfig;235impl Config for XcmConfig {236 type Call = Call;237 type XcmSender = XcmRouter;238 // How to withdraw and deposit an asset.239 type AssetTransactor = LocalAssetTransactor;240 type OriginConverter = XcmOriginToTransactDispatchOrigin;241 type IsReserve = NativeAsset;242 type IsTeleporter = (); // Teleportation is disabled243 type LocationInverter = LocationInverter<Ancestry>;244 type Barrier = Barrier;245 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;246 type Trader =247 UsingOnlySelfCurrencyComponents<LinearFee<Balance>, RelayLocation, AccountId, Balances, ()>;248 type ResponseHandler = (); // Don't handle responses for now.249 type SubscriptionService = PolkadotXcm;250251 type AssetTrap = PolkadotXcm;252 type AssetClaims = PolkadotXcm;253}254255impl pallet_xcm::Config for Runtime {256 type Event = Event;257 type SendXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;258 type XcmRouter = XcmRouter;259 type ExecuteXcmOrigin = EnsureXcmOrigin<Origin, LocalOriginToLocation>;260 type XcmExecuteFilter = Everything;261 type XcmExecutor = XcmExecutor<XcmConfig>;262 type XcmTeleportFilter = Everything;263 type XcmReserveTransferFilter = Everything;264 type Weigher = FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;265 type LocationInverter = LocationInverter<Ancestry>;266 type Origin = Origin;267 type Call = Call;268 const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100;269 type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion;270}271272impl cumulus_pallet_xcm::Config for Runtime {273 type Event = Event;274 type XcmExecutor = XcmExecutor<XcmConfig>;275}276277impl cumulus_pallet_xcmp_queue::Config for Runtime {278 type WeightInfo = ();279 type Event = Event;280 type XcmExecutor = XcmExecutor<XcmConfig>;281 type ChannelInfo = ParachainSystem;282 type VersionWrapper = ();283 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;284 type ControllerOrigin = EnsureRoot<AccountId>;285 type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin;286}287288impl cumulus_pallet_dmp_queue::Config for Runtime {289 type Event = Event;290 type XcmExecutor = XcmExecutor<XcmConfig>;291 type ExecuteOverweightOrigin = frame_system::EnsureRoot<AccountId>;292}runtime/common/ethereum/mod.rsdiffbeforeafterboth--- a/runtime/common/ethereum/mod.rs
+++ b/runtime/common/ethereum/mod.rs
@@ -14,6 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+pub mod self_contained_call;
pub mod sponsoring;
pub mod transaction_converter;
-pub mod self_contained_call;
runtime/common/ethereum/self_contained_call.rsdiffbeforeafterboth--- a/runtime/common/ethereum/self_contained_call.rs
+++ b/runtime/common/ethereum/self_contained_call.rs
@@ -16,8 +16,8 @@
use sp_core::H160;
use sp_runtime::{
- traits::{Dispatchable, DispatchInfoOf, PostDispatchInfoOf},
- transaction_validity::{TransactionValidityError, TransactionValidity},
+ traits::{Dispatchable, DispatchInfoOf, PostDispatchInfoOf},
+ transaction_validity::{TransactionValidityError, TransactionValidity},
};
use crate::{Origin, Call};
runtime/common/ethereum/sponsoring.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring.rs
+++ b/runtime/common/ethereum/sponsoring.rs
@@ -27,10 +27,7 @@
use up_data_structs::{TokenId, CreateItemData, CreateNftData, CollectionMode};
use pallet_unique::Config as UniqueConfig;
-use crate::{
- Runtime,
- runtime_common::sponsoring::*
-};
+use crate::{Runtime, runtime_common::sponsoring::*};
use pallet_nonfungible::erc::{
UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721MintableCall, ERC721Call, TokenPropertiesCall,
runtime/common/ethereum/transaction_converter.rsdiffbeforeafterboth--- a/runtime/common/ethereum/transaction_converter.rs
+++ b/runtime/common/ethereum/transaction_converter.rs
@@ -15,11 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use codec::{Encode, Decode};
-use crate::{
- opaque,
- Runtime,
- UncheckedExtrinsic,
-};
+use crate::{opaque, Runtime, UncheckedExtrinsic};
pub struct TransactionConverter;
runtime/common/instance.rsdiffbeforeafterboth--- a/runtime/common/instance.rs
+++ b/runtime/common/instance.rs
@@ -1,9 +1,8 @@
use crate::{
- runtime_common::{
- config::ethereum::CrossAccountId,
- ethereum::transaction_converter::TransactionConverter
- },
- Runtime,
+ runtime_common::{
+ config::ethereum::CrossAccountId, ethereum::transaction_converter::TransactionConverter,
+ },
+ Runtime,
};
use common_types::opaque::RuntimeInstance;
runtime/common/mod.rsdiffbeforeafterboth--- a/runtime/common/mod.rs
+++ b/runtime/common/mod.rs
@@ -14,23 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+pub mod config;
pub mod constants;
pub mod construct_runtime;
pub mod dispatch;
+pub mod ethereum;
+pub mod instance;
pub mod runtime_apis;
+pub mod scheduler;
pub mod sponsoring;
pub mod weights;
-pub mod config;
-pub mod instance;
-pub mod ethereum;
-pub mod scheduler;
use sp_core::H160;
use frame_support::traits::{Currency, OnUnbalanced, Imbalance};
use sp_runtime::{
- generic,
- traits::{BlakeTwo256, BlockNumberProvider},
- impl_opaque_keys,
+ generic,
+ traits::{BlakeTwo256, BlockNumberProvider},
+ impl_opaque_keys,
};
use sp_std::vec::Vec;
@@ -38,7 +38,7 @@
use sp_version::NativeVersion;
use crate::{
- Runtime, Call, Balances, Treasury, Aura, Signature, AllPalletsReversedWithSystemFirst,
+ Runtime, Call, Balances, Treasury, Aura, Signature, AllPalletsReversedWithSystemFirst,
InherentDataExt,
};
use common_types::{AccountId, BlockNumber};
runtime/common/scheduler.rsdiffbeforeafterboth--- a/runtime/common/scheduler.rs
+++ b/runtime/common/scheduler.rs
@@ -15,19 +15,16 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
use frame_support::{
- traits::NamedReservableCurrency,
- weights::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},
+ traits::NamedReservableCurrency,
+ weights::{GetDispatchInfo, PostDispatchInfo, DispatchInfo},
};
use sp_runtime::{
- traits::{Dispatchable, Applyable, Member},
+ traits::{Dispatchable, Applyable, Member},
generic::Era,
- transaction_validity::TransactionValidityError,
+ transaction_validity::TransactionValidityError,
DispatchErrorWithPostInfo, DispatchError,
-};
-use crate::{
- Runtime, Call, Origin, Balances,
- ChargeTransactionPayment,
};
+use crate::{Runtime, Call, Origin, Balances, ChargeTransactionPayment};
use common_types::{AccountId, Balance};
use fp_self_contained::SelfContainedCall;
use pallet_unique_scheduler::DispatchCall;
@@ -85,11 +82,11 @@
SignedExtraScheduler,
SelfContainedSignedInfo,
> {
- signed:
- fp_self_contained::CheckedSignature::<AccountId, SignedExtraScheduler, SelfContainedSignedInfo>::Signed(
- signer.clone().into(),
- get_signed_extras(signer.into()),
- ),
+ signed: fp_self_contained::CheckedSignature::<
+ AccountId,
+ SignedExtraScheduler,
+ SelfContainedSignedInfo,
+ >::Signed(signer.clone().into(), get_signed_extras(signer.into())),
function: call.into(),
};