git.delta.rocks / unique-network / refs/commits / da133e176114

difftreelog

refac(app-promo): impl for `unstake_all` & `unstake_partial` extrinsics

PraetorP2023-02-14parent: #59f9c8e.patch.diff
in: master
Added benchmark for `unstake_partial` extrinsic

7 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5782,7 +5782,7 @@
 
 [[package]]
 name = "pallet-app-promotion"
-version = "0.1.4"
+version = "0.1.5"
 dependencies = [
  "frame-benchmarking",
  "frame-support",
modifiedpallets/app-promotion/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/app-promotion/CHANGELOG.md
+++ b/pallets/app-promotion/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.1.5] - 2023-02-14
+
+### Added
+
+- `unstake_partial` extrinsic.
+
 ## [0.1.4] - 2023-01-31
 
 ### Changed
modifiedpallets/app-promotion/Cargo.tomldiffbeforeafterboth
--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -9,7 +9,7 @@
 license = 'GPLv3'
 name = 'pallet-app-promotion'
 repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = '0.1.4'
+version = '0.1.5'
 
 [package.metadata.docs.rs]
 targets = ['x86_64-unknown-linux-gnu']
modifiedpallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -65,7 +65,7 @@
 			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());
 			PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())?;
-			PromototionPallet::<T>::unstake(RawOrigin::Signed(staker.clone()).into()).map_err(|e| e.error)?;
+			PromototionPallet::<T>::unstake_all(RawOrigin::Signed(staker.clone()).into()).map_err(|e| e.error)?;
 			Result::<(), sp_runtime::DispatchError>::Ok(())
 		})?;
 		let block_number = <frame_system::Pallet<T>>::current_block_number() + T::PendingInterval::get();
@@ -115,7 +115,7 @@
 		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
 	} : _(RawOrigin::Signed(caller.clone()), share * <T as Config>::Currency::total_balance(&caller))
 
-	unstake {
+	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());
@@ -130,6 +130,21 @@
 
 	} : _(RawOrigin::Signed(caller.clone()))
 
+	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());
+		(1..11).map(|i| {
+			// used to change block number
+			<frame_system::Pallet<T>>::set_block_number(i.into());
+			T::RelayBlockNumberProvider::set_block_number((2*i).into());
+			assert_eq!(<frame_system::Pallet<T>>::block_number(), i.into());
+			assert_eq!(T::RelayBlockNumberProvider::current_block_number(), (2*i).into());
+			PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), Into::<BalanceOf<T>>::into(100u128) * T::Nominal::get())
+		}).collect::<Result<Vec<_>, _>>()?;
+
+	} : _(RawOrigin::Signed(caller.clone()), Into::<BalanceOf<T>>::into(1000u128) * T::Nominal::get())
+
 	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()))?;
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -208,6 +208,8 @@
 		SponsorNotSet,
 		/// Errors caused by incorrect actions with a locked balance.
 		IncorrectLockedBalanceOperation,
+		/// Errors caused by insufficient staked balance.
+		InsufficientStakedBalance,
 	}
 
 	/// Stores the total staked amount.
@@ -489,65 +491,30 @@
 		}
 
 		/// Unstakes all stakes.
-		/// Moves the sum of all stakes to the `reserved` state.
 		/// After the end of `PendingInterval` this sum becomes completely
 		/// free for further use.
 		#[pallet::call_index(2)]
-		#[pallet::weight(<T as Config>::WeightInfo::unstake())]
-		pub fn unstake_all(staker: OriginFor<T>) -> DispatchResultWithPostInfo {
+		#[pallet::weight(<T as Config>::WeightInfo::unstake_all())]
+		pub fn unstake_all(staker: OriginFor<T>) -> DispatchResult {
 			let staker_id = ensure_signed(staker)?;
-			let config = <PalletConfiguration<T>>::get();
-
-			// calculate block number where the sum would be free
-			let block = <frame_system::Pallet<T>>::block_number() + config.pending_interval;
-
-			let mut pendings = <PendingUnstake<T>>::get(block);
-
-			// checks that we can do unreserve stakes in the block
-			ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);
-
-			let mut total_stakes = 0u64;
-
-			let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))
-				.map(|(_, (amount, _))| {
-					total_stakes += 1;
-					amount
-				})
-				.sum();
-
-			if total_staked.is_zero() {
-				return Ok(None::<Weight>.into()); // TO-DO
-			}
-
-			pendings
-				.try_push((staker_id.clone(), total_staked))
-				.map_err(|_| Error::<T>::PendingForBlockOverflow)?;
 
