git.delta.rocks / unique-network / refs/commits / 87f464dc41c1

difftreelog

feat switch `inflation` from `Currency` trait to `fungible::*` traits fix: benchmarks

Grigoriy Simonov2023-05-23parent: #d516d14.patch.diff
in: master

5 files changed

modifiedpallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth
33where33where
34 T: Config + pallet_unique::Config + pallet_evm_migration::Config,34 T: Config + pallet_unique::Config + pallet_evm_migration::Config,
35 T::BlockNumber: From<u32> + Into<u32>,35 T::BlockNumber: From<u32> + Into<u32>,
36 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>,36 BalanceOf<T>: Sum + From<u128>,
37{37{
38 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);38 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
3939
40 <T as Config>::Currency::make_free_balance_be(40 <T as Config>::Currency::set_balance(
41 &pallet_admin,41 &pallet_admin,
42 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),42 Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value(),
43 );43 );
54 where_clause{54 where_clause{
55 where T: Config + pallet_unique::Config + pallet_evm_migration::Config ,55 where T: Config + pallet_unique::Config + pallet_evm_migration::Config ,
56 T::BlockNumber: From<u32> + Into<u32>,56 T::BlockNumber: From<u32> + Into<u32>,
57 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>57 BalanceOf<T>: Sum + From<u128>
58 }58 }
5959
60 on_initialize {60 on_initialize {
6363
64 (0..b).try_for_each(|index| {64 (0..b).try_for_each(|index| {
65 let staker = account::<T::AccountId>("staker", index, SEED);65 let staker = account::<T::AccountId>("staker", index, SEED);
66 <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());66 <T as Config>::Currency::set_balance(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
67 PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())?;67 PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())?;
68 PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker.clone()).into())?;68 PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker.clone()).into())?;
69 Result::<(), sp_runtime::DispatchError>::Ok(())69 Result::<(), sp_runtime::DispatchError>::Ok(())
7373
74 set_admin_address {74 set_admin_address {
75 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);75 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
76 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());76 let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
77 } : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin))77 } : _(RawOrigin::Root, T::CrossAccountId::from_sub(pallet_admin))
7878
79 payout_stakers{79 payout_stakers{
82 let pallet_admin = account::<T::AccountId>("admin", 1, SEED);82 let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
83 let share = Perbill::from_rational(1u32, 20);83 let share = Perbill::from_rational(1u32, 20);
84 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;84 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
85 <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());85 <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
86 <T as Config>::Currency::make_free_balance_be(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());86 <T as Config>::Currency::set_balance(&<T as pallet::Config>::TreasuryAccountId::get(), Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
8787
88 let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();88 let stakers: Vec<T::AccountId> = (0..b).map(|index| account("staker", index, SEED)).collect();
89 stakers.iter().for_each(|staker| {89 stakers.iter().for_each(|staker| {
90 <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());90 <T as Config>::Currency::set_balance(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
91 });91 });
92 (1..11).try_for_each(|i| {92 (1..11).try_for_each(|i| {
93 <frame_system::Pallet<T>>::set_block_number(i.into());93 <frame_system::Pallet<T>>::set_block_number(i.into());
112 stake {112 stake {
113 let caller = account::<T::AccountId>("caller", 0, SEED);113 let caller = account::<T::AccountId>("caller", 0, SEED);
114 let share = Perbill::from_rational(1u32, 10);114 let share = Perbill::from_rational(1u32, 10);
115 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());115 let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
116 } : _(RawOrigin::Signed(caller.clone()), share * <T as Config>::Currency::total_balance(&caller))116 } : _(RawOrigin::Signed(caller.clone()), share * <T as Config>::Currency::total_balance(&caller))
117117
118 unstake_all {118 unstake_all {
119 let caller = account::<T::AccountId>("caller", 0, SEED);119 let caller = account::<T::AccountId>("caller", 0, SEED);
120 let share = Perbill::from_rational(1u32, 20);120 let share = Perbill::from_rational(1u32, 20);
121 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());121 let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
122 (1..11).map(|i| {122 (1..11).map(|i| {
123 // used to change block number123 // used to change block number
124 <frame_system::Pallet<T>>::set_block_number(i.into());124 <frame_system::Pallet<T>>::set_block_number(i.into());
133 unstake_partial {133 unstake_partial {
134 let caller = account::<T::AccountId>("caller", 0, SEED);134 let caller = account::<T::AccountId>("caller", 0, SEED);
135 let share = Perbill::from_rational(1u32, 20);135 let share = Perbill::from_rational(1u32, 20);
136 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());136 let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
137 (1..11).map(|i| {137 (1..11).map(|i| {
138 // used to change block number138 // used to change block number
139 <frame_system::Pallet<T>>::set_block_number(i.into());139 <frame_system::Pallet<T>>::set_block_number(i.into());
148 sponsor_collection {148 sponsor_collection {
149 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);149 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
150 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;150 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
151 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());151 let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
152 let caller: T::AccountId = account("caller", 0, SEED);152 let caller: T::AccountId = account("caller", 0, SEED);
153 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());153 let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
154 let collection = create_nft_collection::<T>(caller.clone())?;154 let collection = create_nft_collection::<T>(caller.clone())?;
155 } : _(RawOrigin::Signed(pallet_admin.clone()), collection)155 } : _(RawOrigin::Signed(pallet_admin.clone()), collection)
156156
157 stop_sponsoring_collection {157 stop_sponsoring_collection {
158 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);158 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
159 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;159 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
160 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());160 let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
161 let caller: T::AccountId = account("caller", 0, SEED);161 let caller: T::AccountId = account("caller", 0, SEED);
162 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());162 let _ = <T as Config>::Currency::set_balance(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
163 let collection = create_nft_collection::<T>(caller.clone())?;163 let collection = create_nft_collection::<T>(caller.clone())?;
164 PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;164 PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;
165 } : _(RawOrigin::Signed(pallet_admin.clone()), collection)165 } : _(RawOrigin::Signed(pallet_admin.clone()), collection)
168 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);168 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
169 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;169 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
170170
171 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());171 let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
172 let address = H160::from_low_u64_be(SEED as u64);172 let address = H160::from_low_u64_be(SEED as u64);
173 let data: Vec<u8> = (0..20 as u8).collect();173 let data: Vec<u8> = (0..20 as u8).collect();
174 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;174 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
179 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);179 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
180 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;180 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
181181
182 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());182 let _ = <T as Config>::Currency::set_balance(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
183 let address = H160::from_low_u64_be(SEED as u64);183 let address = H160::from_low_u64_be(SEED as u64);
184 let data: Vec<u8> = (0..20 as u8).collect();184 let data: Vec<u8> = (0..20 as u8).collect();
185 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;185 <EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;
modifiedpallets/configuration/src/benchmarking.rsdiffbeforeafterboth
68 }68 }
6969
70 set_collator_selection_license_bond {70 set_collator_selection_license_bond {
71 let bond_cost: Option<BalanceOf<T>> = Some(T::Balances::minimum_balance() * 10u32.into());71 let bond_cost: Option<BalanceOf<T>> = Some(T::Currency::minimum_balance() * 10u32.into());
72 }: {72 }: {
73 assert_ok!(73 assert_ok!(
74 <Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost.clone())74 <Pallet<T>>::set_collator_selection_license_bond(RawOrigin::Root.into(), bond_cost.clone())
modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
3939
40use frame_support::{40use frame_support::{
41 dispatch::{DispatchResult},41 dispatch::{DispatchResult},
42 traits::{Currency, Get},42 traits::{
43 fungible::{Balanced, Inspect, Mutate},
44 Get, Imbalance,
45 tokens::Precision,
46 },
43};47};
44pub use pallet::*;48pub use pallet::*;
45use sp_runtime::{49use sp_runtime::{
46 Perbill,50 Perbill,
47 traits::{BlockNumberProvider},51 traits::{BlockNumberProvider, Zero},
48};52};
4953
50use sp_std::convert::TryInto;54use sp_std::convert::TryInto;
5155
52type BalanceOf<T> =56type BalanceOf<T> =
53 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;57 <<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;
5458
55pub const YEAR: u32 = 5_259_600; // 6-second block59pub const YEAR: u32 = 5_259_600; // 6-second block
56 // pub const YEAR: u32 = 2_629_800; // 12-second block60 // pub const YEAR: u32 = 2_629_800; // 12-second block
6670
67 #[pallet::config]71 #[pallet::config]
68 pub trait Config: frame_system::Config {72 pub trait Config: frame_system::Config {
69 type Currency: Currency<Self::AccountId>;73 type Currency: Balanced<Self::AccountId>
74 + Inspect<Self::AccountId>
75 + Mutate<Self::AccountId>;
70 type TreasuryAccountId: Get<Self::AccountId>;76 type TreasuryAccountId: Get<Self::AccountId>;
7177
72 // The block number provider78 // The block number provider
133 add_weight(0, 4, Weight::from_parts(5_000_000, 0));139 add_weight(0, 4, Weight::from_parts(5_000_000, 0));
134 }140 }
135141
136 T::Currency::deposit_into_existing(142 T::Currency::mint_into(&T::TreasuryAccountId::get(), <BlockInflation<T>>::get())
137 &T::TreasuryAccountId::get(),
138 <BlockInflation<T>>::get(),
139 )
184 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());187 <NextInflationBlock<T>>::set(inflation_start_relay_block + block_interval.into());
185188
186 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else189 // First time deposit - create Treasury account so that we can call deposit_into_existing everywhere else
187 T::Currency::deposit_creating(190 let imbalance = T::Currency::deposit(
188 &T::TreasuryAccountId::get(),191 &T::TreasuryAccountId::get(),
189 <BlockInflation<T>>::get(),192 <BlockInflation<T>>::get(),
193 Precision::Exact,
190 );194 )?;
195 debug_assert!(imbalance.peek().is_zero());
191 }196 }
192197
193 Ok(())198 Ok(())
modifiedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
17use super::*;17use super::*;
1818
19use frame_benchmarking::{benchmarks, account};19use frame_benchmarking::{benchmarks, account};
20use frame_support::traits::{Currency, Get};20use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
21use up_data_structs::{21use up_data_structs::{
22 CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,22 CreateCollectionData, CollectionMode, CreateItemData, CollectionFlags, CreateNftData,
23 budget::Unlimited,23 budget::Unlimited,
32 let caller: T::AccountId = account("caller", 0, SEED);32 let caller: T::AccountId = account("caller", 0, SEED);
33 let caller_cross = T::CrossAccountId::from_sub(caller.clone());33 let caller_cross = T::CrossAccountId::from_sub(caller.clone());
3434
35 <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());35 let _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
36 T::CollectionDispatch::create(36 T::CollectionDispatch::create(
37 caller_cross.clone(),37 caller_cross.clone(),
38 caller_cross.clone(),38 caller_cross.clone(),
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
19use super::*;19use super::*;
20use crate::Pallet;20use crate::Pallet;
21use frame_system::RawOrigin;21use frame_system::RawOrigin;
22use frame_support::traits::{tokens::currency::Currency, Get};22use frame_support::traits::{fungible::Balanced, Get, tokens::Precision};
23use frame_benchmarking::{benchmarks, account};23use frame_benchmarking::{benchmarks, account};
24use sp_runtime::DispatchError;24use sp_runtime::DispatchError;
25use pallet_common::{25use pallet_common::{
38 owner: T::AccountId,38 owner: T::AccountId,
39 mode: CollectionMode,39 mode: CollectionMode,
40) -> Result<CollectionId, DispatchError> {40) -> Result<CollectionId, DispatchError> {
41 <T as CommonConfig>::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());41 let _ = <T as CommonConfig>::Currency::deposit(
42 &owner,
43 T::CollectionCreationPrice::get(),
44 Precision::Exact,
45 )
46 .unwrap();
42 let col_name = create_u16_data::<{ MAX_COLLECTION_NAME_LENGTH }>();47 let col_name = create_u16_data::<{ MAX_COLLECTION_NAME_LENGTH }>();
43 let col_desc = create_u16_data::<{ MAX_COLLECTION_DESCRIPTION_LENGTH }>();48 let col_desc = create_u16_data::<{ MAX_COLLECTION_DESCRIPTION_LENGTH }>();
44 let token_prefix = create_data::<{ MAX_TOKEN_PREFIX_LENGTH }>();49 let token_prefix = create_data::<{ MAX_TOKEN_PREFIX_LENGTH }>();
64 let token_prefix = create_data::<{MAX_TOKEN_PREFIX_LENGTH}>();69 let token_prefix = create_data::<{MAX_TOKEN_PREFIX_LENGTH}>();
65 let mode: CollectionMode = CollectionMode::NFT;70 let mode: CollectionMode = CollectionMode::NFT;
66 let caller: T::AccountId = account("caller", 0, SEED);71 let caller: T::AccountId = account("caller", 0, SEED);
67 <T as CommonConfig>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());72 let _ = <T as CommonConfig>::Currency::deposit(&caller, T::CollectionCreationPrice::get(), Precision::Exact).unwrap();
68 }: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)73 }: _(RawOrigin::Signed(caller.clone()), col_name.clone(), col_desc.clone(), token_prefix.clone(), mode)
69 verify {74 verify {
70 assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);75 assert_eq!(<pallet_common::CollectionById<T>>::get(CollectionId(1)).unwrap().owner, caller);