# Note for reviewer

Most changes are just syntax changes necessary for the new version.
Most important files should be the ones under the `xcm` folder.

# Description 

Added XCMv4.

## Removed `Multi` prefix
The following types have been renamed:
- MultiLocation -> Location
- MultiAsset -> Asset
- MultiAssets -> Assets
- InteriorMultiLocation -> InteriorLocation
- MultiAssetFilter -> AssetFilter
- VersionedMultiAsset -> VersionedAsset
- WildMultiAsset -> WildAsset
- VersionedMultiLocation -> VersionedLocation

In order to fix a name conflict, the `Assets` in `xcm-executor` were
renamed to `HoldingAssets`, as they represent assets in holding.

## Removed `Abstract` asset id

It was not being used anywhere and this simplifies the code.

Now assets are just constructed as follows:

```rust
let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into();
```

No need for specifying `Concrete` anymore.

## Outcome is now a named fields struct

Instead of

```rust
pub enum Outcome {
  Complete(Weight),
  Incomplete(Weight, Error),
  Error(Error),
}
```

we now have

```rust
pub enum Outcome {
  Complete { used: Weight },
  Incomplete { used: Weight, error: Error },
  Error { error: Error },
}
```

## Added Reanchorable trait

Now both locations and assets implement this trait, making it easier to
reanchor both.

## New syntax for building locations and junctions

Now junctions are built using the following methods:

```rust
let location = Location {
    parents: 1,
    interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into()
};
```

or

```rust
let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]);
```

And they are matched like so:

```rust
match location.unpack() {
  (1, [Parachain(id)]) => ...
  (0, Here) => ...,
  (1, [_]) => ...,
}
```

This syntax is mandatory in v4, and has been also implemented for v2 and
v3 for easier migration.

This was needed to make all sizes smaller.

# TODO
- [x] Scaffold v4
- [x] Port github.com/paritytech/polkadot/pull/7236
- [x] Remove `Multi` prefix
- [x] Remove `Abstract` asset id

---------

Co-authored-by: command-bot <>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Francisco Aguirre
2024-01-16 19:18:04 +01:00
committed by GitHub
parent ec7bfae00a
commit 8428f678fe
255 changed files with 12425 additions and 6726 deletions
+15 -18
View File
@@ -60,12 +60,9 @@ pub use polkadot_runtime_parachains::inclusion::{AggregateMessageOrigin, UmpQueu
// Polkadot
pub use polkadot_parachain_primitives::primitives::RelayChainBlockNumber;
use sp_core::crypto::AccountId32;
pub use xcm::{
prelude::{AccountId32 as AccountId32Junction, Here},
v3::prelude::{
Ancestor, MultiAssets, MultiLocation, Parachain as ParachainJunction, Parent, WeightLimit,
XcmHash, X1,
},
pub use xcm::latest::prelude::{
AccountId32 as AccountId32Junction, Ancestor, Assets, Here, Location,
Parachain as ParachainJunction, Parent, WeightLimit, XcmHash,
};
pub use xcm_executor::traits::ConvertLocation;
@@ -231,11 +228,11 @@ pub trait RelayChain: Chain {
fn init();
fn child_location_of(id: ParaId) -> MultiLocation {
fn child_location_of(id: ParaId) -> Location {
(Ancestor(0), ParachainJunction(id.into())).into()
}
fn sovereign_account_id_of(location: MultiLocation) -> AccountIdOf<Self::Runtime> {
fn sovereign_account_id_of(location: Location) -> AccountIdOf<Self::Runtime> {
Self::SovereignAccountOf::convert_location(&location).unwrap()
}
@@ -263,15 +260,15 @@ pub trait Parachain: Chain {
Self::ext_wrapper(|| Self::ParachainInfo::get())
}
fn parent_location() -> MultiLocation {
fn parent_location() -> Location {
(Parent).into()
}
fn sibling_location_of(para_id: ParaId) -> MultiLocation {
(Parent, X1(ParachainJunction(para_id.into()))).into()
fn sibling_location_of(para_id: ParaId) -> Location {
(Parent, ParachainJunction(para_id.into())).into()
}
fn sovereign_account_id_of(location: MultiLocation) -> AccountIdOf<Self::Runtime> {
fn sovereign_account_id_of(location: Location) -> AccountIdOf<Self::Runtime> {
Self::LocationToAccountId::convert_location(&location).unwrap()
}
}
@@ -1432,10 +1429,10 @@ pub struct TestAccount<R: Chain> {
/// Default `Args` provided by xcm-emulator to be stored in a `Test` instance
#[derive(Clone)]
pub struct TestArgs {
pub dest: MultiLocation,
pub beneficiary: MultiLocation,
pub dest: Location,
pub beneficiary: Location,
pub amount: Balance,
pub assets: MultiAssets,
pub assets: Assets,
pub asset_id: Option<u32>,
pub fee_asset_item: u32,
pub weight_limit: WeightLimit,
@@ -1443,7 +1440,7 @@ pub struct TestArgs {
impl TestArgs {
/// Returns a [`TestArgs`] instance to be used for the Relay Chain across integration tests.
pub fn new_relay(dest: MultiLocation, beneficiary_id: AccountId32, amount: Balance) -> Self {
pub fn new_relay(dest: Location, beneficiary_id: AccountId32, amount: Balance) -> Self {
Self {
dest,
beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(),
@@ -1457,10 +1454,10 @@ impl TestArgs {
/// Returns a [`TestArgs`] instance to be used for parachains across integration tests.
pub fn new_para(
dest: MultiLocation,
dest: Location,
beneficiary_id: AccountId32,
amount: Balance,
assets: MultiAssets,
assets: Assets,
asset_id: Option<u32>,
fee_asset_item: u32,
) -> Self {