diff --git a/pallets/liquidity-mining/Cargo.toml b/pallets/liquidity-mining/Cargo.toml
index e87a7475b1..0d0f18c258 100644
--- a/pallets/liquidity-mining/Cargo.toml
+++ b/pallets/liquidity-mining/Cargo.toml
@@ -12,6 +12,7 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false }
node-primitives = { path = "../../node/primitives", default-features = false }
orml-traits = { version = "0.4.1-dev", default-features = false }
+frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9", default-features = false, optional = true }
[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.9" }
@@ -28,4 +29,14 @@ std = [
"frame-support/std",
"node-primitives/std",
"orml-traits/std",
+]
+
+runtime-benchmarks = [
+ "frame-benchmarking",
+ "frame-support/runtime-benchmarks",
+ "frame-system/runtime-benchmarks",
+]
+
+local-benchmarks = [
+ "pallet-collective/runtime-benchmarks",
]
\ No newline at end of file
diff --git a/pallets/liquidity-mining/src/benchmarking.rs b/pallets/liquidity-mining/src/benchmarking.rs
new file mode 100644
index 0000000000..12e9c0d304
--- /dev/null
+++ b/pallets/liquidity-mining/src/benchmarking.rs
@@ -0,0 +1,224 @@
+// 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 .
+
+// Ensure we're `no_std` when compiling for Wasm.
+#![cfg(feature = "runtime-benchmarks")]
+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 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);
+
+fn run_to_block(n: BlockNumberFor) {
+ type System = frame_system::Pallet;
+
+ while System::::block_number() < n {
+ LM::::on_finalize(System::::block_number());
+ System::::on_finalize(System::::block_number());
+ System::::set_block_number(System::::block_number() + 1u128.saturated_into());
+ System::::on_initialize(System::::block_number());
+ LM::::on_initialize(System::::block_number());
+ }
+}
+
+benchmarks! {
+ charge {
+ let caller: T::AccountId = whitelisted_caller();
+
+ 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()
+ };
+
+ assert_ok!(::MultiCurrency::deposit(REWARD_1, &caller, reward_amount));
+ assert_ok!(::MultiCurrency::deposit(REWARD_2, &caller, reward_amount));
+
+ assert_ok!(LM::::create_pool(
+ (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
+ (REWARD_1, reward_amount),
+ vec![(REWARD_2, reward_amount)].try_into().unwrap(),
+ PoolType::Farming,
+ duration,
+ min_deposit_to_start,
+ 0u128.saturated_into()
+ ));
+ }: _(RawOrigin::Signed(caller.clone()), 0)
+
+ 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 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!(LM::::create_pool(
+ (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
+ (REWARD_1, reward_amount),
+ vec![(REWARD_2, reward_amount)].try_into().unwrap(),
+ PoolType::Farming,
+ duration,
+ min_deposit_to_start,
+ 0u128.saturated_into()
+ ));
+
+ assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0));
+
+ }: _(RawOrigin::Signed(caller.clone()), 0, T::MinimumDepositOfUser::get())
+
+ 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 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!(LM::::create_pool(
+ (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
+ (REWARD_1, reward_amount),
+ vec![(REWARD_2, reward_amount)].try_into().unwrap(),
+ PoolType::Farming,
+ duration,
+ min_deposit_to_start,
+ 0u128.saturated_into()
+ ));
+
+ assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0));
+
+ assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
+
+ // Run to block
+ run_to_block::(duration);
+
+ }: _(RawOrigin::Signed(caller.clone()), 0)
+ verify {
+ let pool = LM::::pool(0);
+ let deposit_data = LM::::user_deposit_data(0, caller.clone());
+ assert!(pool.is_none());
+ assert!(deposit_data.is_none());
+ }
+
+ 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 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!(LM::::create_pool(
+ (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
+ (REWARD_1, reward_amount),
+ vec![(REWARD_2, reward_amount)].try_into().unwrap(),
+ PoolType::Farming,
+ duration,
+ min_deposit_to_start,
+ 0u128.saturated_into()
+ ));
+
+ assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0));
+
+ assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
+
+ // Run to block
+ run_to_block::(duration);
+
+ let volunteer = account("lm", 0, 1);
+
+ }: _(RawOrigin::Signed(volunteer), 0, None)
+ verify {
+ let pool = LM::::pool(0);
+ let deposit_data = LM::::user_deposit_data(0, caller.clone());
+ assert!(pool.is_none());
+ assert!(deposit_data.is_none());
+ }
+
+ 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 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!(LM::::create_pool(
+ (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
+ (REWARD_1, reward_amount),
+ vec![(REWARD_2, reward_amount)].try_into().unwrap(),
+ PoolType::Farming,
+ duration,
+ min_deposit_to_start,
+ 0u128.saturated_into()
+ ));
+
+ assert_ok!(LM::::charge(RawOrigin::Signed(investor).into(), 0));
+
+ assert_ok!(LM::::deposit(RawOrigin::Signed(caller.clone()).into(), 0, T::MinimumDepositOfUser::get()));
+
+ // Run to block
+ run_to_block::(1u128.saturated_into());
+
+ }: _(RawOrigin::Signed(caller.clone()), 0)
+}
+
+impl_benchmark_test_suite!(LM, crate::mock::new_test_ext(), crate::mock::Test);
diff --git a/pallets/liquidity-mining/src/lib.rs b/pallets/liquidity-mining/src/lib.rs
index 6ec1496e98..8d2645e1d4 100644
--- a/pallets/liquidity-mining/src/lib.rs
+++ b/pallets/liquidity-mining/src/lib.rs
@@ -39,10 +39,13 @@ use node_primitives::{CurrencyId, CurrencyIdExt, LeasePeriod, ParaId, TokenInfo,
use orml_traits::{LockIdentifier, MultiCurrency, MultiLockableCurrency, MultiReservableCurrency};
pub use pallet::*;
+#[cfg(feature = "runtime-benchmarks")]
+mod benchmarking;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
+pub mod weights;
const DEPOSIT_ID: LockIdentifier = *b"lm/depos";
@@ -197,8 +200,11 @@ impl PoolInfo {
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Debug)]
pub enum PoolType {
+ /// Only `LpToken` can deposit into the pool
Mining,
+ /// Only `vsToken` + `vsBond` can deposit into the pool
Farming,
+ /// Only `vsToken(reserved)` + `vsBond(reserved)` can deposit into the pool
EBFarming,
}
@@ -470,7 +476,11 @@ pub mod pallet {
#[pallet::call]
impl Pallet {
- #[pallet::weight(1_000)]
+ #[pallet::weight((
+ 0,
+ DispatchClass::Normal,
+ Pays::No
+ ))]
pub fn create_mining_pool(
origin: OriginFor,
trading_pair: (CurrencyId, CurrencyId),
@@ -480,6 +490,8 @@ pub mod pallet {
#[pallet::compact] min_deposit_to_start: BalanceOf,
#[pallet::compact] after_block_to_start: BlockNumberFor,
) -> DispatchResultWithPostInfo {
+ let _ = T::ControlOrigin::ensure_origin(origin)?;
+
// Order the trading_pair
let (token1, token2) = trading_pair;
@@ -490,7 +502,6 @@ pub mod pallet {
let trading_pair = if id1 <= id2 { (token1, token2) } else { (token2, token1) };
Self::create_pool(
- origin,
trading_pair,
main_reward,
option_rewards,
@@ -503,7 +514,11 @@ pub mod pallet {
Ok(().into())
}
- #[pallet::weight(1_000)]
+ #[pallet::weight((
+ 0,
+ DispatchClass::Normal,
+ Pays::No
+ ))]
pub fn create_farming_pool(
origin: OriginFor,
index: ParaId,
@@ -515,11 +530,12 @@ pub mod pallet {
#[pallet::compact] min_deposit_to_start: BalanceOf,
#[pallet::compact] after_block_to_start: BlockNumberFor,
) -> DispatchResultWithPostInfo {
+ let _ = T::ControlOrigin::ensure_origin(origin)?;
+
#[allow(non_snake_case)]
let trading_pair = Self::vsAssets(index, first_slot, last_slot);
Self::create_pool(
- origin,
trading_pair,
main_reward,
option_rewards,
@@ -532,7 +548,11 @@ pub mod pallet {
Ok(().into())
}
- #[pallet::weight(1_000)]
+ #[pallet::weight((
+ 0,
+ DispatchClass::Normal,
+ Pays::No
+ ))]
pub fn create_eb_farming_pool(
origin: OriginFor,
index: ParaId,
@@ -544,11 +564,12 @@ pub mod pallet {
#[pallet::compact] min_deposit_to_start: BalanceOf,
#[pallet::compact] after_block_to_start: BlockNumberFor,
) -> DispatchResultWithPostInfo {
+ let _ = T::ControlOrigin::ensure_origin(origin)?;
+
#[allow(non_snake_case)]
let trading_pair = Self::vsAssets(index, first_slot, last_slot);
Self::create_pool(
- origin,
trading_pair,
main_reward,
option_rewards,
@@ -595,7 +616,11 @@ pub mod pallet {
Ok(().into())
}
- #[pallet::weight(1_000)]
+ #[pallet::weight((
+ 0,
+ DispatchClass::Normal,
+ Pays::No
+ ))]
pub fn kill_pool(origin: OriginFor, pid: PoolId) -> DispatchResultWithPostInfo {
let _ = T::ControlOrigin::ensure_origin(origin)?;
@@ -615,7 +640,11 @@ pub mod pallet {
Ok(().into())
}
- #[pallet::weight(1_000)]
+ #[pallet::weight((
+ 0,
+ DispatchClass::Normal,
+ Pays::No
+ ))]
pub fn force_retire_pool(origin: OriginFor, pid: PoolId) -> DispatchResultWithPostInfo {
let _ = T::ControlOrigin::ensure_origin(origin)?;
@@ -912,7 +941,6 @@ pub mod pallet {
impl Pallet {
pub(crate) fn create_pool(
- origin: OriginFor,
trading_pair: (CurrencyId, CurrencyId),
main_reward: (CurrencyId, BalanceOf),
option_rewards: BoundedVec<(CurrencyId, BalanceOf), T::MaximumOptionRewards>,
@@ -921,8 +949,6 @@ pub mod pallet {
min_deposit_to_start: BalanceOf,
after_block_to_start: BlockNumberFor,
) -> DispatchResult {
- let _ = T::ControlOrigin::ensure_origin(origin)?;
-
// Check the trading-pair
ensure!(trading_pair.0 != trading_pair.1, Error::::InvalidTradingPair);
diff --git a/pallets/liquidity-mining/src/mock.rs b/pallets/liquidity-mining/src/mock.rs
index 9b445b55ee..d233118ce1 100644
--- a/pallets/liquidity-mining/src/mock.rs
+++ b/pallets/liquidity-mining/src/mock.rs
@@ -32,14 +32,14 @@ use sp_core::H256;
use crate as lm;
pub(crate) type AccountId = <::Signer as IdentifyAccount>::AccountId;
-pub(crate) type Block = frame_system::mocking::MockBlock;
+pub(crate) type Block = frame_system::mocking::MockBlock;
pub(crate) type BlockNumber = u32;
pub(crate) type Index = u32;
pub(crate) type Signature = MultiSignature;
-pub(crate) type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
+pub(crate) type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
construct_runtime!(
- pub enum T where
+ pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
@@ -48,7 +48,7 @@ construct_runtime!(
Balances: pallet_balances::{Pallet, Call, Storage, Event},
Currencies: orml_currencies::{Pallet, Call, Event},
Tokens: orml_tokens::{Pallet, Call, Storage, Event, Config},
- TechnicalCommittee: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config},
+ Collective: pallet_collective::::{Pallet, Call, Storage, Origin, Event, Config},
LM: lm::{Pallet, Call, Storage, Event},
}
);
@@ -64,7 +64,7 @@ parameter_types! {
frame_system::limits::BlockWeights::simple_max(1024);
}
-impl frame_system::Config for T {
+impl frame_system::Config for Test {
type AccountData = pallet_balances::AccountData;
type AccountId = AccountId;
type BaseCallFilter = frame_support::traits::Everything;
@@ -99,7 +99,7 @@ parameter_types! {
pub const MaxReserves: u32 = 999_999;
}
-impl pallet_balances::Config for T {
+impl pallet_balances::Config for Test {
type AccountStore = System;
/// The type for recording an account's balance.
type Balance = Balance;
@@ -110,12 +110,12 @@ impl pallet_balances::Config for T {
type MaxLocks = MaxLocks;
type MaxReserves = MaxReserves;
type ReserveIdentifier = [u8; 8];
- type WeightInfo = pallet_balances::weights::SubstrateWeight;
+ type WeightInfo = pallet_balances::weights::SubstrateWeight;
}
-pub type BifrostToken = orml_currencies::BasicCurrencyAdapter;
+pub type BifrostToken = orml_currencies::BasicCurrencyAdapter;
-impl orml_currencies::Config for T {
+impl orml_currencies::Config for Test {
type Event = Event;
type GetNativeCurrencyId = NativeCurrencyId;
type MultiCurrency = Tokens;
@@ -129,7 +129,7 @@ orml_traits::parameter_type_with_key! {
};
}
-impl orml_tokens::Config for T {
+impl orml_tokens::Config for Test {
type Amount = Amount;
type Balance = Balance;
type CurrencyId = CurrencyId;
@@ -148,7 +148,7 @@ parameter_types! {
}
type TechnicalCollective = pallet_collective::Instance1;
-impl pallet_collective::Config for T {
+impl pallet_collective::Config for Test {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type Event = Event;
type MaxMembers = TechnicalMaxMembers;
@@ -156,7 +156,7 @@ impl pallet_collective::Config for T {
type MotionDuration = TechnicalMotionDuration;
type Origin = Origin;
type Proposal = Call;
- type WeightInfo = pallet_collective::weights::SubstrateWeight;
+ type WeightInfo = pallet_collective::weights::SubstrateWeight;
}
parameter_types! {
@@ -170,7 +170,7 @@ parameter_types! {
pub const LiquidityMiningPalletId: PalletId = PalletId(*b"mining##");
}
-impl lm::Config for T {
+impl lm::Config for Test {
type Event = Event;
type ControlOrigin = pallet_collective::EnsureMember;
type MultiCurrency = Tokens;
@@ -186,7 +186,7 @@ impl lm::Config for T {
pub(crate) fn new_test_ext() -> TestExternalities {
GenesisConfig {
- tokens: orml_tokens::GenesisConfig:: {
+ tokens: orml_tokens::GenesisConfig:: {
balances: vec![
(INVESTOR, REWARD_1, REWARD_AMOUNT),
(INVESTOR, REWARD_2, REWARD_AMOUNT),
@@ -201,7 +201,7 @@ pub(crate) fn new_test_ext() -> TestExternalities {
(RICHER, MINING_DEPOSIT, 1_000_000_000_000 * UNIT),
],
},
- technical_committee: pallet_collective::GenesisConfig {
+ collective: pallet_collective::GenesisConfig {
members: vec![TC_MEMBER_1, TC_MEMBER_2, TC_MEMBER_3],
phantom: Default::default(),
},
diff --git a/pallets/liquidity-mining/src/tests.rs b/pallets/liquidity-mining/src/tests.rs
index 8c2e1b3d75..bc5c026e19 100644
--- a/pallets/liquidity-mining/src/tests.rs
+++ b/pallets/liquidity-mining/src/tests.rs
@@ -24,10 +24,14 @@ use frame_support::{
sp_runtime::{FixedPointNumber, FixedU128},
traits::Hooks,
};
+use frame_system::pallet_prelude::OriginFor;
use node_primitives::{Balance, CurrencyId, TokenSymbol};
use orml_traits::MultiReservableCurrency;
-use crate::{mock::*, Error, PoolId, PoolInfo, PoolState, PoolType, TotalPoolInfos};
+use crate::{
+ mock::{Test as T, *},
+ Error, PoolId, PoolInfo, PoolState, PoolType, TotalPoolInfos,
+};
fn run_to_block(n: BlockNumber) {
while System::block_number() < n {
@@ -138,7 +142,6 @@ fn increase_pid_when_create_pool_should_work() {
const NUM: PoolId = 8;
for pid in 0..NUM {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT / NUM as Balance),
vec![(REWARD_2, REWARD_AMOUNT / NUM as Balance)].try_into().unwrap(),
@@ -156,47 +159,53 @@ fn increase_pid_when_create_pool_should_work() {
#[test]
fn create_pool_with_wrong_origin_should_fail() {
new_test_ext().execute_with(|| {
- assert_noop!(
- LM::create_pool(
- Origin::root(),
- (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
- (REWARD_1, REWARD_AMOUNT),
- vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
- PoolType::Farming,
- DAYS,
- 1_000 * UNIT,
- 0
- ),
- DispatchError::BadOrigin,
- );
-
- assert_noop!(
- LM::create_pool(
- Origin::none(),
- (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
- (REWARD_1, REWARD_AMOUNT),
- vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
- PoolType::Farming,
- DAYS,
- 1_000 * UNIT,
- 0
- ),
- DispatchError::BadOrigin,
- );
-
- assert_noop!(
- LM::create_pool(
- Some(INVESTOR).into(),
- (FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
- (REWARD_1, REWARD_AMOUNT),
- vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
- PoolType::Farming,
- DAYS,
- 1_000 * UNIT,
- 0
- ),
- DispatchError::BadOrigin,
- );
+ let wrong_origins: [OriginFor; 3] =
+ [Origin::root(), Origin::none(), Some(INVESTOR).into()];
+
+ for wrong_origin in wrong_origins {
+ assert_noop!(
+ LM::create_mining_pool(
+ wrong_origin.clone(),
+ MINING_TRADING_PAIR,
+ (REWARD_1, REWARD_AMOUNT),
+ vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
+ DAYS,
+ 1_000 * UNIT,
+ 0
+ ),
+ DispatchError::BadOrigin,
+ );
+
+ assert_noop!(
+ LM::create_farming_pool(
+ wrong_origin.clone(),
+ 2001,
+ 13,
+ 20,
+ (REWARD_1, REWARD_AMOUNT),
+ vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
+ DAYS,
+ 1_000 * UNIT,
+ 0
+ ),
+ DispatchError::BadOrigin
+ );
+
+ assert_noop!(
+ LM::create_eb_farming_pool(
+ wrong_origin.clone(),
+ 2001,
+ 13,
+ 20,
+ (REWARD_1, REWARD_AMOUNT),
+ vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
+ DAYS,
+ 1_000 * UNIT,
+ 0
+ ),
+ DispatchError::BadOrigin
+ );
+ }
});
}
@@ -205,7 +214,6 @@ fn create_pool_with_duplicate_trading_pair_should_fail() {
new_test_ext().execute_with(|| {
assert_noop!(
LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_1),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -224,7 +232,6 @@ fn create_pool_with_too_small_duration_should_fail() {
new_test_ext().execute_with(|| {
assert_noop!(
LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -243,7 +250,6 @@ fn create_pool_with_wrong_condition_should_fail() {
new_test_ext().execute_with(|| {
assert_noop!(
LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -257,7 +263,6 @@ fn create_pool_with_wrong_condition_should_fail() {
assert_noop!(
LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -276,7 +281,6 @@ fn create_pool_with_too_small_per_block_should_fail() {
new_test_ext().execute_with(|| {
assert_noop!(
LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -294,7 +298,6 @@ fn create_pool_with_too_small_per_block_should_fail() {
fn create_pool_with_duplicate_reward_should_fail() {
new_test_ext().execute_with(|| {
let result = LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_1, REWARD_AMOUNT)].try_into().unwrap(),
@@ -311,7 +314,6 @@ fn create_pool_with_duplicate_reward_should_fail() {
fn charge_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -357,7 +359,6 @@ fn charge_should_work() {
fn charge_with_wrong_origin_should_fail() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -380,7 +381,6 @@ fn charge_with_wrong_origin_should_fail() {
fn charge_with_wrong_state_should_fail() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -400,7 +400,6 @@ fn charge_exceed_maximum_should_fail() {
new_test_ext().execute_with(|| {
for i in 0..MaximumApproved::get() {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT / (MaximumApproved::get() + 1) as u128),
vec![(REWARD_2, REWARD_AMOUNT / (MaximumApproved::get() + 1) as u128)]
@@ -418,7 +417,6 @@ fn charge_exceed_maximum_should_fail() {
}
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT / (MaximumApproved::get() + 1) as u128),
vec![(REWARD_2, REWARD_AMOUNT / (MaximumApproved::get() + 1) as u128)]
@@ -443,7 +441,6 @@ fn charge_exceed_maximum_should_fail() {
fn charge_without_enough_balance_should_fail() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -466,7 +463,6 @@ fn charge_without_enough_balance_should_fail() {
fn kill_pool_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -489,7 +485,6 @@ fn kill_pool_should_work() {
fn kill_pool_with_wrong_origin_should_fail() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
@@ -509,7 +504,6 @@ fn kill_pool_with_wrong_origin_should_fail() {
fn kill_pool_with_wrong_state_should_fail() {
new_test_ext().execute_with(|| {
assert_ok!(LM::create_pool(
- pallet_collective::RawOrigin::Member(TC_MEMBER_1).into(),
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, REWARD_AMOUNT),
vec![(REWARD_2, REWARD_AMOUNT)].try_into().unwrap(),
diff --git a/pallets/liquidity-mining/src/weights.rs b/pallets/liquidity-mining/src/weights.rs
new file mode 100644
index 0000000000..363226cc5d
--- /dev/null
+++ b/pallets/liquidity-mining/src/weights.rs
@@ -0,0 +1,58 @@
+// 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 .
+
+#![allow(unused_parens)]
+#![allow(unused_imports)]
+
+use frame_support::{
+ sp_std::marker::PhantomData,
+ traits::Get,
+ weights::{constants::RocksDbWeight, Weight},
+};
+
+/// Weight functions needed for the pallet.
+pub trait WeightInfo {
+ fn charge() -> Weight;
+ fn deposit() -> Weight;
+ fn redeem() -> Weight;
+ fn volunteer_to_redeem() -> Weight;
+ fn claim() -> Weight;
+}
+
+// For backwards compatibility and tests
+impl WeightInfo for () {
+ fn charge() -> Weight {
+ (50_000_000 as Weight)
+ }
+
+ fn deposit() -> Weight {
+ (50_000_000 as Weight)
+ }
+
+ fn redeem() -> Weight {
+ (50_000_000 as Weight)
+ }
+
+ fn volunteer_to_redeem() -> Weight {
+ (50_000_000 as Weight)
+ }
+
+ fn claim() -> Weight {
+ (50_000_000 as Weight)
+ }
+}
diff --git a/pallets/salp/src/benchmarking.rs b/pallets/salp/src/benchmarking.rs
index c57c6c5e18..c0cb10dd57 100644
--- a/pallets/salp/src/benchmarking.rs
+++ b/pallets/salp/src/benchmarking.rs
@@ -81,13 +81,11 @@ benchmarks! {
));
assert_ok!(Salp::::fund_fail(RawOrigin::Root.into(), fund_index));
assert_ok!(Salp::::withdraw(RawOrigin::Root.into(), fund_index));
- assert_eq!(Salp::::refund_pool(), T::MinContribution::get());
let fund = Salp::::funds(fund_index).unwrap();
let (_, status) = Salp::::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Idle);
}: _(RawOrigin::Signed(caller.clone()), fund_index)
verify {
- assert_eq!(Salp::::refund_pool(), 0_u32.saturated_into());
let (_, status) = Salp::::contribution(fund.trie_index, &caller);
assert_eq!(status, ContributionStatus::Refunded);
assert_last_event::(Event::::Refunded(caller.clone(), fund_index, contribution).into())
diff --git a/pallets/vsbond-auction/src/benchmarking.rs b/pallets/vsbond-auction/src/benchmarking.rs
index f7366f19e1..a53e76d76c 100644
--- a/pallets/vsbond-auction/src/benchmarking.rs
+++ b/pallets/vsbond-auction/src/benchmarking.rs
@@ -34,7 +34,8 @@ benchmarks! {
let last_slot = 20u32;
let supply = BalanceOf::::unique_saturated_from(10u128);
let total_price = BalanceOf::::unique_saturated_from(30u128);
- }: _(RawOrigin::Signed(caller), index, first_slot, last_slot, supply, total_price)
+ let order_type = OrderType::Sell;
+ }: _(RawOrigin::Signed(caller), index, first_slot, last_slot, supply, total_price, order_type)
revoke_order {
let caller: T::AccountId = whitelisted_caller();
@@ -43,8 +44,9 @@ benchmarks! {
let last_slot = 20u32;
let supply = BalanceOf::::unique_saturated_from(10u128);
let total_price = BalanceOf::::unique_saturated_from(30u128);
+ let order_type = OrderType::Sell;
- VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(caller.clone())), index, first_slot, last_slot, supply, total_price)?;
+ VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(caller.clone())), index, first_slot, last_slot, supply, total_price, order_type)?;
}: _(RawOrigin::Signed(caller),0u64)
clinch_order {
@@ -55,8 +57,9 @@ benchmarks! {
let supply = BalanceOf::::unique_saturated_from(10u128);
let total_price = BalanceOf::::unique_saturated_from(30u128);
let order_owner = account("bechmarking_account_1", 0, 0);
+ let order_type = OrderType::Sell;
- VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price)?;
+ VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price, order_type)?;
}: _(RawOrigin::Signed(caller),0u64)
partial_clinch_order {
@@ -67,8 +70,9 @@ benchmarks! {
let supply = BalanceOf::::unique_saturated_from(10u128);
let total_price = BalanceOf::::unique_saturated_from(30u128);
let order_owner = account("bechmarking_account_1", 0, 0);
+ let order_type = OrderType::Sell;
- VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price)?;
+ VSBondAuction::::create_order(::Origin::from(RawOrigin::Signed(order_owner)), index, first_slot, last_slot, supply, total_price, order_type)?;
}: _(RawOrigin::Signed(caller),0u64, BalanceOf::::unique_saturated_from(5u128))
}
diff --git a/runtime/bifrost/Cargo.toml b/runtime/bifrost/Cargo.toml
index 2b0ed0f3d9..0cc55cbcc8 100644
--- a/runtime/bifrost/Cargo.toml
+++ b/runtime/bifrost/Cargo.toml
@@ -185,6 +185,7 @@ runtime-benchmarks = [
"xcm-builder/runtime-benchmarks",
"bifrost-flexible-fee/runtime-benchmarks",
"bifrost-salp/runtime-benchmarks",
+ "bifrost-liquidity-mining/runtime-benchmarks",
]
try-runtime = [
diff --git a/runtime/bifrost/src/lib.rs b/runtime/bifrost/src/lib.rs
index cfef66fa00..b29d2a193d 100644
--- a/runtime/bifrost/src/lib.rs
+++ b/runtime/bifrost/src/lib.rs
@@ -1321,6 +1321,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, bifrost_flexible_fee, FlexibleFee);
list_benchmark!(list, extra, bifrost_salp, Salp);
+ list_benchmark!(list, extra, bifrost_liquidity_mining, LiquidityMining);
let storage_info = AllPalletsWithSystem::storage_info();
@@ -1353,6 +1354,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_vesting, Vesting);
add_benchmark!(params, batches, bifrost_flexible_fee, FlexibleFee);
add_benchmark!(params, batches, bifrost_salp, Salp);
+ add_benchmark!(params, batches, bifrost_liquidity_mining, LiquidityMining);
if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)