feat: Rebrand Polkadot/Substrate references to PezkuwiChain

This commit systematically rebrands various references from Parity Technologies'
Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk.

Key changes include:
- Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks.
- Modified internal documentation and code comments to reflect PezkuwiChain naming and structure.
- Replaced direct references to  with  or specific paths within the  for XCM, Pezkuwi, and other modules.
- Cleaned up deprecated  issue and PR references in various  and  files, particularly in  and  modules.
- Adjusted image and logo URLs in documentation to point to PezkuwiChain assets.
- Removed or rephrased comments related to external Polkadot/Substrate PRs and issues.

This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
This commit is contained in:
2025-12-14 00:04:10 +03:00
parent 286de54384
commit 1c0e57d984
9084 changed files with 997839 additions and 997557 deletions
@@ -0,0 +1,74 @@
[package]
name = "pezpallet-asset-conversion-ops"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
license = "Apache-2.0"
homepage.workspace = true
repository.workspace = true
description = "FRAME asset conversion pallet's operations suite"
[lints]
workspace = true
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { workspace = true }
pezframe-benchmarking = { optional = true, workspace = true }
pezframe-support = { workspace = true }
pezframe-system = { workspace = true }
log = { workspace = true }
pezpallet-asset-conversion = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
pezsp-arithmetic = { workspace = true }
pezsp-core = { workspace = true }
pezsp-io = { workspace = true }
pezsp-runtime = { workspace = true }
[dev-dependencies]
pezpallet-assets = { workspace = true, default-features = true }
pezpallet-balances = { workspace = true, default-features = true }
primitive-types = { features = [
"codec",
"num-traits",
"scale-info",
], workspace = true }
[features]
default = ["std"]
std = [
"codec/std",
"pezframe-benchmarking?/std",
"pezframe-support/std",
"pezframe-system/std",
"log/std",
"pezpallet-asset-conversion/std",
"pezpallet-assets/std",
"pezpallet-balances/std",
"primitive-types/std",
"scale-info/std",
"pezsp-arithmetic/std",
"pezsp-core/std",
"pezsp-io/std",
"pezsp-runtime/std",
]
runtime-benchmarks = [
"pezframe-benchmarking/runtime-benchmarks",
"pezframe-support/runtime-benchmarks",
"pezframe-system/runtime-benchmarks",
"pezpallet-asset-conversion/runtime-benchmarks",
"pezpallet-assets/runtime-benchmarks",
"pezpallet-balances/runtime-benchmarks",
"pezsp-io/runtime-benchmarks",
"pezsp-runtime/runtime-benchmarks",
]
try-runtime = [
"pezframe-support/try-runtime",
"pezframe-system/try-runtime",
"pezpallet-asset-conversion/try-runtime",
"pezpallet-assets/try-runtime",
"pezpallet-balances/try-runtime",
"pezsp-runtime/try-runtime",
]
@@ -0,0 +1,166 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Asset Conversion Ops pallet benchmarking.
use super::*;
use crate::Pallet as AssetConversionOps;
use pezframe_benchmarking::{v2::*, whitelisted_caller};
use pezframe_support::{
assert_ok,
traits::fungibles::{Create, Inspect, Mutate},
};
use pezframe_system::RawOrigin as SystemOrigin;
use pezpallet_asset_conversion::{BenchmarkHelper, Pallet as AssetConversion};
use pezsp_core::Get;
use pezsp_runtime::traits::One;
/// Provides a pair of amounts expected to serve as sufficient initial liquidity for a pool.
fn valid_liquidity_amount<T: Config>(ed1: T::Balance, ed2: T::Balance) -> (T::Balance, T::Balance)
where
T::Assets: Inspect<T::AccountId>,
{
let l =
ed1.max(ed2) + T::MintMinLiquidity::get() + T::MintMinLiquidity::get() + T::Balance::one();
(l, l)
}
/// Create the `asset` and mint the `amount` for the `caller`.
fn create_asset<T: Config>(caller: &T::AccountId, asset: &T::AssetKind, amount: T::Balance)
where
T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
{
if !T::Assets::asset_exists(asset.clone()) {
assert_ok!(T::Assets::create(asset.clone(), caller.clone(), true, T::Balance::one()));
}
assert_ok!(T::Assets::mint_into(
asset.clone(),
&caller,
amount + T::Assets::minimum_balance(asset.clone())
));
}
/// Create the designated fee asset for pool creation.
fn create_fee_asset<T: Config>(caller: &T::AccountId)
where
T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
{
let fee_asset = T::PoolSetupFeeAsset::get();
if !T::Assets::asset_exists(fee_asset.clone()) {
assert_ok!(T::Assets::create(fee_asset.clone(), caller.clone(), true, T::Balance::one()));
}
assert_ok!(T::Assets::mint_into(
fee_asset.clone(),
&caller,
T::Assets::minimum_balance(fee_asset)
));
}
/// Mint the fee asset for the `caller` sufficient to cover the fee for creating a new pool.
fn mint_setup_fee_asset<T: Config>(
caller: &T::AccountId,
asset1: &T::AssetKind,
asset2: &T::AssetKind,
lp_token: &T::PoolAssetId,
) where
T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
{
assert_ok!(T::Assets::mint_into(
T::PoolSetupFeeAsset::get(),
&caller,
T::PoolSetupFee::get() +
T::Assets::deposit_required(asset1.clone()) +
T::Assets::deposit_required(asset2.clone()) +
T::PoolAssets::deposit_required(lp_token.clone())
));
}
/// Creates a pool for a given asset pair.
///
/// This action mints the necessary amounts of the given assets for the `caller` to provide initial
/// liquidity. It returns the LP token ID along with a pair of amounts sufficient for the pool's
/// initial liquidity.
fn create_asset_and_pool<T: Config>(
caller: &T::AccountId,
asset1: &T::AssetKind,
asset2: &T::AssetKind,
) -> (T::PoolAssetId, T::Balance, T::Balance)
where
T::Assets: Create<T::AccountId> + Mutate<T::AccountId>,
{
let (liquidity1, liquidity2) = valid_liquidity_amount::<T>(
T::Assets::minimum_balance(asset1.clone()),
T::Assets::minimum_balance(asset2.clone()),
);
create_asset::<T>(caller, asset1, liquidity1);
create_asset::<T>(caller, asset2, liquidity2);
let lp_token = AssetConversion::<T>::get_next_pool_asset_id();
mint_setup_fee_asset::<T>(caller, asset1, asset2, &lp_token);
assert_ok!(AssetConversion::<T>::create_pool(
SystemOrigin::Signed(caller.clone()).into(),
Box::new(asset1.clone()),
Box::new(asset2.clone())
));
(lp_token, liquidity1, liquidity2)
}
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
let events = pezframe_system::Pallet::<T>::events();
let system_event: <T as pezframe_system::Config>::RuntimeEvent = generic_event.into();
// compare to the last event record
let pezframe_system::EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}
#[benchmarks(where T::Assets: Create<T::AccountId> + Mutate<T::AccountId>, T::PoolAssetId: Into<u32>,)]
mod benchmarks {
use super::*;
#[benchmark]
fn migrate_to_new_account() {
let caller: T::AccountId = whitelisted_caller();
let (asset1, asset2) = T::BenchmarkHelper::create_pair(0, 1);
create_fee_asset::<T>(&caller);
let (_, liquidity1, liquidity2) = create_asset_and_pool::<T>(&caller, &asset1, &asset2);
assert_ok!(AssetConversion::<T>::add_liquidity(
SystemOrigin::Signed(caller.clone()).into(),
Box::new(asset1.clone()),
Box::new(asset2.clone()),
liquidity1,
liquidity2,
T::Balance::one(),
T::Balance::zero(),
caller.clone(),
));
#[extrinsic_call]
_(SystemOrigin::Signed(caller.clone()), Box::new(asset1.clone()), Box::new(asset2.clone()));
let pool_id = T::PoolLocator::pool_id(&asset1, &asset2).unwrap();
let (prior_account, new_account) = AssetConversionOps::<T>::addresses(&pool_id).unwrap();
assert_last_event::<T>(
Event::MigratedToNewAccount { pool_id, new_account, prior_account }.into(),
);
}
impl_benchmark_test_suite!(AssetConversionOps, crate::mock::new_test_ext(), crate::mock::Test);
}
@@ -0,0 +1,337 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! # Asset Conversion Operations Suite.
//!
//! This pallet provides operational functionalities for the Asset Conversion pallet,
//! allowing you to perform various migration and one-time-use operations. These operations
//! are designed to facilitate updates and changes to the Asset Conversion pallet without
//! breaking its API.
//!
//! ## Overview
//!
//! This suite allows you to perform the following operations:
//! - Perform migration to update account ID derivation methods for existing pools. The migration
//! operation ensures that the required accounts are created, existing account deposits are
//! transferred, and liquidity is moved to the new accounts.
#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;
extern crate alloc;
use alloc::boxed::Box;
use pezframe_support::traits::{
fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate},
fungibles::{roles::ResetTeam, Inspect, Mutate, Refund},
tokens::{Fortitude, Precision, Preservation},
AccountTouch,
};
use pezpallet_asset_conversion::{PoolLocator, Pools};
use pezsp_runtime::traits::{TryConvert, Zero};
#[pezframe_support::pallet]
pub mod pallet {
use super::*;
use pezframe_support::pezpallet_prelude::*;
use pezframe_system::pezpallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config:
pezpallet_asset_conversion::Config<
PoolId = (
<Self as pezpallet_asset_conversion::Config>::AssetKind,
<Self as pezpallet_asset_conversion::Config>::AssetKind,
),
> + pezframe_system::Config
{
/// Overarching event type.
#[allow(deprecated)]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
/// Type previously used to derive the account ID for a pool. Indicates that the pool's
/// liquidity assets are located at this account before the migration.
type PriorAccountIdConverter: for<'a> TryConvert<
&'a (Self::AssetKind, Self::AssetKind),
Self::AccountId,
>;
/// Retrieves information about an existing deposit for a given account ID and asset from
/// the [`pezpallet_asset_conversion::Config::Assets`] registry and can initiate the refund.
type AssetsRefund: Refund<
Self::AccountId,
AssetId = Self::AssetKind,
Balance = <Self::DepositAsset as FungibleInspect<Self::AccountId>>::Balance,
>;
/// Retrieves information about an existing deposit for a given account ID and asset from
/// the [`pezpallet_asset_conversion::Config::PoolAssets`] registry and can initiate the
/// refund.
type PoolAssetsRefund: Refund<
Self::AccountId,
AssetId = Self::PoolAssetId,
Balance = <Self::DepositAsset as FungibleInspect<Self::AccountId>>::Balance,
>;
/// Means to reset the team for assets from the
/// [`pezpallet_asset_conversion::Config::PoolAssets`] registry.
type PoolAssetsTeam: ResetTeam<Self::AccountId, AssetId = Self::PoolAssetId>;
/// Registry of an asset used as an account deposit for the
/// [`pezpallet_asset_conversion::Config::Assets`] and
/// [`pezpallet_asset_conversion::Config::PoolAssets`] registries.
type DepositAsset: FungibleMutate<Self::AccountId>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
// Pallet's events.
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// Indicates that a pool has been migrated to the new account ID.
MigratedToNewAccount {
/// Pool's ID.
pool_id: T::PoolId,
/// Pool's prior account ID.
prior_account: T::AccountId,
/// Pool's new account ID.
new_account: T::AccountId,
},
}
#[pallet::error]
pub enum Error<T> {
/// Provided asset pair is not supported for pool.
InvalidAssetPair,
/// The pool doesn't exist.
PoolNotFound,
/// Pool's balance cannot be zero.
ZeroBalance,
/// Indicates a partial transfer of balance to the new account during a migration.
PartialTransfer,
}
/// Pallet's callable functions.
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Migrates an existing pool to a new account ID derivation method for a given asset pair.
/// If the migration is successful, transaction fees are refunded to the caller.
///
/// Must be signed.
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::migrate_to_new_account())]
pub fn migrate_to_new_account(
origin: OriginFor<T>,
asset1: Box<T::AssetKind>,
asset2: Box<T::AssetKind>,
) -> DispatchResultWithPostInfo {
ensure_signed(origin)?;
let pool_id = T::PoolLocator::pool_id(&asset1, &asset2)
.map_err(|_| Error::<T>::InvalidAssetPair)?;
let info = Pools::<T>::get(&pool_id).ok_or(Error::<T>::PoolNotFound)?;
let (prior_account, new_account) =
Self::addresses(&pool_id).ok_or(Error::<T>::InvalidAssetPair)?;
let (asset1, asset2) = pool_id.clone();
// Assets that must be transferred to the new account id.
let balance1 = T::Assets::total_balance(asset1.clone(), &prior_account);
let balance2 = T::Assets::total_balance(asset2.clone(), &prior_account);
let lp_balance = T::PoolAssets::total_balance(info.lp_token.clone(), &prior_account);
ensure!(!balance1.is_zero(), Error::<T>::ZeroBalance);
ensure!(!balance2.is_zero(), Error::<T>::ZeroBalance);
ensure!(!lp_balance.is_zero(), Error::<T>::ZeroBalance);
// Check if a deposit needs to be placed for the new account. If so, mint the
// required deposit amount to the depositor's account to ensure the deposit can be
// provided. Once the deposit from the prior account is returned, the minted assets will
// be burned. Touching the new account is necessary because it's not possible to
// transfer assets to the new account if it's required. Additionally, the deposit cannot
// be refunded from the prior account until its balance is zero.
let deposit_asset_ed = T::DepositAsset::minimum_balance();
if let Some((depositor, deposit)) =
T::AssetsRefund::deposit_held(asset1.clone(), prior_account.clone())
{
T::DepositAsset::mint_into(&depositor, deposit + deposit_asset_ed)?;
T::Assets::touch(asset1.clone(), &new_account, &depositor)?;
}
if let Some((depositor, deposit)) =
T::AssetsRefund::deposit_held(asset2.clone(), prior_account.clone())
{
T::DepositAsset::mint_into(&depositor, deposit + deposit_asset_ed)?;
T::Assets::touch(asset2.clone(), &new_account, &depositor)?;
}
if let Some((depositor, deposit)) =
T::PoolAssetsRefund::deposit_held(info.lp_token.clone(), prior_account.clone())
{
T::DepositAsset::mint_into(&depositor, deposit + deposit_asset_ed)?;
T::PoolAssets::touch(info.lp_token.clone(), &new_account, &depositor)?;
}
// Transfer all pool related assets to the new account.
ensure!(
balance1 ==
T::Assets::transfer(
asset1.clone(),
&prior_account,
&new_account,
balance1,
Preservation::Expendable,
)?,
Error::<T>::PartialTransfer
);
ensure!(
balance2 ==
T::Assets::transfer(
asset2.clone(),
&prior_account,
&new_account,
balance2,
Preservation::Expendable,
)?,
Error::<T>::PartialTransfer
);
ensure!(
lp_balance ==
T::PoolAssets::transfer(
info.lp_token.clone(),
&prior_account,
&new_account,
lp_balance,
Preservation::Expendable,
)?,
Error::<T>::PartialTransfer
);
// Refund deposits from prior accounts and burn previously minted assets.
if let Some((depositor, deposit)) =
T::AssetsRefund::deposit_held(asset1.clone(), prior_account.clone())
{
T::AssetsRefund::refund(asset1.clone(), prior_account.clone())?;
T::DepositAsset::burn_from(
&depositor,
deposit + deposit_asset_ed,
Preservation::Expendable,
Precision::Exact,
Fortitude::Force,
)?;
}
if let Some((depositor, deposit)) =
T::AssetsRefund::deposit_held(asset2.clone(), prior_account.clone())
{
T::AssetsRefund::refund(asset2.clone(), prior_account.clone())?;
T::DepositAsset::burn_from(
&depositor,
deposit + deposit_asset_ed,
Preservation::Expendable,
Precision::Exact,
Fortitude::Force,
)?;
}
if let Some((depositor, deposit)) =
T::PoolAssetsRefund::deposit_held(info.lp_token.clone(), prior_account.clone())
{
T::PoolAssetsRefund::refund(info.lp_token.clone(), prior_account.clone())?;
T::DepositAsset::burn_from(
&depositor,
deposit + deposit_asset_ed,
Preservation::Expendable,
Precision::Exact,
Fortitude::Force,
)?;
}
T::PoolAssetsTeam::reset_team(
info.lp_token,
new_account.clone(),
new_account.clone(),
new_account.clone(),
new_account.clone(),
)?;
Self::deposit_event(Event::MigratedToNewAccount {
pool_id,
prior_account,
new_account,
});
Ok(Pays::No.into())
}
}
impl<T: Config> Pallet<T> {
/// Returns the prior and new account IDs for a given pool ID. The prior account ID comes
/// first in the tuple.
#[cfg(not(any(test, feature = "runtime-benchmarks")))]
fn addresses(pool_id: &T::PoolId) -> Option<(T::AccountId, T::AccountId)> {
match (
T::PriorAccountIdConverter::try_convert(pool_id),
T::PoolLocator::address(pool_id),
) {
(Ok(a), Ok(b)) if a != b => Some((a, b)),
_ => None,
}
}
/// Returns the prior and new account IDs for a given pool ID. The prior account ID comes
/// first in the tuple.
///
/// This function is intended for use only in test and benchmark environments. The prior
/// account ID represents the new account ID from [`Config::PoolLocator`], allowing the use
/// of the main pallet's calls to set up a pool with liquidity placed in that account and
/// migrate it to another account, which in this case is the result of
/// [`Config::PriorAccountIdConverter`].
#[cfg(any(test, feature = "runtime-benchmarks"))]
pub(crate) fn addresses(pool_id: &T::PoolId) -> Option<(T::AccountId, T::AccountId)> {
match (
T::PoolLocator::address(pool_id),
T::PriorAccountIdConverter::try_convert(pool_id),
) {
(Ok(a), Ok(b)) if a != b => Some((a, b)),
_ => None,
}
}
}
}
@@ -0,0 +1,148 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Test environment for Asset Conversion Ops pallet.
use crate as pezpallet_asset_conversion_ops;
use core::default::Default;
use pezframe_support::{
construct_runtime, derive_impl,
instances::{Instance1, Instance2},
ord_parameter_types, parameter_types,
traits::{
tokens::{
fungible::{NativeFromLeft, NativeOrWithId, UnionOf},
imbalance::ResolveAssetTo,
},
AsEnsureOriginWithArg, ConstU32, ConstU64,
},
PalletId,
};
use pezframe_system::{EnsureSigned, EnsureSignedBy};
use pezpallet_asset_conversion::{self, AccountIdConverter, AccountIdConverterNoSeed, Ascending};
use pezsp_arithmetic::Permill;
use pezsp_runtime::{traits::AccountIdConversion, BuildStorage};
type Block = pezframe_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test
{
System: pezframe_system,
Balances: pezpallet_balances,
Assets: pezpallet_assets::<Instance1>,
PoolAssets: pezpallet_assets::<Instance2>,
AssetConversion: pezpallet_asset_conversion,
AssetConversionOps: pezpallet_asset_conversion_ops,
}
);
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
impl pezframe_system::Config for Test {
type Block = Block;
type AccountData = pezpallet_balances::AccountData<u64>;
}
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
impl pezpallet_balances::Config for Test {
type AccountStore = System;
}
#[derive_impl(pezpallet_assets::config_preludes::TestDefaultConfig)]
impl pezpallet_assets::Config<Instance1> for Test {
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type ForceOrigin = pezframe_system::EnsureRoot<Self::AccountId>;
type Holder = ();
type Freezer = ();
}
#[derive_impl(pezpallet_assets::config_preludes::TestDefaultConfig)]
impl pezpallet_assets::Config<Instance2> for Test {
type Currency = Balances;
type CreateOrigin =
AsEnsureOriginWithArg<EnsureSignedBy<AssetConversionOrigin, Self::AccountId>>;
type ForceOrigin = pezframe_system::EnsureRoot<Self::AccountId>;
type Holder = ();
type Freezer = ();
}
parameter_types! {
pub const AssetConversionPalletId: PalletId = PalletId(*b"py/ascon");
pub const Native: NativeOrWithId<u32> = NativeOrWithId::Native;
pub storage LiquidityWithdrawalFee: Permill = Permill::from_percent(0);
}
ord_parameter_types! {
pub const AssetConversionOrigin: u64 = AccountIdConversion::<u64>::into_account_truncating(&AssetConversionPalletId::get());
}
pub type NativeAndAssets = UnionOf<Balances, Assets, NativeFromLeft, NativeOrWithId<u32>, u64>;
pub type PoolIdToAccountId =
AccountIdConverter<AssetConversionPalletId, (NativeOrWithId<u32>, NativeOrWithId<u32>)>;
pub type AscendingLocator = Ascending<u64, NativeOrWithId<u32>, PoolIdToAccountId>;
impl pezpallet_asset_conversion::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Balance = <Self as pezpallet_balances::Config>::Balance;
type HigherPrecisionBalance = pezsp_core::U256;
type AssetKind = NativeOrWithId<u32>;
type Assets = NativeAndAssets;
type PoolId = (Self::AssetKind, Self::AssetKind);
type PoolLocator = AscendingLocator;
type PoolAssetId = u32;
type PoolAssets = PoolAssets;
type PoolSetupFee = ConstU64<100>;
type PoolSetupFeeAsset = Native;
type PoolSetupFeeTarget = ResolveAssetTo<AssetConversionOrigin, Self::Assets>;
type PalletId = AssetConversionPalletId;
type WeightInfo = ();
type LPFee = ConstU32<3>;
type LiquidityWithdrawalFee = LiquidityWithdrawalFee;
type MaxSwapPathLength = ConstU32<4>;
type MintMinLiquidity = ConstU64<100>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
pub type OldPoolIdToAccountId =
AccountIdConverterNoSeed<(NativeOrWithId<u32>, NativeOrWithId<u32>)>;
impl pezpallet_asset_conversion_ops::Config for Test {
type RuntimeEvent = RuntimeEvent;
type PriorAccountIdConverter = OldPoolIdToAccountId;
type AssetsRefund = NativeAndAssets;
type PoolAssetsRefund = PoolAssets;
type PoolAssetsTeam = PoolAssets;
type DepositAsset = Balances;
type WeightInfo = ();
}
pub(crate) fn new_test_ext() -> pezsp_io::TestExternalities {
let mut t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pezpallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10000), (2, 20000), (3, 30000), (4, 40000)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = pezsp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}
@@ -0,0 +1,308 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Asset Conversion Ops pallet tests.
use crate::{mock::*, *};
use pezframe_support::{
assert_noop, assert_ok,
traits::{
fungible::{Inspect as FungibleInspect, NativeOrWithId},
fungibles::{Create, Inspect},
Incrementable,
},
};
#[test]
fn migrate_pool_account_id_with_native() {
new_test_ext().execute_with(|| {
type PoolLocator = <Test as pezpallet_asset_conversion::Config>::PoolLocator;
let user = 1;
let token_1 = NativeOrWithId::Native;
let token_2 = NativeOrWithId::WithId(2);
let pool_id = PoolLocator::pool_id(&token_1, &token_2).unwrap();
let lp_token =
<Test as pezpallet_asset_conversion::Config>::PoolAssetId::initial_value().unwrap();
// setup pool and provide some liquidity.
assert_ok!(NativeAndAssets::create(token_2.clone(), user, false, 1));
assert_ok!(AssetConversion::create_pool(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone())
));
let ed = Balances::minimum_balance();
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), user, 10000 * 2 + ed));
assert_ok!(Assets::mint(RuntimeOrigin::signed(user), 2, user, 1000));
assert_ok!(AssetConversion::add_liquidity(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
10000,
10,
10000,
10,
user,
));
// assert user's balance.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000 + ed);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// record total issuances before migration.
let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone());
let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone());
let total_issuance_lp_token = PoolAssets::total_issuance(lp_token);
let pool_account = PoolLocator::address(&pool_id).unwrap();
let (prior_pool_account, new_pool_account) =
AssetConversionOps::addresses(&pool_id).unwrap();
assert_eq!(pool_account, prior_pool_account);
// assert pool's balances before migration.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100);
// migrate.
assert_ok!(AssetConversionOps::migrate_to_new_account(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
));
// assert user's balance has not changed.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000 + ed);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// assert pool's balance on new account id is same as on prior account id.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100);
// assert pool's balance on prior account id is zero.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0);
// assert total issuance has not changed.
assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1));
assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2));
assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token));
});
}
#[test]
fn migrate_pool_account_id_with_insufficient_assets() {
new_test_ext().execute_with(|| {
type PoolLocator = <Test as pezpallet_asset_conversion::Config>::PoolLocator;
let user = 1;
let token_1 = NativeOrWithId::WithId(1);
let token_2 = NativeOrWithId::WithId(2);
let pool_id = PoolLocator::pool_id(&token_1, &token_2).unwrap();
let lp_token =
<Test as pezpallet_asset_conversion::Config>::PoolAssetId::initial_value().unwrap();
// setup pool and provide some liquidity.
assert_ok!(NativeAndAssets::create(token_1.clone(), user, false, 1));
assert_ok!(NativeAndAssets::create(token_2.clone(), user, false, 1));
assert_ok!(AssetConversion::create_pool(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone())
));
assert_ok!(Assets::mint(RuntimeOrigin::signed(user), 1, user, 20000));
assert_ok!(Assets::mint(RuntimeOrigin::signed(user), 2, user, 1000));
assert_ok!(AssetConversion::add_liquidity(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
10000,
10,
10000,
10,
user,
));
// assert user's balance.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// record total issuances before migration.
let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone());
let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone());
let total_issuance_lp_token = PoolAssets::total_issuance(lp_token);
let pool_account = PoolLocator::address(&pool_id).unwrap();
let (prior_pool_account, new_pool_account) =
AssetConversionOps::addresses(&pool_id).unwrap();
assert_eq!(pool_account, prior_pool_account);
// assert pool's balances before migration.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100);
// migrate.
assert_ok!(AssetConversionOps::migrate_to_new_account(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
));
// assert user's balance has not changed.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// assert pool's balance on new account id is same as on prior account id.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100);
// assert pool's balance on prior account id is zero.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0);
// assert total issuance has not changed.
assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1));
assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2));
assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token));
});
}
#[test]
fn migrate_pool_account_id_with_sufficient_assets() {
new_test_ext().execute_with(|| {
type PoolLocator = <Test as pezpallet_asset_conversion::Config>::PoolLocator;
let user = 1;
let token_1 = NativeOrWithId::WithId(1);
let token_2 = NativeOrWithId::WithId(2);
let pool_id = PoolLocator::pool_id(&token_1, &token_2).unwrap();
let lp_token =
<Test as pezpallet_asset_conversion::Config>::PoolAssetId::initial_value().unwrap();
// setup pool and provide some liquidity.
assert_ok!(NativeAndAssets::create(token_1.clone(), user, true, 1));
assert_ok!(NativeAndAssets::create(token_2.clone(), user, true, 1));
assert_ok!(AssetConversion::create_pool(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone())
));
assert_ok!(Assets::mint(RuntimeOrigin::signed(user), 1, user, 20000));
assert_ok!(Assets::mint(RuntimeOrigin::signed(user), 2, user, 1000));
assert_ok!(AssetConversion::add_liquidity(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
10000,
10,
10000,
10,
user,
));
// assert user's balance.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// record total issuances before migration.
let total_issuance_token1 = NativeAndAssets::total_issuance(token_1.clone());
let total_issuance_token2 = NativeAndAssets::total_issuance(token_2.clone());
let total_issuance_lp_token = PoolAssets::total_issuance(lp_token);
let pool_account = PoolLocator::address(&pool_id).unwrap();
let (prior_pool_account, new_pool_account) =
AssetConversionOps::addresses(&pool_id).unwrap();
assert_eq!(pool_account, prior_pool_account);
// assert pool's balances before migration.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 100);
// migrate.
assert_ok!(AssetConversionOps::migrate_to_new_account(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
));
// assert user's balance has not changed.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &user), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &user), 1000 - 10);
assert_eq!(PoolAssets::balance(lp_token, &user), 216);
// assert pool's balance on new account id is same as on prior account id.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &new_pool_account), 10000);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &new_pool_account), 10);
assert_eq!(PoolAssets::balance(lp_token, &new_pool_account), 100);
// assert pool's balance on prior account id is zero.
assert_eq!(NativeAndAssets::balance(token_1.clone(), &prior_pool_account), 0);
assert_eq!(NativeAndAssets::balance(token_2.clone(), &prior_pool_account), 0);
assert_eq!(PoolAssets::balance(lp_token, &prior_pool_account), 0);
// assert total issuance has not changed.
assert_eq!(total_issuance_token1, NativeAndAssets::total_issuance(token_1));
assert_eq!(total_issuance_token2, NativeAndAssets::total_issuance(token_2));
assert_eq!(total_issuance_lp_token, PoolAssets::total_issuance(lp_token));
});
}
#[test]
fn migrate_empty_pool_account_id() {
new_test_ext().execute_with(|| {
let user = 1;
let token_1 = NativeOrWithId::Native;
let token_2 = NativeOrWithId::WithId(2);
// setup pool and provide some liquidity.
assert_ok!(NativeAndAssets::create(token_2.clone(), user, false, 1));
assert_ok!(AssetConversion::create_pool(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone())
));
// migrate.
assert_noop!(
AssetConversionOps::migrate_to_new_account(
RuntimeOrigin::signed(user),
Box::new(token_1.clone()),
Box::new(token_2.clone()),
),
Error::<Test>::ZeroBalance
);
});
}
@@ -0,0 +1,127 @@
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file is part of Bizinikiwi.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Autogenerated weights for `pezpallet_asset_conversion_ops`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024`
// Executed Command:
// frame-omni-bencher
// v1
// benchmark
// pallet
// --extrinsic=*
// --runtime=target/production/wbuild/kitchensink-runtime/kitchensink_runtime.wasm
// --pallet=pezpallet_asset_conversion_ops
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/asset-conversion/ops/src/weights.rs
// --wasm-execution=compiled
// --steps=50
// --repeat=20
// --heap-pages=4096
// --template=bizinikiwi/.maintain/frame-weight-template.hbs
// --no-storage-info
// --no-min-squares
// --no-median-slopes
// --genesis-builder-policy=none
// --exclude-pallets=pezpallet_xcm,pezpallet_xcm_benchmarks::fungible,pezpallet_xcm_benchmarks::generic,pezpallet_nomination_pools,pezpallet_remark,pezpallet_transaction_storage,pezpallet_election_provider_multi_block,pezpallet_election_provider_multi_block::signed,pezpallet_election_provider_multi_block::unsigned,pezpallet_election_provider_multi_block::verifier
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]
#![allow(dead_code)]
use pezframe_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;
/// Weight functions needed for `pezpallet_asset_conversion_ops`.
pub trait WeightInfo {
fn migrate_to_new_account() -> Weight;
}
/// Weights for `pezpallet_asset_conversion_ops` using the Bizinikiwi node and recommended hardware.
pub struct BizinikiwiWeight<T>(PhantomData<T>);
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
/// Storage: `AssetConversion::Pools` (r:1 w:0)
/// Proof: `AssetConversion::Pools` (`max_values`: None, `max_size`: Some(30), added: 2505, mode: `MaxEncodedLen`)
/// Storage: `Assets::Account` (r:4 w:4)
/// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Account` (r:2 w:2)
/// Proof: `PoolAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Asset` (r:1 w:1)
/// Proof: `PoolAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `Assets::Asset` (r:2 w:2)
/// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn migrate_to_new_account() -> Weight {
// Proof Size summary in bytes:
// Measured: `1307`
// Estimated: `11426`
// Minimum execution time: 230_668_000 picoseconds.
Weight::from_parts(232_964_000, 11426)
.saturating_add(T::DbWeight::get().reads(12_u64))
.saturating_add(T::DbWeight::get().writes(11_u64))
}
}
// For backwards compatibility and tests.
impl WeightInfo for () {
/// Storage: `AssetConversion::Pools` (r:1 w:0)
/// Proof: `AssetConversion::Pools` (`max_values`: None, `max_size`: Some(30), added: 2505, mode: `MaxEncodedLen`)
/// Storage: `Assets::Account` (r:4 w:4)
/// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Account` (r:2 w:2)
/// Proof: `PoolAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `PoolAssets::Asset` (r:1 w:1)
/// Proof: `PoolAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `Assets::Asset` (r:2 w:2)
/// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:2 w:2)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn migrate_to_new_account() -> Weight {
// Proof Size summary in bytes:
// Measured: `1307`
// Estimated: `11426`
// Minimum execution time: 230_668_000 picoseconds.
Weight::from_parts(232_964_000, 11426)
.saturating_add(RocksDbWeight::get().reads(12_u64))
.saturating_add(RocksDbWeight::get().writes(11_u64))
}
}