difftreelog
refac(app-promo): impl for `unstake_all` & `unstake_partial` extrinsics
in: master
Added benchmark for `unstake_partial` extrinsic
7 files changed
Cargo.lockdiffbeforeafterboth578257825783[[package]]5783[[package]]5784name = "pallet-app-promotion"5784name = "pallet-app-promotion"5785version = "0.1.4"5785version = "0.1.5"5786dependencies = [5786dependencies = [5787 "frame-benchmarking",5787 "frame-benchmarking",5788 "frame-support",5788 "frame-support",pallets/app-promotion/CHANGELOG.mddiffbeforeafterboth445<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->667## [0.1.5] - 2023-02-1489### Added1011- `unstake_partial` extrinsic.127## [0.1.4] - 2023-01-3113## [0.1.4] - 2023-01-318149### Changed15### Changedpallets/app-promotion/Cargo.tomldiffbeforeafterboth9license = 'GPLv3'9license = 'GPLv3'10name = 'pallet-app-promotion'10name = 'pallet-app-promotion'11repository = 'https://github.com/UniqueNetwork/unique-chain'11repository = 'https://github.com/UniqueNetwork/unique-chain'12version = '0.1.4'12version = '0.1.5'131314[package.metadata.docs.rs]14[package.metadata.docs.rs]15targets = ['x86_64-unknown-linux-gnu']15targets = ['x86_64-unknown-linux-gnu']pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth65 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::make_free_balance_be(&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(RawOrigin::Signed(staker.clone()).into()).map_err(|e| e.error)?;68 PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker.clone()).into()).map_err(|e| e.error)?;69 Result::<(), sp_runtime::DispatchError>::Ok(())69 Result::<(), sp_runtime::DispatchError>::Ok(())70 })?;70 })?;71 let block_number = <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();71 let block_number = <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();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::make_free_balance_be(&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))117117118 unstake {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::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());130130131 } : _(RawOrigin::Signed(caller.clone()))131 } : _(RawOrigin::Signed(caller.clone()))132133 unstake_partial {134 let caller = account::<T::AccountId>("caller", 0, SEED);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());137 (1..11).map(|i| {138 // used to change block number139 <frame_system::Pallet<T>>::set_block_number(i.into());140 T::RelayBlockNumberProvider::set_block_number((2*i).into());141 assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());142 assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());143 PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())144 }).collect::<Result<Vec<_>, _>>()?;145146 } : _(RawOrigin::Signed(caller.clone()), Into::<BalanceOf<T>>::into(1000u128) * T::Nominal::get())132147133 sponsor_collection {148 sponsor_collection {134 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);149 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);pallets/app-promotion/src/lib.rsdiffbeforeafterboth208 SponsorNotSet,208 SponsorNotSet,209 /// Errors caused by incorrect actions with a locked balance.209 /// Errors caused by incorrect actions with a locked balance.210 IncorrectLockedBalanceOperation,210 IncorrectLockedBalanceOperation,211 /// Errors caused by insufficient staked balance.212 InsufficientStakedBalance,211 }213 }212214213 /// Stores the total staked amount.215 /// Stores the total staked amount.489 }491 }490492491 /// Unstakes all stakes.493 /// Unstakes all stakes.492 /// Moves the sum of all stakes to the `reserved` state.493 /// After the end of `PendingInterval` this sum becomes completely494 /// After the end of `PendingInterval` this sum becomes completely494 /// free for further use.495 /// free for further use.495 #[pallet::call_index(2)]496 #[pallet::call_index(2)]496 #[pallet::weight(<T as Config>::WeightInfo::unstake())]497 #[pallet::weight(<T as Config>::WeightInfo::unstake_all())]497 pub fn unstake_all(staker: OriginFor<T>) -> DispatchResultWithPostInfo {498 pub fn unstake_all(staker: OriginFor<T>) -> DispatchResult {498 let staker_id = ensure_signed(staker)?;499 let staker_id = ensure_signed(staker)?;499 let config = <PalletConfiguration<T>>::get();500501 // calculate block number where the sum would be free502 let block = <frame_system::Pallet<T>>::block_number() + config.pending_interval;503504 let mut pendings = <PendingUnstake<T>>::get(block);505506 // checks that we can do unreserve stakes in the block507 ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);508509 let mut total_stakes = 0u64;510511 let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))512 .map(|(_, (amount, _))| {513 total_stakes += 1;514 amount515 })516 .sum();517518 if total_staked.is_zero() {519 return Ok(None::<Weight>.into()); // TO-DO520 }521522 pendings523 .try_push((staker_id.clone(), total_staked))524 .map_err(|_| Error::<T>::PendingForBlockOverflow)?;525526 <PendingUnstake<T>>::insert(block, pendings);527528 TotalStaked::<T>::set(529 TotalStaked::<T>::get()530 .checked_sub(&total_staked)531 .ok_or(ArithmeticError::Underflow)?,532 );533534 StakesPerAccount::<T>::remove(&staker_id);535500536 Self::deposit_event(Event::Unstake(staker_id, total_staked));501 Self::unstake_all_internal(staker_id)537538 Ok(None::<Weight>.into())539 }502 }540503541 /// Unstakes all stakes.504 /// Unstakes the amount of balance for the staker.542 /// Moves the sum of all stakes to the `reserved` state.543 /// After the end of `PendingInterval` this sum becomes completely505 /// After the end of `PendingInterval` this sum becomes completely544 /// free for further use.506 /// free for further use.507 ///508 /// # Arguments509 ///510 /// * `staker`: staker account.511 /// * `amount`: amount of unstaked funds.545 #[pallet::call_index(8)]512 #[pallet::call_index(8)]546 #[pallet::weight(<T as Config>::WeightInfo::unstake())]513 #[pallet::weight(<T as Config>::WeightInfo::unstake_partial())]547 pub fn unstake_partial(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {514 pub fn unstake_partial(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {548 let staker_id = ensure_signed(staker)?;515 let staker_id = ensure_signed(staker)?;549516550 Self::partial_unstake(&staker_id, amount)517 Self::unstake_partial_internal(staker_id, amount)551 }518 }552519553 /// Sets the pallet to be the sponsor for the collection.520 /// Sets the pallet to be the sponsor for the collection.821 T::PalletId::get().into_account_truncating()788 T::PalletId::get().into_account_truncating()822 }789 }823790791 /// Unstakes the balance for the staker.792 ///793 /// - `staker`: staker account.794 /// - `amount`: amount of unstaked funds.824 fn partial_unstake(staker_id: &T::AccountId, unstaked_balance: BalanceOf<T>) -> DispatchResult {795 fn unstake_partial_internal(825 796 staker_id: T::AccountId,797 unstaked_balance: BalanceOf<T>,798 ) -> DispatchResult {826 if unstaked_balance == Default::default() {799 if unstaked_balance == Default::default() {827 return Ok(());800 return Ok(());837 // checks that we can do unreserve stakes in the block810 // checks that we can do unreserve stakes in the block838 ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);811 ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);839812840 let mut stakes = Staked::<T>::iter_prefix((staker_id,)).collect::<Vec<_>>();813 let mut stakes = Staked::<T>::iter_prefix((&staker_id,)).collect::<Vec<_>>();841814842 let total_staked = stakes815 let total_staked = stakes843 .iter()816 .iter()844 .fold(<BalanceOf<T>>::default(), |acc, (_, (balance, _))| {817 .fold(<BalanceOf<T>>::default(), |acc, (_, (balance, _))| {845 acc + *balance818 acc + *balance846 });819 });847820848 ensure!(total_staked >= unstaked_balance, ArithmeticError::Underflow);821 ensure!(822 total_staked >= unstaked_balance,823 <Error<T>>::InsufficientStakedBalance824 );849825850 <TotalStaked<T>>::set(826 <TotalStaked<T>>::set(880 .try_push((staker_id.clone(), unstaked_balance))856 .try_push((staker_id.clone(), unstaked_balance))881 .map_err(|_| Error::<T>::PendingForBlockOverflow)?;857 .map_err(|_| Error::<T>::PendingForBlockOverflow)?;882858883 StakesPerAccount::<T>::try_mutate(staker_id, |stakes| -> DispatchResult {859 StakesPerAccount::<T>::try_mutate(&staker_id, |stakes| -> DispatchResult {884 *stakes = stakes860 *stakes = stakes885 .checked_sub(will_deleted_stakes_count)861 .checked_sub(will_deleted_stakes_count)886 .ok_or(ArithmeticError::Underflow)?;862 .ok_or(ArithmeticError::Underflow)?;891 .iter()867 .iter()892 .for_each(|(staked_block, (current_stake_state, _))| {868 .for_each(|(staked_block, (current_stake_state, _))| {893 if current_stake_state == &Default::default() {869 if current_stake_state == &Default::default() {894 <Staked<T>>::remove((staker_id, staked_block));870 <Staked<T>>::remove((&staker_id, staked_block));895 } else {871 } else {896 <Staked<T>>::mutate((staker_id, staked_block), |(old_stake_state, _)| {872 <Staked<T>>::mutate((&staker_id, staked_block), |(old_stake_state, _)| {897 *old_stake_state = *current_stake_state873 *old_stake_state = *current_stake_state898 });874 });899 }875 }900 });876 });901877902 <PendingUnstake<T>>::insert(unpending_block, pendings);878 <PendingUnstake<T>>::insert(unpending_block, pendings);903879904 Self::deposit_event(Event::Unstake(staker_id.clone(), total_staked));880 Self::deposit_event(Event::Unstake(staker_id, total_staked));905881906 Ok(())882 Ok(())907 }883 }1103 unsorted_res1079 unsorted_res1104 }1080 }10811082 fn unstake_all_internal(staker_id: T::AccountId) -> DispatchResult {1083 let config = <PalletConfiguration<T>>::get();10841085 // calculate block number where the sum would be free1086 let block = <frame_system::Pallet<T>>::block_number() + config.pending_interval;10871088 let mut pendings = <PendingUnstake<T>>::get(block);10891090 // checks that we can do unreserve stakes in the block1091 ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);10921093 let mut total_stakes = 0u64;10941095 let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))1096 .map(|(_, (amount, _))| {1097 total_stakes += 1;1098 amount1099 })1100 .sum();11011102 if total_staked.is_zero() {1103 return Ok(());1104 }11051106 pendings1107 .try_push((staker_id.clone(), total_staked))1108 .map_err(|_| Error::<T>::PendingForBlockOverflow)?;11091110 <PendingUnstake<T>>::insert(block, pendings);11111112 TotalStaked::<T>::set(1113 TotalStaked::<T>::get()1114 .checked_sub(&total_staked)1115 .ok_or(ArithmeticError::Underflow)?,1116 );11171118 StakesPerAccount::<T>::remove(&staker_id);11191120 Self::deposit_event(Event::Unstake(staker_id, total_staked));11211122 Ok(())1123 }1105}1124}11061125pallets/app-promotion/src/weights.rsdiffbeforeafterboth3//! Autogenerated weights for pallet_app_promotion3//! Autogenerated weights for pallet_app_promotion4//!4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-12-25, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`6//! DATE: 2023-02-14, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 10247//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024889// Executed Command:9// Executed Command:38 fn set_admin_address() -> Weight;38 fn set_admin_address() -> Weight;39 fn payout_stakers(b: u32, ) -> Weight;39 fn payout_stakers(b: u32, ) -> Weight;40 fn stake() -> Weight;40 fn stake() -> Weight;41 fn unstake() -> Weight;41 fn unstake_all() -> Weight;42 fn unstake_partial() -> Weight;42 fn sponsor_collection() -> Weight;43 fn sponsor_collection() -> Weight;43 fn stop_sponsoring_collection() -> Weight;44 fn stop_sponsoring_collection() -> Weight;44 fn sponsor_contract() -> Weight;45 fn sponsor_contract() -> Weight;49pub struct SubstrateWeight<T>(PhantomData<T>);50pub struct SubstrateWeight<T>(PhantomData<T>);50impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {51impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {51 // Storage: AppPromotion PendingUnstake (r:1 w:0)52 // Storage: AppPromotion PendingUnstake (r:1 w:0)53 // Storage: Balances Locks (r:1 w:1)52 // Storage: System Account (r:1 w:1)54 // Storage: System Account (r:1 w:1)53 fn on_initialize(b: u32, ) -> Weight {55 fn on_initialize(b: u32, ) -> Weight {54 Weight::from_ref_time(3_079_948 as u64)56 Weight::from_ref_time(2_562_275 as u64)55 // Standard Error: 30_37657 // Standard Error: 21_95056 .saturating_add(Weight::from_ref_time(6_343_630 as u64).saturating_mul(b as u64))58 .saturating_add(Weight::from_ref_time(7_177_129 as u64).saturating_mul(b as u64))57 .saturating_add(T::DbWeight::get().reads(1 as u64))59 .saturating_add(T::DbWeight::get().reads(1 as u64))58 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(b as u64)))60 .saturating_add(T::DbWeight::get().reads((2 as u64).saturating_mul(b as u64)))59 .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(b as u64)))61 .saturating_add(T::DbWeight::get().writes((2 as u64).saturating_mul(b as u64)))60 }62 }61 // Storage: AppPromotion Admin (r:0 w:1)63 // Storage: AppPromotion Admin (r:0 w:1)62 fn set_admin_address() -> Weight {64 fn set_admin_address() -> Weight {63 Weight::from_ref_time(6_653_000 as u64)65 Weight::from_ref_time(6_146_000 as u64)64 .saturating_add(T::DbWeight::get().writes(1 as u64))66 .saturating_add(T::DbWeight::get().writes(1 as u64))65 }67 }66 // Storage: AppPromotion Admin (r:1 w:0)68 // Storage: AppPromotion Admin (r:1 w:0)72 // Storage: Balances Locks (r:1 w:1)74 // Storage: Balances Locks (r:1 w:1)73 // Storage: AppPromotion TotalStaked (r:1 w:1)75 // Storage: AppPromotion TotalStaked (r:1 w:1)74 fn payout_stakers(b: u32, ) -> Weight {76 fn payout_stakers(b: u32, ) -> Weight {75 Weight::from_ref_time(74_048_000 as u64)77 Weight::from_ref_time(64_035_000 as u64)76 // Standard Error: 33_22378 // Standard Error: 19_43477 .saturating_add(Weight::from_ref_time(57_702_092 as u64).saturating_mul(b as u64))79 .saturating_add(Weight::from_ref_time(47_251_111 as u64).saturating_mul(b as u64))78 .saturating_add(T::DbWeight::get().reads(7 as u64))80 .saturating_add(T::DbWeight::get().reads(7 as u64))79 .saturating_add(T::DbWeight::get().reads((12 as u64).saturating_mul(b as u64)))81 .saturating_add(T::DbWeight::get().reads((12 as u64).saturating_mul(b as u64)))80 .saturating_add(T::DbWeight::get().writes(3 as u64))82 .saturating_add(T::DbWeight::get().writes(3 as u64))88 // Storage: AppPromotion Staked (r:1 w:1)90 // Storage: AppPromotion Staked (r:1 w:1)89 // Storage: AppPromotion TotalStaked (r:1 w:1)91 // Storage: AppPromotion TotalStaked (r:1 w:1)90 fn stake() -> Weight {92 fn stake() -> Weight {91 Weight::from_ref_time(20_314_000 as u64)93 Weight::from_ref_time(18_078_000 as u64)92 .saturating_add(T::DbWeight::get().reads(7 as u64))94 .saturating_add(T::DbWeight::get().reads(7 as u64))93 .saturating_add(T::DbWeight::get().writes(5 as u64))95 .saturating_add(T::DbWeight::get().writes(5 as u64))94 }96 }95 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)97 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)96 // Storage: AppPromotion PendingUnstake (r:1 w:1)98 // Storage: AppPromotion PendingUnstake (r:1 w:1)97 // Storage: AppPromotion Staked (r:11 w:10)99 // Storage: AppPromotion Staked (r:11 w:10)98 // Storage: Balances Locks (r:1 w:1)99 // Storage: System Account (r:1 w:1)100 // Storage: AppPromotion TotalStaked (r:1 w:1)100 // Storage: AppPromotion TotalStaked (r:1 w:1)101 // Storage: AppPromotion StakesPerAccount (r:0 w:1)101 // Storage: AppPromotion StakesPerAccount (r:0 w:1)102 fn unstake() -> Weight {102 fn unstake_all() -> Weight {103 Weight::from_ref_time(64_582_000 as u64)103 Weight::from_ref_time(45_038_000 as u64)104 .saturating_add(T::DbWeight::get().reads(16 as u64))104 .saturating_add(T::DbWeight::get().reads(14 as u64))105 .saturating_add(T::DbWeight::get().writes(15 as u64))105 .saturating_add(T::DbWeight::get().writes(13 as u64))106 }106 }107 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)108 // Storage: AppPromotion PendingUnstake (r:1 w:1)109 // Storage: AppPromotion Staked (r:11 w:10)110 // Storage: AppPromotion TotalStaked (r:1 w:1)111 // Storage: AppPromotion StakesPerAccount (r:1 w:1)112 fn unstake_partial() -> Weight {113 Weight::from_ref_time(48_863_000 as u64)114 .saturating_add(T::DbWeight::get().reads(15 as u64))115 .saturating_add(T::DbWeight::get().writes(13 as u64))116 }107 // Storage: AppPromotion Admin (r:1 w:0)117 // Storage: AppPromotion Admin (r:1 w:0)108 // Storage: Common CollectionById (r:1 w:1)118 // Storage: Common CollectionById (r:1 w:1)109 fn sponsor_collection() -> Weight {119 fn sponsor_collection() -> Weight {110 Weight::from_ref_time(16_364_000 as u64)120 Weight::from_ref_time(14_808_000 as u64)111 .saturating_add(T::DbWeight::get().reads(2 as u64))121 .saturating_add(T::DbWeight::get().reads(2 as u64))112 .saturating_add(T::DbWeight::get().writes(1 as u64))122 .saturating_add(T::DbWeight::get().writes(1 as u64))113 }123 }114 // Storage: AppPromotion Admin (r:1 w:0)124 // Storage: AppPromotion Admin (r:1 w:0)115 // Storage: Common CollectionById (r:1 w:1)125 // Storage: Common CollectionById (r:1 w:1)116 fn stop_sponsoring_collection() -> Weight {126 fn stop_sponsoring_collection() -> Weight {117 Weight::from_ref_time(15_710_000 as u64)127 Weight::from_ref_time(14_587_000 as u64)118 .saturating_add(T::DbWeight::get().reads(2 as u64))128 .saturating_add(T::DbWeight::get().reads(2 as u64))119 .saturating_add(T::DbWeight::get().writes(1 as u64))129 .saturating_add(T::DbWeight::get().writes(1 as u64))120 }130 }121 // Storage: AppPromotion Admin (r:1 w:0)131 // Storage: AppPromotion Admin (r:1 w:0)122 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)132 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)123 fn sponsor_contract() -> Weight {133 fn sponsor_contract() -> Weight {124 Weight::from_ref_time(12_669_000 as u64)134 Weight::from_ref_time(11_791_000 as u64)125 .saturating_add(T::DbWeight::get().reads(1 as u64))135 .saturating_add(T::DbWeight::get().reads(1 as u64))126 .saturating_add(T::DbWeight::get().writes(1 as u64))136 .saturating_add(T::DbWeight::get().writes(1 as u64))127 }137 }128 // Storage: AppPromotion Admin (r:1 w:0)138 // Storage: AppPromotion Admin (r:1 w:0)129 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)139 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)130 fn stop_sponsoring_contract() -> Weight {140 fn stop_sponsoring_contract() -> Weight {131 Weight::from_ref_time(14_406_000 as u64)141 Weight::from_ref_time(13_576_000 as u64)132 .saturating_add(T::DbWeight::get().reads(2 as u64))142 .saturating_add(T::DbWeight::get().reads(2 as u64))133 .saturating_add(T::DbWeight::get().writes(1 as u64))143 .saturating_add(T::DbWeight::get().writes(1 as u64))134 }144 }137// For backwards compatibility and tests147// For backwards compatibility and tests138impl WeightInfo for () {148impl WeightInfo for () {139 // Storage: AppPromotion PendingUnstake (r:1 w:0)149 // Storage: AppPromotion PendingUnstake (r:1 w:0)150 // Storage: Balances Locks (r:1 w:1)140 // Storage: System Account (r:1 w:1)151 // Storage: System Account (r:1 w:1)141 fn on_initialize(b: u32, ) -> Weight {152 fn on_initialize(b: u32, ) -> Weight {142 Weight::from_ref_time(3_079_948 as u64)153 Weight::from_ref_time(2_562_275 as u64)143 // Standard Error: 30_376154 // Standard Error: 21_950144 .saturating_add(Weight::from_ref_time(6_343_630 as u64).saturating_mul(b as u64))155 .saturating_add(Weight::from_ref_time(7_177_129 as u64).saturating_mul(b as u64))145 .saturating_add(RocksDbWeight::get().reads(1 as u64))156 .saturating_add(RocksDbWeight::get().reads(1 as u64))146 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(b as u64)))157 .saturating_add(RocksDbWeight::get().reads((2 as u64).saturating_mul(b as u64)))147 .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(b as u64)))158 .saturating_add(RocksDbWeight::get().writes((2 as u64).saturating_mul(b as u64)))148 }159 }149 // Storage: AppPromotion Admin (r:0 w:1)160 // Storage: AppPromotion Admin (r:0 w:1)150 fn set_admin_address() -> Weight {161 fn set_admin_address() -> Weight {151 Weight::from_ref_time(6_653_000 as u64)162 Weight::from_ref_time(6_146_000 as u64)152 .saturating_add(RocksDbWeight::get().writes(1 as u64))163 .saturating_add(RocksDbWeight::get().writes(1 as u64))153 }164 }154 // Storage: AppPromotion Admin (r:1 w:0)165 // Storage: AppPromotion Admin (r:1 w:0)160 // Storage: Balances Locks (r:1 w:1)171 // Storage: Balances Locks (r:1 w:1)161 // Storage: AppPromotion TotalStaked (r:1 w:1)172 // Storage: AppPromotion TotalStaked (r:1 w:1)162 fn payout_stakers(b: u32, ) -> Weight {173 fn payout_stakers(b: u32, ) -> Weight {163 Weight::from_ref_time(74_048_000 as u64)174 Weight::from_ref_time(64_035_000 as u64)164 // Standard Error: 33_223175 // Standard Error: 19_434165 .saturating_add(Weight::from_ref_time(57_702_092 as u64).saturating_mul(b as u64))176 .saturating_add(Weight::from_ref_time(47_251_111 as u64).saturating_mul(b as u64))166 .saturating_add(RocksDbWeight::get().reads(7 as u64))177 .saturating_add(RocksDbWeight::get().reads(7 as u64))167 .saturating_add(RocksDbWeight::get().reads((12 as u64).saturating_mul(b as u64)))178 .saturating_add(RocksDbWeight::get().reads((12 as u64).saturating_mul(b as u64)))168 .saturating_add(RocksDbWeight::get().writes(3 as u64))179 .saturating_add(RocksDbWeight::get().writes(3 as u64))176 // Storage: AppPromotion Staked (r:1 w:1)187 // Storage: AppPromotion Staked (r:1 w:1)177 // Storage: AppPromotion TotalStaked (r:1 w:1)188 // Storage: AppPromotion TotalStaked (r:1 w:1)178 fn stake() -> Weight {189 fn stake() -> Weight {179 Weight::from_ref_time(20_314_000 as u64)190 Weight::from_ref_time(18_078_000 as u64)180 .saturating_add(RocksDbWeight::get().reads(7 as u64))191 .saturating_add(RocksDbWeight::get().reads(7 as u64))181 .saturating_add(RocksDbWeight::get().writes(5 as u64))192 .saturating_add(RocksDbWeight::get().writes(5 as u64))182 }193 }183 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)194 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)184 // Storage: AppPromotion PendingUnstake (r:1 w:1)195 // Storage: AppPromotion PendingUnstake (r:1 w:1)185 // Storage: AppPromotion Staked (r:11 w:10)196 // Storage: AppPromotion Staked (r:11 w:10)186 // Storage: Balances Locks (r:1 w:1)187 // Storage: System Account (r:1 w:1)188 // Storage: AppPromotion TotalStaked (r:1 w:1)197 // Storage: AppPromotion TotalStaked (r:1 w:1)189 // Storage: AppPromotion StakesPerAccount (r:0 w:1)198 // Storage: AppPromotion StakesPerAccount (r:0 w:1)190 fn unstake() -> Weight {199 fn unstake_all() -> Weight {191 Weight::from_ref_time(64_582_000 as u64)200 Weight::from_ref_time(45_038_000 as u64)192 .saturating_add(RocksDbWeight::get().reads(16 as u64))201 .saturating_add(RocksDbWeight::get().reads(14 as u64))193 .saturating_add(RocksDbWeight::get().writes(15 as u64))202 .saturating_add(RocksDbWeight::get().writes(13 as u64))194 }203 }204 // Storage: Configuration AppPromomotionConfigurationOverride (r:1 w:0)205 // Storage: AppPromotion PendingUnstake (r:1 w:1)206 // Storage: AppPromotion Staked (r:11 w:10)207 // Storage: AppPromotion TotalStaked (r:1 w:1)208 // Storage: AppPromotion StakesPerAccount (r:1 w:1)209 fn unstake_partial() -> Weight {210 Weight::from_ref_time(48_863_000 as u64)211 .saturating_add(RocksDbWeight::get().reads(15 as u64))212 .saturating_add(RocksDbWeight::get().writes(13 as u64))213 }195 // Storage: AppPromotion Admin (r:1 w:0)214 // Storage: AppPromotion Admin (r:1 w:0)196 // Storage: Common CollectionById (r:1 w:1)215 // Storage: Common CollectionById (r:1 w:1)197 fn sponsor_collection() -> Weight {216 fn sponsor_collection() -> Weight {198 Weight::from_ref_time(16_364_000 as u64)217 Weight::from_ref_time(14_808_000 as u64)199 .saturating_add(RocksDbWeight::get().reads(2 as u64))218 .saturating_add(RocksDbWeight::get().reads(2 as u64))200 .saturating_add(RocksDbWeight::get().writes(1 as u64))219 .saturating_add(RocksDbWeight::get().writes(1 as u64))201 }220 }202 // Storage: AppPromotion Admin (r:1 w:0)221 // Storage: AppPromotion Admin (r:1 w:0)203 // Storage: Common CollectionById (r:1 w:1)222 // Storage: Common CollectionById (r:1 w:1)204 fn stop_sponsoring_collection() -> Weight {223 fn stop_sponsoring_collection() -> Weight {205 Weight::from_ref_time(15_710_000 as u64)224 Weight::from_ref_time(14_587_000 as u64)206 .saturating_add(RocksDbWeight::get().reads(2 as u64))225 .saturating_add(RocksDbWeight::get().reads(2 as u64))207 .saturating_add(RocksDbWeight::get().writes(1 as u64))226 .saturating_add(RocksDbWeight::get().writes(1 as u64))208 }227 }209 // Storage: AppPromotion Admin (r:1 w:0)228 // Storage: AppPromotion Admin (r:1 w:0)210 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)229 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)211 fn sponsor_contract() -> Weight {230 fn sponsor_contract() -> Weight {212 Weight::from_ref_time(12_669_000 as u64)231 Weight::from_ref_time(11_791_000 as u64)213 .saturating_add(RocksDbWeight::get().reads(1 as u64))232 .saturating_add(RocksDbWeight::get().reads(1 as u64))214 .saturating_add(RocksDbWeight::get().writes(1 as u64))233 .saturating_add(RocksDbWeight::get().writes(1 as u64))215 }234 }216 // Storage: AppPromotion Admin (r:1 w:0)235 // Storage: AppPromotion Admin (r:1 w:0)217 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)236 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)218 fn stop_sponsoring_contract() -> Weight {237 fn stop_sponsoring_contract() -> Weight {219 Weight::from_ref_time(14_406_000 as u64)238 Weight::from_ref_time(13_576_000 as u64)220 .saturating_add(RocksDbWeight::get().reads(2 as u64))239 .saturating_add(RocksDbWeight::get().reads(2 as u64))221 .saturating_add(RocksDbWeight::get().writes(1 as u64))240 .saturating_add(RocksDbWeight::get().writes(1 as u64))222 }241 }tests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth247 // unstake has no effect if no stakes at all247 // unstake has no effect if no stakes at all248 testCase.method === 'unstakeAll'248 testCase.method === 'unstakeAll'249 ? await helper.staking.unstakeAll(staker)249 ? await helper.staking.unstakeAll(staker)250 : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');250 : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');251251252 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);252 expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);253 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper253 expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper262 await helper.staking.unstakeAll(staker);262 await helper.staking.unstakeAll(staker);263 } else {263 } else {264 await helper.staking.unstakePartial(staker, 100n * nominal);264 await helper.staking.unstakePartial(staker, 100n * nominal);265 await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');265 await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');266 }266 }267267268 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);268 expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);