mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 02:51: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
@@ -20,12 +20,12 @@ use super::{
|
||||
ToWestendXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
|
||||
};
|
||||
use assets_common::{
|
||||
local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation,
|
||||
local_and_foreign_assets::MatchesLocalAndForeignAssetsLocation,
|
||||
matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset},
|
||||
TrustBackedAssetsAsMultiLocation,
|
||||
TrustBackedAssetsAsLocation,
|
||||
};
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{
|
||||
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, Equals, Everything, Nothing,
|
||||
PalletInfoAccess,
|
||||
@@ -64,26 +64,32 @@ use xcm_builder::{
|
||||
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const TokenLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const TokenLocation: Location = Location::parent();
|
||||
pub const TokenLocationV3: xcm::v3::Location = xcm::v3::Location::parent();
|
||||
pub const RelayNetwork: NetworkId = NetworkId::Rococo;
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorMultiLocation =
|
||||
X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
|
||||
pub UniversalLocation: InteriorLocation =
|
||||
[GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
|
||||
pub UniversalLocationNetworkId: NetworkId = UniversalLocation::get().global_consensus().unwrap();
|
||||
pub AssetsPalletIndex: u32 = <Assets as PalletInfoAccess>::index() as u32;
|
||||
pub TrustBackedAssetsPalletLocation: MultiLocation = PalletInstance(AssetsPalletIndex::get() as u8).into();
|
||||
pub ForeignAssetsPalletLocation: MultiLocation =
|
||||
pub TrustBackedAssetsPalletLocation: Location =
|
||||
PalletInstance(TrustBackedAssetsPalletIndex::get()).into();
|
||||
pub TrustBackedAssetsPalletIndex: u8 = <Assets as PalletInfoAccess>::index() as u8;
|
||||
pub TrustBackedAssetsPalletLocationV3: xcm::v3::Location =
|
||||
xcm::v3::Junction::PalletInstance(<Assets as PalletInfoAccess>::index() as u8).into();
|
||||
pub ForeignAssetsPalletLocation: Location =
|
||||
PalletInstance(<ForeignAssets as PalletInfoAccess>::index() as u8).into();
|
||||
pub PoolAssetsPalletLocation: MultiLocation =
|
||||
pub PoolAssetsPalletLocation: Location =
|
||||
PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
|
||||
pub PoolAssetsPalletLocationV3: xcm::v3::Location =
|
||||
xcm::v3::Junction::PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
|
||||
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
|
||||
pub const GovernanceLocation: Location = Location::parent();
|
||||
pub StakingPot: AccountId = CollatorSelection::account_id();
|
||||
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
|
||||
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
|
||||
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).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 = (
|
||||
@@ -110,7 +116,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<TokenLocation>,
|
||||
// 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,
|
||||
@@ -128,7 +134,7 @@ pub type FungiblesTransactor = FungiblesAdapter<
|
||||
Assets,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
TrustBackedAssetsConvertedConcreteId,
|
||||
// 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,
|
||||
@@ -145,8 +151,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
|
||||
// Ignore `TrustBackedAssets` explicitly
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
// Ignore assets that start explicitly with our `GlobalConsensus(NetworkId)`, means:
|
||||
// - foreign assets from our consensus should be: `MultiLocation {parents: 1,
|
||||
// X*(Parachain(xyz), ..)}`
|
||||
// - foreign assets from our consensus should be: `Location {parents: 1, X*(Parachain(xyz),
|
||||
// ..)}`
|
||||
// - foreign assets outside our consensus with the same `GlobalConsensus(NetworkId)` won't
|
||||
// be accepted here
|
||||
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
|
||||
@@ -160,7 +166,7 @@ pub type ForeignFungiblesTransactor = FungiblesAdapter<
|
||||
ForeignAssets,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
ForeignAssetsConvertedConcreteId,
|
||||
// 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,7 +186,7 @@ pub type PoolFungiblesTransactor = FungiblesAdapter<
|
||||
PoolAssets,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
PoolAssetsConvertedConcreteId,
|
||||
// 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,
|
||||
@@ -195,20 +201,32 @@ pub type PoolFungiblesTransactor = FungiblesAdapter<
|
||||
pub type AssetTransactors =
|
||||
(CurrencyTransactor, FungiblesTransactor, ForeignFungiblesTransactor, PoolFungiblesTransactor);
|
||||
|
||||
/// Simple `MultiLocation` matcher for Local and Foreign asset `MultiLocation`.
|
||||
pub struct LocalAndForeignAssetsMultiLocationMatcher;
|
||||
impl MatchesLocalAndForeignAssetsMultiLocation for LocalAndForeignAssetsMultiLocationMatcher {
|
||||
fn is_local(location: &MultiLocation) -> bool {
|
||||
use assets_common::fungible_conversion::MatchesMultiLocation;
|
||||
TrustBackedAssetsConvertedConcreteId::contains(location)
|
||||
/// Simple `Location` matcher for Local and Foreign asset `Location`.
|
||||
pub struct LocalAndForeignAssetsLocationMatcher;
|
||||
impl MatchesLocalAndForeignAssetsLocation<xcm::v3::Location>
|
||||
for LocalAndForeignAssetsLocationMatcher
|
||||
{
|
||||
fn is_local(location: &xcm::v3::Location) -> bool {
|
||||
use assets_common::fungible_conversion::MatchesLocation;
|
||||
let latest_location: Location = if let Ok(location) = (*location).try_into() {
|
||||
location
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
TrustBackedAssetsConvertedConcreteId::contains(&latest_location)
|
||||
}
|
||||
fn is_foreign(location: &MultiLocation) -> bool {
|
||||
use assets_common::fungible_conversion::MatchesMultiLocation;
|
||||
ForeignAssetsConvertedConcreteId::contains(location)
|
||||
fn is_foreign(location: &xcm::v3::Location) -> bool {
|
||||
use assets_common::fungible_conversion::MatchesLocation;
|
||||
let latest_location: Location = if let Ok(location) = (*location).try_into() {
|
||||
location
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
ForeignAssetsConvertedConcreteId::contains(&latest_location)
|
||||
}
|
||||
}
|
||||
impl Contains<MultiLocation> for LocalAndForeignAssetsMultiLocationMatcher {
|
||||
fn contains(location: &MultiLocation) -> bool {
|
||||
impl Contains<xcm::v3::Location> for LocalAndForeignAssetsLocationMatcher {
|
||||
fn contains(location: &xcm::v3::Location) -> bool {
|
||||
Self::is_local(location) || Self::is_foreign(location)
|
||||
}
|
||||
}
|
||||
@@ -243,11 +261,11 @@ parameter_types! {
|
||||
pub XcmAssetFeesReceiver: Option<AccountId> = Authorship::author();
|
||||
}
|
||||
|
||||
match_types! {
|
||||
pub type ParentOrParentsPlurality: impl Contains<MultiLocation> = {
|
||||
MultiLocation { parents: 1, interior: Here } |
|
||||
MultiLocation { parents: 1, interior: X1(Plurality { .. }) }
|
||||
};
|
||||
pub struct ParentOrParentsPlurality;
|
||||
impl Contains<Location> for ParentOrParentsPlurality {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
|
||||
}
|
||||
}
|
||||
|
||||
/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
|
||||
@@ -556,12 +574,12 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type Trader = (
|
||||
UsingComponents<WeightToFee, TokenLocation, AccountId, Balances, ToStakingPot<Runtime>>,
|
||||
cumulus_primitives_utility::SwapFirstAssetTrader<
|
||||
TokenLocation,
|
||||
TokenLocationV3,
|
||||
crate::AssetConversion,
|
||||
WeightToFee,
|
||||
crate::NativeAndAssets,
|
||||
(
|
||||
TrustBackedAssetsAsMultiLocation<TrustBackedAssetsPalletLocation, Balance>,
|
||||
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance>,
|
||||
ForeignAssetsConvertedConcreteId,
|
||||
),
|
||||
ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
|
||||
@@ -588,7 +606,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type Aliasers = Nothing;
|
||||
}
|
||||
|
||||
/// Converts a local signed origin into an XCM multilocation.
|
||||
/// Converts a local signed origin into an XCM location.
|
||||
/// Forms the basis for local origins sending/executing XCMs.
|
||||
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;
|
||||
|
||||
@@ -664,9 +682,9 @@ pub type ForeignCreatorsSovereignAccountOf = (
|
||||
/// 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)])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,7 +716,7 @@ pub mod bridging {
|
||||
pub storage XcmBridgeHubRouterByteFee: Balance = TransactionByteFee::get();
|
||||
|
||||
pub SiblingBridgeHubParaId: u32 = bp_bridge_hub_rococo::BRIDGE_HUB_ROCOCO_PARACHAIN_ID;
|
||||
pub SiblingBridgeHub: MultiLocation = MultiLocation::new(1, X1(Parachain(SiblingBridgeHubParaId::get())));
|
||||
pub SiblingBridgeHub: Location = Location::new(1, [Parachain(SiblingBridgeHubParaId::get())]);
|
||||
/// Router expects payment with this `AssetId`.
|
||||
/// (`AssetId` has to be aligned with `BridgeTable`)
|
||||
pub XcmBridgeHubRouterFeeAssetId: AssetId = TokenLocation::get().into();
|
||||
@@ -722,25 +740,25 @@ pub mod bridging {
|
||||
use super::*;
|
||||
|
||||
parameter_types! {
|
||||
pub SiblingBridgeHubWithBridgeHubWestendInstance: MultiLocation = MultiLocation::new(
|
||||
pub SiblingBridgeHubWithBridgeHubWestendInstance: Location = Location::new(
|
||||
1,
|
||||
X2(
|
||||
[
|
||||
Parachain(SiblingBridgeHubParaId::get()),
|
||||
PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX)
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
pub const WestendNetwork: NetworkId = NetworkId::Westend;
|
||||
pub AssetHubWestend: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(WestendNetwork::get()), Parachain(bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID)));
|
||||
pub WndLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(WestendNetwork::get())));
|
||||
pub AssetHubWestend: Location = Location::new(2, [GlobalConsensus(WestendNetwork::get()), Parachain(bp_asset_hub_westend::ASSET_HUB_WESTEND_PARACHAIN_ID)]);
|
||||
pub WndLocation: Location = Location::new(2, [GlobalConsensus(WestendNetwork::get())]);
|
||||
|
||||
pub WndFromAssetHubWestend: (MultiAssetFilter, MultiLocation) = (
|
||||
Wild(AllOf { fun: WildFungible, id: Concrete(WndLocation::get()) }),
|
||||
pub WndFromAssetHubWestend: (AssetFilter, Location) = (
|
||||
Wild(AllOf { fun: WildFungible, id: AssetId(WndLocation::get()) }),
|
||||
AssetHubWestend::get()
|
||||
);
|
||||
|
||||
/// Set up exporters configuration.
|
||||
/// `Option<MultiAsset>` represents static "base fee" which is used for total delivery fee calculation.
|
||||
/// `Option<Asset>` represents static "base fee" which is used for total delivery fee calculation.
|
||||
pub BridgeTable: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec![
|
||||
NetworkExportTableItem::new(
|
||||
WestendNetwork::get(),
|
||||
@@ -757,15 +775,15 @@ pub mod bridging {
|
||||
];
|
||||
|
||||
/// Universal aliases
|
||||
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
|
||||
pub UniversalAliases: BTreeSet<(Location, Junction)> = BTreeSet::from_iter(
|
||||
sp_std::vec![
|
||||
(SiblingBridgeHubWithBridgeHubWestendInstance::get(), GlobalConsensus(WestendNetwork::get()))
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
impl Contains<(MultiLocation, Junction)> for UniversalAliases {
|
||||
fn contains(alias: &(MultiLocation, Junction)) -> bool {
|
||||
impl Contains<(Location, Junction)> for UniversalAliases {
|
||||
fn contains(alias: &(Location, Junction)) -> bool {
|
||||
UniversalAliases::get().contains(alias)
|
||||
}
|
||||
}
|
||||
@@ -804,16 +822,16 @@ pub mod bridging {
|
||||
/// Polkadot uses 10 decimals, Kusama and Rococo 12 decimals.
|
||||
pub const DefaultBridgeHubEthereumBaseFee: Balance = 2_750_872_500_000;
|
||||
pub storage BridgeHubEthereumBaseFee: Balance = DefaultBridgeHubEthereumBaseFee::get();
|
||||
pub SiblingBridgeHubWithEthereumInboundQueueInstance: MultiLocation = MultiLocation::new(
|
||||
pub SiblingBridgeHubWithEthereumInboundQueueInstance: Location = Location::new(
|
||||
1,
|
||||
X2(
|
||||
[
|
||||
Parachain(SiblingBridgeHubParaId::get()),
|
||||
PalletInstance(parachains_common::rococo::snowbridge::INBOUND_QUEUE_PALLET_INDEX)
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
/// Set up exporters configuration.
|
||||
/// `Option<MultiAsset>` represents static "base fee" which is used for total delivery fee calculation.
|
||||
/// `Option<Asset>` represents static "base fee" which is used for total delivery fee calculation.
|
||||
pub BridgeTable: sp_std::vec::Vec<NetworkExportTableItem> = sp_std::vec![
|
||||
NetworkExportTableItem::new(
|
||||
EthereumNetwork::get(),
|
||||
@@ -827,7 +845,7 @@ pub mod bridging {
|
||||
];
|
||||
|
||||
/// Universal aliases
|
||||
pub UniversalAliases: BTreeSet<(MultiLocation, Junction)> = BTreeSet::from_iter(
|
||||
pub UniversalAliases: BTreeSet<(Location, Junction)> = BTreeSet::from_iter(
|
||||
sp_std::vec![
|
||||
(SiblingBridgeHubWithEthereumInboundQueueInstance::get(), GlobalConsensus(EthereumNetwork::get())),
|
||||
]
|
||||
@@ -837,8 +855,8 @@ pub mod bridging {
|
||||
pub type IsTrustedBridgedReserveLocationForForeignAsset =
|
||||
matching::IsForeignConcreteAsset<FromNetwork<UniversalLocation, EthereumNetwork>>;
|
||||
|
||||
impl Contains<(MultiLocation, Junction)> for UniversalAliases {
|
||||
fn contains(alias: &(MultiLocation, Junction)) -> bool {
|
||||
impl Contains<(Location, Junction)> for UniversalAliases {
|
||||
fn contains(alias: &(Location, Junction)) -> bool {
|
||||
UniversalAliases::get().contains(alias)
|
||||
}
|
||||
}
|
||||
@@ -850,7 +868,7 @@ pub mod bridging {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl BridgingBenchmarksHelper {
|
||||
pub fn prepare_universal_alias() -> Option<(MultiLocation, Junction)> {
|
||||
pub fn prepare_universal_alias() -> Option<(Location, Junction)> {
|
||||
let alias =
|
||||
to_westend::UniversalAliases::get()
|
||||
.into_iter()
|
||||
|
||||
Reference in New Issue
Block a user