# 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
@@ -31,7 +31,7 @@ use frame_support::{
use pallet_balances::{BalanceLock, Reasons};
use pallet_contracts::{Code, CollectEvents, DebugInfo, Determinism};
use pallet_contracts_fixtures::compile_module;
use xcm::{v3::prelude::*, VersionedMultiLocation, VersionedXcm};
use xcm::{v4::prelude::*, VersionedLocation, VersionedXcm};
use xcm_simulator::TestExt;
type ParachainContracts = pallet_contracts::Pallet<parachain::Runtime>;
@@ -82,7 +82,7 @@ fn test_xcm_execute() {
let amount: u128 = 10 * CENTS;
// The XCM used to transfer funds to Bob.
let message: xcm_simulator::Xcm<()> = Xcm(vec![
let message: Xcm<()> = Xcm(vec![
WithdrawAsset(vec![(Here, amount).into()].into()),
DepositAsset {
assets: All.into(),
@@ -96,7 +96,7 @@ fn test_xcm_execute() {
0,
Weight::MAX,
None,
VersionedXcm::V3(message).encode(),
VersionedXcm::V4(message).encode(),
DebugInfo::UnsafeDebug,
CollectEvents::UnsafeCollect,
Determinism::Enforced,
@@ -106,7 +106,7 @@ fn test_xcm_execute() {
let mut data = &result.data[..];
let outcome = Outcome::decode(&mut data).expect("Failed to decode xcm_execute Outcome");
assert_matches!(outcome, Outcome::Complete(_));
assert_matches!(outcome, Outcome::Complete { .. });
// Check if the funds are subtracted from the account of Alice and added to the account of
// Bob.
@@ -137,7 +137,7 @@ fn test_xcm_execute_filtered_call() {
0,
Weight::MAX,
None,
VersionedXcm::V3(message).encode(),
VersionedXcm::V4(message).encode(),
DebugInfo::UnsafeDebug,
CollectEvents::UnsafeCollect,
Determinism::Enforced,
@@ -178,7 +178,7 @@ fn test_xcm_execute_reentrant_call() {
0,
Weight::MAX,
None,
VersionedXcm::V3(message).encode(),
VersionedXcm::V4(message).encode(),
DebugInfo::UnsafeDebug,
CollectEvents::UnsafeCollect,
Determinism::Enforced,
@@ -188,7 +188,10 @@ fn test_xcm_execute_reentrant_call() {
let mut data = &result.data[..];
let outcome = Outcome::decode(&mut data).expect("Failed to decode xcm_execute Outcome");
assert_matches!(outcome, Outcome::Incomplete(_, XcmError::ExpectationFalse));
assert_matches!(
outcome,
Outcome::Incomplete { used: _, error: XcmError::ExpectationFalse }
);
// Funds should not change hands as the XCM transact failed.
assert_eq!(ParachainBalances::free_balance(BOB), INITIAL_BALANCE);
@@ -203,15 +206,15 @@ fn test_xcm_send() {
// Send XCM instructions through the contract, to lock some funds on the relay chain.
ParaA::execute_with(|| {
let dest = MultiLocation::from(Parent);
let dest = VersionedMultiLocation::V3(dest);
let dest = Location::from(Parent);
let dest = VersionedLocation::V4(dest);
let message: xcm_simulator::Xcm<()> = Xcm(vec![
let message: Xcm<()> = Xcm(vec![
WithdrawAsset((Here, fee).into()),
BuyExecution { fees: (Here, fee).into(), weight_limit: WeightLimit::Unlimited },
LockAsset { asset: (Here, 5 * CENTS).into(), unlocker: (Parachain(1)).into() },
]);
let message = VersionedXcm::V3(message);
let message = VersionedXcm::V4(message);
let exec = ParachainContracts::bare_call(
ALICE,
contract_addr.clone(),