-			<PendingUnstake<T>>::insert(block, pendings);
-
-			TotalStaked::<T>::set(
-				TotalStaked::<T>::get()
-					.checked_sub(&total_staked)
-					.ok_or(ArithmeticError::Underflow)?,
-			);
-
-			StakesPerAccount::<T>::remove(&staker_id);
-
-			Self::deposit_event(Event::Unstake(staker_id, total_staked));
-
-			Ok(None::<Weight>.into())
+			Self::unstake_all_internal(staker_id)
 		}
 
-		/// Unstakes all stakes.
-		/// Moves the sum of all stakes to the `reserved` state.
+		/// Unstakes the amount of balance for the staker.
 		/// After the end of `PendingInterval` this sum becomes completely
 		/// free for further use.
+		///
+		///  # Arguments
+		///
+		/// * `staker`: staker account.
+		/// * `amount`: amount of unstaked funds.
 		#[pallet::call_index(8)]
-		#[pallet::weight(<T as Config>::WeightInfo::unstake())]
+		#[pallet::weight(<T as Config>::WeightInfo::unstake_partial())]
 		pub fn unstake_partial(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
 			let staker_id = ensure_signed(staker)?;
 
-			Self::partial_unstake(&staker_id, amount)
+			Self::unstake_partial_internal(staker_id, amount)
 		}
 
 		/// Sets the pallet to be the sponsor for the collection.
@@ -821,12 +788,18 @@
 		T::PalletId::get().into_account_truncating()
 	}
 
-	fn partial_unstake(staker_id: &T::AccountId, unstaked_balance: BalanceOf<T>) -> DispatchResult {
-		
+	/// Unstakes the balance for the staker.
+	///
+	/// - `staker`: staker account.
+	/// - `amount`: amount of unstaked funds.
+	fn unstake_partial_internal(
+		staker_id: T::AccountId,
+		unstaked_balance: BalanceOf<T>,
+	) -> DispatchResult {
 		if unstaked_balance == Default::default() {
 			return Ok(());
 		}
-		
+
 		let config = <PalletConfiguration<T>>::get();
 
 		// calculate block number where the sum would be free
@@ -837,7 +810,7 @@
 		// checks that we can do unreserve stakes in the block
 		ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);
 
-		let mut stakes = Staked::<T>::iter_prefix((staker_id,)).collect::<Vec<_>>();
+		let mut stakes = Staked::<T>::iter_prefix((&staker_id,)).collect::<Vec<_>>();
 
 		let total_staked = stakes
 			.iter()
@@ -845,7 +818,10 @@
 				acc + *balance
 			});
 
