mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01: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
@@ -32,7 +32,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
|
||||
mod weights;
|
||||
pub mod xcm_config;
|
||||
|
||||
use assets_common::MultiLocationForAssetId;
|
||||
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
|
||||
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
|
||||
use frame_support::{
|
||||
@@ -474,8 +473,8 @@ pub type ForeignAssetsInstance = pallet_assets::Instance2;
|
||||
impl pallet_assets::Config<ForeignAssetsInstance> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Balance = Balance;
|
||||
type AssetId = MultiLocationForAssetId;
|
||||
type AssetIdParameter = MultiLocationForAssetId;
|
||||
type AssetId = xcm::v3::Location;
|
||||
type AssetIdParameter = xcm::v3::Location;
|
||||
type Currency = Balances;
|
||||
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
|
||||
type ForceOrigin = EnsureRoot<AccountId>;
|
||||
|
||||
@@ -29,7 +29,7 @@ use super::{
|
||||
};
|
||||
use core::marker::PhantomData;
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{
|
||||
fungibles::{self, Balanced, Credit},
|
||||
ConstU32, Contains, ContainsPair, Everything, Get, Nothing,
|
||||
@@ -59,13 +59,13 @@ use xcm_builder::{
|
||||
use xcm_executor::{traits::JustTry, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const RelayLocation: Location = Location::parent();
|
||||
pub const RelayNetwork: Option<NetworkId> = None;
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(ParachainInfo::parachain_id().into()));
|
||||
pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into();
|
||||
}
|
||||
|
||||
/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used
|
||||
/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
|
||||
/// when determining ownership of accounts for asset transacting and when attempting to use XCM
|
||||
/// `Transact` in order to determine the dispatch Origin.
|
||||
pub type LocationToAccountId = (
|
||||
@@ -84,7 +84,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<RelayLocation>,
|
||||
// Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID:
|
||||
// Do a simple punn to convert an AccountId32 Location into a native chain account ID:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
@@ -115,7 +115,7 @@ pub type FungiblesTransactor = FungiblesAdapter<
|
||||
JustTry,
|
||||
>,
|
||||
),
|
||||
// Convert an XCM MultiLocation into a local account id:
|
||||
// Convert an XCM Location into a local account id:
|
||||
LocationToAccountId,
|
||||
// Our chain's account ID type (we can't get away without mentioning it explicitly):
|
||||
AccountId,
|
||||
@@ -180,14 +180,18 @@ parameter_types! {
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
}
|
||||
|
||||
match_types! {
|
||||
pub type ParentOrParentsExecutivePlurality: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 1, interior: Here } |
|
||||
MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) }
|
||||
};
|
||||
pub type CommonGoodAssetsParachain: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(1000)) }
|
||||
};
|
||||
pub struct ParentOrParentsExecutivePlurality;
|
||||
impl Contains<Location> for ParentOrParentsExecutivePlurality {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CommonGoodAssetsParachain;
|
||||
impl Contains<Location> for CommonGoodAssetsParachain {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, [Parachain(1000)]))
|
||||
}
|
||||
}
|
||||
|
||||
pub type Barrier = TrailingSetTopicAsId<
|
||||
@@ -224,15 +228,15 @@ pub type AccountIdOf<R> = <R as frame_system::Config>::AccountId;
|
||||
|
||||
/// Asset filter that allows all assets from a certain location matching asset id.
|
||||
pub struct AssetPrefixFrom<Prefix, Origin>(PhantomData<(Prefix, Origin)>);
|
||||
impl<Prefix, Origin> ContainsPair<MultiAsset, MultiLocation> for AssetPrefixFrom<Prefix, Origin>
|
||||
impl<Prefix, Origin> ContainsPair<Asset, Location> for AssetPrefixFrom<Prefix, Origin>
|
||||
where
|
||||
Prefix: Get<MultiLocation>,
|
||||
Origin: Get<MultiLocation>,
|
||||
Prefix: Get<Location>,
|
||||
Origin: Get<Location>,
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
let loc = Origin::get();
|
||||
&loc == origin &&
|
||||
matches!(asset, MultiAsset { id: AssetId::Concrete(asset_loc), fun: Fungible(_a) }
|
||||
matches!(asset, Asset { id: AssetId(asset_loc), fun: Fungible(_a) }
|
||||
if asset_loc.starts_with(&Prefix::get()))
|
||||
}
|
||||
}
|
||||
@@ -241,12 +245,12 @@ type AssetsFrom<T> = AssetPrefixFrom<T, T>;
|
||||
|
||||
/// Asset filter that allows native/relay asset if coming from a certain location.
|
||||
pub struct NativeAssetFrom<T>(PhantomData<T>);
|
||||
impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for NativeAssetFrom<T> {
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
impl<T: Get<Location>> ContainsPair<Asset, Location> for NativeAssetFrom<T> {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
let loc = T::get();
|
||||
&loc == origin &&
|
||||
matches!(asset, MultiAsset { id: AssetId::Concrete(asset_loc), fun: Fungible(_a) }
|
||||
if *asset_loc == MultiLocation::from(Parent))
|
||||
matches!(asset, Asset { id: AssetId(asset_loc), fun: Fungible(_a) }
|
||||
if *asset_loc == Location::from(Parent))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,29 +286,34 @@ where
|
||||
pub const TELEPORTABLE_ASSET_ID: u32 = 2;
|
||||
parameter_types! {
|
||||
/// The location that this chain recognizes as the Relay network's Asset Hub.
|
||||
pub SystemAssetHubLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(1000)));
|
||||
pub SystemAssetHubLocation: Location = Location::new(1, [Parachain(1000)]);
|
||||
// ALWAYS ensure that the index in PalletInstance stays up-to-date with
|
||||
// the Relay Chain's Asset Hub's Assets pallet index
|
||||
pub SystemAssetHubAssetsPalletLocation: MultiLocation =
|
||||
MultiLocation::new(1, X2(Parachain(1000), PalletInstance(50)));
|
||||
pub AssetsPalletLocation: MultiLocation =
|
||||
MultiLocation::new(0, X1(PalletInstance(50)));
|
||||
pub SystemAssetHubAssetsPalletLocation: Location =
|
||||
Location::new(1, [Parachain(1000), PalletInstance(50)]);
|
||||
pub AssetsPalletLocation: Location =
|
||||
Location::new(0, [PalletInstance(50)]);
|
||||
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
|
||||
pub LocalTeleportableToAssetHub: MultiLocation = MultiLocation::new(
|
||||
pub LocalTeleportableToAssetHub: Location = Location::new(
|
||||
0,
|
||||
X2(PalletInstance(50), GeneralIndex(TELEPORTABLE_ASSET_ID.into()))
|
||||
[PalletInstance(50), GeneralIndex(TELEPORTABLE_ASSET_ID.into())]
|
||||
);
|
||||
pub EthereumLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(EthereumNetwork::get())));
|
||||
pub LocalTeleportableToAssetHubV3: xcm::v3::Location = xcm::v3::Location::new(
|
||||
0,
|
||||
[xcm::v3::Junction::PalletInstance(50), xcm::v3::Junction::GeneralIndex(TELEPORTABLE_ASSET_ID.into())]
|
||||
);
|
||||
pub EthereumLocation: Location = Location::new(2, [GlobalConsensus(EthereumNetwork::get())]);
|
||||
}
|
||||
|
||||
/// Accepts asset with ID `AssetLocation` and is coming from `Origin` chain.
|
||||
pub struct AssetFromChain<AssetLocation, Origin>(PhantomData<(AssetLocation, Origin)>);
|
||||
impl<AssetLocation: Get<MultiLocation>, Origin: Get<MultiLocation>>
|
||||
ContainsPair<MultiAsset, MultiLocation> for AssetFromChain<AssetLocation, Origin>
|
||||
impl<AssetLocation: Get<Location>, Origin: Get<Location>> ContainsPair<Asset, Location>
|
||||
for AssetFromChain<AssetLocation, Origin>
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
log::trace!(target: "xcm::contains", "AssetFromChain asset: {:?}, origin: {:?}", asset, origin);
|
||||
*origin == Origin::get() && matches!(asset.id, Concrete(id) if id == AssetLocation::get())
|
||||
*origin == Origin::get() &&
|
||||
matches!(asset.id.clone(), AssetId(id) if id == AssetLocation::get())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,8 +407,8 @@ impl cumulus_pallet_xcm::Config for Runtime {
|
||||
/// Simple conversion of `u32` into an `AssetId` for use in benchmarking.
|
||||
pub struct XcmBenchmarkHelper;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl pallet_assets::BenchmarkHelper<MultiLocation> for XcmBenchmarkHelper {
|
||||
fn create_asset_id_parameter(id: u32) -> MultiLocation {
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) }
|
||||
impl pallet_assets::BenchmarkHelper<xcm::v3::Location> for XcmBenchmarkHelper {
|
||||
fn create_asset_id_parameter(id: u32) -> xcm::v3::Location {
|
||||
xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(id)])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user