git.delta.rocks / unique-network / refs/commits / 834c75ed844b

difftreelog

change unstake and on_initrialize logicc and + added `Reserved`

PraetorP2022-09-02parent: #492b651.patch.diff
in: master

7 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
600 <Block as BlockT>::Hash,
601 BlockNumber,
602 CrossAccountId,
603 AccountId,
594 for AppPromotion<C, Block>604 > for AppPromotion<C, Block>
595where605where
596 Block: BlockT,606 Block: BlockT,
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
152 Block,
153 BlockNumber,
154 <R as RuntimeInstance>::CrossAccountId,
155 AccountId,
156 >,
152 C::Api: rmrk_rpc::RmrkApi<157 C::Api: rmrk_rpc::RmrkApi<
153 Block,158 Block,
modifiedpallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth
39 T::BlockNumber: From<u32> + Into<u32>,39 T::BlockNumber: From<u32> + Into<u32>,
40 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>40 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>
41 }41 }
42 start_app_promotion {42 // start_app_promotion {
4343
44 } : {PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), None)?}44 // } : {PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), None)?}
4545
46 stop_app_promotion{46 // stop_app_promotion{
47 PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?;47 // PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?;
48 } : {PromototionPallet::<T>::stop_app_promotion(RawOrigin::Root.into())?}48 // } : {PromototionPallet::<T>::stop_app_promotion(RawOrigin::Root.into())?}
4949
50 set_admin_address {50 set_admin_address {
51 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);51 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
58 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;58 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
59 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());59 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
60 let staker: T::AccountId = account("caller", 0, SEED);60 let staker: T::AccountId = account("caller", 0, SEED);
61 let stakers: Vec<T::AccountId> = (0..100).map(|index| account("staker", index, SEED)).collect();
62 stakers.iter().for_each(|staker| {
63 <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
64 });
61 let _ = <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());65 let _ = <T as Config>::Currency::make_free_balance_be(&staker, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
62 let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;66 let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;
63 } : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?}67 } : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?}
7074
71 unstake {75 unstake {
72 let caller = account::<T::AccountId>("caller", 0, SEED);76 let caller = account::<T::AccountId>("caller", 0, SEED);
73 let share = Perbill::from_rational(1u32, 10);77 let share = Perbill::from_rational(1u32, 20);
74 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());78 let _ = <T as Config>::Currency::make_free_balance_be(&caller, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
75 let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?;79 (0..10).map(|_| PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))).collect::<Result<Vec<_>, _>>()?;
7680
77 } : {PromototionPallet::<T>::unstake(RawOrigin::Signed(caller.clone()).into())?}81 } : {PromototionPallet::<T>::unstake(RawOrigin::Signed(caller.clone()).into())?}
7882
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
36pub mod types;36pub mod types;
37pub mod weights;37pub mod weights;
3838
39use sp_std::{vec::Vec, iter::Sum, borrow::ToOwned};39use sp_std::{
40 vec::{Vec},
41 vec,
42 iter::Sum,
43 borrow::ToOwned,
44};
40use sp_core::H160;45use sp_core::H160;
41use codec::EncodeLike;46use codec::EncodeLike;
42use pallet_balances::BalanceLock;47use pallet_balances::BalanceLock;
63 ArithmeticError,68 ArithmeticError,
64};69};
6570
71pub const LOCK_IDENTIFIER: [u8; 8] = *b"appstake";
72const PENDING_LIMIT_PER_BLOCK: u32 = 3;
73
66type BalanceOf<T> =74type BalanceOf<T> =
67 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;75 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
6876
72// const TWO_WEEK: u32 = 2 * WEEK;80// const TWO_WEEK: u32 = 2 * WEEK;
73// const YEAR: u32 = DAY * 365;81// const YEAR: u32 = DAY * 365;
7482
75pub const LOCK_IDENTIFIER: [u8; 8] = *b"appstake";
76
77#[frame_support::pallet]83#[frame_support::pallet]
78pub mod pallet {84pub mod pallet {
79 use super::*;85 use super::*;
80 use frame_support::{Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, PalletId};86 use frame_support::{
87 Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key, PalletId,
88 traits::ReservableCurrency,
89 };
81 use frame_system::pallet_prelude::*;90 use frame_system::pallet_prelude::*;
8291
83 #[pallet::config]92 #[pallet::config]
84 pub trait Config: frame_system::Config + pallet_evm::account::Config {93 pub trait Config: frame_system::Config + pallet_evm::account::Config {
85 type Currency: ExtendedLockableCurrency<Self::AccountId>;94 type Currency: ExtendedLockableCurrency<Self::AccountId>
95 + ReservableCurrency<Self::AccountId>;
8696
87 type CollectionHandler: CollectionHandler<97 type CollectionHandler: CollectionHandler<
88 AccountId = Self::AccountId,98 AccountId = Self::AccountId,
149 NoPermission,159 NoPermission,
150 /// Insufficient funds to perform an action160 /// Insufficient funds to perform an action
151 NotSufficientFounds,161 NotSufficientFounds,
162 PendingForBlockOverflow,
152 /// An error related to the fact that an invalid argument was passed to perform an action163 /// An error related to the fact that an invalid argument was passed to perform an action
153 InvalidArgument,164 InvalidArgument,
154 }165 }
175 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;186 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;
176187
177 /// Amount of tokens pending unstake per user per block.188 /// Amount of tokens pending unstake per user per block.
189 // #[pallet::storage]
190 // pub type PendingUnstake<T: Config> = StorageNMap<
191 // Key = (
192 // Key<Blake2_128Concat, T::AccountId>,
193 // Key<Twox64Concat, T::BlockNumber>,
194 // ),
195 // Value = BalanceOf<T>,
196 // QueryKind = ValueQuery,
197 // >;
178 #[pallet::storage]198 #[pallet::storage]
179 pub type PendingUnstake<T: Config> = StorageNMap<199 pub type PendingUnstake<T: Config> = StorageMap<
180 Key = (200 _,
181 Key<Blake2_128Concat, T::AccountId>,201 Twox64Concat,
202 T::BlockNumber,
182 Key<Twox64Concat, T::BlockNumber>,203 BoundedVec<(T::AccountId, BalanceOf<T>), ConstU32<PENDING_LIMIT_PER_BLOCK>>,
183 ),
184 Value = BalanceOf<T>,
185 QueryKind = ValueQuery,204 ValueQuery,
186 >;205 >;
187206
188 /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.207 /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
189 #[pallet::storage]208 #[pallet::storage]
190 pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;209 pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
191210
192 /// Next target block when interest is recalculated211 // /// Next target block when interest is recalculated
193 #[pallet::storage]212 // #[pallet::storage]
194 #[pallet::getter(fn get_interest_block)]213 // #[pallet::getter(fn get_interest_block)]
195 pub type NextInterestBlock<T: Config> =214 // pub type NextInterestBlock<T: Config> =
196 StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;215 // StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
197216
198 /// Stores hash a record for which the last revenue recalculation was performed.217 /// Stores hash a record for which the last revenue recalculation was performed.
199 /// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.218 /// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.
204223
205 #[pallet::hooks]224 #[pallet::hooks]
206 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {225 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
207 fn on_initialize(current_block: T::BlockNumber) -> Weight226 fn on_initialize(current_block_number: T::BlockNumber) -> Weight
208 where227 where
209 <T as frame_system::Config>::BlockNumber: From<u32>,228 <T as frame_system::Config>::BlockNumber: From<u32>,
210 {229 {
211 let mut consumed_weight = 0;230 let mut consumed_weight = 0;
212 // let mut add_weight = |reads, writes, weight| {231 let mut add_weight = |reads, writes, weight| {
213 // consumed_weight += T::DbWeight::get().reads_writes(reads, writes);232 consumed_weight += T::DbWeight::get().reads_writes(reads, writes);
214 // consumed_weight += weight;233 consumed_weight += weight;
215 // };234 };
216235
217 let current_relay_block = T::RelayBlockNumberProvider::current_block_number();236 let block_pending = PendingUnstake::<T>::take(current_block_number);
218 PendingUnstake::<T>::iter()
219 .filter_map(|((staker, block), amount)| {
220 if block <= current_relay_block {
221 Some((staker, block, amount))
222 } else {
223 None
224 }
225 })
226 .for_each(|(staker, block, amount)| {
227 Self::unlock_balance_unchecked(&staker, amount);
228 <PendingUnstake<T>>::remove((staker, block));
229 });
230237
231 // let next_interest_block = Self::get_interest_block();238 add_weight(0, 1, 0);
232 // let current_relay_block = T::RelayBlockNumberProvider::current_block_number();
233 // if next_interest_block != 0.into() && current_relay_block >= next_interest_block {
234 // let mut acc = <BalanceOf<T>>::default();
235 // let mut base_acc = <BalanceOf<T>>::default();
236239
237 // NextInterestBlock::<T>::set(240 if !block_pending.is_empty() {
238 // NextInterestBlock::<T>::get() + T::RecalculationInterval::get(),241 block_pending.into_iter().for_each(|(staker, amount)| {
242 <T::Currency as ReservableCurrency<T::AccountId>>::unreserve(&staker, amount);
239 // );243 });
240 // add_weight(0, 1, 0);244 }
241245
242 // Staked::<T>::iter()
243 // .filter(|((_, block), _)| {
244 // *block + T::RecalculationInterval::get() <= current_relay_block
245 // })
246 // .for_each(|((staker, block), amount)| {
247 // Self::recalculate_stake(&staker, block, amount, &mut acc);
248 // add_weight(0, 0, T::WeightInfo::recalculate_stake());
249 // base_acc += amount;
250 // });
251 // <TotalStaked<T>>::get()
252 // .checked_add(&acc)
253 // .map(|res| <TotalStaked<T>>::set(res));
254
255 // Self::deposit_event(Event::StakingRecalculation(base_acc, acc));
256 // add_weight(0, 1, 0);
257 // } else {
258 // add_weight(1, 0, 0)
259 // };
260 consumed_weight246 consumed_weight
261 }247 }
262 }248 }
275 Ok(())261 Ok(())
276 }262 }
277263
278 #[pallet::weight(T::WeightInfo::start_app_promotion())]264 // #[pallet::weight(T::WeightInfo::start_app_promotion())]
279 pub fn start_app_promotion(265 // pub fn start_app_promotion(
280 origin: OriginFor<T>,266 // origin: OriginFor<T>,
281 promotion_start_relay_block: Option<T::BlockNumber>,267 // promotion_start_relay_block: Option<T::BlockNumber>,
282 ) -> DispatchResult268 // ) -> DispatchResult
283 where269 // where
284 <T as frame_system::Config>::BlockNumber: From<u32>,270 // <T as frame_system::Config>::BlockNumber: From<u32>,
285 {271 // {
286 ensure_root(origin)?;272 // ensure_root(origin)?;
287273
288 // Start app-promotion mechanics if it has not been yet initialized274 // // Start app-promotion mechanics if it has not been yet initialized
289 if <StartBlock<T>>::get() == 0u32.into() {275 // if <StartBlock<T>>::get() == 0u32.into() {
290 let start_block = promotion_start_relay_block276 // let start_block = promotion_start_relay_block
291 .unwrap_or(T::RelayBlockNumberProvider::current_block_number());277 // .unwrap_or(T::RelayBlockNumberProvider::current_block_number());
292278
293 // Set promotion global start block279 // // Set promotion global start block
294 <StartBlock<T>>::set(start_block);280 // <StartBlock<T>>::set(start_block);
295281
296 <NextInterestBlock<T>>::set(start_block + T::RecalculationInterval::get());282 // <NextInterestBlock<T>>::set(start_block + T::RecalculationInterval::get());
297 }283 // }
298284
299 Ok(())285 // Ok(())
300 }286 // }
301287
302 #[pallet::weight(T::WeightInfo::stop_app_promotion())]288 // #[pallet::weight(T::WeightInfo::stop_app_promotion())]
303 pub fn stop_app_promotion(origin: OriginFor<T>) -> DispatchResult289 // pub fn stop_app_promotion(origin: OriginFor<T>) -> DispatchResult
304 where290 // where
305 <T as frame_system::Config>::BlockNumber: From<u32>,291 // <T as frame_system::Config>::BlockNumber: From<u32>,
306 {292 // {
307 ensure_root(origin)?;293 // ensure_root(origin)?;
308294
309 if <StartBlock<T>>::get() != 0u32.into() {295 // if <StartBlock<T>>::get() != 0u32.into() {
310 <StartBlock<T>>::set(T::BlockNumber::default());296 // <StartBlock<T>>::set(T::BlockNumber::default());
311 <NextInterestBlock<T>>::set(T::BlockNumber::default());297 // <NextInterestBlock<T>>::set(T::BlockNumber::default());
312 }298 // }
313299
314 Ok(())300 // Ok(())
315 }301 // }
316302
317 #[pallet::weight(T::WeightInfo::stake())]303 #[pallet::weight(T::WeightInfo::stake())]
318 pub fn stake(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {304 pub fn stake(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
369 #[pallet::weight(T::WeightInfo::unstake())]355 #[pallet::weight(T::WeightInfo::unstake())]
370 pub fn unstake(staker: OriginFor<T>) -> DispatchResultWithPostInfo {356 pub fn unstake(staker: OriginFor<T>) -> DispatchResultWithPostInfo {
371 let staker_id = ensure_signed(staker)?;357 let staker_id = ensure_signed(staker)?;
358 let block = <frame_system::Pallet<T>>::block_number() + T::PendingInterval::get();
359 let mut pendings = <PendingUnstake<T>>::get(block);
372360
361 ensure!(pendings.is_full(), Error::<T>::PendingForBlockOverflow);
362
373 let mut total_stakes = 0u64;363 let mut total_stakes = 0u64;
374364
375 let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))365 let total_staked: BalanceOf<T> = Staked::<T>::drain_prefix((&staker_id,))
382 if total_staked.is_zero() {372 if total_staked.is_zero() {
383 return Ok(None.into());373 return Ok(None.into());
384 }374 }
385 let block =
386 T::RelayBlockNumberProvider::current_block_number() + T::PendingInterval::get();
387 <PendingUnstake<T>>::insert(
388 (&staker_id, block),
389 <PendingUnstake<T>>::get((&staker_id, block))
390 .checked_add(&total_staked)
391 .ok_or(ArithmeticError::Overflow)?,
392 );
393375
376 pendings
377 .try_push((staker_id.clone(), total_staked))
378 .map_err(|_| Error::<T>::PendingForBlockOverflow)?;
379
380 <PendingUnstake<T>>::insert(block, pendings);
381
382 Self::unlock_balance_unchecked(&staker_id, total_staked);
383
384 <T::Currency as ReservableCurrency<T::AccountId>>::reserve(&staker_id, total_staked)?;
385
394 TotalStaked::<T>::set(386 TotalStaked::<T>::set(
395 TotalStaked::<T>::get()387 TotalStaked::<T>::get()
396 .checked_sub(&total_staked)388 .checked_sub(&total_staked)
671 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum,663 <<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum,
672{664{
673 pub fn cross_id_pending_unstake(staker: Option<T::CrossAccountId>) -> BalanceOf<T> {665 pub fn cross_id_pending_unstake(staker: Option<T::CrossAccountId>) -> BalanceOf<T> {
674 staker.map_or(PendingUnstake::<T>::iter_values().sum(), |s| {666 staker.map_or(
667 PendingUnstake::<T>::iter_values()
668 .flat_map(|pendings| pendings.into_iter().map(|(_, amount)| amount))
669 .sum(),
670 |s| {
675 PendingUnstake::<T>::iter_prefix_values((s.as_sub(),)).sum()671 PendingUnstake::<T>::iter_values()
672 .flatten()
673 .filter_map(|(id, amount)| {
674 if id == *s.as_sub() {
675 Some(amount)
676 } else {
677 None
678 }
679 })
680 .sum()
676 })681 },
682 )
677 }683 }
678684
679 pub fn cross_id_pending_unstake_per_block(685 pub fn cross_id_pending_unstake_per_block(
680 staker: T::CrossAccountId,686 staker: T::CrossAccountId,
681 ) -> Vec<(T::BlockNumber, BalanceOf<T>)> {687 ) -> Vec<(T::BlockNumber, BalanceOf<T>)> {
682 let mut unsorted_res = PendingUnstake::<T>::iter_prefix((staker.as_sub(),))688 let mut unsorted_res = vec![];
689 PendingUnstake::<T>::iter().for_each(|(block, pendings)| {
690 pendings.into_iter().for_each(|(id, amount)| {
683 .into_iter()691 if id == *staker.as_sub() {
684 .collect::<Vec<_>>();692 unsorted_res.push((block, amount));
693 };
694 })
695 });
696
685 unsorted_res.sort_by_key(|(block, _)| *block);697 unsorted_res.sort_by_key(|(block, _)| *block);
686 unsorted_res698 unsorted_res
modifiedpallets/app-promotion/src/tests.rsdiffbeforeafterboth
1616
17#![cfg(test)]17#![cfg(test)]
18#![allow(clippy::from_over_into)]18#![allow(clippy::from_over_into)]
19use crate as pallet_promotion;19// use crate as pallet_promotion;
2020
21use frame_benchmarking::{add_benchmark, BenchmarkBatch};21// use frame_benchmarking::{add_benchmark, BenchmarkBatch};
22use frame_support::{22// use frame_support::{
23 assert_ok, parameter_types,23// assert_ok, parameter_types,
24 traits::{Currency, OnInitialize, Everything, ConstU32},24// traits::{Currency, OnInitialize, Everything, ConstU32},
25};25// };
26use frame_system::RawOrigin;26// use frame_system::RawOrigin;
27use sp_core::H256;27// use sp_core::H256;
28use sp_runtime::{28// use sp_runtime::{
29 traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup},29// traits::{BlakeTwo256, BlockNumberProvider, IdentityLookup},
30 testing::Header,30// testing::Header,
31 Perbill, Perquintill,31// Perbill, Perquintill,
32};32// };
3333
34// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;34// type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
35// type Block = frame_system::mocking::MockBlock<Test>;35// type Block = frame_system::mocking::MockBlock<Test>;
127// } )127// } )
128// }128// }
129129
130#[test]130// #[test]
131fn test_perbill() {131// fn test_perbill() {
132 const ONE_UNIQE: u128 = 1_000_000_000_000_000_000;132// const ONE_UNIQE: u128 = 1_000_000_000_000_000_000;
133 const SECONDS_TO_BLOCK: u32 = 12;133// const SECONDS_TO_BLOCK: u32 = 12;
134 const DAY: u32 = 60 * 60 * 24 / SECONDS_TO_BLOCK;134// const DAY: u32 = 60 * 60 * 24 / SECONDS_TO_BLOCK;
135 const RECALCULATION_INTERVAL: u32 = 10;135// const RECALCULATION_INTERVAL: u32 = 10;
136 let day_rate = Perbill::from_rational(5u64, 10_000);136// let day_rate = Perbill::from_rational(5u64, 10_000);
137 let interval_rate =137// let interval_rate =
138 Perbill::from_rational::<u64>(RECALCULATION_INTERVAL.into(), DAY.into()) * day_rate;138// Perbill::from_rational::<u64>(RECALCULATION_INTERVAL.into(), DAY.into()) * day_rate;
139 println!("{:?}", interval_rate * ONE_UNIQE + ONE_UNIQE);139// println!("{:?}", interval_rate * ONE_UNIQE + ONE_UNIQE);
140 println!("{:?}", day_rate * ONE_UNIQE);140// println!("{:?}", day_rate * ONE_UNIQE);
141 println!("{:?}", Perbill::one() * ONE_UNIQE);141// println!("{:?}", Perbill::one() * ONE_UNIQE);
142 println!("{:?}", ONE_UNIQE);142// println!("{:?}", ONE_UNIQE);
143 let mut next_iters = ONE_UNIQE + interval_rate * ONE_UNIQE;143// let mut next_iters = ONE_UNIQE + interval_rate * ONE_UNIQE;
144 next_iters += interval_rate * next_iters;144// next_iters += interval_rate * next_iters;
145 println!("{:?}", next_iters);145// println!("{:?}", next_iters);
146 let day_income = day_rate * ONE_UNIQE;146// let day_income = day_rate * ONE_UNIQE;
147 let interval_income = interval_rate * ONE_UNIQE;147// let interval_income = interval_rate * ONE_UNIQE;
148 let ratio = day_income / interval_income;148// let ratio = day_income / interval_income;
149 println!("{:?} || {:?}", ratio, DAY / RECALCULATION_INTERVAL);149// println!("{:?} || {:?}", ratio, DAY / RECALCULATION_INTERVAL);
150}150// }
151151
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-08-31, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`6//! DATE: 2022-09-01, 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:
3434
35/// Weight functions needed for pallet_app_promotion.35/// Weight functions needed for pallet_app_promotion.
36pub trait WeightInfo {36pub trait WeightInfo {
37 fn start_app_promotion() -> Weight;
38 fn stop_app_promotion() -> Weight;
39 fn set_admin_address() -> Weight;37 fn set_admin_address() -> Weight;
40 fn payout_stakers() -> Weight;38 fn payout_stakers() -> Weight;
41 fn stake() -> Weight;39 fn stake() -> Weight;
49/// Weights for pallet_app_promotion using the Substrate node and recommended hardware.47/// Weights for pallet_app_promotion using the Substrate node and recommended hardware.
50pub struct SubstrateWeight<T>(PhantomData<T>);48pub struct SubstrateWeight<T>(PhantomData<T>);
51impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {49impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
52 // Storage: Promotion StartBlock (r:1 w:1)
53 // Storage: ParachainSystem ValidationData (r:1 w:0)
54 // Storage: Promotion NextInterestBlock (r:0 w:1)
55 fn start_app_promotion() -> Weight {
56 (3_995_000 as Weight)
57 .saturating_add(T::DbWeight::get().reads(2 as Weight))
58 .saturating_add(T::DbWeight::get().writes(2 as Weight))
59 }
60 // Storage: Promotion StartBlock (r:1 w:1)
61 // Storage: Promotion NextInterestBlock (r:0 w:1)
62 fn stop_app_promotion() -> Weight {
63 (3_623_000 as Weight)
64 .saturating_add(T::DbWeight::get().reads(1 as Weight))
65 .saturating_add(T::DbWeight::get().writes(2 as Weight))
66 }
67 // Storage: Promotion Admin (r:0 w:1)50 // Storage: Promotion Admin (r:0 w:1)
68 fn set_admin_address() -> Weight {51 fn set_admin_address() -> Weight {
69 (1_203_000 as Weight)52 (515_000 as Weight)
70 .saturating_add(T::DbWeight::get().writes(1 as Weight))53 .saturating_add(T::DbWeight::get().writes(1 as Weight))
71 }54 }
72 // Storage: Promotion Admin (r:1 w:0)55 // Storage: Promotion Admin (r:1 w:0)
73 // Storage: ParachainSystem ValidationData (r:1 w:0)56 // Storage: ParachainSystem ValidationData (r:1 w:0)
74 // Storage: Promotion NextCalculatedRecord (r:1 w:1)57 // Storage: Promotion NextCalculatedRecord (r:1 w:1)
75 // Storage: Promotion Staked (r:2 w:0)58 // Storage: Promotion Staked (r:2 w:0)
76 fn payout_stakers() -> Weight {59 fn payout_stakers() -> Weight {
77 (10_859_000 as Weight)60 (8_475_000 as Weight)
78 .saturating_add(T::DbWeight::get().reads(5 as Weight))61 .saturating_add(T::DbWeight::get().reads(5 as Weight))
79 .saturating_add(T::DbWeight::get().writes(1 as Weight))62 .saturating_add(T::DbWeight::get().writes(1 as Weight))
80 }63 }
81 // Storage: System Account (r:1 w:1)64 // Storage: System Account (r:1 w:1)
65 // Storage: Promotion StakesPerAccount (r:1 w:1)
82 // Storage: Balances Locks (r:1 w:1)66 // Storage: Balances Locks (r:1 w:1)
83 // Storage: ParachainSystem ValidationData (r:1 w:0)67 // Storage: ParachainSystem ValidationData (r:1 w:0)
84 // Storage: Promotion Staked (r:1 w:1)68 // Storage: Promotion Staked (r:1 w:1)
85 // Storage: Promotion TotalStaked (r:1 w:1)69 // Storage: Promotion TotalStaked (r:1 w:1)
86 fn stake() -> Weight {70 fn stake() -> Weight {
87 (14_789_000 as Weight)71 (12_266_000 as Weight)
88 .saturating_add(T::DbWeight::get().reads(5 as Weight))72 .saturating_add(T::DbWeight::get().reads(6 as Weight))
89 .saturating_add(T::DbWeight::get().writes(4 as Weight))73 .saturating_add(T::DbWeight::get().writes(5 as Weight))
90 }74 }
91 // Storage: Promotion Staked (r:2 w:1)75 // Storage: Promotion Staked (r:2 w:1)
92 // Storage: ParachainSystem ValidationData (r:1 w:0)76 // Storage: ParachainSystem ValidationData (r:1 w:0)
93 // Storage: Promotion PendingUnstake (r:1 w:1)77 // Storage: Promotion PendingUnstake (r:1 w:1)
94 // Storage: Promotion TotalStaked (r:1 w:1)78 // Storage: Promotion TotalStaked (r:1 w:1)
79 // Storage: Promotion StakesPerAccount (r:0 w:1)
95 fn unstake() -> Weight {80 fn unstake() -> Weight {
96 (16_889_000 as Weight)81 (10_663_000 as Weight)
97 .saturating_add(T::DbWeight::get().reads(5 as Weight))82 .saturating_add(T::DbWeight::get().reads(5 as Weight))
98 .saturating_add(T::DbWeight::get().writes(3 as Weight))83 .saturating_add(T::DbWeight::get().writes(4 as Weight))
99 }84 }
100 // Storage: Promotion Admin (r:1 w:0)85 // Storage: Promotion Admin (r:1 w:0)
101 // Storage: Common CollectionById (r:1 w:1)86 // Storage: Common CollectionById (r:1 w:1)
102 fn sponsor_collection() -> Weight {87 fn sponsor_collection() -> Weight {
103 (18_377_000 as Weight)88 (10_879_000 as Weight)
104 .saturating_add(T::DbWeight::get().reads(2 as Weight))89 .saturating_add(T::DbWeight::get().reads(2 as Weight))
105 .saturating_add(T::DbWeight::get().writes(1 as Weight))90 .saturating_add(T::DbWeight::get().writes(1 as Weight))
106 }91 }
107 // Storage: Promotion Admin (r:1 w:0)92 // Storage: Promotion Admin (r:1 w:0)
108 // Storage: Common CollectionById (r:1 w:1)93 // Storage: Common CollectionById (r:1 w:1)
109 fn stop_sponsoring_collection() -> Weight {94 fn stop_sponsoring_collection() -> Weight {
110 (13_989_000 as Weight)95 (10_548_000 as Weight)
111 .saturating_add(T::DbWeight::get().reads(2 as Weight))96 .saturating_add(T::DbWeight::get().reads(2 as Weight))
112 .saturating_add(T::DbWeight::get().writes(1 as Weight))97 .saturating_add(T::DbWeight::get().writes(1 as Weight))
113 }98 }
114 // Storage: Promotion Admin (r:1 w:0)99 // Storage: Promotion Admin (r:1 w:0)
115 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)100 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)
116 fn sponsor_contract() -> Weight {101 fn sponsor_contract() -> Weight {
117 (4_162_000 as Weight)102 (2_130_000 as Weight)
118 .saturating_add(T::DbWeight::get().reads(1 as Weight))103 .saturating_add(T::DbWeight::get().reads(1 as Weight))
119 .saturating_add(T::DbWeight::get().writes(1 as Weight))104 .saturating_add(T::DbWeight::get().writes(1 as Weight))
120 }105 }
121 // Storage: Promotion Admin (r:1 w:0)106 // Storage: Promotion Admin (r:1 w:0)
122 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)107 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)
123 fn stop_sponsoring_contract() -> Weight {108 fn stop_sponsoring_contract() -> Weight {
124 (5_457_000 as Weight)109 (3_509_000 as Weight)
125 .saturating_add(T::DbWeight::get().reads(2 as Weight))110 .saturating_add(T::DbWeight::get().reads(2 as Weight))
126 .saturating_add(T::DbWeight::get().writes(1 as Weight))111 .saturating_add(T::DbWeight::get().writes(1 as Weight))
127 }112 }
128}113}
129114
130// For backwards compatibility and tests115// For backwards compatibility and tests
131impl WeightInfo for () {116impl WeightInfo for () {
132 // Storage: Promotion StartBlock (r:1 w:1)
133 // Storage: ParachainSystem ValidationData (r:1 w:0)
134 // Storage: Promotion NextInterestBlock (r:0 w:1)
135 fn start_app_promotion() -> Weight {
136 (3_995_000 as Weight)
137 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
138 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
139 }
140 // Storage: Promotion StartBlock (r:1 w:1)
141 // Storage: Promotion NextInterestBlock (r:0 w:1)
142 fn stop_app_promotion() -> Weight {
143 (3_623_000 as Weight)
144 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
145 .saturating_add(RocksDbWeight::get().writes(2 as Weight))
146 }
147 // Storage: Promotion Admin (r:0 w:1)117 // Storage: Promotion Admin (r:0 w:1)
148 fn set_admin_address() -> Weight {118 fn set_admin_address() -> Weight {
149 (1_203_000 as Weight)119 (515_000 as Weight)
150 .saturating_add(RocksDbWeight::get().writes(1 as Weight))120 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
151 }121 }
152 // Storage: Promotion Admin (r:1 w:0)122 // Storage: Promotion Admin (r:1 w:0)
153 // Storage: ParachainSystem ValidationData (r:1 w:0)123 // Storage: ParachainSystem ValidationData (r:1 w:0)
154 // Storage: Promotion NextCalculatedRecord (r:1 w:1)124 // Storage: Promotion NextCalculatedRecord (r:1 w:1)
155 // Storage: Promotion Staked (r:2 w:0)125 // Storage: Promotion Staked (r:2 w:0)
156 fn payout_stakers() -> Weight {126 fn payout_stakers() -> Weight {
157 (10_859_000 as Weight)127 (8_475_000 as Weight)
158 .saturating_add(RocksDbWeight::get().reads(5 as Weight))128 .saturating_add(RocksDbWeight::get().reads(5 as Weight))
159 .saturating_add(RocksDbWeight::get().writes(1 as Weight))129 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
160 }130 }
161 // Storage: System Account (r:1 w:1)131 // Storage: System Account (r:1 w:1)
132 // Storage: Promotion StakesPerAccount (r:1 w:1)
162 // Storage: Balances Locks (r:1 w:1)133 // Storage: Balances Locks (r:1 w:1)
163 // Storage: ParachainSystem ValidationData (r:1 w:0)134 // Storage: ParachainSystem ValidationData (r:1 w:0)
164 // Storage: Promotion Staked (r:1 w:1)135 // Storage: Promotion Staked (r:1 w:1)
165 // Storage: Promotion TotalStaked (r:1 w:1)136 // Storage: Promotion TotalStaked (r:1 w:1)
166 fn stake() -> Weight {137 fn stake() -> Weight {
167 (14_789_000 as Weight)138 (12_266_000 as Weight)
168 .saturating_add(RocksDbWeight::get().reads(5 as Weight))139 .saturating_add(RocksDbWeight::get().reads(6 as Weight))
169 .saturating_add(RocksDbWeight::get().writes(4 as Weight))140 .saturating_add(RocksDbWeight::get().writes(5 as Weight))
170 }141 }
171 // Storage: Promotion Staked (r:2 w:1)142 // Storage: Promotion Staked (r:2 w:1)
172 // Storage: ParachainSystem ValidationData (r:1 w:0)143 // Storage: ParachainSystem ValidationData (r:1 w:0)
173 // Storage: Promotion PendingUnstake (r:1 w:1)144 // Storage: Promotion PendingUnstake (r:1 w:1)
174 // Storage: Promotion TotalStaked (r:1 w:1)145 // Storage: Promotion TotalStaked (r:1 w:1)
146 // Storage: Promotion StakesPerAccount (r:0 w:1)
175 fn unstake() -> Weight {147 fn unstake() -> Weight {
176 (16_889_000 as Weight)148 (10_663_000 as Weight)
177 .saturating_add(RocksDbWeight::get().reads(5 as Weight))149 .saturating_add(RocksDbWeight::get().reads(5 as Weight))
178 .saturating_add(RocksDbWeight::get().writes(3 as Weight))150 .saturating_add(RocksDbWeight::get().writes(4 as Weight))
179 }151 }
180 // Storage: Promotion Admin (r:1 w:0)152 // Storage: Promotion Admin (r:1 w:0)
181 // Storage: Common CollectionById (r:1 w:1)153 // Storage: Common CollectionById (r:1 w:1)
182 fn sponsor_collection() -> Weight {154 fn sponsor_collection() -> Weight {
183 (18_377_000 as Weight)155 (10_879_000 as Weight)
184 .saturating_add(RocksDbWeight::get().reads(2 as Weight))156 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
185 .saturating_add(RocksDbWeight::get().writes(1 as Weight))157 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
186 }158 }
187 // Storage: Promotion Admin (r:1 w:0)159 // Storage: Promotion Admin (r:1 w:0)
188 // Storage: Common CollectionById (r:1 w:1)160 // Storage: Common CollectionById (r:1 w:1)
189 fn stop_sponsoring_collection() -> Weight {161 fn stop_sponsoring_collection() -> Weight {
190 (13_989_000 as Weight)162 (10_548_000 as Weight)
191 .saturating_add(RocksDbWeight::get().reads(2 as Weight))163 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
192 .saturating_add(RocksDbWeight::get().writes(1 as Weight))164 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
193 }165 }
194 // Storage: Promotion Admin (r:1 w:0)166 // Storage: Promotion Admin (r:1 w:0)
195 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)167 // Storage: EvmContractHelpers Sponsoring (r:0 w:1)
196 fn sponsor_contract() -> Weight {168 fn sponsor_contract() -> Weight {
197 (4_162_000 as Weight)169 (2_130_000 as Weight)
198 .saturating_add(RocksDbWeight::get().reads(1 as Weight))170 .saturating_add(RocksDbWeight::get().reads(1 as Weight))
199 .saturating_add(RocksDbWeight::get().writes(1 as Weight))171 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
200 }172 }
201 // Storage: Promotion Admin (r:1 w:0)173 // Storage: Promotion Admin (r:1 w:0)
202 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)174 // Storage: EvmContractHelpers Sponsoring (r:1 w:1)
203 fn stop_sponsoring_contract() -> Weight {175 fn stop_sponsoring_contract() -> Weight {
204 (5_457_000 as Weight)176 (3_509_000 as Weight)
205 .saturating_add(RocksDbWeight::get().reads(2 as Weight))177 .saturating_add(RocksDbWeight::get().reads(2 as Weight))
206 .saturating_add(RocksDbWeight::get().writes(1 as Weight))178 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
207 }179 }
modifiedruntime/common/runtime_apis.rsdiffbeforeafterboth

no syntactic changes