Skip to content

Commit 937ac46

Browse files
authored
[AMH] Xtokens add MigrationPhase (#1033)
* add MigrationPhase * fix * fix
1 parent c02a0ba commit 937ac46

File tree

9 files changed

+310
-203
lines changed

9 files changed

+310
-203
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
- name: Update
3737
run: |
3838
cargo update
39-
cargo update base64ct --precise 1.6.0 # 1.8.0 requires the Cargo feature called `edition2024`
4039
cargo update pallet-revive-proc-macro --precise 0.3.0 # TODO: https://github.com/paritytech/polkadot-sdk/issues/9425
4140
- name: Run clippy
4241
run: cargo clippy -- -D warnings

asset-registry/src/mock/para.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ use frame_support::{
1010
PalletId,
1111
};
1212
use frame_system::{EnsureRoot, EnsureSignedBy};
13-
use orml_traits::{
14-
location::{AbsoluteReserveProvider, RelativeReserveProvider},
15-
parameter_type_with_key, FixedConversionRateProvider, MultiCurrency,
16-
};
13+
use orml_traits::{parameter_type_with_key, FixedConversionRateProvider, MultiCurrency};
1714
use orml_xcm_support::{IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset};
15+
use orml_xtokens::{AbsoluteReserveProviderMigrationPhase, RelativeReserveProviderMigrationPhase};
1816
use pallet_xcm::XcmPassthrough;
1917
use parity_scale_codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
2018
use polkadot_parachain_primitives::primitives::Sibling;
@@ -212,7 +210,7 @@ impl Config for XcmConfig {
212210
type XcmSender = XcmRouter;
213211
type AssetTransactor = LocalAssetTransactor;
214212
type OriginConverter = XcmOriginToCallOrigin;
215-
type IsReserve = MultiNativeAsset<AbsoluteReserveProvider>;
213+
type IsReserve = MultiNativeAsset<AbsoluteReserveProviderMigrationPhase<Runtime>>;
216214
type IsTeleporter = ();
217215
type UniversalLocation = UniversalLocation;
218216
type Barrier = Barrier;
@@ -329,9 +327,10 @@ impl orml_xtokens::Config for Runtime {
329327
type BaseXcmWeight = BaseXcmWeight;
330328
type UniversalLocation = UniversalLocation;
331329
type MaxAssetsForTransfer = MaxAssetsForTransfer;
332-
type ReserveProvider = RelativeReserveProvider;
330+
type ReserveProvider = RelativeReserveProviderMigrationPhase<Runtime>;
333331
type RateLimiter = ();
334332
type RateLimiterId = ();
333+
type MigrationPhaseUpdateOrigin = EnsureRoot<AccountId>;
335334
}
336335

337336
impl orml_xcm::Config for Runtime {

traits/src/location.rs

Lines changed: 1 addition & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,13 @@
11
use sp_core::{bounded::BoundedVec, ConstU32};
22
use xcm::v5::prelude::*;
33

4-
pub trait Parse {
5-
/// Returns the "chain" location part. It could be parent, sibling
6-
/// parachain, or child parachain.
7-
fn chain_part(&self) -> Option<Location>;
8-
/// Returns "non-chain" location part.
9-
fn non_chain_part(&self) -> Option<Location>;
10-
}
11-
12-
fn is_chain_junction(junction: Option<&Junction>) -> bool {
13-
matches!(junction, Some(Parachain(_)))
14-
}
15-
16-
impl Parse for Location {
17-
fn chain_part(&self) -> Option<Location> {
18-
match (self.parents, self.first_interior()) {
19-
// sibling parachain
20-
(1, Some(Parachain(id))) => Some(Location::new(1, [Parachain(*id)])),
21-
// parent
22-
(1, _) => Some(Location::parent()),
23-
// children parachain
24-
(0, Some(Parachain(id))) => Some(Location::new(0, [Parachain(*id)])),
25-
_ => None,
26-
}
27-
}
28-
29-
fn non_chain_part(&self) -> Option<Location> {
30-
let mut junctions = self.interior().clone();
31-
while is_chain_junction(junctions.first()) {
32-
let _ = junctions.take_first();
33-
}
34-
35-
if junctions != Here {
36-
Some(Location::new(0, junctions))
37-
} else {
38-
None
39-
}
40-
}
41-
}
4+
pub const ASSET_HUB_ID: u32 = 1000;
425

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

48-
// Provide reserve in absolute path view
49-
pub struct AbsoluteReserveProvider;
50-
51-
impl Reserve for AbsoluteReserveProvider {
52-
fn reserve(asset: &Asset) -> Option<Location> {
53-
let AssetId(location) = &asset.id;
54-
location.chain_part()
55-
}
56-
}
57-
58-
// Provide reserve in relative path view
59-
// Self tokens are represeneted as Here
60-
pub struct RelativeReserveProvider;
61-
62-
impl Reserve for RelativeReserveProvider {
63-
fn reserve(asset: &Asset) -> Option<Location> {
64-
let AssetId(location) = &asset.id;
65-
if location.parents == 0 && !is_chain_junction(location.first_interior()) {
66-
Some(Location::here())
67-
} else {
68-
location.chain_part()
69-
}
70-
}
71-
}
72-
7311
pub trait RelativeLocations {
7412
fn sibling_parachain_general_key(para_id: u32, general_key: BoundedVec<u8, ConstU32<32>>) -> Location;
7513
}
@@ -79,93 +17,3 @@ impl RelativeLocations for Location {
7917
Location::new(1, [Parachain(para_id), general_key.as_bounded_slice().into()])
8018
}
8119
}
82-
83-
#[cfg(test)]
84-
mod tests {
85-
use super::*;
86-
87-
const PARACHAIN: Junction = Parachain(1);
88-
const GENERAL_INDEX: Junction = GeneralIndex(1);
89-
90-
fn concrete_fungible(id: Location) -> Asset {
91-
(id, 1).into()
92-
}
93-
94-
#[test]
95-
fn parent_as_reserve_chain() {
96-
assert_eq!(
97-
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))),
98-
Some(Location::parent())
99-
);
100-
assert_eq!(
101-
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [GENERAL_INDEX]))),
102-
Some(Location::parent())
103-
);
104-
}
105-
106-
#[test]
107-
fn sibling_parachain_as_reserve_chain() {
108-
assert_eq!(
109-
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))),
110-
Some(Location::new(1, [PARACHAIN]))
111-
);
112-
assert_eq!(
113-
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(1, [PARACHAIN, GENERAL_INDEX]))),
114-
Some(Location::new(1, [PARACHAIN]))
115-
);
116-
}
117-
118-
#[test]
119-
fn child_parachain_as_reserve_chain() {
120-
assert_eq!(
121-
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))),
122-
Some(PARACHAIN.into())
123-
);
124-
assert_eq!(
125-
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(0, [PARACHAIN, GENERAL_INDEX]))),
126-
Some(PARACHAIN.into())
127-
);
128-
}
129-
130-
#[test]
131-
fn no_reserve_chain_for_absolute_self_for_relative() {
132-
assert_eq!(
133-
AbsoluteReserveProvider::reserve(&concrete_fungible(Location::new(
134-
0,
135-
[Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())]
136-
))),
137-
None
138-
);
139-
assert_eq!(
140-
RelativeReserveProvider::reserve(&concrete_fungible(Location::new(
141-
0,
142-
[Junction::from(BoundedVec::try_from(b"DOT".to_vec()).unwrap())]
143-
))),
144-
Some(Location::here())
145-
);
146-
}
147-
148-
#[test]
149-
fn non_chain_part_works() {
150-
assert_eq!(Location::parent().non_chain_part(), None);
151-
assert_eq!(Location::new(1, [PARACHAIN]).non_chain_part(), None);
152-
assert_eq!(Location::new(0, [PARACHAIN]).non_chain_part(), None);
153-
154-
assert_eq!(
155-
Location::new(1, [GENERAL_INDEX]).non_chain_part(),
156-
Some(GENERAL_INDEX.into())
157-
);
158-
assert_eq!(
159-
Location::new(1, [GENERAL_INDEX, GENERAL_INDEX]).non_chain_part(),
160-
Some((GENERAL_INDEX, GENERAL_INDEX).into())
161-
);
162-
assert_eq!(
163-
Location::new(1, [PARACHAIN, GENERAL_INDEX]).non_chain_part(),
164-
Some(GENERAL_INDEX.into())
165-
);
166-
assert_eq!(
167-
Location::new(0, [PARACHAIN, GENERAL_INDEX]).non_chain_part(),
168-
Some(GENERAL_INDEX.into())
169-
);
170-
}
171-
}

