Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 18 additions & 36 deletions pallets/liquidity-mining/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
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, *};

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<T: Config>(n: BlockNumberFor<T>) {
type System<T> = frame_system::Pallet<T>;
Expand All @@ -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<T> = {
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<T> = UNIT.saturated_into();

assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &caller, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &caller, reward_amount));
Expand All @@ -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<T> = {
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<T> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, reward_amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount));

assert_ok!(LM::<T>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
Expand All @@ -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<T> = {
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<T> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, reward_amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount));

assert_ok!(LM::<T>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
Expand All @@ -127,7 +117,7 @@ benchmarks! {

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount));

// Run to block
run_to_block::<T>(duration);
Expand All @@ -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<T> = {
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<T> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, reward_amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount));

assert_ok!(LM::<T>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
Expand All @@ -169,7 +155,7 @@ benchmarks! {

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount));

// Run to block
run_to_block::<T>(duration);
Expand All @@ -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<T> = {
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<T> = UNIT.saturated_into();

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_1, &investor, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(REWARD_2, &investor, reward_amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, T::MinimumDepositOfUser::get()));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, reward_amount));
assert_ok!(<T as Config>::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, reward_amount));

assert_ok!(LM::<T>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
Expand All @@ -213,7 +195,7 @@ benchmarks! {

assert_ok!(LM::<T>::charge(RawOrigin::Signed(investor).into(), 0));

assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
assert_ok!(LM::<T>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, reward_amount));

// Run to block
run_to_block::<T>(1u128.saturated_into());
Expand Down
14 changes: 9 additions & 5 deletions pallets/liquidity-mining/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -370,6 +372,8 @@ pub mod pallet {
/// ModuleID for creating sub account
#[pallet::constant]
type PalletId: Get<PalletId>;

type WeightInfo: WeightInfo;
}

#[pallet::error]
Expand Down Expand Up @@ -582,7 +586,7 @@ pub mod pallet {
Ok(().into())
}

#[pallet::weight(1_000)]
#[pallet::weight(T::WeightInfo::charge())]
pub fn charge(origin: OriginFor<T>, pid: PoolId) -> DispatchResultWithPostInfo {
let investor = ensure_signed(origin)?;

Expand Down Expand Up @@ -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<T>,
pid: PoolId,
Expand Down Expand Up @@ -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<T>, pid: PoolId) -> DispatchResultWithPostInfo {
let user = ensure_signed(origin)?;

Expand Down Expand Up @@ -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<T>,
pid: PoolId,
Expand Down Expand Up @@ -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<T>, pid: PoolId) -> DispatchResultWithPostInfo {
let user = ensure_signed(origin)?;

Expand Down
1 change: 1 addition & 0 deletions pallets/liquidity-mining/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions runtime/asgard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>;
}

// Bifrost modules end
Expand Down
117 changes: 117 additions & 0 deletions runtime/bifrost/src/weights/bifrost_liquidity_mining.rs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

//! 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<T>(PhantomData<T>);
impl<T: frame_system::Config> bifrost_liquidity_mining::WeightInfo for WeightInfo<T> {
// 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))
}
}
1 change: 1 addition & 0 deletions runtime/bifrost/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down