-		ensure!(total_staked >= unstaked_balance, ArithmeticError::Underflow);
+		ensure!(
+			total_staked >= unstaked_balance,
+			<Error<T>>::InsufficientStakedBalance
+		);
 
 		<TotalStaked<T>>::set(
 			<TotalStaked<T>>::get()
@@ -880,7 +856,7 @@
 			.try_push((staker_id.clone(), unstaked_balance))
 			.map_err(|_| Error::<T>::PendingForBlockOverflow)?;
 
-		StakesPerAccount::<T>::try_mutate(staker_id, |stakes| -> DispatchResult {
+		StakesPerAccount::<T>::try_mutate(&staker_id, |stakes| -> DispatchResult {
 			*stakes = stakes
 				.checked_sub(will_deleted_stakes_count)
 				.ok_or(ArithmeticError::Underflow)?;
@@ -891,9 +867,9 @@
 			.iter()
 			.for_each(|(staked_block, (current_stake_state, _))| {
 				if current_stake_state == &Default::default() {
-					<Staked<T>>::remove((staker_id, staked_block));
+					<Staked<T>>::remove((&staker_id, staked_block));
 				} else {
-					<Staked<T>>::mutate((staker_id, staked_block), |(old_stake_state, _)| {
+					<Staked<T>>::mutate((&staker_id, staked_block), |(old_stake_state, _)| {
 						*old_stake_state = *current_stake_state
 					});
 				}
@@ -901,7 +877,7 @@
 
 		<PendingUnstake<T>>::insert(unpending_block, pendings);
 
-		Self::deposit_event(Event::Unstake(staker_id.clone(), total_staked));
+		Self::deposit_event(Event::Unstake(staker_id, total_staked));
 
 		Ok(())
 	}
@@ -1102,4 +1078,47 @@
 		unsorted_res.sort_by_key(|(block, _)| *block);
 		unsorted_res
 	}
+
+	fn unstake_all_internal(staker_id: T::AccountId) -> DispatchResult {
+		let config = <PalletConfiguration<T>>::get();
+
+		// calculate block number where the sum would be free
+		let block = <frame_system::Pallet<T>>::block_number() + config.pending_interval;
+
+		let mut pendings = <PendingUnstake<T>>::get(block);
+
+		// checks that we can do unreserve stakes in the block
+		ensure!(!pendings.is_full(), Error::<T>::PendingForBlockOverflow);
+
+		let mut total_stakes = 0u64;
+
+		let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))
+			.map(|(_, (amount, _))| {
+				total_stakes += 1;
+				amount
+			})
+			.sum();
+
+		if total_staked.is_zero() {
+			return Ok(());
+		}
+
+		pendings
+			.try_push((staker_id.clone(), total_staked))
+			.map_err(|_| Error::<T>::PendingForBlockOverflow)?;
+
+		<PendingUnstake<T>>::insert(block, pendings);
+
+		TotalStaked::<T>::set(
+			TotalStaked::<T>::get()
+				.checked_sub(&total_staked)
+				.ok_or(ArithmeticError::Underflow)?,
+		);
+
+		StakesPerAccount::<T>::remove(&staker_id);
+
+		Self::deposit_event(Event::Unstake(staker_id, total_staked));
+
+		Ok(())
+	}
 }
modifiedpallets/app-promotion/src/weights.rsdiffbeforeafterboth
3//! Autogenerated weights for pallet_app_promotion3//! Autogenerated weights for pallet_app_promotion
4//!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-dev
6//! 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: 1024
88
9// 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_950
56 .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_434
77 .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 tests
138impl 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_950
144 .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_434
165 .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 }
modifiedtests/src/sub/appPromotion/appPromotion.test.tsdiffbeforeafterboth
--- a/tests/src/sub/appPromotion/appPromotion.test.ts
+++ b/tests/src/sub/appPromotion/appPromotion.test.ts
@@ -247,7 +247,7 @@
         // unstake has no effect if no stakes at all
         testCase.method === 'unstakeAll'
           ? await helper.staking.unstakeAll(staker)
-          : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
+          : await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');
 
         expect(await helper.staking.getPendingUnstake({Substrate: staker.address})).to.be.equal(0n);
         expect(await helper.balance.getSubstrate(staker.address) / nominal).to.be.equal(999n); // TODO bigint closeTo helper
@@ -262,7 +262,7 @@
           await helper.staking.unstakeAll(staker);
         } else {
           await helper.staking.unstakePartial(staker, 100n * nominal);
-          await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('Arithmetic: Underflow');
+          await expect(helper.staking.unstakePartial(staker, 100n * nominal)).to.be.rejectedWith('appPromotion.InsufficientStakedBalance');
         }
 
         expect(await helper.staking.getStakesNumber({Substrate: staker.address})).to.eq(0);