# 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
@@ -93,10 +93,10 @@ parameter_types! {
pub struct MatchAnyFungible;
impl xcm_executor::traits::MatchesFungible<u64> for MatchAnyFungible {
fn matches_fungible(m: &MultiAsset) -> Option<u64> {
fn matches_fungible(m: &Asset) -> Option<u64> {
use sp_runtime::traits::SaturatedConversion;
match m {
MultiAsset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
Asset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
_ => None,
}
}
@@ -151,13 +151,12 @@ impl crate::Config for Test {
type XcmConfig = XcmConfig;
type AccountIdConverter = AccountIdConverter;
type DeliveryHelper = ();
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
let valid_destination: MultiLocation =
X1(AccountId32 { network: None, id: [0u8; 32] }).into();
fn valid_destination() -> Result<Location, BenchmarkError> {
let valid_destination: Location = [AccountId32 { network: None, id: [0u8; 32] }].into();
Ok(valid_destination)
}
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
fn worst_case_holding(depositable_count: u32) -> Assets {
crate::mock_worst_case_holding(
depositable_count,
<XcmConfig as xcm_executor::Config>::MaxAssetsIntoHolding::get(),
@@ -170,19 +169,19 @@ pub type TrustedReserves = xcm_builder::Case<ReserveConcreteFungible>;
parameter_types! {
pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local));
pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location();
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub ChildTeleporter: Location = Parachain(1000).into_location();
pub TrustedTeleporter: Option<(Location, Asset)> = Some((
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedReserve: Option<(Location, Asset)> = Some((
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
));
pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
pub TeleportConcreteFungible: (AssetFilter, Location) =
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
pub ReserveConcreteFungible: (AssetFilter, Location) =
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
}
impl xcm_balances_benchmark::Config for Test {
@@ -191,10 +190,10 @@ impl xcm_balances_benchmark::Config for Test {
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;
fn get_multi_asset() -> MultiAsset {
fn get_asset() -> Asset {
let amount =
<Balances as frame_support::traits::fungible::Inspect<u64>>::minimum_balance() as u128;
MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) }
Asset { id: AssetId(Here.into()), fun: Fungible(amount) }
}
}