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: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
- name: Update
run: |
cargo update
cargo update base64ct --precise 1.6.0 # 1.8.0 requires the Cargo feature called `edition2024`
cargo update pallet-revive-proc-macro --precise 0.3.0 # TODO: https://github.com/paritytech/polkadot-sdk/issues/9425
- name: Run clippy
run: cargo clippy -- -D warnings
Expand Down
11 changes: 5 additions & 6 deletions asset-registry/src/mock/para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ use frame_support::{
PalletId,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use orml_traits::{
location::{AbsoluteReserveProvider, RelativeReserveProvider},
parameter_type_with_key, FixedConversionRateProvider, MultiCurrency,
};
use orml_traits::{parameter_type_with_key, FixedConversionRateProvider, MultiCurrency};
use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
use orml_xtokens::{AbsoluteReserveProviderMigrationPhase, RelativeReserveProviderMigrationPhase};
use pallet_xcm::XcmPassthrough;
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use polkadot_parachain_primitives::primitives::Sibling;
Expand Down Expand Up @@ -212,7 +210,7 @@ impl Config for XcmConfig {
type XcmSender = XcmRouter;
type AssetTransactor = LocalAssetTransactor;
type OriginConverter = XcmOriginToCallOrigin;
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
type IsReserve = MultiNativeAsset<AbsoluteReserveProviderMigrationPhase<Runtime>>;
type IsTeleporter = ();
type UniversalLocation = UniversalLocation;
type Barrier = Barrier;
Expand Down Expand Up @@ -329,9 +327,10 @@ impl orml_xtokens::Config for Runtime {
type BaseXcmWeight = BaseXcmWeight;
type UniversalLocation = UniversalLocation;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
type ReserveProvider = RelativeReserveProvider;
type ReserveProvider = RelativeReserveProviderMigrationPhase<Runtime>;
type RateLimiter = ();
type RateLimiterId = ();
type MigrationPhaseUpdateOrigin = EnsureRoot<AccountId>;
}

impl orml_xcm::Config for Runtime {
Expand Down
154 changes: 1 addition & 153 deletions traits/src/location.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,13 @@
use sp_core::{bounded::BoundedVec, ConstU32};
use xcm::v5::prelude::*;

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

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

impl Parse for Location {
fn chain_part(&self) -> Option<Location> {
match (self.parents, self.first_interior()) {
// sibling parachain
(1, Some(Parachain(id))) => Some(Location::new(1, [Parachain(*id)])),
// parent
(1, _) => Some(Location::parent()),
// children parachain
(0, Some(Parachain(id))) => Some(Location::new(0, [Parachain(*id)])),
_ => None,
}
}

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

if junctions != Here {
Some(Location::new(0, junctions))
} else {
None
}
}
}
pub const ASSET_HUB_ID: u32 = 1000;

pub trait Reserve {
/// Returns assets reserve location.
fn reserve(asset: &Asset) -> Option<Location>;
}

// Provide reserve in absolute path view
pub struct AbsoluteReserveProvider;

impl Reserve for AbsoluteReserveProvider {
fn reserve(asset: &Asset) -> Option<Location> {
let AssetId(location) = &asset.id;
location.chain_part()
}
}

// Provide reserve in relative path view
// Self tokens are represeneted as Here
pub struct RelativeReserveProvider;

impl Reserve for RelativeReserveProvider {
fn reserve(asset: &Asset) -> Option<Location> {
let AssetId(location) = &asset.id;
if location.parents == 0 && !is_chain_junction(location.first_interior()) {
Some(Location::here())
} else {
location.chain_part()
}
}
}

pub trait RelativeLocations {
fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec<u8, ConstU32<32>>) -> Location;
}
Expand All @@ -79,93 +17,3 @@ impl RelativeLocations for Location {
Location::new(1, [Parachain(para_id), general_key.as_bounded_slice().into()])
}
}

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

const PARACHAIN: Junction = Parachain(1);
const GENERAL_INDEX: Junction = GeneralIndex(1);

fn concrete_fungible(id: Location) -> Asset {
(id, 1).into()
}

#[test]
fn parent_as_reserve_chain() {
assert_eq!(
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))),
Some(Location::parent())
);
assert_eq!(
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))),
Some(Location::parent())
);
}

#[test]
fn sibling_parachain_as_reserve_chain() {
assert_eq!(
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))),
Some(Location::new(1, [PARACHAIN]))
);
assert_eq!(
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))),
Some(Location::new(1, [PARACHAIN]))
);
}

#[test]
fn child_parachain_as_reserve_chain() {
assert_eq!(
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))),
Some(PARACHAIN.into())
);
assert_eq!(
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))),
Some(PARACHAIN.into())
);
}

#[test]
fn no_reserve_chain_for_absolute_self_for_relative() {
assert_eq!(
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(
0,
[Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())]
))),
None
);
assert_eq!(
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(
0,
[Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())]
))),
Some(Location::here())
);
}

#[test]
fn non_chain_part_works() {
assert_eq!(Location::parent().non_chain_part(), None);
assert_eq!(Location::new(1, [PARACHAIN]).non_chain_part(), None);
assert_eq!(Location::new(0, [PARACHAIN]).non_chain_part(), None);

assert_eq!(
Location::new(1, [GENERAL_INDEX]).non_chain_part(),
Some(GENERAL_INDEX.into())
);
assert_eq!(
Location::new(1, [GENERAL_INDEX, GENERAL_INDEX]).non_chain_part(),
Some((GENERAL_INDEX, GENERAL_INDEX).into())
);
assert_eq!(
Location::new(1, [PARACHAIN, GENERAL_INDEX]).non_chain_part(),
Some(GENERAL_INDEX.into())
);
assert_eq!(
Location::new(0, [PARACHAIN, GENERAL_INDEX]).non_chain_part(),
Some(GENERAL_INDEX.into())
);
}
}
21 changes: 1 addition & 20 deletions xcm-support/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use super::*;

use orml_traits::{location::AbsoluteReserveProvider, location::RelativeLocations, ConcreteFungibleAsset};
use orml_traits::{location::RelativeLocations, ConcreteFungibleAsset};

#[derive(Debug, PartialEq, Eq)]
pub enum TestCurrencyId {
Expand Down Expand Up @@ -88,22 +88,3 @@ fn is_native_concrete_does_not_matches_non_native_currencies() {
})
.is_none());
}

#[test]
fn multi_native_asset() {
assert!(MultiNativeAsset::<AbsoluteReserveProvider>::contains(
&Asset {
fun: Fungible(10),
id: AssetId(Location::parent())
},
&Parent.into()
));
assert!(MultiNativeAsset::<AbsoluteReserveProvider>::contains(
&Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100),
&Location::new(1, [Parachain(1)]),
));
assert!(!MultiNativeAsset::<AbsoluteReserveProvider>::contains(
&Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100),
&Location::parent(),
));
}
Loading