diff --git a/pallets/liquidity-mining/src/benchmarking.rs b/pallets/liquidity-mining/src/benchmarking.rs index 12e9c0d304..6dbaf0329d 100644 --- a/pallets/liquidity-mining/src/benchmarking.rs +++ b/pallets/liquidity-mining/src/benchmarking.rs @@ -21,6 +21,7 @@ use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::{assert_ok, sp_runtime::sp_std::convert::TryInto, sp_std::prelude::*}; use frame_system::RawOrigin; +use node_primitives::Balance; use crate::{Pallet as LM, *}; @@ -28,6 +29,7 @@ const FARMING_DEPOSIT_1: CurrencyId = CurrencyId::VSToken(TokenSymbol::KSM); const FARMING_DEPOSIT_2: CurrencyId = CurrencyId::VSBond(TokenSymbol::KSM, 2001, 13, 20); const REWARD_1: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); const REWARD_2: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); +const UNIT: Balance = 1_000_000_000_000; fn run_to_block(n: BlockNumberFor) { type System = frame_system::Pallet; @@ -47,11 +49,7 @@ benchmarks! { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let reward_amount: BalanceOf = { - let duration: u128 = duration.saturated_into(); - let per_block: u128 = T::MinimumRewardPerBlock::get().saturated_into(); - (duration * (per_block + 1)).saturated_into() - }; + let reward_amount: BalanceOf = UNIT.saturated_into(); assert_ok!(::MultiCurrency::deposit(REWARD_1, &caller, reward_amount)); assert_ok!(::MultiCurrency::deposit(REWARD_2, &caller, reward_amount)); @@ -70,19 +68,15 @@ benchmarks! { deposit { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let reward_amount: BalanceOf = { - let duration: u128 = duration.saturated_into(); - let per_block: u128 = T::MinimumRewardPerBlock::get().saturated_into(); - (duration * (per_block + 1)).saturated_into() - }; + let reward_amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, reward_amount)); assert_ok!(::MultiCurrency::deposit(REWARD_2, &investor, reward_amount)); let caller: T::AccountId = whitelisted_caller(); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get())); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get())); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount)); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount)); assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), @@ -101,19 +95,15 @@ benchmarks! { redeem { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let reward_amount: BalanceOf = { - let duration: u128 = duration.saturated_into(); - let per_block: u128 = T::MinimumRewardPerBlock::get().saturated_into(); - (duration * (per_block + 1)).saturated_into() - }; + let reward_amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, reward_amount)); assert_ok!(::MultiCurrency::deposit(REWARD_2, &investor, reward_amount)); let caller: T::AccountId = whitelisted_caller(); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get())); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get())); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount)); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount)); assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), @@ -127,7 +117,7 @@ benchmarks! { assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get())); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount)); // Run to block run_to_block::(duration); @@ -143,19 +133,15 @@ benchmarks! { volunteer_to_redeem { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let reward_amount: BalanceOf = { - let duration: u128 = duration.saturated_into(); - let per_block: u128 = T::MinimumRewardPerBlock::get().saturated_into(); - (duration * (per_block + 1)).saturated_into() - }; + let reward_amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, reward_amount)); assert_ok!(::MultiCurrency::deposit(REWARD_2, &investor, reward_amount)); let caller: T::AccountId = whitelisted_caller(); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get())); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get())); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount)); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount)); assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), @@ -169,7 +155,7 @@ benchmarks! { assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get())); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount)); // Run to block run_to_block::(duration); @@ -187,19 +173,15 @@ benchmarks! { claim { let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into()); let min_deposit_to_start = T::MinimumDepositOfUser::get(); - let reward_amount: BalanceOf = { - let duration: u128 = duration.saturated_into(); - let per_block: u128 = T::MinimumRewardPerBlock::get().saturated_into(); - (duration * (per_block + 1)).saturated_into() - }; + let reward_amount: BalanceOf = UNIT.saturated_into(); let investor: T::AccountId = account("lm", 0, 0); assert_ok!(::MultiCurrency::deposit(REWARD_1, &investor, reward_amount)); assert_ok!(::MultiCurrency::deposit(REWARD_2, &investor, reward_amount)); let caller: T::AccountId = whitelisted_caller(); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get())); - assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get())); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount)); + assert_ok!(::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount)); assert_ok!(LM::::create_pool( (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2), @@ -213,7 +195,7 @@ benchmarks! { assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0)); - assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get())); + assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount)); // Run to block run_to_block::(1u128.saturated_into()); diff --git a/pallets/liquidity-mining/src/lib.rs b/pallets/liquidity-mining/src/lib.rs index 8d2645e1d4..012494d959 100644 --- a/pallets/liquidity-mining/src/lib.rs +++ b/pallets/liquidity-mining/src/lib.rs @@ -47,6 +47,8 @@ mod mock; mod tests; pub mod weights; +pub use weights::*; + const DEPOSIT_ID: LockIdentifier = *b"lm/depos"; #[derive(Encode, Decode, Clone, Eq, PartialEq)] @@ -370,6 +372,8 @@ pub mod pallet { /// ModuleID for creating sub account #[pallet::constant] type PalletId: Get; + + type WeightInfo: WeightInfo; } #[pallet::error] @@ -582,7 +586,7 @@ pub mod pallet { Ok(().into()) } - #[pallet::weight(1_000)] + #[pallet::weight(T::WeightInfo::charge())] pub fn charge(origin: OriginFor, pid: PoolId) -> DispatchResultWithPostInfo { let investor = ensure_signed(origin)?; @@ -684,7 +688,7 @@ pub mod pallet { /// - User should deposit enough(greater than `T::MinimumDeposit`) token to liquidity-pool; /// - The liquidity-pool should be in special state: `Charged`, `Ongoing`; #[transactional] - #[pallet::weight(1_000)] + #[pallet::weight(T::WeightInfo::deposit())] pub fn deposit( origin: OriginFor, pid: PoolId, @@ -789,7 +793,7 @@ pub mod pallet { /// - User should have some deposit in the liquidity-pool; /// - The liquidity-pool should be in special state: `Ongoing`, `Retired`; #[transactional] - #[pallet::weight(1_000)] + #[pallet::weight(T::WeightInfo::redeem())] pub fn redeem(origin: OriginFor, pid: PoolId) -> DispatchResultWithPostInfo { let user = ensure_signed(origin)?; @@ -882,7 +886,7 @@ pub mod pallet { /// /// NOTE: The liquidity-pool should be in retired state. #[transactional] - #[pallet::weight(1_000)] + #[pallet::weight(T::WeightInfo::volunteer_to_redeem())] pub fn volunteer_to_redeem( _origin: OriginFor, pid: PoolId, @@ -917,7 +921,7 @@ pub mod pallet { /// - User should have enough token deposited in the liquidity-pool; /// - The liquidity-pool should be in special states: `Ongoing`; #[transactional] - #[pallet::weight(1_000)] + #[pallet::weight(T::WeightInfo::claim())] pub fn claim(origin: OriginFor, pid: PoolId) -> DispatchResultWithPostInfo { let user = ensure_signed(origin)?; diff --git a/pallets/liquidity-mining/src/mock.rs b/pallets/liquidity-mining/src/mock.rs index d233118ce1..174ba5e4cc 100644 --- a/pallets/liquidity-mining/src/mock.rs +++ b/pallets/liquidity-mining/src/mock.rs @@ -182,6 +182,7 @@ impl lm::Config for Test { type MaximumCharged = MaximumApproved; type MaximumOptionRewards = MaximumOptionRewards; type PalletId = LiquidityMiningPalletId; + type WeightInfo = (); } pub(crate) fn new_test_ext() -> TestExternalities { diff --git a/runtime/asgard/src/lib.rs b/runtime/asgard/src/lib.rs index a7d2a78872..114eadd3cc 100644 --- a/runtime/asgard/src/lib.rs +++ b/runtime/asgard/src/lib.rs @@ -1162,6 +1162,7 @@ impl bifrost_liquidity_mining::Config for Runtime { type MaximumCharged = MaximumApproved; type MaximumOptionRewards = MaximumOptionRewards; type PalletId = LiquidityMiningPalletId; + type WeightInfo = (); } // bifrost runtime end diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs index 7816b57aa0..5f62ab6d0b 100644 --- a/runtime/bifrost/src/lib.rs +++ b/runtime/bifrost/src/lib.rs @@ -1066,6 +1066,7 @@ impl bifrost_liquidity_mining::Config for Runtime { type MaximumCharged = MaximumCharged; type MaximumOptionRewards = MaximumOptionRewards; type PalletId = LiquidityMiningPalletId; + type WeightInfo = weights::bifrost_liquidity_mining::WeightInfo; } // Bifrost modules end diff --git a/runtime/bifrost/src/weights/bifrost_liquidity_mining.rs b/runtime/bifrost/src/weights/bifrost_liquidity_mining.rs new file mode 100644 index 0000000000..391f8ffee2 --- /dev/null +++ b/runtime/bifrost/src/weights/bifrost_liquidity_mining.rs @@ -0,0 +1,117 @@ +// This file is part of Bifrost. + +// Copyright (C) 2019-2021 Liebi Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Autogenerated weights for `bifrost_liquidity_mining` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-23, STEPS: `50`, REPEAT: 1, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("bifrost-local"), DB CACHE: 128 + +// Executed Command: +// target/release/bifrost +// benchmark +// --chain=bifrost-local +// --steps=50 +// --repeat=1 +// --pallet=bifrost-liquidity-mining +// --extrinsic=* +// --execution=wasm +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./runtime/bifrost/src/weights/bifrost_liquidity_mining + + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +/// Weight functions for bifrost_liquidity_mining. +pub struct WeightInfo(PhantomData); +impl bifrost_liquidity_mining::WeightInfo for WeightInfo { + // Storage: LiquidityMining ChargedPoolIds (r:1 w:1) + // Storage: LiquidityMining TotalPoolInfos (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: System Account (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + fn charge() -> Weight { + (132_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } + // Storage: LiquidityMining TotalPoolInfos (r:1 w:1) + // Storage: LiquidityMining TotalDepositData (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: Tokens Locks (r:2 w:2) + // Storage: System Number (r:1 w:0) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + fn deposit() -> Weight { + (88_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(10 as Weight)) + .saturating_add(T::DbWeight::get().writes(8 as Weight)) + } + // Storage: LiquidityMining TotalPoolInfos (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: LiquidityMining TotalDepositData (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: Tokens Locks (r:2 w:2) + fn redeem() -> Weight { + (179_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(13 as Weight)) + .saturating_add(T::DbWeight::get().writes(11 as Weight)) + } + // Storage: LiquidityMining TotalPoolInfos (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: LiquidityMining TotalDepositData (r:2 w:1) + // Storage: System Account (r:1 w:1) + // Storage: Tokens Accounts (r:4 w:4) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + // Storage: Tokens Locks (r:2 w:2) + fn volunteer_to_redeem() -> Weight { + (199_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(14 as Weight)) + .saturating_add(T::DbWeight::get().writes(11 as Weight)) + } + // Storage: LiquidityMining TotalPoolInfos (r:1 w:1) + // Storage: System Number (r:1 w:0) + // Storage: LiquidityMining TotalDepositData (r:1 w:1) + // Storage: System Account (r:1 w:1) + // Storage: Tokens Accounts (r:2 w:2) + // Storage: System ExecutionPhase (r:1 w:0) + // Storage: System EventCount (r:1 w:1) + // Storage: System Events (r:1 w:1) + fn claim() -> Weight { + (117_000_000 as Weight) + .saturating_add(T::DbWeight::get().reads(9 as Weight)) + .saturating_add(T::DbWeight::get().writes(7 as Weight)) + } +} diff --git a/runtime/bifrost/src/weights/mod.rs b/runtime/bifrost/src/weights/mod.rs index d86013d5af..a5c5464385 100644 --- a/runtime/bifrost/src/weights/mod.rs +++ b/runtime/bifrost/src/weights/mod.rs @@ -21,6 +21,7 @@ //! A list of the different weight modules for our runtime. pub mod bifrost_flexible_fee; +pub mod bifrost_liquidity_mining; pub mod bifrost_salp; pub mod frame_system; pub mod orml_tokens; diff --git a/runtime/dev/src/lib.rs b/runtime/dev/src/lib.rs index 21c39e2bfe..2b9c35f8ff 100644 --- a/runtime/dev/src/lib.rs +++ b/runtime/dev/src/lib.rs @@ -1132,6 +1132,7 @@ impl bifrost_liquidity_mining::Config for Runtime { type MaximumCharged = MaximumApproved; type MaximumOptionRewards = MaximumOptionRewards; type PalletId = LiquidityMiningPalletId; + type WeightInfo = (); } // bifrost runtime end