mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 07:31:02 +00:00
Remove xcm::v3 from assets-common nits (#4037)
This PR mainly removes `xcm::v3` stuff from `assets-common` to make it
more generic and facilitate the transition to newer XCM versions. Some
of the implementations here used hard-coded `xcm::v3::Location`, but now
it's up to the runtime to configure according to its needs.
Additional/consequent changes:
- `penpal` runtime uses now `xcm::latest::Location` for `pallet_assets`
as `AssetId`, because we don't care about migrations here
- it pretty much simplify xcm-emulator integration tests, where we don't
need now a lots of boilerplate conversions:
```
v3::Location::try_from(...).expect("conversion works")`
```
- xcm-emulator tests
- split macro `impl_assets_helpers_for_parachain` to the
`impl_assets_helpers_for_parachain` and
`impl_foreign_assets_helpers_for_parachain` (avoids using hard-coded
`xcm::v3::Location`)
This commit is contained in:
@@ -316,7 +316,7 @@ pub type LocalAndForeignAssets = fungibles::UnionOf<
|
||||
Assets,
|
||||
ForeignAssets,
|
||||
LocalFromLeft<
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3>,
|
||||
AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocationV3, xcm::v3::Location>,
|
||||
AssetIdForTrustBackedAssets,
|
||||
xcm::v3::Location,
|
||||
>,
|
||||
|
||||
@@ -82,8 +82,6 @@ parameter_types! {
|
||||
PalletInstance(<PoolAssets as PalletInfoAccess>::index() as u8).into();
|
||||
pub UniquesPalletLocation: Location =
|
||||
PalletInstance(<Uniques 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();
|
||||
@@ -179,6 +177,7 @@ pub type ForeignAssetsConvertedConcreteId = assets_common::ForeignAssetsConverte
|
||||
StartsWithExplicitGlobalConsensus<UniversalLocationNetworkId>,
|
||||
),
|
||||
Balance,
|
||||
xcm::v3::Location,
|
||||
>;
|
||||
|
||||
/// Means for transacting foreign assets from different global consensus.
|
||||
@@ -581,7 +580,11 @@ impl xcm_executor::Config for XcmConfig {
|
||||
WeightToFee,
|
||||
crate::NativeAndAssets,
|
||||
(
|
||||
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance>,
|
||||
TrustBackedAssetsAsLocation<
|
||||
TrustBackedAssetsPalletLocation,
|
||||
Balance,
|
||||
xcm::v3::Location,
|
||||
>,
|
||||
ForeignAssetsConvertedConcreteId,
|
||||
),
|
||||
ResolveAssetTo<StakingPot, crate::NativeAndAssets>,
|
||||
|
||||
@@ -22,8 +22,7 @@ use asset_hub_rococo_runtime::{
|
||||
xcm_config::{
|
||||
bridging, AssetFeeAsExistentialDepositMultiplierFeeCharger, CheckingAccount,
|
||||
ForeignAssetFeeAsExistentialDepositMultiplierFeeCharger, ForeignCreatorsSovereignAccountOf,
|
||||
LocationToAccountId, StakingPot, TokenLocation, TokenLocationV3,
|
||||
TrustBackedAssetsPalletLocation, TrustBackedAssetsPalletLocationV3, XcmConfig,
|
||||
LocationToAccountId, StakingPot, TokenLocation, TrustBackedAssetsPalletLocation, XcmConfig,
|
||||
},
|
||||
AllPalletsWithoutSystem, AssetConversion, AssetDeposit, Assets, Balances, CollatorSelection,
|
||||
ExistentialDeposit, ForeignAssets, ForeignAssetsInstance, MetadataDepositBase,
|
||||
@@ -53,17 +52,14 @@ use sp_std::ops::Mul;
|
||||
use std::convert::Into;
|
||||
use testnet_parachains_constants::rococo::{consensus::*, currency::UNITS, fee::WeightToFee};
|
||||
use xcm::latest::prelude::{Assets as XcmAssets, *};
|
||||
use xcm_builder::V4V3LocationConverter;
|
||||
use xcm_builder::WithLatestLocationConverter;
|
||||
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<TrustBackedAssetsPalletLocationV3>;
|
||||
|
||||
type AssetIdForTrustBackedAssetsConvertLatest =
|
||||
assets_common::AssetIdForTrustBackedAssetsConvertLatest<TrustBackedAssetsPalletLocation>;
|
||||
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
|
||||
|
||||
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
|
||||
|
||||
@@ -204,7 +200,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 = TokenLocationV3::get();
|
||||
let native_location = TokenLocation::get();
|
||||
let asset_1_location =
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&asset_1).unwrap();
|
||||
// bob's initial balance for native and `asset1` assets.
|
||||
@@ -221,14 +217,24 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
|
||||
|
||||
assert_ok!(AssetConversion::create_pool(
|
||||
RuntimeHelper::origin_of(bob.clone()),
|
||||
Box::new(native_location),
|
||||
Box::new(asset_1_location)
|
||||
Box::new(
|
||||
xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
|
||||
),
|
||||
Box::new(
|
||||
xcm::v3::Location::try_from(asset_1_location.clone())
|
||||
.expect("conversion works")
|
||||
)
|
||||
));
|
||||
|
||||
assert_ok!(AssetConversion::add_liquidity(
|
||||
RuntimeHelper::origin_of(bob.clone()),
|
||||
Box::new(native_location),
|
||||
Box::new(asset_1_location),
|
||||
Box::new(
|
||||
xcm::v3::Location::try_from(native_location.clone()).expect("conversion works")
|
||||
),
|
||||
Box::new(
|
||||
xcm::v3::Location::try_from(asset_1_location.clone())
|
||||
.expect("conversion works")
|
||||
),
|
||||
pool_liquidity,
|
||||
pool_liquidity,
|
||||
1,
|
||||
@@ -240,8 +246,6 @@ 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);
|
||||
@@ -249,7 +253,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: Asset = (asset_1_location_latest.clone(), asset_fee + extra_amount).into();
|
||||
let payment: Asset = (asset_1_location.clone(), asset_fee + extra_amount).into();
|
||||
|
||||
// init trader and buy weight.
|
||||
let mut trader = <XcmConfig as xcm_executor::Config>::Trader::new();
|
||||
@@ -257,24 +261,25 @@ 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_latest.clone().into())
|
||||
.map_or(0, |a| *a);
|
||||
let unused_amount =
|
||||
unused_asset.fungible.get(&asset_1_location.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);
|
||||
|
||||
// prepare input to refund weight.
|
||||
let refund_weight = Weight::from_parts(1_000_000_000, 0);
|
||||
let refund = WeightToFee::weight_to_fee(&refund_weight);
|
||||
let (reserve1, reserve2) =
|
||||
AssetConversion::get_reserves(native_location, asset_1_location).unwrap();
|
||||
let (reserve1, reserve2) = AssetConversion::get_reserves(
|
||||
xcm::v3::Location::try_from(native_location).expect("conversion works"),
|
||||
xcm::v3::Location::try_from(asset_1_location.clone()).expect("conversion works"),
|
||||
)
|
||||
.unwrap();
|
||||
let asset_refund =
|
||||
AssetConversion::get_amount_out(&refund, &reserve1, &reserve2).unwrap();
|
||||
|
||||
// refund.
|
||||
let actual_refund = trader.refund_weight(refund_weight, &ctx).unwrap();
|
||||
assert_eq!(actual_refund, (asset_1_location_latest, asset_refund).into());
|
||||
assert_eq!(actual_refund, (asset_1_location, asset_refund).into());
|
||||
|
||||
// assert.
|
||||
assert_eq!(Balances::balance(&staking_pot), initial_balance);
|
||||
@@ -303,7 +308,8 @@ 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 = TokenLocationV3::get();
|
||||
let native_location =
|
||||
xcm::v3::Location::try_from(TokenLocation::get()).expect("conversion works");
|
||||
let foreign_location = xcm::v3::Location {
|
||||
parents: 1,
|
||||
interior: (
|
||||
@@ -435,7 +441,7 @@ fn test_asset_xcm_take_first_trader() {
|
||||
|
||||
// get asset id as location
|
||||
let asset_location =
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap();
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap();
|
||||
|
||||
// Set Alice as block author, who will receive fees
|
||||
RuntimeHelper::run_to_block(2, AccountId::from(ALICE));
|
||||
@@ -603,9 +609,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
|
||||
|
||||
// We are going to buy 4e9 weight
|
||||
let bought = Weight::from_parts(4_000_000_000u64, 0);
|
||||
|
||||
let asset_location =
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
|
||||
let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
|
||||
|
||||
// lets calculate amount needed
|
||||
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
||||
@@ -623,7 +627,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
|
||||
// We actually use half of the weight
|
||||
let weight_used = bought / 2;
|
||||
|
||||
// Make sure refurnd works.
|
||||
// Make sure refund works.
|
||||
let amount_refunded = WeightToFee::weight_to_fee(&(bought - weight_used));
|
||||
|
||||
assert_eq!(
|
||||
@@ -677,8 +681,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e
|
||||
// We are going to buy small amount
|
||||
let bought = Weight::from_parts(500_000_000u64, 0);
|
||||
|
||||
let asset_location =
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
|
||||
let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
|
||||
|
||||
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
||||
|
||||
@@ -730,8 +733,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() {
|
||||
// We are gonna buy ED
|
||||
let bought = Weight::from_parts(ExistentialDeposit::get().try_into().unwrap(), 0);
|
||||
|
||||
let asset_location =
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
|
||||
let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
|
||||
|
||||
let amount_bought = WeightToFee::weight_to_fee(&bought);
|
||||
|
||||
@@ -807,8 +809,7 @@ fn test_asset_xcm_trader_not_possible_for_non_sufficient_assets() {
|
||||
// lets calculate amount needed
|
||||
let asset_amount_needed = WeightToFee::weight_to_fee(&bought);
|
||||
|
||||
let asset_location =
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&1).unwrap();
|
||||
let asset_location = AssetIdForTrustBackedAssetsConvert::convert_back(&1).unwrap();
|
||||
|
||||
let asset: Asset = (asset_location, asset_amount_needed).into();
|
||||
|
||||
@@ -925,13 +926,16 @@ fn test_assets_balances_api_works() {
|
||||
)));
|
||||
// check trusted asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
AssetIdForTrustBackedAssetsConvertLatest::convert_back(&local_asset_id).unwrap(),
|
||||
AssetIdForTrustBackedAssetsConvert::convert_back(&local_asset_id).unwrap(),
|
||||
minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
// check foreign asset
|
||||
assert!(result.inner().iter().any(|asset| asset.eq(&(
|
||||
V4V3LocationConverter::convert_back(&foreign_asset_id_location).unwrap(),
|
||||
WithLatestLocationConverter::<xcm::v3::Location>::convert_back(
|
||||
&foreign_asset_id_location
|
||||
)
|
||||
.unwrap(),
|
||||
6 * foreign_asset_minimum_asset_balance
|
||||
)
|
||||
.into())));
|
||||
@@ -1004,7 +1008,7 @@ asset_test_utils::include_asset_transactor_transfer_with_pallet_assets_instance_
|
||||
XcmConfig,
|
||||
TrustBackedAssetsInstance,
|
||||
AssetIdForTrustBackedAssets,
|
||||
AssetIdForTrustBackedAssetsConvertLatest,
|
||||
AssetIdForTrustBackedAssetsConvert,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
12345,
|
||||
@@ -1044,7 +1048,7 @@ asset_test_utils::include_create_and_manage_foreign_assets_for_local_consensus_p
|
||||
ForeignCreatorsSovereignAccountOf,
|
||||
ForeignAssetsInstance,
|
||||
xcm::v3::Location,
|
||||
V4V3LocationConverter,
|
||||
WithLatestLocationConverter<xcm::v3::Location>,
|
||||
collator_session_keys(),
|
||||
ExistentialDeposit::get(),
|
||||
AssetDeposit::get(),
|
||||
|
||||
Reference in New Issue
Block a user