mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 01:01:01 +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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user