mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41:03 +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
@@ -38,7 +38,7 @@ use frame_support::weights::Weight;
|
||||
use pallet_bridge_messages::benchmarking::{MessageDeliveryProofParams, MessageProofParams};
|
||||
use sp_runtime::traits::{Header, Zero};
|
||||
use sp_std::prelude::*;
|
||||
use xcm::v3::prelude::*;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
/// Prepare inbound bridge message according to given message proof parameters.
|
||||
fn prepare_inbound_message(
|
||||
@@ -266,19 +266,19 @@ where
|
||||
/// Returns callback which generates `BridgeMessage` from Polkadot XCM builder based on
|
||||
/// `expected_message_size` for benchmark.
|
||||
pub fn generate_xcm_builder_bridge_message_sample(
|
||||
destination: InteriorMultiLocation,
|
||||
destination: InteriorLocation,
|
||||
) -> impl Fn(usize) -> MessagePayload {
|
||||
move |expected_message_size| -> MessagePayload {
|
||||
// For XCM bridge hubs, it is the message that
|
||||
// will be pushed further to some XCM queue (XCMP/UMP)
|
||||
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
|
||||
let location = xcm::VersionedInteriorLocation::V4(destination.clone());
|
||||
let location_encoded_size = location.encoded_size();
|
||||
|
||||
// we don't need to be super-precise with `expected_size` here
|
||||
let xcm_size = expected_message_size.saturating_sub(location_encoded_size);
|
||||
let xcm_data_size = xcm_size.saturating_sub(
|
||||
// minus empty instruction size
|
||||
xcm::v3::Instruction::<()>::ExpectPallet {
|
||||
Instruction::<()>::ExpectPallet {
|
||||
index: 0,
|
||||
name: vec![],
|
||||
module_name: vec![],
|
||||
@@ -294,8 +294,8 @@ pub fn generate_xcm_builder_bridge_message_sample(
|
||||
expected_message_size, location_encoded_size, xcm_size, xcm_data_size,
|
||||
);
|
||||
|
||||
let xcm = xcm::VersionedXcm::<()>::V3(
|
||||
vec![xcm::v3::Instruction::<()>::ExpectPallet {
|
||||
let xcm = xcm::VersionedXcm::<()>::V4(
|
||||
vec![Instruction::<()>::ExpectPallet {
|
||||
index: 0,
|
||||
name: vec![42; xcm_data_size],
|
||||
module_name: vec![],
|
||||
|
||||
@@ -123,14 +123,14 @@ impl<
|
||||
#[cfg_attr(feature = "std", derive(Debug, Eq, PartialEq))]
|
||||
pub struct SenderAndLane {
|
||||
/// Sending chain relative location.
|
||||
pub location: MultiLocation,
|
||||
pub location: Location,
|
||||
/// Message lane, used by the sending chain.
|
||||
pub lane: LaneId,
|
||||
}
|
||||
|
||||
impl SenderAndLane {
|
||||
/// Create new object using provided location and lane.
|
||||
pub fn new(location: MultiLocation, lane: LaneId) -> Self {
|
||||
pub fn new(location: Location, lane: LaneId) -> Self {
|
||||
SenderAndLane { location, lane }
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ pub struct XcmBlobHaulerAdapter<XcmBlobHauler, Lanes>(
|
||||
|
||||
impl<
|
||||
H: XcmBlobHauler,
|
||||
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>,
|
||||
Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>,
|
||||
> OnMessagesDelivered for XcmBlobHaulerAdapter<H, Lanes>
|
||||
{
|
||||
fn on_messages_delivered(lane: LaneId, enqueued_messages: MessageNonce) {
|
||||
@@ -288,7 +288,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
/// Send congested signal to the `sending_chain_location`.
|
||||
fn send_congested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
|
||||
if let Some(msg) = H::CongestedMessage::get() {
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
|
||||
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::insert(
|
||||
sender_and_lane.lane,
|
||||
true,
|
||||
@@ -300,7 +300,7 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
/// Send `uncongested` signal to the `sending_chain_location`.
|
||||
fn send_uncongested_signal(sender_and_lane: &SenderAndLane) -> Result<(), SendError> {
|
||||
if let Some(msg) = H::UncongestedMessage::get() {
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location, msg)?;
|
||||
send_xcm::<H::ToSourceChainSender>(sender_and_lane.location.clone(), msg)?;
|
||||
OutboundLanesCongestedSignals::<H::Runtime, H::MessagesInstance>::remove(
|
||||
sender_and_lane.lane,
|
||||
);
|
||||
@@ -315,10 +315,10 @@ impl<H: XcmBlobHauler> LocalXcmQueueManager<H> {
|
||||
pub struct XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>(
|
||||
sp_std::marker::PhantomData<(Version, RemoteBridge)>,
|
||||
);
|
||||
impl<Version: GetVersion, RemoteBridge: Get<MultiLocation>> GetVersion
|
||||
impl<Version: GetVersion, RemoteBridge: Get<Location>> GetVersion
|
||||
for XcmVersionOfDestAndRemoteBridge<Version, RemoteBridge>
|
||||
{
|
||||
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
|
||||
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
|
||||
let dest_version = Version::get_version_for(dest);
|
||||
let bridge_hub_version = Version::get_version_for(&RemoteBridge::get());
|
||||
|
||||
@@ -342,11 +342,11 @@ mod tests {
|
||||
|
||||
parameter_types! {
|
||||
pub TestSenderAndLane: SenderAndLane = SenderAndLane {
|
||||
location: MultiLocation::new(1, X1(Parachain(1000))),
|
||||
location: Location::new(1, [Parachain(1000)]),
|
||||
lane: TEST_LANE_ID,
|
||||
};
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorMultiLocation::Here))
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (NetworkId::ByGenesis([0; 32]), InteriorLocation::Here))
|
||||
];
|
||||
pub DummyXcmMessage: Xcm<()> = Xcm::new();
|
||||
}
|
||||
@@ -363,7 +363,7 @@ mod tests {
|
||||
type Ticket = ();
|
||||
|
||||
fn validate(
|
||||
_destination: &mut Option<MultiLocation>,
|
||||
_destination: &mut Option<Location>,
|
||||
_message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok(((), Default::default()))
|
||||
|
||||
@@ -37,10 +37,10 @@ pub trait Config<I: 'static>: crate::Config<I> {
|
||||
/// Returns destination which is valid for this router instance.
|
||||
/// (Needs to pass `T::Bridges`)
|
||||
/// Make sure that `SendXcm` will pass.
|
||||
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
Ok(MultiLocation::new(
|
||||
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError> {
|
||||
Ok(Location::new(
|
||||
Self::UniversalLocation::get().len() as u8,
|
||||
X1(GlobalConsensus(Self::BridgedNetworkId::get().unwrap())),
|
||||
[GlobalConsensus(Self::BridgedNetworkId::get().unwrap())],
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ pub mod pallet {
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
/// Universal location of this runtime.
|
||||
type UniversalLocation: Get<InteriorMultiLocation>;
|
||||
type UniversalLocation: Get<InteriorLocation>;
|
||||
/// The bridged network that this config is for if specified.
|
||||
/// Also used for filtering `Bridges` by `BridgedNetworkId`.
|
||||
/// If not specified, allows all networks pass through.
|
||||
@@ -235,9 +235,9 @@ type ViaBridgeHubExporter<T, I> = SovereignPaidRemoteExporter<
|
||||
impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
|
||||
fn exporter_for(
|
||||
network: &NetworkId,
|
||||
remote_location: &InteriorMultiLocation,
|
||||
remote_location: &InteriorLocation,
|
||||
message: &Xcm<()>,
|
||||
) -> Option<(MultiLocation, Option<MultiAsset>)> {
|
||||
) -> Option<(Location, Option<Asset>)> {
|
||||
// ensure that the message is sent to the expected bridged network (if specified).
|
||||
if let Some(bridged_network) = T::BridgedNetworkId::get() {
|
||||
if *network != bridged_network {
|
||||
@@ -268,7 +268,7 @@ impl<T: Config<I>, I: 'static> ExporterFor for Pallet<T, I> {
|
||||
// take `base_fee` from `T::Brides`, but it has to be the same `T::FeeAsset`
|
||||
let base_fee = match maybe_payment {
|
||||
Some(payment) => match payment {
|
||||
MultiAsset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
|
||||
Asset { fun: Fungible(amount), id } if id.eq(&T::FeeAsset::get()) => amount,
|
||||
invalid_asset => {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
@@ -318,7 +318,7 @@ impl<T: Config<I>, I: 'static> SendXcm for Pallet<T, I> {
|
||||
type Ticket = (u32, <T::ToBridgeHubSender as SendXcm>::Ticket);
|
||||
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
dest: &mut Option<Location>,
|
||||
xcm: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
// `dest` and `xcm` are required here
|
||||
@@ -446,7 +446,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_eq!(
|
||||
send_xcm::<XcmBridgeHubRouter>(
|
||||
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
|
||||
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
|
||||
vec![].into(),
|
||||
),
|
||||
Err(SendError::NotApplicable),
|
||||
@@ -459,7 +459,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
assert_eq!(
|
||||
send_xcm::<XcmBridgeHubRouter>(
|
||||
MultiLocation::new(2, X2(GlobalConsensus(Rococo), Parachain(1000))),
|
||||
Location::new(2, [GlobalConsensus(Rococo), Parachain(1000)]),
|
||||
vec![ClearOrigin; HARD_MESSAGE_SIZE_LIMIT as usize].into(),
|
||||
),
|
||||
Err(SendError::ExceedsMaxMessageSize),
|
||||
@@ -483,14 +483,14 @@ mod tests {
|
||||
#[test]
|
||||
fn returns_proper_delivery_price() {
|
||||
run_test(|| {
|
||||
let dest = MultiLocation::new(2, X1(GlobalConsensus(BridgedNetworkId::get())));
|
||||
let dest = Location::new(2, [GlobalConsensus(BridgedNetworkId::get())]);
|
||||
let xcm: Xcm<()> = vec![ClearOrigin].into();
|
||||
let msg_size = xcm.encoded_size();
|
||||
|
||||
// initially the base fee is used: `BASE_FEE + BYTE_FEE * msg_size + HRMP_FEE`
|
||||
let expected_fee = BASE_FEE + BYTE_FEE * (msg_size as u128) + HRMP_FEE;
|
||||
assert_eq!(
|
||||
XcmBridgeHubRouter::validate(&mut Some(dest), &mut Some(xcm.clone()))
|
||||
XcmBridgeHubRouter::validate(&mut Some(dest.clone()), &mut Some(xcm.clone()))
|
||||
.unwrap()
|
||||
.1
|
||||
.get(0),
|
||||
@@ -518,10 +518,7 @@ mod tests {
|
||||
run_test(|| {
|
||||
let old_bridge = XcmBridgeHubRouter::bridge();
|
||||
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
|
||||
MultiLocation::new(
|
||||
2,
|
||||
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
|
||||
),
|
||||
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
|
||||
vec![ClearOrigin].into(),
|
||||
)
|
||||
.map(drop));
|
||||
@@ -538,10 +535,7 @@ mod tests {
|
||||
|
||||
let old_bridge = XcmBridgeHubRouter::bridge();
|
||||
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
|
||||
MultiLocation::new(
|
||||
2,
|
||||
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
|
||||
),
|
||||
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
|
||||
vec![ClearOrigin].into(),
|
||||
)
|
||||
.map(drop));
|
||||
@@ -560,10 +554,7 @@ mod tests {
|
||||
|
||||
let old_bridge = XcmBridgeHubRouter::bridge();
|
||||
assert_ok!(send_xcm::<XcmBridgeHubRouter>(
|
||||
MultiLocation::new(
|
||||
2,
|
||||
X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(1000))
|
||||
),
|
||||
Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(1000)]),
|
||||
vec![ClearOrigin].into(),
|
||||
)
|
||||
.map(drop));
|
||||
|
||||
@@ -49,9 +49,9 @@ construct_runtime! {
|
||||
parameter_types! {
|
||||
pub ThisNetworkId: NetworkId = Polkadot;
|
||||
pub BridgedNetworkId: NetworkId = Kusama;
|
||||
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(ThisNetworkId::get()), Parachain(1000));
|
||||
pub SiblingBridgeHubLocation: MultiLocation = ParentThen(X1(Parachain(1002))).into();
|
||||
pub BridgeFeeAsset: AssetId = MultiLocation::parent().into();
|
||||
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ThisNetworkId::get()), Parachain(1000)].into();
|
||||
pub SiblingBridgeHubLocation: Location = ParentThen([Parachain(1002)].into()).into();
|
||||
pub BridgeFeeAsset: AssetId = Location::parent().into();
|
||||
pub BridgeTable: Vec<NetworkExportTableItem>
|
||||
= vec![
|
||||
NetworkExportTableItem::new(
|
||||
@@ -61,7 +61,7 @@ parameter_types! {
|
||||
Some((BridgeFeeAsset::get(), BASE_FEE).into())
|
||||
)
|
||||
];
|
||||
pub UnknownXcmVersionLocation: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)));
|
||||
pub UnknownXcmVersionLocation: Location = Location::new(2, [GlobalConsensus(BridgedNetworkId::get()), Parachain(9999)]);
|
||||
}
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
@@ -87,11 +87,11 @@ impl pallet_xcm_bridge_hub_router::Config<()> for TestRuntime {
|
||||
}
|
||||
|
||||
pub struct LatestOrNoneForLocationVersionChecker<Location>(sp_std::marker::PhantomData<Location>);
|
||||
impl<Location: Contains<MultiLocation>> GetVersion
|
||||
for LatestOrNoneForLocationVersionChecker<Location>
|
||||
impl<LocationValue: Contains<Location>> GetVersion
|
||||
for LatestOrNoneForLocationVersionChecker<LocationValue>
|
||||
{
|
||||
fn get_version_for(dest: &MultiLocation) -> Option<XcmVersion> {
|
||||
if Location::contains(dest) {
|
||||
fn get_version_for(dest: &Location) -> Option<XcmVersion> {
|
||||
if LocationValue::contains(dest) {
|
||||
return None
|
||||
}
|
||||
Some(XCM_VERSION)
|
||||
@@ -110,7 +110,7 @@ impl SendXcm for TestToBridgeHubSender {
|
||||
type Ticket = ();
|
||||
|
||||
fn validate(
|
||||
_destination: &mut Option<MultiLocation>,
|
||||
_destination: &mut Option<Location>,
|
||||
_message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok(((), (BridgeFeeAsset::get(), HRMP_FEE).into()))
|
||||
|
||||
@@ -52,10 +52,10 @@ where
|
||||
fn validate(
|
||||
network: NetworkId,
|
||||
channel: u32,
|
||||
universal_source: &mut Option<InteriorMultiLocation>,
|
||||
destination: &mut Option<InteriorMultiLocation>,
|
||||
universal_source: &mut Option<InteriorLocation>,
|
||||
destination: &mut Option<InteriorLocation>,
|
||||
message: &mut Option<Xcm<()>>,
|
||||
) -> Result<(Self::Ticket, MultiAssets), SendError> {
|
||||
) -> Result<(Self::Ticket, Assets), SendError> {
|
||||
// Find supported lane_id.
|
||||
let sender_and_lane = Self::lane_for(
|
||||
universal_source.as_ref().ok_or(SendError::MissingArgument)?,
|
||||
@@ -137,11 +137,11 @@ mod tests {
|
||||
use frame_support::assert_ok;
|
||||
use xcm_executor::traits::export_xcm;
|
||||
|
||||
fn universal_source() -> InteriorMultiLocation {
|
||||
X2(GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID))
|
||||
fn universal_source() -> InteriorLocation {
|
||||
[GlobalConsensus(RelayNetwork::get()), Parachain(SIBLING_ASSET_HUB_ID)].into()
|
||||
}
|
||||
|
||||
fn universal_destination() -> InteriorMultiLocation {
|
||||
fn universal_destination() -> InteriorLocation {
|
||||
BridgedDestination::get()
|
||||
}
|
||||
|
||||
|
||||
@@ -45,25 +45,25 @@ pub mod pallet {
|
||||
BridgeMessagesConfig<Self::BridgeMessagesPalletInstance>
|
||||
{
|
||||
/// Runtime's universal location.
|
||||
type UniversalLocation: Get<InteriorMultiLocation>;
|
||||
type UniversalLocation: Get<InteriorLocation>;
|
||||
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1666 remove `ChainId` and
|
||||
// replace it with the `NetworkId` - then we'll be able to use
|
||||
// `T as pallet_bridge_messages::Config<T::BridgeMessagesPalletInstance>::BridgedChain::NetworkId`
|
||||
/// Bridged network as relative location of bridged `GlobalConsensus`.
|
||||
#[pallet::constant]
|
||||
type BridgedNetwork: Get<MultiLocation>;
|
||||
type BridgedNetwork: Get<Location>;
|
||||
/// Associated messages pallet instance that bridges us with the
|
||||
/// `BridgedNetworkId` consensus.
|
||||
type BridgeMessagesPalletInstance: 'static;
|
||||
|
||||
/// Price of single message export to the bridged consensus (`Self::BridgedNetworkId`).
|
||||
type MessageExportPrice: Get<MultiAssets>;
|
||||
type MessageExportPrice: Get<Assets>;
|
||||
/// Checks the XCM version for the destination.
|
||||
type DestinationVersion: GetVersion;
|
||||
|
||||
/// Get point-to-point links with bridged consensus (`Self::BridgedNetworkId`).
|
||||
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
|
||||
type Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))>>;
|
||||
type Lanes: Get<sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))>>;
|
||||
/// Support for point-to-point links
|
||||
/// (this will be replaced with dynamic on-chain bridges - `Bridges V2`)
|
||||
type LanesSupport: XcmBlobHauler;
|
||||
@@ -86,10 +86,10 @@ pub mod pallet {
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
/// Returns dedicated/configured lane identifier.
|
||||
pub(crate) fn lane_for(
|
||||
source: &InteriorMultiLocation,
|
||||
dest: (&NetworkId, &InteriorMultiLocation),
|
||||
source: &InteriorLocation,
|
||||
dest: (&NetworkId, &InteriorLocation),
|
||||
) -> Option<SenderAndLane> {
|
||||
let source = source.relative_to(&T::UniversalLocation::get());
|
||||
let source = source.clone().relative_to(&T::UniversalLocation::get());
|
||||
|
||||
// Check that we have configured a point-to-point lane for 'source' and `dest`.
|
||||
T::Lanes::get()
|
||||
|
||||
@@ -170,16 +170,13 @@ impl pallet_bridge_messages::WeightInfoExt for TestMessagesWeights {
|
||||
parameter_types! {
|
||||
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
|
||||
pub const BridgedRelayNetwork: NetworkId = NetworkId::Polkadot;
|
||||
pub const BridgedRelayNetworkLocation: MultiLocation = MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(GlobalConsensus(BridgedRelayNetwork::get()))
|
||||
};
|
||||
pub BridgedRelayNetworkLocation: Location = (Parent, GlobalConsensus(BridgedRelayNetwork::get())).into();
|
||||
pub const NonBridgedRelayNetwork: NetworkId = NetworkId::Rococo;
|
||||
pub const BridgeReserve: Balance = 100_000;
|
||||
pub UniversalLocation: InteriorMultiLocation = X2(
|
||||
pub UniversalLocation: InteriorLocation = [
|
||||
GlobalConsensus(RelayNetwork::get()),
|
||||
Parachain(THIS_BRIDGE_HUB_ID),
|
||||
);
|
||||
].into();
|
||||
pub const Penalty: Balance = 1_000;
|
||||
}
|
||||
|
||||
@@ -197,13 +194,13 @@ impl pallet_xcm_bridge_hub::Config for TestRuntime {
|
||||
|
||||
parameter_types! {
|
||||
pub TestSenderAndLane: SenderAndLane = SenderAndLane {
|
||||
location: MultiLocation::new(1, X1(Parachain(SIBLING_ASSET_HUB_ID))),
|
||||
location: Location::new(1, [Parachain(SIBLING_ASSET_HUB_ID)]),
|
||||
lane: TEST_LANE_ID,
|
||||
};
|
||||
pub const BridgedDestination: InteriorMultiLocation = X1(
|
||||
pub BridgedDestination: InteriorLocation = [
|
||||
Parachain(BRIDGED_ASSET_HUB_ID)
|
||||
);
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
].into();
|
||||
pub TestLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(TestSenderAndLane::get(), (BridgedRelayNetwork::get(), BridgedDestination::get()))
|
||||
];
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ use scale_info::TypeInfo;
|
||||
use sp_core::{H160, H256};
|
||||
use sp_std::{convert::TryFrom, vec};
|
||||
use xcm::prelude::{
|
||||
send_xcm, Instruction::SetTopic, Junction::*, Junctions::*, MultiLocation,
|
||||
SendError as XcmpSendError, SendXcm, Xcm, XcmContext, XcmHash,
|
||||
send_xcm, Instruction::SetTopic, Junction::*, Location, SendError as XcmpSendError, SendXcm,
|
||||
Xcm, XcmContext, XcmHash,
|
||||
};
|
||||
use xcm_executor::traits::TransactAsset;
|
||||
|
||||
@@ -324,7 +324,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
pub fn send_xcm(xcm: Xcm<()>, dest: ParaId) -> Result<XcmHash, Error<T>> {
|
||||
let dest = MultiLocation { parents: 1, interior: X1(Parachain(dest.into())) };
|
||||
let dest = Location::new(1, [Parachain(dest.into())]);
|
||||
let (xcm_hash, _) = send_xcm::<T::XcmSender>(dest, xcm).map_err(Error::<T>::from)?;
|
||||
Ok(xcm_hash)
|
||||
}
|
||||
@@ -341,8 +341,8 @@ pub mod pallet {
|
||||
pub fn burn_fees(para_id: ParaId, fee: BalanceOf<T>) -> DispatchResult {
|
||||
let dummy_context =
|
||||
XcmContext { origin: None, message_id: Default::default(), topic: None };
|
||||
let dest = MultiLocation { parents: 1, interior: X1(Parachain(para_id.into())) };
|
||||
let fees = (MultiLocation::parent(), fee.saturated_into::<u128>()).into();
|
||||
let dest = Location::new(1, [Parachain(para_id.into())]);
|
||||
let fees = (Location::parent(), fee.saturated_into::<u128>()).into();
|
||||
T::AssetTransactor::can_check_out(&dest, &fees, &dummy_context).map_err(|error| {
|
||||
log::error!(
|
||||
target: LOG_TARGET,
|
||||
|
||||
@@ -21,8 +21,8 @@ use sp_runtime::{
|
||||
BuildStorage, FixedU128, MultiSignature,
|
||||
};
|
||||
use sp_std::convert::From;
|
||||
use xcm::v3::{prelude::*, MultiAssets, SendXcm};
|
||||
use xcm_executor::Assets;
|
||||
use xcm::v4::{prelude::*, SendXcm};
|
||||
use xcm_executor::AssetsInHolding;
|
||||
|
||||
use crate::{self as inbound_queue};
|
||||
|
||||
@@ -155,17 +155,16 @@ impl SendXcm for MockXcmSender {
|
||||
type Ticket = Xcm<()>;
|
||||
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
xcm: &mut Option<xcm::v3::Xcm<()>>,
|
||||
dest: &mut Option<Location>,
|
||||
xcm: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
match dest {
|
||||
Some(MultiLocation { interior, .. }) => {
|
||||
if let X1(Parachain(1001)) = interior {
|
||||
return Err(XcmpSendError::NotApplicable)
|
||||
if let Some(location) = dest {
|
||||
match location.unpack() {
|
||||
(_, [Parachain(1001)]) => return Err(XcmpSendError::NotApplicable),
|
||||
_ => Ok((xcm.clone().unwrap(), Assets::default())),
|
||||
}
|
||||
Ok((xcm.clone().unwrap(), MultiAssets::default()))
|
||||
},
|
||||
_ => Ok((xcm.clone().unwrap(), MultiAssets::default())),
|
||||
} else {
|
||||
Ok((xcm.clone().unwrap(), Assets::default()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,45 +202,33 @@ impl StaticLookup for MockChannelLookup {
|
||||
|
||||
pub struct SuccessfulTransactor;
|
||||
impl TransactAsset for SuccessfulTransactor {
|
||||
fn can_check_in(
|
||||
_origin: &MultiLocation,
|
||||
_what: &MultiAsset,
|
||||
_context: &XcmContext,
|
||||
) -> XcmResult {
|
||||
fn can_check_in(_origin: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn can_check_out(
|
||||
_dest: &MultiLocation,
|
||||
_what: &MultiAsset,
|
||||
_context: &XcmContext,
|
||||
) -> XcmResult {
|
||||
fn can_check_out(_dest: &Location, _what: &Asset, _context: &XcmContext) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn deposit_asset(
|
||||
_what: &MultiAsset,
|
||||
_who: &MultiLocation,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> XcmResult {
|
||||
fn deposit_asset(_what: &Asset, _who: &Location, _context: Option<&XcmContext>) -> XcmResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn withdraw_asset(
|
||||
_what: &MultiAsset,
|
||||
_who: &MultiLocation,
|
||||
_what: &Asset,
|
||||
_who: &Location,
|
||||
_context: Option<&XcmContext>,
|
||||
) -> Result<Assets, XcmError> {
|
||||
Ok(Assets::default())
|
||||
) -> Result<AssetsInHolding, XcmError> {
|
||||
Ok(AssetsInHolding::default())
|
||||
}
|
||||
|
||||
fn internal_transfer_asset(
|
||||
_what: &MultiAsset,
|
||||
_from: &MultiLocation,
|
||||
_to: &MultiLocation,
|
||||
_what: &Asset,
|
||||
_from: &Location,
|
||||
_to: &Location,
|
||||
_context: &XcmContext,
|
||||
) -> Result<Assets, XcmError> {
|
||||
Ok(Assets::default())
|
||||
) -> Result<AssetsInHolding, XcmError> {
|
||||
Ok(AssetsInHolding::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ fn test_submit_happy_path() {
|
||||
.into(),
|
||||
nonce: 1,
|
||||
message_id: [
|
||||
27, 217, 88, 127, 46, 143, 199, 70, 236, 66, 212, 244, 85, 221, 153, 104, 175, 37,
|
||||
224, 20, 140, 95, 140, 7, 27, 74, 182, 199, 77, 12, 194, 236,
|
||||
57, 61, 232, 3, 66, 61, 25, 190, 234, 188, 193, 174, 13, 186, 1, 64, 237, 94, 73,
|
||||
83, 14, 18, 209, 213, 78, 121, 43, 108, 251, 245, 107, 67,
|
||||
],
|
||||
fee_burned: 110000000000,
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use snowbridge_core::AgentId;
|
||||
use xcm::VersionedMultiLocation;
|
||||
use xcm::VersionedLocation;
|
||||
|
||||
sp_api::decl_runtime_apis! {
|
||||
pub trait ControlApi
|
||||
{
|
||||
fn agent_id(location: VersionedMultiLocation) -> Option<AgentId>;
|
||||
fn agent_id(location: VersionedLocation) -> Option<AgentId>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
//! Helpers for implementing runtime api
|
||||
|
||||
use snowbridge_core::AgentId;
|
||||
use xcm::{prelude::*, VersionedMultiLocation};
|
||||
use xcm::{prelude::*, VersionedLocation};
|
||||
|
||||
use crate::{agent_id_of, Config};
|
||||
|
||||
pub fn agent_id<Runtime>(location: VersionedMultiLocation) -> Option<AgentId>
|
||||
pub fn agent_id<Runtime>(location: VersionedLocation) -> Option<AgentId>
|
||||
where
|
||||
Runtime: Config,
|
||||
{
|
||||
let location: MultiLocation = location.try_into().ok()?;
|
||||
let location: Location = location.try_into().ok()?;
|
||||
agent_id_of::<Runtime>(&location).ok()
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn create_agent() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
fund_sovereign_account::<T>(origin_para_id.into())?;
|
||||
|
||||
@@ -76,7 +76,7 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn create_channel() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
fund_sovereign_account::<T>(origin_para_id.into())?;
|
||||
|
||||
@@ -91,7 +91,7 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn update_channel() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
fund_sovereign_account::<T>(origin_para_id.into())?;
|
||||
SnowbridgeControl::<T>::create_agent(origin.clone())?;
|
||||
@@ -106,7 +106,7 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn force_update_channel() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
let channel_id: ChannelId = ParaId::from(origin_para_id).into();
|
||||
|
||||
@@ -123,7 +123,7 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn transfer_native_from_agent() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
fund_sovereign_account::<T>(origin_para_id.into())?;
|
||||
SnowbridgeControl::<T>::create_agent(origin.clone())?;
|
||||
@@ -138,12 +138,12 @@ mod benchmarks {
|
||||
#[benchmark]
|
||||
fn force_transfer_native_from_agent() -> Result<(), BenchmarkError> {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin = T::Helper::make_xcm_origin(origin_location);
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let origin = T::Helper::make_xcm_origin(origin_location.clone());
|
||||
fund_sovereign_account::<T>(origin_para_id.into())?;
|
||||
SnowbridgeControl::<T>::create_agent(origin.clone())?;
|
||||
|
||||
let versioned_location: VersionedMultiLocation = origin_location.into();
|
||||
let versioned_location: VersionedLocation = origin_location.into();
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, Box::new(versioned_location), H160::default(), 1);
|
||||
|
||||
@@ -87,12 +87,12 @@ pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
|
||||
pub type PricingParametersOf<T> = PricingParametersRecord<BalanceOf<T>>;
|
||||
|
||||
/// Ensure origin location is a sibling
|
||||
fn ensure_sibling<T>(location: &MultiLocation) -> Result<(ParaId, H256), DispatchError>
|
||||
fn ensure_sibling<T>(location: &Location) -> Result<(ParaId, H256), DispatchError>
|
||||
where
|
||||
T: Config,
|
||||
{
|
||||
match location {
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(para_id)) } => {
|
||||
match location.unpack() {
|
||||
(1, [Parachain(para_id)]) => {
|
||||
let agent_id = agent_id_of::<T>(location)?;
|
||||
Ok(((*para_id).into(), agent_id))
|
||||
},
|
||||
@@ -101,7 +101,7 @@ where
|
||||
}
|
||||
|
||||
/// Hash the location to produce an agent id
|
||||
fn agent_id_of<T: Config>(location: &MultiLocation) -> Result<H256, DispatchError> {
|
||||
fn agent_id_of<T: Config>(location: &Location) -> Result<H256, DispatchError> {
|
||||
T::AgentIdOf::convert_location(location).ok_or(Error::<T>::LocationConversionFailed.into())
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ pub trait BenchmarkHelper<O>
|
||||
where
|
||||
O: OriginTrait,
|
||||
{
|
||||
fn make_xcm_origin(location: MultiLocation) -> O;
|
||||
fn make_xcm_origin(location: Location) -> O;
|
||||
}
|
||||
|
||||
/// Whether a fee should be withdrawn to an account for sending an outbound message
|
||||
@@ -145,9 +145,9 @@ pub mod pallet {
|
||||
type OutboundQueue: SendMessage<Balance = BalanceOf<Self>>;
|
||||
|
||||
/// Origin check for XCM locations that can create agents
|
||||
type SiblingOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = MultiLocation>;
|
||||
type SiblingOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Location>;
|
||||
|
||||
/// Converts MultiLocation to AgentId
|
||||
/// Converts Location to AgentId
|
||||
type AgentIdOf: ConvertLocation<AgentId>;
|
||||
|
||||
/// Token reserved for control operations
|
||||
@@ -180,7 +180,7 @@ pub mod pallet {
|
||||
},
|
||||
/// An CreateAgent message was sent to the Gateway
|
||||
CreateAgent {
|
||||
location: Box<MultiLocation>,
|
||||
location: Box<Location>,
|
||||
agent_id: AgentId,
|
||||
},
|
||||
/// An CreateChannel message was sent to the Gateway
|
||||
@@ -299,7 +299,7 @@ pub mod pallet {
|
||||
///
|
||||
/// Fee required: No
|
||||
///
|
||||
/// - `origin`: Must be `MultiLocation`
|
||||
/// - `origin`: Must be `Location`
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight((T::WeightInfo::set_operating_mode(), DispatchClass::Operational))]
|
||||
pub fn set_operating_mode(origin: OriginFor<T>, mode: OperatingMode) -> DispatchResult {
|
||||
@@ -342,11 +342,11 @@ pub mod pallet {
|
||||
///
|
||||
/// Fee required: Yes
|
||||
///
|
||||
/// - `origin`: Must be `MultiLocation` of a sibling parachain
|
||||
/// - `origin`: Must be `Location` of a sibling parachain
|
||||
#[pallet::call_index(3)]
|
||||
#[pallet::weight(T::WeightInfo::create_agent())]
|
||||
pub fn create_agent(origin: OriginFor<T>) -> DispatchResult {
|
||||
let origin_location: MultiLocation = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
let origin_location: Location = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
|
||||
// Ensure that origin location is some consensus system on a sibling parachain
|
||||
let (para_id, agent_id) = ensure_sibling::<T>(&origin_location)?;
|
||||
@@ -375,12 +375,12 @@ pub mod pallet {
|
||||
///
|
||||
/// The message is sent over the bridge on BridgeHub's own channel to the Gateway.
|
||||
///
|
||||
/// - `origin`: Must be `MultiLocation`
|
||||
/// - `origin`: Must be `Location`
|
||||
/// - `mode`: Initial operating mode of the channel
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight(T::WeightInfo::create_channel())]
|
||||
pub fn create_channel(origin: OriginFor<T>, mode: OperatingMode) -> DispatchResult {
|
||||
let origin_location: MultiLocation = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
let origin_location: Location = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
|
||||
// Ensure that origin location is a sibling parachain
|
||||
let (para_id, agent_id) = ensure_sibling::<T>(&origin_location)?;
|
||||
@@ -407,12 +407,12 @@ pub mod pallet {
|
||||
///
|
||||
/// A partial fee will be charged for local processing only.
|
||||
///
|
||||
/// - `origin`: Must be `MultiLocation`
|
||||
/// - `origin`: Must be `Location`
|
||||
/// - `mode`: Initial operating mode of the channel
|
||||
#[pallet::call_index(5)]
|
||||
#[pallet::weight(T::WeightInfo::update_channel())]
|
||||
pub fn update_channel(origin: OriginFor<T>, mode: OperatingMode) -> DispatchResult {
|
||||
let origin_location: MultiLocation = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
let origin_location: Location = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
|
||||
// Ensure that origin location is a sibling parachain
|
||||
let (para_id, _) = ensure_sibling::<T>(&origin_location)?;
|
||||
@@ -461,7 +461,7 @@ pub mod pallet {
|
||||
///
|
||||
/// A partial fee will be charged for local processing only.
|
||||
///
|
||||
/// - `origin`: Must be `MultiLocation`
|
||||
/// - `origin`: Must be `Location`
|
||||
#[pallet::call_index(7)]
|
||||
#[pallet::weight(T::WeightInfo::transfer_native_from_agent())]
|
||||
pub fn transfer_native_from_agent(
|
||||
@@ -469,7 +469,7 @@ pub mod pallet {
|
||||
recipient: H160,
|
||||
amount: u128,
|
||||
) -> DispatchResult {
|
||||
let origin_location: MultiLocation = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
let origin_location: Location = T::SiblingOrigin::ensure_origin(origin)?;
|
||||
|
||||
// Ensure that origin location is some consensus system on a sibling parachain
|
||||
let (para_id, agent_id) = ensure_sibling::<T>(&origin_location)?;
|
||||
@@ -501,14 +501,14 @@ pub mod pallet {
|
||||
#[pallet::weight(T::WeightInfo::force_transfer_native_from_agent())]
|
||||
pub fn force_transfer_native_from_agent(
|
||||
origin: OriginFor<T>,
|
||||
location: Box<VersionedMultiLocation>,
|
||||
location: Box<VersionedLocation>,
|
||||
recipient: H160,
|
||||
amount: u128,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
|
||||
// Ensure that location is some consensus system on a sibling parachain
|
||||
let location: MultiLocation =
|
||||
let location: Location =
|
||||
(*location).try_into().map_err(|_| Error::<T>::UnsupportedLocationVersion)?;
|
||||
let (_, agent_id) =
|
||||
ensure_sibling::<T>(&location).map_err(|_| Error::<T>::InvalidLocation)?;
|
||||
@@ -621,8 +621,8 @@ pub mod pallet {
|
||||
/// Initializes agents and channels.
|
||||
pub fn initialize(para_id: ParaId, asset_hub_para_id: ParaId) -> Result<(), DispatchError> {
|
||||
// Asset Hub
|
||||
let asset_hub_location: MultiLocation =
|
||||
ParentThen(X1(Parachain(asset_hub_para_id.into()))).into();
|
||||
let asset_hub_location: Location =
|
||||
ParentThen(Parachain(asset_hub_para_id.into()).into()).into();
|
||||
let asset_hub_agent_id = agent_id_of::<T>(&asset_hub_location)?;
|
||||
let asset_hub_channel_id: ChannelId = asset_hub_para_id.into();
|
||||
Agents::<T>::insert(asset_hub_agent_id, ());
|
||||
@@ -632,7 +632,7 @@ pub mod pallet {
|
||||
);
|
||||
|
||||
// Governance channels
|
||||
let bridge_hub_agent_id = agent_id_of::<T>(&MultiLocation::here())?;
|
||||
let bridge_hub_agent_id = agent_id_of::<T>(&Location::here())?;
|
||||
// Agent for BridgeHub
|
||||
Agents::<T>::insert(bridge_hub_agent_id, ());
|
||||
|
||||
|
||||
@@ -49,22 +49,22 @@ mod pallet_xcm_origin {
|
||||
// Insert this custom Origin into the aggregate RuntimeOrigin
|
||||
#[pallet::origin]
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
pub struct Origin(pub MultiLocation);
|
||||
pub struct Origin(pub Location);
|
||||
|
||||
impl From<MultiLocation> for Origin {
|
||||
fn from(location: MultiLocation) -> Origin {
|
||||
impl From<Location> for Origin {
|
||||
fn from(location: Location) -> Origin {
|
||||
Origin(location)
|
||||
}
|
||||
}
|
||||
|
||||
/// `EnsureOrigin` implementation succeeding with a `MultiLocation` value to recognize and
|
||||
/// `EnsureOrigin` implementation succeeding with a `Location` value to recognize and
|
||||
/// filter the contained location
|
||||
pub struct EnsureXcm<F>(PhantomData<F>);
|
||||
impl<O: OriginTrait + From<Origin>, F: Contains<MultiLocation>> EnsureOrigin<O> for EnsureXcm<F>
|
||||
impl<O: OriginTrait + From<Origin>, F: Contains<Location>> EnsureOrigin<O> for EnsureXcm<F>
|
||||
where
|
||||
O::PalletsOrigin: From<Origin> + TryInto<Origin, Error = O::PalletsOrigin>,
|
||||
{
|
||||
type Success = MultiLocation;
|
||||
type Success = Location;
|
||||
|
||||
fn try_origin(outer: O) -> Result<Self::Success, O> {
|
||||
outer.try_with_caller(|caller| {
|
||||
@@ -77,7 +77,7 @@ mod pallet_xcm_origin {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin() -> Result<O, ()> {
|
||||
Ok(O::from(Origin(MultiLocation { parents: 1, interior: X1(Parachain(2000)) })))
|
||||
Ok(O::from(Origin(Location::new(1, [Parachain(2000)]))))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,9 +186,9 @@ parameter_types! {
|
||||
pub const SS58Prefix: u8 = 42;
|
||||
pub const AnyNetwork: Option<NetworkId> = None;
|
||||
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Kusama);
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
pub UniversalLocation: InteriorMultiLocation =
|
||||
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(1013));
|
||||
pub const RelayLocation: Location = Location::parent();
|
||||
pub UniversalLocation: InteriorLocation =
|
||||
[GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(1013)].into();
|
||||
}
|
||||
|
||||
pub const DOT: u128 = 10_000_000_000;
|
||||
@@ -211,7 +211,7 @@ parameter_types! {
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl BenchmarkHelper<RuntimeOrigin> for () {
|
||||
fn make_xcm_origin(location: MultiLocation) -> RuntimeOrigin {
|
||||
fn make_xcm_origin(location: Location) -> RuntimeOrigin {
|
||||
RuntimeOrigin::from(pallet_xcm_origin::Origin(location))
|
||||
}
|
||||
}
|
||||
@@ -260,11 +260,11 @@ pub fn new_test_ext(genesis_build: bool) -> sp_io::TestExternalities {
|
||||
|
||||
// Test helpers
|
||||
|
||||
pub fn make_xcm_origin(location: MultiLocation) -> RuntimeOrigin {
|
||||
pub fn make_xcm_origin(location: Location) -> RuntimeOrigin {
|
||||
pallet_xcm_origin::Origin(location).into()
|
||||
}
|
||||
|
||||
pub fn make_agent_id(location: MultiLocation) -> AgentId {
|
||||
pub fn make_agent_id(location: Location) -> AgentId {
|
||||
<Test as snowbridge_system::Config>::AgentIdOf::convert_location(&location)
|
||||
.expect("convert location")
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ use sp_runtime::{AccountId32, DispatchError::BadOrigin, TokenError};
|
||||
fn create_agent() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let agent_id = make_agent_id(origin_location);
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let agent_id = make_agent_id(origin_location.clone());
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(origin_para_id.into());
|
||||
|
||||
// fund sovereign account of origin
|
||||
@@ -30,7 +30,7 @@ fn create_agent() {
|
||||
#[test]
|
||||
fn test_agent_for_here() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_location = MultiLocation::here();
|
||||
let origin_location = Location::here();
|
||||
let agent_id = make_agent_id(origin_location);
|
||||
assert_eq!(
|
||||
agent_id,
|
||||
@@ -42,7 +42,7 @@ fn test_agent_for_here() {
|
||||
#[test]
|
||||
fn create_agent_fails_on_funds_unavailable() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(2000)) };
|
||||
let origin_location = Location::new(1, [Parachain(2000)]);
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
// Reset balance of sovereign_account to zero so to trigger the FundsUnavailable error
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(2000.into());
|
||||
@@ -56,19 +56,16 @@ fn create_agent_bad_origin() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
// relay chain location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::create_agent(make_xcm_origin(MultiLocation {
|
||||
parents: 1,
|
||||
interior: Here,
|
||||
})),
|
||||
EthereumSystem::create_agent(make_xcm_origin(Location::new(1, [],))),
|
||||
BadOrigin,
|
||||
);
|
||||
|
||||
// local account location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::create_agent(make_xcm_origin(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Junction::AccountId32 { network: None, id: [67u8; 32] }),
|
||||
})),
|
||||
EthereumSystem::create_agent(make_xcm_origin(Location::new(
|
||||
0,
|
||||
[Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
))),
|
||||
BadOrigin,
|
||||
);
|
||||
|
||||
@@ -243,7 +240,7 @@ fn set_token_transfer_fees_invalid() {
|
||||
fn create_channel() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(origin_para_id.into());
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
|
||||
@@ -259,7 +256,7 @@ fn create_channel() {
|
||||
fn create_channel_fail_already_exists() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(origin_para_id.into());
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
|
||||
@@ -282,7 +279,7 @@ fn create_channel_bad_origin() {
|
||||
// relay chain location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::create_channel(
|
||||
make_xcm_origin(MultiLocation { parents: 1, interior: Here }),
|
||||
make_xcm_origin(Location::new(1, [])),
|
||||
OperatingMode::Normal,
|
||||
),
|
||||
BadOrigin,
|
||||
@@ -291,13 +288,10 @@ fn create_channel_bad_origin() {
|
||||
// child of sibling location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::create_channel(
|
||||
make_xcm_origin(MultiLocation {
|
||||
parents: 1,
|
||||
interior: X2(
|
||||
Parachain(2000),
|
||||
Junction::AccountId32 { network: None, id: [67u8; 32] }
|
||||
),
|
||||
}),
|
||||
make_xcm_origin(Location::new(
|
||||
1,
|
||||
[Parachain(2000), Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
)),
|
||||
OperatingMode::Normal,
|
||||
),
|
||||
BadOrigin,
|
||||
@@ -306,10 +300,10 @@ fn create_channel_bad_origin() {
|
||||
// local account location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::create_channel(
|
||||
make_xcm_origin(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Junction::AccountId32 { network: None, id: [67u8; 32] }),
|
||||
}),
|
||||
make_xcm_origin(Location::new(
|
||||
0,
|
||||
[Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
)),
|
||||
OperatingMode::Normal,
|
||||
),
|
||||
BadOrigin,
|
||||
@@ -333,7 +327,7 @@ fn create_channel_bad_origin() {
|
||||
fn update_channel() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(origin_para_id.into());
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
|
||||
@@ -359,23 +353,17 @@ fn update_channel_bad_origin() {
|
||||
|
||||
// relay chain location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::update_channel(
|
||||
make_xcm_origin(MultiLocation { parents: 1, interior: Here }),
|
||||
mode,
|
||||
),
|
||||
EthereumSystem::update_channel(make_xcm_origin(Location::new(1, [])), mode,),
|
||||
BadOrigin,
|
||||
);
|
||||
|
||||
// child of sibling location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::update_channel(
|
||||
make_xcm_origin(MultiLocation {
|
||||
parents: 1,
|
||||
interior: X2(
|
||||
Parachain(2000),
|
||||
Junction::AccountId32 { network: None, id: [67u8; 32] }
|
||||
),
|
||||
}),
|
||||
make_xcm_origin(Location::new(
|
||||
1,
|
||||
[Parachain(2000), Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
)),
|
||||
mode,
|
||||
),
|
||||
BadOrigin,
|
||||
@@ -384,10 +372,10 @@ fn update_channel_bad_origin() {
|
||||
// local account location not allowed
|
||||
assert_noop!(
|
||||
EthereumSystem::update_channel(
|
||||
make_xcm_origin(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(Junction::AccountId32 { network: None, id: [67u8; 32] }),
|
||||
}),
|
||||
make_xcm_origin(Location::new(
|
||||
0,
|
||||
[Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
)),
|
||||
mode,
|
||||
),
|
||||
BadOrigin,
|
||||
@@ -407,7 +395,7 @@ fn update_channel_bad_origin() {
|
||||
#[test]
|
||||
fn update_channel_fails_not_exist() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(2000)) };
|
||||
let origin_location = Location::new(1, [Parachain(2000)]);
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
|
||||
// Now try to update it
|
||||
@@ -422,7 +410,7 @@ fn update_channel_fails_not_exist() {
|
||||
fn force_update_channel() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_para_id = 2000;
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(origin_para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(origin_para_id)]);
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(origin_para_id.into());
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
|
||||
@@ -468,8 +456,8 @@ fn force_update_channel_bad_origin() {
|
||||
#[test]
|
||||
fn transfer_native_from_agent() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(2000)) };
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
let origin_location = Location::new(1, [Parachain(2000)]);
|
||||
let origin = make_xcm_origin(origin_location.clone());
|
||||
let recipient: H160 = [27u8; 20].into();
|
||||
let amount = 103435;
|
||||
|
||||
@@ -477,7 +465,7 @@ fn transfer_native_from_agent() {
|
||||
assert_ok!(EthereumSystem::create_agent(origin.clone()));
|
||||
assert_ok!(EthereumSystem::create_channel(origin, OperatingMode::Normal));
|
||||
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
let origin = make_xcm_origin(origin_location.clone());
|
||||
assert_ok!(EthereumSystem::transfer_native_from_agent(origin, recipient, amount),);
|
||||
|
||||
System::assert_last_event(RuntimeEvent::EthereumSystem(
|
||||
@@ -494,13 +482,13 @@ fn transfer_native_from_agent() {
|
||||
fn force_transfer_native_from_agent() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let origin = RuntimeOrigin::root();
|
||||
let location = MultiLocation { parents: 1, interior: X1(Parachain(2000)) };
|
||||
let versioned_location: Box<VersionedMultiLocation> = Box::new(location.into());
|
||||
let location = Location::new(1, [Parachain(2000)]);
|
||||
let versioned_location: Box<VersionedLocation> = Box::new(location.clone().into());
|
||||
let recipient: H160 = [27u8; 20].into();
|
||||
let amount = 103435;
|
||||
|
||||
// First create the agent
|
||||
Agents::<Test>::insert(make_agent_id(location), ());
|
||||
Agents::<Test>::insert(make_agent_id(location.clone()), ());
|
||||
|
||||
assert_ok!(EthereumSystem::force_transfer_native_from_agent(
|
||||
origin,
|
||||
@@ -530,13 +518,10 @@ fn force_transfer_native_from_agent_bad_origin() {
|
||||
EthereumSystem::force_transfer_native_from_agent(
|
||||
RuntimeOrigin::signed([14; 32].into()),
|
||||
Box::new(
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X2(
|
||||
Parachain(2000),
|
||||
Junction::AccountId32 { network: None, id: [67u8; 32] }
|
||||
),
|
||||
}
|
||||
Location::new(
|
||||
1,
|
||||
[Parachain(2000), Junction::AccountId32 { network: None, id: [67u8; 32] }],
|
||||
)
|
||||
.into()
|
||||
),
|
||||
recipient,
|
||||
@@ -571,8 +556,8 @@ fn check_sibling_sovereign_account() {
|
||||
fn charge_fee_for_create_agent() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let para_id: u32 = TestParaId::get();
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(para_id)) };
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
let origin_location = Location::new(1, [Parachain(para_id)]);
|
||||
let origin = make_xcm_origin(origin_location.clone());
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(para_id.into());
|
||||
let (_, agent_id) = ensure_sibling::<Test>(&origin_location).unwrap();
|
||||
|
||||
@@ -605,10 +590,10 @@ fn charge_fee_for_create_agent() {
|
||||
fn charge_fee_for_transfer_native_from_agent() {
|
||||
new_test_ext(true).execute_with(|| {
|
||||
let para_id: u32 = TestParaId::get();
|
||||
let origin_location = MultiLocation { parents: 1, interior: X1(Parachain(para_id)) };
|
||||
let origin_location = Location::new(1, [Parachain(para_id)]);
|
||||
let recipient: H160 = [27u8; 20].into();
|
||||
let amount = 103435;
|
||||
let origin = make_xcm_origin(origin_location);
|
||||
let origin = make_xcm_origin(origin_location.clone());
|
||||
let (_, agent_id) = ensure_sibling::<Test>(&origin_location).unwrap();
|
||||
|
||||
let sovereign_account = sibling_sovereign_account::<Test>(para_id.into());
|
||||
|
||||
@@ -28,11 +28,7 @@ use sp_core::H256;
|
||||
use sp_io::hashing::keccak_256;
|
||||
use sp_runtime::{traits::AccountIdConversion, RuntimeDebug};
|
||||
use sp_std::prelude::*;
|
||||
use xcm::prelude::{
|
||||
Junction::Parachain,
|
||||
Junctions::{Here, X1},
|
||||
MultiLocation,
|
||||
};
|
||||
use xcm::prelude::{Junction::Parachain, Location};
|
||||
use xcm_builder::{DescribeAllTerminal, DescribeFamily, DescribeLocation, HashedDescription};
|
||||
|
||||
/// The ID of an agent contract
|
||||
@@ -53,9 +49,9 @@ pub fn sibling_sovereign_account_raw(para_id: ParaId) -> [u8; 32] {
|
||||
}
|
||||
|
||||
pub struct AllowSiblingsOnly;
|
||||
impl Contains<MultiLocation> for AllowSiblingsOnly {
|
||||
fn contains(location: &MultiLocation) -> bool {
|
||||
matches!(location, MultiLocation { parents: 1, interior: X1(Parachain(_)) })
|
||||
impl Contains<Location> for AllowSiblingsOnly {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, [Parachain(_)]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,14 +157,14 @@ pub const SECONDARY_GOVERNANCE_CHANNEL: ChannelId =
|
||||
|
||||
pub struct DescribeHere;
|
||||
impl DescribeLocation for DescribeHere {
|
||||
fn describe_location(l: &MultiLocation) -> Option<Vec<u8>> {
|
||||
match (l.parents, l.interior) {
|
||||
(0, Here) => Some(Vec::<u8>::new().encode()),
|
||||
fn describe_location(l: &Location) -> Option<Vec<u8>> {
|
||||
match l.unpack() {
|
||||
(0, []) => Some(Vec::<u8>::new().encode()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates an AgentId from a MultiLocation. An AgentId is a unique mapping to a Agent contract on
|
||||
/// Ethereum which acts as the sovereign account for the MultiLocation.
|
||||
/// Creates an AgentId from a Location. An AgentId is a unique mapping to a Agent contract on
|
||||
/// Ethereum which acts as the sovereign account for the Location.
|
||||
pub type AgentIdOf = HashedDescription<H256, (DescribeHere, DescribeFamily<DescribeAllTerminal>)>;
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
mod tests {
|
||||
use frame_support::traits::Contains;
|
||||
use snowbridge_core::AllowSiblingsOnly;
|
||||
use xcm::prelude::{Junction::Parachain, Junctions::X1, MultiLocation};
|
||||
use xcm::prelude::{Junction::Parachain, Location};
|
||||
|
||||
#[test]
|
||||
fn allow_siblings_predicate_only_allows_siblings() {
|
||||
let sibling = MultiLocation::new(1, X1(Parachain(1000)));
|
||||
let child = MultiLocation::new(0, X1(Parachain(1000)));
|
||||
let sibling = Location::new(1, [Parachain(1000)]);
|
||||
let child = Location::new(0, [Parachain(1000)]);
|
||||
assert!(AllowSiblingsOnly::contains(&sibling), "Sibling returns true.");
|
||||
assert!(!AllowSiblingsOnly::contains(&child), "Child returns false.");
|
||||
}
|
||||
|
||||
@@ -161,13 +161,13 @@ where
|
||||
{
|
||||
fn convert_register_token(chain_id: u64, token: H160, fee: u128) -> (Xcm<()>, Balance) {
|
||||
let network = Ethereum { chain_id };
|
||||
let xcm_fee: MultiAsset = (MultiLocation::parent(), fee).into();
|
||||
let deposit: MultiAsset = (MultiLocation::parent(), CreateAssetDeposit::get()).into();
|
||||
let xcm_fee: Asset = (Location::parent(), fee).into();
|
||||
let deposit: Asset = (Location::parent(), CreateAssetDeposit::get()).into();
|
||||
|
||||
let total_amount = fee + CreateAssetDeposit::get();
|
||||
let total: MultiAsset = (MultiLocation::parent(), total_amount).into();
|
||||
let total: Asset = (Location::parent(), total_amount).into();
|
||||
|
||||
let bridge_location: MultiLocation = (Parent, Parent, GlobalConsensus(network)).into();
|
||||
let bridge_location: Location = (Parent, Parent, GlobalConsensus(network)).into();
|
||||
|
||||
let owner = GlobalConsensusEthereumConvertsFor::<[u8; 32]>::from_chain_id(&chain_id);
|
||||
let asset_id = Self::convert_token_address(network, token);
|
||||
@@ -182,7 +182,7 @@ where
|
||||
// Fund the snowbridge sovereign with the required deposit for creation.
|
||||
DepositAsset { assets: Definite(deposit.into()), beneficiary: bridge_location },
|
||||
// Only our inbound-queue pallet is allowed to invoke `UniversalOrigin`
|
||||
DescendOrigin(X1(PalletInstance(inbound_queue_pallet_index))),
|
||||
DescendOrigin(PalletInstance(inbound_queue_pallet_index).into()),
|
||||
// Change origin to the bridge.
|
||||
UniversalOrigin(GlobalConsensus(network)),
|
||||
// Call create_asset on foreign assets pallet.
|
||||
@@ -216,40 +216,37 @@ where
|
||||
asset_hub_fee: u128,
|
||||
) -> (Xcm<()>, Balance) {
|
||||
let network = Ethereum { chain_id };
|
||||
let asset_hub_fee_asset: MultiAsset = (MultiLocation::parent(), asset_hub_fee).into();
|
||||
let asset: MultiAsset = (Self::convert_token_address(network, token), amount).into();
|
||||
let asset_hub_fee_asset: Asset = (Location::parent(), asset_hub_fee).into();
|
||||
let asset: Asset = (Self::convert_token_address(network, token), amount).into();
|
||||
|
||||
let (dest_para_id, beneficiary, dest_para_fee) = match destination {
|
||||
// Final destination is a 32-byte account on AssetHub
|
||||
Destination::AccountId32 { id } => (
|
||||
None,
|
||||
MultiLocation { parents: 0, interior: X1(AccountId32 { network: None, id }) },
|
||||
0,
|
||||
),
|
||||
Destination::AccountId32 { id } =>
|
||||
(None, Location::new(0, [AccountId32 { network: None, id }]), 0),
|
||||
// Final destination is a 32-byte account on a sibling of AssetHub
|
||||
Destination::ForeignAccountId32 { para_id, id, fee } => (
|
||||
Some(para_id),
|
||||
MultiLocation { parents: 0, interior: X1(AccountId32 { network: None, id }) },
|
||||
Location::new(0, [AccountId32 { network: None, id }]),
|
||||
// Total fee needs to cover execution on AssetHub and Sibling
|
||||
fee,
|
||||
),
|
||||
// Final destination is a 20-byte account on a sibling of AssetHub
|
||||
Destination::ForeignAccountId20 { para_id, id, fee } => (
|
||||
Some(para_id),
|
||||
MultiLocation { parents: 0, interior: X1(AccountKey20 { network: None, key: id }) },
|
||||
Location::new(0, [AccountKey20 { network: None, key: id }]),
|
||||
// Total fee needs to cover execution on AssetHub and Sibling
|
||||
fee,
|
||||
),
|
||||
};
|
||||
|
||||
let total_fees = asset_hub_fee.saturating_add(dest_para_fee);
|
||||
let total_fee_asset: MultiAsset = (MultiLocation::parent(), total_fees).into();
|
||||
let total_fee_asset: Asset = (Location::parent(), total_fees).into();
|
||||
let inbound_queue_pallet_index = InboundQueuePalletInstance::get();
|
||||
|
||||
let mut instructions = vec![
|
||||
ReceiveTeleportedAsset(total_fee_asset.into()),
|
||||
BuyExecution { fees: asset_hub_fee_asset, weight_limit: Unlimited },
|
||||
DescendOrigin(X1(PalletInstance(inbound_queue_pallet_index))),
|
||||
DescendOrigin(PalletInstance(inbound_queue_pallet_index).into()),
|
||||
UniversalOrigin(GlobalConsensus(network)),
|
||||
ReserveAssetDeposited(asset.clone().into()),
|
||||
ClearOrigin,
|
||||
@@ -257,14 +254,13 @@ where
|
||||
|
||||
match dest_para_id {
|
||||
Some(dest_para_id) => {
|
||||
let dest_para_fee_asset: MultiAsset =
|
||||
(MultiLocation::parent(), dest_para_fee).into();
|
||||
let dest_para_fee_asset: Asset = (Location::parent(), dest_para_fee).into();
|
||||
|
||||
instructions.extend(vec![
|
||||
// Perform a deposit reserve to send to destination chain.
|
||||
DepositReserveAsset {
|
||||
assets: Definite(vec![dest_para_fee_asset.clone(), asset.clone()].into()),
|
||||
dest: MultiLocation { parents: 1, interior: X1(Parachain(dest_para_id)) },
|
||||
dest: Location::new(1, [Parachain(dest_para_id)]),
|
||||
xcm: vec![
|
||||
// Buy execution on target.
|
||||
BuyExecution { fees: dest_para_fee_asset, weight_limit: Unlimited },
|
||||
@@ -286,15 +282,12 @@ where
|
||||
(instructions.into(), total_fees.into())
|
||||
}
|
||||
|
||||
// Convert ERC20 token address to a Multilocation that can be understood by Assets Hub.
|
||||
fn convert_token_address(network: NetworkId, token: H160) -> MultiLocation {
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
GlobalConsensus(network),
|
||||
AccountKey20 { network: None, key: token.into() },
|
||||
),
|
||||
}
|
||||
// Convert ERC20 token address to a location that can be understood by Assets Hub.
|
||||
fn convert_token_address(network: NetworkId, token: H160) -> Location {
|
||||
Location::new(
|
||||
2,
|
||||
[GlobalConsensus(network), AccountKey20 { network: None, key: token.into() }],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,12 +296,11 @@ impl<AccountId> ConvertLocation<AccountId> for GlobalConsensusEthereumConvertsFo
|
||||
where
|
||||
AccountId: From<[u8; 32]> + Clone,
|
||||
{
|
||||
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
|
||||
if let MultiLocation { interior: X1(GlobalConsensus(Ethereum { chain_id })), .. } = location
|
||||
{
|
||||
Some(Self::from_chain_id(chain_id).into())
|
||||
} else {
|
||||
None
|
||||
fn convert_location(location: &Location) -> Option<AccountId> {
|
||||
match location.unpack() {
|
||||
(_, [GlobalConsensus(Ethereum { chain_id })]) =>
|
||||
Some(Self::from_chain_id(chain_id).into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::GlobalConsensusEthereumConvertsFor;
|
||||
use crate::inbound::CallIndex;
|
||||
use frame_support::parameter_types;
|
||||
use hex_literal::hex;
|
||||
use xcm::v3::prelude::*;
|
||||
use xcm::v4::prelude::*;
|
||||
use xcm_executor::traits::ConvertLocation;
|
||||
|
||||
const NETWORK: NetworkId = Ethereum { chain_id: 11155111 };
|
||||
@@ -20,7 +20,7 @@ parameter_types! {
|
||||
fn test_contract_location_with_network_converts_successfully() {
|
||||
let expected_account: [u8; 32] =
|
||||
hex!("ce796ae65569a670d0c1cc1ac12515a3ce21b5fbf729d63d7b289baad070139d");
|
||||
let contract_location = MultiLocation { parents: 2, interior: X1(GlobalConsensus(NETWORK)) };
|
||||
let contract_location = Location::new(2, [GlobalConsensus(NETWORK)]);
|
||||
|
||||
let account =
|
||||
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location)
|
||||
@@ -31,8 +31,7 @@ fn test_contract_location_with_network_converts_successfully() {
|
||||
|
||||
#[test]
|
||||
fn test_contract_location_with_incorrect_location_fails_convert() {
|
||||
let contract_location =
|
||||
MultiLocation { parents: 2, interior: X2(GlobalConsensus(Polkadot), Parachain(1000)) };
|
||||
let contract_location = Location::new(2, [GlobalConsensus(Polkadot), Parachain(1000)]);
|
||||
|
||||
assert_eq!(
|
||||
GlobalConsensusEthereumConvertsFor::<[u8; 32]>::convert_location(&contract_location),
|
||||
|
||||
@@ -16,7 +16,7 @@ use snowbridge_core::{
|
||||
};
|
||||
use sp_core::{H160, H256};
|
||||
use sp_std::{iter::Peekable, marker::PhantomData, prelude::*};
|
||||
use xcm::v3::prelude::*;
|
||||
use xcm::v4::prelude::*;
|
||||
use xcm_executor::traits::{ConvertLocation, ExportXcm};
|
||||
|
||||
pub struct EthereumBlobExporter<
|
||||
@@ -29,7 +29,7 @@ pub struct EthereumBlobExporter<
|
||||
impl<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription> ExportXcm
|
||||
for EthereumBlobExporter<UniversalLocation, EthereumNetwork, OutboundQueue, AgentHashedDescription>
|
||||
where
|
||||
UniversalLocation: Get<InteriorMultiLocation>,
|
||||
UniversalLocation: Get<InteriorLocation>,
|
||||
EthereumNetwork: Get<NetworkId>,
|
||||
OutboundQueue: SendMessage<Balance = u128>,
|
||||
AgentHashedDescription: ConvertLocation<H256>,
|
||||
@@ -39,8 +39,8 @@ where
|
||||
fn validate(
|
||||
network: NetworkId,
|
||||
_channel: u32,
|
||||
universal_source: &mut Option<InteriorMultiLocation>,
|
||||
destination: &mut Option<InteriorMultiLocation>,
|
||||
universal_source: &mut Option<InteriorLocation>,
|
||||
destination: &mut Option<InteriorLocation>,
|
||||
message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
let expected_network = EthereumNetwork::get();
|
||||
@@ -74,8 +74,8 @@ where
|
||||
return Err(SendError::NotApplicable)
|
||||
}
|
||||
|
||||
let para_id = match local_sub {
|
||||
X1(Parachain(para_id)) => para_id,
|
||||
let para_id = match local_sub.as_slice() {
|
||||
[Parachain(para_id)] => *para_id,
|
||||
_ => {
|
||||
log::error!(target: "xcm::ethereum_blob_exporter", "could not get parachain id from universal source '{local_sub:?}'.");
|
||||
return Err(SendError::MissingArgument)
|
||||
@@ -93,7 +93,7 @@ where
|
||||
SendError::Unroutable
|
||||
})?;
|
||||
|
||||
let source_location: MultiLocation = MultiLocation { parents: 1, interior: local_sub };
|
||||
let source_location = Location::new(1, local_sub.clone());
|
||||
let agent_id = match AgentHashedDescription::convert_location(&source_location) {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
@@ -116,8 +116,8 @@ where
|
||||
SendError::Unroutable
|
||||
})?;
|
||||
|
||||
// convert fee to MultiAsset
|
||||
let fee = MultiAsset::from((MultiLocation::parent(), fee.total())).into();
|
||||
// convert fee to Asset
|
||||
let fee = Asset::from((Location::parent(), fee.total())).into();
|
||||
|
||||
Ok(((ticket.encode(), message_id), fee))
|
||||
}
|
||||
@@ -216,8 +216,8 @@ impl<'a, Call> XcmConverter<'a, Call> {
|
||||
|
||||
// assert that the beneficiary is AccountKey20.
|
||||
let recipient = match_expression!(
|
||||
beneficiary,
|
||||
MultiLocation { parents: 0, interior: X1(AccountKey20 { network, key }) }
|
||||
beneficiary.unpack(),
|
||||
(0, [AccountKey20 { network, key }])
|
||||
if self.network_matches(network),
|
||||
H160(*key)
|
||||
)
|
||||
@@ -245,14 +245,15 @@ impl<'a, Call> XcmConverter<'a, Call> {
|
||||
}
|
||||
}
|
||||
|
||||
let (token, amount) = match_expression!(
|
||||
reserve_asset,
|
||||
MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 0, interior: X1(AccountKey20 { network , key })}),
|
||||
fun: Fungible(amount)
|
||||
} if self.network_matches(network),
|
||||
(H160(*key), *amount)
|
||||
)
|
||||
let (token, amount) = match reserve_asset {
|
||||
Asset { id: AssetId(inner_location), fun: Fungible(amount) } =>
|
||||
match inner_location.unpack() {
|
||||
(0, [AccountKey20 { network, key }]) if self.network_matches(network) =>
|
||||
Some((H160(*key), *amount)),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
.ok_or(AssetResolutionFailed)?;
|
||||
|
||||
// transfer amount must be greater than 0.
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::*;
|
||||
parameter_types! {
|
||||
const MaxMessageSize: u32 = u32::MAX;
|
||||
const RelayNetwork: NetworkId = Polkadot;
|
||||
const UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(1013));
|
||||
UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(1013)].into();
|
||||
const BridgedNetwork: NetworkId = Ethereum{ chain_id: 1 };
|
||||
const NonBridgedNetwork: NetworkId = Ethereum{ chain_id: 2 };
|
||||
}
|
||||
@@ -61,8 +61,8 @@ impl SendMessageFeeProvider for MockErrOutboundQueue {
|
||||
fn exporter_validate_with_unknown_network_yields_not_applicable() {
|
||||
let network = Ethereum { chain_id: 1337 };
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = None;
|
||||
let mut destination: Option<InteriorMultiLocation> = None;
|
||||
let mut universal_source: Option<InteriorLocation> = None;
|
||||
let mut destination: Option<InteriorLocation> = None;
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -80,8 +80,8 @@ fn exporter_validate_with_unknown_network_yields_not_applicable() {
|
||||
fn exporter_validate_with_invalid_destination_yields_missing_argument() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = None;
|
||||
let mut destination: Option<InteriorMultiLocation> = None;
|
||||
let mut universal_source: Option<InteriorLocation> = None;
|
||||
let mut destination: Option<InteriorLocation> = None;
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -99,10 +99,11 @@ fn exporter_validate_with_invalid_destination_yields_missing_argument() {
|
||||
fn exporter_validate_with_x8_destination_yields_not_applicable() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = None;
|
||||
let mut destination: Option<InteriorMultiLocation> = Some(X8(
|
||||
OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild,
|
||||
));
|
||||
let mut universal_source: Option<InteriorLocation> = None;
|
||||
let mut destination: Option<InteriorLocation> = Some(
|
||||
[OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild, OnlyChild]
|
||||
.into(),
|
||||
);
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -120,8 +121,8 @@ fn exporter_validate_with_x8_destination_yields_not_applicable() {
|
||||
fn exporter_validate_without_universal_source_yields_missing_argument() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = None;
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> = None;
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -139,8 +140,8 @@ fn exporter_validate_without_universal_source_yields_missing_argument() {
|
||||
fn exporter_validate_without_global_universal_location_yields_unroutable() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> = Here.into();
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -158,8 +159,8 @@ fn exporter_validate_without_global_universal_location_yields_unroutable() {
|
||||
fn exporter_validate_without_global_bridge_location_yields_not_applicable() {
|
||||
let network = NonBridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> = Here.into();
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -177,9 +178,9 @@ fn exporter_validate_without_global_bridge_location_yields_not_applicable() {
|
||||
fn exporter_validate_with_remote_universal_source_yields_not_applicable() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X2(GlobalConsensus(Kusama), Parachain(1000)));
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Kusama), Parachain(1000)].into());
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -197,8 +198,8 @@ fn exporter_validate_with_remote_universal_source_yields_not_applicable() {
|
||||
fn exporter_validate_without_para_id_in_source_yields_missing_argument() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> = Some(X1(GlobalConsensus(Polkadot)));
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> = Some(GlobalConsensus(Polkadot).into());
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -216,9 +217,9 @@ fn exporter_validate_without_para_id_in_source_yields_missing_argument() {
|
||||
fn exporter_validate_complex_para_id_in_source_yields_missing_argument() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X3(GlobalConsensus(Polkadot), Parachain(1000), PalletInstance(12)));
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Polkadot), Parachain(1000), PalletInstance(12)].into());
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -236,9 +237,9 @@ fn exporter_validate_complex_para_id_in_source_yields_missing_argument() {
|
||||
fn exporter_validate_without_xcm_message_yields_missing_argument() {
|
||||
let network = BridgedNetwork::get();
|
||||
let channel: u32 = 0;
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X2(GlobalConsensus(Polkadot), Parachain(1000)));
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Polkadot), Parachain(1000)].into());
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
let mut message: Option<Xcm<()>> = None;
|
||||
|
||||
let result = EthereumBlobExporter::<
|
||||
@@ -255,23 +256,23 @@ fn exporter_validate_without_xcm_message_yields_missing_argument() {
|
||||
#[test]
|
||||
fn exporter_validate_with_max_target_fee_yields_unroutable() {
|
||||
let network = BridgedNetwork::get();
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X2(GlobalConsensus(Polkadot), Parachain(1000)));
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Polkadot), Parachain(1000)].into());
|
||||
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let channel: u32 = 0;
|
||||
let fee = MultiAsset { id: Concrete(Here.into()), fun: Fungible(1000) };
|
||||
let fees: MultiAssets = vec![fee.clone()].into();
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let fee = Asset { id: AssetId(Here.into()), fun: Fungible(1000) };
|
||||
let fees: Assets = vec![fee.clone()].into();
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let mut message: Option<Xcm<()>> = Some(
|
||||
vec![
|
||||
@@ -280,7 +281,7 @@ fn exporter_validate_with_max_target_fee_yields_unroutable() {
|
||||
WithdrawAsset(assets),
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: Some(network), key: beneficiary_address })
|
||||
beneficiary: AccountKey20 { network: Some(network), key: beneficiary_address }
|
||||
.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
@@ -303,14 +304,14 @@ fn exporter_validate_with_max_target_fee_yields_unroutable() {
|
||||
#[test]
|
||||
fn exporter_validate_with_unparsable_xcm_yields_unroutable() {
|
||||
let network = BridgedNetwork::get();
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X2(GlobalConsensus(Polkadot), Parachain(1000)));
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Polkadot), Parachain(1000)].into());
|
||||
|
||||
let channel: u32 = 0;
|
||||
let fee = MultiAsset { id: Concrete(Here.into()), fun: Fungible(1000) };
|
||||
let fees: MultiAssets = vec![fee.clone()].into();
|
||||
let fee = Asset { id: AssetId(Here.into()), fun: Fungible(1000) };
|
||||
let fees: Assets = vec![fee.clone()].into();
|
||||
|
||||
let mut message: Option<Xcm<()>> =
|
||||
Some(vec![WithdrawAsset(fees), BuyExecution { fees: fee, weight_limit: Unlimited }].into());
|
||||
@@ -330,22 +331,22 @@ fn exporter_validate_with_unparsable_xcm_yields_unroutable() {
|
||||
#[test]
|
||||
fn exporter_validate_xcm_success_case_1() {
|
||||
let network = BridgedNetwork::get();
|
||||
let mut destination: Option<InteriorMultiLocation> = Here.into();
|
||||
let mut destination: Option<InteriorLocation> = Here.into();
|
||||
|
||||
let mut universal_source: Option<InteriorMultiLocation> =
|
||||
Some(X2(GlobalConsensus(Polkadot), Parachain(1000)));
|
||||
let mut universal_source: Option<InteriorLocation> =
|
||||
Some([GlobalConsensus(Polkadot), Parachain(1000)].into());
|
||||
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let channel: u32 = 0;
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let fee = assets.clone().get(0).unwrap().clone();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let mut message: Option<Xcm<()>> = Some(
|
||||
vec![
|
||||
@@ -354,7 +355,7 @@ fn exporter_validate_xcm_success_case_1() {
|
||||
BuyExecution { fees: fee, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -391,12 +392,12 @@ fn xcm_converter_convert_success() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -404,7 +405,7 @@ fn xcm_converter_convert_success() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -426,18 +427,18 @@ fn xcm_converter_convert_without_buy_execution_yields_success() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -459,12 +460,12 @@ fn xcm_converter_convert_with_wildcard_all_asset_filter_succeeds() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(All);
|
||||
let filter: AssetFilter = Wild(All);
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -472,7 +473,7 @@ fn xcm_converter_convert_with_wildcard_all_asset_filter_succeeds() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -494,13 +495,12 @@ fn xcm_converter_convert_with_fees_less_than_reserve_yields_success() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let asset_location = X1(AccountKey20 { network: None, key: token_address }).into();
|
||||
let fee_asset = MultiAsset { id: Concrete(asset_location), fun: Fungible(500) };
|
||||
let asset_location: Location = [AccountKey20 { network: None, key: token_address }].into();
|
||||
let fee_asset = Asset { id: AssetId(asset_location.clone()), fun: Fungible(500) };
|
||||
|
||||
let assets: MultiAssets =
|
||||
vec![MultiAsset { id: Concrete(asset_location), fun: Fungible(1000) }].into();
|
||||
let assets: Assets = vec![Asset { id: AssetId(asset_location), fun: Fungible(1000) }].into();
|
||||
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -508,7 +508,7 @@ fn xcm_converter_convert_with_fees_less_than_reserve_yields_success() {
|
||||
BuyExecution { fees: fee_asset, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -530,19 +530,19 @@ fn xcm_converter_convert_without_set_topic_yields_set_topic_expected() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
ClearTopic,
|
||||
]
|
||||
@@ -557,8 +557,8 @@ fn xcm_converter_convert_with_partial_message_yields_unexpected_end_of_xcm() {
|
||||
let network = BridgedNetwork::get();
|
||||
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
@@ -576,16 +576,13 @@ fn xcm_converter_with_different_fee_asset_fails() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let asset_location = X1(AccountKey20 { network: None, key: token_address }).into();
|
||||
let fee_asset = MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 0, interior: Here }),
|
||||
fun: Fungible(1000),
|
||||
};
|
||||
let asset_location = [AccountKey20 { network: None, key: token_address }].into();
|
||||
let fee_asset =
|
||||
Asset { id: AssetId(Location { parents: 0, interior: Here }), fun: Fungible(1000) };
|
||||
|
||||
let assets: MultiAssets =
|
||||
vec![MultiAsset { id: Concrete(asset_location), fun: Fungible(1000) }].into();
|
||||
let assets: Assets = vec![Asset { id: AssetId(asset_location), fun: Fungible(1000) }].into();
|
||||
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -593,7 +590,7 @@ fn xcm_converter_with_different_fee_asset_fails() {
|
||||
BuyExecution { fees: fee_asset, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -610,13 +607,12 @@ fn xcm_converter_with_fees_greater_than_reserve_fails() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let asset_location = X1(AccountKey20 { network: None, key: token_address }).into();
|
||||
let fee_asset = MultiAsset { id: Concrete(asset_location), fun: Fungible(1001) };
|
||||
let asset_location: Location = [AccountKey20 { network: None, key: token_address }].into();
|
||||
let fee_asset = Asset { id: AssetId(asset_location.clone()), fun: Fungible(1001) };
|
||||
|
||||
let assets: MultiAssets =
|
||||
vec![MultiAsset { id: Concrete(asset_location), fun: Fungible(1000) }].into();
|
||||
let assets: Assets = vec![Asset { id: AssetId(asset_location), fun: Fungible(1000) }].into();
|
||||
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -624,7 +620,7 @@ fn xcm_converter_with_fees_greater_than_reserve_fails() {
|
||||
BuyExecution { fees: fee_asset, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -653,12 +649,12 @@ fn xcm_converter_convert_with_extra_instructions_yields_end_of_xcm_message_expec
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -666,7 +662,7 @@ fn xcm_converter_convert_with_extra_instructions_yields_end_of_xcm_message_expec
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
ClearError,
|
||||
@@ -685,19 +681,19 @@ fn xcm_converter_convert_without_withdraw_asset_yields_withdraw_expected() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([AccountKey20 { network: None, key: token_address }].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
ClearOrigin,
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -714,8 +710,8 @@ fn xcm_converter_convert_without_withdraw_asset_yields_deposit_expected() {
|
||||
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
@@ -741,11 +737,11 @@ fn xcm_converter_convert_without_assets_yields_no_reserve_assets() {
|
||||
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![].into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let assets: Assets = vec![].into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let fee = MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let fee = Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
};
|
||||
|
||||
@@ -755,7 +751,7 @@ fn xcm_converter_convert_without_assets_yields_no_reserve_assets() {
|
||||
BuyExecution { fees: fee, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -774,18 +770,18 @@ fn xcm_converter_convert_with_two_assets_yields_too_many_assets() {
|
||||
let token_address_2: [u8; 20] = hex!("1100000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![
|
||||
MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address_1 }).into()),
|
||||
let assets: Assets = vec![
|
||||
Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address_1 }.into()),
|
||||
fun: Fungible(1000),
|
||||
},
|
||||
MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address_2 }).into()),
|
||||
Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address_2 }.into()),
|
||||
fun: Fungible(500),
|
||||
},
|
||||
]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = assets.clone().into();
|
||||
let filter: AssetFilter = assets.clone().into();
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -793,7 +789,7 @@ fn xcm_converter_convert_with_two_assets_yields_too_many_assets() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -811,12 +807,12 @@ fn xcm_converter_convert_without_consuming_filter_yields_filter_does_not_consume
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(0));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(0));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -824,7 +820,7 @@ fn xcm_converter_convert_without_consuming_filter_yields_filter_does_not_consume
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -842,12 +838,12 @@ fn xcm_converter_convert_with_zero_amount_asset_yields_zero_asset_transfer() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(0),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -855,7 +851,7 @@ fn xcm_converter_convert_with_zero_amount_asset_yields_zero_asset_transfer() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -872,12 +868,12 @@ fn xcm_converter_convert_non_ethereum_asset_yields_asset_resolution_failed() {
|
||||
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X3(GlobalConsensus(Polkadot), Parachain(1000), GeneralIndex(0)).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId([GlobalConsensus(Polkadot), Parachain(1000), GeneralIndex(0)].into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -885,7 +881,7 @@ fn xcm_converter_convert_non_ethereum_asset_yields_asset_resolution_failed() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -903,14 +899,14 @@ fn xcm_converter_convert_non_ethereum_chain_asset_yields_asset_resolution_failed
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(
|
||||
X1(AccountKey20 { network: Some(Ethereum { chain_id: 2 }), key: token_address }).into(),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(
|
||||
AccountKey20 { network: Some(Ethereum { chain_id: 2 }), key: token_address }.into(),
|
||||
),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -918,7 +914,7 @@ fn xcm_converter_convert_non_ethereum_chain_asset_yields_asset_resolution_failed
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -936,14 +932,14 @@ fn xcm_converter_convert_non_ethereum_chain_yields_asset_resolution_failed() {
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(
|
||||
X1(AccountKey20 { network: Some(NonBridgedNetwork::get()), key: token_address }).into(),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(
|
||||
[AccountKey20 { network: Some(NonBridgedNetwork::get()), key: token_address }].into(),
|
||||
),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -951,7 +947,7 @@ fn xcm_converter_convert_non_ethereum_chain_yields_asset_resolution_failed() {
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 { network: None, key: beneficiary_address }).into(),
|
||||
beneficiary: AccountKey20 { network: None, key: beneficiary_address }.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]
|
||||
@@ -971,23 +967,23 @@ fn xcm_converter_convert_with_non_ethereum_beneficiary_yields_beneficiary_resolu
|
||||
let beneficiary_address: [u8; 32] =
|
||||
hex!("2000000000000000000000000000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
ClearOrigin,
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X3(
|
||||
beneficiary: [
|
||||
GlobalConsensus(Polkadot),
|
||||
Parachain(1000),
|
||||
AccountId32 { network: Some(Polkadot), id: beneficiary_address },
|
||||
)
|
||||
]
|
||||
.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
@@ -1007,12 +1003,12 @@ fn xcm_converter_convert_with_non_ethereum_chain_beneficiary_yields_beneficiary_
|
||||
let token_address: [u8; 20] = hex!("1000000000000000000000000000000000000000");
|
||||
let beneficiary_address: [u8; 20] = hex!("2000000000000000000000000000000000000000");
|
||||
|
||||
let assets: MultiAssets = vec![MultiAsset {
|
||||
id: Concrete(X1(AccountKey20 { network: None, key: token_address }).into()),
|
||||
let assets: Assets = vec![Asset {
|
||||
id: AssetId(AccountKey20 { network: None, key: token_address }.into()),
|
||||
fun: Fungible(1000),
|
||||
}]
|
||||
.into();
|
||||
let filter: MultiAssetFilter = Wild(WildMultiAsset::AllCounted(1));
|
||||
let filter: AssetFilter = Wild(WildAsset::AllCounted(1));
|
||||
|
||||
let message: Xcm<()> = vec![
|
||||
WithdrawAsset(assets.clone()),
|
||||
@@ -1020,10 +1016,10 @@ fn xcm_converter_convert_with_non_ethereum_chain_beneficiary_yields_beneficiary_
|
||||
BuyExecution { fees: assets.get(0).unwrap().clone(), weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: filter,
|
||||
beneficiary: X1(AccountKey20 {
|
||||
beneficiary: AccountKey20 {
|
||||
network: Some(Ethereum { chain_id: 2 }),
|
||||
key: beneficiary_address,
|
||||
})
|
||||
}
|
||||
.into(),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
@@ -1037,14 +1033,13 @@ fn xcm_converter_convert_with_non_ethereum_chain_beneficiary_yields_beneficiary_
|
||||
|
||||
#[test]
|
||||
fn test_describe_asset_hub() {
|
||||
let legacy_location: MultiLocation =
|
||||
MultiLocation { parents: 0, interior: X1(Parachain(1000)) };
|
||||
let legacy_location: Location = Location::new(0, [Parachain(1000)]);
|
||||
let legacy_agent_id = AgentIdOf::convert_location(&legacy_location).unwrap();
|
||||
assert_eq!(
|
||||
legacy_agent_id,
|
||||
hex!("72456f48efed08af20e5b317abf8648ac66e86bb90a411d9b0b713f7364b75b4").into()
|
||||
);
|
||||
let location: MultiLocation = MultiLocation { parents: 1, interior: X1(Parachain(1000)) };
|
||||
let location: Location = Location::new(1, [Parachain(1000)]);
|
||||
let agent_id = AgentIdOf::convert_location(&location).unwrap();
|
||||
assert_eq!(
|
||||
agent_id,
|
||||
@@ -1054,7 +1049,7 @@ fn test_describe_asset_hub() {
|
||||
|
||||
#[test]
|
||||
fn test_describe_here() {
|
||||
let location: MultiLocation = MultiLocation { parents: 0, interior: Here };
|
||||
let location: Location = Location::new(0, []);
|
||||
let agent_id = AgentIdOf::convert_location(&location).unwrap();
|
||||
assert_eq!(
|
||||
agent_id,
|
||||
|
||||
@@ -46,32 +46,27 @@ impl<Balance, AccountId, FeeAssetLocation, EthereumNetwork, AssetTransactor, Fee
|
||||
> where
|
||||
Balance: BaseArithmetic + Unsigned + Copy + From<u128> + Into<u128>,
|
||||
AccountId: Clone + Into<[u8; 32]> + From<[u8; 32]>,
|
||||
FeeAssetLocation: Get<MultiLocation>,
|
||||
FeeAssetLocation: Get<Location>,
|
||||
EthereumNetwork: Get<NetworkId>,
|
||||
AssetTransactor: TransactAsset,
|
||||
FeeProvider: SendMessageFeeProvider<Balance = Balance>,
|
||||
{
|
||||
fn handle_fee(
|
||||
fees: MultiAssets,
|
||||
context: Option<&XcmContext>,
|
||||
reason: FeeReason,
|
||||
) -> MultiAssets {
|
||||
fn handle_fee(fees: Assets, context: Option<&XcmContext>, reason: FeeReason) -> Assets {
|
||||
let token_location = FeeAssetLocation::get();
|
||||
|
||||
// Check the reason to see if this export is for snowbridge.
|
||||
if !matches!(
|
||||
reason,
|
||||
FeeReason::Export { network: bridged_network, destination }
|
||||
if bridged_network == EthereumNetwork::get() && destination == Here
|
||||
FeeReason::Export { network: bridged_network, ref destination }
|
||||
if bridged_network == EthereumNetwork::get() && destination == &Here
|
||||
) {
|
||||
return fees
|
||||
}
|
||||
|
||||
// Get the parachain sovereign from the `context`.
|
||||
let para_sovereign = if let Some(XcmContext {
|
||||
origin: Some(MultiLocation { parents: 1, interior }),
|
||||
..
|
||||
}) = context
|
||||
let para_sovereign =
|
||||
if let Some(XcmContext { origin: Some(Location { parents: 1, interior }), .. }) =
|
||||
context
|
||||
{
|
||||
if let Some(Parachain(sibling_para_id)) = interior.first() {
|
||||
let account: AccountId =
|
||||
@@ -90,8 +85,8 @@ impl<Balance, AccountId, FeeAssetLocation, EthereumNetwork, AssetTransactor, Fee
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, asset)| {
|
||||
if let MultiAsset { id: Concrete(location), fun: Fungible(amount) } = asset {
|
||||
if *location == token_location {
|
||||
if let Asset { id: location, fun: Fungible(amount) } = asset {
|
||||
if location.0 == token_location {
|
||||
return Some((index, (*amount).into()))
|
||||
}
|
||||
}
|
||||
@@ -104,7 +99,7 @@ impl<Balance, AccountId, FeeAssetLocation, EthereumNetwork, AssetTransactor, Fee
|
||||
if remote_fee > (0u128).into() {
|
||||
// Refund remote component of fee to physical origin
|
||||
deposit_or_burn_fee::<AssetTransactor, _>(
|
||||
MultiAsset { id: Concrete(token_location), fun: Fungible(remote_fee.into()) }
|
||||
Asset { id: AssetId(token_location.clone()), fun: Fungible(remote_fee.into()) }
|
||||
.into(),
|
||||
context,
|
||||
para_sovereign,
|
||||
@@ -112,8 +107,8 @@ impl<Balance, AccountId, FeeAssetLocation, EthereumNetwork, AssetTransactor, Fee
|
||||
// Return remaining fee to the next fee handler in the chain.
|
||||
let mut modified_fees = fees.inner().clone();
|
||||
modified_fees.remove(fee_index);
|
||||
modified_fees.push(MultiAsset {
|
||||
id: Concrete(token_location),
|
||||
modified_fees.push(Asset {
|
||||
id: AssetId(token_location),
|
||||
fun: Fungible((total_fee - remote_fee).into()),
|
||||
});
|
||||
return modified_fees.into()
|
||||
|
||||
@@ -49,38 +49,36 @@ where
|
||||
+ snowbridge_pallet_outbound_queue::Config,
|
||||
XcmConfig: xcm_executor::Config,
|
||||
{
|
||||
let assethub_parachain_location = MultiLocation::new(1, Parachain(assethub_parachain_id));
|
||||
let asset = MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountKey20 { network: None, key: weth_contract_address.into() }),
|
||||
}),
|
||||
let assethub_parachain_location = Location::new(1, Parachain(assethub_parachain_id));
|
||||
let asset = Asset {
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[AccountKey20 { network: None, key: weth_contract_address.into() }],
|
||||
)),
|
||||
fun: Fungible(1000000000),
|
||||
};
|
||||
let assets = vec![asset.clone()];
|
||||
|
||||
let inner_xcm = Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(assets.clone())),
|
||||
WithdrawAsset(Assets::from(assets.clone())),
|
||||
ClearOrigin,
|
||||
BuyExecution { fees: asset, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: Wild(All),
|
||||
beneficiary: MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountKey20 { network: None, key: destination_address.into() }),
|
||||
},
|
||||
beneficiary: Location::new(
|
||||
0,
|
||||
[AccountKey20 { network: None, key: destination_address.into() }],
|
||||
),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]);
|
||||
|
||||
let fee = MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
fun: Fungible(fee_amount),
|
||||
};
|
||||
let fee =
|
||||
Asset { id: AssetId(Location { parents: 1, interior: Here }), fun: Fungible(fee_amount) };
|
||||
|
||||
// prepare transfer token message
|
||||
let xcm = Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(vec![fee.clone()])),
|
||||
WithdrawAsset(Assets::from(vec![fee.clone()])),
|
||||
BuyExecution { fees: fee, weight_limit: Unlimited },
|
||||
ExportMessage {
|
||||
network: Ethereum { chain_id: 11155111 },
|
||||
@@ -90,12 +88,13 @@ where
|
||||
]);
|
||||
|
||||
// execute XCM
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
assethub_parachain_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -176,7 +175,7 @@ pub fn send_unpaid_transfer_token_message<Runtime, XcmConfig>(
|
||||
XcmConfig: xcm_executor::Config,
|
||||
ValidatorIdOf<Runtime>: From<AccountIdOf<Runtime>>,
|
||||
{
|
||||
let assethub_parachain_location = MultiLocation::new(1, Parachain(assethub_parachain_id));
|
||||
let assethub_parachain_location = Location::new(1, Parachain(assethub_parachain_id));
|
||||
|
||||
ExtBuilder::<Runtime>::default()
|
||||
.with_collators(collator_session_key.collators())
|
||||
@@ -194,28 +193,25 @@ pub fn send_unpaid_transfer_token_message<Runtime, XcmConfig>(
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let asset = MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountKey20 { network: None, key: weth_contract_address.into() }),
|
||||
}),
|
||||
let asset = Asset {
|
||||
id: AssetId(Location::new(
|
||||
0,
|
||||
[AccountKey20 { network: None, key: weth_contract_address.into() }],
|
||||
)),
|
||||
fun: Fungible(1000000000),
|
||||
};
|
||||
let assets = vec![asset.clone()];
|
||||
|
||||
let inner_xcm = Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(assets.clone())),
|
||||
WithdrawAsset(Assets::from(assets.clone())),
|
||||
ClearOrigin,
|
||||
BuyExecution { fees: asset, weight_limit: Unlimited },
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountKey20 {
|
||||
network: None,
|
||||
key: destination_contract.into(),
|
||||
}),
|
||||
},
|
||||
beneficiary: Location::new(
|
||||
0,
|
||||
[AccountKey20 { network: None, key: destination_contract.into() }],
|
||||
),
|
||||
},
|
||||
SetTopic([0; 32]),
|
||||
]);
|
||||
@@ -231,12 +227,13 @@ pub fn send_unpaid_transfer_token_message<Runtime, XcmConfig>(
|
||||
]);
|
||||
|
||||
// execute XCM
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
assethub_parachain_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
);
|
||||
// check error is barrier
|
||||
assert_err!(outcome.ensure_complete(), Barrier);
|
||||
|
||||
@@ -135,7 +135,7 @@ pub mod pallet {
|
||||
/// The origin that is allowed to resume or suspend the XCMP queue.
|
||||
type ControllerOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The conversion function used to attempt to convert an XCM `MultiLocation` origin to a
|
||||
/// The conversion function used to attempt to convert an XCM `Location` origin to a
|
||||
/// superuser origin.
|
||||
type ControllerOriginConverter: ConvertOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
@@ -903,14 +903,14 @@ impl<T: Config> SendXcm for Pallet<T> {
|
||||
type Ticket = (ParaId, VersionedXcm<()>);
|
||||
|
||||
fn validate(
|
||||
dest: &mut Option<MultiLocation>,
|
||||
dest: &mut Option<Location>,
|
||||
msg: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<(ParaId, VersionedXcm<()>)> {
|
||||
let d = dest.take().ok_or(SendError::MissingArgument)?;
|
||||
|
||||
match &d {
|
||||
match d.unpack() {
|
||||
// An HRMP message for a sibling parachain.
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) } => {
|
||||
(1, [Parachain(id)]) => {
|
||||
let xcm = msg.take().ok_or(SendError::MissingArgument)?;
|
||||
let id = ParaId::from(*id);
|
||||
let price = T::PriceForSiblingDelivery::price_for_delivery(id, &xcm);
|
||||
|
||||
@@ -124,8 +124,8 @@ impl cumulus_pallet_parachain_system::Config for Test {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayChain: MultiLocation = MultiLocation::parent();
|
||||
pub UniversalLocation: InteriorMultiLocation = X1(Parachain(1u32));
|
||||
pub const RelayChain: Location = Location::parent();
|
||||
pub UniversalLocation: InteriorLocation = [Parachain(1u32)].into();
|
||||
pub UnitWeightCost: Weight = Weight::from_parts(1_000_000, 1024);
|
||||
pub const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
@@ -138,7 +138,7 @@ pub type LocalAssetTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<RelayChain>,
|
||||
// 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,
|
||||
@@ -187,17 +187,14 @@ impl<RuntimeOrigin: OriginTrait> ConvertOrigin<RuntimeOrigin>
|
||||
for SystemParachainAsSuperuser<RuntimeOrigin>
|
||||
{
|
||||
fn convert_origin(
|
||||
origin: impl Into<MultiLocation>,
|
||||
origin: impl Into<Location>,
|
||||
kind: OriginKind,
|
||||
) -> Result<RuntimeOrigin, MultiLocation> {
|
||||
) -> Result<RuntimeOrigin, Location> {
|
||||
let origin = origin.into();
|
||||
if kind == OriginKind::Superuser &&
|
||||
matches!(
|
||||
origin,
|
||||
MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(id)),
|
||||
} if ParaId::from(id).is_system(),
|
||||
origin.unpack(),
|
||||
(1, [Parachain(id)]) if ParaId::from(*id).is_system(),
|
||||
) {
|
||||
Ok(RuntimeOrigin::root())
|
||||
} else {
|
||||
@@ -256,7 +253,7 @@ impl<T: OnQueueChanged<ParaId>> EnqueueMessage<ParaId> for EnqueueToLocalStorage
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(RelayChain::get());
|
||||
pub FeeAssetId: AssetId = AssetId(RelayChain::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: Balance = 300_000_000;
|
||||
/// The fee per byte
|
||||
|
||||
@@ -333,11 +333,11 @@ struct OkFixedXcmHashWithAssertingRequiredInputsSender;
|
||||
impl OkFixedXcmHashWithAssertingRequiredInputsSender {
|
||||
const FIXED_XCM_HASH: [u8; 32] = [9; 32];
|
||||
|
||||
fn fixed_delivery_asset() -> MultiAssets {
|
||||
MultiAssets::new()
|
||||
fn fixed_delivery_asset() -> Assets {
|
||||
Assets::new()
|
||||
}
|
||||
|
||||
fn expected_delivery_result() -> Result<(XcmHash, MultiAssets), SendError> {
|
||||
fn expected_delivery_result() -> Result<(XcmHash, Assets), SendError> {
|
||||
Ok((Self::FIXED_XCM_HASH, Self::fixed_delivery_asset()))
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ impl SendXcm for OkFixedXcmHashWithAssertingRequiredInputsSender {
|
||||
type Ticket = ();
|
||||
|
||||
fn validate(
|
||||
destination: &mut Option<MultiLocation>,
|
||||
destination: &mut Option<Location>,
|
||||
message: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
assert!(destination.is_some());
|
||||
@@ -392,8 +392,8 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() {
|
||||
let message = Xcm(vec![Trap(5)]);
|
||||
|
||||
// XcmpQueue - check dest/msg is valid
|
||||
let dest = (Parent, X1(Parachain(5555)));
|
||||
let mut dest_wrapper = Some(dest.into());
|
||||
let dest: Location = (Parent, Parachain(5555)).into();
|
||||
let mut dest_wrapper = Some(dest.clone());
|
||||
let mut msg_wrapper = Some(message.clone());
|
||||
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -416,7 +416,7 @@ fn xcmp_queue_consumes_dest_and_msg_on_ok_validate() {
|
||||
|
||||
#[test]
|
||||
fn xcmp_queue_validate_nested_xcm_works() {
|
||||
let dest = (Parent, X1(Parachain(5555)));
|
||||
let dest = (Parent, Parachain(5555));
|
||||
// Message that is not too deeply nested:
|
||||
let mut good = Xcm(vec![ClearOrigin]);
|
||||
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
|
||||
@@ -441,7 +441,7 @@ fn xcmp_queue_validate_nested_xcm_works() {
|
||||
|
||||
#[test]
|
||||
fn send_xcm_nested_works() {
|
||||
let dest = (Parent, X1(Parachain(HRMP_PARA_ID)));
|
||||
let dest = (Parent, Parachain(HRMP_PARA_ID));
|
||||
// Message that is not too deeply nested:
|
||||
let mut good = Xcm(vec![ClearOrigin]);
|
||||
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
|
||||
@@ -455,7 +455,7 @@ fn send_xcm_nested_works() {
|
||||
XcmpQueue::take_outbound_messages(usize::MAX),
|
||||
vec![(
|
||||
HRMP_PARA_ID.into(),
|
||||
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::V3(good.clone()))
|
||||
(XcmpMessageFormat::ConcatenatedVersionedXcm, VersionedXcm::V4(good.clone()))
|
||||
.encode(),
|
||||
)]
|
||||
);
|
||||
@@ -474,7 +474,7 @@ fn hrmp_signals_are_prioritized() {
|
||||
let message = Xcm(vec![Trap(5)]);
|
||||
|
||||
let sibling_para_id = ParaId::from(12345);
|
||||
let dest = (Parent, X1(Parachain(sibling_para_id.into())));
|
||||
let dest = (Parent, Parachain(sibling_para_id.into()));
|
||||
let mut dest_wrapper = Some(dest.into());
|
||||
let mut msg_wrapper = Some(message.clone());
|
||||
|
||||
@@ -511,7 +511,7 @@ fn hrmp_signals_are_prioritized() {
|
||||
// Without a signal we get the messages in order:
|
||||
let mut expected_msg = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
|
||||
for _ in 0..31 {
|
||||
expected_msg.extend(VersionedXcm::V3(message.clone()).encode());
|
||||
expected_msg.extend(VersionedXcm::V4(message.clone()).encode());
|
||||
}
|
||||
|
||||
hypothetically!({
|
||||
@@ -590,7 +590,7 @@ fn take_first_concatenated_xcm_good_recursion_depth_works() {
|
||||
for _ in 0..MAX_XCM_DECODE_DEPTH - 1 {
|
||||
good = Xcm(vec![SetAppendix(good)]);
|
||||
}
|
||||
let good = VersionedXcm::V3(good);
|
||||
let good = VersionedXcm::V4(good);
|
||||
|
||||
let page = good.encode();
|
||||
assert_ok!(XcmpQueue::take_first_concatenated_xcm(&mut &page[..], &mut WeightMeter::new()));
|
||||
@@ -603,7 +603,7 @@ fn take_first_concatenated_xcm_good_bad_depth_errors() {
|
||||
for _ in 0..MAX_XCM_DECODE_DEPTH {
|
||||
bad = Xcm(vec![SetAppendix(bad)]);
|
||||
}
|
||||
let bad = VersionedXcm::V3(bad);
|
||||
let bad = VersionedXcm::V4(bad);
|
||||
|
||||
let page = bad.encode();
|
||||
assert_err!(
|
||||
@@ -699,12 +699,12 @@ fn lazy_migration_noop_when_out_of_weight() {
|
||||
fn xcmp_queue_send_xcm_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let sibling_para_id = ParaId::from(12345);
|
||||
let dest = (Parent, X1(Parachain(sibling_para_id.into()))).into();
|
||||
let dest: Location = (Parent, Parachain(sibling_para_id.into())).into();
|
||||
let msg = Xcm(vec![ClearOrigin]);
|
||||
|
||||
// try to send without opened HRMP channel to the sibling_para_id
|
||||
assert_eq!(
|
||||
send_xcm::<XcmpQueue>(dest, msg.clone()),
|
||||
send_xcm::<XcmpQueue>(dest.clone(), msg.clone()),
|
||||
Err(SendError::Transport("NoChannel")),
|
||||
);
|
||||
|
||||
@@ -728,7 +728,7 @@ fn xcmp_queue_send_xcm_works() {
|
||||
fn xcmp_queue_send_too_big_xcm_fails() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let sibling_para_id = ParaId::from(12345);
|
||||
let dest = (Parent, X1(Parachain(sibling_para_id.into()))).into();
|
||||
let dest = (Parent, Parachain(sibling_para_id.into())).into();
|
||||
|
||||
let max_message_size = 100_u32;
|
||||
|
||||
@@ -774,7 +774,7 @@ fn verify_fee_factor_increase_and_decrease() {
|
||||
use sp_runtime::FixedU128;
|
||||
|
||||
let sibling_para_id = ParaId::from(12345);
|
||||
let destination = (Parent, Parachain(sibling_para_id.into())).into();
|
||||
let destination: Location = (Parent, Parachain(sibling_para_id.into())).into();
|
||||
let xcm = Xcm(vec![ClearOrigin; 100]);
|
||||
let versioned_xcm = VersionedXcm::from(xcm.clone());
|
||||
let mut xcmp_message = XcmpMessageFormat::ConcatenatedVersionedXcm.encode();
|
||||
@@ -799,15 +799,15 @@ fn verify_fee_factor_increase_and_decrease() {
|
||||
|
||||
// Fee factor is only increased in `send_fragment`, which is called by `send_xcm`.
|
||||
// When queue is not congested, fee factor doesn't change.
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 104
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 208
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 312
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 416
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 104
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 208
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 312
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 416
|
||||
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), initial);
|
||||
|
||||
// Sending the message right now is cheap
|
||||
let (_, delivery_fees) =
|
||||
validate_send::<XcmpQueue>(destination, xcm.clone()).expect("message can be sent; qed");
|
||||
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination.clone(), xcm.clone())
|
||||
.expect("message can be sent; qed");
|
||||
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else {
|
||||
unreachable!("asset is fungible; qed");
|
||||
};
|
||||
@@ -817,18 +817,18 @@ fn verify_fee_factor_increase_and_decrease() {
|
||||
|
||||
// When we get to half of `max_total_size`, because `THRESHOLD_FACTOR` is 2,
|
||||
// then the fee factor starts to increase.
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, xcm.clone())); // Size 520
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), xcm.clone())); // Size 520
|
||||
assert_eq!(DeliveryFeeFactor::<Test>::get(sibling_para_id), FixedU128::from_float(1.05));
|
||||
|
||||
for _ in 0..12 {
|
||||
// We finish at size 929
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination, smaller_xcm.clone()));
|
||||
assert_ok!(send_xcm::<XcmpQueue>(destination.clone(), smaller_xcm.clone()));
|
||||
}
|
||||
assert!(DeliveryFeeFactor::<Test>::get(sibling_para_id) > FixedU128::from_float(1.88));
|
||||
|
||||
// Sending the message right now is expensive
|
||||
let (_, delivery_fees) =
|
||||
validate_send::<XcmpQueue>(destination, xcm.clone()).expect("message can be sent; qed");
|
||||
let (_, delivery_fees) = validate_send::<XcmpQueue>(destination.clone(), xcm.clone())
|
||||
.expect("message can be sent; qed");
|
||||
let Fungible(delivery_fee_amount) = delivery_fees.inner()[0].fun else {
|
||||
unreachable!("asset is fungible; qed");
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@ use super::{
|
||||
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue,
|
||||
};
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
traits::{ConstU32, Everything, Nothing},
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
@@ -25,13 +25,13 @@ use xcm_builder::{
|
||||
use xcm_executor::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 = Parachain(ParachainInfo::parachain_id().into()).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 = (
|
||||
@@ -50,7 +50,7 @@ pub type LocalAssetTransactor = 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,
|
||||
@@ -86,11 +86,11 @@ 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 struct ParentOrParentsExecutivePlurality;
|
||||
impl Contains<Location> for ParentOrParentsExecutivePlurality {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Plurality { id: BodyId::Executive, .. }]))
|
||||
}
|
||||
}
|
||||
|
||||
pub type Barrier = TrailingSetTopicAsId<
|
||||
|
||||
@@ -24,8 +24,8 @@ use pallet_asset_tx_payment::HandleCredit;
|
||||
use sp_runtime::traits::Zero;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
use xcm::latest::{
|
||||
AssetId, Fungibility, Fungibility::Fungible, Junction, Junctions::Here, MultiAsset,
|
||||
MultiLocation, Parent, WeightLimit,
|
||||
Asset, AssetId, Fungibility, Fungibility::Fungible, Junction, Junctions::Here, Location,
|
||||
Parent, WeightLimit,
|
||||
};
|
||||
use xcm_executor::traits::ConvertLocation;
|
||||
|
||||
@@ -113,11 +113,11 @@ where
|
||||
|
||||
/// Asset filter that allows all assets from a certain location.
|
||||
pub struct AssetsFrom<T>(PhantomData<T>);
|
||||
impl<T: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation> for AssetsFrom<T> {
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
impl<T: Get<Location>> ContainsPair<Asset, Location> for AssetsFrom<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) }
|
||||
matches!(asset, Asset { id: AssetId(asset_loc), fun: Fungible(_a) }
|
||||
if asset_loc.match_and_split(&loc).is_some())
|
||||
}
|
||||
}
|
||||
@@ -148,7 +148,7 @@ where
|
||||
Err(amount) => amount,
|
||||
};
|
||||
let imbalance = amount.peek();
|
||||
let root_location: MultiLocation = Here.into();
|
||||
let root_location: Location = Here.into();
|
||||
let root_account: AccountIdOf<T> =
|
||||
match AccountIdConverter::convert_location(&root_location) {
|
||||
Some(a) => a,
|
||||
@@ -329,13 +329,13 @@ mod tests {
|
||||
#[test]
|
||||
fn assets_from_filters_correctly() {
|
||||
parameter_types! {
|
||||
pub SomeSiblingParachain: MultiLocation = MultiLocation::new(1, X1(Parachain(1234)));
|
||||
pub SomeSiblingParachain: Location = (Parent, Parachain(1234)).into();
|
||||
}
|
||||
|
||||
let asset_location = SomeSiblingParachain::get()
|
||||
.pushed_with_interior(GeneralIndex(42))
|
||||
.expect("multilocation will only have 2 junctions; qed");
|
||||
let asset = MultiAsset { id: Concrete(asset_location), fun: 1_000_000u128.into() };
|
||||
.expect("location will only have 2 junctions; qed");
|
||||
let asset = Asset { id: AssetId(asset_location), fun: 1_000_000u128.into() };
|
||||
assert!(
|
||||
AssetsFrom::<SomeSiblingParachain>::contains(&asset, &SomeSiblingParachain::get()),
|
||||
"AssetsFrom should allow assets from any of its interior locations"
|
||||
|
||||
@@ -66,37 +66,36 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Accepts an asset if it is a native asset from a particular `MultiLocation`.
|
||||
pub struct ConcreteNativeAssetFrom<Location>(PhantomData<Location>);
|
||||
impl<Location: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
for ConcreteNativeAssetFrom<Location>
|
||||
/// Accepts an asset if it is a native asset from a particular `Location`.
|
||||
pub struct ConcreteNativeAssetFrom<LocationValue>(PhantomData<LocationValue>);
|
||||
impl<LocationValue: Get<Location>> ContainsPair<Asset, Location>
|
||||
for ConcreteNativeAssetFrom<LocationValue>
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
log::trace!(target: "xcm::filter_asset_location",
|
||||
"ConcreteNativeAsset asset: {:?}, origin: {:?}, location: {:?}",
|
||||
asset, origin, Location::get());
|
||||
matches!(asset.id, Concrete(ref id) if id == origin && origin == &Location::get())
|
||||
asset, origin, LocationValue::get());
|
||||
asset.id.0 == *origin && origin == &LocationValue::get()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RelayOrOtherSystemParachains<
|
||||
SystemParachainMatcher: Contains<MultiLocation>,
|
||||
SystemParachainMatcher: Contains<Location>,
|
||||
Runtime: parachain_info::Config,
|
||||
> {
|
||||
_runtime: PhantomData<(SystemParachainMatcher, Runtime)>,
|
||||
}
|
||||
impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::Config>
|
||||
Contains<MultiLocation> for RelayOrOtherSystemParachains<SystemParachainMatcher, Runtime>
|
||||
impl<SystemParachainMatcher: Contains<Location>, Runtime: parachain_info::Config> Contains<Location>
|
||||
for RelayOrOtherSystemParachains<SystemParachainMatcher, Runtime>
|
||||
{
|
||||
fn contains(l: &MultiLocation) -> bool {
|
||||
fn contains(l: &Location) -> bool {
|
||||
let self_para_id: u32 = parachain_info::Pallet::<Runtime>::get().into();
|
||||
if let MultiLocation { parents: 0, interior: X1(Parachain(para_id)) } = l {
|
||||
if let (0, [Parachain(para_id)]) = l.unpack() {
|
||||
if *para_id == self_para_id {
|
||||
return false
|
||||
}
|
||||
}
|
||||
matches!(l, MultiLocation { parents: 1, interior: Here }) ||
|
||||
SystemParachainMatcher::contains(l)
|
||||
matches!(l.unpack(), (1, [])) || SystemParachainMatcher::contains(l)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,14 +104,12 @@ impl<SystemParachainMatcher: Contains<MultiLocation>, Runtime: parachain_info::C
|
||||
/// This structure can only be used at a parachain level. In the Relay Chain, please use
|
||||
/// the `xcm_builder::IsChildSystemParachain` matcher.
|
||||
pub struct AllSiblingSystemParachains;
|
||||
|
||||
impl Contains<MultiLocation> for AllSiblingSystemParachains {
|
||||
fn contains(l: &MultiLocation) -> bool {
|
||||
impl Contains<Location> for AllSiblingSystemParachains {
|
||||
fn contains(l: &Location) -> bool {
|
||||
log::trace!(target: "xcm::contains", "AllSiblingSystemParachains location: {:?}", l);
|
||||
match *l {
|
||||
match l.unpack() {
|
||||
// System parachain
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
|
||||
ParaId::from(id).is_system(),
|
||||
(1, [Parachain(id)]) => ParaId::from(*id).is_system(),
|
||||
// Everything else
|
||||
_ => false,
|
||||
}
|
||||
@@ -121,21 +118,20 @@ impl Contains<MultiLocation> for AllSiblingSystemParachains {
|
||||
|
||||
/// Accepts an asset if it is a concrete asset from the system (Relay Chain or system parachain).
|
||||
pub struct ConcreteAssetFromSystem<AssetLocation>(PhantomData<AssetLocation>);
|
||||
impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
impl<AssetLocation: Get<Location>> ContainsPair<Asset, Location>
|
||||
for ConcreteAssetFromSystem<AssetLocation>
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
log::trace!(target: "xcm::contains", "ConcreteAssetFromSystem asset: {:?}, origin: {:?}", asset, origin);
|
||||
let is_system = match origin {
|
||||
let is_system = match origin.unpack() {
|
||||
// The Relay Chain
|
||||
MultiLocation { parents: 1, interior: Here } => true,
|
||||
(1, []) => true,
|
||||
// System parachain
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(id)) } =>
|
||||
ParaId::from(*id).is_system(),
|
||||
(1, [Parachain(id)]) => ParaId::from(*id).is_system(),
|
||||
// Others
|
||||
_ => false,
|
||||
};
|
||||
matches!(asset.id, Concrete(id) if id == AssetLocation::get()) && is_system
|
||||
asset.id.0 == AssetLocation::get() && is_system
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +140,9 @@ impl<AssetLocation: Get<MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
/// This type should only be used within the context of a parachain, since it does not verify that
|
||||
/// the parent is indeed a Relay Chain.
|
||||
pub struct ParentRelayOrSiblingParachains;
|
||||
impl Contains<MultiLocation> for ParentRelayOrSiblingParachains {
|
||||
fn contains(location: &MultiLocation) -> bool {
|
||||
matches!(
|
||||
location,
|
||||
MultiLocation { parents: 1, interior: Here } |
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(_)) }
|
||||
)
|
||||
impl Contains<Location> for ParentRelayOrSiblingParachains {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Parachain(_)]))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,20 +151,20 @@ mod tests {
|
||||
use frame_support::{parameter_types, traits::Contains};
|
||||
|
||||
use super::{
|
||||
AllSiblingSystemParachains, ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here,
|
||||
MultiAsset, MultiLocation, PalletInstance, Parachain, Parent,
|
||||
AllSiblingSystemParachains, Asset, ConcreteAssetFromSystem, ContainsPair, GeneralIndex,
|
||||
Here, Location, PalletInstance, Parachain, Parent,
|
||||
};
|
||||
use polkadot_primitives::LOWEST_PUBLIC_ID;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
parameter_types! {
|
||||
pub const RelayLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const RelayLocation: Location = Location::parent();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn concrete_asset_from_relay_works() {
|
||||
let expected_asset: MultiAsset = (Parent, 1000000).into();
|
||||
let expected_origin: MultiLocation = (Parent, Here).into();
|
||||
let expected_asset: Asset = (Parent, 1000000).into();
|
||||
let expected_origin: Location = (Parent, Here).into();
|
||||
|
||||
assert!(<ConcreteAssetFromSystem<RelayLocation>>::contains(
|
||||
&expected_asset,
|
||||
@@ -182,12 +174,12 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn concrete_asset_from_sibling_system_para_fails_for_wrong_asset() {
|
||||
let unexpected_assets: Vec<MultiAsset> = vec![
|
||||
let unexpected_assets: Vec<Asset> = vec![
|
||||
(Here, 1000000).into(),
|
||||
((PalletInstance(50), GeneralIndex(1)), 1000000).into(),
|
||||
((Parent, Parachain(1000), PalletInstance(50), GeneralIndex(1)), 1000000).into(),
|
||||
];
|
||||
let expected_origin: MultiLocation = (Parent, Parachain(1000)).into();
|
||||
let expected_origin: Location = (Parent, Parachain(1000)).into();
|
||||
|
||||
unexpected_assets.iter().for_each(|asset| {
|
||||
assert!(!<ConcreteAssetFromSystem<RelayLocation>>::contains(asset, &expected_origin));
|
||||
@@ -206,10 +198,10 @@ mod tests {
|
||||
(2001, false), // Not a System Parachain
|
||||
];
|
||||
|
||||
let expected_asset: MultiAsset = (Parent, 1000000).into();
|
||||
let expected_asset: Asset = (Parent, 1000000).into();
|
||||
|
||||
for (para_id, expected_result) in test_data {
|
||||
let origin: MultiLocation = (Parent, Parachain(para_id)).into();
|
||||
let origin: Location = (Parent, Parachain(para_id)).into();
|
||||
assert_eq!(
|
||||
expected_result,
|
||||
<ConcreteAssetFromSystem<RelayLocation>>::contains(&expected_asset, &origin)
|
||||
@@ -220,15 +212,15 @@ mod tests {
|
||||
#[test]
|
||||
fn all_sibling_system_parachains_works() {
|
||||
// system parachain
|
||||
assert!(AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(Parachain(1)))));
|
||||
assert!(AllSiblingSystemParachains::contains(&Location::new(1, [Parachain(1)])));
|
||||
// non-system parachain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(
|
||||
assert!(!AllSiblingSystemParachains::contains(&Location::new(
|
||||
1,
|
||||
X1(Parachain(LOWEST_PUBLIC_ID.into()))
|
||||
[Parachain(LOWEST_PUBLIC_ID.into())]
|
||||
)));
|
||||
// when used at relay chain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(0, X1(Parachain(1)))));
|
||||
assert!(!AllSiblingSystemParachains::contains(&Location::new(0, [Parachain(1)])));
|
||||
// when used with non-parachain
|
||||
assert!(!AllSiblingSystemParachains::contains(&MultiLocation::new(1, X1(OnlyChild))));
|
||||
assert!(!AllSiblingSystemParachains::contains(&Location::new(1, [OnlyChild])));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -15,7 +15,9 @@
|
||||
|
||||
mod genesis;
|
||||
pub use genesis::{genesis, ED, PARA_ID_A, PARA_ID_B};
|
||||
pub use penpal_runtime::xcm_config::{LocalTeleportableToAssetHub, XcmConfig};
|
||||
pub use penpal_runtime::xcm_config::{
|
||||
LocalTeleportableToAssetHub, LocalTeleportableToAssetHubV3, XcmConfig,
|
||||
};
|
||||
|
||||
// Substrate
|
||||
use frame_support::traits::OnInitialize;
|
||||
|
||||
@@ -38,8 +38,9 @@ pub use polkadot_runtime_parachains::{
|
||||
inclusion::{AggregateMessageOrigin, UmpQueueId},
|
||||
};
|
||||
pub use xcm::{
|
||||
prelude::{MultiLocation, OriginKind, Outcome, VersionedXcm, XcmVersion},
|
||||
v3::Error,
|
||||
prelude::{Location, OriginKind, Outcome, VersionedXcm, XcmVersion},
|
||||
v3,
|
||||
v4::Error as XcmError,
|
||||
DoubleEncoded,
|
||||
};
|
||||
|
||||
@@ -209,7 +210,7 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::<N>::XcmPallet(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete { used: weight } }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
|
||||
@@ -224,21 +225,21 @@ macro_rules! impl_assert_events_helpers_for_relay_chain {
|
||||
/// Asserts a dispatchable is incompletely executed and XCM sent
|
||||
pub fn assert_xcm_pallet_attempted_incomplete(
|
||||
expected_weight: Option<$crate::impls::Weight>,
|
||||
expected_error: Option<$crate::impls::Error>,
|
||||
expected_error: Option<$crate::impls::XcmError>,
|
||||
) {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
// Dispatchable is properly executed and XCM message sent
|
||||
[<$chain RuntimeEvent>]::<N>::XcmPallet(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete { used: weight, error } }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
|
||||
expected_weight.unwrap_or(*weight),
|
||||
*weight
|
||||
),
|
||||
error: *error == expected_error.unwrap_or(*error),
|
||||
error: *error == expected_error.unwrap_or((*error).into()).into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -365,7 +366,7 @@ macro_rules! impl_send_transact_helpers_for_relay_chain {
|
||||
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
let root_origin = <Self as Chain>::RuntimeOrigin::root();
|
||||
let destination: $crate::impls::MultiLocation = <Self as RelayChain>::child_location_of(recipient);
|
||||
let destination: $crate::impls::Location = <Self as RelayChain>::child_location_of(recipient);
|
||||
let xcm = $crate::impls::xcm_transact_unpaid_execution(call, $crate::impls::OriginKind::Superuser);
|
||||
|
||||
// Send XCM `Transact`
|
||||
@@ -416,13 +417,13 @@ macro_rules! impl_accounts_helpers_for_parachain {
|
||||
network_id: $crate::impls::NetworkId,
|
||||
para_id: $crate::impls::ParaId,
|
||||
) -> $crate::impls::AccountId {
|
||||
let remote_location = $crate::impls::MultiLocation {
|
||||
parents: 2,
|
||||
interior: $crate::impls::Junctions::X2(
|
||||
let remote_location = $crate::impls::Location::new(
|
||||
2,
|
||||
[
|
||||
$crate::impls::Junction::GlobalConsensus(network_id),
|
||||
$crate::impls::Junction::Parachain(para_id.into()),
|
||||
),
|
||||
};
|
||||
],
|
||||
);
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
Self::sovereign_account_id_of(remote_location)
|
||||
})
|
||||
@@ -445,7 +446,7 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
Self,
|
||||
vec![
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) }
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete { used: weight } }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
|
||||
@@ -460,36 +461,36 @@ macro_rules! impl_assert_events_helpers_for_parachain {
|
||||
/// Asserts a dispatchable is incompletely executed and XCM sent
|
||||
pub fn assert_xcm_pallet_attempted_incomplete(
|
||||
expected_weight: Option<$crate::impls::Weight>,
|
||||
expected_error: Option<$crate::impls::Error>,
|
||||
expected_error: Option<$crate::impls::XcmError>,
|
||||
) {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
// Dispatchable is properly executed and XCM message sent
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) }
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete { used: weight, error } }
|
||||
) => {
|
||||
weight: $crate::impls::weight_within_threshold(
|
||||
($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD),
|
||||
expected_weight.unwrap_or(*weight),
|
||||
*weight
|
||||
),
|
||||
error: *error == expected_error.unwrap_or(*error),
|
||||
error: *error == expected_error.unwrap_or((*error).into()).into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// Asserts a dispatchable throws and error when trying to be sent
|
||||
pub fn assert_xcm_pallet_attempted_error(expected_error: Option<$crate::impls::Error>) {
|
||||
pub fn assert_xcm_pallet_attempted_error(expected_error: Option<$crate::impls::XcmError>) {
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
vec![
|
||||
// Execution fails in the origin with `Barrier`
|
||||
[<$chain RuntimeEvent>]::<N>::PolkadotXcm(
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Error(error) }
|
||||
$crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Error { error } }
|
||||
) => {
|
||||
error: *error == expected_error.unwrap_or(*error),
|
||||
error: *error == expected_error.unwrap_or((*error).into()).into(),
|
||||
},
|
||||
]
|
||||
);
|
||||
@@ -639,7 +640,7 @@ macro_rules! impl_assets_helpers_for_parachain {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::Assets::mint(
|
||||
signed_origin,
|
||||
id.into(),
|
||||
id.clone().into(),
|
||||
beneficiary.clone().into(),
|
||||
amount_to_mint
|
||||
));
|
||||
@@ -717,7 +718,7 @@ macro_rules! impl_assets_helpers_for_parachain {
|
||||
]
|
||||
);
|
||||
|
||||
assert!(<Self as [<$chain ParaPallet>]>::Assets::asset_exists(id.into()));
|
||||
assert!(<Self as [<$chain ParaPallet>]>::Assets::asset_exists(id.clone().into()));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -732,7 +733,7 @@ macro_rules! impl_foreign_assets_helpers_for_parachain {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Create foreign assets using sudo `ForeignAssets::force_create()`
|
||||
pub fn force_create_foreign_asset(
|
||||
id: $crate::impls::MultiLocation,
|
||||
id: $crate::impls::v3::Location,
|
||||
owner: $crate::impls::AccountId,
|
||||
is_sufficient: bool,
|
||||
min_balance: u128,
|
||||
@@ -744,13 +745,13 @@ macro_rules! impl_foreign_assets_helpers_for_parachain {
|
||||
$crate::impls::assert_ok!(
|
||||
<Self as [<$chain ParaPallet>]>::ForeignAssets::force_create(
|
||||
sudo_origin,
|
||||
id,
|
||||
id.clone(),
|
||||
owner.clone().into(),
|
||||
is_sufficient,
|
||||
min_balance,
|
||||
)
|
||||
);
|
||||
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id));
|
||||
assert!(<Self as [<$chain ParaPallet>]>::ForeignAssets::asset_exists(id.clone()));
|
||||
type RuntimeEvent<N> = <$chain<N> as $crate::impls::Chain>::RuntimeEvent;
|
||||
$crate::impls::assert_expected_events!(
|
||||
Self,
|
||||
@@ -767,21 +768,21 @@ macro_rules! impl_foreign_assets_helpers_for_parachain {
|
||||
for (beneficiary, amount) in prefund_accounts.into_iter() {
|
||||
let signed_origin =
|
||||
<$chain<N> as $crate::impls::Chain>::RuntimeOrigin::signed(owner.clone());
|
||||
Self::mint_foreign_asset(signed_origin, id, beneficiary, amount);
|
||||
Self::mint_foreign_asset(signed_origin, id.clone(), beneficiary, amount);
|
||||
}
|
||||
}
|
||||
|
||||
/// Mint assets making use of the ForeignAssets pallet-assets instance
|
||||
pub fn mint_foreign_asset(
|
||||
signed_origin: <Self as $crate::impls::Chain>::RuntimeOrigin,
|
||||
id: $crate::impls::MultiLocation,
|
||||
id: $crate::impls::v3::Location,
|
||||
beneficiary: $crate::impls::AccountId,
|
||||
amount_to_mint: u128,
|
||||
) {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::ForeignAssets::mint(
|
||||
signed_origin,
|
||||
id.into(),
|
||||
id.clone().into(),
|
||||
beneficiary.clone().into(),
|
||||
amount_to_mint
|
||||
));
|
||||
@@ -813,7 +814,7 @@ macro_rules! impl_xcm_helpers_for_parachain {
|
||||
$crate::impls::paste::paste! {
|
||||
impl<N: $crate::impls::Network> $chain<N> {
|
||||
/// Set XCM version for destination.
|
||||
pub fn force_xcm_version(dest: $crate::impls::MultiLocation, version: $crate::impls::XcmVersion) {
|
||||
pub fn force_xcm_version(dest: $crate::impls::Location, version: $crate::impls::XcmVersion) {
|
||||
<Self as $crate::impls::TestExt>::execute_with(|| {
|
||||
$crate::impls::assert_ok!(<Self as [<$chain ParaPallet>]>::PolkadotXcm::force_xcm_version(
|
||||
<Self as $crate::impls::Chain>::RuntimeOrigin::root(),
|
||||
|
||||
@@ -40,6 +40,7 @@ use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy;
|
||||
|
||||
pub const XCM_V2: u32 = 2;
|
||||
pub const XCM_V3: u32 = 3;
|
||||
pub const XCM_V4: u32 = 4;
|
||||
pub const REF_TIME_THRESHOLD: u64 = 33;
|
||||
pub const PROOF_SIZE_THRESHOLD: u64 = 33;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ macro_rules! test_parachain_is_trusted_teleporter {
|
||||
<$receiver_para as $crate::macros::Chain>::account_data_of(receiver.clone()).free;
|
||||
let para_destination =
|
||||
<$sender_para>::sibling_location_of(<$receiver_para>::para_id());
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
$crate::macros::AccountId32 { network: None, id: receiver.clone().into() }.into();
|
||||
|
||||
// Send XCM message from Origin Parachain
|
||||
@@ -57,8 +57,8 @@ macro_rules! test_parachain_is_trusted_teleporter {
|
||||
<$sender_para>::execute_with(|| {
|
||||
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::limited_teleport_assets(
|
||||
origin.clone(),
|
||||
bx!(para_destination.into()),
|
||||
bx!(beneficiary.into()),
|
||||
bx!(para_destination.clone().into()),
|
||||
bx!(beneficiary.clone().into()),
|
||||
bx!($assets.clone().into()),
|
||||
fee_asset_item,
|
||||
weight_limit.clone(),
|
||||
@@ -127,8 +127,8 @@ macro_rules! include_penpal_create_foreign_asset_on_asset_hub {
|
||||
$crate::impls::paste::paste! {
|
||||
pub fn penpal_create_foreign_asset_on_asset_hub(
|
||||
asset_id_on_penpal: u32,
|
||||
foreign_asset_at_asset_hub: MultiLocation,
|
||||
ah_as_seen_by_penpal: MultiLocation,
|
||||
foreign_asset_at_asset_hub: v3::Location,
|
||||
ah_as_seen_by_penpal: Location,
|
||||
is_sufficient: bool,
|
||||
asset_owner: AccountId,
|
||||
prefund_amount: u128,
|
||||
@@ -144,14 +144,14 @@ macro_rules! include_penpal_create_foreign_asset_on_asset_hub {
|
||||
// prefund SA of Penpal on AssetHub with enough native tokens to pay for creating
|
||||
// new foreign asset, also prefund CheckingAccount with ED, because teleported asset
|
||||
// itself might not be sufficient and CheckingAccount cannot be created otherwise
|
||||
let sov_penpal_on_ah = $asset_hub::sovereign_account_id_of(penpal_as_seen_by_ah);
|
||||
let sov_penpal_on_ah = $asset_hub::sovereign_account_id_of(penpal_as_seen_by_ah.clone());
|
||||
$asset_hub::fund_accounts(vec![
|
||||
(sov_penpal_on_ah.clone().into(), $relay_ed * 100_000_000_000),
|
||||
(ah_check_account.clone().into(), $relay_ed * 1000),
|
||||
]);
|
||||
|
||||
// prefund SA of AssetHub on Penpal with native asset
|
||||
let sov_ah_on_penpal = $penpal::sovereign_account_id_of(ah_as_seen_by_penpal);
|
||||
let sov_ah_on_penpal = $penpal::sovereign_account_id_of(ah_as_seen_by_penpal.clone());
|
||||
$penpal::fund_accounts(vec![
|
||||
(sov_ah_on_penpal.into(), $relay_ed * 1_000_000_000),
|
||||
(penpal_check_account.clone().into(), $relay_ed * 1000),
|
||||
@@ -183,8 +183,8 @@ macro_rules! include_penpal_create_foreign_asset_on_asset_hub {
|
||||
let buy_execution_fee_amount = $weight_to_fee::weight_to_fee(
|
||||
&Weight::from_parts(10_100_000_000_000, 300_000),
|
||||
);
|
||||
let buy_execution_fee = MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
let buy_execution_fee = Asset {
|
||||
id: AssetId(Location { parents: 1, interior: Here }),
|
||||
fun: Fungible(buy_execution_fee_amount),
|
||||
};
|
||||
let xcm = VersionedXcm::from(Xcm(vec![
|
||||
|
||||
@@ -23,12 +23,12 @@ use xcm::{prelude::*, DoubleEncoded};
|
||||
pub fn xcm_transact_paid_execution(
|
||||
call: DoubleEncoded<()>,
|
||||
origin_kind: OriginKind,
|
||||
native_asset: MultiAsset,
|
||||
native_asset: Asset,
|
||||
beneficiary: AccountId,
|
||||
) -> VersionedXcm<()> {
|
||||
let weight_limit = WeightLimit::Unlimited;
|
||||
let require_weight_at_most = Weight::from_parts(1000000000, 200000);
|
||||
let native_assets: MultiAssets = native_asset.clone().into();
|
||||
let native_assets: Assets = native_asset.clone().into();
|
||||
|
||||
VersionedXcm::from(Xcm(vec![
|
||||
WithdrawAsset(native_assets),
|
||||
@@ -37,9 +37,9 @@ pub fn xcm_transact_paid_execution(
|
||||
RefundSurplus,
|
||||
DepositAsset {
|
||||
assets: All.into(),
|
||||
beneficiary: MultiLocation {
|
||||
beneficiary: Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 { network: None, id: beneficiary.into() }),
|
||||
interior: [AccountId32 { network: None, id: beneficiary.into() }].into(),
|
||||
},
|
||||
},
|
||||
]))
|
||||
@@ -61,15 +61,11 @@ pub fn xcm_transact_unpaid_execution(
|
||||
}
|
||||
|
||||
/// Helper method to get the non-fee asset used in multiple assets transfer
|
||||
pub fn non_fee_asset(assets: &MultiAssets, fee_idx: usize) -> Option<(MultiLocation, u128)> {
|
||||
pub fn non_fee_asset(assets: &Assets, fee_idx: usize) -> Option<(Location, u128)> {
|
||||
let asset = assets.inner().into_iter().enumerate().find(|a| a.0 != fee_idx)?.1.clone();
|
||||
let asset_id = match asset.id {
|
||||
Concrete(id) => id,
|
||||
_ => return None,
|
||||
};
|
||||
let asset_amount = match asset.fun {
|
||||
Fungible(amount) => amount,
|
||||
_ => return None,
|
||||
};
|
||||
Some((asset_id, asset_amount))
|
||||
Some((asset.id.0, asset_amount))
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ pub use frame_support::{
|
||||
// Polkadot
|
||||
pub use xcm::{
|
||||
prelude::{AccountId32 as AccountId32Junction, *},
|
||||
v3::{Error, NetworkId::Rococo as RococoId},
|
||||
v3::{self, Error, NetworkId::Rococo as RococoId},
|
||||
};
|
||||
|
||||
// Cumulus
|
||||
|
||||
+9
-9
@@ -30,7 +30,7 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == Rococo::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -53,7 +53,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubRococo::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -130,7 +130,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubRococo::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -190,10 +190,10 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa
|
||||
fn reserve_transfer_native_asset_from_relay_to_system_para_fails() {
|
||||
let signed_origin = <Rococo as Chain>::RuntimeOrigin::signed(RococoSender::get().into());
|
||||
let destination = Rococo::child_location_of(AssetHubRococo::para_id());
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: AssetHubRococoReceiver::get().into() }.into();
|
||||
let amount_to_send: Balance = ROCOCO_ED * 1000;
|
||||
let assets: MultiAssets = (Here, amount_to_send).into();
|
||||
let assets: Assets = (Here, amount_to_send).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
// this should fail
|
||||
@@ -225,11 +225,11 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() {
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get().into());
|
||||
let destination = AssetHubRococo::parent_location();
|
||||
let beneficiary_id = RococoReceiver::get();
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: beneficiary_id.into() }.into();
|
||||
let amount_to_send: Balance = ASSET_HUB_ROCOCO_ED * 1000;
|
||||
|
||||
let assets: MultiAssets = (Parent, amount_to_send).into();
|
||||
let assets: Assets = (Parent, amount_to_send).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
// this should fail
|
||||
@@ -418,9 +418,9 @@ fn reserve_transfer_assets_from_system_para_to_para() {
|
||||
let beneficiary_id = PenpalAReceiver::get();
|
||||
let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 1000;
|
||||
let asset_amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
let assets: MultiAssets = vec![
|
||||
let assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), asset_amount_to_send)
|
||||
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send)
|
||||
.into(),
|
||||
]
|
||||
.into();
|
||||
|
||||
+3
-4
@@ -19,14 +19,13 @@ use crate::*;
|
||||
fn relay_sets_system_para_xcm_supported_version() {
|
||||
// Init tests variables
|
||||
let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
|
||||
let system_para_destination: MultiLocation =
|
||||
Rococo::child_location_of(AssetHubRococo::para_id());
|
||||
let system_para_destination: Location = Rococo::child_location_of(AssetHubRococo::para_id());
|
||||
|
||||
// Relay Chain sets supported version for Asset Parachain
|
||||
Rococo::execute_with(|| {
|
||||
assert_ok!(<Rococo as RococoPallet>::XcmPallet::force_xcm_version(
|
||||
sudo_origin,
|
||||
bx!(system_para_destination),
|
||||
bx!(system_para_destination.clone()),
|
||||
XCM_V3
|
||||
));
|
||||
|
||||
@@ -52,7 +51,7 @@ fn system_para_sets_relay_xcm_supported_version() {
|
||||
<AssetHubRococo as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
|
||||
<AssetHubRococo as Chain>::Runtime,
|
||||
>::force_xcm_version {
|
||||
location: bx!(parent_location),
|
||||
location: bx!(parent_location.clone()),
|
||||
version: XCM_V3,
|
||||
})
|
||||
.encode()
|
||||
|
||||
+38
-30
@@ -15,16 +15,19 @@
|
||||
|
||||
use crate::*;
|
||||
use parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT;
|
||||
use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub;
|
||||
use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3;
|
||||
use sp_runtime::ModuleError;
|
||||
|
||||
#[test]
|
||||
fn swap_locally_on_chain_using_local_assets() {
|
||||
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
|
||||
let asset_one = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
|
||||
};
|
||||
let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get());
|
||||
let asset_one = Box::new(v3::Location::new(
|
||||
0,
|
||||
[
|
||||
v3::Junction::PalletInstance(ASSETS_PALLET_ID),
|
||||
v3::Junction::GeneralIndex(ASSET_ID.into()),
|
||||
],
|
||||
));
|
||||
|
||||
AssetHubRococo::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
|
||||
@@ -46,8 +49,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
));
|
||||
|
||||
assert_expected_events!(
|
||||
@@ -59,8 +62,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
0,
|
||||
@@ -75,7 +78,7 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
]
|
||||
);
|
||||
|
||||
let path = vec![Box::new(asset_native), Box::new(asset_one)];
|
||||
let path = vec![asset_native.clone(), asset_one.clone()];
|
||||
|
||||
assert_ok!(
|
||||
<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
@@ -100,8 +103,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native,
|
||||
asset_one,
|
||||
1414213562273 - EXISTENTIAL_DEPOSIT * 2, // all but the 2 EDs can't be retrieved.
|
||||
0,
|
||||
0,
|
||||
@@ -112,16 +115,16 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
#[test]
|
||||
fn swap_locally_on_chain_using_foreign_assets() {
|
||||
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
|
||||
let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get());
|
||||
let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id());
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get();
|
||||
let asset_id_on_penpal = match asset_location_on_penpal.last() {
|
||||
Some(GeneralIndex(id)) => *id as u32,
|
||||
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let asset_owner_on_penpal = PenpalASender::get();
|
||||
let foreign_asset_at_asset_hub_rococo =
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalA::para_id().into())) }
|
||||
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())])
|
||||
.appended_with(asset_location_on_penpal)
|
||||
.unwrap();
|
||||
|
||||
@@ -167,7 +170,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 4. Create pool:
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_rococo),
|
||||
));
|
||||
|
||||
@@ -181,7 +184,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 5. Add liquidity:
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_rococo),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
@@ -200,7 +203,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
);
|
||||
|
||||
// 6. Swap!
|
||||
let path = vec![Box::new(asset_native), Box::new(foreign_asset_at_asset_hub_rococo)];
|
||||
let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_rococo)];
|
||||
|
||||
assert_ok!(
|
||||
<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
@@ -226,7 +229,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 7. Remove liquidity
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahr.clone()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_rococo),
|
||||
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
|
||||
0,
|
||||
@@ -238,9 +241,11 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
#[test]
|
||||
fn cannot_create_pool_from_pool_assets() {
|
||||
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
|
||||
let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocation::get();
|
||||
asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
|
||||
let asset_native = Box::new(asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get());
|
||||
let mut asset_one = asset_hub_rococo_runtime::xcm_config::PoolAssetsPalletLocationV3::get();
|
||||
asset_one
|
||||
.append_with(v3::Junction::GeneralIndex(ASSET_ID.into()))
|
||||
.expect("pool assets");
|
||||
|
||||
AssetHubRococo::execute_with(|| {
|
||||
let pool_owner_account_id = asset_hub_rococo_runtime::AssetConversionOrigin::get();
|
||||
@@ -263,7 +268,7 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
assert_matches::assert_matches!(
|
||||
<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(asset_native),
|
||||
asset_native,
|
||||
Box::new(asset_one),
|
||||
),
|
||||
Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown"))
|
||||
@@ -273,10 +278,14 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
|
||||
#[test]
|
||||
fn pay_xcm_fee_with_some_asset_swapped_for_native() {
|
||||
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocation::get();
|
||||
let asset_one = MultiLocation {
|
||||
let asset_native = asset_hub_rococo_runtime::xcm_config::TokenLocationV3::get();
|
||||
let asset_one = xcm::v3::Location {
|
||||
parents: 0,
|
||||
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
|
||||
interior: [
|
||||
xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID),
|
||||
xcm::v3::Junction::GeneralIndex(ASSET_ID.into()),
|
||||
]
|
||||
.into(),
|
||||
};
|
||||
let penpal = AssetHubRococo::sovereign_account_id_of(AssetHubRococo::sibling_location_of(
|
||||
PenpalA::para_id(),
|
||||
@@ -365,8 +374,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() {
|
||||
let penpal_root = <PenpalA as Chain>::RuntimeOrigin::root();
|
||||
let fee_amount = 4_000_000_000_000u128;
|
||||
let asset_one =
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount)
|
||||
.into();
|
||||
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into();
|
||||
let asset_hub_location = PenpalA::sibling_location_of(AssetHubRococo::para_id()).into();
|
||||
let xcm = xcm_transact_paid_execution(
|
||||
call,
|
||||
|
||||
+18
-13
@@ -17,7 +17,7 @@ use crate::*;
|
||||
use asset_hub_rococo_runtime::xcm_config::XcmConfig as AssetHubRococoXcmConfig;
|
||||
use emulated_integration_tests_common::xcm_helpers::non_fee_asset;
|
||||
use rococo_runtime::xcm_config::XcmConfig as RococoXcmConfig;
|
||||
use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub;
|
||||
use rococo_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3;
|
||||
|
||||
fn relay_origin_assertions(t: RelayToSystemParaTest) {
|
||||
type RuntimeEvent = <Rococo as Chain>::RuntimeEvent;
|
||||
@@ -143,6 +143,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) {
|
||||
);
|
||||
let (expected_foreign_asset_id, expected_foreign_asset_amount) =
|
||||
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
|
||||
let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap();
|
||||
assert_expected_events!(
|
||||
AssetHubRococo,
|
||||
vec![
|
||||
@@ -157,7 +158,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) {
|
||||
who: *who == t.receiver.account_id,
|
||||
},
|
||||
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => {
|
||||
asset_id: *asset_id == expected_foreign_asset_id,
|
||||
asset_id: *asset_id == expected_foreign_asset_id_v3,
|
||||
owner: *owner == t.receiver.account_id,
|
||||
amount: *amount == expected_foreign_asset_amount,
|
||||
},
|
||||
@@ -174,6 +175,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
AssetHubRococo::assert_xcm_pallet_attempted_complete(None);
|
||||
let (expected_foreign_asset_id, expected_foreign_asset_amount) =
|
||||
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
|
||||
let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap();
|
||||
assert_expected_events!(
|
||||
AssetHubRococo,
|
||||
vec![
|
||||
@@ -183,13 +185,13 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubRococo::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
// foreign asset is burned locally as part of teleportation
|
||||
RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
|
||||
asset_id: *asset_id == expected_foreign_asset_id,
|
||||
asset_id: *asset_id == expected_foreign_asset_id_v3,
|
||||
owner: *owner == t.sender.account_id,
|
||||
balance: *balance == expected_foreign_asset_amount,
|
||||
},
|
||||
@@ -542,7 +544,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() {
|
||||
#[test]
|
||||
fn teleport_to_other_system_parachains_works() {
|
||||
let amount = ASSET_HUB_ROCOCO_ED * 100;
|
||||
let native_asset: MultiAssets = (Parent, amount).into();
|
||||
let native_asset: Assets = (Parent, amount).into();
|
||||
|
||||
test_parachain_is_trusted_teleporter!(
|
||||
AssetHubRococo, // Origin
|
||||
@@ -557,20 +559,20 @@ fn teleport_to_other_system_parachains_works() {
|
||||
#[test]
|
||||
fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
let ah_as_seen_by_penpal = PenpalA::sibling_location_of(AssetHubRococo::para_id());
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get();
|
||||
let asset_id_on_penpal = match asset_location_on_penpal.last() {
|
||||
Some(GeneralIndex(id)) => *id as u32,
|
||||
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let asset_owner_on_penpal = PenpalASender::get();
|
||||
let foreign_asset_at_asset_hub_rococo =
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalA::para_id().into())) }
|
||||
v3::Location::new(1, [v3::Junction::Parachain(PenpalA::para_id().into())])
|
||||
.appended_with(asset_location_on_penpal)
|
||||
.unwrap();
|
||||
super::penpal_create_foreign_asset_on_asset_hub(
|
||||
asset_id_on_penpal,
|
||||
foreign_asset_at_asset_hub_rococo,
|
||||
ah_as_seen_by_penpal,
|
||||
ah_as_seen_by_penpal.clone(),
|
||||
false,
|
||||
asset_owner_on_penpal,
|
||||
ASSET_MIN_BALANCE * 1_000_000,
|
||||
@@ -580,9 +582,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
let fee_amount_to_send = ASSET_HUB_ROCOCO_ED * 10_000;
|
||||
let asset_amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
|
||||
let penpal_assets: MultiAssets = vec![
|
||||
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
|
||||
let penpal_assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(asset_location_on_penpal, asset_amount_to_send).into(),
|
||||
(asset_location_on_penpal_latest, asset_amount_to_send).into(),
|
||||
]
|
||||
.into();
|
||||
let fee_asset_index = penpal_assets
|
||||
@@ -670,11 +673,13 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
));
|
||||
});
|
||||
|
||||
let foreign_asset_at_asset_hub_rococo_latest: Location =
|
||||
foreign_asset_at_asset_hub_rococo.try_into().unwrap();
|
||||
let ah_to_penpal_beneficiary_id = PenpalAReceiver::get();
|
||||
let penpal_as_seen_by_ah = AssetHubRococo::sibling_location_of(PenpalA::para_id());
|
||||
let ah_assets: MultiAssets = vec![
|
||||
let ah_assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(foreign_asset_at_asset_hub_rococo, asset_amount_to_send).into(),
|
||||
(foreign_asset_at_asset_hub_rococo_latest, asset_amount_to_send).into(),
|
||||
]
|
||||
.into();
|
||||
let fee_asset_index = ah_assets
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ pub use frame_support::{
|
||||
// Polkadot
|
||||
pub use xcm::{
|
||||
prelude::{AccountId32 as AccountId32Junction, *},
|
||||
v3::{Error, NetworkId::Westend as WestendId},
|
||||
v3::{self, Error, NetworkId::Westend as WestendId},
|
||||
};
|
||||
|
||||
// Cumulus
|
||||
|
||||
+6
-8
@@ -24,22 +24,20 @@ fn create_and_claim_treasury_spend() {
|
||||
const ASSET_ID: u32 = 1984;
|
||||
const SPEND_AMOUNT: u128 = 1_000_000;
|
||||
// treasury location from a sibling parachain.
|
||||
let treasury_location: MultiLocation = MultiLocation::new(
|
||||
1,
|
||||
X2(Parachain(CollectivesWestend::para_id().into()), PalletInstance(65)),
|
||||
);
|
||||
let treasury_location: Location =
|
||||
Location::new(1, [Parachain(CollectivesWestend::para_id().into()), PalletInstance(65)]);
|
||||
// treasury account on a sibling parachain.
|
||||
let treasury_account =
|
||||
asset_hub_westend_runtime::xcm_config::LocationToAccountId::convert_location(
|
||||
&treasury_location,
|
||||
)
|
||||
.unwrap();
|
||||
let asset_hub_location = MultiLocation::new(1, Parachain(AssetHubWestend::para_id().into()));
|
||||
let asset_hub_location = Location::new(1, [Parachain(AssetHubWestend::para_id().into())]);
|
||||
let root = <CollectivesWestend as Chain>::RuntimeOrigin::root();
|
||||
// asset kind to be spent from the treasury.
|
||||
let asset_kind = VersionedLocatableAsset::V3 {
|
||||
let asset_kind = VersionedLocatableAsset::V4 {
|
||||
location: asset_hub_location,
|
||||
asset_id: AssetId::Concrete((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()),
|
||||
asset_id: AssetId((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()),
|
||||
};
|
||||
// treasury spend beneficiary.
|
||||
let alice: AccountId = Westend::account_id_of(ALICE);
|
||||
@@ -75,7 +73,7 @@ fn create_and_claim_treasury_spend() {
|
||||
root,
|
||||
Box::new(asset_kind),
|
||||
SPEND_AMOUNT,
|
||||
Box::new(MultiLocation::new(0, Into::<[u8; 32]>::into(alice.clone())).into()),
|
||||
Box::new(Location::new(0, Into::<[u8; 32]>::into(alice.clone())).into()),
|
||||
None,
|
||||
));
|
||||
// claim the spend.
|
||||
|
||||
+9
-9
@@ -32,7 +32,7 @@ fn relay_to_para_sender_assertions(t: RelayToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == Westend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -57,7 +57,7 @@ fn system_para_to_para_sender_assertions(t: SystemParaToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubWestend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -140,7 +140,7 @@ fn system_para_to_para_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
asset_id: *asset_id == ASSET_ID,
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubWestend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
@@ -200,10 +200,10 @@ fn para_to_system_para_reserve_transfer_assets(t: ParaToSystemParaTest) -> Dispa
|
||||
fn reserve_transfer_native_asset_from_relay_to_system_para_fails() {
|
||||
let signed_origin = <Westend as Chain>::RuntimeOrigin::signed(WestendSender::get().into());
|
||||
let destination = Westend::child_location_of(AssetHubWestend::para_id());
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: AssetHubWestendReceiver::get().into() }.into();
|
||||
let amount_to_send: Balance = WESTEND_ED * 1000;
|
||||
let assets: MultiAssets = (Here, amount_to_send).into();
|
||||
let assets: Assets = (Here, amount_to_send).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
// this should fail
|
||||
@@ -235,10 +235,10 @@ fn reserve_transfer_native_asset_from_system_para_to_relay_fails() {
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get().into());
|
||||
let destination = AssetHubWestend::parent_location();
|
||||
let beneficiary_id = WestendReceiver::get();
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: beneficiary_id.into() }.into();
|
||||
let amount_to_send: Balance = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let assets: MultiAssets = (Parent, amount_to_send).into();
|
||||
let assets: Assets = (Parent, amount_to_send).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
// this should fail
|
||||
@@ -428,9 +428,9 @@ fn reserve_transfer_assets_from_system_para_to_para() {
|
||||
let beneficiary_id = PenpalBReceiver::get();
|
||||
let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let asset_amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
let assets: MultiAssets = vec![
|
||||
let assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), asset_amount_to_send)
|
||||
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], asset_amount_to_send)
|
||||
.into(),
|
||||
]
|
||||
.into();
|
||||
|
||||
+3
-4
@@ -19,14 +19,13 @@ use crate::*;
|
||||
fn relay_sets_system_para_xcm_supported_version() {
|
||||
// Init tests variables
|
||||
let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
|
||||
let system_para_destination: MultiLocation =
|
||||
Westend::child_location_of(AssetHubWestend::para_id());
|
||||
let system_para_destination: Location = Westend::child_location_of(AssetHubWestend::para_id());
|
||||
|
||||
// Relay Chain sets supported version for Asset Parachain
|
||||
Westend::execute_with(|| {
|
||||
assert_ok!(<Westend as WestendPallet>::XcmPallet::force_xcm_version(
|
||||
sudo_origin,
|
||||
bx!(system_para_destination),
|
||||
bx!(system_para_destination.clone()),
|
||||
XCM_V3
|
||||
));
|
||||
|
||||
@@ -52,7 +51,7 @@ fn system_para_sets_relay_xcm_supported_version() {
|
||||
<AssetHubWestend as Chain>::RuntimeCall::PolkadotXcm(pallet_xcm::Call::<
|
||||
<AssetHubWestend as Chain>::Runtime,
|
||||
>::force_xcm_version {
|
||||
location: bx!(parent_location),
|
||||
location: bx!(parent_location.clone()),
|
||||
version: XCM_V3,
|
||||
})
|
||||
.encode()
|
||||
|
||||
+38
-29
@@ -14,15 +14,19 @@
|
||||
// limitations under the License.
|
||||
|
||||
use crate::*;
|
||||
use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub;
|
||||
use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3;
|
||||
|
||||
#[test]
|
||||
fn swap_locally_on_chain_using_local_assets() {
|
||||
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get();
|
||||
let asset_one = MultiLocation {
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get());
|
||||
let asset_one = Box::new(v3::Location {
|
||||
parents: 0,
|
||||
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
|
||||
};
|
||||
interior: [
|
||||
v3::Junction::PalletInstance(ASSETS_PALLET_ID),
|
||||
v3::Junction::GeneralIndex(ASSET_ID.into()),
|
||||
]
|
||||
.into(),
|
||||
});
|
||||
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
@@ -44,8 +48,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
));
|
||||
|
||||
assert_expected_events!(
|
||||
@@ -57,8 +61,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
0,
|
||||
@@ -73,7 +77,7 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
]
|
||||
);
|
||||
|
||||
let path = vec![Box::new(asset_native), Box::new(asset_one)];
|
||||
let path = vec![asset_native.clone(), asset_one.clone()];
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
@@ -96,8 +100,8 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(asset_native),
|
||||
Box::new(asset_one),
|
||||
asset_native.clone(),
|
||||
asset_one.clone(),
|
||||
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
|
||||
0,
|
||||
0,
|
||||
@@ -108,16 +112,16 @@ fn swap_locally_on_chain_using_local_assets() {
|
||||
|
||||
#[test]
|
||||
fn swap_locally_on_chain_using_foreign_assets() {
|
||||
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get();
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get());
|
||||
let ah_as_seen_by_penpal = PenpalB::sibling_location_of(AssetHubWestend::para_id());
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get();
|
||||
let asset_id_on_penpal = match asset_location_on_penpal.last() {
|
||||
Some(GeneralIndex(id)) => *id as u32,
|
||||
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let asset_owner_on_penpal = PenpalBSender::get();
|
||||
let foreign_asset_at_asset_hub_westend =
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalB::para_id().into())) }
|
||||
v3::Location::new(1, [v3::Junction::Parachain(PenpalB::para_id().into())])
|
||||
.appended_with(asset_location_on_penpal)
|
||||
.unwrap();
|
||||
|
||||
@@ -163,7 +167,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 4. Create pool:
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_westend),
|
||||
));
|
||||
|
||||
@@ -177,7 +181,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 5. Add liquidity:
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahw.clone()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_westend),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
@@ -196,7 +200,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
);
|
||||
|
||||
// 6. Swap!
|
||||
let path = vec![Box::new(asset_native), Box::new(foreign_asset_at_asset_hub_westend)];
|
||||
let path = vec![asset_native.clone(), Box::new(foreign_asset_at_asset_hub_westend)];
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::swap_exact_tokens_for_tokens(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
@@ -220,7 +224,7 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
// 7. Remove liquidity
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::remove_liquidity(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(sov_penpal_on_ahw.clone()),
|
||||
Box::new(asset_native),
|
||||
asset_native.clone(),
|
||||
Box::new(foreign_asset_at_asset_hub_westend),
|
||||
1414213562273 - 2_000_000_000, // all but the 2 EDs can't be retrieved.
|
||||
0,
|
||||
@@ -232,9 +236,11 @@ fn swap_locally_on_chain_using_foreign_assets() {
|
||||
|
||||
#[test]
|
||||
fn cannot_create_pool_from_pool_assets() {
|
||||
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get();
|
||||
let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocation::get();
|
||||
asset_one.append_with(GeneralIndex(ASSET_ID.into())).expect("pool assets");
|
||||
let asset_native = Box::new(asset_hub_westend_runtime::xcm_config::WestendLocationV3::get());
|
||||
let mut asset_one = asset_hub_westend_runtime::xcm_config::PoolAssetsPalletLocationV3::get();
|
||||
asset_one
|
||||
.append_with(v3::Junction::GeneralIndex(ASSET_ID.into()))
|
||||
.expect("pool assets");
|
||||
|
||||
AssetHubWestend::execute_with(|| {
|
||||
let pool_owner_account_id = asset_hub_westend_runtime::AssetConversionOrigin::get();
|
||||
@@ -257,7 +263,7 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
assert_matches::assert_matches!(
|
||||
<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(asset_native),
|
||||
asset_native,
|
||||
Box::new(asset_one),
|
||||
),
|
||||
Err(DispatchError::Module(ModuleError{index: _, error: _, message})) => assert_eq!(message, Some("Unknown"))
|
||||
@@ -267,10 +273,14 @@ fn cannot_create_pool_from_pool_assets() {
|
||||
|
||||
#[test]
|
||||
fn pay_xcm_fee_with_some_asset_swapped_for_native() {
|
||||
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocation::get();
|
||||
let asset_one = MultiLocation {
|
||||
let asset_native = asset_hub_westend_runtime::xcm_config::WestendLocationV3::get();
|
||||
let asset_one = xcm::v3::Location {
|
||||
parents: 0,
|
||||
interior: X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())),
|
||||
interior: [
|
||||
xcm::v3::Junction::PalletInstance(ASSETS_PALLET_ID),
|
||||
xcm::v3::Junction::GeneralIndex(ASSET_ID.into()),
|
||||
]
|
||||
.into(),
|
||||
};
|
||||
let penpal = AssetHubWestend::sovereign_account_id_of(AssetHubWestend::sibling_location_of(
|
||||
PenpalB::para_id(),
|
||||
@@ -359,8 +369,7 @@ fn pay_xcm_fee_with_some_asset_swapped_for_native() {
|
||||
let penpal_root = <PenpalB as Chain>::RuntimeOrigin::root();
|
||||
let fee_amount = 4_000_000_000_000u128;
|
||||
let asset_one =
|
||||
(X2(PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())), fee_amount)
|
||||
.into();
|
||||
([PalletInstance(ASSETS_PALLET_ID), GeneralIndex(ASSET_ID.into())], fee_amount).into();
|
||||
let asset_hub_location = PenpalB::sibling_location_of(AssetHubWestend::para_id()).into();
|
||||
let xcm = xcm_transact_paid_execution(
|
||||
call,
|
||||
|
||||
+18
-13
@@ -17,7 +17,7 @@ use crate::*;
|
||||
use asset_hub_westend_runtime::xcm_config::XcmConfig as AssetHubWestendXcmConfig;
|
||||
use emulated_integration_tests_common::xcm_helpers::non_fee_asset;
|
||||
use westend_runtime::xcm_config::XcmConfig as WestendXcmConfig;
|
||||
use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHub as PenpalLocalTeleportableToAssetHub;
|
||||
use westend_system_emulated_network::penpal_emulated_chain::LocalTeleportableToAssetHubV3 as PenpalLocalTeleportableToAssetHubV3;
|
||||
|
||||
fn relay_origin_assertions(t: RelayToSystemParaTest) {
|
||||
type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
|
||||
@@ -143,6 +143,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) {
|
||||
);
|
||||
let (expected_foreign_asset_id, expected_foreign_asset_amount) =
|
||||
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
|
||||
let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap();
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
@@ -157,7 +158,7 @@ fn penpal_to_ah_foreign_assets_receiver_assertions(t: ParaToSystemParaTest) {
|
||||
who: *who == t.receiver.account_id,
|
||||
},
|
||||
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, amount }) => {
|
||||
asset_id: *asset_id == expected_foreign_asset_id,
|
||||
asset_id: *asset_id == expected_foreign_asset_id_v3,
|
||||
owner: *owner == t.receiver.account_id,
|
||||
amount: *amount == expected_foreign_asset_amount,
|
||||
},
|
||||
@@ -174,6 +175,7 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
AssetHubWestend::assert_xcm_pallet_attempted_complete(None);
|
||||
let (expected_foreign_asset_id, expected_foreign_asset_amount) =
|
||||
non_fee_asset(&t.args.assets, t.args.fee_asset_item as usize).unwrap();
|
||||
let expected_foreign_asset_id_v3: v3::Location = expected_foreign_asset_id.try_into().unwrap();
|
||||
assert_expected_events!(
|
||||
AssetHubWestend,
|
||||
vec![
|
||||
@@ -183,13 +185,13 @@ fn ah_to_penpal_foreign_assets_sender_assertions(t: SystemParaToParaTest) {
|
||||
) => {
|
||||
from: *from == t.sender.account_id,
|
||||
to: *to == AssetHubWestend::sovereign_account_id_of(
|
||||
t.args.dest
|
||||
t.args.dest.clone()
|
||||
),
|
||||
amount: *amount == t.args.amount,
|
||||
},
|
||||
// foreign asset is burned locally as part of teleportation
|
||||
RuntimeEvent::ForeignAssets(pallet_assets::Event::Burned { asset_id, owner, balance }) => {
|
||||
asset_id: *asset_id == expected_foreign_asset_id,
|
||||
asset_id: *asset_id == expected_foreign_asset_id_v3,
|
||||
owner: *owner == t.sender.account_id,
|
||||
balance: *balance == expected_foreign_asset_amount,
|
||||
},
|
||||
@@ -542,7 +544,7 @@ fn teleport_native_assets_from_system_para_to_relay_fails() {
|
||||
#[test]
|
||||
fn teleport_to_other_system_parachains_works() {
|
||||
let amount = ASSET_HUB_WESTEND_ED * 100;
|
||||
let native_asset: MultiAssets = (Parent, amount).into();
|
||||
let native_asset: Assets = (Parent, amount).into();
|
||||
|
||||
test_parachain_is_trusted_teleporter!(
|
||||
AssetHubWestend, // Origin
|
||||
@@ -557,20 +559,20 @@ fn teleport_to_other_system_parachains_works() {
|
||||
#[test]
|
||||
fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
let ah_as_seen_by_penpal = PenpalB::sibling_location_of(AssetHubWestend::para_id());
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHub::get();
|
||||
let asset_location_on_penpal = PenpalLocalTeleportableToAssetHubV3::get();
|
||||
let asset_id_on_penpal = match asset_location_on_penpal.last() {
|
||||
Some(GeneralIndex(id)) => *id as u32,
|
||||
Some(v3::Junction::GeneralIndex(id)) => *id as u32,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
let asset_owner_on_penpal = PenpalBSender::get();
|
||||
let foreign_asset_at_asset_hub_westend =
|
||||
MultiLocation { parents: 1, interior: X1(Parachain(PenpalB::para_id().into())) }
|
||||
v3::Location::new(1, [v3::Junction::Parachain(PenpalB::para_id().into())])
|
||||
.appended_with(asset_location_on_penpal)
|
||||
.unwrap();
|
||||
super::penpal_create_foreign_asset_on_asset_hub(
|
||||
asset_id_on_penpal,
|
||||
foreign_asset_at_asset_hub_westend,
|
||||
ah_as_seen_by_penpal,
|
||||
ah_as_seen_by_penpal.clone(),
|
||||
false,
|
||||
asset_owner_on_penpal,
|
||||
ASSET_MIN_BALANCE * 1_000_000,
|
||||
@@ -580,9 +582,10 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
let fee_amount_to_send = ASSET_HUB_WESTEND_ED * 1000;
|
||||
let asset_amount_to_send = ASSET_MIN_BALANCE * 1000;
|
||||
|
||||
let penpal_assets: MultiAssets = vec![
|
||||
let asset_location_on_penpal_latest: Location = asset_location_on_penpal.try_into().unwrap();
|
||||
let penpal_assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(asset_location_on_penpal, asset_amount_to_send).into(),
|
||||
(asset_location_on_penpal_latest, asset_amount_to_send).into(),
|
||||
]
|
||||
.into();
|
||||
let fee_asset_index = penpal_assets
|
||||
@@ -670,11 +673,13 @@ fn bidirectional_teleport_foreign_assets_between_para_and_asset_hub() {
|
||||
));
|
||||
});
|
||||
|
||||
let foreign_asset_at_asset_hub_westend_latest: Location =
|
||||
foreign_asset_at_asset_hub_westend.try_into().unwrap();
|
||||
let ah_to_penpal_beneficiary_id = PenpalBReceiver::get();
|
||||
let penpal_as_seen_by_ah = AssetHubWestend::sibling_location_of(PenpalB::para_id());
|
||||
let ah_assets: MultiAssets = vec![
|
||||
let ah_assets: Assets = vec![
|
||||
(Parent, fee_amount_to_send).into(),
|
||||
(foreign_asset_at_asset_hub_westend, asset_amount_to_send).into(),
|
||||
(foreign_asset_at_asset_hub_westend_latest, asset_amount_to_send).into(),
|
||||
]
|
||||
.into();
|
||||
let fee_asset_index = ah_assets
|
||||
|
||||
+5
-5
@@ -24,19 +24,19 @@ fn create_and_claim_treasury_spend() {
|
||||
const ASSET_ID: u32 = 1984;
|
||||
const SPEND_AMOUNT: u128 = 1_000_000;
|
||||
// treasury location from a sibling parachain.
|
||||
let treasury_location: MultiLocation = MultiLocation::new(1, PalletInstance(37));
|
||||
let treasury_location: Location = Location::new(1, PalletInstance(37));
|
||||
// treasury account on a sibling parachain.
|
||||
let treasury_account =
|
||||
asset_hub_westend_runtime::xcm_config::LocationToAccountId::convert_location(
|
||||
&treasury_location,
|
||||
)
|
||||
.unwrap();
|
||||
let asset_hub_location = MultiLocation::new(0, Parachain(AssetHubWestend::para_id().into()));
|
||||
let asset_hub_location = Location::new(0, Parachain(AssetHubWestend::para_id().into()));
|
||||
let root = <Westend as Chain>::RuntimeOrigin::root();
|
||||
// asset kind to be spend from the treasury.
|
||||
let asset_kind = VersionedLocatableAsset::V3 {
|
||||
let asset_kind = VersionedLocatableAsset::V4 {
|
||||
location: asset_hub_location,
|
||||
asset_id: AssetId::Concrete((PalletInstance(50), GeneralIndex(ASSET_ID.into())).into()),
|
||||
asset_id: AssetId([PalletInstance(50), GeneralIndex(ASSET_ID.into())].into()),
|
||||
};
|
||||
// treasury spend beneficiary.
|
||||
let alice: AccountId = Westend::account_id_of(ALICE);
|
||||
@@ -71,7 +71,7 @@ fn create_and_claim_treasury_spend() {
|
||||
root,
|
||||
Box::new(asset_kind),
|
||||
SPEND_AMOUNT,
|
||||
Box::new(MultiLocation::new(0, Into::<[u8; 32]>::into(alice.clone())).into()),
|
||||
Box::new(Location::new(0, Into::<[u8; 32]>::into(alice.clone())).into()),
|
||||
None,
|
||||
));
|
||||
// claim the spend.
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ pub use xcm::{
|
||||
latest::ParentThen,
|
||||
prelude::{AccountId32 as AccountId32Junction, *},
|
||||
v3::{
|
||||
Error,
|
||||
self, Error,
|
||||
NetworkId::{Rococo as RococoId, Westend as WestendId},
|
||||
},
|
||||
};
|
||||
|
||||
+14
-9
@@ -15,14 +15,14 @@
|
||||
|
||||
use crate::tests::*;
|
||||
|
||||
fn send_asset_from_asset_hub_rococo_to_asset_hub_westend(id: MultiLocation, amount: u128) {
|
||||
fn send_asset_from_asset_hub_rococo_to_asset_hub_westend(id: Location, amount: u128) {
|
||||
let destination = asset_hub_westend_location();
|
||||
|
||||
// fund the AHR's SA on BHR for paying bridge transport fees
|
||||
BridgeHubRococo::fund_para_sovereign(AssetHubRococo::para_id(), 10_000_000_000_000u128);
|
||||
|
||||
// set XCM versions
|
||||
AssetHubRococo::force_xcm_version(destination, XCM_VERSION);
|
||||
AssetHubRococo::force_xcm_version(destination.clone(), XCM_VERSION);
|
||||
BridgeHubRococo::force_xcm_version(bridge_hub_westend_location(), XCM_VERSION);
|
||||
|
||||
// send message over bridge
|
||||
@@ -33,9 +33,9 @@ fn send_asset_from_asset_hub_rococo_to_asset_hub_westend(id: MultiLocation, amou
|
||||
|
||||
#[test]
|
||||
fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
let roc_at_asset_hub_rococo: MultiLocation = Parent.into();
|
||||
let roc_at_asset_hub_rococo: v3::Location = v3::Parent.into();
|
||||
let roc_at_asset_hub_westend =
|
||||
MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) };
|
||||
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]);
|
||||
let owner: AccountId = AssetHubWestend::account_id_of(ALICE);
|
||||
AssetHubWestend::force_create_foreign_asset(
|
||||
roc_at_asset_hub_westend,
|
||||
@@ -62,7 +62,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::create_pool(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(Parent.into()),
|
||||
Box::new(xcm::v3::Parent.into()),
|
||||
Box::new(roc_at_asset_hub_westend),
|
||||
));
|
||||
|
||||
@@ -75,7 +75,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
|
||||
assert_ok!(<AssetHubWestend as AssetHubWestendPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get()),
|
||||
Box::new(Parent.into()),
|
||||
Box::new(xcm::v3::Parent.into()),
|
||||
Box::new(roc_at_asset_hub_westend),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
@@ -101,8 +101,9 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
<Assets as Inspect<_>>::balance(roc_at_asset_hub_westend, &AssetHubWestendReceiver::get())
|
||||
});
|
||||
|
||||
let roc_at_asset_hub_rococo_latest: Location = roc_at_asset_hub_rococo.try_into().unwrap();
|
||||
let amount = ASSET_HUB_ROCOCO_ED * 1_000_000;
|
||||
send_asset_from_asset_hub_rococo_to_asset_hub_westend(roc_at_asset_hub_rococo, amount);
|
||||
send_asset_from_asset_hub_rococo_to_asset_hub_westend(roc_at_asset_hub_rococo_latest, amount);
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
assert_expected_events!(
|
||||
@@ -142,7 +143,7 @@ fn send_rocs_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
let prefund_amount = 10_000_000_000_000u128;
|
||||
let wnd_at_asset_hub_rococo =
|
||||
MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) };
|
||||
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
|
||||
let owner: AccountId = AssetHubWestend::account_id_of(ALICE);
|
||||
AssetHubRococo::force_create_foreign_asset(
|
||||
wnd_at_asset_hub_rococo,
|
||||
@@ -170,8 +171,12 @@ fn send_wnds_from_asset_hub_rococo_to_asset_hub_westend() {
|
||||
let receiver_wnds_before =
|
||||
<AssetHubWestend as Chain>::account_data_of(AssetHubWestendReceiver::get()).free;
|
||||
|
||||
let wnd_at_asset_hub_rococo_latest: Location = wnd_at_asset_hub_rococo.try_into().unwrap();
|
||||
let amount_to_send = ASSET_HUB_WESTEND_ED * 1_000;
|
||||
send_asset_from_asset_hub_rococo_to_asset_hub_westend(wnd_at_asset_hub_rococo, amount_to_send);
|
||||
send_asset_from_asset_hub_rococo_to_asset_hub_westend(
|
||||
wnd_at_asset_hub_rococo_latest.clone(),
|
||||
amount_to_send,
|
||||
);
|
||||
AssetHubWestend::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubWestend as Chain>::RuntimeEvent;
|
||||
assert_expected_events!(
|
||||
|
||||
+14
-20
@@ -20,37 +20,31 @@ mod send_xcm;
|
||||
mod snowbridge;
|
||||
mod teleport;
|
||||
|
||||
pub(crate) fn asset_hub_westend_location() -> MultiLocation {
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
GlobalConsensus(NetworkId::Westend),
|
||||
Parachain(AssetHubWestend::para_id().into()),
|
||||
),
|
||||
}
|
||||
pub(crate) fn asset_hub_westend_location() -> Location {
|
||||
Location::new(
|
||||
2,
|
||||
[GlobalConsensus(NetworkId::Westend), Parachain(AssetHubWestend::para_id().into())],
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn bridge_hub_westend_location() -> MultiLocation {
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
GlobalConsensus(NetworkId::Westend),
|
||||
Parachain(BridgeHubWestend::para_id().into()),
|
||||
),
|
||||
}
|
||||
pub(crate) fn bridge_hub_westend_location() -> Location {
|
||||
Location::new(
|
||||
2,
|
||||
[GlobalConsensus(NetworkId::Westend), Parachain(BridgeHubWestend::para_id().into())],
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn send_asset_from_asset_hub_rococo(
|
||||
destination: MultiLocation,
|
||||
(id, amount): (MultiLocation, u128),
|
||||
destination: Location,
|
||||
(id, amount): (Location, u128),
|
||||
) -> DispatchResult {
|
||||
let signed_origin =
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get().into());
|
||||
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: AssetHubWestendReceiver::get().into() }.into();
|
||||
|
||||
let assets: MultiAssets = (id, amount).into();
|
||||
let assets: Assets = (id, amount).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
AssetHubRococo::execute_with(|| {
|
||||
|
||||
+15
-9
@@ -29,8 +29,8 @@ fn send_xcm_from_rococo_relay_to_westend_asset_hub_should_fail_on_not_applicable
|
||||
let xcm = VersionedXcm::from(Xcm(vec![
|
||||
UnpaidExecution { weight_limit, check_origin },
|
||||
ExportMessage {
|
||||
network: WestendId,
|
||||
destination: X1(Parachain(AssetHubWestend::para_id().into())),
|
||||
network: WestendId.into(),
|
||||
destination: [Parachain(AssetHubWestend::para_id().into())].into(),
|
||||
xcm: remote_xcm,
|
||||
},
|
||||
]));
|
||||
@@ -68,7 +68,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
|
||||
// prepare data
|
||||
let destination = asset_hub_westend_location();
|
||||
let native_token = MultiLocation::parent();
|
||||
let native_token = Location::parent();
|
||||
let amount = ASSET_HUB_ROCOCO_ED * 1_000;
|
||||
|
||||
// fund the AHR's SA on BHR for paying bridge transport fees
|
||||
@@ -78,7 +78,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
|
||||
// send XCM from AssetHubRococo - fails - destination version not known
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_rococo(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -87,7 +87,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
|
||||
// set destination version
|
||||
AssetHubRococo::force_xcm_version(destination, xcm::v3::prelude::XCM_VERSION);
|
||||
AssetHubRococo::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);
|
||||
|
||||
// TODO: remove this block, when removing `xcm:v2`
|
||||
{
|
||||
@@ -95,7 +95,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
// version, which does not have the `ExportMessage` instruction. If the default `2` is
|
||||
// changed to `3`, then this assert can go away"
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_rococo(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -110,7 +110,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
// send XCM from AssetHubRococo - fails - `ExportMessage` is not in `2`
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_rococo(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_rococo(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -125,7 +125,10 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
xcm::v3::prelude::XCM_VERSION,
|
||||
);
|
||||
// send XCM from AssetHubRococo - ok
|
||||
assert_ok!(send_asset_from_asset_hub_rococo(destination, (native_token, amount)));
|
||||
assert_ok!(send_asset_from_asset_hub_rococo(
|
||||
destination.clone(),
|
||||
(native_token.clone(), amount)
|
||||
));
|
||||
|
||||
// `ExportMessage` on local BridgeHub - fails - remote BridgeHub version not known
|
||||
assert_bridge_hub_rococo_message_accepted(false);
|
||||
@@ -142,7 +145,10 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
|
||||
// send XCM from AssetHubRococo - ok
|
||||
assert_ok!(send_asset_from_asset_hub_rococo(destination, (native_token, amount)));
|
||||
assert_ok!(send_asset_from_asset_hub_rococo(
|
||||
destination.clone(),
|
||||
(native_token.clone(), amount)
|
||||
));
|
||||
assert_bridge_hub_rococo_message_accepted(true);
|
||||
assert_bridge_hub_westend_message_received();
|
||||
// message delivered and processed at destination
|
||||
|
||||
+30
-33
@@ -61,7 +61,7 @@ fn create_agent() {
|
||||
|
||||
let remote_xcm = VersionedXcm::from(Xcm(vec![
|
||||
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
||||
DescendOrigin(X1(Parachain(origin_para))),
|
||||
DescendOrigin(Parachain(origin_para).into()),
|
||||
Transact {
|
||||
require_weight_at_most: 3000000000.into(),
|
||||
origin_kind: OriginKind::Xcm,
|
||||
@@ -109,14 +109,14 @@ fn create_channel() {
|
||||
BridgeHubRococo::fund_para_sovereign(origin_para.into(), INITIAL_FUND);
|
||||
|
||||
let sudo_origin = <Rococo as Chain>::RuntimeOrigin::root();
|
||||
let destination: VersionedMultiLocation =
|
||||
let destination: VersionedLocation =
|
||||
Rococo::child_location_of(BridgeHubRococo::para_id()).into();
|
||||
|
||||
let create_agent_call = SnowbridgeControl::Control(ControlCall::CreateAgent {});
|
||||
|
||||
let create_agent_xcm = VersionedXcm::from(Xcm(vec![
|
||||
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
||||
DescendOrigin(X1(Parachain(origin_para))),
|
||||
DescendOrigin(Parachain(origin_para).into()),
|
||||
Transact {
|
||||
require_weight_at_most: 3000000000.into(),
|
||||
origin_kind: OriginKind::Xcm,
|
||||
@@ -129,7 +129,7 @@ fn create_channel() {
|
||||
|
||||
let create_channel_xcm = VersionedXcm::from(Xcm(vec![
|
||||
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
||||
DescendOrigin(X1(Parachain(origin_para))),
|
||||
DescendOrigin(Parachain(origin_para).into()),
|
||||
Transact {
|
||||
require_weight_at_most: 3000000000.into(),
|
||||
origin_kind: OriginKind::Xcm,
|
||||
@@ -218,10 +218,10 @@ fn register_weth_token_from_ethereum_to_asset_hub() {
|
||||
|
||||
#[test]
|
||||
fn send_token_from_ethereum_to_penpal() {
|
||||
let asset_hub_sovereign = BridgeHubRococo::sovereign_account_id_of(MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(AssetHubRococo::para_id().into())),
|
||||
});
|
||||
let asset_hub_sovereign = BridgeHubRococo::sovereign_account_id_of(Location::new(
|
||||
1,
|
||||
[Parachain(AssetHubRococo::para_id().into())],
|
||||
));
|
||||
BridgeHubRococo::fund_accounts(vec![(asset_hub_sovereign.clone(), INITIAL_FUND)]);
|
||||
|
||||
PenpalA::fund_accounts(vec![
|
||||
@@ -229,9 +229,9 @@ fn send_token_from_ethereum_to_penpal() {
|
||||
(PenpalASender::get(), INITIAL_FUND),
|
||||
]);
|
||||
|
||||
let weth_asset_location: MultiLocation =
|
||||
let weth_asset_location: Location =
|
||||
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
|
||||
let weth_asset_id = weth_asset_location.into();
|
||||
let weth_asset_id: v3::Location = weth_asset_location.try_into().unwrap();
|
||||
|
||||
let origin_location = (Parent, Parent, EthereumNetwork::get()).into();
|
||||
|
||||
@@ -375,18 +375,15 @@ fn send_token_from_ethereum_to_asset_hub() {
|
||||
#[test]
|
||||
fn send_weth_asset_from_asset_hub_to_ethereum() {
|
||||
use asset_hub_rococo_runtime::xcm_config::bridging::to_ethereum::DefaultBridgeHubEthereumBaseFee;
|
||||
let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of(MultiLocation {
|
||||
parents: 1,
|
||||
interior: X1(Parachain(AssetHubRococo::para_id().into())),
|
||||
});
|
||||
let assethub_sovereign = BridgeHubRococo::sovereign_account_id_of(Location::new(
|
||||
1,
|
||||
[Parachain(AssetHubRococo::para_id().into())],
|
||||
));
|
||||
|
||||
AssetHubRococo::force_default_xcm_version(Some(XCM_VERSION));
|
||||
BridgeHubRococo::force_default_xcm_version(Some(XCM_VERSION));
|
||||
AssetHubRococo::force_xcm_version(
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Ethereum { chain_id: CHAIN_ID })),
|
||||
},
|
||||
Location::new(2, [GlobalConsensus(Ethereum { chain_id: CHAIN_ID })]),
|
||||
XCM_VERSION,
|
||||
);
|
||||
|
||||
@@ -437,27 +434,27 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
|
||||
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. }) => {},
|
||||
]
|
||||
);
|
||||
let assets = vec![MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
let assets = vec![Asset {
|
||||
id: AssetId(Location::new(
|
||||
2,
|
||||
[
|
||||
GlobalConsensus(Ethereum { chain_id: CHAIN_ID }),
|
||||
AccountKey20 { network: None, key: WETH },
|
||||
),
|
||||
}),
|
||||
],
|
||||
)),
|
||||
fun: Fungible(WETH_AMOUNT),
|
||||
}];
|
||||
let multi_assets = VersionedMultiAssets::V3(MultiAssets::from(assets));
|
||||
let multi_assets = VersionedAssets::V4(Assets::from(assets));
|
||||
|
||||
let destination = VersionedMultiLocation::V3(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Ethereum { chain_id: CHAIN_ID })),
|
||||
});
|
||||
let destination = VersionedLocation::V4(Location::new(
|
||||
2,
|
||||
[GlobalConsensus(Ethereum { chain_id: CHAIN_ID })],
|
||||
));
|
||||
|
||||
let beneficiary = VersionedMultiLocation::V3(MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }),
|
||||
});
|
||||
let beneficiary = VersionedLocation::V4(Location::new(
|
||||
0,
|
||||
[AccountKey20 { network: None, key: ETHEREUM_DESTINATION_ADDRESS.into() }],
|
||||
));
|
||||
|
||||
let free_balance_before = <AssetHubRococo as AssetHubRococoPallet>::Balances::free_balance(
|
||||
AssetHubRococoReceiver::get(),
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ use bridge_hub_rococo_runtime::xcm_config::XcmConfig;
|
||||
#[test]
|
||||
fn teleport_to_other_system_parachains_works() {
|
||||
let amount = BRIDGE_HUB_ROCOCO_ED * 100;
|
||||
let native_asset: MultiAssets = (Parent, amount).into();
|
||||
let native_asset: Assets = (Parent, amount).into();
|
||||
|
||||
test_parachain_is_trusted_teleporter!(
|
||||
BridgeHubRococo, // Origin
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@ pub use sp_runtime::DispatchError;
|
||||
pub use xcm::{
|
||||
latest::ParentThen,
|
||||
prelude::{AccountId32 as AccountId32Junction, *},
|
||||
v3::{
|
||||
v3,
|
||||
v4::{
|
||||
Error,
|
||||
NetworkId::{Rococo as RococoId, Westend as WestendId},
|
||||
},
|
||||
|
||||
+12
-8
@@ -14,14 +14,14 @@
|
||||
// limitations under the License.
|
||||
use crate::tests::*;
|
||||
|
||||
fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: MultiLocation, amount: u128) {
|
||||
fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: Location, amount: u128) {
|
||||
let destination = asset_hub_rococo_location();
|
||||
|
||||
// fund the AHW's SA on BHW for paying bridge transport fees
|
||||
BridgeHubWestend::fund_para_sovereign(AssetHubWestend::para_id(), 10_000_000_000_000u128);
|
||||
|
||||
// set XCM versions
|
||||
AssetHubWestend::force_xcm_version(destination, XCM_VERSION);
|
||||
AssetHubWestend::force_xcm_version(destination.clone(), XCM_VERSION);
|
||||
BridgeHubWestend::force_xcm_version(bridge_hub_rococo_location(), XCM_VERSION);
|
||||
|
||||
// send message over bridge
|
||||
@@ -32,9 +32,9 @@ fn send_asset_from_asset_hub_westend_to_asset_hub_rococo(id: MultiLocation, amou
|
||||
|
||||
#[test]
|
||||
fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
let wnd_at_asset_hub_westend: MultiLocation = Parent.into();
|
||||
let wnd_at_asset_hub_westend: Location = Parent.into();
|
||||
let wnd_at_asset_hub_rococo =
|
||||
MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Westend)) };
|
||||
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Westend)]);
|
||||
let owner: AccountId = AssetHubRococo::account_id_of(ALICE);
|
||||
AssetHubRococo::force_create_foreign_asset(
|
||||
wnd_at_asset_hub_rococo,
|
||||
@@ -61,7 +61,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::create_pool(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(Parent.into()),
|
||||
Box::new(xcm::v3::Parent.into()),
|
||||
Box::new(wnd_at_asset_hub_rococo),
|
||||
));
|
||||
|
||||
@@ -74,7 +74,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
|
||||
assert_ok!(<AssetHubRococo as AssetHubRococoPallet>::AssetConversion::add_liquidity(
|
||||
<AssetHubRococo as Chain>::RuntimeOrigin::signed(AssetHubRococoSender::get()),
|
||||
Box::new(Parent.into()),
|
||||
Box::new(xcm::v3::Parent.into()),
|
||||
Box::new(wnd_at_asset_hub_rococo),
|
||||
1_000_000_000_000,
|
||||
2_000_000_000_000,
|
||||
@@ -141,7 +141,7 @@ fn send_wnds_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
let prefund_amount = 10_000_000_000_000u128;
|
||||
let roc_at_asset_hub_westend =
|
||||
MultiLocation { parents: 2, interior: X1(GlobalConsensus(NetworkId::Rococo)) };
|
||||
v3::Location::new(2, [v3::Junction::GlobalConsensus(v3::NetworkId::Rococo)]);
|
||||
let owner: AccountId = AssetHubWestend::account_id_of(ALICE);
|
||||
AssetHubWestend::force_create_foreign_asset(
|
||||
roc_at_asset_hub_westend,
|
||||
@@ -169,8 +169,12 @@ fn send_rocs_from_asset_hub_westend_to_asset_hub_rococo() {
|
||||
let receiver_rocs_before =
|
||||
<AssetHubRococo as Chain>::account_data_of(AssetHubRococoReceiver::get()).free;
|
||||
|
||||
let roc_at_asset_hub_westend_latest: Location = roc_at_asset_hub_westend.try_into().unwrap();
|
||||
let amount_to_send = ASSET_HUB_ROCOCO_ED * 1_000;
|
||||
send_asset_from_asset_hub_westend_to_asset_hub_rococo(roc_at_asset_hub_westend, amount_to_send);
|
||||
send_asset_from_asset_hub_westend_to_asset_hub_rococo(
|
||||
roc_at_asset_hub_westend_latest.clone(),
|
||||
amount_to_send,
|
||||
);
|
||||
AssetHubRococo::execute_with(|| {
|
||||
type RuntimeEvent = <AssetHubRococo as Chain>::RuntimeEvent;
|
||||
assert_expected_events!(
|
||||
|
||||
+14
-20
@@ -19,37 +19,31 @@ mod asset_transfers;
|
||||
mod send_xcm;
|
||||
mod teleport;
|
||||
|
||||
pub(crate) fn asset_hub_rococo_location() -> MultiLocation {
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
GlobalConsensus(NetworkId::Rococo),
|
||||
Parachain(AssetHubRococo::para_id().into()),
|
||||
),
|
||||
}
|
||||
pub(crate) fn asset_hub_rococo_location() -> Location {
|
||||
Location::new(
|
||||
2,
|
||||
[GlobalConsensus(NetworkId::Rococo), Parachain(AssetHubRococo::para_id().into())],
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn bridge_hub_rococo_location() -> MultiLocation {
|
||||
MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
GlobalConsensus(NetworkId::Rococo),
|
||||
Parachain(BridgeHubRococo::para_id().into()),
|
||||
),
|
||||
}
|
||||
pub(crate) fn bridge_hub_rococo_location() -> Location {
|
||||
Location::new(
|
||||
2,
|
||||
[GlobalConsensus(NetworkId::Rococo), Parachain(BridgeHubRococo::para_id().into())],
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn send_asset_from_asset_hub_westend(
|
||||
destination: MultiLocation,
|
||||
(id, amount): (MultiLocation, u128),
|
||||
destination: Location,
|
||||
(id, amount): (Location, u128),
|
||||
) -> DispatchResult {
|
||||
let signed_origin =
|
||||
<AssetHubWestend as Chain>::RuntimeOrigin::signed(AssetHubWestendSender::get().into());
|
||||
|
||||
let beneficiary: MultiLocation =
|
||||
let beneficiary: Location =
|
||||
AccountId32Junction { network: None, id: AssetHubRococoReceiver::get().into() }.into();
|
||||
|
||||
let assets: MultiAssets = (id, amount).into();
|
||||
let assets: Assets = (id, amount).into();
|
||||
let fee_asset_item = 0;
|
||||
|
||||
AssetHubWestend::execute_with(|| {
|
||||
|
||||
+14
-8
@@ -30,7 +30,7 @@ fn send_xcm_from_westend_relay_to_rococo_asset_hub_should_fail_on_not_applicable
|
||||
UnpaidExecution { weight_limit, check_origin },
|
||||
ExportMessage {
|
||||
network: RococoId,
|
||||
destination: X1(Parachain(AssetHubRococo::para_id().into())),
|
||||
destination: [Parachain(AssetHubRococo::para_id().into())].into(),
|
||||
xcm: remote_xcm,
|
||||
},
|
||||
]));
|
||||
@@ -68,7 +68,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
|
||||
// prepare data
|
||||
let destination = asset_hub_rococo_location();
|
||||
let native_token = MultiLocation::parent();
|
||||
let native_token = Location::parent();
|
||||
let amount = ASSET_HUB_WESTEND_ED * 1_000;
|
||||
|
||||
// fund the AHR's SA on BHR for paying bridge transport fees
|
||||
@@ -78,7 +78,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
|
||||
// send XCM from AssetHubWestend - fails - destination version not known
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_westend(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -87,7 +87,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
|
||||
// set destination version
|
||||
AssetHubWestend::force_xcm_version(destination, xcm::v3::prelude::XCM_VERSION);
|
||||
AssetHubWestend::force_xcm_version(destination.clone(), xcm::v3::prelude::XCM_VERSION);
|
||||
|
||||
// TODO: remove this block, when removing `xcm:v2`
|
||||
{
|
||||
@@ -95,7 +95,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
// version, which does not have the `ExportMessage` instruction. If the default `2` is
|
||||
// changed to `3`, then this assert can go away"
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_westend(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -110,7 +110,7 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
// send XCM from AssetHubWestend - fails - `ExportMessage` is not in `2`
|
||||
assert_err!(
|
||||
send_asset_from_asset_hub_westend(destination, (native_token, amount)),
|
||||
send_asset_from_asset_hub_westend(destination.clone(), (native_token.clone(), amount)),
|
||||
DispatchError::Module(sp_runtime::ModuleError {
|
||||
index: 31,
|
||||
error: [1, 0, 0, 0],
|
||||
@@ -125,7 +125,10 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
xcm::v3::prelude::XCM_VERSION,
|
||||
);
|
||||
// send XCM from AssetHubWestend - ok
|
||||
assert_ok!(send_asset_from_asset_hub_westend(destination, (native_token, amount)));
|
||||
assert_ok!(send_asset_from_asset_hub_westend(
|
||||
destination.clone(),
|
||||
(native_token.clone(), amount)
|
||||
));
|
||||
|
||||
// `ExportMessage` on local BridgeHub - fails - remote BridgeHub version not known
|
||||
assert_bridge_hub_westend_message_accepted(false);
|
||||
@@ -142,7 +145,10 @@ fn send_xcm_through_opened_lane_with_different_xcm_version_on_hops_works() {
|
||||
);
|
||||
|
||||
// send XCM from AssetHubWestend - ok
|
||||
assert_ok!(send_asset_from_asset_hub_westend(destination, (native_token, amount)));
|
||||
assert_ok!(send_asset_from_asset_hub_westend(
|
||||
destination.clone(),
|
||||
(native_token.clone(), amount)
|
||||
));
|
||||
assert_bridge_hub_westend_message_accepted(true);
|
||||
assert_bridge_hub_rococo_message_received();
|
||||
// message delivered and processed at destination
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ use bridge_hub_westend_runtime::xcm_config::XcmConfig;
|
||||
#[test]
|
||||
fn teleport_to_other_system_parachains_works() {
|
||||
let amount = BRIDGE_HUB_WESTEND_ED * 100;
|
||||
let native_asset: MultiAssets = (Parent, amount).into();
|
||||
let native_asset: Assets = (Parent, amount).into();
|
||||
|
||||
test_parachain_is_trusted_teleporter!(
|
||||
BridgeHubWestend, // Origin
|
||||
|
||||
@@ -77,9 +77,9 @@ pub mod pallet {
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
PingSent(ParaId, u32, Vec<u8>, XcmHash, MultiAssets),
|
||||
PingSent(ParaId, u32, Vec<u8>, XcmHash, Assets),
|
||||
Pinged(ParaId, u32, Vec<u8>),
|
||||
PongSent(ParaId, u32, Vec<u8>, XcmHash, MultiAssets),
|
||||
PongSent(ParaId, u32, Vec<u8>, XcmHash, Assets),
|
||||
Ponged(ParaId, u32, Vec<u8>, BlockNumberFor<T>),
|
||||
ErrorSendingPing(SendError, ParaId, u32, Vec<u8>),
|
||||
ErrorSendingPong(SendError, ParaId, u32, Vec<u8>),
|
||||
|
||||
@@ -31,7 +31,7 @@ use assets_common::{
|
||||
foreign_creators::ForeignCreators,
|
||||
local_and_foreign_assets::{LocalFromLeft, TargetFromLeft},
|
||||
matching::{FromNetwork, FromSiblingParachain},
|
||||
AssetIdForTrustBackedAssetsConvert, MultiLocationForAssetId,
|
||||
AssetIdForTrustBackedAssetsConvert,
|
||||
};
|
||||
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
|
||||
use cumulus_primitives_core::AggregateMessageOrigin;
|
||||
@@ -80,13 +80,11 @@ use parachains_common::{
|
||||
Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT,
|
||||
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
|
||||
};
|
||||
|
||||
use sp_runtime::{Perbill, RuntimeDebug};
|
||||
use xcm::opaque::v3::MultiLocation;
|
||||
use xcm_config::{
|
||||
ForeignAssetsConvertedConcreteId, ForeignCreatorsSovereignAccountOf, GovernanceLocation,
|
||||
PoolAssetsConvertedConcreteId, TokenLocation, TrustBackedAssetsConvertedConcreteId,
|
||||
TrustBackedAssetsPalletLocation,
|
||||
PoolAssetsConvertedConcreteId, TokenLocation, TokenLocationV3,
|
||||
TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3,
|
||||
};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -95,7 +93,13 @@ pub use sp_runtime::BuildStorage;
|
||||
// Polkadot imports
|
||||
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
|
||||
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
|
||||
use xcm::latest::prelude::*;
|
||||
// We exclude `Assets` since it's the name of a pallet
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use xcm::latest::prelude::{
|
||||
Asset, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, NetworkId,
|
||||
NonFungible, Parent, ParentThen, Response, XCM_VERSION,
|
||||
};
|
||||
use xcm::latest::prelude::{AssetId, BodyId};
|
||||
|
||||
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
|
||||
|
||||
@@ -317,10 +321,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
|
||||
Assets,
|
||||
ForeignAssets,
|
||||
LocalFromLeft<
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>,
|
||||
AssetIdForTrustBackedAssets,
|
||||
xcm::v3::Location,
|
||||
>,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
AccountId,
|
||||
>;
|
||||
|
||||
@@ -328,8 +333,8 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
|
||||
pub type NativeAndAssets = fungible::UnionOf<
|
||||
Balances,
|
||||
LocalAndForeignAssets,
|
||||
TargetFromLeft<TokenLocation>,
|
||||
MultiLocation,
|
||||
TargetFromLeft<TokenLocationV3, xcm::v3::Location>,
|
||||
xcm::v3::Location,
|
||||
AccountId,
|
||||
>;
|
||||
|
||||
@@ -337,15 +342,15 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Balance = Balance;
|
||||
type HigherPrecisionBalance = sp_core::U256;
|
||||
type AssetKind = MultiLocation;
|
||||
type AssetKind = xcm::v3::Location;
|
||||
type Assets = NativeAndAssets;
|
||||
type PoolId = (Self::AssetKind, Self::AssetKind);
|
||||
type PoolLocator =
|
||||
pallet_asset_conversion::WithFirstAsset<TokenLocation, AccountId, Self::AssetKind>;
|
||||
pallet_asset_conversion::WithFirstAsset<TokenLocationV3, AccountId, Self::AssetKind>;
|
||||
type PoolAssetId = u32;
|
||||
type PoolAssets = PoolAssets;
|
||||
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
|
||||
type PoolSetupFeeAsset = TokenLocation;
|
||||
type PoolSetupFeeAsset = TokenLocationV3;
|
||||
type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
|
||||
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
|
||||
type LPFee = ConstU32<3>;
|
||||
@@ -355,9 +360,10 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_asset_conversion::WeightInfo<Runtime>;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
|
||||
TokenLocation,
|
||||
TokenLocationV3,
|
||||
parachain_info::Pallet<Runtime>,
|
||||
xcm_config::AssetsPalletIndex,
|
||||
xcm_config::TrustBackedAssetsPalletIndex,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -379,16 +385,17 @@ 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::MultiLocation;
|
||||
type AssetIdParameter = xcm::v3::MultiLocation;
|
||||
type Currency = Balances;
|
||||
type CreateOrigin = ForeignCreators<
|
||||
(
|
||||
FromSiblingParachain<parachain_info::Pallet<Runtime>>,
|
||||
FromNetwork<xcm_config::UniversalLocation, EthereumNetwork>,
|
||||
FromSiblingParachain<parachain_info::Pallet<Runtime>, xcm::v3::Location>,
|
||||
FromNetwork<xcm_config::UniversalLocation, EthereumNetwork, xcm::v3::Location>,
|
||||
),
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
AccountId,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
type ForceOrigin = AssetsForceOrigin;
|
||||
type AssetDeposit = ForeignAssetsAssetDeposit;
|
||||
@@ -664,7 +671,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(xcm_config::TokenLocation::get());
|
||||
pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocation::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
|
||||
}
|
||||
@@ -753,7 +760,7 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Fungibles = LocalAndForeignAssets;
|
||||
type OnChargeAssetTransaction =
|
||||
AssetConversionAdapter<Balances, AssetConversion, TokenLocation>;
|
||||
AssetConversionAdapter<Balances, AssetConversion, TokenLocationV3>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -1157,18 +1164,16 @@ impl_runtime_apis! {
|
||||
impl pallet_asset_conversion::AssetConversionApi<
|
||||
Block,
|
||||
Balance,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
> for Runtime
|
||||
{
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: MultiLocation, asset2: MultiLocation, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
|
||||
}
|
||||
|
||||
fn quote_price_tokens_for_exact_tokens(asset1: MultiLocation, asset2: MultiLocation, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
|
||||
}
|
||||
|
||||
fn get_reserves(asset1: MultiLocation, asset2: MultiLocation) -> Option<(Balance, Balance)> {
|
||||
fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> {
|
||||
AssetConversion::get_reserves(asset1, asset2).ok()
|
||||
}
|
||||
}
|
||||
@@ -1222,7 +1227,7 @@ impl_runtime_apis! {
|
||||
AccountId,
|
||||
> for Runtime
|
||||
{
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
use assets_common::fungible_conversion::{convert, convert_balance};
|
||||
Ok([
|
||||
// collect pallet_balance
|
||||
@@ -1346,45 +1351,45 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
let random_para_id = 43211234;
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
random_para_id.into()
|
||||
);
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
ParentThen(Parachain(random_para_id).into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
) -> Option<(xcm::v4::Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
// Transfer to Relay some local AH asset (local-reserve-transfer) while paying
|
||||
// fees using teleported native token.
|
||||
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
|
||||
let dest = Parent.into();
|
||||
|
||||
let fee_amount = EXISTENTIAL_DEPOSIT;
|
||||
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();
|
||||
let fee_asset: Asset = (Location::parent(), fee_amount).into();
|
||||
|
||||
let who = frame_benchmarking::whitelisted_caller();
|
||||
// Give some multiple of the existential deposit
|
||||
@@ -1402,13 +1407,13 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
pallet_assets::Instance1
|
||||
>(true, initial_asset_amount);
|
||||
let asset_location = MultiLocation::new(
|
||||
let asset_location = Location::new(
|
||||
0,
|
||||
X2(PalletInstance(50), GeneralIndex(u32::from(asset_id).into()))
|
||||
[PalletInstance(50), GeneralIndex(u32::from(asset_id).into())]
|
||||
);
|
||||
let transfer_asset: MultiAsset = (asset_location, asset_amount).into();
|
||||
let transfer_asset: Asset = (asset_location, asset_amount).into();
|
||||
|
||||
let assets: MultiAssets = vec![fee_asset.clone(), transfer_asset].into();
|
||||
let assets: xcm::v4::Assets = vec![fee_asset.clone(), transfer_asset].into();
|
||||
let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 };
|
||||
|
||||
// verify transferred successfully
|
||||
@@ -1432,14 +1437,14 @@ impl_runtime_apis! {
|
||||
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
|
||||
);
|
||||
}
|
||||
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError> {
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
|
||||
);
|
||||
let bridged_asset_hub = xcm_config::bridging::to_westend::AssetHubWestend::get();
|
||||
let _ = PolkadotXcm::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(bridged_asset_hub),
|
||||
Box::new(bridged_asset_hub.clone()),
|
||||
XCM_VERSION,
|
||||
).map_err(|e| {
|
||||
log::error!(
|
||||
@@ -1455,12 +1460,11 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_config::{TokenLocation, MaxAssetsIntoHolding};
|
||||
use pallet_xcm_benchmarks::asset_instance_from;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
@@ -1471,33 +1475,33 @@ impl_runtime_apis! {
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositMultiAsset,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
Ok(TokenLocation::get())
|
||||
}
|
||||
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
|
||||
fn worst_case_holding(depositable_count: u32) -> xcm::v4::Assets {
|
||||
// A mix of fungible, non-fungible, and concrete assets.
|
||||
let holding_non_fungibles = MaxAssetsIntoHolding::get() / 2 - depositable_count;
|
||||
let holding_fungibles = holding_non_fungibles.saturating_sub(1);
|
||||
let fungibles_amount: u128 = 100;
|
||||
let mut assets = (0..holding_fungibles)
|
||||
.map(|i| {
|
||||
MultiAsset {
|
||||
id: Concrete(GeneralIndex(i as u128).into()),
|
||||
Asset {
|
||||
id: GeneralIndex(i as u128).into(),
|
||||
fun: Fungible(fungibles_amount * i as u128),
|
||||
}
|
||||
})
|
||||
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
|
||||
.chain((0..holding_non_fungibles).map(|i| MultiAsset {
|
||||
id: Concrete(GeneralIndex(i as u128).into()),
|
||||
.chain(core::iter::once(Asset { id: Here.into(), fun: Fungible(u128::MAX) }))
|
||||
.chain((0..holding_non_fungibles).map(|i| Asset {
|
||||
id: GeneralIndex(i as u128).into(),
|
||||
fun: NonFungible(asset_instance_from(i)),
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assets.push(MultiAsset {
|
||||
id: Concrete(TokenLocation::get()),
|
||||
assets.push(Asset {
|
||||
id: AssetId(TokenLocation::get()),
|
||||
fun: Fungible(1_000_000 * UNITS),
|
||||
});
|
||||
assets.into()
|
||||
@@ -1505,16 +1509,16 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
|
||||
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
|
||||
TokenLocation::get(),
|
||||
MultiAsset { fun: Fungible(UNITS), id: Concrete(TokenLocation::get()) },
|
||||
Asset { fun: Fungible(UNITS), id: AssetId(TokenLocation::get()) },
|
||||
));
|
||||
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
|
||||
// AssetHubRococo trusts AssetHubWestend as reserve for WNDs
|
||||
pub TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(
|
||||
pub TrustedReserve: Option<(Location, Asset)> = Some(
|
||||
(
|
||||
xcm_config::bridging::to_westend::AssetHubWestend::get(),
|
||||
MultiAsset::from((xcm_config::bridging::to_westend::WndLocation::get(), 1000000000000 as u128))
|
||||
Asset::from((xcm_config::bridging::to_westend::WndLocation::get(), 1000000000000 as u128))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1526,9 +1530,9 @@ impl_runtime_apis! {
|
||||
type TrustedTeleporter = TrustedTeleporter;
|
||||
type TrustedReserve = TrustedReserve;
|
||||
|
||||
fn get_multi_asset() -> MultiAsset {
|
||||
MultiAsset {
|
||||
id: Concrete(TokenLocation::get()),
|
||||
fn get_asset() -> Asset {
|
||||
Asset {
|
||||
id: AssetId(TokenLocation::get()),
|
||||
fun: Fungible(UNITS),
|
||||
}
|
||||
}
|
||||
@@ -1542,42 +1546,42 @@ impl_runtime_apis! {
|
||||
(0u64, Response::Version(Default::default()))
|
||||
}
|
||||
|
||||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
|
||||
fn worst_case_asset_exchange() -> Result<(xcm::v4::Assets, xcm::v4::Assets), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
|
||||
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
|
||||
match xcm_config::bridging::BridgingBenchmarksHelper::prepare_universal_alias() {
|
||||
Some(alias) => Ok(alias),
|
||||
None => Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
|
||||
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
|
||||
fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
|
||||
Ok((TokenLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
|
||||
}
|
||||
|
||||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn subscribe_origin() -> Result<Location, BenchmarkError> {
|
||||
Ok(TokenLocation::get())
|
||||
}
|
||||
|
||||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
|
||||
fn claimable_asset() -> Result<(Location, Location, xcm::v4::Assets), BenchmarkError> {
|
||||
let origin = TokenLocation::get();
|
||||
let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = MultiLocation { parents: 0, interior: Here };
|
||||
let assets: xcm::v4::Assets = (TokenLocation::get(), 1_000 * UNITS).into();
|
||||
let ticket = Location { parents: 0, interior: Here };
|
||||
Ok((origin, ticket, assets))
|
||||
}
|
||||
|
||||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
|
||||
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn export_message_origin_and_destination(
|
||||
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
|
||||
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
|
||||
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
|
||||
use sp_std::prelude::*;
|
||||
use xcm::{latest::prelude::*, DoubleEncoded};
|
||||
|
||||
trait WeighMultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
|
||||
trait WeighAssets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight;
|
||||
}
|
||||
|
||||
const MAX_ASSETS: u64 = 100;
|
||||
|
||||
impl WeighMultiAssets for MultiAssetFilter {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for AssetFilter {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
match self {
|
||||
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
|
||||
Self::Wild(asset) => match asset {
|
||||
@@ -50,40 +50,36 @@ impl WeighMultiAssets for MultiAssetFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeighMultiAssets for MultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for Assets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
weight.saturating_mul(self.inner().iter().count() as u64)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AssetHubRococoXcmWeight<Call>(core::marker::PhantomData<Call>);
|
||||
impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn withdraw_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
fn withdraw_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
}
|
||||
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
fn reserve_asset_deposited(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
}
|
||||
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
fn receive_teleported_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
}
|
||||
fn query_response(
|
||||
_query_id: &u64,
|
||||
_response: &Response,
|
||||
_max_weight: &Weight,
|
||||
_querier: &Option<MultiLocation>,
|
||||
_querier: &Option<Location>,
|
||||
) -> Weight {
|
||||
XcmGeneric::<Runtime>::query_response()
|
||||
}
|
||||
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
}
|
||||
fn transfer_reserve_asset(
|
||||
assets: &MultiAssets,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
}
|
||||
fn transact(
|
||||
_origin_type: &OriginKind,
|
||||
@@ -111,43 +107,35 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn clear_origin() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_origin()
|
||||
}
|
||||
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
|
||||
fn descend_origin(_who: &InteriorLocation) -> Weight {
|
||||
XcmGeneric::<Runtime>::descend_origin()
|
||||
}
|
||||
fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_error()
|
||||
}
|
||||
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
}
|
||||
fn deposit_reserve_asset(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
}
|
||||
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
|
||||
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn initiate_reserve_withdraw(
|
||||
assets: &MultiAssetFilter,
|
||||
_reserve: &MultiLocation,
|
||||
assets: &AssetFilter,
|
||||
_reserve: &Location,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
}
|
||||
fn initiate_teleport(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
}
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_holding()
|
||||
}
|
||||
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
|
||||
fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
|
||||
XcmGeneric::<Runtime>::buy_execution()
|
||||
}
|
||||
fn refund_surplus() -> Weight {
|
||||
@@ -162,7 +150,7 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn clear_error() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_error()
|
||||
}
|
||||
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
|
||||
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
|
||||
XcmGeneric::<Runtime>::claim_asset()
|
||||
}
|
||||
fn trap(_code: &u64) -> Weight {
|
||||
@@ -174,13 +162,13 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn unsubscribe_version() -> Weight {
|
||||
XcmGeneric::<Runtime>::unsubscribe_version()
|
||||
}
|
||||
fn burn_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
fn burn_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
}
|
||||
fn expect_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
fn expect_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
}
|
||||
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
|
||||
fn expect_origin(_origin: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::expect_origin()
|
||||
}
|
||||
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
|
||||
@@ -213,16 +201,16 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn lock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn unlock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn note_unlockable(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn request_unlock(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn set_fees_mode(_: &bool) -> Weight {
|
||||
@@ -234,11 +222,11 @@ impl<Call> XcmWeightInfo<Call> for AssetHubRococoXcmWeight<Call> {
|
||||
fn clear_topic() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_topic()
|
||||
}
|
||||
fn alias_origin(_: &MultiLocation) -> Weight {
|
||||
fn alias_origin(_: &Location) -> Weight {
|
||||
// XCM Executor does not currently support alias origin operations
|
||||
Weight::MAX
|
||||
}
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::unpaid_execution()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -19,12 +19,18 @@
|
||||
|
||||
use asset_hub_rococo_runtime::{
|
||||
xcm_config,
|
||||
xcm_config::{bridging, ForeignCreatorsSovereignAccountOf, LocationToAccountId, TokenLocation},
|
||||
xcm_config::{
|
||||
bridging, ForeignCreatorsSovereignAccountOf, LocationToAccountId, TokenLocation,
|
||||
TokenLocationV3,
|
||||
},
|
||||
AllPalletsWithoutSystem, MetadataDepositBase, MetadataDepositPerByte, RuntimeCall,
|
||||
RuntimeEvent, ToWestendXcmRouterInstance, XcmpQueue,
|
||||
};
|
||||
pub use asset_hub_rococo_runtime::{
|
||||
xcm_config::{CheckingAccount, TrustBackedAssetsPalletLocation, XcmConfig},
|
||||
xcm_config::{
|
||||
CheckingAccount, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3,
|
||||
XcmConfig,
|
||||
},
|
||||
AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit,
|
||||
ForeignAssets, ForeignAssetsInstance, ParachainSystem, Runtime, SessionKeys, System,
|
||||
TrustBackedAssetsInstance,
|
||||
@@ -49,14 +55,18 @@ use parachains_common::{
|
||||
};
|
||||
use sp_runtime::traits::MaybeEquivalence;
|
||||
use std::convert::Into;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::traits::{Identity, JustTry, WeightTrader};
|
||||
use xcm::latest::prelude::{Assets as XcmAssets, *};
|
||||
use xcm_builder::V4V3LocationConverter;
|
||||
use xcm_executor::traits::{JustTry, WeightTrader};
|
||||
|
||||
const ALICE: [u8; 32] = [1u8; 32];
|
||||
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvert =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>;
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvertLatest =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
|
||||
|
||||
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
|
||||
|
||||
@@ -99,7 +109,7 @@ fn test_buy_and_refund_weight_in_native() {
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (native_location, fee + extra_amount).into();
|
||||
let payment: Asset = (native_location.clone(), fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -108,7 +118,7 @@ fn test_buy_and_refund_weight_in_native() {
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&native_location.into()).map_or(0, |a| *a);
|
||||
unused_asset.fungible.get(&native_location.clone().into()).map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(Balances::total_issuance(), total_issuance);
|
||||
|
||||
@@ -144,7 +154,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
||||
let staking_pot = CollatorSelection::account_id();
|
||||
let asset_1: u32 = 1;
|
||||
let native_location = TokenLocation::get();
|
||||
let native_location = TokenLocationV3::get();
|
||||
let asset_1_location =
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
|
||||
// bob's initial balance for native and `asset1` assets.
|
||||
@@ -180,6 +190,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
let asset_total_issuance = Assets::total_issuance(asset_1);
|
||||
let native_total_issuance = Balances::total_issuance();
|
||||
|
||||
let asset_1_location_latest: Location = asset_1_location.try_into().unwrap();
|
||||
|
||||
// prepare input to buy weight.
|
||||
let weight = Weight::from_parts(4_000_000_000, 0);
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
@@ -187,7 +199,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (asset_1_location, asset_fee + extra_amount).into();
|
||||
let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -195,8 +207,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&asset_1_location.into()).map_or(0, |a| *a);
|
||||
let unused_amount = unused_asset
|
||||
.fungible
|
||||
.get(&asset_1_location_latest.clone().into())
|
||||
.map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee);
|
||||
|
||||
@@ -210,7 +224,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
|
||||
// refund.
|
||||
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
||||
assert_eq!(actual_refund, (asset_1_location, asset_refund).into());
|
||||
assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into());
|
||||
|
||||
// assert.
|
||||
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
||||
@@ -239,9 +253,15 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
.execute_with(|| {
|
||||
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
||||
let staking_pot = CollatorSelection::account_id();
|
||||
let native_location = TokenLocation::get();
|
||||
let foreign_location =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) };
|
||||
let native_location = TokenLocationV3::get();
|
||||
let foreign_location = xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: (
|
||||
xcm::v3::Junction::Parachain(1234),
|
||||
xcm::v3::Junction::GeneralIndex(12345),
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
// bob's initial balance for native and `asset1` assets.
|
||||
let initial_balance = 200 * UNITS;
|
||||
// liquidity for both arms of (native, asset1) pool.
|
||||
@@ -280,6 +300,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
let asset_total_issuance = ForeignAssets::total_issuance(foreign_location);
|
||||
let native_total_issuance = Balances::total_issuance();
|
||||
|
||||
let foreign_location_latest: Location = foreign_location.try_into().unwrap();
|
||||
|
||||
// prepare input to buy weight.
|
||||
let weight = Weight::from_parts(4_000_000_000, 0);
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
@@ -287,7 +309,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (foreign_location, asset_fee + extra_amount).into();
|
||||
let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -295,8 +317,10 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&foreign_location.into()).map_or(0, |a| *a);
|
||||
let unused_amount = unused_asset
|
||||
.fungible
|
||||
.get(&foreign_location_latest.clone().into())
|
||||
.map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(
|
||||
ForeignAssets::total_issuance(foreign_location),
|
||||
@@ -313,7 +337,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
|
||||
// refund.
|
||||
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
||||
assert_eq!(actual_refund, (foreign_location, asset_refund).into());
|
||||
assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into());
|
||||
|
||||
// assert.
|
||||
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
||||
@@ -343,19 +367,21 @@ fn test_assets_balances_api_works() {
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let local_asset_id = 1;
|
||||
let foreign_asset_id_multilocation =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) };
|
||||
let foreign_asset_id_location = xcm::v3::Location::new(
|
||||
1,
|
||||
[xcm::v3::Junction::Parachain(1234), xcm::v3::Junction::GeneralIndex(12345)],
|
||||
);
|
||||
|
||||
// check before
|
||||
assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
||||
0
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_as::<MultiAssets>()
|
||||
.try_as::<XcmAssets>()
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
@@ -386,7 +412,7 @@ fn test_assets_balances_api_works() {
|
||||
let foreign_asset_minimum_asset_balance = 3333333_u128;
|
||||
assert_ok!(ForeignAssets::force_create(
|
||||
RuntimeHelper::root_origin(),
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
AccountId::from(SOME_ASSET_ADMIN).into(),
|
||||
false,
|
||||
foreign_asset_minimum_asset_balance
|
||||
@@ -395,7 +421,7 @@ fn test_assets_balances_api_works() {
|
||||
// We first mint enough asset for the account to exist for assets
|
||||
assert_ok!(ForeignAssets::mint(
|
||||
RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)),
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
AccountId::from(ALICE).into(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
));
|
||||
@@ -406,12 +432,12 @@ fn test_assets_balances_api_works() {
|
||||
minimum_asset_balance
|
||||
);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
||||
6 * minimum_asset_balance
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
let result: XcmAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
@@ -426,13 +452,13 @@ fn test_assets_balances_api_works() {
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(),
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
Identity::convert_back(&foreign_asset_id_multilocation).unwrap(),
|
||||
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
@@ -503,7 +529,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
XcmConfig,
|
||||
TrustBackedAssetsInstance,
|
||||
AssetIdForTrustBackedAssets,
|
||||
AssetIdForTrustBackedAssetsConvert,
|
||||
AssetIdForTrustBackedAssetsConvertLatest,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
12345,
|
||||
@@ -520,11 +546,14 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
JustTry,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) },
|
||||
xcm::v3::Location::new(
|
||||
1,
|
||||
[xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)]
|
||||
),
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
@@ -539,8 +568,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
|
||||
WeightToFee,
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
JustTry,
|
||||
xcm::v3::Location,
|
||||
V4V3LocationConverter,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
AssetDeposit::get(),
|
||||
@@ -637,12 +666,12 @@ mod asset_hub_rococo_tests {
|
||||
AccountId::from([73; 32]),
|
||||
AccountId::from(BLOCK_AUTHOR_ACCOUNT),
|
||||
// receiving WNDs
|
||||
(MultiLocation { parents: 2, interior: X1(GlobalConsensus(Westend)) }, 1000000000000, 1_000_000_000),
|
||||
(xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Westend)]), 1000000000000, 1_000_000_000),
|
||||
bridging_to_asset_hub_westend,
|
||||
(
|
||||
X1(PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX)),
|
||||
[PalletInstance(bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX)].into(),
|
||||
GlobalConsensus(Westend),
|
||||
X1(Parachain(1000))
|
||||
[Parachain(1000)].into()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -76,21 +76,25 @@ use sp_std::prelude::*;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_version::NativeVersion;
|
||||
use sp_version::RuntimeVersion;
|
||||
use xcm::opaque::v3::MultiLocation;
|
||||
use xcm_config::{
|
||||
ForeignAssetsConvertedConcreteId, PoolAssetsConvertedConcreteId,
|
||||
TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, WestendLocation,
|
||||
XcmOriginToTransactDispatchOrigin,
|
||||
TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocationV3, WestendLocation,
|
||||
WestendLocationV3, XcmOriginToTransactDispatchOrigin,
|
||||
};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
pub use sp_runtime::BuildStorage;
|
||||
|
||||
use assets_common::{
|
||||
foreign_creators::ForeignCreators, matching::FromSiblingParachain, MultiLocationForAssetId,
|
||||
};
|
||||
use assets_common::{foreign_creators::ForeignCreators, matching::FromSiblingParachain};
|
||||
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
|
||||
use xcm::latest::prelude::*;
|
||||
// We exclude `Assets` since it's the name of a pallet
|
||||
use xcm::latest::prelude::AssetId;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
use xcm::latest::prelude::{
|
||||
Asset, Fungible, Here, InteriorLocation, Junction, Junction::*, Location, NetworkId,
|
||||
NonFungible, Parent, ParentThen, Response, XCM_VERSION,
|
||||
};
|
||||
|
||||
use crate::xcm_config::ForeignCreatorsSovereignAccountOf;
|
||||
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
|
||||
@@ -300,10 +304,11 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
|
||||
Assets,
|
||||
ForeignAssets,
|
||||
LocalFromLeft<
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>,
|
||||
AssetIdForTrustBackedAssets,
|
||||
xcm::v3::Location,
|
||||
>,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
AccountId,
|
||||
>;
|
||||
|
||||
@@ -311,8 +316,8 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
|
||||
pub type NativeAndAssets = fungible::UnionOf<
|
||||
Balances,
|
||||
LocalAndForeignAssets,
|
||||
TargetFromLeft<WestendLocation>,
|
||||
MultiLocation,
|
||||
TargetFromLeft<WestendLocationV3, xcm::v3::Location>,
|
||||
xcm::v3::Location,
|
||||
AccountId,
|
||||
>;
|
||||
|
||||
@@ -320,15 +325,15 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Balance = Balance;
|
||||
type HigherPrecisionBalance = sp_core::U256;
|
||||
type AssetKind = MultiLocation;
|
||||
type AssetKind = xcm::v3::Location;
|
||||
type Assets = NativeAndAssets;
|
||||
type PoolId = (Self::AssetKind, Self::AssetKind);
|
||||
type PoolLocator =
|
||||
pallet_asset_conversion::WithFirstAsset<WestendLocation, AccountId, Self::AssetKind>;
|
||||
pallet_asset_conversion::WithFirstAsset<WestendLocationV3, AccountId, Self::AssetKind>;
|
||||
type PoolAssetId = u32;
|
||||
type PoolAssets = PoolAssets;
|
||||
type PoolSetupFee = ConstU128<0>; // Asset class deposit fees are sufficient to prevent spam
|
||||
type PoolSetupFeeAsset = WestendLocation;
|
||||
type PoolSetupFeeAsset = WestendLocationV3;
|
||||
type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
|
||||
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
|
||||
type LPFee = ConstU32<3>;
|
||||
@@ -338,9 +343,10 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_asset_conversion::WeightInfo<Runtime>;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = assets_common::benchmarks::AssetPairFactory<
|
||||
WestendLocation,
|
||||
WestendLocationV3,
|
||||
parachain_info::Pallet<Runtime>,
|
||||
xcm_config::AssetsPalletIndex,
|
||||
xcm_config::TrustBackedAssetsPalletIndex,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
}
|
||||
|
||||
@@ -362,13 +368,14 @@ 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 = ForeignCreators<
|
||||
(FromSiblingParachain<parachain_info::Pallet<Runtime>>,),
|
||||
FromSiblingParachain<parachain_info::Pallet<Runtime>, xcm::v3::Location>,
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
AccountId,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
type ForceOrigin = AssetsForceOrigin;
|
||||
type AssetDeposit = ForeignAssetsAssetDeposit;
|
||||
@@ -644,7 +651,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(xcm_config::WestendLocation::get());
|
||||
pub FeeAssetId: AssetId = AssetId(xcm_config::WestendLocation::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
|
||||
}
|
||||
@@ -728,7 +735,7 @@ impl pallet_asset_conversion_tx_payment::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Fungibles = LocalAndForeignAssets;
|
||||
type OnChargeAssetTransaction =
|
||||
AssetConversionAdapter<Balances, AssetConversion, WestendLocation>;
|
||||
AssetConversionAdapter<Balances, AssetConversion, WestendLocationV3>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
@@ -1229,18 +1236,18 @@ impl_runtime_apis! {
|
||||
impl pallet_asset_conversion::AssetConversionApi<
|
||||
Block,
|
||||
Balance,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
> for Runtime
|
||||
{
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: MultiLocation, asset2: MultiLocation, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
AssetConversion::quote_price_exact_tokens_for_tokens(asset1, asset2, amount, include_fee)
|
||||
}
|
||||
|
||||
fn quote_price_tokens_for_exact_tokens(asset1: MultiLocation, asset2: MultiLocation, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_tokens_for_exact_tokens(asset1: xcm::v3::Location, asset2: xcm::v3::Location, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
|
||||
}
|
||||
|
||||
fn get_reserves(asset1: MultiLocation, asset2: MultiLocation) -> Option<(Balance, Balance)> {
|
||||
fn get_reserves(asset1: xcm::v3::Location, asset2: xcm::v3::Location) -> Option<(Balance, Balance)> {
|
||||
AssetConversion::get_reserves(asset1, asset2).ok()
|
||||
}
|
||||
}
|
||||
@@ -1294,7 +1301,7 @@ impl_runtime_apis! {
|
||||
AccountId,
|
||||
> for Runtime
|
||||
{
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedAssets, assets_common::runtime_api::FungiblesAccessError> {
|
||||
use assets_common::fungible_conversion::{convert, convert_balance};
|
||||
Ok([
|
||||
// collect pallet_balance
|
||||
@@ -1413,45 +1420,45 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported between AH and Relay.
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// AH can reserve transfer native token to some random parachain.
|
||||
let random_para_id = 43211234;
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
random_para_id.into()
|
||||
);
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
ParentThen(Parachain(random_para_id).into()).into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
) -> Option<(xcm::v4::Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
// Transfer to Relay some local AH asset (local-reserve-transfer) while paying
|
||||
// fees using teleported native token.
|
||||
// (We don't care that Relay doesn't accept incoming unknown AH local asset)
|
||||
let dest = Parent.into();
|
||||
|
||||
let fee_amount = EXISTENTIAL_DEPOSIT;
|
||||
let fee_asset: MultiAsset = (MultiLocation::parent(), fee_amount).into();
|
||||
let fee_asset: Asset = (Location::parent(), fee_amount).into();
|
||||
|
||||
let who = frame_benchmarking::whitelisted_caller();
|
||||
// Give some multiple of the existential deposit
|
||||
@@ -1469,13 +1476,13 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
pallet_assets::Instance1
|
||||
>(true, initial_asset_amount);
|
||||
let asset_location = MultiLocation::new(
|
||||
let asset_location = Location::new(
|
||||
0,
|
||||
X2(PalletInstance(50), GeneralIndex(u32::from(asset_id).into()))
|
||||
[PalletInstance(50), GeneralIndex(u32::from(asset_id).into())]
|
||||
);
|
||||
let transfer_asset: MultiAsset = (asset_location, asset_amount).into();
|
||||
let transfer_asset: Asset = (asset_location, asset_amount).into();
|
||||
|
||||
let assets: MultiAssets = vec![fee_asset.clone(), transfer_asset].into();
|
||||
let assets: xcm::v4::Assets = vec![fee_asset.clone(), transfer_asset].into();
|
||||
let fee_index = if assets.get(0).unwrap().eq(&fee_asset) { 0 } else { 1 };
|
||||
|
||||
// verify transferred successfully
|
||||
@@ -1504,14 +1511,14 @@ impl_runtime_apis! {
|
||||
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
|
||||
);
|
||||
}
|
||||
fn ensure_bridged_target_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn ensure_bridged_target_destination() -> Result<Location, BenchmarkError> {
|
||||
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
|
||||
xcm_config::bridging::SiblingBridgeHubParaId::get().into()
|
||||
);
|
||||
let bridged_asset_hub = xcm_config::bridging::to_rococo::AssetHubRococo::get();
|
||||
let _ = PolkadotXcm::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(bridged_asset_hub),
|
||||
Box::new(bridged_asset_hub.clone()),
|
||||
XCM_VERSION,
|
||||
).map_err(|e| {
|
||||
log::error!(
|
||||
@@ -1527,12 +1534,11 @@ impl_runtime_apis! {
|
||||
}
|
||||
}
|
||||
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_config::{MaxAssetsIntoHolding, WestendLocation};
|
||||
use pallet_xcm_benchmarks::asset_instance_from;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
WestendLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
@@ -1543,33 +1549,33 @@ impl_runtime_apis! {
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositMultiAsset,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
Ok(WestendLocation::get())
|
||||
}
|
||||
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
|
||||
fn worst_case_holding(depositable_count: u32) -> xcm::v4::Assets {
|
||||
// A mix of fungible, non-fungible, and concrete assets.
|
||||
let holding_non_fungibles = MaxAssetsIntoHolding::get() / 2 - depositable_count;
|
||||
let holding_fungibles = holding_non_fungibles - 1;
|
||||
let fungibles_amount: u128 = 100;
|
||||
let mut assets = (0..holding_fungibles)
|
||||
.map(|i| {
|
||||
MultiAsset {
|
||||
id: Concrete(GeneralIndex(i as u128).into()),
|
||||
Asset {
|
||||
id: AssetId(GeneralIndex(i as u128).into()),
|
||||
fun: Fungible(fungibles_amount * i as u128),
|
||||
}
|
||||
})
|
||||
.chain(core::iter::once(MultiAsset { id: Concrete(Here.into()), fun: Fungible(u128::MAX) }))
|
||||
.chain((0..holding_non_fungibles).map(|i| MultiAsset {
|
||||
id: Concrete(GeneralIndex(i as u128).into()),
|
||||
.chain(core::iter::once(Asset { id: AssetId(Here.into()), fun: Fungible(u128::MAX) }))
|
||||
.chain((0..holding_non_fungibles).map(|i| Asset {
|
||||
id: AssetId(GeneralIndex(i as u128).into()),
|
||||
fun: NonFungible(asset_instance_from(i)),
|
||||
}))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assets.push(MultiAsset {
|
||||
id: Concrete(WestendLocation::get()),
|
||||
assets.push(Asset {
|
||||
id: AssetId(WestendLocation::get()),
|
||||
fun: Fungible(1_000_000 * UNITS),
|
||||
});
|
||||
assets.into()
|
||||
@@ -1577,16 +1583,16 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
|
||||
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
|
||||
WestendLocation::get(),
|
||||
MultiAsset { fun: Fungible(UNITS), id: Concrete(WestendLocation::get()) },
|
||||
Asset { fun: Fungible(UNITS), id: AssetId(WestendLocation::get()) },
|
||||
));
|
||||
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
|
||||
// AssetHubWestend trusts AssetHubRococo as reserve for ROCs
|
||||
pub TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some(
|
||||
pub TrustedReserve: Option<(Location, Asset)> = Some(
|
||||
(
|
||||
xcm_config::bridging::to_rococo::AssetHubRococo::get(),
|
||||
MultiAsset::from((xcm_config::bridging::to_rococo::RocLocation::get(), 1000000000000 as u128))
|
||||
Asset::from((xcm_config::bridging::to_rococo::RocLocation::get(), 1000000000000 as u128))
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1598,9 +1604,9 @@ impl_runtime_apis! {
|
||||
type TrustedTeleporter = TrustedTeleporter;
|
||||
type TrustedReserve = TrustedReserve;
|
||||
|
||||
fn get_multi_asset() -> MultiAsset {
|
||||
MultiAsset {
|
||||
id: Concrete(WestendLocation::get()),
|
||||
fn get_asset() -> Asset {
|
||||
Asset {
|
||||
id: AssetId(WestendLocation::get()),
|
||||
fun: Fungible(UNITS),
|
||||
}
|
||||
}
|
||||
@@ -1614,42 +1620,42 @@ impl_runtime_apis! {
|
||||
(0u64, Response::Version(Default::default()))
|
||||
}
|
||||
|
||||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
|
||||
fn worst_case_asset_exchange() -> Result<(xcm::v4::Assets, xcm::v4::Assets), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
|
||||
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
|
||||
match xcm_config::bridging::BridgingBenchmarksHelper::prepare_universal_alias() {
|
||||
Some(alias) => Ok(alias),
|
||||
None => Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
|
||||
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
|
||||
fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
|
||||
Ok((WestendLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
|
||||
}
|
||||
|
||||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn subscribe_origin() -> Result<Location, BenchmarkError> {
|
||||
Ok(WestendLocation::get())
|
||||
}
|
||||
|
||||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
|
||||
fn claimable_asset() -> Result<(Location, Location, xcm::v4::Assets), BenchmarkError> {
|
||||
let origin = WestendLocation::get();
|
||||
let assets: MultiAssets = (Concrete(WestendLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = MultiLocation { parents: 0, interior: Here };
|
||||
let assets: xcm::v4::Assets = (AssetId(WestendLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = Location { parents: 0, interior: Here };
|
||||
Ok((origin, ticket, assets))
|
||||
}
|
||||
|
||||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
|
||||
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn export_message_origin_and_destination(
|
||||
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
|
||||
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
|
||||
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
|
||||
use sp_std::prelude::*;
|
||||
use xcm::{latest::prelude::*, DoubleEncoded};
|
||||
|
||||
trait WeighMultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
|
||||
trait WeighAssets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight;
|
||||
}
|
||||
|
||||
const MAX_ASSETS: u64 = 100;
|
||||
|
||||
impl WeighMultiAssets for MultiAssetFilter {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for AssetFilter {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
match self {
|
||||
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
|
||||
Self::Wild(asset) => match asset {
|
||||
@@ -49,40 +49,36 @@ impl WeighMultiAssets for MultiAssetFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeighMultiAssets for MultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for Assets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
weight.saturating_mul(self.inner().iter().count() as u64)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AssetHubWestendXcmWeight<Call>(core::marker::PhantomData<Call>);
|
||||
impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn withdraw_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
fn withdraw_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
}
|
||||
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
fn reserve_asset_deposited(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
}
|
||||
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
fn receive_teleported_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
}
|
||||
fn query_response(
|
||||
_query_id: &u64,
|
||||
_response: &Response,
|
||||
_max_weight: &Weight,
|
||||
_querier: &Option<MultiLocation>,
|
||||
_querier: &Option<Location>,
|
||||
) -> Weight {
|
||||
XcmGeneric::<Runtime>::query_response()
|
||||
}
|
||||
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
}
|
||||
fn transfer_reserve_asset(
|
||||
assets: &MultiAssets,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
}
|
||||
fn transact(
|
||||
_origin_type: &OriginKind,
|
||||
@@ -110,44 +106,36 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn clear_origin() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_origin()
|
||||
}
|
||||
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
|
||||
fn descend_origin(_who: &InteriorLocation) -> Weight {
|
||||
XcmGeneric::<Runtime>::descend_origin()
|
||||
}
|
||||
fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_error()
|
||||
}
|
||||
|
||||
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
}
|
||||
fn deposit_reserve_asset(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
}
|
||||
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
|
||||
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn initiate_reserve_withdraw(
|
||||
assets: &MultiAssetFilter,
|
||||
_reserve: &MultiLocation,
|
||||
assets: &AssetFilter,
|
||||
_reserve: &Location,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
}
|
||||
fn initiate_teleport(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
}
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_holding()
|
||||
}
|
||||
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
|
||||
fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
|
||||
XcmGeneric::<Runtime>::buy_execution()
|
||||
}
|
||||
fn refund_surplus() -> Weight {
|
||||
@@ -162,7 +150,7 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn clear_error() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_error()
|
||||
}
|
||||
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
|
||||
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
|
||||
XcmGeneric::<Runtime>::claim_asset()
|
||||
}
|
||||
fn trap(_code: &u64) -> Weight {
|
||||
@@ -174,13 +162,13 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn unsubscribe_version() -> Weight {
|
||||
XcmGeneric::<Runtime>::unsubscribe_version()
|
||||
}
|
||||
fn burn_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
fn burn_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
}
|
||||
fn expect_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
fn expect_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
}
|
||||
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
|
||||
fn expect_origin(_origin: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::expect_origin()
|
||||
}
|
||||
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
|
||||
@@ -213,16 +201,16 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn export_message(_: &NetworkId, _: &Junctions, _: &Xcm<()>) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn lock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn unlock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn note_unlockable(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn request_unlock(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn set_fees_mode(_: &bool) -> Weight {
|
||||
@@ -234,11 +222,11 @@ impl<Call> XcmWeightInfo<Call> for AssetHubWestendXcmWeight<Call> {
|
||||
fn clear_topic() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_topic()
|
||||
}
|
||||
fn alias_origin(_: &MultiLocation) -> Weight {
|
||||
fn alias_origin(_: &Location) -> Weight {
|
||||
// XCM Executor does not currently support alias origin operations
|
||||
Weight::MAX
|
||||
}
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::unpaid_execution()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ use super::{
|
||||
ToRococoXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, WeightToFee, XcmpQueue,
|
||||
};
|
||||
use assets_common::{
|
||||
local_and_foreign_assets::MatchesLocalAndForeignAssetsMultiLocation,
|
||||
local_and_foreign_assets::MatchesLocalAndForeignAssetsLocation,
|
||||
matching::{FromSiblingParachain, IsForeignConcreteAsset},
|
||||
TrustBackedAssetsAsMultiLocation,
|
||||
TrustBackedAssetsAsLocation,
|
||||
};
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{
|
||||
tokens::imbalance::ResolveAssetTo, ConstU32, Contains, Equals, Everything, Nothing,
|
||||
PalletInfoAccess,
|
||||
@@ -61,25 +61,31 @@ use xcm_builder::{
|
||||
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const WestendLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const WestendLocation: Location = Location::parent();
|
||||
pub const WestendLocationV3: xcm::v3::Location = xcm::v3::Location::parent();
|
||||
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Westend);
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorMultiLocation =
|
||||
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
|
||||
pub UniversalLocation: InteriorLocation =
|
||||
[GlobalConsensus(RelayNetwork::get().unwrap()), 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 StakingPot: AccountId = CollatorSelection::account_id();
|
||||
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
|
||||
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_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 = (
|
||||
@@ -104,7 +110,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<WestendLocation>,
|
||||
// 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,
|
||||
@@ -122,7 +128,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,
|
||||
@@ -139,8 +145,8 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
|
||||
// Ignore `TrustBackedAssets` explicitly
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
// Ignore asset which starts 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)` wont
|
||||
// be accepted here
|
||||
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
|
||||
@@ -154,7 +160,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,
|
||||
@@ -174,7 +180,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,
|
||||
@@ -189,21 +195,33 @@ 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)
|
||||
}
|
||||
}
|
||||
@@ -238,23 +256,30 @@ 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 type FellowshipEntities: impl Contains<MultiLocation> = {
|
||||
// Fellowship Plurality
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) } |
|
||||
// Fellowship Salary Pallet
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(64)) } |
|
||||
// Fellowship Treasury Pallet
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(65)) }
|
||||
};
|
||||
pub type AmbassadorEntities: impl Contains<MultiLocation> = {
|
||||
// Ambassador Salary Pallet
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(74)) }
|
||||
};
|
||||
pub struct ParentOrParentsPlurality;
|
||||
impl Contains<Location> for ParentOrParentsPlurality {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, []) | (1, [Plurality { .. }]))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FellowshipEntities;
|
||||
impl Contains<Location> for FellowshipEntities {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(
|
||||
location.unpack(),
|
||||
(1, [Parachain(1001), Plurality { id: BodyId::Technical, .. }]) |
|
||||
(1, [Parachain(1001), PalletInstance(64)]) |
|
||||
(1, [Parachain(1001), PalletInstance(65)])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AmbassadorEntities;
|
||||
impl Contains<Location> for AmbassadorEntities {
|
||||
fn contains(location: &Location) -> bool {
|
||||
matches!(location.unpack(), (1, [Parachain(1001), PalletInstance(74)]))
|
||||
}
|
||||
}
|
||||
|
||||
/// A call filter for the XCM Transact instruction. This is a temporary measure until we properly
|
||||
@@ -573,12 +598,12 @@ impl xcm_executor::Config for XcmConfig {
|
||||
type Trader = (
|
||||
UsingComponents<WeightToFee, WestendLocation, AccountId, Balances, ToStakingPot<Runtime>>,
|
||||
cumulus_primitives_utility::SwapFirstAssetTrader<
|
||||
WestendLocation,
|
||||
WestendLocationV3,
|
||||
crate::AssetConversion,
|
||||
WeightToFee,
|
||||
crate::NativeAndAssets,
|
||||
(
|
||||
TrustBackedAssetsAsMultiLocation<TrustBackedAssetsPalletLocation, Balance>,
|
||||
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance>,
|
||||
ForeignAssetsConvertedConcreteId,
|
||||
),
|
||||
ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
|
||||
@@ -671,9 +696,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)])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,7 +729,7 @@ pub mod bridging {
|
||||
pub storage XcmBridgeHubRouterByteFee: Balance = TransactionByteFee::get();
|
||||
|
||||
pub SiblingBridgeHubParaId: u32 = bp_bridge_hub_westend::BRIDGE_HUB_WESTEND_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 = WestendLocation::get().into();
|
||||
@@ -721,25 +746,25 @@ pub mod bridging {
|
||||
use super::*;
|
||||
|
||||
parameter_types! {
|
||||
pub SiblingBridgeHubWithBridgeHubRococoInstance: MultiLocation = MultiLocation::new(
|
||||
pub SiblingBridgeHubWithBridgeHubRococoInstance: Location = Location::new(
|
||||
1,
|
||||
X2(
|
||||
[
|
||||
Parachain(SiblingBridgeHubParaId::get()),
|
||||
PalletInstance(bp_bridge_hub_westend::WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX)
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
pub const RococoNetwork: NetworkId = NetworkId::Rococo;
|
||||
pub AssetHubRococo: MultiLocation = MultiLocation::new(2, X2(GlobalConsensus(RococoNetwork::get()), Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)));
|
||||
pub RocLocation: MultiLocation = MultiLocation::new(2, X1(GlobalConsensus(RococoNetwork::get())));
|
||||
pub AssetHubRococo: Location = Location::new(2, [GlobalConsensus(RococoNetwork::get()), Parachain(bp_asset_hub_rococo::ASSET_HUB_ROCOCO_PARACHAIN_ID)]);
|
||||
pub RocLocation: Location = Location::new(2, [GlobalConsensus(RococoNetwork::get())]);
|
||||
|
||||
pub RocFromAssetHubRococo: (MultiAssetFilter, MultiLocation) = (
|
||||
Wild(AllOf { fun: WildFungible, id: Concrete(RocLocation::get()) }),
|
||||
pub RocFromAssetHubRococo: (AssetFilter, Location) = (
|
||||
Wild(AllOf { fun: WildFungible, id: AssetId(RocLocation::get()) }),
|
||||
AssetHubRococo::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(
|
||||
RococoNetwork::get(),
|
||||
@@ -756,15 +781,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![
|
||||
(SiblingBridgeHubWithBridgeHubRococoInstance::get(), GlobalConsensus(RococoNetwork::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)
|
||||
}
|
||||
}
|
||||
@@ -799,7 +824,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_rococo::UniversalAliases::get().into_iter().find_map(|(location, junction)| {
|
||||
match to_rococo::SiblingBridgeHubWithBridgeHubRococoInstance::get()
|
||||
|
||||
@@ -21,12 +21,16 @@ use asset_hub_westend_runtime::{
|
||||
xcm_config,
|
||||
xcm_config::{
|
||||
bridging, ForeignCreatorsSovereignAccountOf, LocationToAccountId, WestendLocation,
|
||||
WestendLocationV3,
|
||||
},
|
||||
AllPalletsWithoutSystem, MetadataDepositBase, MetadataDepositPerByte, PolkadotXcm, RuntimeCall,
|
||||
RuntimeEvent, RuntimeOrigin, ToRococoXcmRouterInstance, XcmpQueue,
|
||||
};
|
||||
pub use asset_hub_westend_runtime::{
|
||||
xcm_config::{CheckingAccount, TrustBackedAssetsPalletLocation, XcmConfig},
|
||||
xcm_config::{
|
||||
CheckingAccount, TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3,
|
||||
XcmConfig,
|
||||
},
|
||||
AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection, ExistentialDeposit,
|
||||
ForeignAssets, ForeignAssetsInstance, ParachainSystem, Runtime, SessionKeys, System,
|
||||
TrustBackedAssetsInstance,
|
||||
@@ -51,14 +55,18 @@ use parachains_common::{
|
||||
};
|
||||
use sp_runtime::traits::MaybeEquivalence;
|
||||
use std::convert::Into;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::traits::{Identity, JustTry, WeightTrader};
|
||||
use xcm::latest::prelude::{Assets as XcmAssets, *};
|
||||
use xcm_builder::V4V3LocationConverter;
|
||||
use xcm_executor::traits::{JustTry, WeightTrader};
|
||||
|
||||
const ALICE: [u8; 32] = [1u8; 32];
|
||||
const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32];
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvert =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>;
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvertLatest =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
|
||||
|
||||
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
|
||||
|
||||
@@ -101,7 +109,7 @@ fn test_buy_and_refund_weight_in_native() {
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (native_location, fee + extra_amount).into();
|
||||
let payment: Asset = (native_location.clone(), fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -110,7 +118,7 @@ fn test_buy_and_refund_weight_in_native() {
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&native_location.into()).map_or(0, |a| *a);
|
||||
unused_asset.fungible.get(&native_location.clone().into()).map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(Balances::total_issuance(), total_issuance);
|
||||
|
||||
@@ -146,7 +154,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
||||
let staking_pot = CollatorSelection::account_id();
|
||||
let asset_1: u32 = 1;
|
||||
let native_location = WestendLocation::get();
|
||||
let native_location = WestendLocationV3::get();
|
||||
let asset_1_location =
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
|
||||
// bob's initial balance for native and `asset1` assets.
|
||||
@@ -182,6 +190,8 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
let asset_total_issuance = Assets::total_issuance(asset_1);
|
||||
let native_total_issuance = Balances::total_issuance();
|
||||
|
||||
let asset_1_location_latest: Location = asset_1_location.try_into().unwrap();
|
||||
|
||||
// prepare input to buy weight.
|
||||
let weight = Weight::from_parts(4_000_000_000, 0);
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
@@ -189,7 +199,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (asset_1_location, asset_fee + extra_amount).into();
|
||||
let payment: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -197,8 +207,10 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&asset_1_location.into()).map_or(0, |a| *a);
|
||||
let unused_amount = unused_asset
|
||||
.fungible
|
||||
.get(&asset_1_location_latest.clone().into())
|
||||
.map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(Assets::total_issuance(asset_1), asset_total_issuance + asset_fee);
|
||||
|
||||
@@ -212,7 +224,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
|
||||
// refund.
|
||||
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
||||
assert_eq!(actual_refund, (asset_1_location, asset_refund).into());
|
||||
assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into());
|
||||
|
||||
// assert.
|
||||
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
||||
@@ -241,9 +253,15 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
.execute_with(|| {
|
||||
let bob: AccountId = SOME_ASSET_ADMIN.into();
|
||||
let staking_pot = CollatorSelection::account_id();
|
||||
let native_location = WestendLocation::get();
|
||||
let foreign_location =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) };
|
||||
let native_location = WestendLocationV3::get();
|
||||
let foreign_location = xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: (
|
||||
xcm::v3::Junction::Parachain(1234),
|
||||
xcm::v3::Junction::GeneralIndex(12345),
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
// bob's initial balance for native and `asset1` assets.
|
||||
let initial_balance = 200 * UNITS;
|
||||
// liquidity for both arms of (native, asset1) pool.
|
||||
@@ -282,6 +300,8 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
let asset_total_issuance = ForeignAssets::total_issuance(foreign_location);
|
||||
let native_total_issuance = Balances::total_issuance();
|
||||
|
||||
let foreign_location_latest: Location = foreign_location.try_into().unwrap();
|
||||
|
||||
// prepare input to buy weight.
|
||||
let weight = Weight::from_parts(4_000_000_000, 0);
|
||||
let fee = WeightToFee::weight_to_fee(&weight);
|
||||
@@ -289,7 +309,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
AssetConversion::get_amount_in(&fee, &pool_liquidity, &pool_liquidity).unwrap();
|
||||
let extra_amount = 100;
|
||||
let ctx = XcmContext { origin: None, message_id: XcmHash::default(), topic: None };
|
||||
let payment: MultiAsset = (foreign_location, asset_fee + extra_amount).into();
|
||||
let payment: Asset = (foreign_location_latest.clone(), asset_fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -297,8 +317,10 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
trader.buy_weight(weight, payment.into(), &ctx).expect("Expected Ok");
|
||||
|
||||
// assert.
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&foreign_location.into()).map_or(0, |a| *a);
|
||||
let unused_amount = unused_asset
|
||||
.fungible
|
||||
.get(&foreign_location_latest.clone().into())
|
||||
.map_or(0, |a| *a);
|
||||
assert_eq!(unused_amount, extra_amount);
|
||||
assert_eq!(
|
||||
ForeignAssets::total_issuance(foreign_location),
|
||||
@@ -315,7 +337,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
|
||||
|
||||
// refund.
|
||||
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
||||
assert_eq!(actual_refund, (foreign_location, asset_refund).into());
|
||||
assert_eq!(actual_refund, (foreign_location_latest, asset_refund).into());
|
||||
|
||||
// assert.
|
||||
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
||||
@@ -345,19 +367,25 @@ fn test_assets_balances_api_works() {
|
||||
.build()
|
||||
.execute_with(|| {
|
||||
let local_asset_id = 1;
|
||||
let foreign_asset_id_multilocation =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1234), GeneralIndex(12345)) };
|
||||
let foreign_asset_id_location = xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: [
|
||||
xcm::v3::Junction::Parachain(1234),
|
||||
xcm::v3::Junction::GeneralIndex(12345),
|
||||
]
|
||||
.into(),
|
||||
};
|
||||
|
||||
// check before
|
||||
assert_eq!(Assets::balance(local_asset_id, AccountId::from(ALICE)), 0);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
||||
0
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 0);
|
||||
assert!(Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_as::<MultiAssets>()
|
||||
.try_as::<XcmAssets>()
|
||||
.unwrap()
|
||||
.is_none());
|
||||
|
||||
@@ -388,7 +416,7 @@ fn test_assets_balances_api_works() {
|
||||
let foreign_asset_minimum_asset_balance = 3333333_u128;
|
||||
assert_ok!(ForeignAssets::force_create(
|
||||
RuntimeHelper::root_origin(),
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
AccountId::from(SOME_ASSET_ADMIN).into(),
|
||||
false,
|
||||
foreign_asset_minimum_asset_balance
|
||||
@@ -397,7 +425,7 @@ fn test_assets_balances_api_works() {
|
||||
// We first mint enough asset for the account to exist for assets
|
||||
assert_ok!(ForeignAssets::mint(
|
||||
RuntimeHelper::origin_of(AccountId::from(SOME_ASSET_ADMIN)),
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
AccountId::from(ALICE).into(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
));
|
||||
@@ -408,12 +436,12 @@ fn test_assets_balances_api_works() {
|
||||
minimum_asset_balance
|
||||
);
|
||||
assert_eq!(
|
||||
ForeignAssets::balance(foreign_asset_id_multilocation, AccountId::from(ALICE)),
|
||||
ForeignAssets::balance(foreign_asset_id_location, AccountId::from(ALICE)),
|
||||
6 * minimum_asset_balance
|
||||
);
|
||||
assert_eq!(Balances::free_balance(AccountId::from(ALICE)), some_currency);
|
||||
|
||||
let result: MultiAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
let result: XcmAssets = Runtime::query_account_balances(AccountId::from(ALICE))
|
||||
.unwrap()
|
||||
.try_into()
|
||||
.unwrap();
|
||||
@@ -428,13 +456,13 @@ fn test_assets_balances_api_works() {
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(),
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
Identity::convert_back(&foreign_asset_id_multilocation).unwrap(),
|
||||
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
@@ -505,7 +533,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
XcmConfig,
|
||||
TrustBackedAssetsInstance,
|
||||
AssetIdForTrustBackedAssets,
|
||||
AssetIdForTrustBackedAssetsConvert,
|
||||
AssetIdForTrustBackedAssetsConvertLatest,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
12345,
|
||||
@@ -522,11 +550,15 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
Runtime,
|
||||
XcmConfig,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
xcm::v3::Location,
|
||||
JustTry,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(1313), GeneralIndex(12345)) },
|
||||
xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: [xcm::v3::Junction::Parachain(1313), xcm::v3::Junction::GeneralIndex(12345)]
|
||||
.into()
|
||||
},
|
||||
Box::new(|| {
|
||||
assert!(Assets::asset_ids().collect::<Vec<_>>().is_empty());
|
||||
}),
|
||||
@@ -541,8 +573,8 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
|
||||
WeightToFee,
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
ForeignAssetsInstance,
|
||||
MultiLocation,
|
||||
JustTry,
|
||||
xcm::v3::Location,
|
||||
V4V3LocationConverter,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
AssetDeposit::get(),
|
||||
@@ -626,12 +658,12 @@ fn receive_reserve_asset_deposited_roc_from_asset_hub_rococo_works() {
|
||||
AccountId::from([73; 32]),
|
||||
AccountId::from(BLOCK_AUTHOR_ACCOUNT),
|
||||
// receiving ROCs
|
||||
(MultiLocation { parents: 2, interior: X1(GlobalConsensus(Rococo)) }, 1000000000000, 1_000_000_000),
|
||||
(xcm::v3::Location::new(2, [xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::Rococo)]), 1000000000000, 1_000_000_000),
|
||||
bridging_to_asset_hub_rococo,
|
||||
(
|
||||
X1(PalletInstance(bp_bridge_hub_westend::WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX)),
|
||||
[PalletInstance(bp_bridge_hub_westend::WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX)].into(),
|
||||
GlobalConsensus(Rococo),
|
||||
X1(Parachain(1000))
|
||||
[Parachain(1000)].into()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -19,26 +19,25 @@ use sp_std::marker::PhantomData;
|
||||
use xcm::latest::prelude::*;
|
||||
|
||||
/// Creates asset pairs for liquidity pools with `Target` always being the first asset.
|
||||
pub struct AssetPairFactory<Target, SelfParaId, PalletId>(
|
||||
PhantomData<(Target, SelfParaId, PalletId)>,
|
||||
pub struct AssetPairFactory<Target, SelfParaId, PalletId, L = Location>(
|
||||
PhantomData<(Target, SelfParaId, PalletId, L)>,
|
||||
);
|
||||
impl<Target: Get<MultiLocation>, SelfParaId: Get<ParaId>, PalletId: Get<u32>>
|
||||
pallet_asset_conversion::BenchmarkHelper<MultiLocation>
|
||||
for AssetPairFactory<Target, SelfParaId, PalletId>
|
||||
impl<Target: Get<L>, SelfParaId: Get<ParaId>, PalletId: Get<u32>, L: TryFrom<Location>>
|
||||
pallet_asset_conversion::BenchmarkHelper<L> for AssetPairFactory<Target, SelfParaId, PalletId, L>
|
||||
{
|
||||
fn create_pair(seed1: u32, seed2: u32) -> (MultiLocation, MultiLocation) {
|
||||
let with_id = MultiLocation::new(
|
||||
fn create_pair(seed1: u32, seed2: u32) -> (L, L) {
|
||||
let with_id = Location::new(
|
||||
1,
|
||||
X3(
|
||||
[
|
||||
Parachain(SelfParaId::get().into()),
|
||||
PalletInstance(PalletId::get() as u8),
|
||||
GeneralIndex(seed2.into()),
|
||||
),
|
||||
],
|
||||
);
|
||||
if seed1 % 2 == 0 {
|
||||
(with_id, Target::get())
|
||||
(with_id.try_into().map_err(|_| "Something went wrong").unwrap(), Target::get())
|
||||
} else {
|
||||
(Target::get(), with_id)
|
||||
(Target::get(), with_id.try_into().map_err(|_| "Something went wrong").unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,21 +17,21 @@ use frame_support::traits::{
|
||||
ContainsPair, EnsureOrigin, EnsureOriginWithArg, Everything, OriginTrait,
|
||||
};
|
||||
use pallet_xcm::{EnsureXcm, Origin as XcmOrigin};
|
||||
use xcm::latest::MultiLocation;
|
||||
use xcm::latest::Location;
|
||||
use xcm_executor::traits::ConvertLocation;
|
||||
|
||||
/// `EnsureOriginWithArg` impl for `CreateOrigin` that allows only XCM origins that are locations
|
||||
/// containing the class location.
|
||||
pub struct ForeignCreators<IsForeign, AccountOf, AccountId>(
|
||||
sp_std::marker::PhantomData<(IsForeign, AccountOf, AccountId)>,
|
||||
pub struct ForeignCreators<IsForeign, AccountOf, AccountId, L = Location>(
|
||||
sp_std::marker::PhantomData<(IsForeign, AccountOf, AccountId, L)>,
|
||||
);
|
||||
impl<
|
||||
IsForeign: ContainsPair<MultiLocation, MultiLocation>,
|
||||
IsForeign: ContainsPair<L, L>,
|
||||
AccountOf: ConvertLocation<AccountId>,
|
||||
AccountId: Clone,
|
||||
RuntimeOrigin: From<XcmOrigin> + OriginTrait + Clone,
|
||||
> EnsureOriginWithArg<RuntimeOrigin, MultiLocation>
|
||||
for ForeignCreators<IsForeign, AccountOf, AccountId>
|
||||
L: TryFrom<Location> + TryInto<Location> + Clone,
|
||||
> EnsureOriginWithArg<RuntimeOrigin, L> for ForeignCreators<IsForeign, AccountOf, AccountId, L>
|
||||
where
|
||||
RuntimeOrigin::PalletsOrigin:
|
||||
From<XcmOrigin> + TryInto<XcmOrigin, Error = RuntimeOrigin::PalletsOrigin>,
|
||||
@@ -40,17 +40,20 @@ where
|
||||
|
||||
fn try_origin(
|
||||
origin: RuntimeOrigin,
|
||||
asset_location: &MultiLocation,
|
||||
asset_location: &L,
|
||||
) -> sp_std::result::Result<Self::Success, RuntimeOrigin> {
|
||||
let origin_location = EnsureXcm::<Everything>::try_origin(origin.clone())?;
|
||||
let origin_location = EnsureXcm::<Everything, L>::try_origin(origin.clone())?;
|
||||
if !IsForeign::contains(asset_location, &origin_location) {
|
||||
return Err(origin)
|
||||
}
|
||||
AccountOf::convert_location(&origin_location).ok_or(origin)
|
||||
let latest_location: Location =
|
||||
origin_location.clone().try_into().map_err(|_| origin.clone())?;
|
||||
AccountOf::convert_location(&latest_location).ok_or(origin)
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn try_successful_origin(a: &MultiLocation) -> Result<RuntimeOrigin, ()> {
|
||||
Ok(pallet_xcm::Origin::Xcm(*a).into())
|
||||
fn try_successful_origin(a: &L) -> Result<RuntimeOrigin, ()> {
|
||||
let latest_location: Location = (*a).clone().try_into().map_err(|_| ())?;
|
||||
Ok(pallet_xcm::Origin::Xcm(latest_location).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,52 +19,48 @@ use crate::runtime_api::FungiblesAccessError;
|
||||
use frame_support::traits::Contains;
|
||||
use sp_runtime::traits::MaybeEquivalence;
|
||||
use sp_std::{borrow::Borrow, vec::Vec};
|
||||
use xcm::latest::{MultiAsset, MultiLocation};
|
||||
use xcm::latest::{Asset, Location};
|
||||
use xcm_builder::{ConvertedConcreteId, MatchedConvertedConcreteId};
|
||||
use xcm_executor::traits::MatchesFungibles;
|
||||
|
||||
/// Converting any [`(AssetId, Balance)`] to [`MultiAsset`]
|
||||
pub trait MultiAssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>:
|
||||
/// Converting any [`(AssetId, Balance)`] to [`Asset`]
|
||||
pub trait AssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>:
|
||||
MatchesFungibles<AssetId, Balance>
|
||||
where
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
{
|
||||
fn convert_ref(
|
||||
value: impl Borrow<(AssetId, Balance)>,
|
||||
) -> Result<MultiAsset, FungiblesAccessError>;
|
||||
fn convert_ref(value: impl Borrow<(AssetId, Balance)>) -> Result<Asset, FungiblesAccessError>;
|
||||
}
|
||||
|
||||
/// Checks for `MultiLocation`.
|
||||
pub trait MatchesMultiLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>:
|
||||
/// Checks for `Location`.
|
||||
pub trait MatchesLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>:
|
||||
MatchesFungibles<AssetId, Balance>
|
||||
where
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
MatchAssetId: Contains<MultiLocation>,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
MatchAssetId: Contains<Location>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
{
|
||||
fn contains(location: &MultiLocation) -> bool;
|
||||
fn contains(location: &Location) -> bool;
|
||||
}
|
||||
|
||||
impl<
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
> MultiAssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>
|
||||
> AssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>
|
||||
for ConvertedConcreteId<AssetId, Balance, ConvertAssetId, ConvertBalance>
|
||||
{
|
||||
fn convert_ref(
|
||||
value: impl Borrow<(AssetId, Balance)>,
|
||||
) -> Result<MultiAsset, FungiblesAccessError> {
|
||||
fn convert_ref(value: impl Borrow<(AssetId, Balance)>) -> Result<Asset, FungiblesAccessError> {
|
||||
let (asset_id, balance) = value.borrow();
|
||||
match ConvertAssetId::convert_back(asset_id) {
|
||||
Some(asset_id_as_multilocation) => match ConvertBalance::convert_back(balance) {
|
||||
Some(amount) => Ok((asset_id_as_multilocation, amount).into()),
|
||||
Some(asset_id_as_location) => match ConvertBalance::convert_back(balance) {
|
||||
Some(amount) => Ok((asset_id_as_location, amount).into()),
|
||||
None => Err(FungiblesAccessError::AmountToBalanceConversionFailed),
|
||||
},
|
||||
None => Err(FungiblesAccessError::AssetIdConversionFailed),
|
||||
@@ -75,19 +71,17 @@ impl<
|
||||
impl<
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
MatchAssetId: Contains<MultiLocation>,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
MatchAssetId: Contains<Location>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
> MultiAssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>
|
||||
> AssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>
|
||||
for MatchedConvertedConcreteId<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>
|
||||
{
|
||||
fn convert_ref(
|
||||
value: impl Borrow<(AssetId, Balance)>,
|
||||
) -> Result<MultiAsset, FungiblesAccessError> {
|
||||
fn convert_ref(value: impl Borrow<(AssetId, Balance)>) -> Result<Asset, FungiblesAccessError> {
|
||||
let (asset_id, balance) = value.borrow();
|
||||
match ConvertAssetId::convert_back(asset_id) {
|
||||
Some(asset_id_as_multilocation) => match ConvertBalance::convert_back(balance) {
|
||||
Some(amount) => Ok((asset_id_as_multilocation, amount).into()),
|
||||
Some(asset_id_as_location) => match ConvertBalance::convert_back(balance) {
|
||||
Some(amount) => Ok((asset_id_as_location, amount).into()),
|
||||
None => Err(FungiblesAccessError::AmountToBalanceConversionFailed),
|
||||
},
|
||||
None => Err(FungiblesAccessError::AssetIdConversionFailed),
|
||||
@@ -98,13 +92,13 @@ impl<
|
||||
impl<
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
MatchAssetId: Contains<MultiLocation>,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
MatchAssetId: Contains<Location>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
> MatchesMultiLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>
|
||||
> MatchesLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>
|
||||
for MatchedConvertedConcreteId<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance>
|
||||
{
|
||||
fn contains(location: &MultiLocation) -> bool {
|
||||
fn contains(location: &Location) -> bool {
|
||||
MatchAssetId::contains(location)
|
||||
}
|
||||
}
|
||||
@@ -113,12 +107,12 @@ impl<
|
||||
impl<
|
||||
AssetId: Clone,
|
||||
Balance: Clone,
|
||||
MatchAssetId: Contains<MultiLocation>,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
MatchAssetId: Contains<Location>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
> MatchesMultiLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance> for Tuple
|
||||
> MatchesLocation<AssetId, Balance, MatchAssetId, ConvertAssetId, ConvertBalance> for Tuple
|
||||
{
|
||||
fn contains(location: &MultiLocation) -> bool {
|
||||
fn contains(location: &Location) -> bool {
|
||||
for_tuples!( #(
|
||||
match Tuple::contains(location) { o @ true => return o, _ => () }
|
||||
)* );
|
||||
@@ -127,27 +121,24 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function to convert collections with [`(AssetId, Balance)`] to [`MultiAsset`]
|
||||
/// Helper function to convert collections with [`(AssetId, Balance)`] to [`Asset`]
|
||||
pub fn convert<'a, AssetId, Balance, ConvertAssetId, ConvertBalance, Converter>(
|
||||
items: impl Iterator<Item = &'a (AssetId, Balance)>,
|
||||
) -> Result<Vec<MultiAsset>, FungiblesAccessError>
|
||||
) -> Result<Vec<Asset>, FungiblesAccessError>
|
||||
where
|
||||
AssetId: Clone + 'a,
|
||||
Balance: Clone + 'a,
|
||||
ConvertAssetId: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
ConvertAssetId: MaybeEquivalence<Location, AssetId>,
|
||||
ConvertBalance: MaybeEquivalence<u128, Balance>,
|
||||
Converter: MultiAssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>,
|
||||
Converter: AssetConverter<AssetId, Balance, ConvertAssetId, ConvertBalance>,
|
||||
{
|
||||
items.map(Converter::convert_ref).collect()
|
||||
}
|
||||
|
||||
/// Helper function to convert `Balance` with MultiLocation` to `MultiAsset`
|
||||
pub fn convert_balance<
|
||||
T: frame_support::pallet_prelude::Get<MultiLocation>,
|
||||
Balance: TryInto<u128>,
|
||||
>(
|
||||
/// Helper function to convert `Balance` with Location` to `Asset`
|
||||
pub fn convert_balance<T: frame_support::pallet_prelude::Get<Location>, Balance: TryInto<u128>>(
|
||||
balance: Balance,
|
||||
) -> Result<MultiAsset, FungiblesAccessError> {
|
||||
) -> Result<Asset, FungiblesAccessError> {
|
||||
match balance.try_into() {
|
||||
Ok(balance) => Ok((T::get(), balance).into()),
|
||||
Err(_) => Err(FungiblesAccessError::AmountToBalanceConversionFailed),
|
||||
@@ -162,20 +153,20 @@ mod tests {
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm_executor::traits::{Identity, JustTry};
|
||||
|
||||
type Converter = MatchedConvertedConcreteId<MultiLocation, u64, Everything, Identity, JustTry>;
|
||||
type Converter = MatchedConvertedConcreteId<Location, u64, Everything, Identity, JustTry>;
|
||||
|
||||
#[test]
|
||||
fn converted_concrete_id_fungible_multi_asset_conversion_roundtrip_works() {
|
||||
let location = MultiLocation::new(0, X1(GlobalConsensus(ByGenesis([0; 32]))));
|
||||
let location = Location::new(0, [GlobalConsensus(ByGenesis([0; 32]))]);
|
||||
let amount = 123456_u64;
|
||||
let expected_multi_asset = MultiAsset {
|
||||
id: Concrete(MultiLocation::new(0, X1(GlobalConsensus(ByGenesis([0; 32]))))),
|
||||
let expected_multi_asset = Asset {
|
||||
id: AssetId(Location::new(0, [GlobalConsensus(ByGenesis([0; 32]))])),
|
||||
fun: Fungible(123456_u128),
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
Converter::matches_fungibles(&expected_multi_asset).map_err(|_| ()),
|
||||
Ok((location, amount))
|
||||
Ok((location.clone(), amount))
|
||||
);
|
||||
|
||||
assert_eq!(Converter::convert_ref((location, amount)), Ok(expected_multi_asset));
|
||||
@@ -184,17 +175,17 @@ mod tests {
|
||||
#[test]
|
||||
fn converted_concrete_id_fungible_multi_asset_conversion_collection_works() {
|
||||
let data = vec![
|
||||
(MultiLocation::new(0, X1(GlobalConsensus(ByGenesis([0; 32])))), 123456_u64),
|
||||
(MultiLocation::new(1, X1(GlobalConsensus(ByGenesis([1; 32])))), 654321_u64),
|
||||
(Location::new(0, [GlobalConsensus(ByGenesis([0; 32]))]), 123456_u64),
|
||||
(Location::new(1, [GlobalConsensus(ByGenesis([1; 32]))]), 654321_u64),
|
||||
];
|
||||
|
||||
let expected_data = vec![
|
||||
MultiAsset {
|
||||
id: Concrete(MultiLocation::new(0, X1(GlobalConsensus(ByGenesis([0; 32]))))),
|
||||
Asset {
|
||||
id: AssetId(Location::new(0, [GlobalConsensus(ByGenesis([0; 32]))])),
|
||||
fun: Fungible(123456_u128),
|
||||
},
|
||||
MultiAsset {
|
||||
id: Concrete(MultiLocation::new(1, X1(GlobalConsensus(ByGenesis([1; 32]))))),
|
||||
Asset {
|
||||
id: AssetId(Location::new(1, [GlobalConsensus(ByGenesis([1; 32]))])),
|
||||
fun: Fungible(654321_u128),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -23,15 +23,24 @@ pub mod local_and_foreign_assets;
|
||||
pub mod matching;
|
||||
pub mod runtime_api;
|
||||
|
||||
use crate::matching::{LocalMultiLocationPattern, ParentLocation};
|
||||
use crate::matching::{LocalLocationPattern, ParentLocation};
|
||||
use frame_support::traits::{Equals, EverythingBut};
|
||||
use parachains_common::AssetIdForTrustBackedAssets;
|
||||
use xcm::prelude::MultiLocation;
|
||||
use xcm_builder::{AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith};
|
||||
use xcm_executor::traits::{Identity, JustTry};
|
||||
use xcm_builder::{
|
||||
AsPrefixedGeneralIndex, MatchedConvertedConcreteId, StartsWith, V4V3LocationConverter,
|
||||
};
|
||||
use xcm_executor::traits::JustTry;
|
||||
|
||||
/// `MultiLocation` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets`
|
||||
/// `Location` vs `AssetIdForTrustBackedAssets` converter for `TrustBackedAssets`
|
||||
pub type AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation> =
|
||||
AsPrefixedGeneralIndex<
|
||||
TrustBackedAssetsPalletLocation,
|
||||
AssetIdForTrustBackedAssets,
|
||||
JustTry,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
|
||||
pub type AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation> =
|
||||
AsPrefixedGeneralIndex<TrustBackedAssetsPalletLocation, AssetIdForTrustBackedAssets, JustTry>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
|
||||
@@ -40,59 +49,55 @@ pub type TrustBackedAssetsConvertedConcreteId<TrustBackedAssetsPalletLocation, B
|
||||
AssetIdForTrustBackedAssets,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>,
|
||||
AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>,
|
||||
JustTry,
|
||||
>;
|
||||
|
||||
/// AssetId used for identifying assets by MultiLocation.
|
||||
pub type MultiLocationForAssetId = MultiLocation;
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `Location`.
|
||||
pub type LocationConvertedConcreteId<LocationFilter, Balance> = MatchedConvertedConcreteId<
|
||||
xcm::v3::Location,
|
||||
Balance,
|
||||
LocationFilter,
|
||||
V4V3LocationConverter,
|
||||
JustTry,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `TrustBackedAssets`
|
||||
pub type TrustBackedAssetsAsMultiLocation<TrustBackedAssetsPalletLocation, Balance> =
|
||||
pub type TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance> =
|
||||
MatchedConvertedConcreteId<
|
||||
MultiLocationForAssetId,
|
||||
xcm::v3::Location,
|
||||
Balance,
|
||||
StartsWith<TrustBackedAssetsPalletLocation>,
|
||||
Identity,
|
||||
JustTry,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `AssetId` as `MultiLocation`.
|
||||
pub type MultiLocationConvertedConcreteId<MultiLocationFilter, Balance> =
|
||||
MatchedConvertedConcreteId<
|
||||
MultiLocationForAssetId,
|
||||
Balance,
|
||||
MultiLocationFilter,
|
||||
Identity,
|
||||
V4V3LocationConverter,
|
||||
JustTry,
|
||||
>;
|
||||
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for storing `ForeignAssets` with `AssetId` as
|
||||
/// `MultiLocation`.
|
||||
/// `Location`.
|
||||
///
|
||||
/// Excludes by default:
|
||||
/// - parent as relay chain
|
||||
/// - all local MultiLocations
|
||||
/// - all local Locations
|
||||
///
|
||||
/// `AdditionalMultiLocationExclusionFilter` can customize additional excluded MultiLocations
|
||||
pub type ForeignAssetsConvertedConcreteId<AdditionalMultiLocationExclusionFilter, Balance> =
|
||||
MultiLocationConvertedConcreteId<
|
||||
/// `AdditionalLocationExclusionFilter` can customize additional excluded Locations
|
||||
pub type ForeignAssetsConvertedConcreteId<AdditionalLocationExclusionFilter, Balance> =
|
||||
LocationConvertedConcreteId<
|
||||
EverythingBut<(
|
||||
// Excludes relay/parent chain currency
|
||||
Equals<ParentLocation>,
|
||||
// Here we rely on fact that something like this works:
|
||||
// assert!(MultiLocation::new(1,
|
||||
// X1(Parachain(100))).starts_with(&MultiLocation::parent()));
|
||||
// assert!(X1(Parachain(100)).starts_with(&Here));
|
||||
StartsWith<LocalMultiLocationPattern>,
|
||||
// assert!(Location::new(1,
|
||||
// [Parachain(100)]).starts_with(&Location::parent()));
|
||||
// assert!([Parachain(100)].into().starts_with(&Here));
|
||||
StartsWith<LocalLocationPattern>,
|
||||
// Here we can exclude more stuff or leave it as `()`
|
||||
AdditionalMultiLocationExclusionFilter,
|
||||
AdditionalLocationExclusionFilter,
|
||||
)>,
|
||||
Balance,
|
||||
>;
|
||||
|
||||
type AssetIdForPoolAssets = u32;
|
||||
/// `MultiLocation` vs `AssetIdForPoolAssets` converter for `PoolAssets`.
|
||||
/// `Location` vs `AssetIdForPoolAssets` converter for `PoolAssets`.
|
||||
pub type AssetIdForPoolAssetsConvert<PoolAssetsPalletLocation> =
|
||||
AsPrefixedGeneralIndex<PoolAssetsPalletLocation, AssetIdForPoolAssets, JustTry>;
|
||||
/// [`MatchedConvertedConcreteId`] converter dedicated for `PoolAssets`
|
||||
@@ -109,28 +114,28 @@ pub type PoolAssetsConvertedConcreteId<PoolAssetsPalletLocation, Balance> =
|
||||
mod tests {
|
||||
use super::*;
|
||||
use sp_runtime::traits::MaybeEquivalence;
|
||||
use xcm::latest::prelude::*;
|
||||
use xcm::prelude::*;
|
||||
use xcm_builder::StartsWithExplicitGlobalConsensus;
|
||||
use xcm_executor::traits::{Error as MatchError, MatchesFungibles};
|
||||
|
||||
#[test]
|
||||
fn asset_id_for_trust_backed_assets_convert_works() {
|
||||
frame_support::parameter_types! {
|
||||
pub TrustBackedAssetsPalletLocation: MultiLocation = MultiLocation::new(5, X1(PalletInstance(13)));
|
||||
pub TrustBackedAssetsPalletLocation: Location = Location::new(5, [PalletInstance(13)]);
|
||||
}
|
||||
let local_asset_id = 123456789 as AssetIdForTrustBackedAssets;
|
||||
let expected_reverse_ref =
|
||||
MultiLocation::new(5, X2(PalletInstance(13), GeneralIndex(local_asset_id.into())));
|
||||
Location::new(5, [PalletInstance(13), GeneralIndex(local_asset_id.into())]);
|
||||
|
||||
assert_eq!(
|
||||
AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert_back(
|
||||
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert_back(
|
||||
&local_asset_id
|
||||
)
|
||||
.unwrap(),
|
||||
expected_reverse_ref
|
||||
);
|
||||
assert_eq!(
|
||||
AssetIdForTrustBackedAssetsConvert::<TrustBackedAssetsPalletLocation>::convert(
|
||||
AssetIdForTrustBackedAssetsConvertLatest::<TrustBackedAssetsPalletLocation>::convert(
|
||||
&expected_reverse_ref
|
||||
)
|
||||
.unwrap(),
|
||||
@@ -141,7 +146,7 @@ mod tests {
|
||||
#[test]
|
||||
fn trust_backed_assets_match_fungibles_works() {
|
||||
frame_support::parameter_types! {
|
||||
pub TrustBackedAssetsPalletLocation: MultiLocation = MultiLocation::new(0, X1(PalletInstance(13)));
|
||||
pub TrustBackedAssetsPalletLocation: Location = Location::new(0, [PalletInstance(13)]);
|
||||
}
|
||||
// setup convert
|
||||
type TrustBackedAssetsConvert =
|
||||
@@ -149,85 +154,86 @@ mod tests {
|
||||
|
||||
let test_data = vec![
|
||||
// missing GeneralIndex
|
||||
(ma_1000(0, X1(PalletInstance(13))), Err(MatchError::AssetIdConversionFailed)),
|
||||
(ma_1000(0, [PalletInstance(13)].into()), Err(MatchError::AssetIdConversionFailed)),
|
||||
(
|
||||
ma_1000(0, X2(PalletInstance(13), GeneralKey { data: [0; 32], length: 32 })),
|
||||
ma_1000(0, [PalletInstance(13), GeneralKey { data: [0; 32], length: 32 }].into()),
|
||||
Err(MatchError::AssetIdConversionFailed),
|
||||
),
|
||||
(
|
||||
ma_1000(0, X2(PalletInstance(13), Parachain(1000))),
|
||||
ma_1000(0, [PalletInstance(13), Parachain(1000)].into()),
|
||||
Err(MatchError::AssetIdConversionFailed),
|
||||
),
|
||||
// OK
|
||||
(ma_1000(0, X2(PalletInstance(13), GeneralIndex(1234))), Ok((1234, 1000))),
|
||||
(ma_1000(0, [PalletInstance(13), GeneralIndex(1234)].into()), Ok((1234, 1000))),
|
||||
(
|
||||
ma_1000(0, X3(PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222))),
|
||||
ma_1000(0, [PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222)].into()),
|
||||
Ok((1234, 1000)),
|
||||
),
|
||||
(
|
||||
ma_1000(
|
||||
0,
|
||||
X4(
|
||||
[
|
||||
PalletInstance(13),
|
||||
GeneralIndex(1234),
|
||||
GeneralIndex(2222),
|
||||
GeneralKey { data: [0; 32], length: 32 },
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
),
|
||||
Ok((1234, 1000)),
|
||||
),
|
||||
// wrong pallet instance
|
||||
(
|
||||
ma_1000(0, X2(PalletInstance(77), GeneralIndex(1234))),
|
||||
ma_1000(0, [PalletInstance(77), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(0, X3(PalletInstance(77), GeneralIndex(1234), GeneralIndex(2222))),
|
||||
ma_1000(0, [PalletInstance(77), GeneralIndex(1234), GeneralIndex(2222)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// wrong parent
|
||||
(
|
||||
ma_1000(1, X2(PalletInstance(13), GeneralIndex(1234))),
|
||||
ma_1000(1, [PalletInstance(13), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(1, X3(PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222))),
|
||||
ma_1000(1, [PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(1, X2(PalletInstance(77), GeneralIndex(1234))),
|
||||
ma_1000(1, [PalletInstance(77), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(1, X3(PalletInstance(77), GeneralIndex(1234), GeneralIndex(2222))),
|
||||
ma_1000(1, [PalletInstance(77), GeneralIndex(1234), GeneralIndex(2222)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// wrong parent
|
||||
(
|
||||
ma_1000(2, X2(PalletInstance(13), GeneralIndex(1234))),
|
||||
ma_1000(2, [PalletInstance(13), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(2, X3(PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222))),
|
||||
ma_1000(2, [PalletInstance(13), GeneralIndex(1234), GeneralIndex(2222)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// missing GeneralIndex
|
||||
(ma_1000(0, X1(PalletInstance(77))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(1, X1(PalletInstance(13))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(2, X1(PalletInstance(13))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(0, [PalletInstance(77)].into()), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(1, [PalletInstance(13)].into()), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(2, [PalletInstance(13)].into()), Err(MatchError::AssetNotHandled)),
|
||||
];
|
||||
|
||||
for (multi_asset, expected_result) in test_data {
|
||||
for (asset, expected_result) in test_data {
|
||||
assert_eq!(
|
||||
<TrustBackedAssetsConvert as MatchesFungibles<AssetIdForTrustBackedAssets, u128>>::matches_fungibles(&multi_asset),
|
||||
expected_result, "multi_asset: {:?}", multi_asset);
|
||||
<TrustBackedAssetsConvert as MatchesFungibles<AssetIdForTrustBackedAssets, u128>>::matches_fungibles(&asset.clone().try_into().unwrap()),
|
||||
expected_result, "asset: {:?}", asset);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_location_converted_concrete_id_converter_works() {
|
||||
fn location_converted_concrete_id_converter_works() {
|
||||
frame_support::parameter_types! {
|
||||
pub Parachain100Pattern: MultiLocation = MultiLocation::new(1, X1(Parachain(100)));
|
||||
pub Parachain100Pattern: Location = Location::new(1, [Parachain(100)]);
|
||||
pub UniversalLocationNetworkId: NetworkId = NetworkId::ByGenesis([9; 32]);
|
||||
}
|
||||
|
||||
@@ -243,95 +249,125 @@ mod tests {
|
||||
let test_data = vec![
|
||||
// excluded as local
|
||||
(ma_1000(0, Here), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(0, X1(Parachain(100))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(0, [Parachain(100)].into()), Err(MatchError::AssetNotHandled)),
|
||||
(
|
||||
ma_1000(0, X2(PalletInstance(13), GeneralIndex(1234))),
|
||||
ma_1000(0, [PalletInstance(13), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// excluded as parent
|
||||
(ma_1000(1, Here), Err(MatchError::AssetNotHandled)),
|
||||
// excluded as additional filter - Parachain100Pattern
|
||||
(ma_1000(1, X1(Parachain(100))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(1, X2(Parachain(100), GeneralIndex(1234))), Err(MatchError::AssetNotHandled)),
|
||||
(ma_1000(1, [Parachain(100)].into()), Err(MatchError::AssetNotHandled)),
|
||||
(
|
||||
ma_1000(1, X3(Parachain(100), PalletInstance(13), GeneralIndex(1234))),
|
||||
ma_1000(1, [Parachain(100), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(1, [Parachain(100), PalletInstance(13), GeneralIndex(1234)].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// excluded as additional filter - StartsWithExplicitGlobalConsensus
|
||||
(
|
||||
ma_1000(1, X1(GlobalConsensus(NetworkId::ByGenesis([9; 32])))),
|
||||
ma_1000(1, [GlobalConsensus(NetworkId::ByGenesis([9; 32]))].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(2, X1(GlobalConsensus(NetworkId::ByGenesis([9; 32])))),
|
||||
ma_1000(2, [GlobalConsensus(NetworkId::ByGenesis([9; 32]))].into()),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
(
|
||||
ma_1000(
|
||||
2,
|
||||
X3(
|
||||
[
|
||||
GlobalConsensus(NetworkId::ByGenesis([9; 32])),
|
||||
Parachain(200),
|
||||
GeneralIndex(1234),
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
),
|
||||
Err(MatchError::AssetNotHandled),
|
||||
),
|
||||
// ok
|
||||
(ma_1000(1, X1(Parachain(200))), Ok((MultiLocation::new(1, X1(Parachain(200))), 1000))),
|
||||
(ma_1000(2, X1(Parachain(200))), Ok((MultiLocation::new(2, X1(Parachain(200))), 1000))),
|
||||
(
|
||||
ma_1000(1, X2(Parachain(200), GeneralIndex(1234))),
|
||||
Ok((MultiLocation::new(1, X2(Parachain(200), GeneralIndex(1234))), 1000)),
|
||||
ma_1000(1, [Parachain(200)].into()),
|
||||
Ok((xcm::v3::Location::new(1, [xcm::v3::Junction::Parachain(200)]), 1000)),
|
||||
),
|
||||
(
|
||||
ma_1000(2, X2(Parachain(200), GeneralIndex(1234))),
|
||||
Ok((MultiLocation::new(2, X2(Parachain(200), GeneralIndex(1234))), 1000)),
|
||||
ma_1000(2, [Parachain(200)].into()),
|
||||
Ok((xcm::v3::Location::new(2, [xcm::v3::Junction::Parachain(200)]), 1000)),
|
||||
),
|
||||
(
|
||||
ma_1000(2, X1(GlobalConsensus(NetworkId::ByGenesis([7; 32])))),
|
||||
ma_1000(1, [Parachain(200), GeneralIndex(1234)].into()),
|
||||
Ok((
|
||||
MultiLocation::new(2, X1(GlobalConsensus(NetworkId::ByGenesis([7; 32])))),
|
||||
xcm::v3::Location::new(
|
||||
1,
|
||||
[xcm::v3::Junction::Parachain(200), xcm::v3::Junction::GeneralIndex(1234)],
|
||||
),
|
||||
1000,
|
||||
)),
|
||||
),
|
||||
(
|
||||
ma_1000(2, [Parachain(200), GeneralIndex(1234)].into()),
|
||||
Ok((
|
||||
xcm::v3::Location::new(
|
||||
2,
|
||||
[xcm::v3::Junction::Parachain(200), xcm::v3::Junction::GeneralIndex(1234)],
|
||||
),
|
||||
1000,
|
||||
)),
|
||||
),
|
||||
(
|
||||
ma_1000(2, [GlobalConsensus(NetworkId::ByGenesis([7; 32]))].into()),
|
||||
Ok((
|
||||
xcm::v3::Location::new(
|
||||
2,
|
||||
[xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::ByGenesis(
|
||||
[7; 32],
|
||||
))],
|
||||
),
|
||||
1000,
|
||||
)),
|
||||
),
|
||||
(
|
||||
ma_1000(
|
||||
2,
|
||||
X3(
|
||||
[
|
||||
GlobalConsensus(NetworkId::ByGenesis([7; 32])),
|
||||
Parachain(200),
|
||||
GeneralIndex(1234),
|
||||
),
|
||||
]
|
||||
.into(),
|
||||
),
|
||||
Ok((
|
||||
MultiLocation::new(
|
||||
xcm::v3::Location::new(
|
||||
2,
|
||||
X3(
|
||||
GlobalConsensus(NetworkId::ByGenesis([7; 32])),
|
||||
Parachain(200),
|
||||
GeneralIndex(1234),
|
||||
),
|
||||
[
|
||||
xcm::v3::Junction::GlobalConsensus(xcm::v3::NetworkId::ByGenesis(
|
||||
[7; 32],
|
||||
)),
|
||||
xcm::v3::Junction::Parachain(200),
|
||||
xcm::v3::Junction::GeneralIndex(1234),
|
||||
],
|
||||
),
|
||||
1000,
|
||||
)),
|
||||
),
|
||||
];
|
||||
|
||||
for (multi_asset, expected_result) in test_data {
|
||||
for (asset, expected_result) in test_data {
|
||||
assert_eq!(
|
||||
<Convert as MatchesFungibles<MultiLocationForAssetId, u128>>::matches_fungibles(
|
||||
&multi_asset
|
||||
<Convert as MatchesFungibles<xcm::v3::MultiLocation, u128>>::matches_fungibles(
|
||||
&asset.clone().try_into().unwrap()
|
||||
),
|
||||
expected_result,
|
||||
"multi_asset: {:?}",
|
||||
multi_asset
|
||||
"asset: {:?}",
|
||||
asset
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create MultiAsset
|
||||
fn ma_1000(parents: u8, interior: Junctions) -> MultiAsset {
|
||||
(MultiLocation::new(parents, interior), 1000).into()
|
||||
// Create Asset
|
||||
fn ma_1000(parents: u8, interior: Junctions) -> Asset {
|
||||
(Location::new(parents, interior), 1000).into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,32 +20,32 @@ use sp_runtime::{
|
||||
Either::{Left, Right},
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
use xcm::latest::MultiLocation;
|
||||
use xcm::latest::Location;
|
||||
|
||||
/// Converts a given [`MultiLocation`] to [`Either::Left`] when equal to `Target`, or
|
||||
/// Converts a given [`Location`] to [`Either::Left`] when equal to `Target`, or
|
||||
/// [`Either::Right`] otherwise.
|
||||
///
|
||||
/// Suitable for use as a `Criterion` with [`frame_support::traits::tokens::fungible::UnionOf`].
|
||||
pub struct TargetFromLeft<Target>(PhantomData<Target>);
|
||||
impl<Target: Get<MultiLocation>> Convert<MultiLocation, Either<(), MultiLocation>>
|
||||
for TargetFromLeft<Target>
|
||||
{
|
||||
fn convert(l: MultiLocation) -> Either<(), MultiLocation> {
|
||||
pub struct TargetFromLeft<Target, L = Location>(PhantomData<(Target, L)>);
|
||||
impl<Target: Get<L>, L: PartialEq + Eq> Convert<L, Either<(), L>> for TargetFromLeft<Target, L> {
|
||||
fn convert(l: L) -> Either<(), L> {
|
||||
Target::get().eq(&l).then(|| Left(())).map_or(Right(l), |n| n)
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a given [`MultiLocation`] to [`Either::Left`] based on the `Equivalence` criteria.
|
||||
/// Converts a given [`Location`] to [`Either::Left`] based on the `Equivalence` criteria.
|
||||
/// Returns [`Either::Right`] if not equivalent.
|
||||
///
|
||||
/// Suitable for use as a `Criterion` with [`frame_support::traits::tokens::fungibles::UnionOf`].
|
||||
pub struct LocalFromLeft<Equivalence, AssetId>(PhantomData<(Equivalence, AssetId)>);
|
||||
impl<Equivalence, AssetId> Convert<MultiLocation, Either<AssetId, MultiLocation>>
|
||||
for LocalFromLeft<Equivalence, AssetId>
|
||||
pub struct LocalFromLeft<Equivalence, AssetId, L = Location>(
|
||||
PhantomData<(Equivalence, AssetId, L)>,
|
||||
);
|
||||
impl<Equivalence, AssetId, L> Convert<L, Either<AssetId, L>>
|
||||
for LocalFromLeft<Equivalence, AssetId, L>
|
||||
where
|
||||
Equivalence: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
Equivalence: MaybeEquivalence<L, AssetId>,
|
||||
{
|
||||
fn convert(l: MultiLocation) -> Either<AssetId, MultiLocation> {
|
||||
fn convert(l: L) -> Either<AssetId, L> {
|
||||
match Equivalence::convert(&l) {
|
||||
Some(id) => Left(id),
|
||||
None => Right(l),
|
||||
@@ -53,7 +53,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MatchesLocalAndForeignAssetsMultiLocation {
|
||||
fn is_local(location: &MultiLocation) -> bool;
|
||||
fn is_foreign(location: &MultiLocation) -> bool;
|
||||
pub trait MatchesLocalAndForeignAssetsLocation<L = Location> {
|
||||
fn is_local(location: &L) -> bool;
|
||||
fn is_foreign(location: &L) -> bool;
|
||||
}
|
||||
|
||||
@@ -15,67 +15,72 @@
|
||||
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use frame_support::{pallet_prelude::Get, traits::ContainsPair};
|
||||
use xcm::{
|
||||
latest::prelude::{MultiAsset, MultiLocation},
|
||||
prelude::*,
|
||||
};
|
||||
use xcm::prelude::*;
|
||||
|
||||
use xcm_builder::ensure_is_remote;
|
||||
|
||||
frame_support::parameter_types! {
|
||||
pub LocalMultiLocationPattern: MultiLocation = MultiLocation::new(0, Here);
|
||||
pub ParentLocation: MultiLocation = MultiLocation::parent();
|
||||
pub LocalLocationPattern: Location = Location::new(0, Here);
|
||||
pub ParentLocation: Location = Location::parent();
|
||||
}
|
||||
|
||||
/// Accepts an asset if it is from the origin.
|
||||
pub struct IsForeignConcreteAsset<IsForeign>(sp_std::marker::PhantomData<IsForeign>);
|
||||
impl<IsForeign: ContainsPair<MultiLocation, MultiLocation>> ContainsPair<MultiAsset, MultiLocation>
|
||||
impl<IsForeign: ContainsPair<Location, Location>> ContainsPair<Asset, Location>
|
||||
for IsForeignConcreteAsset<IsForeign>
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
log::trace!(target: "xcm::contains", "IsForeignConcreteAsset asset: {:?}, origin: {:?}", asset, origin);
|
||||
matches!(asset.id, Concrete(ref id) if IsForeign::contains(id, origin))
|
||||
matches!(asset.id, AssetId(ref id) if IsForeign::contains(id, origin))
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `a` is from sibling location `b`. Checks that `MultiLocation-a` starts with
|
||||
/// `MultiLocation-b`, and that the `ParaId` of `b` is not equal to `a`.
|
||||
pub struct FromSiblingParachain<SelfParaId>(sp_std::marker::PhantomData<SelfParaId>);
|
||||
impl<SelfParaId: Get<ParaId>> ContainsPair<MultiLocation, MultiLocation>
|
||||
for FromSiblingParachain<SelfParaId>
|
||||
/// Checks if `a` is from sibling location `b`. Checks that `Location-a` starts with
|
||||
/// `Location-b`, and that the `ParaId` of `b` is not equal to `a`.
|
||||
pub struct FromSiblingParachain<SelfParaId, L = Location>(
|
||||
sp_std::marker::PhantomData<(SelfParaId, L)>,
|
||||
);
|
||||
impl<SelfParaId: Get<ParaId>, L: TryFrom<Location> + TryInto<Location> + Clone> ContainsPair<L, L>
|
||||
for FromSiblingParachain<SelfParaId, L>
|
||||
{
|
||||
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
|
||||
// `a` needs to be from `b` at least
|
||||
if !a.starts_with(b) {
|
||||
return false
|
||||
}
|
||||
fn contains(a: &L, b: &L) -> bool {
|
||||
// We convert locations to latest
|
||||
let a = match ((*a).clone().try_into(), (*b).clone().try_into()) {
|
||||
(Ok(a), Ok(b)) if a.starts_with(&b) => a, // `a` needs to be from `b` at least
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
// here we check if sibling
|
||||
match a {
|
||||
MultiLocation { parents: 1, interior } =>
|
||||
match a.unpack() {
|
||||
(1, interior) =>
|
||||
matches!(interior.first(), Some(Parachain(sibling_para_id)) if sibling_para_id.ne(&u32::from(SelfParaId::get()))),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `a` is from the expected global consensus network. Checks that `MultiLocation-a`
|
||||
/// starts with `MultiLocation-b`, and that network is a foreign consensus system.
|
||||
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId>(
|
||||
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId)>,
|
||||
/// Checks if `a` is from the expected global consensus network. Checks that `Location-a`
|
||||
/// starts with `Location-b`, and that network is a foreign consensus system.
|
||||
pub struct FromNetwork<UniversalLocation, ExpectedNetworkId, L = Location>(
|
||||
sp_std::marker::PhantomData<(UniversalLocation, ExpectedNetworkId, L)>,
|
||||
);
|
||||
impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<NetworkId>>
|
||||
ContainsPair<MultiLocation, MultiLocation> for FromNetwork<UniversalLocation, ExpectedNetworkId>
|
||||
impl<
|
||||
UniversalLocation: Get<InteriorLocation>,
|
||||
ExpectedNetworkId: Get<NetworkId>,
|
||||
L: TryFrom<Location> + TryInto<Location> + Clone,
|
||||
> ContainsPair<L, L> for FromNetwork<UniversalLocation, ExpectedNetworkId, L>
|
||||
{
|
||||
fn contains(&a: &MultiLocation, b: &MultiLocation) -> bool {
|
||||
// `a` needs to be from `b` at least
|
||||
if !a.starts_with(b) {
|
||||
return false
|
||||
}
|
||||
fn contains(a: &L, b: &L) -> bool {
|
||||
// We convert locations to latest
|
||||
let a = match ((*a).clone().try_into(), (*b).clone().try_into()) {
|
||||
(Ok(a), Ok(b)) if a.starts_with(&b) => a, // `a` needs to be from `b` at least
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
let universal_source = UniversalLocation::get();
|
||||
|
||||
// ensure that `a`` is remote and from the expected network
|
||||
match ensure_is_remote(universal_source, a) {
|
||||
// ensure that `a` is remote and from the expected network
|
||||
match ensure_is_remote(universal_source.clone(), a.clone()) {
|
||||
Ok((network_id, _)) => network_id == ExpectedNetworkId::get(),
|
||||
Err(e) => {
|
||||
log::trace!(
|
||||
@@ -89,19 +94,17 @@ impl<UniversalLocation: Get<InteriorMultiLocation>, ExpectedNetworkId: Get<Netwo
|
||||
}
|
||||
}
|
||||
|
||||
/// Adapter verifies if it is allowed to receive `MultiAsset` from `MultiLocation`.
|
||||
/// Adapter verifies if it is allowed to receive `Asset` from `Location`.
|
||||
///
|
||||
/// Note: `MultiLocation` has to be from a different global consensus.
|
||||
/// Note: `Location` has to be from a different global consensus.
|
||||
pub struct IsTrustedBridgedReserveLocationForConcreteAsset<UniversalLocation, Reserves>(
|
||||
sp_std::marker::PhantomData<(UniversalLocation, Reserves)>,
|
||||
);
|
||||
impl<
|
||||
UniversalLocation: Get<InteriorMultiLocation>,
|
||||
Reserves: ContainsPair<MultiAsset, MultiLocation>,
|
||||
> ContainsPair<MultiAsset, MultiLocation>
|
||||
impl<UniversalLocation: Get<InteriorLocation>, Reserves: ContainsPair<Asset, Location>>
|
||||
ContainsPair<Asset, Location>
|
||||
for IsTrustedBridgedReserveLocationForConcreteAsset<UniversalLocation, Reserves>
|
||||
{
|
||||
fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool {
|
||||
fn contains(asset: &Asset, origin: &Location) -> bool {
|
||||
let universal_source = UniversalLocation::get();
|
||||
log::trace!(
|
||||
target: "xcm::contains",
|
||||
@@ -110,7 +113,7 @@ impl<
|
||||
);
|
||||
|
||||
// check remote origin
|
||||
let _ = match ensure_is_remote(universal_source, *origin) {
|
||||
let _ = match ensure_is_remote(universal_source.clone(), origin.clone()) {
|
||||
Ok(devolved) => devolved,
|
||||
Err(_) => {
|
||||
log::trace!(
|
||||
@@ -133,14 +136,14 @@ mod tests {
|
||||
use frame_support::parameter_types;
|
||||
|
||||
parameter_types! {
|
||||
pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(Rococo), Parachain(1000));
|
||||
pub UniversalLocation: InteriorLocation = [GlobalConsensus(Rococo), Parachain(1000)].into();
|
||||
pub ExpectedNetworkId: NetworkId = Wococo;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_network_contains_works() {
|
||||
// asset and origin from foreign consensus works
|
||||
let asset: MultiLocation = (
|
||||
let asset: Location = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Wococo),
|
||||
@@ -149,12 +152,11 @@ mod tests {
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
let origin: Location = (Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
assert!(FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from local consensus fails
|
||||
let asset: MultiLocation = (
|
||||
let asset: Location = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Rococo),
|
||||
@@ -163,17 +165,16 @@ mod tests {
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into();
|
||||
let origin: Location = (Parent, Parent, GlobalConsensus(Rococo), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from here fails
|
||||
let asset: MultiLocation = (PalletInstance(1), GeneralIndex(1)).into();
|
||||
let origin: MultiLocation = Here.into();
|
||||
let asset: Location = (PalletInstance(1), GeneralIndex(1)).into();
|
||||
let origin: Location = Here.into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset from different consensus fails
|
||||
let asset: MultiLocation = (
|
||||
let asset: Location = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Polkadot),
|
||||
@@ -182,12 +183,11 @@ mod tests {
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
let origin: Location = (Parent, Parent, GlobalConsensus(Wococo), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// origin from different consensus fails
|
||||
let asset: MultiLocation = (
|
||||
let asset: Location = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Wococo),
|
||||
@@ -196,12 +196,11 @@ mod tests {
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
let origin: Location = (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
|
||||
// asset and origin from unexpected consensus fails
|
||||
let asset: MultiLocation = (
|
||||
let asset: Location = (
|
||||
Parent,
|
||||
Parent,
|
||||
GlobalConsensus(Polkadot),
|
||||
@@ -210,8 +209,7 @@ mod tests {
|
||||
GeneralIndex(1),
|
||||
)
|
||||
.into();
|
||||
let origin: MultiLocation =
|
||||
(Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
let origin: Location = (Parent, Parent, GlobalConsensus(Polkadot), Parachain(1000)).into();
|
||||
assert!(!FromNetwork::<UniversalLocation, ExpectedNetworkId>::contains(&asset, &origin));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
use codec::{Codec, Decode, Encode};
|
||||
use sp_runtime::RuntimeDebug;
|
||||
#[cfg(feature = "std")]
|
||||
use {sp_std::vec::Vec, xcm::latest::MultiAsset};
|
||||
use {sp_std::vec::Vec, xcm::latest::Asset};
|
||||
|
||||
/// The possible errors that can happen querying the storage of assets.
|
||||
#[derive(Eq, PartialEq, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)]
|
||||
pub enum FungiblesAccessError {
|
||||
/// `MultiLocation` to `AssetId`/`ClassId` conversion failed.
|
||||
/// `Location` to `AssetId`/`ClassId` conversion failed.
|
||||
AssetIdConversionFailed,
|
||||
/// `u128` amount to currency `Balance` conversion failed.
|
||||
AmountToBalanceConversionFailed,
|
||||
@@ -36,11 +36,11 @@ sp_api::decl_runtime_apis! {
|
||||
where
|
||||
AccountId: Codec,
|
||||
{
|
||||
/// Returns the list of all [`MultiAsset`] that an `AccountId` has.
|
||||
/// Returns the list of all [`Asset`] that an `AccountId` has.
|
||||
#[changed_in(2)]
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<MultiAsset>, FungiblesAccessError>;
|
||||
fn query_account_balances(account: AccountId) -> Result<Vec<Asset>, FungiblesAccessError>;
|
||||
|
||||
/// Returns the list of all [`MultiAsset`] that an `AccountId` has.
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedMultiAssets, FungiblesAccessError>;
|
||||
/// Returns the list of all [`Asset`] that an `AccountId` has.
|
||||
fn query_account_balances(account: AccountId) -> Result<xcm::VersionedAssets, FungiblesAccessError>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ use xcm::latest::prelude::*;
|
||||
use xcm_builder::{CreateMatcher, MatchXcm};
|
||||
|
||||
/// Given a message, a sender, and a destination, it returns the delivery fees
|
||||
fn get_fungible_delivery_fees<S: SendXcm>(destination: MultiLocation, message: Xcm<()>) -> u128 {
|
||||
fn get_fungible_delivery_fees<S: SendXcm>(destination: Location, message: Xcm<()>) -> u128 {
|
||||
let Ok((_, delivery_fees)) = validate_send::<S>(destination, message) else {
|
||||
unreachable!("message can be sent; qed")
|
||||
};
|
||||
@@ -46,8 +46,8 @@ fn get_fungible_delivery_fees<S: SendXcm>(destination: MultiLocation, message: X
|
||||
/// chain as part of a reserve-asset-transfer.
|
||||
pub(crate) fn assert_matches_reserve_asset_deposited_instructions<RuntimeCall: Debug>(
|
||||
xcm: &mut Xcm<RuntimeCall>,
|
||||
expected_reserve_assets_deposited: &MultiAssets,
|
||||
expected_beneficiary: &MultiLocation,
|
||||
expected_reserve_assets_deposited: &Assets,
|
||||
expected_beneficiary: &Location,
|
||||
) {
|
||||
let _ = xcm
|
||||
.0
|
||||
|
||||
@@ -37,7 +37,7 @@ use sp_runtime::{
|
||||
traits::{MaybeEquivalence, StaticLookup, Zero},
|
||||
DispatchError, Saturating,
|
||||
};
|
||||
use xcm::{latest::prelude::*, VersionedMultiAssets};
|
||||
use xcm::{latest::prelude::*, VersionedAssets};
|
||||
use xcm_executor::{traits::ConvertLocation, XcmExecutor};
|
||||
|
||||
type RuntimeHelper<Runtime, AllPalletsWithoutSystem = ()> =
|
||||
@@ -110,7 +110,7 @@ pub fn teleports_for_native_asset_works<
|
||||
0.into()
|
||||
);
|
||||
|
||||
let native_asset_id = MultiLocation::parent();
|
||||
let native_asset_id = Location::parent();
|
||||
let buy_execution_fee_amount_eta =
|
||||
WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 1024));
|
||||
let native_asset_amount_unit = existential_deposit;
|
||||
@@ -119,38 +119,40 @@ pub fn teleports_for_native_asset_works<
|
||||
|
||||
// 1. process received teleported assets from relaychain
|
||||
let xcm = Xcm(vec![
|
||||
ReceiveTeleportedAsset(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(native_asset_id),
|
||||
ReceiveTeleportedAsset(Assets::from(vec![Asset {
|
||||
id: AssetId(native_asset_id.clone()),
|
||||
fun: Fungible(native_asset_amount_received.into()),
|
||||
}])),
|
||||
ClearOrigin,
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(native_asset_id),
|
||||
fees: Asset {
|
||||
id: AssetId(native_asset_id.clone()),
|
||||
fun: Fungible(buy_execution_fee_amount_eta),
|
||||
},
|
||||
weight_limit: Limited(Weight::from_parts(3035310000, 65536)),
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: MultiLocation {
|
||||
beneficiary: Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
interior: [AccountId32 {
|
||||
network: None,
|
||||
id: target_account.clone().into(),
|
||||
}),
|
||||
}]
|
||||
.into(),
|
||||
},
|
||||
},
|
||||
ExpectTransactStatus(MaybeErrorCode::Success),
|
||||
]);
|
||||
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
Parent,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Parent),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
|
||||
@@ -163,14 +165,14 @@ pub fn teleports_for_native_asset_works<
|
||||
|
||||
// 2. try to teleport asset back to the relaychain
|
||||
{
|
||||
let dest = MultiLocation::parent();
|
||||
let mut dest_beneficiary = MultiLocation::parent()
|
||||
let dest = Location::parent();
|
||||
let mut dest_beneficiary = Location::parent()
|
||||
.appended_with(AccountId32 {
|
||||
network: None,
|
||||
id: sp_runtime::AccountId32::new([3; 32]).into(),
|
||||
})
|
||||
.unwrap();
|
||||
dest_beneficiary.reanchor(&dest, XcmConfig::UniversalLocation::get()).unwrap();
|
||||
dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap();
|
||||
|
||||
let target_account_balance_before_teleport =
|
||||
<pallet_balances::Pallet<Runtime>>::free_balance(&target_account);
|
||||
@@ -183,11 +185,11 @@ pub fn teleports_for_native_asset_works<
|
||||
// Mint funds into account to ensure it has enough balance to pay delivery fees
|
||||
let delivery_fees =
|
||||
xcm_helpers::transfer_assets_delivery_fees::<XcmConfig::XcmSender>(
|
||||
(native_asset_id, native_asset_to_teleport_away.into()).into(),
|
||||
(native_asset_id.clone(), native_asset_to_teleport_away.into()).into(),
|
||||
0,
|
||||
Unlimited,
|
||||
dest_beneficiary,
|
||||
dest,
|
||||
dest_beneficiary.clone(),
|
||||
dest.clone(),
|
||||
);
|
||||
<pallet_balances::Pallet<Runtime>>::mint_into(
|
||||
&target_account,
|
||||
@@ -199,7 +201,7 @@ pub fn teleports_for_native_asset_works<
|
||||
RuntimeHelper::<Runtime>::origin_of(target_account.clone()),
|
||||
dest,
|
||||
dest_beneficiary,
|
||||
(native_asset_id, native_asset_to_teleport_away.into()),
|
||||
(native_asset_id.clone(), native_asset_to_teleport_away.into()),
|
||||
None,
|
||||
included_head.clone(),
|
||||
&alice,
|
||||
@@ -228,14 +230,14 @@ pub fn teleports_for_native_asset_works<
|
||||
// trust `IsTeleporter` for `(relay-native-asset, para(2345))` pair
|
||||
{
|
||||
let other_para_id = 2345;
|
||||
let dest = MultiLocation::new(1, X1(Parachain(other_para_id)));
|
||||
let mut dest_beneficiary = MultiLocation::new(1, X1(Parachain(other_para_id)))
|
||||
let dest = Location::new(1, [Parachain(other_para_id)]);
|
||||
let mut dest_beneficiary = Location::new(1, [Parachain(other_para_id)])
|
||||
.appended_with(AccountId32 {
|
||||
network: None,
|
||||
id: sp_runtime::AccountId32::new([3; 32]).into(),
|
||||
})
|
||||
.unwrap();
|
||||
dest_beneficiary.reanchor(&dest, XcmConfig::UniversalLocation::get()).unwrap();
|
||||
dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap();
|
||||
|
||||
let target_account_balance_before_teleport =
|
||||
<pallet_balances::Pallet<Runtime>>::free_balance(&target_account);
|
||||
@@ -245,6 +247,7 @@ pub fn teleports_for_native_asset_works<
|
||||
native_asset_to_teleport_away <
|
||||
target_account_balance_before_teleport - existential_deposit
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
RuntimeHelper::<Runtime>::do_teleport_assets::<HrmpChannelOpener>(
|
||||
RuntimeHelper::<Runtime>::origin_of(target_account.clone()),
|
||||
@@ -356,9 +359,9 @@ pub fn teleports_for_foreign_assets_works<
|
||||
<WeightToFee as frame_support::weights::WeightToFee>::Balance: From<u128> + Into<u128>,
|
||||
SovereignAccountOf: ConvertLocation<AccountIdOf<Runtime>>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::AssetId:
|
||||
From<MultiLocation> + Into<MultiLocation>,
|
||||
From<xcm::v3::Location> + Into<xcm::v3::Location>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::AssetIdParameter:
|
||||
From<MultiLocation> + Into<MultiLocation>,
|
||||
From<xcm::v3::Location> + Into<xcm::v3::Location>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::Balance:
|
||||
From<Balance> + Into<u128>,
|
||||
<Runtime as frame_system::Config>::AccountId:
|
||||
@@ -370,23 +373,25 @@ pub fn teleports_for_foreign_assets_works<
|
||||
{
|
||||
// foreign parachain with the same consensus currency as asset
|
||||
let foreign_para_id = 2222;
|
||||
let foreign_asset_id_multilocation = MultiLocation {
|
||||
let foreign_asset_id_location = xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: X2(Parachain(foreign_para_id), GeneralIndex(1234567)),
|
||||
interior: [
|
||||
xcm::v3::Junction::Parachain(foreign_para_id),
|
||||
xcm::v3::Junction::GeneralIndex(1234567),
|
||||
]
|
||||
.into(),
|
||||
};
|
||||
|
||||
// foreign creator, which can be sibling parachain to match ForeignCreators
|
||||
let foreign_creator = MultiLocation { parents: 1, interior: X1(Parachain(foreign_para_id)) };
|
||||
let foreign_creator = Location { parents: 1, interior: [Parachain(foreign_para_id)].into() };
|
||||
let foreign_creator_as_account_id =
|
||||
SovereignAccountOf::convert_location(&foreign_creator).expect("");
|
||||
|
||||
// we want to buy execution with local relay chain currency
|
||||
let buy_execution_fee_amount =
|
||||
WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 0));
|
||||
let buy_execution_fee = MultiAsset {
|
||||
id: Concrete(MultiLocation::parent()),
|
||||
fun: Fungible(buy_execution_fee_amount),
|
||||
};
|
||||
let buy_execution_fee =
|
||||
Asset { id: AssetId(Location::parent()), fun: Fungible(buy_execution_fee_amount) };
|
||||
|
||||
let teleported_foreign_asset_amount = 10_000_000_000_000;
|
||||
let runtime_para_id = 1000;
|
||||
@@ -425,14 +430,14 @@ pub fn teleports_for_foreign_assets_works<
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&CheckingAccount::get()
|
||||
),
|
||||
0.into()
|
||||
@@ -441,14 +446,14 @@ pub fn teleports_for_foreign_assets_works<
|
||||
assert_total::<
|
||||
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
|
||||
AccountIdOf<Runtime>,
|
||||
>(foreign_asset_id_multilocation, 0, 0);
|
||||
>(foreign_asset_id_location, 0, 0);
|
||||
|
||||
// create foreign asset (0 total issuance)
|
||||
let asset_minimum_asset_balance = 3333333_u128;
|
||||
assert_ok!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::force_create(
|
||||
RuntimeHelper::<Runtime>::root_origin(),
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
asset_owner.into(),
|
||||
false,
|
||||
asset_minimum_asset_balance.into()
|
||||
@@ -457,47 +462,52 @@ pub fn teleports_for_foreign_assets_works<
|
||||
assert_total::<
|
||||
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
|
||||
AccountIdOf<Runtime>,
|
||||
>(foreign_asset_id_multilocation, 0, 0);
|
||||
>(foreign_asset_id_location, 0, 0);
|
||||
assert!(teleported_foreign_asset_amount > asset_minimum_asset_balance);
|
||||
|
||||
let foreign_asset_id_location_latest: Location =
|
||||
foreign_asset_id_location.try_into().unwrap();
|
||||
|
||||
// 1. process received teleported assets from sibling parachain (foreign_para_id)
|
||||
let xcm = Xcm(vec![
|
||||
// BuyExecution with relaychain native token
|
||||
WithdrawAsset(buy_execution_fee.clone().into()),
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation::parent()),
|
||||
fees: Asset {
|
||||
id: AssetId(Location::parent()),
|
||||
fun: Fungible(buy_execution_fee_amount),
|
||||
},
|
||||
weight_limit: Limited(Weight::from_parts(403531000, 65536)),
|
||||
},
|
||||
// Process teleported asset
|
||||
ReceiveTeleportedAsset(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(foreign_asset_id_multilocation),
|
||||
ReceiveTeleportedAsset(Assets::from(vec![Asset {
|
||||
id: AssetId(foreign_asset_id_location_latest.clone()),
|
||||
fun: Fungible(teleported_foreign_asset_amount),
|
||||
}])),
|
||||
DepositAsset {
|
||||
assets: Wild(AllOf {
|
||||
id: Concrete(foreign_asset_id_multilocation),
|
||||
id: AssetId(foreign_asset_id_location_latest.clone()),
|
||||
fun: WildFungibility::Fungible,
|
||||
}),
|
||||
beneficiary: MultiLocation {
|
||||
beneficiary: Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
interior: [AccountId32 {
|
||||
network: None,
|
||||
id: target_account.clone().into(),
|
||||
}),
|
||||
}]
|
||||
.into(),
|
||||
},
|
||||
},
|
||||
ExpectTransactStatus(MaybeErrorCode::Success),
|
||||
]);
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
foreign_creator,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
|
||||
@@ -508,7 +518,7 @@ pub fn teleports_for_foreign_assets_works<
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account
|
||||
),
|
||||
teleported_foreign_asset_amount.into()
|
||||
@@ -520,7 +530,7 @@ pub fn teleports_for_foreign_assets_works<
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&CheckingAccount::get()
|
||||
),
|
||||
0.into()
|
||||
@@ -530,25 +540,25 @@ pub fn teleports_for_foreign_assets_works<
|
||||
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
|
||||
AccountIdOf<Runtime>,
|
||||
>(
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
teleported_foreign_asset_amount,
|
||||
teleported_foreign_asset_amount,
|
||||
);
|
||||
|
||||
// 2. try to teleport asset back to source parachain (foreign_para_id)
|
||||
{
|
||||
let dest = MultiLocation::new(1, X1(Parachain(foreign_para_id)));
|
||||
let mut dest_beneficiary = MultiLocation::new(1, X1(Parachain(foreign_para_id)))
|
||||
let dest = Location::new(1, [Parachain(foreign_para_id)]);
|
||||
let mut dest_beneficiary = Location::new(1, [Parachain(foreign_para_id)])
|
||||
.appended_with(AccountId32 {
|
||||
network: None,
|
||||
id: sp_runtime::AccountId32::new([3; 32]).into(),
|
||||
})
|
||||
.unwrap();
|
||||
dest_beneficiary.reanchor(&dest, XcmConfig::UniversalLocation::get()).unwrap();
|
||||
dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap();
|
||||
|
||||
let target_account_balance_before_teleport =
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account,
|
||||
);
|
||||
let asset_to_teleport_away = asset_minimum_asset_balance * 3;
|
||||
@@ -562,11 +572,11 @@ pub fn teleports_for_foreign_assets_works<
|
||||
// Make sure the target account has enough native asset to pay for delivery fees
|
||||
let delivery_fees =
|
||||
xcm_helpers::transfer_assets_delivery_fees::<XcmConfig::XcmSender>(
|
||||
(foreign_asset_id_multilocation, asset_to_teleport_away).into(),
|
||||
(foreign_asset_id_location_latest.clone(), asset_to_teleport_away).into(),
|
||||
0,
|
||||
Unlimited,
|
||||
dest_beneficiary,
|
||||
dest,
|
||||
dest_beneficiary.clone(),
|
||||
dest.clone(),
|
||||
);
|
||||
<pallet_balances::Pallet<Runtime>>::mint_into(
|
||||
&target_account,
|
||||
@@ -578,7 +588,7 @@ pub fn teleports_for_foreign_assets_works<
|
||||
RuntimeHelper::<Runtime>::origin_of(target_account.clone()),
|
||||
dest,
|
||||
dest_beneficiary,
|
||||
(foreign_asset_id_multilocation, asset_to_teleport_away),
|
||||
(foreign_asset_id_location_latest.clone(), asset_to_teleport_away),
|
||||
Some((runtime_para_id, foreign_para_id)),
|
||||
included_head,
|
||||
&alice,
|
||||
@@ -587,14 +597,14 @@ pub fn teleports_for_foreign_assets_works<
|
||||
// check balances
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account
|
||||
),
|
||||
(target_account_balance_before_teleport - asset_to_teleport_away.into())
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&CheckingAccount::get()
|
||||
),
|
||||
0.into()
|
||||
@@ -604,7 +614,7 @@ pub fn teleports_for_foreign_assets_works<
|
||||
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
|
||||
AccountIdOf<Runtime>,
|
||||
>(
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
teleported_foreign_asset_amount - asset_to_teleport_away,
|
||||
teleported_foreign_asset_amount - asset_to_teleport_away,
|
||||
);
|
||||
@@ -717,17 +727,19 @@ pub fn asset_transactor_transfer_with_local_consensus_currency_works<Runtime, Xc
|
||||
|
||||
// transfer_asset (deposit/withdraw) ALICE -> BOB
|
||||
let _ = RuntimeHelper::<XcmConfig>::do_transfer(
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 { network: None, id: source_account.clone().into() }),
|
||||
interior: [AccountId32 { network: None, id: source_account.clone().into() }]
|
||||
.into(),
|
||||
},
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 { network: None, id: target_account.clone().into() }),
|
||||
interior: [AccountId32 { network: None, id: target_account.clone().into() }]
|
||||
.into(),
|
||||
},
|
||||
// local_consensus_currency_asset, e.g.: relaychain token (KSM, DOT, ...)
|
||||
(
|
||||
MultiLocation { parents: 1, interior: Here },
|
||||
Location { parents: 1, interior: Here },
|
||||
(BalanceOf::<Runtime>::from(1_u128) * unit).into(),
|
||||
),
|
||||
)
|
||||
@@ -820,8 +832,8 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
<<Runtime as frame_system::Config>::Lookup as StaticLookup>::Source:
|
||||
From<<Runtime as frame_system::Config>::AccountId>,
|
||||
AssetsPalletInstance: 'static,
|
||||
AssetId: Clone + Copy,
|
||||
AssetIdConverter: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
AssetId: Clone,
|
||||
AssetIdConverter: MaybeEquivalence<Location, AssetId>,
|
||||
{
|
||||
ExtBuilder::<Runtime>::default()
|
||||
.with_collators(collator_session_keys.collators())
|
||||
@@ -836,10 +848,10 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
.execute_with(|| {
|
||||
// create some asset class
|
||||
let asset_minimum_asset_balance = 3333333_u128;
|
||||
let asset_id_as_multilocation = AssetIdConverter::convert_back(&asset_id).unwrap();
|
||||
let asset_id_as_location = AssetIdConverter::convert_back(&asset_id).unwrap();
|
||||
assert_ok!(<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::force_create(
|
||||
RuntimeHelper::<Runtime>::root_origin(),
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
asset_owner.clone().into(),
|
||||
false,
|
||||
asset_minimum_asset_balance.into()
|
||||
@@ -848,7 +860,7 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
// We first mint enough asset for the account to exist for assets
|
||||
assert_ok!(<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::mint(
|
||||
RuntimeHelper::<Runtime>::origin_of(asset_owner.clone()),
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
alice_account.clone().into(),
|
||||
(6 * asset_minimum_asset_balance).into()
|
||||
));
|
||||
@@ -856,28 +868,28 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
// check Assets before
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&alice_account
|
||||
),
|
||||
(6 * asset_minimum_asset_balance).into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&bob_account
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&charlie_account
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&asset_owner
|
||||
),
|
||||
0.into()
|
||||
@@ -904,21 +916,20 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
// ExistentialDeposit)
|
||||
assert_noop!(
|
||||
RuntimeHelper::<XcmConfig>::do_transfer(
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
network: None,
|
||||
id: alice_account.clone().into()
|
||||
}),
|
||||
interior: [AccountId32 { network: None, id: alice_account.clone().into() }]
|
||||
.into(),
|
||||
},
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
interior: [AccountId32 {
|
||||
network: None,
|
||||
id: charlie_account.clone().into()
|
||||
}),
|
||||
}]
|
||||
.into(),
|
||||
},
|
||||
(asset_id_as_multilocation, asset_minimum_asset_balance),
|
||||
(asset_id_as_location.clone(), asset_minimum_asset_balance),
|
||||
),
|
||||
XcmError::FailedToTransactAsset(Into::<&str>::into(
|
||||
sp_runtime::TokenError::CannotCreate
|
||||
@@ -928,18 +939,17 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
// transfer_asset (deposit/withdraw) ALICE -> BOB (ok - has ExistentialDeposit)
|
||||
assert!(matches!(
|
||||
RuntimeHelper::<XcmConfig>::do_transfer(
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
network: None,
|
||||
id: alice_account.clone().into()
|
||||
}),
|
||||
interior: [AccountId32 { network: None, id: alice_account.clone().into() }]
|
||||
.into(),
|
||||
},
|
||||
MultiLocation {
|
||||
Location {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 { network: None, id: bob_account.clone().into() }),
|
||||
interior: [AccountId32 { network: None, id: bob_account.clone().into() }]
|
||||
.into(),
|
||||
},
|
||||
(asset_id_as_multilocation, asset_minimum_asset_balance),
|
||||
(asset_id_as_location, asset_minimum_asset_balance),
|
||||
),
|
||||
Ok(_)
|
||||
));
|
||||
@@ -947,21 +957,21 @@ pub fn asset_transactor_transfer_with_pallet_assets_instance_works<
|
||||
// check Assets after
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&alice_account
|
||||
),
|
||||
(5 * asset_minimum_asset_balance).into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&bob_account
|
||||
),
|
||||
asset_minimum_asset_balance.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, AssetsPalletInstance>>::balance(
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
&charlie_account
|
||||
),
|
||||
0.into()
|
||||
@@ -1093,26 +1103,23 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
<<Runtime as frame_system::Config>::Lookup as StaticLookup>::Source:
|
||||
From<<Runtime as frame_system::Config>::AccountId>,
|
||||
ForeignAssetsPalletInstance: 'static,
|
||||
AssetId: Clone + Copy,
|
||||
AssetIdConverter: MaybeEquivalence<MultiLocation, AssetId>,
|
||||
AssetId: Clone,
|
||||
AssetIdConverter: MaybeEquivalence<Location, AssetId>,
|
||||
{
|
||||
// foreign parachain with the same consensus currency as asset
|
||||
let foreign_asset_id_multilocation =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(2222), GeneralIndex(1234567)) };
|
||||
let asset_id = AssetIdConverter::convert(&foreign_asset_id_multilocation).unwrap();
|
||||
// foreign parachain with the same consenus currency as asset
|
||||
let foreign_asset_id_location = Location::new(1, [Parachain(2222), GeneralIndex(1234567)]);
|
||||
let asset_id = AssetIdConverter::convert(&foreign_asset_id_location).unwrap();
|
||||
|
||||
// foreign creator, which can be sibling parachain to match ForeignCreators
|
||||
let foreign_creator = MultiLocation { parents: 1, interior: X1(Parachain(2222)) };
|
||||
let foreign_creator = Location { parents: 1, interior: [Parachain(2222)].into() };
|
||||
let foreign_creator_as_account_id =
|
||||
SovereignAccountOf::convert_location(&foreign_creator).expect("");
|
||||
|
||||
// we want to buy execution with local relay chain currency
|
||||
let buy_execution_fee_amount =
|
||||
WeightToFee::weight_to_fee(&Weight::from_parts(90_000_000_000, 0));
|
||||
let buy_execution_fee = MultiAsset {
|
||||
id: Concrete(MultiLocation::parent()),
|
||||
fun: Fungible(buy_execution_fee_amount),
|
||||
};
|
||||
let buy_execution_fee =
|
||||
Asset { id: AssetId(Location::parent()), fun: Fungible(buy_execution_fee_amount) };
|
||||
|
||||
const ASSET_NAME: &str = "My super coin";
|
||||
const ASSET_SYMBOL: &str = "MY_S_COIN";
|
||||
@@ -1152,7 +1159,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
Runtime,
|
||||
ForeignAssetsPalletInstance,
|
||||
>::create {
|
||||
id: asset_id.into(),
|
||||
id: asset_id.clone().into(),
|
||||
// admin as sovereign_account
|
||||
admin: foreign_creator_as_account_id.clone().into(),
|
||||
min_balance: 1.into(),
|
||||
@@ -1162,7 +1169,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
Runtime,
|
||||
ForeignAssetsPalletInstance,
|
||||
>::set_metadata {
|
||||
id: asset_id.into(),
|
||||
id: asset_id.clone().into(),
|
||||
name: Vec::from(ASSET_NAME),
|
||||
symbol: Vec::from(ASSET_SYMBOL),
|
||||
decimals: 12,
|
||||
@@ -1172,7 +1179,7 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
Runtime,
|
||||
ForeignAssetsPalletInstance,
|
||||
>::set_team {
|
||||
id: asset_id.into(),
|
||||
id: asset_id.clone().into(),
|
||||
issuer: foreign_creator_as_account_id.clone().into(),
|
||||
admin: foreign_creator_as_account_id.clone().into(),
|
||||
freezer: bob_account.clone().into(),
|
||||
@@ -1202,14 +1209,15 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
]);
|
||||
|
||||
// messages with different consensus should go through the local bridge-hub
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
// execute xcm as XcmpQueue would do
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
foreign_creator,
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
foreign_creator.clone(),
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
|
||||
@@ -1230,25 +1238,25 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
use frame_support::traits::fungibles::roles::Inspect as InspectRoles;
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::owner(
|
||||
asset_id.into()
|
||||
asset_id.clone().into()
|
||||
),
|
||||
Some(foreign_creator_as_account_id.clone())
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::admin(
|
||||
asset_id.into()
|
||||
asset_id.clone().into()
|
||||
),
|
||||
Some(foreign_creator_as_account_id.clone())
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::issuer(
|
||||
asset_id.into()
|
||||
asset_id.clone().into()
|
||||
),
|
||||
Some(foreign_creator_as_account_id.clone())
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::freezer(
|
||||
asset_id.into()
|
||||
asset_id.clone().into()
|
||||
),
|
||||
Some(bob_account.clone())
|
||||
);
|
||||
@@ -1262,13 +1270,13 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
assert_metadata::<
|
||||
pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>,
|
||||
AccountIdOf<Runtime>,
|
||||
>(asset_id, ASSET_NAME, ASSET_SYMBOL, 12);
|
||||
>(asset_id.clone(), ASSET_NAME, ASSET_SYMBOL, 12);
|
||||
|
||||
// check if changed freezer, can freeze
|
||||
assert_noop!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::freeze(
|
||||
RuntimeHelper::<Runtime>::origin_of(bob_account),
|
||||
asset_id.into(),
|
||||
asset_id.clone().into(),
|
||||
alice_account.clone().into()
|
||||
),
|
||||
pallet_assets::Error::<Runtime, ForeignAssetsPalletInstance>::NoAccount
|
||||
@@ -1284,9 +1292,9 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
|
||||
// lets try create asset for different parachain(3333) (foreign_creator(2222) can create
|
||||
// just his assets)
|
||||
let foreign_asset_id_multilocation =
|
||||
MultiLocation { parents: 1, interior: X2(Parachain(3333), GeneralIndex(1234567)) };
|
||||
let asset_id = AssetIdConverter::convert(&foreign_asset_id_multilocation).unwrap();
|
||||
let foreign_asset_id_location =
|
||||
Location { parents: 1, interior: [Parachain(3333), GeneralIndex(1234567)].into() };
|
||||
let asset_id = AssetIdConverter::convert(&foreign_asset_id_location).unwrap();
|
||||
|
||||
// prepare data for xcm::Transact(create)
|
||||
let foreign_asset_create = runtime_call_encode(pallet_assets::Call::<
|
||||
@@ -1310,14 +1318,15 @@ pub fn create_and_manage_foreign_assets_for_local_consensus_parachain_assets_wor
|
||||
]);
|
||||
|
||||
// messages with different consensus should go through the local bridge-hub
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
// execute xcm as XcmpQueue would do
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
foreign_creator,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
|
||||
@@ -1441,15 +1450,15 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
|
||||
// reserve-transfer native asset with local reserve to remote parachain (2345)
|
||||
|
||||
let other_para_id = 2345;
|
||||
let native_asset = MultiLocation::parent();
|
||||
let dest = MultiLocation::new(1, X1(Parachain(other_para_id)));
|
||||
let mut dest_beneficiary = MultiLocation::new(1, X1(Parachain(other_para_id)))
|
||||
let native_asset = Location::parent();
|
||||
let dest = Location::new(1, [Parachain(other_para_id)]);
|
||||
let mut dest_beneficiary = Location::new(1, [Parachain(other_para_id)])
|
||||
.appended_with(AccountId32 {
|
||||
network: None,
|
||||
id: sp_runtime::AccountId32::new([3; 32]).into(),
|
||||
})
|
||||
.unwrap();
|
||||
dest_beneficiary.reanchor(&dest, XcmConfig::UniversalLocation::get()).unwrap();
|
||||
dest_beneficiary.reanchor(&dest, &XcmConfig::UniversalLocation::get()).unwrap();
|
||||
|
||||
let reserve_account = LocationToAccountId::convert_location(&dest)
|
||||
.expect("Sovereign account for reserves");
|
||||
@@ -1495,17 +1504,15 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
|
||||
);
|
||||
|
||||
// local native asset (pallet_balances)
|
||||
let asset_to_transfer = MultiAsset {
|
||||
fun: Fungible(balance_to_transfer.into()),
|
||||
id: Concrete(native_asset),
|
||||
};
|
||||
let asset_to_transfer =
|
||||
Asset { fun: Fungible(balance_to_transfer.into()), id: AssetId(native_asset) };
|
||||
|
||||
// pallet_xcm call reserve transfer
|
||||
assert_ok!(<pallet_xcm::Pallet<Runtime>>::limited_reserve_transfer_assets(
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::origin_of(alice_account.clone()),
|
||||
Box::new(dest.into_versioned()),
|
||||
Box::new(dest_beneficiary.into_versioned()),
|
||||
Box::new(VersionedMultiAssets::from(MultiAssets::from(asset_to_transfer))),
|
||||
Box::new(dest.clone().into_versioned()),
|
||||
Box::new(dest_beneficiary.clone().into_versioned()),
|
||||
Box::new(VersionedAssets::from(Assets::from(asset_to_transfer))),
|
||||
0,
|
||||
weight_limit,
|
||||
));
|
||||
@@ -1535,9 +1542,12 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let v4_xcm: Xcm<()> = xcm_sent.clone().try_into().unwrap();
|
||||
dbg!(&v4_xcm);
|
||||
|
||||
let delivery_fees = get_fungible_delivery_fees::<
|
||||
<XcmConfig as xcm_executor::Config>::XcmSender,
|
||||
>(dest, Xcm::try_from(xcm_sent.clone()).unwrap());
|
||||
>(dest.clone(), Xcm::try_from(xcm_sent.clone()).unwrap());
|
||||
|
||||
assert_eq!(
|
||||
xcm_sent_message_hash,
|
||||
@@ -1547,8 +1557,8 @@ pub fn reserve_transfer_native_asset_to_non_teleport_para_works<
|
||||
|
||||
// check sent XCM Program to other parachain
|
||||
println!("reserve_transfer_native_asset_works sent xcm: {:?}", xcm_sent);
|
||||
let reserve_assets_deposited = MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
let reserve_assets_deposited = Assets::from(vec![Asset {
|
||||
id: AssetId(Location { parents: 1, interior: Here }),
|
||||
fun: Fungible(1000000000000),
|
||||
}]);
|
||||
|
||||
|
||||
@@ -31,15 +31,15 @@ use parachains_runtimes_test_utils::{
|
||||
};
|
||||
use sp_runtime::{traits::StaticLookup, Saturating};
|
||||
use sp_std::ops::Mul;
|
||||
use xcm::{latest::prelude::*, VersionedMultiAssets};
|
||||
use xcm::{latest::prelude::*, VersionedAssets};
|
||||
use xcm_builder::{CreateMatcher, MatchXcm};
|
||||
use xcm_executor::{traits::ConvertLocation, XcmExecutor};
|
||||
|
||||
pub struct TestBridgingConfig {
|
||||
pub bridged_network: NetworkId,
|
||||
pub local_bridge_hub_para_id: u32,
|
||||
pub local_bridge_hub_location: MultiLocation,
|
||||
pub bridged_target_location: MultiLocation,
|
||||
pub local_bridge_hub_location: Location,
|
||||
pub bridged_target_location: Location,
|
||||
}
|
||||
|
||||
/// Test-case makes sure that `Runtime` can initiate **reserve transfer assets** over bridge.
|
||||
@@ -117,7 +117,7 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
|
||||
LocationToAccountId::convert_location(&target_location_from_different_consensus)
|
||||
.expect("Sovereign account for reserves");
|
||||
let balance_to_transfer = 1_000_000_000_000_u128;
|
||||
let native_asset = MultiLocation::parent();
|
||||
let native_asset = Location::parent();
|
||||
|
||||
// open HRMP to bridge hub
|
||||
mock_open_hrmp_channel::<Runtime, HrmpChannelOpener>(
|
||||
@@ -163,35 +163,33 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
|
||||
.unwrap_or(0.into());
|
||||
|
||||
// local native asset (pallet_balances)
|
||||
let asset_to_transfer = MultiAsset {
|
||||
fun: Fungible(balance_to_transfer.into()),
|
||||
id: Concrete(native_asset),
|
||||
};
|
||||
let asset_to_transfer =
|
||||
Asset { fun: Fungible(balance_to_transfer.into()), id: native_asset.into() };
|
||||
|
||||
// destination is (some) account relative to the destination different consensus
|
||||
let target_destination_account = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 {
|
||||
let target_destination_account = Location::new(
|
||||
0,
|
||||
[AccountId32 {
|
||||
network: Some(bridged_network),
|
||||
id: sp_runtime::AccountId32::new([3; 32]).into(),
|
||||
}),
|
||||
};
|
||||
}],
|
||||
);
|
||||
|
||||
let assets_to_transfer = MultiAssets::from(asset_to_transfer);
|
||||
let assets_to_transfer = Assets::from(asset_to_transfer);
|
||||
let mut expected_assets = assets_to_transfer.clone();
|
||||
let context = XcmConfig::UniversalLocation::get();
|
||||
expected_assets
|
||||
.reanchor(&target_location_from_different_consensus, context)
|
||||
.reanchor(&target_location_from_different_consensus, &context)
|
||||
.unwrap();
|
||||
|
||||
let expected_beneficiary = target_destination_account;
|
||||
let expected_beneficiary = target_destination_account.clone();
|
||||
|
||||
// do pallet_xcm call reserve transfer
|
||||
assert_ok!(<pallet_xcm::Pallet<Runtime>>::limited_reserve_transfer_assets(
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::origin_of(alice_account.clone()),
|
||||
Box::new(target_location_from_different_consensus.into_versioned()),
|
||||
Box::new(target_location_from_different_consensus.clone().into_versioned()),
|
||||
Box::new(target_destination_account.into_versioned()),
|
||||
Box::new(VersionedMultiAssets::from(assets_to_transfer)),
|
||||
Box::new(VersionedAssets::from(assets_to_transfer)),
|
||||
0,
|
||||
weight_limit,
|
||||
));
|
||||
@@ -266,13 +264,17 @@ pub fn limited_reserve_transfer_assets_for_native_asset_works<
|
||||
let (_, target_location_junctions_without_global_consensus) =
|
||||
target_location_from_different_consensus
|
||||
.interior
|
||||
.clone()
|
||||
.split_global()
|
||||
.expect("split works");
|
||||
assert_eq!(destination, &target_location_junctions_without_global_consensus);
|
||||
// Call `SendXcm::validate` to get delivery fees.
|
||||
delivery_fees = get_fungible_delivery_fees::<
|
||||
<XcmConfig as xcm_executor::Config>::XcmSender,
|
||||
>(target_location_from_different_consensus, inner_xcm.clone());
|
||||
>(
|
||||
target_location_from_different_consensus.clone(),
|
||||
inner_xcm.clone(),
|
||||
);
|
||||
assert_matches_reserve_asset_deposited_instructions(
|
||||
inner_xcm,
|
||||
&expected_assets,
|
||||
@@ -322,10 +324,10 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
target_account: AccountIdOf<Runtime>,
|
||||
block_author_account: AccountIdOf<Runtime>,
|
||||
(
|
||||
foreign_asset_id_multilocation,
|
||||
foreign_asset_id_location,
|
||||
transfered_foreign_asset_id_amount,
|
||||
foreign_asset_id_minimum_balance,
|
||||
): (MultiLocation, u128, u128),
|
||||
): (xcm::v3::Location, u128, u128),
|
||||
prepare_configuration: fn() -> TestBridgingConfig,
|
||||
(bridge_instance, universal_origin, descend_origin): (Junctions, Junction, Junctions), /* bridge adds origin manipulation on the way */
|
||||
) where
|
||||
@@ -347,9 +349,9 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
XcmConfig: xcm_executor::Config,
|
||||
LocationToAccountId: ConvertLocation<AccountIdOf<Runtime>>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::AssetId:
|
||||
From<MultiLocation> + Into<MultiLocation>,
|
||||
From<xcm::v3::Location> + Into<xcm::v3::Location>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::AssetIdParameter:
|
||||
From<MultiLocation> + Into<MultiLocation>,
|
||||
From<xcm::v3::Location> + Into<xcm::v3::Location>,
|
||||
<Runtime as pallet_assets::Config<ForeignAssetsPalletInstance>>::Balance:
|
||||
From<Balance> + Into<u128> + From<u128>,
|
||||
<Runtime as frame_system::Config>::AccountId: Into<<<Runtime as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId>
|
||||
@@ -357,7 +359,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
<<Runtime as frame_system::Config>::Lookup as StaticLookup>::Source:
|
||||
From<<Runtime as frame_system::Config>::AccountId>,
|
||||
<Runtime as pallet_asset_conversion::Config>::AssetKind:
|
||||
From<MultiLocation> + Into<MultiLocation>,
|
||||
From<xcm::v3::Location> + Into<xcm::v3::Location>,
|
||||
<Runtime as pallet_asset_conversion::Config>::Balance: From<Balance>,
|
||||
ForeignAssetsPalletInstance: 'static,
|
||||
{
|
||||
@@ -385,7 +387,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
// sovereign account as foreign asset owner (can be whoever for this scenario, doesnt
|
||||
// matter)
|
||||
let sovereign_account_as_owner_of_foreign_asset =
|
||||
LocationToAccountId::convert_location(&MultiLocation::parent()).unwrap();
|
||||
LocationToAccountId::convert_location(&Location::parent()).unwrap();
|
||||
|
||||
// staking pot account for collecting local native fees from `BuyExecution`
|
||||
let staking_pot = <pallet_collator_selection::Pallet<Runtime>>::account_id();
|
||||
@@ -398,16 +400,16 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
assert_ok!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::force_create(
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::root_origin(),
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
sovereign_account_as_owner_of_foreign_asset.clone().into(),
|
||||
true, // is_sufficient=true
|
||||
foreign_asset_id_minimum_balance.into()
|
||||
)
|
||||
);
|
||||
|
||||
// setup a pool to pay fees with `foreign_asset_id_multilocation` tokens
|
||||
// setup a pool to pay fees with `foreign_asset_id_location` tokens
|
||||
let pool_owner: AccountIdOf<Runtime> = [1u8; 32].into();
|
||||
let native_asset = MultiLocation::parent();
|
||||
let native_asset = xcm::v3::Location::parent();
|
||||
let pool_liquidity: u128 =
|
||||
existential_deposit.into().max(foreign_asset_id_minimum_balance).mul(100_000);
|
||||
|
||||
@@ -420,7 +422,7 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::origin_of(
|
||||
sovereign_account_as_owner_of_foreign_asset
|
||||
),
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
pool_owner.clone().into(),
|
||||
(foreign_asset_id_minimum_balance + pool_liquidity).mul(2).into(),
|
||||
));
|
||||
@@ -428,13 +430,13 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
assert_ok!(<pallet_asset_conversion::Pallet<Runtime>>::create_pool(
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::origin_of(pool_owner.clone()),
|
||||
Box::new(native_asset.into()),
|
||||
Box::new(foreign_asset_id_multilocation.into())
|
||||
Box::new(foreign_asset_id_location.into())
|
||||
));
|
||||
|
||||
assert_ok!(<pallet_asset_conversion::Pallet<Runtime>>::add_liquidity(
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::origin_of(pool_owner.clone()),
|
||||
Box::new(native_asset.into()),
|
||||
Box::new(foreign_asset_id_multilocation.into()),
|
||||
Box::new(foreign_asset_id_location.into()),
|
||||
pool_liquidity.into(),
|
||||
pool_liquidity.into(),
|
||||
1.into(),
|
||||
@@ -459,34 +461,37 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
// ForeignAssets balances before
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&block_author_account
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&staking_pot
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
|
||||
let expected_assets = MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(foreign_asset_id_multilocation),
|
||||
let foreign_asset_id_location_latest: Location =
|
||||
foreign_asset_id_location.try_into().unwrap();
|
||||
|
||||
let expected_assets = Assets::from(vec![Asset {
|
||||
id: AssetId(foreign_asset_id_location_latest.clone()),
|
||||
fun: Fungible(transfered_foreign_asset_id_amount),
|
||||
}]);
|
||||
let expected_beneficiary = MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(AccountId32 { network: None, id: target_account.clone().into() }),
|
||||
};
|
||||
let expected_beneficiary = Location::new(
|
||||
0,
|
||||
[AccountId32 { network: None, id: target_account.clone().into() }],
|
||||
);
|
||||
|
||||
// Call received XCM execution
|
||||
let xcm = Xcm(vec![
|
||||
@@ -496,13 +501,16 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
ReserveAssetDeposited(expected_assets.clone()),
|
||||
ClearOrigin,
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(foreign_asset_id_multilocation),
|
||||
fees: Asset {
|
||||
id: AssetId(foreign_asset_id_location_latest.clone()),
|
||||
fun: Fungible(transfered_foreign_asset_id_amount),
|
||||
},
|
||||
weight_limit: Unlimited,
|
||||
},
|
||||
DepositAsset { assets: Wild(AllCounted(1)), beneficiary: expected_beneficiary },
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: expected_beneficiary.clone(),
|
||||
},
|
||||
SetTopic([
|
||||
220, 188, 144, 32, 213, 83, 111, 175, 44, 210, 111, 19, 90, 165, 191, 112, 140,
|
||||
247, 192, 124, 42, 17, 153, 141, 114, 34, 189, 20, 83, 69, 237, 173,
|
||||
@@ -514,16 +522,17 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
&expected_beneficiary,
|
||||
);
|
||||
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
// execute xcm as XcmpQueue would do
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
local_bridge_hub_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::xcm_max_weight(
|
||||
XcmReceivedFrom::Sibling,
|
||||
),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
|
||||
@@ -545,20 +554,20 @@ pub fn receive_reserve_asset_deposited_from_different_consensus_works<
|
||||
// ForeignAssets balances after
|
||||
assert!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&target_account
|
||||
) > 0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&staking_pot
|
||||
),
|
||||
0.into()
|
||||
);
|
||||
assert_eq!(
|
||||
<pallet_assets::Pallet<Runtime, ForeignAssetsPalletInstance>>::balance(
|
||||
foreign_asset_id_multilocation.into(),
|
||||
foreign_asset_id_location.into(),
|
||||
&block_author_account
|
||||
),
|
||||
0.into()
|
||||
@@ -614,14 +623,15 @@ pub fn report_bridge_status_from_xcm_bridge_router_works<
|
||||
|
||||
// Call received XCM execution
|
||||
let xcm = if is_congested { congested_message() } else { uncongested_message() };
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
|
||||
// execute xcm as XcmpQueue would do
|
||||
let outcome = XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let outcome = XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
local_bridge_hub_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime, AllPalletsWithoutSystem>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
);
|
||||
assert_ok!(outcome.ensure_complete());
|
||||
assert_eq!(is_congested, pallet_xcm_bridge_hub_router::Pallet::<Runtime, XcmBridgeHubRouterInstance>::bridge().is_congested);
|
||||
|
||||
@@ -23,11 +23,11 @@ use xcm::latest::prelude::*;
|
||||
/// Because it returns only a `u128`, it assumes delivery fees are only paid
|
||||
/// in one asset and that asset is known.
|
||||
pub fn transfer_assets_delivery_fees<S: SendXcm>(
|
||||
assets: MultiAssets,
|
||||
assets: Assets,
|
||||
fee_asset_item: u32,
|
||||
weight_limit: WeightLimit,
|
||||
beneficiary: MultiLocation,
|
||||
destination: MultiLocation,
|
||||
beneficiary: Location,
|
||||
destination: Location,
|
||||
) -> u128 {
|
||||
let message = teleport_assets_dummy_message(assets, fee_asset_item, weight_limit, beneficiary);
|
||||
get_fungible_delivery_fees::<S>(destination, message)
|
||||
@@ -35,7 +35,7 @@ pub fn transfer_assets_delivery_fees<S: SendXcm>(
|
||||
|
||||
/// Returns the delivery fees amount for a query response as a result of the execution
|
||||
/// of a `ExpectError` instruction with no error.
|
||||
pub fn query_response_delivery_fees<S: SendXcm>(querier: MultiLocation) -> u128 {
|
||||
pub fn query_response_delivery_fees<S: SendXcm>(querier: Location) -> u128 {
|
||||
// Message to calculate delivery fees, it's encoded size is what's important.
|
||||
// This message reports that there was no error, if an error is reported, the encoded size would
|
||||
// be different.
|
||||
@@ -45,7 +45,7 @@ pub fn query_response_delivery_fees<S: SendXcm>(querier: MultiLocation) -> u128
|
||||
query_id: 0, // Dummy query id
|
||||
response: Response::ExecutionResult(None),
|
||||
max_weight: Weight::zero(),
|
||||
querier: Some(querier),
|
||||
querier: Some(querier.clone()),
|
||||
},
|
||||
SetTopic([0u8; 32]), // Dummy topic
|
||||
]);
|
||||
@@ -55,9 +55,9 @@ pub fn query_response_delivery_fees<S: SendXcm>(querier: MultiLocation) -> u128
|
||||
/// Returns the delivery fees amount for the execution of `PayOverXcm`
|
||||
pub fn pay_over_xcm_delivery_fees<S: SendXcm>(
|
||||
interior: Junctions,
|
||||
destination: MultiLocation,
|
||||
beneficiary: MultiLocation,
|
||||
asset: MultiAsset,
|
||||
destination: Location,
|
||||
beneficiary: Location,
|
||||
asset: Asset,
|
||||
) -> u128 {
|
||||
// This is a dummy message.
|
||||
// The encoded size is all that matters for delivery fees.
|
||||
@@ -66,7 +66,11 @@ pub fn pay_over_xcm_delivery_fees<S: SendXcm>(
|
||||
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
|
||||
SetAppendix(Xcm(vec![
|
||||
SetFeesMode { jit_withdraw: true },
|
||||
ReportError(QueryResponseInfo { destination, query_id: 0, max_weight: Weight::zero() }),
|
||||
ReportError(QueryResponseInfo {
|
||||
destination: destination.clone(),
|
||||
query_id: 0,
|
||||
max_weight: Weight::zero(),
|
||||
}),
|
||||
])),
|
||||
TransferAsset { beneficiary, assets: vec![asset].into() },
|
||||
]);
|
||||
@@ -78,10 +82,10 @@ pub fn pay_over_xcm_delivery_fees<S: SendXcm>(
|
||||
/// However, it should have the same encoded size, which is what matters for delivery fees.
|
||||
/// Also has same encoded size as the one created by the reserve transfer assets extrinsic.
|
||||
fn teleport_assets_dummy_message(
|
||||
assets: MultiAssets,
|
||||
assets: Assets,
|
||||
fee_asset_item: u32,
|
||||
weight_limit: WeightLimit,
|
||||
beneficiary: MultiLocation,
|
||||
beneficiary: Location,
|
||||
) -> Xcm<()> {
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset(assets.clone()), // Same encoded size as `ReserveAssetDeposited`
|
||||
@@ -93,7 +97,7 @@ fn teleport_assets_dummy_message(
|
||||
}
|
||||
|
||||
/// Given a message, a sender, and a destination, it returns the delivery fees
|
||||
fn get_fungible_delivery_fees<S: SendXcm>(destination: MultiLocation, message: Xcm<()>) -> u128 {
|
||||
fn get_fungible_delivery_fees<S: SendXcm>(destination: Location, message: Xcm<()>) -> u128 {
|
||||
let Ok((_, delivery_fees)) = validate_send::<S>(destination, message) else {
|
||||
unreachable!("message can be sent; qed")
|
||||
};
|
||||
|
||||
+15
-15
@@ -48,7 +48,7 @@ use frame_support::{parameter_types, traits::PalletInfoAccess};
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use xcm::{
|
||||
latest::prelude::*,
|
||||
prelude::{InteriorMultiLocation, NetworkId},
|
||||
prelude::{InteriorLocation, NetworkId},
|
||||
};
|
||||
use xcm_builder::BridgeBlobDispatcher;
|
||||
|
||||
@@ -65,16 +65,16 @@ parameter_types! {
|
||||
/// Bridge specific chain (network) identifier of the Rococo Bulletin Chain.
|
||||
pub const RococoBulletinChainId: bp_runtime::ChainId = bp_runtime::POLKADOT_BULLETIN_CHAIN_ID;
|
||||
/// Interior location (relative to this runtime) of the with-RococoBulletin messages pallet.
|
||||
pub BridgeRococoToRococoBulletinMessagesPalletInstance: InteriorMultiLocation = X1(
|
||||
pub BridgeRococoToRococoBulletinMessagesPalletInstance: InteriorLocation = [
|
||||
PalletInstance(<BridgeRococoBulletinMessages as PalletInfoAccess>::index() as u8)
|
||||
);
|
||||
].into();
|
||||
/// Rococo Bulletin Network identifier.
|
||||
pub RococoBulletinGlobalConsensusNetwork: NetworkId = NetworkId::PolkadotBulletin;
|
||||
/// Relative location of the Rococo Bulletin chain.
|
||||
pub RococoBulletinGlobalConsensusNetworkLocation: MultiLocation = MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get()))
|
||||
};
|
||||
pub RococoBulletinGlobalConsensusNetworkLocation: Location = Location::new(
|
||||
2,
|
||||
[GlobalConsensus(RococoBulletinGlobalConsensusNetwork::get())]
|
||||
);
|
||||
/// All active lanes that the current bridge supports.
|
||||
pub ActiveOutboundLanesToRococoBulletin: &'static [bp_messages::LaneId]
|
||||
= &[XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN];
|
||||
@@ -94,11 +94,11 @@ parameter_types! {
|
||||
/// A route (XCM location and bridge lane) that the Rococo People Chain -> Rococo Bulletin Chain
|
||||
/// message is following.
|
||||
pub FromRococoPeopleToRococoBulletinRoute: SenderAndLane = SenderAndLane::new(
|
||||
ParentThen(X1(Parachain(RococoPeopleParaId::get().into()))).into(),
|
||||
ParentThen(Parachain(RococoPeopleParaId::get().into()).into()).into(),
|
||||
XCM_LANE_FOR_ROCOCO_PEOPLE_TO_ROCOCO_BULLETIN,
|
||||
);
|
||||
/// All active routes and their destinations.
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(
|
||||
FromRococoPeopleToRococoBulletinRoute::get(),
|
||||
(RococoBulletinGlobalConsensusNetwork::get(), Here)
|
||||
@@ -282,11 +282,11 @@ mod tests {
|
||||
PriorityBoostPerMessage,
|
||||
>(FEE_BOOST_PER_MESSAGE);
|
||||
|
||||
assert_eq!(
|
||||
BridgeRococoToRococoBulletinMessagesPalletInstance::get(),
|
||||
X1(PalletInstance(
|
||||
bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX
|
||||
))
|
||||
);
|
||||
let expected: InteriorLocation = PalletInstance(
|
||||
bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_BULLETIN_MESSAGES_PALLET_INDEX,
|
||||
)
|
||||
.into();
|
||||
|
||||
assert_eq!(BridgeRococoToRococoBulletinMessagesPalletInstance::get(), expected,);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -48,7 +48,7 @@ use frame_support::{parameter_types, traits::PalletInfoAccess};
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use xcm::{
|
||||
latest::prelude::*,
|
||||
prelude::{InteriorMultiLocation, NetworkId},
|
||||
prelude::{InteriorLocation, NetworkId},
|
||||
};
|
||||
use xcm_builder::BridgeBlobDispatcher;
|
||||
|
||||
@@ -58,12 +58,12 @@ parameter_types! {
|
||||
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
|
||||
bp_bridge_hub_rococo::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
|
||||
pub const BridgeHubWestendChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_WESTEND_CHAIN_ID;
|
||||
pub BridgeRococoToWestendMessagesPalletInstance: InteriorMultiLocation = X1(PalletInstance(<BridgeWestendMessages as PalletInfoAccess>::index() as u8));
|
||||
pub BridgeRococoToWestendMessagesPalletInstance: InteriorLocation = [PalletInstance(<BridgeWestendMessages as PalletInfoAccess>::index() as u8)].into();
|
||||
pub WestendGlobalConsensusNetwork: NetworkId = NetworkId::Westend;
|
||||
pub WestendGlobalConsensusNetworkLocation: MultiLocation = MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(WestendGlobalConsensusNetwork::get()))
|
||||
};
|
||||
pub WestendGlobalConsensusNetworkLocation: Location = Location::new(
|
||||
2,
|
||||
[GlobalConsensus(WestendGlobalConsensusNetwork::get())]
|
||||
);
|
||||
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
|
||||
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;
|
||||
|
||||
@@ -74,26 +74,26 @@ parameter_types! {
|
||||
pub ActiveOutboundLanesToBridgeHubWestend: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND];
|
||||
pub const AssetHubRococoToAssetHubWestendMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND;
|
||||
pub FromAssetHubRococoToAssetHubWestendRoute: SenderAndLane = SenderAndLane::new(
|
||||
ParentThen(X1(Parachain(AssetHubRococoParaId::get().into()))).into(),
|
||||
ParentThen([Parachain(AssetHubRococoParaId::get().into())].into()).into(),
|
||||
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
|
||||
);
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(
|
||||
FromAssetHubRococoToAssetHubWestendRoute::get(),
|
||||
(WestendGlobalConsensusNetwork::get(), X1(Parachain(AssetHubWestendParaId::get().into())))
|
||||
(WestendGlobalConsensusNetwork::get(), [Parachain(AssetHubWestendParaId::get().into())].into())
|
||||
)
|
||||
];
|
||||
|
||||
pub CongestedMessage: Xcm<()> = build_congestion_message(true).into();
|
||||
pub UncongestedMessage: Xcm<()> = build_congestion_message(false).into();
|
||||
|
||||
pub BridgeHubWestendLocation: MultiLocation = MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
pub BridgeHubWestendLocation: Location = Location::new(
|
||||
2,
|
||||
[
|
||||
GlobalConsensus(WestendGlobalConsensusNetwork::get()),
|
||||
Parachain(<bp_bridge_hub_westend::BridgeHubWestend as bp_runtime::Parachain>::PARACHAIN_ID)
|
||||
)
|
||||
};
|
||||
]
|
||||
);
|
||||
}
|
||||
pub const XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND: LaneId = LaneId([0, 0, 0, 2]);
|
||||
|
||||
@@ -327,11 +327,11 @@ mod tests {
|
||||
PriorityBoostPerMessage,
|
||||
>(FEE_BOOST_PER_MESSAGE);
|
||||
|
||||
assert_eq!(
|
||||
BridgeRococoToWestendMessagesPalletInstance::get(),
|
||||
X1(PalletInstance(
|
||||
bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX
|
||||
))
|
||||
);
|
||||
let expected: InteriorLocation = [PalletInstance(
|
||||
bp_bridge_hub_rococo::WITH_BRIDGE_ROCOCO_TO_WESTEND_MESSAGES_PALLET_INDEX,
|
||||
)]
|
||||
.into();
|
||||
|
||||
assert_eq!(BridgeRococoToWestendMessagesPalletInstance::get(), expected,);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ use bridge_hub_common::{
|
||||
use pallet_xcm::EnsureXcm;
|
||||
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
|
||||
pub use sp_runtime::{MultiAddress, Perbill, Permill};
|
||||
use xcm::VersionedMultiLocation;
|
||||
use xcm::VersionedLocation;
|
||||
use xcm_config::{TreasuryAccount, XcmOriginToTransactDispatchOrigin, XcmRouter};
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -385,7 +385,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(xcm_config::TokenLocation::get());
|
||||
pub FeeAssetId: AssetId = AssetId(xcm_config::TokenLocation::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
|
||||
}
|
||||
@@ -517,7 +517,7 @@ pub mod benchmark_helpers {
|
||||
use snowbridge_beacon_primitives::CompactExecutionHeader;
|
||||
use snowbridge_pallet_inbound_queue::BenchmarkHelper;
|
||||
use sp_core::H256;
|
||||
use xcm::latest::{MultiAssets, MultiLocation, SendError, SendResult, SendXcm, Xcm, XcmHash};
|
||||
use xcm::latest::{Assets, Location, SendError, SendResult, SendXcm, Xcm, XcmHash};
|
||||
|
||||
impl<T: snowbridge_pallet_ethereum_client::Config> BenchmarkHelper<T> for Runtime {
|
||||
fn initialize_storage(block_hash: H256, header: CompactExecutionHeader) {
|
||||
@@ -530,10 +530,10 @@ pub mod benchmark_helpers {
|
||||
type Ticket = Xcm<()>;
|
||||
|
||||
fn validate(
|
||||
_dest: &mut Option<MultiLocation>,
|
||||
_dest: &mut Option<Location>,
|
||||
xcm: &mut Option<Xcm<()>>,
|
||||
) -> SendResult<Self::Ticket> {
|
||||
Ok((xcm.clone().unwrap(), MultiAssets::new()))
|
||||
Ok((xcm.clone().unwrap(), Assets::new()))
|
||||
}
|
||||
fn deliver(xcm: Xcm<()>) -> Result<XcmHash, SendError> {
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
@@ -542,7 +542,7 @@ pub mod benchmark_helpers {
|
||||
}
|
||||
|
||||
impl snowbridge_pallet_system::BenchmarkHelper<RuntimeOrigin> for () {
|
||||
fn make_xcm_origin(location: MultiLocation) -> RuntimeOrigin {
|
||||
fn make_xcm_origin(location: Location) -> RuntimeOrigin {
|
||||
RuntimeOrigin::from(pallet_xcm::Origin::Xcm(location))
|
||||
}
|
||||
}
|
||||
@@ -1016,7 +1016,7 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl snowbridge_system_runtime_api::ControlApi<Block> for Runtime {
|
||||
fn agent_id(location: VersionedMultiLocation) -> Option<AgentId> {
|
||||
fn agent_id(location: VersionedLocation) -> Option<AgentId> {
|
||||
snowbridge_pallet_system::api::agent_id::<Runtime>(location)
|
||||
}
|
||||
}
|
||||
@@ -1095,28 +1095,28 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Reserve transfers are disabled on BH.
|
||||
None
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
// BH only supports teleports to system parachain.
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
let native_location = Parent.into();
|
||||
@@ -1132,7 +1132,7 @@ impl_runtime_apis! {
|
||||
use xcm_config::TokenLocation;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
TokenLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
@@ -1143,17 +1143,17 @@ impl_runtime_apis! {
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositMultiAsset,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
Ok(TokenLocation::get())
|
||||
}
|
||||
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
|
||||
fn worst_case_holding(_depositable_count: u32) -> Assets {
|
||||
// just concrete assets according to relay chain.
|
||||
let assets: Vec<MultiAsset> = vec![
|
||||
MultiAsset {
|
||||
id: Concrete(TokenLocation::get()),
|
||||
let assets: Vec<Asset> = vec![
|
||||
Asset {
|
||||
id: AssetId(TokenLocation::get()),
|
||||
fun: Fungible(1_000_000 * UNITS),
|
||||
}
|
||||
];
|
||||
@@ -1162,12 +1162,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
|
||||
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
|
||||
TokenLocation::get(),
|
||||
MultiAsset { fun: Fungible(UNITS), id: Concrete(TokenLocation::get()) },
|
||||
Asset { fun: Fungible(UNITS), id: AssetId(TokenLocation::get()) },
|
||||
));
|
||||
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
|
||||
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
|
||||
pub const TrustedReserve: Option<(Location, Asset)> = None;
|
||||
}
|
||||
|
||||
impl pallet_xcm_benchmarks::fungible::Config for Runtime {
|
||||
@@ -1177,9 +1177,9 @@ impl_runtime_apis! {
|
||||
type TrustedTeleporter = TrustedTeleporter;
|
||||
type TrustedReserve = TrustedReserve;
|
||||
|
||||
fn get_multi_asset() -> MultiAsset {
|
||||
MultiAsset {
|
||||
id: Concrete(TokenLocation::get()),
|
||||
fn get_asset() -> Asset {
|
||||
Asset {
|
||||
id: AssetId(TokenLocation::get()),
|
||||
fun: Fungible(UNITS),
|
||||
}
|
||||
}
|
||||
@@ -1193,35 +1193,35 @@ impl_runtime_apis! {
|
||||
(0u64, Response::Version(Default::default()))
|
||||
}
|
||||
|
||||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
|
||||
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
|
||||
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
|
||||
fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
|
||||
Ok((TokenLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
|
||||
}
|
||||
|
||||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn subscribe_origin() -> Result<Location, BenchmarkError> {
|
||||
Ok(TokenLocation::get())
|
||||
}
|
||||
|
||||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
|
||||
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
|
||||
let origin = TokenLocation::get();
|
||||
let assets: MultiAssets = (Concrete(TokenLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = MultiLocation { parents: 0, interior: Here };
|
||||
let assets: Assets = (AssetId(TokenLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = Location { parents: 0, interior: Here };
|
||||
Ok((origin, ticket, assets))
|
||||
}
|
||||
|
||||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
|
||||
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn export_message_origin_and_destination(
|
||||
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
|
||||
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
|
||||
// save XCM version for remote bridge hub
|
||||
let _ = PolkadotXcm::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
@@ -1241,12 +1241,12 @@ impl_runtime_apis! {
|
||||
(
|
||||
bridge_to_westend_config::FromAssetHubRococoToAssetHubWestendRoute::get().location,
|
||||
NetworkId::Westend,
|
||||
X1(Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into()))
|
||||
[Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into())].into()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
|
||||
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
@@ -1296,7 +1296,7 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
bridge_common_config::BridgeGrandpaWestendInstance,
|
||||
bridge_to_westend_config::WithBridgeHubWestendMessageBridge,
|
||||
>(params, generate_xcm_builder_bridge_message_sample(X2(GlobalConsensus(Rococo), Parachain(42))))
|
||||
>(params, generate_xcm_builder_bridge_message_sample([GlobalConsensus(Rococo), Parachain(42)].into()))
|
||||
}
|
||||
|
||||
fn prepare_message_delivery_proof(
|
||||
@@ -1331,7 +1331,7 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
bridge_common_config::BridgeGrandpaRococoBulletinInstance,
|
||||
bridge_to_bulletin_config::WithRococoBulletinMessageBridge,
|
||||
>(params, generate_xcm_builder_bridge_message_sample(X2(GlobalConsensus(Rococo), Parachain(42))))
|
||||
>(params, generate_xcm_builder_bridge_message_sample([GlobalConsensus(Rococo), Parachain(42)].into()))
|
||||
}
|
||||
|
||||
fn prepare_message_delivery_proof(
|
||||
|
||||
@@ -24,14 +24,14 @@ use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
|
||||
use sp_std::prelude::*;
|
||||
use xcm::{latest::prelude::*, DoubleEncoded};
|
||||
|
||||
trait WeighMultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
|
||||
trait WeighAssets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight;
|
||||
}
|
||||
|
||||
const MAX_ASSETS: u64 = 100;
|
||||
|
||||
impl WeighMultiAssets for MultiAssetFilter {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for AssetFilter {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
match self {
|
||||
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
|
||||
Self::Wild(asset) => match asset {
|
||||
@@ -50,40 +50,36 @@ impl WeighMultiAssets for MultiAssetFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeighMultiAssets for MultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for Assets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
weight.saturating_mul(self.inner().iter().count() as u64)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BridgeHubRococoXcmWeight<Call>(core::marker::PhantomData<Call>);
|
||||
impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
fn withdraw_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
fn withdraw_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
}
|
||||
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
fn reserve_asset_deposited(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
}
|
||||
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
fn receive_teleported_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
}
|
||||
fn query_response(
|
||||
_query_id: &u64,
|
||||
_response: &Response,
|
||||
_max_weight: &Weight,
|
||||
_querier: &Option<MultiLocation>,
|
||||
_querier: &Option<Location>,
|
||||
) -> Weight {
|
||||
XcmGeneric::<Runtime>::query_response()
|
||||
}
|
||||
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
}
|
||||
fn transfer_reserve_asset(
|
||||
assets: &MultiAssets,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
}
|
||||
fn transact(
|
||||
_origin_type: &OriginKind,
|
||||
@@ -111,44 +107,36 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
fn clear_origin() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_origin()
|
||||
}
|
||||
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
|
||||
fn descend_origin(_who: &InteriorLocation) -> Weight {
|
||||
XcmGeneric::<Runtime>::descend_origin()
|
||||
}
|
||||
fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_error()
|
||||
}
|
||||
|
||||
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
}
|
||||
fn deposit_reserve_asset(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
}
|
||||
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
|
||||
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn initiate_reserve_withdraw(
|
||||
assets: &MultiAssetFilter,
|
||||
_reserve: &MultiLocation,
|
||||
assets: &AssetFilter,
|
||||
_reserve: &Location,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
}
|
||||
fn initiate_teleport(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
}
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_holding()
|
||||
}
|
||||
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
|
||||
fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
|
||||
XcmGeneric::<Runtime>::buy_execution()
|
||||
}
|
||||
fn refund_surplus() -> Weight {
|
||||
@@ -163,7 +151,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
fn clear_error() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_error()
|
||||
}
|
||||
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
|
||||
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
|
||||
XcmGeneric::<Runtime>::claim_asset()
|
||||
}
|
||||
fn trap(_code: &u64) -> Weight {
|
||||
@@ -175,13 +163,13 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
fn unsubscribe_version() -> Weight {
|
||||
XcmGeneric::<Runtime>::unsubscribe_version()
|
||||
}
|
||||
fn burn_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
fn burn_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
}
|
||||
fn expect_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
fn expect_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
}
|
||||
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
|
||||
fn expect_origin(_origin: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::expect_origin()
|
||||
}
|
||||
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
|
||||
@@ -215,16 +203,16 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
let inner_encoded_len = inner.encode().len() as u32;
|
||||
XcmGeneric::<Runtime>::export_message(inner_encoded_len)
|
||||
}
|
||||
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn lock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn unlock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn note_unlockable(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn request_unlock(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn set_fees_mode(_: &bool) -> Weight {
|
||||
@@ -236,11 +224,11 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubRococoXcmWeight<Call> {
|
||||
fn clear_topic() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_topic()
|
||||
}
|
||||
fn alias_origin(_: &MultiLocation) -> Weight {
|
||||
fn alias_origin(_: &Location) -> Weight {
|
||||
// XCM Executor does not currently support alias origin operations
|
||||
Weight::MAX
|
||||
}
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::unpaid_execution()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ use bp_messages::LaneId;
|
||||
use bp_relayers::{PayRewardFromAccount, RewardsAccountOwner, RewardsAccountParams};
|
||||
use bp_runtime::ChainId;
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Equals, Everything, Nothing},
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
@@ -69,19 +69,19 @@ use xcm_executor::{
|
||||
};
|
||||
|
||||
parameter_types! {
|
||||
pub const TokenLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const TokenLocation: Location = Location::parent();
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub RelayNetwork: NetworkId = NetworkId::Rococo;
|
||||
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 const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
|
||||
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub SiblingPeople: MultiLocation = (Parent, Parachain(rococo_runtime_constants::system_parachain::PEOPLE_ID)).into();
|
||||
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub SiblingPeople: Location = (Parent, Parachain(rococo_runtime_constants::system_parachain::PEOPLE_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 = (
|
||||
@@ -100,7 +100,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<TokenLocation>,
|
||||
// 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,
|
||||
@@ -132,11 +132,11 @@ pub type XcmOriginToTransactDispatchOrigin = (
|
||||
XcmPassthrough<RuntimeOrigin>,
|
||||
);
|
||||
|
||||
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
|
||||
@@ -331,7 +331,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
pub type PriceForParentDelivery =
|
||||
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
|
||||
|
||||
/// 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>;
|
||||
|
||||
@@ -407,14 +407,10 @@ impl<
|
||||
BridgeLaneId,
|
||||
>
|
||||
{
|
||||
fn handle_fee(
|
||||
fee: MultiAssets,
|
||||
maybe_context: Option<&XcmContext>,
|
||||
reason: FeeReason,
|
||||
) -> MultiAssets {
|
||||
fn handle_fee(fee: Assets, maybe_context: Option<&XcmContext>, reason: FeeReason) -> Assets {
|
||||
if matches!(reason, FeeReason::Export { network: bridged_network, destination }
|
||||
if bridged_network == DestNetwork::get() &&
|
||||
destination == X1(Parachain(DestParaId::get().into())))
|
||||
destination == [Parachain(DestParaId::get().into())])
|
||||
{
|
||||
// We have 2 relayer rewards accounts:
|
||||
// - the SA of the source parachain on this BH: this pays the relayers for delivering
|
||||
@@ -445,14 +441,14 @@ impl<
|
||||
Fungible(total_fee) => {
|
||||
let source_fee = total_fee / 2;
|
||||
deposit_or_burn_fee::<AssetTransactor, _>(
|
||||
MultiAsset { id: asset.id, fun: Fungible(source_fee) }.into(),
|
||||
Asset { id: asset.id.clone(), fun: Fungible(source_fee) }.into(),
|
||||
maybe_context,
|
||||
source_para_account.clone(),
|
||||
);
|
||||
|
||||
let dest_fee = total_fee - source_fee;
|
||||
deposit_or_burn_fee::<AssetTransactor, _>(
|
||||
MultiAsset { id: asset.id, fun: Fungible(dest_fee) }.into(),
|
||||
Asset { id: asset.id, fun: Fungible(dest_fee) }.into(),
|
||||
maybe_context,
|
||||
dest_para_account.clone(),
|
||||
);
|
||||
@@ -467,7 +463,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
return MultiAssets::new()
|
||||
return Assets::new()
|
||||
}
|
||||
|
||||
fee
|
||||
@@ -477,10 +473,10 @@ impl<
|
||||
pub struct XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, HandleFee>(
|
||||
PhantomData<(WaivedLocations, HandleFee)>,
|
||||
);
|
||||
impl<WaivedLocations: Contains<MultiLocation>, FeeHandler: HandleFee> FeeManager
|
||||
impl<WaivedLocations: Contains<Location>, FeeHandler: HandleFee> FeeManager
|
||||
for XcmFeeManagerFromComponentsBridgeHub<WaivedLocations, FeeHandler>
|
||||
{
|
||||
fn is_waived(origin: Option<&MultiLocation>, fee_reason: FeeReason) -> bool {
|
||||
fn is_waived(origin: Option<&Location>, fee_reason: FeeReason) -> bool {
|
||||
let Some(loc) = origin else { return false };
|
||||
if let Export { network, destination: Here } = fee_reason {
|
||||
return !(network == EthereumNetwork::get())
|
||||
@@ -488,7 +484,7 @@ impl<WaivedLocations: Contains<MultiLocation>, FeeHandler: HandleFee> FeeManager
|
||||
WaivedLocations::contains(loc)
|
||||
}
|
||||
|
||||
fn handle_fee(fee: MultiAssets, context: Option<&XcmContext>, reason: FeeReason) {
|
||||
fn handle_fee(fee: Assets, context: Option<&XcmContext>, reason: FeeReason) {
|
||||
FeeHandler::handle_fee(fee, context, reason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ mod bridge_hub_westend_tests {
|
||||
_ => None,
|
||||
}
|
||||
}),
|
||||
|| ExportMessage { network: Westend, destination: X1(Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into())), xcm: Xcm(vec![]) },
|
||||
|| ExportMessage { network: Westend, destination: [Parachain(bridge_to_westend_config::AssetHubWestendParaId::get().into())].into(), xcm: Xcm(vec![]) },
|
||||
XCM_LANE_FOR_ASSET_HUB_ROCOCO_TO_ASSET_HUB_WESTEND,
|
||||
Some((TokenLocation::get(), ExistentialDeposit::get()).into()),
|
||||
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
|
||||
|
||||
+16
-16
@@ -47,7 +47,7 @@ use frame_support::{
|
||||
use sp_runtime::RuntimeDebug;
|
||||
use xcm::{
|
||||
latest::prelude::*,
|
||||
prelude::{InteriorMultiLocation, NetworkId},
|
||||
prelude::{InteriorLocation, NetworkId},
|
||||
};
|
||||
use xcm_builder::BridgeBlobDispatcher;
|
||||
|
||||
@@ -63,12 +63,12 @@ parameter_types! {
|
||||
pub const MaxUnconfirmedMessagesAtInboundLane: bp_messages::MessageNonce =
|
||||
bp_bridge_hub_westend::MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX;
|
||||
pub const BridgeHubRococoChainId: bp_runtime::ChainId = bp_runtime::BRIDGE_HUB_ROCOCO_CHAIN_ID;
|
||||
pub BridgeWestendToRococoMessagesPalletInstance: InteriorMultiLocation = X1(PalletInstance(<BridgeRococoMessages as PalletInfoAccess>::index() as u8));
|
||||
pub BridgeWestendToRococoMessagesPalletInstance: InteriorLocation = [PalletInstance(<BridgeRococoMessages as PalletInfoAccess>::index() as u8)].into();
|
||||
pub RococoGlobalConsensusNetwork: NetworkId = NetworkId::Rococo;
|
||||
pub RococoGlobalConsensusNetworkLocation: MultiLocation = MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(RococoGlobalConsensusNetwork::get()))
|
||||
};
|
||||
pub RococoGlobalConsensusNetworkLocation: Location = Location::new(
|
||||
2,
|
||||
[GlobalConsensus(RococoGlobalConsensusNetwork::get())]
|
||||
);
|
||||
// see the `FEE_BOOST_PER_MESSAGE` constant to get the meaning of this value
|
||||
pub PriorityBoostPerMessage: u64 = 182_044_444_444_444;
|
||||
|
||||
@@ -79,26 +79,26 @@ parameter_types! {
|
||||
pub ActiveOutboundLanesToBridgeHubRococo: &'static [bp_messages::LaneId] = &[XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO];
|
||||
pub const AssetHubWestendToAssetHubRococoMessagesLane: bp_messages::LaneId = XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO;
|
||||
pub FromAssetHubWestendToAssetHubRococoRoute: SenderAndLane = SenderAndLane::new(
|
||||
ParentThen(X1(Parachain(AssetHubWestendParaId::get().into()))).into(),
|
||||
ParentThen([Parachain(AssetHubWestendParaId::get().into())].into()).into(),
|
||||
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
|
||||
);
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorMultiLocation))> = sp_std::vec![
|
||||
pub ActiveLanes: sp_std::vec::Vec<(SenderAndLane, (NetworkId, InteriorLocation))> = sp_std::vec![
|
||||
(
|
||||
FromAssetHubWestendToAssetHubRococoRoute::get(),
|
||||
(RococoGlobalConsensusNetwork::get(), X1(Parachain(AssetHubRococoParaId::get().into())))
|
||||
(RococoGlobalConsensusNetwork::get(), [Parachain(AssetHubRococoParaId::get().into())].into())
|
||||
)
|
||||
];
|
||||
|
||||
pub CongestedMessage: Xcm<()> = build_congestion_message(true).into();
|
||||
pub UncongestedMessage: Xcm<()> = build_congestion_message(false).into();
|
||||
|
||||
pub BridgeHubRococoLocation: MultiLocation = MultiLocation {
|
||||
parents: 2,
|
||||
interior: X2(
|
||||
pub BridgeHubRococoLocation: Location = Location::new(
|
||||
2,
|
||||
[
|
||||
GlobalConsensus(RococoGlobalConsensusNetwork::get()),
|
||||
Parachain(<bp_bridge_hub_rococo::BridgeHubRococo as bp_runtime::Parachain>::PARACHAIN_ID)
|
||||
)
|
||||
};
|
||||
]
|
||||
);
|
||||
}
|
||||
pub const XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO: LaneId = LaneId([0, 0, 0, 2]);
|
||||
|
||||
@@ -363,9 +363,9 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
BridgeWestendToRococoMessagesPalletInstance::get(),
|
||||
X1(PalletInstance(
|
||||
[PalletInstance(
|
||||
bp_bridge_hub_westend::WITH_BRIDGE_WESTEND_TO_ROCOCO_MESSAGES_PALLET_INDEX
|
||||
))
|
||||
)]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(xcm_config::WestendLocation::get());
|
||||
pub FeeAssetId: AssetId = AssetId(xcm_config::WestendLocation::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
|
||||
}
|
||||
@@ -797,28 +797,28 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
},
|
||||
Parent.into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Reserve transfers are disabled on BH.
|
||||
None
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
// BH only supports teleports to system parachain.
|
||||
// Relay/native token can be teleported between BH and Relay.
|
||||
let native_location = Parent.into();
|
||||
@@ -834,7 +834,7 @@ impl_runtime_apis! {
|
||||
use xcm_config::WestendLocation;
|
||||
|
||||
parameter_types! {
|
||||
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
|
||||
pub ExistentialDepositAsset: Option<Asset> = Some((
|
||||
WestendLocation::get(),
|
||||
ExistentialDeposit::get()
|
||||
).into());
|
||||
@@ -845,17 +845,17 @@ impl_runtime_apis! {
|
||||
type AccountIdConverter = xcm_config::LocationToAccountId;
|
||||
type DeliveryHelper = cumulus_primitives_utility::ToParentDeliveryHelper<
|
||||
xcm_config::XcmConfig,
|
||||
ExistentialDepositMultiAsset,
|
||||
ExistentialDepositAsset,
|
||||
xcm_config::PriceForParentDelivery,
|
||||
>;
|
||||
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn valid_destination() -> Result<Location, BenchmarkError> {
|
||||
Ok(WestendLocation::get())
|
||||
}
|
||||
fn worst_case_holding(_depositable_count: u32) -> MultiAssets {
|
||||
// just concrete assets according to relay chain.
|
||||
let assets: Vec<MultiAsset> = vec![
|
||||
MultiAsset {
|
||||
id: Concrete(WestendLocation::get()),
|
||||
fn worst_case_holding(_depositable_count: u32) -> Assets {
|
||||
// just assets according to relay chain.
|
||||
let assets: Vec<Asset> = vec![
|
||||
Asset {
|
||||
id: AssetId(WestendLocation::get()),
|
||||
fun: Fungible(1_000_000 * UNITS),
|
||||
}
|
||||
];
|
||||
@@ -864,12 +864,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
|
||||
pub const TrustedTeleporter: Option<(Location, Asset)> = Some((
|
||||
WestendLocation::get(),
|
||||
MultiAsset { fun: Fungible(UNITS), id: Concrete(WestendLocation::get()) },
|
||||
Asset { fun: Fungible(UNITS), id: AssetId(WestendLocation::get()) },
|
||||
));
|
||||
pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None;
|
||||
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = None;
|
||||
pub const TrustedReserve: Option<(Location, Asset)> = None;
|
||||
}
|
||||
|
||||
impl pallet_xcm_benchmarks::fungible::Config for Runtime {
|
||||
@@ -879,9 +879,9 @@ impl_runtime_apis! {
|
||||
type TrustedTeleporter = TrustedTeleporter;
|
||||
type TrustedReserve = TrustedReserve;
|
||||
|
||||
fn get_multi_asset() -> MultiAsset {
|
||||
MultiAsset {
|
||||
id: Concrete(WestendLocation::get()),
|
||||
fn get_asset() -> Asset {
|
||||
Asset {
|
||||
id: AssetId(WestendLocation::get()),
|
||||
fun: Fungible(UNITS),
|
||||
}
|
||||
}
|
||||
@@ -895,35 +895,35 @@ impl_runtime_apis! {
|
||||
(0u64, Response::Version(Default::default()))
|
||||
}
|
||||
|
||||
fn worst_case_asset_exchange() -> Result<(MultiAssets, MultiAssets), BenchmarkError> {
|
||||
fn worst_case_asset_exchange() -> Result<(Assets, Assets), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn universal_alias() -> Result<(MultiLocation, Junction), BenchmarkError> {
|
||||
fn universal_alias() -> Result<(Location, Junction), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn transact_origin_and_runtime_call() -> Result<(MultiLocation, RuntimeCall), BenchmarkError> {
|
||||
fn transact_origin_and_runtime_call() -> Result<(Location, RuntimeCall), BenchmarkError> {
|
||||
Ok((WestendLocation::get(), frame_system::Call::remark_with_event { remark: vec![] }.into()))
|
||||
}
|
||||
|
||||
fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
|
||||
fn subscribe_origin() -> Result<Location, BenchmarkError> {
|
||||
Ok(WestendLocation::get())
|
||||
}
|
||||
|
||||
fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
|
||||
fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> {
|
||||
let origin = WestendLocation::get();
|
||||
let assets: MultiAssets = (Concrete(WestendLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = MultiLocation { parents: 0, interior: Here };
|
||||
let assets: Assets = (AssetId(WestendLocation::get()), 1_000 * UNITS).into();
|
||||
let ticket = Location { parents: 0, interior: Here };
|
||||
Ok((origin, ticket, assets))
|
||||
}
|
||||
|
||||
fn unlockable_asset() -> Result<(MultiLocation, MultiLocation, MultiAsset), BenchmarkError> {
|
||||
fn unlockable_asset() -> Result<(Location, Location, Asset), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
|
||||
fn export_message_origin_and_destination(
|
||||
) -> Result<(MultiLocation, NetworkId, InteriorMultiLocation), BenchmarkError> {
|
||||
) -> Result<(Location, NetworkId, InteriorLocation), BenchmarkError> {
|
||||
// save XCM version for remote bridge hub
|
||||
let _ = PolkadotXcm::force_xcm_version(
|
||||
RuntimeOrigin::root(),
|
||||
@@ -943,12 +943,12 @@ impl_runtime_apis! {
|
||||
(
|
||||
bridge_to_rococo_config::FromAssetHubWestendToAssetHubRococoRoute::get().location,
|
||||
NetworkId::Rococo,
|
||||
X1(Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into()))
|
||||
[Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into())].into()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fn alias_origin() -> Result<(MultiLocation, MultiLocation), BenchmarkError> {
|
||||
fn alias_origin() -> Result<(Location, Location), BenchmarkError> {
|
||||
Err(BenchmarkError::Skip)
|
||||
}
|
||||
}
|
||||
@@ -995,7 +995,7 @@ impl_runtime_apis! {
|
||||
Runtime,
|
||||
bridge_to_rococo_config::BridgeGrandpaRococoInstance,
|
||||
bridge_to_rococo_config::WithBridgeHubRococoMessageBridge,
|
||||
>(params, generate_xcm_builder_bridge_message_sample(X2(GlobalConsensus(Westend), Parachain(42))))
|
||||
>(params, generate_xcm_builder_bridge_message_sample([GlobalConsensus(Westend), Parachain(42)].into()))
|
||||
}
|
||||
|
||||
fn prepare_message_delivery_proof(
|
||||
|
||||
@@ -25,14 +25,14 @@ use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;
|
||||
use sp_std::prelude::*;
|
||||
use xcm::{latest::prelude::*, DoubleEncoded};
|
||||
|
||||
trait WeighMultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight;
|
||||
trait WeighAssets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight;
|
||||
}
|
||||
|
||||
const MAX_ASSETS: u64 = 100;
|
||||
|
||||
impl WeighMultiAssets for MultiAssetFilter {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for AssetFilter {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
match self {
|
||||
Self::Definite(assets) => weight.saturating_mul(assets.inner().iter().count() as u64),
|
||||
Self::Wild(asset) => match asset {
|
||||
@@ -51,40 +51,36 @@ impl WeighMultiAssets for MultiAssetFilter {
|
||||
}
|
||||
}
|
||||
|
||||
impl WeighMultiAssets for MultiAssets {
|
||||
fn weigh_multi_assets(&self, weight: Weight) -> Weight {
|
||||
impl WeighAssets for Assets {
|
||||
fn weigh_assets(&self, weight: Weight) -> Weight {
|
||||
weight.saturating_mul(self.inner().iter().count() as u64)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BridgeHubWestendXcmWeight<Call>(core::marker::PhantomData<Call>);
|
||||
impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
fn withdraw_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
fn withdraw_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::withdraw_asset())
|
||||
}
|
||||
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
fn reserve_asset_deposited(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::reserve_asset_deposited())
|
||||
}
|
||||
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
fn receive_teleported_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::receive_teleported_asset())
|
||||
}
|
||||
fn query_response(
|
||||
_query_id: &u64,
|
||||
_response: &Response,
|
||||
_max_weight: &Weight,
|
||||
_querier: &Option<MultiLocation>,
|
||||
_querier: &Option<Location>,
|
||||
) -> Weight {
|
||||
XcmGeneric::<Runtime>::query_response()
|
||||
}
|
||||
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
fn transfer_asset(assets: &Assets, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_asset())
|
||||
}
|
||||
fn transfer_reserve_asset(
|
||||
assets: &MultiAssets,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
fn transfer_reserve_asset(assets: &Assets, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::transfer_reserve_asset())
|
||||
}
|
||||
fn transact(
|
||||
_origin_type: &OriginKind,
|
||||
@@ -112,44 +108,36 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
fn clear_origin() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_origin()
|
||||
}
|
||||
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
|
||||
fn descend_origin(_who: &InteriorLocation) -> Weight {
|
||||
XcmGeneric::<Runtime>::descend_origin()
|
||||
}
|
||||
fn report_error(_query_response_info: &QueryResponseInfo) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_error()
|
||||
}
|
||||
|
||||
fn deposit_asset(assets: &MultiAssetFilter, _dest: &MultiLocation) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
fn deposit_asset(assets: &AssetFilter, _dest: &Location) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_asset())
|
||||
}
|
||||
fn deposit_reserve_asset(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
fn deposit_reserve_asset(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::deposit_reserve_asset())
|
||||
}
|
||||
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets, _maximal: &bool) -> Weight {
|
||||
fn exchange_asset(_give: &AssetFilter, _receive: &Assets, _maximal: &bool) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn initiate_reserve_withdraw(
|
||||
assets: &MultiAssetFilter,
|
||||
_reserve: &MultiLocation,
|
||||
assets: &AssetFilter,
|
||||
_reserve: &Location,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_reserve_withdraw())
|
||||
}
|
||||
fn initiate_teleport(
|
||||
assets: &MultiAssetFilter,
|
||||
_dest: &MultiLocation,
|
||||
_xcm: &Xcm<()>,
|
||||
) -> Weight {
|
||||
assets.weigh_multi_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
fn initiate_teleport(assets: &AssetFilter, _dest: &Location, _xcm: &Xcm<()>) -> Weight {
|
||||
assets.weigh_assets(XcmFungibleWeight::<Runtime>::initiate_teleport())
|
||||
}
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &MultiAssetFilter) -> Weight {
|
||||
fn report_holding(_response_info: &QueryResponseInfo, _assets: &AssetFilter) -> Weight {
|
||||
XcmGeneric::<Runtime>::report_holding()
|
||||
}
|
||||
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
|
||||
fn buy_execution(_fees: &Asset, _weight_limit: &WeightLimit) -> Weight {
|
||||
XcmGeneric::<Runtime>::buy_execution()
|
||||
}
|
||||
fn refund_surplus() -> Weight {
|
||||
@@ -164,7 +152,7 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
fn clear_error() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_error()
|
||||
}
|
||||
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
|
||||
fn claim_asset(_assets: &Assets, _ticket: &Location) -> Weight {
|
||||
XcmGeneric::<Runtime>::claim_asset()
|
||||
}
|
||||
fn trap(_code: &u64) -> Weight {
|
||||
@@ -176,13 +164,13 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
fn unsubscribe_version() -> Weight {
|
||||
XcmGeneric::<Runtime>::unsubscribe_version()
|
||||
}
|
||||
fn burn_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
fn burn_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::burn_asset())
|
||||
}
|
||||
fn expect_asset(assets: &MultiAssets) -> Weight {
|
||||
assets.weigh_multi_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
fn expect_asset(assets: &Assets) -> Weight {
|
||||
assets.weigh_assets(XcmGeneric::<Runtime>::expect_asset())
|
||||
}
|
||||
fn expect_origin(_origin: &Option<MultiLocation>) -> Weight {
|
||||
fn expect_origin(_origin: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::expect_origin()
|
||||
}
|
||||
fn expect_error(_error: &Option<(u32, XcmError)>) -> Weight {
|
||||
@@ -216,16 +204,16 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
let inner_encoded_len = inner.encode().len() as u32;
|
||||
XcmGeneric::<Runtime>::export_message(inner_encoded_len)
|
||||
}
|
||||
fn lock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn lock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn unlock_asset(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn unlock_asset(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn note_unlockable(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn note_unlockable(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn request_unlock(_: &MultiAsset, _: &MultiLocation) -> Weight {
|
||||
fn request_unlock(_: &Asset, _: &Location) -> Weight {
|
||||
Weight::MAX
|
||||
}
|
||||
fn set_fees_mode(_: &bool) -> Weight {
|
||||
@@ -237,11 +225,11 @@ impl<Call> XcmWeightInfo<Call> for BridgeHubWestendXcmWeight<Call> {
|
||||
fn clear_topic() -> Weight {
|
||||
XcmGeneric::<Runtime>::clear_topic()
|
||||
}
|
||||
fn alias_origin(_: &MultiLocation) -> Weight {
|
||||
fn alias_origin(_: &Location) -> Weight {
|
||||
// XCM Executor does not currently support alias origin operations
|
||||
Weight::MAX
|
||||
}
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<MultiLocation>) -> Weight {
|
||||
fn unpaid_execution(_: &WeightLimit, _: &Option<Location>) -> Weight {
|
||||
XcmGeneric::<Runtime>::unpaid_execution()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ use super::{
|
||||
};
|
||||
use crate::bridge_common_config::{DeliveryRewardInBalance, RequiredStakeForStakeAndSlash};
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Equals, Everything, Nothing},
|
||||
};
|
||||
use frame_system::EnsureRoot;
|
||||
@@ -52,18 +52,18 @@ use xcm_builder::{
|
||||
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const WestendLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const WestendLocation: Location = Location::parent();
|
||||
pub const RelayNetwork: NetworkId = NetworkId::Westend;
|
||||
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 const MaxInstructions: u32 = 100;
|
||||
pub const MaxAssetsIntoHolding: u32 = 64;
|
||||
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
|
||||
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_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 = (
|
||||
@@ -82,7 +82,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<WestendLocation>,
|
||||
// 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,
|
||||
@@ -114,11 +114,11 @@ pub type XcmOriginToTransactDispatchOrigin = (
|
||||
XcmPassthrough<RuntimeOrigin>,
|
||||
);
|
||||
|
||||
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
|
||||
@@ -270,7 +270,7 @@ impl xcm_executor::Config for XcmConfig {
|
||||
pub type PriceForParentDelivery =
|
||||
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;
|
||||
|
||||
/// 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>;
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() {
|
||||
_ => None,
|
||||
}
|
||||
}),
|
||||
|| ExportMessage { network: Rococo, destination: X1(Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into())), xcm: Xcm(vec![]) },
|
||||
|| ExportMessage { network: Rococo, destination: [Parachain(bridge_to_rococo_config::AssetHubRococoParaId::get().into())].into(), xcm: Xcm(vec![]) },
|
||||
XCM_LANE_FOR_ASSET_HUB_WESTEND_TO_ASSET_HUB_ROCOCO,
|
||||
Some((WestendLocation::get(), ExistentialDeposit::get()).into()),
|
||||
// value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer`
|
||||
|
||||
@@ -23,7 +23,7 @@ use pallet_message_queue::OnQueueChanged;
|
||||
use scale_info::TypeInfo;
|
||||
use snowbridge_core::ChannelId;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
use xcm::v3::{Junction, MultiLocation};
|
||||
use xcm::v4::{Junction, Location};
|
||||
|
||||
/// The aggregate origin of an inbound message.
|
||||
/// This is specialized for BridgeHub, as the snowbridge-outbound-queue-pallet is also using
|
||||
@@ -46,16 +46,16 @@ pub enum AggregateMessageOrigin {
|
||||
Snowbridge(ChannelId),
|
||||
}
|
||||
|
||||
impl From<AggregateMessageOrigin> for MultiLocation {
|
||||
impl From<AggregateMessageOrigin> for Location {
|
||||
fn from(origin: AggregateMessageOrigin) -> Self {
|
||||
use AggregateMessageOrigin::*;
|
||||
match origin {
|
||||
Here => MultiLocation::here(),
|
||||
Parent => MultiLocation::parent(),
|
||||
Sibling(id) => MultiLocation::new(1, Junction::Parachain(id.into())),
|
||||
Here => Location::here(),
|
||||
Parent => Location::parent(),
|
||||
Sibling(id) => Location::new(1, Junction::Parachain(id.into())),
|
||||
// NOTE: We don't need this conversion for Snowbridge. However we have to
|
||||
// implement it anyway as xcm_builder::ProcessXcmMessage requires it.
|
||||
Snowbridge(_) => MultiLocation::default(),
|
||||
Snowbridge(_) => Location::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -336,9 +336,9 @@ where
|
||||
(),
|
||||
>(
|
||||
LaneId::default(),
|
||||
vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
vec![Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
1,
|
||||
X2(GlobalConsensus(Polkadot), Parachain(1_000)),
|
||||
[GlobalConsensus(Polkadot), Parachain(1_000)].into(),
|
||||
1u32.into(),
|
||||
);
|
||||
|
||||
|
||||
@@ -418,9 +418,9 @@ where
|
||||
(),
|
||||
>(
|
||||
LaneId::default(),
|
||||
vec![xcm::v3::Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
vec![Instruction::<()>::ClearOrigin; 1_024].into(),
|
||||
1,
|
||||
X2(GlobalConsensus(Polkadot), Parachain(1_000)),
|
||||
[GlobalConsensus(Polkadot), Parachain(1_000)].into(),
|
||||
1,
|
||||
5,
|
||||
1_000,
|
||||
|
||||
@@ -230,7 +230,7 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
|
||||
prepare_message_proof_import: impl FnOnce(
|
||||
Runtime::AccountId,
|
||||
Runtime::InboundRelayer,
|
||||
InteriorMultiLocation,
|
||||
InteriorLocation,
|
||||
MessageNonce,
|
||||
Xcm<()>,
|
||||
) -> CallsAndVerifiers<Runtime>,
|
||||
@@ -276,21 +276,21 @@ pub fn relayed_incoming_message_works<Runtime, AllPalletsWithoutSystem, MPI>(
|
||||
|
||||
// set up relayer details and proofs
|
||||
|
||||
let message_destination =
|
||||
X2(GlobalConsensus(local_relay_chain_id), Parachain(sibling_parachain_id));
|
||||
let message_destination: InteriorLocation =
|
||||
[GlobalConsensus(local_relay_chain_id), Parachain(sibling_parachain_id)].into();
|
||||
// some random numbers (checked by test)
|
||||
let message_nonce = 1;
|
||||
|
||||
let xcm = vec![xcm::v3::Instruction::<()>::ClearOrigin; 42];
|
||||
let xcm = vec![Instruction::<()>::ClearOrigin; 42];
|
||||
let expected_dispatch = xcm::latest::Xcm::<()>({
|
||||
let mut expected_instructions = xcm.clone();
|
||||
// dispatch prepends bridge pallet instance
|
||||
expected_instructions.insert(
|
||||
0,
|
||||
DescendOrigin(X1(PalletInstance(
|
||||
DescendOrigin([PalletInstance(
|
||||
<pallet_bridge_messages::Pallet<Runtime, MPI> as PalletInfoAccess>::index()
|
||||
as u8,
|
||||
))),
|
||||
)].into()),
|
||||
);
|
||||
expected_instructions
|
||||
});
|
||||
|
||||
@@ -319,8 +319,8 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
>,
|
||||
export_message_instruction: fn() -> Instruction<XcmConfig::RuntimeCall>,
|
||||
expected_lane_id: LaneId,
|
||||
existential_deposit: Option<MultiAsset>,
|
||||
maybe_paid_export_message: Option<MultiAsset>,
|
||||
existential_deposit: Option<Asset>,
|
||||
maybe_paid_export_message: Option<Asset>,
|
||||
prepare_configuration: impl Fn(),
|
||||
) where
|
||||
Runtime: BasicParachainRuntime + BridgeMessagesConfig<MessagesPalletInstance>,
|
||||
@@ -328,7 +328,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
MessagesPalletInstance: 'static,
|
||||
{
|
||||
assert_ne!(runtime_para_id, sibling_parachain_id);
|
||||
let sibling_parachain_location = MultiLocation::new(1, Parachain(sibling_parachain_id));
|
||||
let sibling_parachain_location = Location::new(1, [Parachain(sibling_parachain_id)]);
|
||||
|
||||
run_test::<Runtime, _>(collator_session_key, runtime_para_id, vec![], || {
|
||||
prepare_configuration();
|
||||
@@ -361,7 +361,7 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
.expect("deposited fee");
|
||||
|
||||
Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(vec![fee.clone()])),
|
||||
WithdrawAsset(Assets::from(vec![fee.clone()])),
|
||||
BuyExecution { fees: fee, weight_limit: Unlimited },
|
||||
export_message_instruction(),
|
||||
])
|
||||
@@ -373,12 +373,13 @@ pub fn handle_export_message_from_system_parachain_to_outbound_queue_works<
|
||||
};
|
||||
|
||||
// execute XCM
|
||||
let hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
assert_ok!(XcmExecutor::<XcmConfig>::execute_xcm(
|
||||
let mut hash = xcm.using_encoded(sp_io::hashing::blake2_256);
|
||||
assert_ok!(XcmExecutor::<XcmConfig>::prepare_and_execute(
|
||||
sibling_parachain_location,
|
||||
xcm,
|
||||
hash,
|
||||
&mut hash,
|
||||
RuntimeHelper::<Runtime>::xcm_max_weight(XcmReceivedFrom::Sibling),
|
||||
Weight::zero(),
|
||||
)
|
||||
.ensure_complete());
|
||||
|
||||
@@ -446,9 +447,9 @@ pub fn message_dispatch_routing_works<
|
||||
NetworkDistanceAsParentCount: Get<u8>,
|
||||
{
|
||||
struct NetworkWithParentCount<N, C>(core::marker::PhantomData<(N, C)>);
|
||||
impl<N: Get<NetworkId>, C: Get<u8>> Get<MultiLocation> for NetworkWithParentCount<N, C> {
|
||||
fn get() -> MultiLocation {
|
||||
MultiLocation { parents: C::get(), interior: X1(GlobalConsensus(N::get())) }
|
||||
impl<N: Get<NetworkId>, C: Get<u8>> Get<Location> for NetworkWithParentCount<N, C> {
|
||||
fn get() -> Location {
|
||||
Location::new(C::get(), [GlobalConsensus(N::get())])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -495,7 +496,7 @@ pub fn message_dispatch_routing_works<
|
||||
BridgedNetwork,
|
||||
NetworkWithParentCount<RuntimeNetwork, NetworkDistanceAsParentCount>,
|
||||
AlwaysLatest,
|
||||
>((RuntimeNetwork::get(), X1(Parachain(sibling_parachain_id))));
|
||||
>((RuntimeNetwork::get(), [Parachain(sibling_parachain_id)].into()));
|
||||
|
||||
// 2.1. WITHOUT opened hrmp channel -> RoutingError
|
||||
let result =
|
||||
@@ -565,52 +566,43 @@ where
|
||||
{
|
||||
// data here are not relevant for weighing
|
||||
let mut xcm = Xcm(vec![
|
||||
WithdrawAsset(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
WithdrawAsset(Assets::from(vec![Asset {
|
||||
id: AssetId(Location::new(1, [])),
|
||||
fun: Fungible(34333299),
|
||||
}])),
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation { parents: 1, interior: Here }),
|
||||
fun: Fungible(34333299),
|
||||
},
|
||||
fees: Asset { id: AssetId(Location::new(1, [])), fun: Fungible(34333299) },
|
||||
weight_limit: Unlimited,
|
||||
},
|
||||
ExportMessage {
|
||||
network: Polkadot,
|
||||
destination: X1(Parachain(1000)),
|
||||
destination: [Parachain(1000)].into(),
|
||||
xcm: Xcm(vec![
|
||||
ReserveAssetDeposited(MultiAssets::from(vec![MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Kusama)),
|
||||
}),
|
||||
ReserveAssetDeposited(Assets::from(vec![Asset {
|
||||
id: AssetId(Location::new(2, [GlobalConsensus(Kusama)])),
|
||||
fun: Fungible(1000000000000),
|
||||
}])),
|
||||
ClearOrigin,
|
||||
BuyExecution {
|
||||
fees: MultiAsset {
|
||||
id: Concrete(MultiLocation {
|
||||
parents: 2,
|
||||
interior: X1(GlobalConsensus(Kusama)),
|
||||
}),
|
||||
fees: Asset {
|
||||
id: AssetId(Location::new(2, [GlobalConsensus(Kusama)])),
|
||||
fun: Fungible(1000000000000),
|
||||
},
|
||||
weight_limit: Unlimited,
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(AllCounted(1)),
|
||||
beneficiary: MultiLocation {
|
||||
parents: 0,
|
||||
interior: X1(xcm::latest::prelude::AccountId32 {
|
||||
beneficiary: Location::new(
|
||||
0,
|
||||
[xcm::latest::prelude::AccountId32 {
|
||||
network: None,
|
||||
id: [
|
||||
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159,
|
||||
214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165,
|
||||
109, 162, 125,
|
||||
],
|
||||
}),
|
||||
},
|
||||
}],
|
||||
),
|
||||
},
|
||||
SetTopic([
|
||||
116, 82, 194, 132, 171, 114, 217, 165, 23, 37, 161, 177, 165, 179, 247, 114,
|
||||
@@ -618,10 +610,7 @@ where
|
||||
]),
|
||||
]),
|
||||
},
|
||||
DepositAsset {
|
||||
assets: Wild(All),
|
||||
beneficiary: MultiLocation { parents: 1, interior: X1(Parachain(1000)) },
|
||||
},
|
||||
DepositAsset { assets: Wild(All), beneficiary: Location::new(1, [Parachain(1000)]) },
|
||||
SetTopic([
|
||||
36, 224, 250, 165, 82, 195, 67, 110, 160, 170, 140, 87, 217, 62, 201, 164, 42, 98, 219,
|
||||
157, 124, 105, 248, 25, 131, 218, 199, 36, 109, 173, 100, 122,
|
||||
|
||||
@@ -37,10 +37,10 @@ use xcm_executor::traits::{validate_export, ExportXcm};
|
||||
|
||||
pub fn prepare_inbound_xcm<InnerXcmRuntimeCall>(
|
||||
xcm_message: Xcm<InnerXcmRuntimeCall>,
|
||||
destination: InteriorMultiLocation,
|
||||
destination: InteriorLocation,
|
||||
) -> Vec<u8> {
|
||||
let location = xcm::VersionedInteriorMultiLocation::V3(destination);
|
||||
let xcm = xcm::VersionedXcm::<InnerXcmRuntimeCall>::V3(xcm_message);
|
||||
let location = xcm::VersionedInteriorLocation::V4(destination);
|
||||
let xcm = xcm::VersionedXcm::<InnerXcmRuntimeCall>::V4(xcm_message);
|
||||
// this is the `BridgeMessage` from polkadot xcm builder, but it has no constructor
|
||||
// or public fields, so just tuple
|
||||
// (double encoding, because `.encode()` is called on original Xcm BLOB when it is pushed
|
||||
@@ -101,7 +101,7 @@ macro_rules! grab_haul_blob (
|
||||
/// which are transferred over bridge.
|
||||
pub(crate) fn simulate_message_exporter_on_bridged_chain<
|
||||
SourceNetwork: Get<NetworkId>,
|
||||
DestinationNetwork: Get<MultiLocation>,
|
||||
DestinationNetwork: Get<Location>,
|
||||
DestinationVersion: GetVersion,
|
||||
>(
|
||||
(destination_network, destination_junctions): (NetworkId, Junctions),
|
||||
@@ -109,8 +109,8 @@ pub(crate) fn simulate_message_exporter_on_bridged_chain<
|
||||
grab_haul_blob!(GrabbingHaulBlob, GRABBED_HAUL_BLOB_PAYLOAD);
|
||||
|
||||
// lets pretend that some parachain on bridged chain exported the message
|
||||
let universal_source_on_bridged_chain =
|
||||
X2(GlobalConsensus(SourceNetwork::get()), Parachain(5678));
|
||||
let universal_source_on_bridged_chain: Junctions =
|
||||
[GlobalConsensus(SourceNetwork::get()), Parachain(5678)].into();
|
||||
let channel = 1_u32;
|
||||
|
||||
// simulate XCM message export
|
||||
|
||||
@@ -215,7 +215,7 @@ pub type AmbassadorSalaryInstance = pallet_salary::Instance2;
|
||||
parameter_types! {
|
||||
// The interior location on AssetHub for the paying account. This is the Ambassador Salary
|
||||
// pallet instance (which sits at index 74). This sovereign account will need funding.
|
||||
pub AmbassadorSalaryLocation: InteriorMultiLocation = PalletInstance(74).into();
|
||||
pub AmbassadorSalaryLocation: InteriorLocation = PalletInstance(74).into();
|
||||
}
|
||||
|
||||
/// [`PayOverXcm`] setup to pay the Ambassador salary on the AssetHub in WND.
|
||||
|
||||
@@ -43,7 +43,7 @@ use parachains_common::{
|
||||
westend::{account, currency::GRAND},
|
||||
};
|
||||
use polkadot_runtime_common::impls::{
|
||||
LocatableAssetConverter, VersionedLocatableAsset, VersionedMultiLocationConverter,
|
||||
LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter,
|
||||
};
|
||||
use sp_arithmetic::Permill;
|
||||
use sp_core::{ConstU128, ConstU32};
|
||||
@@ -202,7 +202,7 @@ pub type FellowshipSalaryInstance = pallet_salary::Instance1;
|
||||
parameter_types! {
|
||||
// The interior location on AssetHub for the paying account. This is the Fellowship Salary
|
||||
// pallet instance (which sits at index 64). This sovereign account will need funding.
|
||||
pub Interior: InteriorMultiLocation = PalletInstance(64).into();
|
||||
pub Interior: InteriorLocation = PalletInstance(64).into();
|
||||
}
|
||||
|
||||
const USDT_UNITS: u128 = 1_000_000;
|
||||
@@ -250,7 +250,7 @@ parameter_types! {
|
||||
pub const MaxBalance: Balance = Balance::max_value();
|
||||
// The asset's interior location for the paying account. This is the Fellowship Treasury
|
||||
// pallet instance (which sits at index 65).
|
||||
pub FellowshipTreasuryInteriorLocation: InteriorMultiLocation = PalletInstance(65).into();
|
||||
pub FellowshipTreasuryInteriorLocation: InteriorLocation = PalletInstance(65).into();
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
@@ -269,10 +269,10 @@ pub type FellowshipTreasuryPaymaster = PayOverXcm<
|
||||
crate::xcm_config::XcmRouter,
|
||||
crate::PolkadotXcm,
|
||||
ConstU32<{ 6 * HOURS }>,
|
||||
VersionedMultiLocation,
|
||||
VersionedLocation,
|
||||
VersionedLocatableAsset,
|
||||
LocatableAssetConverter,
|
||||
VersionedMultiLocationConverter,
|
||||
VersionedLocationConverter,
|
||||
>;
|
||||
|
||||
pub type FellowshipTreasuryInstance = pallet_treasury::Instance1;
|
||||
@@ -327,7 +327,7 @@ impl pallet_treasury::Config<FellowshipTreasuryInstance> for Runtime {
|
||||
>,
|
||||
>;
|
||||
type AssetKind = VersionedLocatableAsset;
|
||||
type Beneficiary = VersionedMultiLocation;
|
||||
type Beneficiary = VersionedLocation;
|
||||
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
type Paymaster = FellowshipTreasuryPaymaster;
|
||||
|
||||
@@ -427,7 +427,7 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}
|
||||
|
||||
parameter_types! {
|
||||
/// The asset ID for the asset that we use to pay for message delivery fees.
|
||||
pub FeeAssetId: AssetId = Concrete(xcm_config::WndLocation::get());
|
||||
pub FeeAssetId: AssetId = AssetId(xcm_config::WndLocation::get());
|
||||
/// The base fee for the message delivery fees.
|
||||
pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3);
|
||||
}
|
||||
@@ -974,28 +974,28 @@ impl_runtime_apis! {
|
||||
|
||||
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsicsBenchmark;
|
||||
impl pallet_xcm::benchmarking::Config for Runtime {
|
||||
fn reachable_dest() -> Option<MultiLocation> {
|
||||
fn reachable_dest() -> Option<Location> {
|
||||
Some(Parent.into())
|
||||
}
|
||||
|
||||
fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn teleportable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Relay/native token can be teleported between Collectives and Relay.
|
||||
Some((
|
||||
MultiAsset {
|
||||
Asset {
|
||||
fun: Fungible(EXISTENTIAL_DEPOSIT),
|
||||
id: Concrete(Parent.into())
|
||||
id: AssetId(Parent.into())
|
||||
}.into(),
|
||||
Parent.into(),
|
||||
))
|
||||
}
|
||||
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
|
||||
fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> {
|
||||
// Reserve transfers are disabled on Collectives.
|
||||
None
|
||||
}
|
||||
|
||||
fn set_up_complex_asset_transfer(
|
||||
) -> Option<(MultiAssets, u32, MultiLocation, Box<dyn FnOnce()>)> {
|
||||
) -> Option<(Assets, u32, Location, Box<dyn FnOnce()>)> {
|
||||
// Collectives only supports teleports to system parachain.
|
||||
// Relay/native token can be teleported between Collectives and Relay.
|
||||
let native_location = Parent.into();
|
||||
|
||||
@@ -19,7 +19,7 @@ use super::{
|
||||
TransactionByteFee, WeightToFee, WestendTreasuryAccount, XcmpQueue,
|
||||
};
|
||||
use frame_support::{
|
||||
match_types, parameter_types,
|
||||
parameter_types,
|
||||
traits::{ConstU32, Contains, Equals, Everything, Nothing},
|
||||
weights::Weight,
|
||||
};
|
||||
@@ -51,17 +51,17 @@ use xcm_builder::{
|
||||
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};
|
||||
|
||||
parameter_types! {
|
||||
pub const WndLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const WndLocation: Location = Location::parent();
|
||||
pub const RelayNetwork: Option<NetworkId> = Some(NetworkId::Westend);
|
||||
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
|
||||
pub UniversalLocation: InteriorMultiLocation =
|
||||
X2(GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into()));
|
||||
pub RelayTreasuryLocation: MultiLocation = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub UniversalLocation: InteriorLocation =
|
||||
[GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into();
|
||||
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(westend_runtime_constants::TREASURY_PALLET_ID)).into();
|
||||
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
|
||||
pub const GovernanceLocation: MultiLocation = MultiLocation::parent();
|
||||
pub const GovernanceLocation: Location = Location::parent();
|
||||
pub const FellowshipAdminBodyId: BodyId = BodyId::Index(xcm_constants::body::FELLOWSHIP_ADMIN_INDEX);
|
||||
pub AssetHub: Location = (Parent, Parachain(1000)).into();
|
||||
pub const TreasurerBodyId: BodyId = BodyId::Index(xcm_constants::body::TREASURER_INDEX);
|
||||
pub AssetHub: MultiLocation = (Parent, Parachain(1000)).into();
|
||||
pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into();
|
||||
pub UsdtAssetHub: LocatableAssetId = LocatableAssetId {
|
||||
location: AssetHub::get(),
|
||||
@@ -73,7 +73,7 @@ parameter_types! {
|
||||
};
|
||||
}
|
||||
|
||||
/// 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 = (
|
||||
@@ -92,7 +92,7 @@ pub type CurrencyTransactor = CurrencyAdapter<
|
||||
Balances,
|
||||
// Use this currency when it is a fungible asset matching the given location or name:
|
||||
IsConcrete<WndLocation>,
|
||||
// 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,
|
||||
@@ -136,11 +136,11 @@ parameter_types! {
|
||||
pub const FellowsBodyId: BodyId = BodyId::Technical;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -292,7 +292,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>;
|
||||
|
||||
@@ -310,10 +310,10 @@ pub type XcmRouter = WithUniqueTopic<(
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
parameter_types! {
|
||||
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
|
||||
pub ReachableDest: Option<Location> = Some(Parent.into());
|
||||
}
|
||||
|
||||
/// Type to convert the Fellows origin to a Plurality `MultiLocation` value.
|
||||
/// Type to convert the Fellows origin to a Plurality `Location` value.
|
||||
pub type FellowsToPlurality = OriginToPluralityVoice<RuntimeOrigin, Fellows, FellowsBodyId>;
|
||||
|
||||
impl pallet_xcm::Config for Runtime {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user