Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add MOVR cross chain transferring to moonriver
  • Loading branch information
girazoki committed Jan 31, 2022
commit b27c5872050eb094e14113b72bf0fd09a1929270
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.

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
14 changes: 9 additions & 5 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use frame_support::{
},
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 = 50 * KILOWEI * SUPPLY_FACTOR;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do some basic testing to ensure this is reasonable for your use case. It appears to be taken from #1218, which is still a WIP.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right in the sense that a token transfer through XCM would cost 50_000_000_000_000, or essentially, 50microMOVR. Maybe this is too low since for KSM we are charging 0.1KSM. I will increase it to match it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I increased it to 100KILOWEI. This means that for 1e9 weight (roughly, the amount needed for a token transfer in XCM) we charge 0.1milliMOVR, which I think gets us closer to what we charge for other assets


pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 1 * MOVR * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE
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>;
15 changes: 9 additions & 6 deletions runtime/moonriver/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ use xcm::latest::{
};
use xcm_builder::{
AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom,
AllowTopLevelPaidExecutionFrom, ConvertedConcreteAssetId, EnsureXcmOrigin, FixedWeightBounds,
AllowTopLevelPaidExecutionFrom, ConvertedConcreteAssetId,
CurrencyAdapter as XcmCurrencyAdapter, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds,
FungiblesAdapter, LocationInverter, ParentAsSuperuser, ParentIsDefault, RelayChainAsNative,
SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountKey20AsNative,
SovereignSignedViaLocation, TakeWeightCredit,
Expand Down Expand Up @@ -262,12 +263,13 @@ parameter_types! {
// 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)
// 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)
Parachain(MsgQueue::parachain_id().into()),
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8
)
)
};
// Bew Self Reserve location, defines the multilocation identifiying the self-reserve currency
Expand All @@ -277,10 +279,11 @@ parameter_types! {
pub NewAnchoringSelfReserve: MultiLocation = MultiLocation {
parents:0,
interior: Junctions::X1(
PalletInstance(<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() as u8)
PalletInstance(
<Runtime as frame_system::Config>::PalletInfo::index::<Balances>().unwrap() 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![
Expand Down
12 changes: 3 additions & 9 deletions runtime/moonriver/tests/xcm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,17 @@

mod xcm_mock;
use frame_support::{
assert_noop, assert_ok,
assert_ok,
traits::{PalletInfo, PalletInfoAccess},
weights::constants::WEIGHT_PER_SECOND,
};
use xcm::latest::prelude::*;
use xcm::{VersionedMultiLocation, WrapVersion};
use xcm_executor::traits::Convert;
use xcm_mock::parachain;
use xcm_mock::relay_chain;
use xcm_mock::*;
use xcm_primitives::UtilityEncodeCall;

use xcm::latest::prelude::QueryResponse;
use xcm::latest::{
Junction::{self, AccountId32, AccountKey20, PalletInstance, Parachain},
Junctions::*,
MultiLocation, NetworkId, Response, Xcm,
};
use xcm_executor::traits::Convert;
use xcm_simulator::TestExt;

// Send a relay asset (like DOT) to a parachain A
Expand Down