difftreelog
feat switch `inflation` from `Currency` trait to `fungible::*` traits fix: benchmarks
in: master
5 files changed
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -33,11 +33,11 @@
where
T: Config + pallet_unique::Config + pallet_evm_migration::Config,
T::BlockNumber: From<u32> + Into<u32>,
- <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>,
+ BalanceOf<T>: Sum + From<u128>,
{
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- <T as Config>::Currency::make_free_balance_be(
+ <T as Config>::Currency::set_balance(
&pallet_admin,
Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
);
@@ -54,7 +54,7 @@
where_clause{
where T: Config + pallet_unique::Config + pallet_evm_migration::Config ,
T::BlockNumber: From<u32> + Into<u32>,
- <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>
+ BalanceOf<T>: Sum + From<u128>
}
on_initialize {
@@ -63,7 +63,7 @@
(0..b).try_for_each(|index| {
let staker = account::<T::AccountId>("staker", index, SEED);
- <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::set_balance(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())?;
PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker.clone()).into())?;
Result::<(), sp_runtime::DispatchError>::Ok(())
@@ -73,7 +73,7 @@
set_admin_address {
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
} : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin))
payout_stakers{
@@ -82,12 +82,12 @@
let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
let share = Perbill::from_rational(1u32, 20);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
- <T as Config>::Currency::make_free_balance_be(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::set_balance(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();
stakers.iter().for_each(|staker| {
- <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ <T as Config>::Currency::set_balance(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
});
(1..11).try_for_each(|i| {
<frame_system::Pallet<T>>::set_block_number(i.into());
@@ -112,13 +112,13 @@
stake {
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 10);
- let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
} : _(RawOrigin::Signed(caller.clone()), share * <T as Config>::Currency::total_balance(&caller))
unstake_all {
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 20);
- let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
(1..11).map(|i| {
// used to change block number
<frame_system::Pallet<T>>::set_block_number(i.into());
@@ -133,7 +133,7 @@
unstake_partial {
let caller = account::<T::AccountId>("caller", 0, SEED);
let share = Perbill::from_rational(1u32, 20);
- let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
(1..11).map(|i| {
// used to change block number
<frame_system::Pallet<T>>::set_block_number(i.into());
@@ -148,18 +148,18 @@
sponsor_collection {
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let caller: T::AccountId = account("caller", 0, SEED);
- let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let collection = create_nft_collection::<T>(caller.clone())?;
} : _(RawOrigin::Signed(pallet_admin.clone()), collection)
stop_sponsoring_collection {
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let caller: T::AccountId = account("caller", 0, SEED);
- let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let collection = create_nft_collection::<T>(caller.clone())?;
PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;
} : _(RawOrigin::Signed(pallet_admin.clone()), collection)
@@ -168,7 +168,7 @@
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let address = H160::from_low_u64_be(SEED as u64);
let data: Vec<u8> = (0..20 as u8).collect();
<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
@@ -179,7 +179,7 @@
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
- let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
+ let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let address = H160::from_low_u64_be(SEED as u64);
let data: Vec<u8> = (0..20 as u8).collect();
<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
pallets/configuration/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/configuration/src/benchmarking.rs
+++ b/pallets/configuration/src/benchmarking.rs
@@ -68,7 +68,7 @@
}
set_collator_selection_license_bond {
- let bond_cost: Option<BalanceOf<T>> = Some(T::Balances::minimum_balance() * 10u32.into());
+ let bond_cost: Option<BalanceOf<T>> = Some(T::Currency::minimum_balance() * 10u32.into());
}: {
assert_ok!(
<Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost.clone())
pallets/inflation/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Inflation18//!19//! The inflation pallet is designed to increase the number of tokens at certain intervals.20//! With each iteration, increases the `total_issuance` value for the native token.21//! Executing an `on_initialize` hook at the beginning of each block, causing inflation to begin.22//!23//! ## Interface24//!25//! ### Dispatchable Functions26//!27//! * `start_inflation` - This method sets the inflation start date. Can be only called once.28//! Inflation start block can be backdated and will catch up. The method will create Treasury29//! account if it does not exist and perform the first inflation deposit.3031// #![recursion_limit = "1024"]32#![cfg_attr(not(feature = "std"), no_std)]3334#[cfg(feature = "runtime-benchmarks")]35mod benchmarking;3637#[cfg(test)]38mod tests;3940use frame_support::{41 dispatch::{DispatchResult},42 traits::{Currency, Get},43};44pub use pallet::*;45use sp_runtime::{46 Perbill,47 traits::{BlockNumberProvider},48};4950use sp_std::convert::TryInto;5152type BalanceOf<T> =53 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;5455pub const YEAR: u32 = 5_259_600; // 6-second block56 // pub const YEAR: u32 = 2_629_800; // 12-second block57pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;58pub const START_INFLATION_PERCENT: u32 = 10;59pub const END_INFLATION_PERCENT: u32 = 4;6061#[frame_support::pallet]62pub mod pallet {63 use super::*;64 use frame_support::pallet_prelude::*;65 use frame_system::pallet_prelude::*;6667 #[pallet::config]68 pub trait Config: frame_system::Config {69 type Currency: Currency<Self::AccountId>;70 type TreasuryAccountId: Get<Self::AccountId>;7172 // The block number provider73 type BlockNumberProvider: BlockNumberProvider<BlockNumber = Self::BlockNumber>;7475 /// Number of blocks that pass between treasury balance updates due to inflation76 #[pallet::constant]77 type InflationBlockInterval: Get<Self::BlockNumber>;78 }7980 #[pallet::pallet]81 pub struct Pallet<T>(_);8283 /// starting year total issuance84 #[pallet::storage]85 pub type StartingYearTotalIssuance<T: Config> =86 StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;8788 /// Current inflation for `InflationBlockInterval` number of blocks89 #[pallet::storage]90 pub type BlockInflation<T: Config> = StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;9192 /// Next target (relay) block when inflation will be applied93 #[pallet::storage]94 pub type NextInflationBlock<T: Config> =95 StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;9697 /// Next target (relay) block when inflation is recalculated98 #[pallet::storage]99 pub type NextRecalculationBlock<T: Config> =100 StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;101102 /// Relay block when inflation has started103 #[pallet::storage]104 pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;105106 #[pallet::hooks]107 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {108 fn on_initialize(_: T::BlockNumber) -> Weight109 where110 <T as frame_system::Config>::BlockNumber: From<u32>,111 {112 let mut consumed_weight = Weight::zero();113 let mut add_weight = |reads, writes, weight| {114 consumed_weight += T::DbWeight::get().reads_writes(reads, writes);115 consumed_weight += weight;116 };117118 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);119 let current_relay_block = T::BlockNumberProvider::current_block_number();120 let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();121 add_weight(1, 0, Weight::from_parts(5_000_000, 0));122123 // Apply inflation every InflationBlockInterval blocks124 // If next_inflation == 0, this means inflation wasn't yet initialized125 if (next_inflation != 0u32.into()) && (current_relay_block >= next_inflation) {126 // Recalculate inflation on the first block of the year (or if it is not initialized yet)127 // Do the "current_relay_block >= next_recalculation" check in the "current_relay_block >= next_inflation"128 // block because it saves InflationBlockInterval DB reads for NextRecalculationBlock.129 let next_recalculation: T::BlockNumber = <NextRecalculationBlock<T>>::get();130 add_weight(1, 0, Weight::zero());131 if current_relay_block >= next_recalculation {132 Self::recalculate_inflation(next_recalculation);133 add_weight(0, 4, Weight::from_parts(5_000_000, 0));134 }135136 T::Currency::deposit_into_existing(137 &T::TreasuryAccountId::get(),138 <BlockInflation<T>>::get(),139 )140 .ok();141142 // Update inflation block143 <NextInflationBlock<T>>::set(next_inflation + block_interval.into());144145 add_weight(3, 3, Weight::from_parts(10_000_000, 0));146 }147148 consumed_weight149 }150 }151152 #[pallet::call]153 impl<T: Config> Pallet<T> {154 /// This method sets the inflation start date. Can be only called once.155 /// Inflation start block can be backdated and will catch up. The method will create Treasury156 /// account if it does not exist and perform the first inflation deposit.157 ///158 /// # Permissions159 ///160 /// * Root161 ///162 /// # Arguments163 ///164 /// * inflation_start_relay_block: The relay chain block at which inflation should start165 #[pallet::call_index(0)]166 #[pallet::weight(0)]167 pub fn start_inflation(168 origin: OriginFor<T>,169 inflation_start_relay_block: T::BlockNumber,170 ) -> DispatchResult171 where172 <T as frame_system::Config>::BlockNumber: From<u32>,173 {174 ensure_root(origin)?;175176 // Start inflation if it has not been yet initialized177 if <StartBlock<T>>::get() == 0u32.into() {178 // Set inflation global start block179 <StartBlock<T>>::set(inflation_start_relay_block);180181 // Recalculate inflation. This can be backdated and will catch up.182 Self::recalculate_inflation(inflation_start_relay_block);183 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);184 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());185186 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else187 T::Currency::deposit_creating(188 &T::TreasuryAccountId::get(),189 <BlockInflation<T>>::get(),190 );191 }192193 Ok(())194 }195 }196}197198impl<T: Config> Pallet<T> {199 pub fn recalculate_inflation(recalculation_block: T::BlockNumber) {200 let current_year: u32 = ((recalculation_block - <StartBlock<T>>::get())201 / T::BlockNumber::from(YEAR))202 .try_into()203 .unwrap_or(0);204 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);205206 let one_percent = Perbill::from_percent(1);207208 if current_year <= TOTAL_YEARS_UNTIL_FLAT {209 let amount: BalanceOf<T> = Perbill::from_rational(210 block_interval211 * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT212 - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)),213 YEAR * TOTAL_YEARS_UNTIL_FLAT,214 ) * (one_percent * T::Currency::total_issuance());215 <BlockInflation<T>>::put(amount);216 } else {217 let amount: BalanceOf<T> =218 Perbill::from_rational(block_interval * END_INFLATION_PERCENT, YEAR)219 * (one_percent * T::Currency::total_issuance());220 <BlockInflation<T>>::put(amount);221 }222 <StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());223224 // Update recalculation and inflation blocks225 <NextRecalculationBlock<T>>::set(recalculation_block + YEAR.into());226 }227}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Inflation18//!19//! The inflation pallet is designed to increase the number of tokens at certain intervals.20//! With each iteration, increases the `total_issuance` value for the native token.21//! Executing an `on_initialize` hook at the beginning of each block, causing inflation to begin.22//!23//! ## Interface24//!25//! ### Dispatchable Functions26//!27//! * `start_inflation` - This method sets the inflation start date. Can be only called once.28//! Inflation start block can be backdated and will catch up. The method will create Treasury29//! account if it does not exist and perform the first inflation deposit.3031// #![recursion_limit = "1024"]32#![cfg_attr(not(feature = "std"), no_std)]3334#[cfg(feature = "runtime-benchmarks")]35mod benchmarking;3637#[cfg(test)]38mod tests;3940use frame_support::{41 dispatch::{DispatchResult},42 traits::{43 fungible::{Balanced, Inspect, Mutate},44 Get, Imbalance,45 tokens::Precision,46 },47};48pub use pallet::*;49use sp_runtime::{50 Perbill,51 traits::{BlockNumberProvider, Zero},52};5354use sp_std::convert::TryInto;5556type BalanceOf<T> =57 <<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;5859pub const YEAR: u32 = 5_259_600; // 6-second block60 // pub const YEAR: u32 = 2_629_800; // 12-second block61pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;62pub const START_INFLATION_PERCENT: u32 = 10;63pub const END_INFLATION_PERCENT: u32 = 4;6465#[frame_support::pallet]66pub mod pallet {67 use super::*;68 use frame_support::pallet_prelude::*;69 use frame_system::pallet_prelude::*;7071 #[pallet::config]72 pub trait Config: frame_system::Config {73 type Currency: Balanced<Self::AccountId>74 + Inspect<Self::AccountId>75 + Mutate<Self::AccountId>;76 type TreasuryAccountId: Get<Self::AccountId>;7778 // The block number provider79 type BlockNumberProvider: BlockNumberProvider<BlockNumber = Self::BlockNumber>;8081 /// Number of blocks that pass between treasury balance updates due to inflation82 #[pallet::constant]83 type InflationBlockInterval: Get<Self::BlockNumber>;84 }8586 #[pallet::pallet]87 pub struct Pallet<T>(_);8889 /// starting year total issuance90 #[pallet::storage]91 pub type StartingYearTotalIssuance<T: Config> =92 StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;9394 /// Current inflation for `InflationBlockInterval` number of blocks95 #[pallet::storage]96 pub type BlockInflation<T: Config> = StorageValue<Value = BalanceOf<T>, QueryKind = ValueQuery>;9798 /// Next target (relay) block when inflation will be applied99 #[pallet::storage]100 pub type NextInflationBlock<T: Config> =101 StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;102103 /// Next target (relay) block when inflation is recalculated104 #[pallet::storage]105 pub type NextRecalculationBlock<T: Config> =106 StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;107108 /// Relay block when inflation has started109 #[pallet::storage]110 pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;111112 #[pallet::hooks]113 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {114 fn on_initialize(_: T::BlockNumber) -> Weight115 where116 <T as frame_system::Config>::BlockNumber: From<u32>,117 {118 let mut consumed_weight = Weight::zero();119 let mut add_weight = |reads, writes, weight| {120 consumed_weight += T::DbWeight::get().reads_writes(reads, writes);121 consumed_weight += weight;122 };123124 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);125 let current_relay_block = T::BlockNumberProvider::current_block_number();126 let next_inflation: T::BlockNumber = <NextInflationBlock<T>>::get();127 add_weight(1, 0, Weight::from_parts(5_000_000, 0));128129 // Apply inflation every InflationBlockInterval blocks130 // If next_inflation == 0, this means inflation wasn't yet initialized131 if (next_inflation != 0u32.into()) && (current_relay_block >= next_inflation) {132 // Recalculate inflation on the first block of the year (or if it is not initialized yet)133 // Do the "current_relay_block >= next_recalculation" check in the "current_relay_block >= next_inflation"134 // block because it saves InflationBlockInterval DB reads for NextRecalculationBlock.135 let next_recalculation: T::BlockNumber = <NextRecalculationBlock<T>>::get();136 add_weight(1, 0, Weight::zero());137 if current_relay_block >= next_recalculation {138 Self::recalculate_inflation(next_recalculation);139 add_weight(0, 4, Weight::from_parts(5_000_000, 0));140 }141142 T::Currency::mint_into(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get())143 .ok();144145 // Update inflation block146 <NextInflationBlock<T>>::set(next_inflation + block_interval.into());147148 add_weight(3, 3, Weight::from_parts(10_000_000, 0));149 }150151 consumed_weight152 }153 }154155 #[pallet::call]156 impl<T: Config> Pallet<T> {157 /// This method sets the inflation start date. Can be only called once.158 /// Inflation start block can be backdated and will catch up. The method will create Treasury159 /// account if it does not exist and perform the first inflation deposit.160 ///161 /// # Permissions162 ///163 /// * Root164 ///165 /// # Arguments166 ///167 /// * inflation_start_relay_block: The relay chain block at which inflation should start168 #[pallet::call_index(0)]169 #[pallet::weight(0)]170 pub fn start_inflation(171 origin: OriginFor<T>,172 inflation_start_relay_block: T::BlockNumber,173 ) -> DispatchResult174 where175 <T as frame_system::Config>::BlockNumber: From<u32>,176 {177 ensure_root(origin)?;178179 // Start inflation if it has not been yet initialized180 if <StartBlock<T>>::get() == 0u32.into() {181 // Set inflation global start block182 <StartBlock<T>>::set(inflation_start_relay_block);183184 // Recalculate inflation. This can be backdated and will catch up.185 Self::recalculate_inflation(inflation_start_relay_block);186 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);187 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());188189 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else190 let imbalance = T::Currency::deposit(191 &T::TreasuryAccountId::get(),192 <BlockInflation<T>>::get(),193 Precision::Exact,194 )?;195 debug_assert!(imbalance.peek().is_zero());196 }197198 Ok(())199 }200 }201}202203impl<T: Config> Pallet<T> {204 pub fn recalculate_inflation(recalculation_block: T::BlockNumber) {205 let current_year: u32 = ((recalculation_block - <StartBlock<T>>::get())206 / T::BlockNumber::from(YEAR))207 .try_into()208 .unwrap_or(0);209 let block_interval: u32 = T::InflationBlockInterval::get().try_into().unwrap_or(0);210211 let one_percent = Perbill::from_percent(1);212213 if current_year <= TOTAL_YEARS_UNTIL_FLAT {214 let amount: BalanceOf<T> = Perbill::from_rational(215 block_interval216 * (START_INFLATION_PERCENT * TOTAL_YEARS_UNTIL_FLAT217 - current_year * (START_INFLATION_PERCENT - END_INFLATION_PERCENT)),218 YEAR * TOTAL_YEARS_UNTIL_FLAT,219 ) * (one_percent * T::Currency::total_issuance());220 <BlockInflation<T>>::put(amount);221 } else {222 let amount: BalanceOf<T> =223 Perbill::from_rational(block_interval * END_INFLATION_PERCENT, YEAR)224 * (one_percent * T::Currency::total_issuance());225 <BlockInflation<T>>::put(amount);226 }227 <StartingYearTotalIssuance<T>>::set(T::Currency::total_issuance());228229 // Update recalculation and inflation blocks230 <NextRecalculationBlock<T>>::set(recalculation_block + YEAR.into());231 }232}pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -17,7 +17,7 @@
use super::*;
use frame_benchmarking::{benchmarks, account};
-use frame_support::traits::{Currency, Get};
+use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
use up_data_structs::{
CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,
budget::Unlimited,
@@ -32,7 +32,7 @@
let caller: T::AccountId = account("caller", 0, SEED);
let caller_cross = T::CrossAccountId::from_sub(caller.clone());
- <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
+ let _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
T::CollectionDispatch::create(
caller_cross.clone(),
caller_cross.clone(),
pallets/unique/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/unique/src/benchmarking.rs
+++ b/pallets/unique/src/benchmarking.rs
@@ -19,7 +19,7 @@
use super::*;
use crate::Pallet;
use frame_system::RawOrigin;
-use frame_support::traits::{tokens::currency::Currency, Get};
+use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
use frame_benchmarking::{benchmarks, account};
use sp_runtime::DispatchError;
use pallet_common::{
@@ -38,7 +38,12 @@
owner: T::AccountId,
mode: CollectionMode,
) -> Result<CollectionId, DispatchError> {
- <T as CommonConfig>::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
+ let _ = <T as CommonConfig>::Currency::deposit(
+ &owner,
+ T::CollectionCreationPrice::get(),
+ Precision::Exact,
+ )
+ .unwrap();
let col_name = create_u16_data::<{ MAX_COLLECTION_NAME_LENGTH }>();
let col_desc = create_u16_data::<{ MAX_COLLECTION_DESCRIPTION_LENGTH }>();
let token_prefix = create_data::<{ MAX_TOKEN_PREFIX_LENGTH }>();
@@ -64,7 +69,7 @@
let token_prefix = create_data::<{MAX_TOKEN_PREFIX_LENGTH}>();
let mode: CollectionMode = CollectionMode::NFT;
let caller: T::AccountId = account("caller", 0, SEED);
- <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
+ let _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
}: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)
verify {
assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);