frequency_runtime/xcm/location_converter.rs
1use crate::{AccountId, RuntimeOrigin};
2use pallet_xcm::XcmPassthrough;
3use polkadot_parachain_primitives::primitives::Sibling;
4use staging_xcm_builder::{
5 AccountId32Aliases, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
6 SiblingParachainConvertsVia, SignedAccountId32AsNative, SovereignSignedViaLocation,
7};
8
9use super::parameters::{RelayChainOrigin, RelayNetwork};
10
11/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used
12/// when determining ownership of accounts for asset transacting and when attempting to use XCM
13/// `Transact` in order to determine the dispatch Origin.
14/// Conversions between Multilocation to an accountid
15/// Parachain origin is converted to corresponding sovereign account
16pub type LocationToAccountId = (
17 // The parent (Relay-chain) origin converts to the parent `AccountId`.
18 ParentIsPreset<AccountId>,
19 // Sibling parachain origins convert to AccountId via the `ParaId::into`.
20 SiblingParachainConvertsVia<Sibling, AccountId>,
21 // Straight up local `AccountId32` origins just alias directly to `AccountId`.
22 AccountId32Aliases<RelayNetwork, AccountId>,
23);
24
25/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
26/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can
27/// biases the kind of local `Origin` it will become.
28/// Converts an incoming XCM origin into a local `RuntimeOrigin` for `Transact` dispatch.
29pub type XcmOriginToTransactDispatchOrigin = (
30 // Sovereign account converter; this attempts to derive an `AccountId` from the origin location
31 // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for
32 // foreign chains who want to have a local sovereign account on this chain which they control.
33 SovereignSignedViaLocation<LocationToAccountId, RuntimeOrigin>,
34 // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when
35 // recognized.
36 RelayChainAsNative<RelayChainOrigin, RuntimeOrigin>,
37 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when
38 // recognized.
39 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,
40 // Native signed account converter; this just converts an `AccountId32` origin into a normal
41 // `RuntimeOrigin::Signed` origin of the same 32-byte value.
42 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,
43 // Xcm origins can be represented natively under the Xcm pallet's Xcm origin.
44 XcmPassthrough<RuntimeOrigin>,
45);
46
47/// Converts a local signed origin into an XCM location. Forms the basis for local origins
48/// sending/executing XCMs.
49/// Converts a local signed origin into a `MultiLocation` for outbound XCMs.
50pub type LocalOriginToLocation =
51 staging_xcm_builder::SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;