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 auction/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

pub struct Handler;
Expand Down
1 change: 1 addition & 0 deletions authority/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions benchmarking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl frame_system::Config for Test {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

impl tests::test::Config for Test {
Expand Down
1 change: 1 addition & 0 deletions currencies/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

type CurrencyId = u32;
Expand Down
1 change: 1 addition & 0 deletions gradually-update/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions nft/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

impl Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions oracle/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl frame_system::Config for Test {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

thread_local! {
Expand Down
1 change: 1 addition & 0 deletions rewards/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

thread_local! {
Expand Down
1 change: 1 addition & 0 deletions tokens/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

thread_local! {
Expand Down
2 changes: 2 additions & 0 deletions traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ num-traits = { version = "0.2.14", default-features = false }
impl-trait-for-tuples = "0.2.1"
frame-support = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1", default-features = false }
orml-utilities = { path = "../utilities", version = "0.4.1-dev", default-features = false }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1", default-features = false }

funty = { version = "=1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105

Expand All @@ -31,4 +32,5 @@ std = [
"num-traits/std",
"frame-support/std",
"orml-utilities/std",
"xcm/std",
]
1 change: 1 addition & 0 deletions traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod auction;
pub mod currency;
pub mod data_provider;
pub mod get_by_key;
pub mod location;
pub mod nft;
pub mod price;
pub mod rewards;
Expand Down
123 changes: 123 additions & 0 deletions traits/src/location.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use xcm::v0::{
Junction::{self, *},
MultiAsset, MultiLocation,
};

pub trait Parse {
/// Returns the "chain" location part. It could be parent, sibling
/// parachain, or child parachain.
fn chain_part(&self) -> Option<MultiLocation>;
/// Returns "non-chain" location part.
fn non_chain_part(&self) -> Option<MultiLocation>;
}

fn is_chain_junction(junction: Option<&Junction>) -> bool {
matches!(junction, Some(Parent) | Some(Parachain { id: _ }))
}

impl Parse for MultiLocation {
fn chain_part(&self) -> Option<MultiLocation> {
match (self.first(), self.at(1)) {
(Some(Parent), Some(Parachain { id })) => Some((Parent, Parachain { id: *id }).into()),
(Some(Parent), _) => Some(Parent.into()),
(Some(Parachain { id }), _) => Some(Parachain { id: *id }.into()),
_ => None,
}
}

fn non_chain_part(&self) -> Option<MultiLocation> {
let mut location = self.clone();
while is_chain_junction(location.first()) {
let _ = location.take_first();
}

if location != MultiLocation::Null {
Some(location)
} else {
None
}
}
}

pub trait Reserve {
/// Returns assets reserve location.
fn reserve(&self) -> Option<MultiLocation>;
}

impl Reserve for MultiAsset {
fn reserve(&self) -> Option<MultiLocation> {
if let MultiAsset::ConcreteFungible { id, .. } = self {
id.chain_part()
} else {
None
}
}
}

#[cfg(test)]
mod tests {
use super::*;

const PARACHAIN: Junction = Parachain { id: 1 };
const GENERAL_INDEX: Junction = GeneralIndex { id: 1 };

fn concrete_fungible(id: MultiLocation) -> MultiAsset {
MultiAsset::ConcreteFungible { id, amount: 1 }
}

#[test]
fn parent_as_reserve_chain() {
assert_eq!(
concrete_fungible(MultiLocation::X2(Parent, GENERAL_INDEX)).reserve(),
Some(Parent.into())
);
}

#[test]
fn sibling_parachain_as_reserve_chain() {
assert_eq!(
concrete_fungible(MultiLocation::X3(Parent, PARACHAIN, GENERAL_INDEX)).reserve(),
Some((Parent, PARACHAIN).into())
);
}

#[test]
fn child_parachain_as_reserve_chain() {
assert_eq!(
concrete_fungible(MultiLocation::X2(PARACHAIN, GENERAL_INDEX)).reserve(),
Some(PARACHAIN.into())
);
}

#[test]
fn no_reserve_chain() {
assert_eq!(
concrete_fungible(MultiLocation::X1(GeneralKey("DOT".into()))).reserve(),
None
);
}

#[test]
fn non_chain_part_works() {
assert_eq!(MultiLocation::X1(Parent).non_chain_part(), None);
assert_eq!(MultiLocation::X2(Parent, PARACHAIN).non_chain_part(), None);
assert_eq!(MultiLocation::X1(PARACHAIN).non_chain_part(), None);

assert_eq!(
MultiLocation::X2(Parent, GENERAL_INDEX).non_chain_part(),
Some(GENERAL_INDEX.into())
);
assert_eq!(
MultiLocation::X3(Parent, GENERAL_INDEX, GENERAL_INDEX).non_chain_part(),
Some((GENERAL_INDEX, GENERAL_INDEX).into())
);
assert_eq!(
MultiLocation::X3(Parent, PARACHAIN, GENERAL_INDEX).non_chain_part(),
Some(GENERAL_INDEX.into())
);
assert_eq!(
MultiLocation::X2(PARACHAIN, GENERAL_INDEX).non_chain_part(),
Some(GENERAL_INDEX.into())
);
}
}
1 change: 1 addition & 0 deletions unknown-tokens/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

impl Config for Runtime {
Expand Down
2 changes: 0 additions & 2 deletions unknown-tokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use super::*;
use mock::{Event, *};

use codec::{Decode, Encode};

use frame_support::{assert_err, assert_ok};
use xcm::v0::Junction;

Expand Down
1 change: 1 addition & 0 deletions vesting/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
}

type Balance = u64;
Expand Down
16 changes: 16 additions & 0 deletions xcm-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use sp_std::{
use xcm::v0::{Junction, MultiAsset, MultiLocation, Xcm};
use xcm_executor::traits::{FilterAssetLocation, MatchesFungible, NativeAsset};

use orml_traits::location::Reserve;

pub use currency_adapter::MultiCurrencyAdapter;

mod currency_adapter;
Expand Down Expand Up @@ -90,6 +92,20 @@ impl<Pairs: Get<BTreeSet<(Vec<u8>, MultiLocation)>>> FilterAssetLocation for Nat
}
}

/// A `FilterAssetLocation` implementation. Filters multi native assets whose
/// reserve is same with `origin`.
pub struct MultiNativeAsset;
impl FilterAssetLocation for MultiNativeAsset {
fn filter_asset_location(asset: &MultiAsset, origin: &MultiLocation) -> bool {
if let Some(ref reserve) = asset.reserve() {
if reserve == origin {
return true;
}
}
false
}
}

/// `CurrencyIdConversion` implementation. Converts relay chain tokens, or
/// parachain tokens that could be decoded from a general key.
pub struct CurrencyIdConverter<CurrencyId, RelayChainCurrencyId>(
Expand Down
11 changes: 11 additions & 0 deletions xtokens/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branc
xcm = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1", default-features = false }

orml-xcm-support = { path = "../xcm-support", default-features = false }
orml-traits = { path = "../traits", default-features = false}

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
xcm-simulator = { git = "https://github.com/shaunxw/xcm-simulator", branch = "master" }
cumulus-pallet-xcm-handler = { git = "https://github.com/paritytech/cumulus", branch = "rococo-v1" }
parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "rococo-v1" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", branch = "rococo-v1" }

orml-tokens = { path = "../tokens", version = "0.4.1-dev" }
orml-traits = { path = "../traits", version = "0.4.1-dev" }

[features]
default = ["std"]
Expand All @@ -41,4 +51,5 @@ std = [
"cumulus-primitives-core/std",
"xcm/std",
"orml-xcm-support/std",
"orml-traits/std",
]
Loading