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:
@@ -0,0 +1,101 @@
|
||||
// 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.
|
||||
|
||||
//! The crate's benchmarks.
|
||||
|
||||
use super::*;
|
||||
use crate::{pallet as pezpallet_asset_rate, Pallet as AssetRate};
|
||||
|
||||
use codec::Encode;
|
||||
use pezframe_benchmarking::v2::*;
|
||||
use pezframe_support::assert_ok;
|
||||
use pezframe_system::RawOrigin;
|
||||
use pezsp_core::crypto::FromEntropy;
|
||||
|
||||
/// Trait describing the factory function for the `AssetKind` parameter.
|
||||
pub trait AssetKindFactory<AssetKind> {
|
||||
fn create_asset_kind(seed: u32) -> AssetKind;
|
||||
}
|
||||
impl<AssetKind> AssetKindFactory<AssetKind> for ()
|
||||
where
|
||||
AssetKind: FromEntropy,
|
||||
{
|
||||
fn create_asset_kind(seed: u32) -> AssetKind {
|
||||
AssetKind::from_entropy(&mut seed.encode().as_slice()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
const SEED: u32 = 1;
|
||||
|
||||
fn default_conversion_rate() -> FixedU128 {
|
||||
FixedU128::from_u32(1u32)
|
||||
}
|
||||
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn create() -> Result<(), BenchmarkError> {
|
||||
let asset_kind: T::AssetKind = T::BenchmarkHelper::create_asset_kind(SEED);
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, Box::new(asset_kind.clone()), default_conversion_rate());
|
||||
|
||||
assert_eq!(
|
||||
pezpallet_asset_rate::ConversionRateToNative::<T>::get(asset_kind),
|
||||
Some(default_conversion_rate())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn update() -> Result<(), BenchmarkError> {
|
||||
let asset_kind: T::AssetKind = T::BenchmarkHelper::create_asset_kind(SEED);
|
||||
assert_ok!(AssetRate::<T>::create(
|
||||
RawOrigin::Root.into(),
|
||||
Box::new(asset_kind.clone()),
|
||||
default_conversion_rate()
|
||||
));
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, Box::new(asset_kind.clone()), FixedU128::from_u32(2));
|
||||
|
||||
assert_eq!(
|
||||
pezpallet_asset_rate::ConversionRateToNative::<T>::get(asset_kind),
|
||||
Some(FixedU128::from_u32(2))
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn remove() -> Result<(), BenchmarkError> {
|
||||
let asset_kind: T::AssetKind = T::BenchmarkHelper::create_asset_kind(SEED);
|
||||
assert_ok!(AssetRate::<T>::create(
|
||||
RawOrigin::Root.into(),
|
||||
Box::new(asset_kind.clone()),
|
||||
default_conversion_rate()
|
||||
));
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Root, Box::new(asset_kind.clone()));
|
||||
|
||||
assert!(pezpallet_asset_rate::ConversionRateToNative::<T>::get(asset_kind).is_none());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite! { AssetRate, crate::mock::new_test_ext(), crate::mock::Test }
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
// 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 Rate Pallet
|
||||
//!
|
||||
//! - [`Config`]
|
||||
//! - [`Call`]
|
||||
//!
|
||||
//! ## Overview
|
||||
//!
|
||||
//! The AssetRate pallet provides means of setting conversion rates for some asset to native
|
||||
//! balance.
|
||||
//!
|
||||
//! The supported dispatchable functions are documented in the [`Call`] enum.
|
||||
//!
|
||||
//! ### Terminology
|
||||
//!
|
||||
//! * **Asset balance**: The balance type of an arbitrary asset. The network might only know about
|
||||
//! the identifier of the asset and nothing more.
|
||||
//! * **Native balance**: The balance type of the network's native currency.
|
||||
//!
|
||||
//! ### Goals
|
||||
//!
|
||||
//! The asset-rate system in Bizinikiwi is designed to make the following possible:
|
||||
//!
|
||||
//! * Providing a soft conversion for the balance of supported assets to a default asset class.
|
||||
//! * Updating existing conversion rates.
|
||||
//!
|
||||
//! ## Interface
|
||||
//!
|
||||
//! ### Permissioned Functions
|
||||
//!
|
||||
//! * `create`: Creates a new asset conversion rate.
|
||||
//! * `remove`: Removes an existing asset conversion rate.
|
||||
//! * `update`: Overwrites an existing assert conversion rate.
|
||||
//!
|
||||
//! Please refer to the [`Call`] enum and its associated variants for documentation on each
|
||||
//! function.
|
||||
//!
|
||||
//! ### Assumptions
|
||||
//!
|
||||
//! * Conversion rates are only used as estimates, and are not designed to be precise or closely
|
||||
//! tracking real world values.
|
||||
//! * All conversion rates reflect the ration of some asset to native, e.g. native = asset * rate.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use pezframe_support::traits::{
|
||||
fungible::Inspect,
|
||||
tokens::{ConversionFromAssetBalance, ConversionToAssetBalance},
|
||||
};
|
||||
use pezsp_runtime::{
|
||||
traits::{CheckedDiv, Zero},
|
||||
FixedPointNumber, FixedU128,
|
||||
};
|
||||
|
||||
pub use pallet::*;
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
mod benchmarking;
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
pub use benchmarking::AssetKindFactory;
|
||||
|
||||
// Type alias for `pezframe_system`'s account id.
|
||||
type AccountIdOf<T> = <T as pezframe_system::Config>::AccountId;
|
||||
// This pallet's asset kind and balance type.
|
||||
type AssetKindOf<T> = <T as Config>::AssetKind;
|
||||
// Generic fungible balance type.
|
||||
type BalanceOf<T> = <<T as Config>::Currency as Inspect<AccountIdOf<T>>>::Balance;
|
||||
|
||||
#[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: pezframe_system::Config {
|
||||
/// The Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
|
||||
/// The runtime event type.
|
||||
#[allow(deprecated)]
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The origin permissioned to create a conversion rate for an asset.
|
||||
type CreateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin permissioned to remove an existing conversion rate for an asset.
|
||||
type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The origin permissioned to update an existing conversion rate for an asset.
|
||||
type UpdateOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The currency mechanism for this pallet.
|
||||
type Currency: Inspect<Self::AccountId>;
|
||||
|
||||
/// The type for asset kinds for which the conversion rate to native balance is set.
|
||||
type AssetKind: Parameter + MaxEncodedLen;
|
||||
|
||||
/// Helper type for benchmarks.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper: crate::AssetKindFactory<Self::AssetKind>;
|
||||
}
|
||||
|
||||
/// Maps an asset to its fixed point representation in the native balance.
|
||||
///
|
||||
/// E.g. `native_amount = asset_amount * ConversionRateToNative::<T>::get(asset_kind)`
|
||||
#[pallet::storage]
|
||||
pub type ConversionRateToNative<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, T::AssetKind, FixedU128, OptionQuery>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
// Some `asset_kind` conversion rate was created.
|
||||
AssetRateCreated { asset_kind: T::AssetKind, rate: FixedU128 },
|
||||
// Some `asset_kind` conversion rate was removed.
|
||||
AssetRateRemoved { asset_kind: T::AssetKind },
|
||||
// Some existing `asset_kind` conversion rate was updated from `old` to `new`.
|
||||
AssetRateUpdated { asset_kind: T::AssetKind, old: FixedU128, new: FixedU128 },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
/// The given asset ID is unknown.
|
||||
UnknownAssetKind,
|
||||
/// The given asset ID already has an assigned conversion rate and cannot be re-created.
|
||||
AlreadyExists,
|
||||
/// Overflow ocurred when calculating the inverse rate.
|
||||
Overflow,
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Initialize a conversion rate to native balance for the given asset.
|
||||
///
|
||||
/// ## Complexity
|
||||
/// - O(1)
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::create())]
|
||||
pub fn create(
|
||||
origin: OriginFor<T>,
|
||||
asset_kind: Box<T::AssetKind>,
|
||||
rate: FixedU128,
|
||||
) -> DispatchResult {
|
||||
T::CreateOrigin::ensure_origin(origin)?;
|
||||
|
||||
ensure!(
|
||||
!ConversionRateToNative::<T>::contains_key(asset_kind.as_ref()),
|
||||
Error::<T>::AlreadyExists
|
||||
);
|
||||
ConversionRateToNative::<T>::set(asset_kind.as_ref(), Some(rate));
|
||||
|
||||
Self::deposit_event(Event::AssetRateCreated { asset_kind: *asset_kind, rate });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the conversion rate to native balance for the given asset.
|
||||
///
|
||||
/// ## Complexity
|
||||
/// - O(1)
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(T::WeightInfo::update())]
|
||||
pub fn update(
|
||||
origin: OriginFor<T>,
|
||||
asset_kind: Box<T::AssetKind>,
|
||||
rate: FixedU128,
|
||||
) -> DispatchResult {
|
||||
T::UpdateOrigin::ensure_origin(origin)?;
|
||||
|
||||
let mut old = FixedU128::zero();
|
||||
ConversionRateToNative::<T>::mutate(asset_kind.as_ref(), |maybe_rate| {
|
||||
if let Some(r) = maybe_rate {
|
||||
old = *r;
|
||||
*r = rate;
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::<T>::UnknownAssetKind)
|
||||
}
|
||||
})?;
|
||||
|
||||
Self::deposit_event(Event::AssetRateUpdated {
|
||||
asset_kind: *asset_kind,
|
||||
old,
|
||||
new: rate,
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove an existing conversion rate to native balance for the given asset.
|
||||
///
|
||||
/// ## Complexity
|
||||
/// - O(1)
|
||||
#[pallet::call_index(2)]
|
||||
#[pallet::weight(T::WeightInfo::remove())]
|
||||
pub fn remove(origin: OriginFor<T>, asset_kind: Box<T::AssetKind>) -> DispatchResult {
|
||||
T::RemoveOrigin::ensure_origin(origin)?;
|
||||
|
||||
ensure!(
|
||||
ConversionRateToNative::<T>::contains_key(asset_kind.as_ref()),
|
||||
Error::<T>::UnknownAssetKind
|
||||
);
|
||||
ConversionRateToNative::<T>::remove(asset_kind.as_ref());
|
||||
|
||||
Self::deposit_event(Event::AssetRateRemoved { asset_kind: *asset_kind });
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Exposes conversion of an arbitrary balance of an asset to native balance.
|
||||
impl<T> ConversionFromAssetBalance<BalanceOf<T>, AssetKindOf<T>, BalanceOf<T>> for Pallet<T>
|
||||
where
|
||||
T: Config,
|
||||
{
|
||||
type Error = pallet::Error<T>;
|
||||
|
||||
fn from_asset_balance(
|
||||
balance: BalanceOf<T>,
|
||||
asset_kind: AssetKindOf<T>,
|
||||
) -> Result<BalanceOf<T>, pallet::Error<T>> {
|
||||
let rate = pallet::ConversionRateToNative::<T>::get(asset_kind)
|
||||
.ok_or(pallet::Error::<T>::UnknownAssetKind.into())?;
|
||||
Ok(rate.saturating_mul_int(balance))
|
||||
}
|
||||
/// Set a conversion rate to `1` for the `asset_id`.
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn ensure_successful(asset_id: AssetKindOf<T>) {
|
||||
pallet::ConversionRateToNative::<T>::set(asset_id.clone(), Some(1.into()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Exposes conversion of a native balance to an asset balance.
|
||||
impl<T> ConversionToAssetBalance<BalanceOf<T>, AssetKindOf<T>, BalanceOf<T>> for Pallet<T>
|
||||
where
|
||||
T: Config,
|
||||
{
|
||||
type Error = pallet::Error<T>;
|
||||
|
||||
fn to_asset_balance(
|
||||
balance: BalanceOf<T>,
|
||||
asset_kind: AssetKindOf<T>,
|
||||
) -> Result<BalanceOf<T>, pallet::Error<T>> {
|
||||
let rate = pallet::ConversionRateToNative::<T>::get(asset_kind)
|
||||
.ok_or(pallet::Error::<T>::UnknownAssetKind.into())?;
|
||||
|
||||
// We cannot use `saturating_div` here so we use `checked_div`.
|
||||
Ok(FixedU128::from_u32(1)
|
||||
.checked_div(&rate)
|
||||
.ok_or(pallet::Error::<T>::Overflow.into())?
|
||||
.saturating_mul_int(balance))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// 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.
|
||||
|
||||
//! The crate's mock.
|
||||
|
||||
use crate as pezpallet_asset_rate;
|
||||
use pezframe_support::derive_impl;
|
||||
use pezsp_runtime::BuildStorage;
|
||||
|
||||
type Block = pezframe_system::mocking::MockBlock<Test>;
|
||||
|
||||
pezframe_support::construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: pezframe_system,
|
||||
AssetRate: pezpallet_asset_rate,
|
||||
Balances: pezpallet_balances,
|
||||
}
|
||||
);
|
||||
|
||||
#[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;
|
||||
}
|
||||
|
||||
impl pezpallet_asset_rate::Config for Test {
|
||||
type WeightInfo = ();
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type CreateOrigin = pezframe_system::EnsureRoot<u64>;
|
||||
type RemoveOrigin = pezframe_system::EnsureRoot<u64>;
|
||||
type UpdateOrigin = pezframe_system::EnsureRoot<u64>;
|
||||
type Currency = Balances;
|
||||
type AssetKind = u32;
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
type BenchmarkHelper = ();
|
||||
}
|
||||
|
||||
// Build genesis storage according to the mock runtime.
|
||||
pub fn new_test_ext() -> pezsp_io::TestExternalities {
|
||||
pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap().into()
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
// 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.
|
||||
|
||||
//! The crate's tests.
|
||||
|
||||
use super::*;
|
||||
use crate::pallet as pezpallet_asset_rate;
|
||||
use pezframe_support::{assert_noop, assert_ok};
|
||||
use mock::{new_test_ext, AssetRate, RuntimeOrigin, Test};
|
||||
use pezsp_runtime::FixedU128;
|
||||
|
||||
const ASSET_ID: u32 = 42;
|
||||
|
||||
#[test]
|
||||
fn create_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(pezpallet_asset_rate::ConversionRateToNative::<Test>::get(ASSET_ID).is_none());
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.1)
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
pezpallet_asset_rate::ConversionRateToNative::<Test>::get(ASSET_ID),
|
||||
Some(FixedU128::from_float(0.1))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_existing_throws() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert!(pezpallet_asset_rate::ConversionRateToNative::<Test>::get(ASSET_ID).is_none());
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.1)
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.1)
|
||||
),
|
||||
Error::<Test>::AlreadyExists
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.1)
|
||||
));
|
||||
|
||||
assert_ok!(AssetRate::remove(RuntimeOrigin::root(), Box::new(ASSET_ID),));
|
||||
assert!(pezpallet_asset_rate::ConversionRateToNative::<Test>::get(ASSET_ID).is_none());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_unknown_throws() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
AssetRate::remove(RuntimeOrigin::root(), Box::new(ASSET_ID),),
|
||||
Error::<Test>::UnknownAssetKind
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.1)
|
||||
));
|
||||
assert_ok!(AssetRate::update(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.5)
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
pezpallet_asset_rate::ConversionRateToNative::<Test>::get(ASSET_ID),
|
||||
Some(FixedU128::from_float(0.5))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update_unknown_throws() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
AssetRate::update(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(0.5)
|
||||
),
|
||||
Error::<Test>::UnknownAssetKind
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_float(2.51)
|
||||
));
|
||||
|
||||
let conversion_from_asset = <AssetRate as ConversionFromAssetBalance<
|
||||
BalanceOf<Test>,
|
||||
<Test as pezpallet_asset_rate::Config>::AssetKind,
|
||||
BalanceOf<Test>,
|
||||
>>::from_asset_balance(10, ASSET_ID);
|
||||
assert_eq!(conversion_from_asset.expect("Conversion rate exists for asset"), 25);
|
||||
|
||||
let conversion_to_asset = <AssetRate as ConversionToAssetBalance<
|
||||
BalanceOf<Test>,
|
||||
<Test as pezpallet_asset_rate::Config>::AssetKind,
|
||||
BalanceOf<Test>,
|
||||
>>::to_asset_balance(25, ASSET_ID);
|
||||
assert_eq!(conversion_to_asset.expect("Conversion rate exists for asset"), 9);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_unknown_throws() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let conversion = <AssetRate as ConversionFromAssetBalance<
|
||||
BalanceOf<Test>,
|
||||
<Test as pezpallet_asset_rate::Config>::AssetKind,
|
||||
BalanceOf<Test>,
|
||||
>>::from_asset_balance(10, ASSET_ID);
|
||||
assert!(conversion.is_err());
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_overflow_throws() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(AssetRate::create(
|
||||
RuntimeOrigin::root(),
|
||||
Box::new(ASSET_ID),
|
||||
FixedU128::from_u32(0)
|
||||
));
|
||||
|
||||
let conversion = <AssetRate as ConversionToAssetBalance<
|
||||
BalanceOf<Test>,
|
||||
<Test as pezpallet_asset_rate::Config>::AssetKind,
|
||||
BalanceOf<Test>,
|
||||
>>::to_asset_balance(10, ASSET_ID);
|
||||
assert!(conversion.is_err());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
// 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_rate`
|
||||
//!
|
||||
//! 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_rate
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/asset-rate/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_rate`.
|
||||
pub trait WeightInfo {
|
||||
fn create() -> Weight;
|
||||
fn update() -> Weight;
|
||||
fn remove() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pezpallet_asset_rate` using the Bizinikiwi node and recommended hardware.
|
||||
pub struct BizinikiwiWeight<T>(PhantomData<T>);
|
||||
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn create() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 6_788_000 picoseconds.
|
||||
Weight::from_parts(7_122_000, 3502)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn update() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `38`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 7_787_000 picoseconds.
|
||||
Weight::from_parts(8_059_000, 3502)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn remove() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `38`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 8_184_000 picoseconds.
|
||||
Weight::from_parts(8_486_000, 3502)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn create() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 6_788_000 picoseconds.
|
||||
Weight::from_parts(7_122_000, 3502)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn update() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `38`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 7_787_000 picoseconds.
|
||||
Weight::from_parts(8_059_000, 3502)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `AssetRate::ConversionRateToNative` (r:1 w:1)
|
||||
/// Proof: `AssetRate::ConversionRateToNative` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`)
|
||||
fn remove() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `38`
|
||||
// Estimated: `3502`
|
||||
// Minimum execution time: 8_184_000 picoseconds.
|
||||
Weight::from_parts(8_486_000, 3502)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user