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
1 change: 1 addition & 0 deletions Cargo.lock

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

20 changes: 9 additions & 11 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
traits::{
Contains, Currency as CurrencyT, EnsureOneOf, EqualPrivilegeOnly, Everything, FindAuthor,
Get, Imbalance, InstanceFilter, Nothing, OffchainWorker, OnFinalize, OnIdle, OnInitialize,
OnRuntimeUpgrade, OnUnbalanced, PalletInfo as PalletInfoTrait,
OnRuntimeUpgrade, OnUnbalanced, PalletInfoAccess,
},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
Expand Down Expand Up @@ -1019,19 +1019,17 @@ parameter_types! {
parents:1,
interior: Junctions::X2(
Parachain(ParachainInfo::parachain_id().into()),
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
// Bew Self Reserve location, defines the multilocation identifiying the self-reserve currency
// New Self Reserve location, defines the multilocation identifiying the self-reserve currency
// This is used to match it also against our Balances pallet when we receive such
// a MultiLocation: (Self Balances pallet index)
// This is the new anchoring way
pub NewAnchoringSelfReserve: MultiLocation = MultiLocation {
parents:0,
interior: Junctions::X1(
PalletInstance(<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};

Expand Down Expand Up @@ -1447,11 +1445,11 @@ where
{
fn convert(currency: CurrencyId) -> Option<MultiLocation> {
match currency {
// For now (and until we upgrade to 0.9.16 is adapted) we need to use the old anchoring
// here
// This is not a problem in either cases, since the view of the destination chain
// does not change
// TODO! change this to NewAnchoringSelfReserve once we uprade to 0.9.16
// For now and until Xtokens is adapted to handle 0.9.16 version we use
// the old anchoring here
// This is not a problem in either cases, since the view of the destination
// chain does not change
// TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it
CurrencyId::SelfReserve => {
let multi: MultiLocation = OldAnchoringSelfReserve::get();
Some(multi)
Expand Down
16 changes: 6 additions & 10 deletions runtime/moonbase/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, Get, Nothing, PalletInfo as PalletInfoTrait},
traits::{Everything, Get, Nothing, PalletInfoAccess},
weights::Weight,
PalletId,
};
Expand Down Expand Up @@ -271,21 +271,17 @@ parameter_types! {
parents:1,
interior: Junctions::X2(
Parachain(MsgQueue::parachain_id().into()),
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
// Bew Self Reserve location, defines the multilocation identifiying the self-reserve currency
// New Self Reserve location, defines the multilocation identifiying the self-reserve currency
// This is used to match it also against our Balances pallet when we receive such
// a MultiLocation: (Self Balances pallet index)
// This is the new anchoring way
pub NewAnchoringSelfReserve: MultiLocation = MultiLocation {
parents:0,
interior: Junctions::X1(
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
// The Locations we accept to refer to our own currency. We need to support both pre and
Expand Down Expand Up @@ -344,11 +340,11 @@ where
fn convert(currency: CurrencyId) -> Option<MultiLocation> {
match currency {
CurrencyId::SelfReserve => {
// For now (and until we upgrade to 0.9.16 is adapted) we need to use
// For now and until Xtokens is adapted to handle 0.9.16 version we use
// the old anchoring here
// This is not a problem in either cases, since the view of the destination
// chain does not change
// TODO! change this to NewAnchoringSelfReserve once we uprade to 0.9.16
// TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it
let multi: MultiLocation = OldAnchoringSelfReserve::get();
Some(multi)
}
Expand Down
6 changes: 2 additions & 4 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
traits::{
Contains, EnsureOneOf, EqualPrivilegeOnly, Everything, Get, Imbalance, InstanceFilter,
Nothing, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade, OnUnbalanced,
PalletInfo as PalletInfoTrait,
PalletInfoAccess,
},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
Expand Down Expand Up @@ -943,9 +943,7 @@ parameter_types! {
parents:1,
interior: Junctions::X2(
Parachain(ParachainInfo::parachain_id().into()),
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use frame_support::{
construct_runtime, parameter_types,
traits::{Everything, Get, Nothing, PalletInfo as PalletInfoTrait},
traits::{Everything, Get, Nothing, PalletInfoAccess},
weights::Weight,
PalletId,
};
Expand Down Expand Up @@ -244,7 +244,7 @@ parameter_types! {
parents:1,
interior: Junctions::X2(
Parachain(MsgQueue::parachain_id().into()),
PalletInstance(<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
}
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ log = "0.4"
rlp = { version = "0.5", optional = true, default-features = false }
serde = { version = "1.0.101", optional = true, default-features = false, features = [ "derive" ] }
sha3 = { version = "0.8", optional = true, default-features = false }
smallvec = "1.8.0"

# Moonbeam
account = { path = "../../primitives/account/", default-features = false }
Expand Down
108 changes: 94 additions & 14 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ use frame_support::{
traits::{
Contains, EnsureOneOf, EqualPrivilegeOnly, Everything, Get, Imbalance, InstanceFilter,
Nothing, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade, OnUnbalanced,
PalletInfo as PalletInfoTrait,
PalletInfoAccess,
},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
DispatchClass, GetDispatchInfo, IdentityFee, Weight,
DispatchClass, GetDispatchInfo, IdentityFee, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
},
PalletId,
};
Expand Down Expand Up @@ -82,16 +83,18 @@ use sp_std::{convert::TryFrom, prelude::*};

use xcm_builder::{
AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, FixedWeightBounds,
FungiblesAdapter, LocationInverter, ParentIsDefault, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative,
SovereignSignedViaLocation, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom, ConvertedConcreteAssetId,
CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedWeightBounds, FungiblesAdapter,
LocationInverter, ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation,
TakeWeightCredit, UsingComponents,
};

use xcm_executor::traits::JustTry;

use xcm::latest::prelude::*;

use smallvec::smallvec;
use xcm_primitives::{
AccountIdToCurrencyId, AccountIdToMultiLocation, AsAssetType, FirstAssetTrader,
MultiNativeAsset, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact,
Expand Down Expand Up @@ -132,6 +135,7 @@ pub mod currency {

pub const TRANSACTION_BYTE_FEE: Balance = 10 * MICROMOVR * SUPPLY_FACTOR;
pub const STORAGE_BYTE_FEE: Balance = 100 * MICROMOVR * SUPPLY_FACTOR;
pub const WEIGHT_FEE: Balance = 100 * KILOWEI * SUPPLY_FACTOR;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 1 * MOVR * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE
Expand Down Expand Up @@ -316,6 +320,28 @@ parameter_types! {
pub OperationalFeeMultiplier: u8 = 5;
}

pub struct WeightToFee;
impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;

/// Return a vec of coefficients. Here we just use one coefficient and reduce it to a constant
/// modifier in order to closely match Ethereum-based fees.
///
/// Calculation, per the documentation in `frame_support`:
///
/// ```ignore
/// coeff_integer * x^(degree) + coeff_frac * x^(degree)
/// ```
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
smallvec![WeightToFeeCoefficient {
degree: 1,
coeff_frac: Perbill::zero(),
coeff_integer: currency::WEIGHT_FEE,
negative: false,
}]
}
}

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees<Runtime>>;
type TransactionByteFee = TransactionByteFee;
Expand Down Expand Up @@ -943,18 +969,34 @@ parameter_types! {
pub RelayChainOrigin: Origin = cumulus_pallet_xcm::Origin::Relay.into();
// The ancestry, defines the multilocation describing this consensus system
pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into();
// Self Reserve location, defines the multilocation identifiying the self-reserve currency
// Old Self Reserve location, defines the multilocation identifiying the self-reserve currency
// This is used to match it against our Balances pallet when we receive such a MultiLocation
// (Parent, Self Para Id, Self Balances pallet index)
pub SelfReserve: MultiLocation = MultiLocation {
// This is the old anchoring way
pub OldAnchoringSelfReserve: MultiLocation = MultiLocation {
parents:1,
interior: Junctions::X2(
Parachain(ParachainInfo::parachain_id().into()),
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};
// New Self Reserve location, defines the multilocation identifiying the self-reserve currency
// This is used to match it also against our Balances pallet when we receive such
// a MultiLocation: (Self Balances pallet index)
// This is the new anchoring way
pub NewAnchoringSelfReserve: MultiLocation = MultiLocation {
parents:0,
interior: Junctions::X1(
PalletInstance(<Balances as PalletInfoAccess>::index() as u8)
)
};

// The Locations we accept to refer to our own currency. We need to support both pre and
// post 0.9.16 versions, hence the reason for this being a Vec
pub SelfReserveRepresentations: Vec<MultiLocation> = vec![
OldAnchoringSelfReserve::get(),
NewAnchoringSelfReserve::get()
];
}

/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
Expand Down Expand Up @@ -993,10 +1035,24 @@ pub type FungiblesTransactor = FungiblesAdapter<
(),
>;

pub type LocalAssetTransactor = XcmCurrencyAdapter<
// Use this currency:
Balances,
// Use this currency when it is a fungible asset matching any of the locations in
// SelfReserveRepresentations
xcm_primitives::MultiIsConcrete<SelfReserveRepresentations>,
// We can convert the MultiLocations with our converter above:
LocationToAccountId,
// Our chain's account ID type (we can't get away without mentioning it explicitly):
AccountId,
// We dont allow teleport
(),
>;

// We use only fungiblesAdapter transactor for now
// The idea is that we only accept the relay token, hence no need to handle the local token
// As long as this does not contain the local transactor, we are good
pub type AssetTransactors = FungiblesTransactor;
pub type AssetTransactors = (LocalAssetTransactor, FungiblesTransactor);

/// 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
Expand Down Expand Up @@ -1073,9 +1129,28 @@ impl xcm_executor::Config for XcmExecutorConfig {
type LocationInverter = LocationInverter<Ancestry>;
type Barrier = XcmBarrier;
type Weigher = XcmWeigher;
// We use three traders
// When we receive either representation of the self-reserve asset,
// we use UsingComponents and the local way of handling fees
// When we receive a non-reserve asset, we use AssetManager to fetch how many
// units per second we should charge
type Trader = FirstAssetTrader<AssetType, AssetManager, XcmFeesToAccount>;
type Trader = (
UsingComponents<
WeightToFee,
OldAnchoringSelfReserve,
AccountId,
Balances,
DealWithFees<Runtime>,
>,
UsingComponents<
WeightToFee,
NewAnchoringSelfReserve,
AccountId,
Balances,
DealWithFees<Runtime>,
>,
FirstAssetTrader<AssetType, AssetManager, XcmFeesToAccount>,
);
type ResponseHandler = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
type AssetTrap = PolkadotXcm;
Expand Down Expand Up @@ -1349,8 +1424,13 @@ where
{
fn convert(currency: CurrencyId) -> Option<MultiLocation> {
match currency {
// For now and until Xtokens is adapted to handle 0.9.16 version we use
// the old anchoring here
// This is not a problem in either cases, since the view of the destination
// chain does not change
// TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it
CurrencyId::SelfReserve => {
let multi: MultiLocation = SelfReserve::get();
let multi: MultiLocation = OldAnchoringSelfReserve::get();
Some(multi)
}
CurrencyId::OtherReserve(asset) => AssetXConverter::reverse_ref(asset).ok(),
Expand Down
1 change: 1 addition & 0 deletions runtime/moonriver/tests/xcm_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,4 @@ pub type XTokens = orml_xtokens::Pallet<parachain::Runtime>;
pub type RelayBalances = pallet_balances::Pallet<relay_chain::Runtime>;
pub type ParaBalances = pallet_balances::Pallet<parachain::Runtime>;
pub type XcmTransactor = xcm_transactor::Pallet<parachain::Runtime>;
pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>;
Loading