mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 22:41:02 +00:00
XCMv4 (#1230)
# 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:
committed by
GitHub
parent
ec7bfae00a
commit
8428f678fe
@@ -115,14 +115,14 @@ impl pallet_assets::Config for Test {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = Here.into_location();
|
||||
pub const RelayLocation: Location = Here.into_location();
|
||||
pub const AnyNetwork: Option<NetworkId> = None;
|
||||
pub UniversalLocation: InteriorMultiLocation = (ByGenesis([0; 32]), Parachain(42)).into();
|
||||
pub UniversalLocation: InteriorLocation = (ByGenesis([0; 32]), Parachain(42)).into();
|
||||
pub UnitWeightCost: u64 = 1_000;
|
||||
pub static AdvertisedXcmVersion: u32 = 3;
|
||||
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000, 1_000);
|
||||
pub CurrencyPerSecondPerByte: (AssetId, u128, u128) = (Concrete(RelayLocation::get()), 1, 1);
|
||||
pub TrustedAssets: (MultiAssetFilter, MultiLocation) = (All.into(), Here.into());
|
||||
pub CurrencyPerSecondPerByte: (AssetId, u128, u128) = (AssetId(RelayLocation::get()), 1, 1);
|
||||
pub TrustedAssets: (AssetFilter, Location) = (All.into(), Here.into());
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
pub CheckingAccount: AccountId = XcmPallet::check_account();
|
||||
@@ -130,28 +130,25 @@ parameter_types! {
|
||||
|
||||
type AssetIdForAssets = u128;
|
||||
|
||||
pub struct FromMultiLocationToAsset<MultiLocation, AssetId>(
|
||||
core::marker::PhantomData<(MultiLocation, AssetId)>,
|
||||
);
|
||||
impl MaybeEquivalence<MultiLocation, AssetIdForAssets>
|
||||
for FromMultiLocationToAsset<MultiLocation, AssetIdForAssets>
|
||||
pub struct FromLocationToAsset<Location, AssetId>(core::marker::PhantomData<(Location, AssetId)>);
|
||||
impl MaybeEquivalence<Location, AssetIdForAssets>
|
||||
for FromLocationToAsset<Location, AssetIdForAssets>
|
||||
{
|
||||
fn convert(value: &MultiLocation) -> Option<AssetIdForAssets> {
|
||||
match value {
|
||||
MultiLocation { parents: 0, interior: Here } => Some(0 as AssetIdForAssets),
|
||||
MultiLocation { parents: 1, interior: Here } => Some(1 as AssetIdForAssets),
|
||||
MultiLocation { parents: 0, interior: X2(PalletInstance(1), GeneralIndex(index)) }
|
||||
if ![0, 1].contains(index) =>
|
||||
fn convert(value: &Location) -> Option<AssetIdForAssets> {
|
||||
match value.unpack() {
|
||||
(0, []) => Some(0 as AssetIdForAssets),
|
||||
(1, []) => Some(1 as AssetIdForAssets),
|
||||
(0, [PalletInstance(1), GeneralIndex(index)]) if ![0, 1].contains(index) =>
|
||||
Some(*index as AssetIdForAssets),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_back(value: &AssetIdForAssets) -> Option<MultiLocation> {
|
||||
fn convert_back(value: &AssetIdForAssets) -> Option<Location> {
|
||||
match value {
|
||||
0u128 => Some(MultiLocation { parents: 1, interior: Here }),
|
||||
0u128 => Some(Location { parents: 1, interior: Here }),
|
||||
para_id @ 1..=1000 =>
|
||||
Some(MultiLocation { parents: 1, interior: X1(Parachain(*para_id as u32)) }),
|
||||
Some(Location { parents: 1, interior: [Parachain(*para_id as u32)].into() }),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -163,7 +160,7 @@ pub type LocalAssetsTransactor = FungiblesAdapter<
|
||||
ConvertedConcreteId<
|
||||
AssetIdForAssets,
|
||||
Balance,
|
||||
FromMultiLocationToAsset<MultiLocation, AssetIdForAssets>,
|
||||
FromLocationToAsset<Location, AssetIdForAssets>,
|
||||
JustTry,
|
||||
>,
|
||||
SovereignAccountOf,
|
||||
@@ -187,10 +184,10 @@ impl WeightTrader for DummyWeightTrader {
|
||||
fn buy_weight(
|
||||
&mut self,
|
||||
_weight: Weight,
|
||||
_payment: xcm_executor::Assets,
|
||||
_payment: xcm_executor::AssetsInHolding,
|
||||
_context: &XcmContext,
|
||||
) -> Result<xcm_executor::Assets, XcmError> {
|
||||
Ok(xcm_executor::Assets::default())
|
||||
) -> Result<xcm_executor::AssetsInHolding, XcmError> {
|
||||
Ok(xcm_executor::AssetsInHolding::default())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,13 +225,10 @@ parameter_types! {
|
||||
|
||||
pub struct TreasuryToAccount;
|
||||
impl ConvertLocation<AccountId> for TreasuryToAccount {
|
||||
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
|
||||
match location {
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior:
|
||||
X2(Parachain(42), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }),
|
||||
} => Some(TreasuryAccountId::get()), // Hardcoded test treasury account id
|
||||
fn convert_location(location: &Location) -> Option<AccountId> {
|
||||
match location.unpack() {
|
||||
(1, [Parachain(42), Plurality { id: BodyId::Treasury, part: BodyPart::Voice }]) =>
|
||||
Some(TreasuryAccountId::get()), // Hardcoded test treasury account id
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -277,7 +271,7 @@ pub const INITIAL_BALANCE: Balance = 100 * UNITS;
|
||||
pub const MINIMUM_BALANCE: Balance = 1 * UNITS;
|
||||
|
||||
pub fn sibling_chain_account_id(para_id: u32, account: [u8; 32]) -> AccountId {
|
||||
let location: MultiLocation =
|
||||
let location: Location =
|
||||
(Parent, Parachain(para_id), Junction::AccountId32 { id: account, network: None }).into();
|
||||
SovereignAccountOf::convert_location(&location).unwrap()
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ use frame_support::{assert_ok, traits::tokens::Pay};
|
||||
|
||||
/// Type representing both a location and an asset that is held at that location.
|
||||
/// The id of the held asset is relative to the location where it is being held.
|
||||
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Encode, Decode, Clone, PartialEq, Eq)]
|
||||
pub struct AssetKind {
|
||||
destination: MultiLocation,
|
||||
destination: Location,
|
||||
asset_id: AssetId,
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ impl sp_runtime::traits::TryConvert<AssetKind, LocatableAssetId> for LocatableAs
|
||||
|
||||
parameter_types! {
|
||||
pub SenderAccount: AccountId = AccountId::new([3u8; 32]);
|
||||
pub InteriorAccount: InteriorMultiLocation = AccountId32 { id: SenderAccount::get().into(), network: None }.into();
|
||||
pub InteriorBody: InteriorMultiLocation = Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into();
|
||||
pub InteriorAccount: InteriorLocation = AccountId32 { id: SenderAccount::get().into(), network: None }.into();
|
||||
pub InteriorBody: InteriorLocation = Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into();
|
||||
pub Timeout: BlockNumber = 5; // 5 blocks
|
||||
}
|
||||
|
||||
@@ -91,13 +91,19 @@ fn pay_over_xcm_works() {
|
||||
vec![((Parent, Parachain(2)).into(), expected_message, expected_hash)]
|
||||
);
|
||||
|
||||
let (_, message, hash) = sent_xcm()[0].clone();
|
||||
let (_, message, mut hash) = sent_xcm()[0].clone();
|
||||
let message =
|
||||
Xcm::<<XcmConfig as xcm_executor::Config>::RuntimeCall>::from(message.clone());
|
||||
|
||||
// Execute message in parachain 2 with parachain 42's origin
|
||||
let origin = (Parent, Parachain(42));
|
||||
XcmExecutor::<XcmConfig>::execute_xcm(origin, message, hash, Weight::MAX);
|
||||
XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
origin,
|
||||
message,
|
||||
&mut hash,
|
||||
Weight::MAX,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(mock::Assets::balance(0, &recipient), amount);
|
||||
});
|
||||
}
|
||||
@@ -152,13 +158,19 @@ fn pay_over_xcm_governance_body() {
|
||||
vec![((Parent, Parachain(2)).into(), expected_message, expected_hash)]
|
||||
);
|
||||
|
||||
let (_, message, hash) = sent_xcm()[0].clone();
|
||||
let (_, message, mut hash) = sent_xcm()[0].clone();
|
||||
let message =
|
||||
Xcm::<<XcmConfig as xcm_executor::Config>::RuntimeCall>::from(message.clone());
|
||||
|
||||
// Execute message in parachain 2 with parachain 42's origin
|
||||
let origin = (Parent, Parachain(42));
|
||||
XcmExecutor::<XcmConfig>::execute_xcm(origin, message, hash, Weight::MAX);
|
||||
XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
origin,
|
||||
message,
|
||||
&mut hash,
|
||||
Weight::MAX,
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_eq!(mock::Assets::balance(relay_asset_index, &recipient), amount);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ use frame_support::{
|
||||
use sp_runtime::{traits::ConvertToValue, DispatchResult};
|
||||
|
||||
parameter_types! {
|
||||
pub Interior: InteriorMultiLocation = Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into();
|
||||
pub Interior: InteriorLocation = Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into();
|
||||
pub Timeout: BlockNumber = 5;
|
||||
pub AssetHub: MultiLocation = (Parent, Parachain(1)).into();
|
||||
pub AssetHub: Location = (Parent, Parachain(1)).into();
|
||||
pub AssetIdGeneralIndex: u128 = 100;
|
||||
pub AssetHubAssetId: AssetId = (PalletInstance(1), GeneralIndex(AssetIdGeneralIndex::get())).into();
|
||||
pub LocatableAsset: LocatableAssetId = LocatableAssetId { asset_id: AssetHubAssetId::get(), location: AssetHub::get() };
|
||||
@@ -140,7 +140,7 @@ fn salary_pay_over_xcm_works() {
|
||||
assert_ok!(Salary::payout(RuntimeOrigin::signed(recipient.clone())));
|
||||
|
||||
// Get message from mock transport layer
|
||||
let (_, message, hash) = sent_xcm()[0].clone();
|
||||
let (_, message, mut hash) = sent_xcm()[0].clone();
|
||||
// Change type from `Xcm<()>` to `Xcm<RuntimeCall>` to be able to execute later
|
||||
let message =
|
||||
Xcm::<<XcmConfig as xcm_executor::Config>::RuntimeCall>::from(message.clone());
|
||||
@@ -164,7 +164,13 @@ fn salary_pay_over_xcm_works() {
|
||||
assert_eq!(message, expected_message);
|
||||
|
||||
// Execute message as the asset hub
|
||||
XcmExecutor::<XcmConfig>::execute_xcm((Parent, Parachain(42)), message, hash, Weight::MAX);
|
||||
XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
(Parent, Parachain(42)),
|
||||
message,
|
||||
&mut hash,
|
||||
Weight::MAX,
|
||||
Weight::zero(),
|
||||
);
|
||||
|
||||
// Recipient receives the payment
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user