xcm-support/src/tests.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use super::*;
66

7-
use orml_traits::{location::AbsoluteReserveProvider, location::RelativeLocations, ConcreteFungibleAsset};
7+
use orml_traits::{location::RelativeLocations, ConcreteFungibleAsset};
88

99
#[derive(Debug, PartialEq, Eq)]
1010
pub enum TestCurrencyId {
@@ -88,22 +88,3 @@ fn is_native_concrete_does_not_matches_non_native_currencies() {
8888
})
8989
.is_none());
9090
}
91-
92-
#[test]
93-
fn multi_native_asset() {
94-
assert!(MultiNativeAsset::<AbsoluteReserveProvider>::contains(
95-
&Asset {
96-
fun: Fungible(10),
97-
id: AssetId(Location::parent())
98-
},
99-
&Parent.into()
100-
));
101-
assert!(MultiNativeAsset::<AbsoluteReserveProvider>::contains(
102-
&Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100),
103-
&Location::new(1, [Parachain(1)]),
104-
));
105-
assert!(!MultiNativeAsset::<AbsoluteReserveProvider>::contains(
106-
&Asset::sibling_parachain_asset(1, b"TokenA".to_vec().try_into().unwrap(), 100),
107-
&Location::parent(),
108-
));
109-
}

0 commit comments

Comments
 (0)