Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bifrost v0.9.22 #476

Merged
merged 2 commits into from
Jan 19, 2022
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
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-cli"
version = "0.9.20"
version = "0.9.22"
authors = ["Liebi Technologies <bifrost@liebi.com>"]
description = "Bifrost Parachain Node"
build = "build.rs"
Expand Down
8 changes: 7 additions & 1 deletion pallets/liquidity-mining/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true }
node-primitives = { path = "../../node/primitives", default-features = false }
orml-traits = { version = "0.4.1-dev", default-features = false }
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.126", optional = true, features = ["derive"] }

[dev-dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" }
Expand All @@ -31,6 +33,8 @@ std = [
"frame-support/std",
"node-primitives/std",
"orml-traits/std",
"log/std",
"serde",
]

runtime-benchmarks = [
Expand All @@ -41,4 +45,6 @@ runtime-benchmarks = [

local-benchmarks = [
"pallet-collective/runtime-benchmarks",
]
]

try-runtime = ["frame-support/try-runtime"]
121 changes: 114 additions & 7 deletions pallets/liquidity-mining/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
use frame_benchmarking::{
account, benchmarks_instance_pallet, impl_benchmark_test_suite, whitelisted_caller,
};
use frame_support::{assert_ok, sp_runtime::sp_std::convert::TryInto, sp_std::prelude::*};
use frame_support::{
assert_ok,
sp_runtime::{sp_std::convert::TryInto, traits::Zero},
sp_std::prelude::*,
};
use frame_system::RawOrigin;
use node_primitives::Balance;

Expand Down Expand Up @@ -63,7 +67,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));
}: _(RawOrigin::Signed(caller.clone()), 0)

Expand All @@ -87,7 +93,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));

assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));
Expand All @@ -114,7 +122,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));

assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));
Expand Down Expand Up @@ -152,7 +162,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));

assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));
Expand Down Expand Up @@ -190,7 +202,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));

assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));
Expand Down Expand Up @@ -230,7 +244,9 @@ benchmarks_instance_pallet! {
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into()
0u128.saturated_into(),
Zero::zero(),
0,
));

assert_ok!(LM::<T,I>::charge(RawOrigin::Signed(investor).into(), 0));
Expand All @@ -241,6 +257,97 @@ benchmarks_instance_pallet! {
run_to_block::<T,I>(1u128.saturated_into());

}: _(RawOrigin::Signed(caller.clone()), 0)

unlock {
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T,I> = UNIT.saturated_into();
let redeem_limit_time: BlockNumberFor<T> = 100u32.saturated_into();
let unlock_limit_nums = 3;

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, amount));

assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into(),
redeem_limit_time,
unlock_limit_nums,
));

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

assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, amount));

// Run to block
run_to_block::<T,I>(duration);

assert_ok!(LM::<T,I>::redeem_all(RawOrigin::Signed(caller.clone()).into(), 0));

run_to_block::<T,I>(duration.saturating_add(redeem_limit_time));

}: _(RawOrigin::Signed(caller.clone()), 0)
verify {
let pool = LM::<T,I>::pool(0);
let deposit_data = LM::<T,I>::user_deposit_data(0, caller.clone());
assert!(pool.is_none());
assert!(deposit_data.is_none());
}

cancel_unlock{
let duration = T::MinimumDuration::get().saturating_add(1u128.saturated_into());
let min_deposit_to_start = T::MinimumDepositOfUser::get();
let amount: BalanceOf<T,I> = UNIT.saturated_into();
let redeem_limit_time: BlockNumberFor<T> = 100u32.saturated_into();
let unlock_limit_nums = 3;

let investor: T::AccountId = account("lm", 0, 0);
assert_ok!(T::MultiCurrency::deposit(REWARD_1, &investor, amount));
assert_ok!(T::MultiCurrency::deposit(REWARD_2, &investor, amount));

let caller: T::AccountId = whitelisted_caller();
let double_amount = amount.saturating_mul(2u128.saturated_into());
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_1, &caller, double_amount));
assert_ok!(T::MultiCurrency::deposit(FARMING_DEPOSIT_2, &caller, double_amount));

assert_ok!(LM::<T,I>::create_pool(
(FARMING_DEPOSIT_1, FARMING_DEPOSIT_2),
(REWARD_1, amount),
vec![(REWARD_2, amount)].try_into().unwrap(),
PoolType::Farming,
duration,
min_deposit_to_start,
0u128.saturated_into(),
redeem_limit_time,
unlock_limit_nums,
));

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

assert_ok!(LM::<T,I>::deposit(RawOrigin::Signed(caller.clone()).into(), 0, double_amount));

// Run to block
run_to_block::<T,I>(1u32.saturated_into());

assert_ok!(LM::<T,I>::redeem(RawOrigin::Signed(caller.clone()).into(), 0, amount));

}: _(RawOrigin::Signed(caller.clone()), 0, 0)
verify {
let pool = LM::<T,I>::pool(0);
let deposit_data = LM::<T,I>::user_deposit_data(0, caller.clone());
assert!(pool.unwrap().pending_unlock_nums == 0);
assert!(deposit_data.unwrap().pending_unlocks.len() == 0);
}
}

impl_benchmark_test_suite!(LM, crate::mock::new_test_ext(), crate::mock::Test);
Loading