mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
pallet-asset-conversion: Swap Credit (#1677)
Introduces a swap implementation that allows the exchange of a credit (aka Negative Imbalance) of one asset for a credit of another asset. This is particularly useful when a credit swap is required but may not have sufficient value to meet the ED constraint, hence cannot be deposited to temp account before. An example use case is when XCM fees are paid using an asset held in the XCM executor registry and has to be swapped for native currency. Additional Updates: - encapsulates the existing `Swap` trait impl within a transactional context, since partial storage mutation is possible when an error occurs; - supplied `Currency` and `Assets` impls must be implemented over the same `Balance` type, the `AssetBalance` generic type is dropped. This helps to avoid numerous type conversion and overflow cases. If those types are different it should be handled outside of the pallet; - `Box` asset kind on a pallet level, unbox on a runtime level - here [why](https://substrate.stackexchange.com/questions/10039/boxed-argument-of-a-dispatchable/10103#10103); - `path` uses `Vec` now, instead of `BoundedVec` since it is never used in PoV; - removes the `Transfer` event due to it's redundancy with the events emitted by `fungible/s` implementations; - modifies the `SwapExecuted` event type; related issue: - https://github.com/paritytech/polkadot-sdk/issues/105 related PRs: - (required for) https://github.com/paritytech/polkadot-sdk/pull/1845 - (caused) https://github.com/paritytech/polkadot-sdk/pull/1717 // DONE make the pallet work only with `fungibles` trait and make it free from the concept of a `native` asset - https://github.com/paritytech/polkadot-sdk/issues/1842 --------- Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
@@ -302,7 +302,6 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type Balance = Balance;
|
||||
type HigherPrecisionBalance = sp_core::U256;
|
||||
type Currency = Balances;
|
||||
type AssetBalance = Balance;
|
||||
type AssetId = MultiLocation;
|
||||
type Assets = LocalAndForeignAssets<
|
||||
Assets,
|
||||
@@ -318,7 +317,7 @@ impl pallet_asset_conversion::Config for Runtime {
|
||||
type PalletId = AssetConversionPalletId;
|
||||
type AllowMultiAssetPools = AllowMultiAssetPools;
|
||||
type MaxSwapPathLength = ConstU32<4>;
|
||||
type MultiAssetId = Box<MultiLocation>;
|
||||
type MultiAssetId = MultiLocation;
|
||||
type MultiAssetIdConverter =
|
||||
MultiLocationConverter<WestendLocation, LocalAndForeignAssetsMultiLocationMatcher>;
|
||||
type MintMinLiquidity = ConstU128<100>;
|
||||
@@ -1218,19 +1217,18 @@ impl_runtime_apis! {
|
||||
impl pallet_asset_conversion::AssetConversionApi<
|
||||
Block,
|
||||
Balance,
|
||||
u128,
|
||||
Box<MultiLocation>,
|
||||
MultiLocation,
|
||||
> for Runtime
|
||||
{
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: Box<MultiLocation>, asset2: Box<MultiLocation>, amount: u128, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_exact_tokens_for_tokens(asset1: MultiLocation, asset2: MultiLocation, 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: Box<MultiLocation>, asset2: Box<MultiLocation>, amount: u128, include_fee: bool) -> Option<Balance> {
|
||||
fn quote_price_tokens_for_exact_tokens(asset1: MultiLocation, asset2: MultiLocation, amount: Balance, include_fee: bool) -> Option<Balance> {
|
||||
AssetConversion::quote_price_tokens_for_exact_tokens(asset1, asset2, amount, include_fee)
|
||||
}
|
||||
|
||||
fn get_reserves(asset1: Box<MultiLocation>, asset2: Box<MultiLocation>) -> Option<(Balance, Balance)> {
|
||||
fn get_reserves(asset1: MultiLocation, asset2: MultiLocation) -> Option<(Balance, Balance)> {
|
||||
AssetConversion::get_reserves(&asset1, &asset2).ok()
|
||||
}
|
||||
}
|
||||
@@ -1710,10 +1708,7 @@ pub mod migrations {
|
||||
/// `MultiLocation { parents: 1, interior: Here }`
|
||||
pub struct NativeAssetParents0ToParents1Migration<T>(sp_std::marker::PhantomData<T>);
|
||||
impl<
|
||||
T: pallet_asset_conversion::Config<
|
||||
MultiAssetId = Box<MultiLocation>,
|
||||
AssetId = MultiLocation,
|
||||
>,
|
||||
T: pallet_asset_conversion::Config<MultiAssetId = MultiLocation, AssetId = MultiLocation>,
|
||||
> OnRuntimeUpgrade for NativeAssetParents0ToParents1Migration<T>
|
||||
where
|
||||
<T as pallet_asset_conversion::Config>::PoolAssetId: Into<u32>,
|
||||
@@ -1739,15 +1734,15 @@ pub mod migrations {
|
||||
pallet_asset_conversion::Pallet::<T>::get_pool_account(&old_pool_id);
|
||||
reads.saturating_accrue(1);
|
||||
let pool_asset_id = pool_info.lp_token.clone();
|
||||
if old_pool_id.0.as_ref() != &invalid_native_asset {
|
||||
if old_pool_id.0 != invalid_native_asset {
|
||||
// skip, if ok
|
||||
continue
|
||||
}
|
||||
|
||||
// fix new account
|
||||
let new_pool_id = pallet_asset_conversion::Pallet::<T>::get_pool_id(
|
||||
Box::new(valid_native_asset),
|
||||
old_pool_id.1.clone(),
|
||||
valid_native_asset,
|
||||
old_pool_id.1,
|
||||
);
|
||||
let new_pool_account =
|
||||
pallet_asset_conversion::Pallet::<T>::get_pool_account(&new_pool_id);
|
||||
@@ -1786,10 +1781,10 @@ pub mod migrations {
|
||||
|
||||
// move LocalOrForeignAssets
|
||||
let _ = T::Assets::transfer(
|
||||
*old_pool_id.1.as_ref(),
|
||||
old_pool_id.1,
|
||||
&old_pool_account,
|
||||
&new_pool_account,
|
||||
T::Assets::balance(*old_pool_id.1.as_ref(), &old_pool_account),
|
||||
T::Assets::balance(old_pool_id.1, &old_pool_account),
|
||||
Preservation::Expendable,
|
||||
);
|
||||
reads.saturating_accrue(1);
|
||||
|
||||
@@ -700,8 +700,7 @@ pub struct BenchmarkMultiLocationConverter<SelfParaId> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
impl<SelfParaId>
|
||||
pallet_asset_conversion::BenchmarkHelper<MultiLocation, sp_std::boxed::Box<MultiLocation>>
|
||||
impl<SelfParaId> pallet_asset_conversion::BenchmarkHelper<MultiLocation, MultiLocation>
|
||||
for BenchmarkMultiLocationConverter<SelfParaId>
|
||||
where
|
||||
SelfParaId: Get<ParaId>,
|
||||
@@ -717,8 +716,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn multiasset_id(asset_id: u32) -> sp_std::boxed::Box<MultiLocation> {
|
||||
sp_std::boxed::Box::new(Self::asset_id(asset_id))
|
||||
fn multiasset_id(asset_id: u32) -> MultiLocation {
|
||||
Self::asset_id(asset_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user