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

Add LP staking into Picasso runtime #3504

Merged
merged 34 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6d2329e
add reward pallet that will store stake amount for LP providers
RustNinja Apr 26, 2023
5649915
add farming pallet
RustNinja Apr 26, 2023
a67f6d4
add reward and farming pallet as dependency to picasso runtime
RustNinja Apr 26, 2023
3c177ee
integrate Farming and Farming Reward pallet in picasso runtime
RustNinja Apr 26, 2023
772495b
use AssetsTransactorRouter for MultiCurrency associated type in farming
RustNinja Apr 26, 2023
d6e8e46
reconfigure farming pallet for picasso. use separate account for farming
RustNinja Apr 26, 2023
1717978
add mock runtime and unit tests for farming pallet.
RustNinja Apr 26, 2023
9511318
add mock runtime and unit tests for reward pallet
RustNinja Apr 26, 2023
ff593e5
Merge remote-tracking branch 'origin/main' into picasso-lp-staking
RustNinja Apr 27, 2023
0c7cc6f
refactor reward pallet and remove unused constant from pallet config
RustNinja Apr 27, 2023
b93ec38
Merge pull request #1 from RustNinja/farming-reward-refactoring
RustNinja Apr 27, 2023
bcc0454
add runtime api for reward pallet
RustNinja Apr 27, 2023
07d5eef
Merge pull request #2 from RustNinja/add-runtime-api-for-reward-pallet
RustNinja Apr 27, 2023
2e3d9eb
add reward-rpc implementation and add dependency to parachain node
RustNinja Apr 27, 2023
feeea35
update RewardApi for reward pallet
RustNinja Apr 27, 2023
3e3416b
Merge pull request #4 from RustNinja/add-reward-rpc-to-composable-node
RustNinja Apr 27, 2023
b410d6d
add reward_rpc_runtime_api::RewardApi to picasso-runtime
RustNinja Apr 27, 2023
4459a17
Complete Farming Api to picasso node
RustNinja Apr 27, 2023
f9a6fe6
add runtime-benchmarks and try-runtime features to reward and farming
RustNinja Apr 27, 2023
4adc62f
Merge branch 'ComposableFi:main' into picasso-lp-staking
RustNinja Apr 27, 2023
cc457bb
update farming and reuse T::AssetId
RustNinja Apr 28, 2023
0131341
update std feature in reward and farming pallet
RustNinja Apr 28, 2023
ce64724
Merge remote-tracking branch 'origin/main' into picasso-lp-staking
RustNinja May 1, 2023
6431cdd
add logs when update reward scheduled failed by overflow
RustNinja May 1, 2023
b97e7e1
remove pool_currency_id.sort().it is not necessary according to AssetId
RustNinja May 1, 2023
6f0a5df
Merge pull request #5 from RustNinja/add-request-changes
RustNinja May 1, 2023
bb1d225
add #[allow(clippy::disallowed_types)] because of ValueQuery
RustNinja May 3, 2023
cac523d
cargo +nightly fmt --all --
RustNinja May 3, 2023
097164b
fix benchmarking tests for farming pallet.
RustNinja May 3, 2023
23ce2cb
Merge pull request #6 from RustNinja/fix-benchmarking-tests
RustNinja May 3, 2023
2fa56c7
fix cargo clippy
RustNinja May 4, 2023
69bbd1f
Merge pull request #7 from RustNinja/fix-benchmarking-tests
RustNinja May 4, 2023
869d5e7
remove commented code and
RustNinja May 4, 2023
fea4c3e
update pub const RewardPeriod: BlockNumber = 5
RustNinja May 4, 2023
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
69 changes: 69 additions & 0 deletions code/Cargo.lock

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

60 changes: 60 additions & 0 deletions code/parachain/frame/farming/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
authors = ["Composable Developers"]
description = "Provides reward mechanism for LP tokens"
edition = "2021"
homepage = "https://composable.finance"
name = "farming"
version = "1.0.0"


[dependencies]
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.137", default-features = false, features = ["derive"], optional = true }
codec = { default-features = false, features = [ "derive", "max-encoded-len"], package = "parity-scale-codec", version = "3.0.0" }
scale-info = { version = "2.1.1", default-features = false, features = [ "derive" ] }

# Orml dependencies
orml-tokens = { workspace = true, default-features = false }
orml-traits = { workspace = true, default-features = false }

reward = { path = "../reward", default-features = false }
# Substrate dependencies
sp-arithmetic = { default-features = false, workspace = true }
sp-core = { default-features = false, workspace = true }
sp-io = { default-features = false, workspace = true }
sp-runtime = { default-features = false, workspace = true }
sp-std = { default-features = false, workspace = true }

frame-support = { default-features = false, workspace = true }
frame-system = { default-features = false, workspace = true }
frame-benchmarking = { default-features = false, workspace = true, optional = true }


[dev-dependencies]
pallet-timestamp = { workspace = true }
pallet-balances = { workspace = true, default-features = false }
# frame-benchmarking = { default-features = false, workspace = true }

[features]
default = ["std"]
std = [
"log/std",
"serde",
"codec/std",

"sp-arithmetic/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",

"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
]

runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
123 changes: 123 additions & 0 deletions code/parachain/frame/farming/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use super::*;
use crate::CurrencyId::Token;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::{assert_ok, traits::Hooks};
use frame_system::RawOrigin;
use primitives::*;
use sp_std::vec;

// Pallets
use crate::Pallet as Farming;
use frame_system::Pallet as System;

fn default_reward_schedule<T: Config>(reward_currency_id: CurrencyId) -> RewardScheduleOf<T> {
let reward_schedule = RewardSchedule {
period_count: 100u32,
per_period: 1000u32.into(),
};
let total_amount = reward_schedule.total().unwrap();

assert_ok!(T::MultiCurrency::deposit(
reward_currency_id,
&T::TreasuryAccountId::get(),
total_amount,
));

reward_schedule
}

fn create_reward_schedule<T: Config>(pool_currency_id: CurrencyId, reward_currency_id: CurrencyId) {
let reward_schedule = default_reward_schedule::<T>(reward_currency_id);

assert_ok!(Farming::<T>::update_reward_schedule(
RawOrigin::Root.into(),
pool_currency_id,
reward_currency_id,
reward_schedule.period_count,
reward_schedule.total().unwrap(),
));
}

fn create_default_reward_schedule<T: Config>() -> (CurrencyId, CurrencyId) {
let pool_currency_id = CurrencyId::LpToken(LpToken::Token(DOT), LpToken::Token(IBTC));
let reward_currency_id = CurrencyId::Token(INTR);
create_reward_schedule::<T>(pool_currency_id, reward_currency_id);
(pool_currency_id, reward_currency_id)
}

fn deposit_lp_tokens<T: Config>(pool_currency_id: CurrencyId, account_id: &T::AccountId, amount: BalanceOf<T>) {
assert_ok!(T::MultiCurrency::deposit(pool_currency_id, account_id, amount));
assert_ok!(Farming::<T>::deposit(
RawOrigin::Signed(account_id.clone()).into(),
pool_currency_id,
));
}

pub fn get_benchmarking_currency_ids() -> Vec<(CurrencyId, CurrencyId)> {
vec![
(Token(DOT), Token(INTR)),
(Token(KSM), Token(KINT)),
(Token(DOT), Token(IBTC)),
(Token(KSM), Token(KBTC)),
]
}

benchmarks! {
on_initialize {
let c in 0 .. get_benchmarking_currency_ids().len() as u32;
let currency_ids = get_benchmarking_currency_ids();
let block_number = T::RewardPeriod::get();

for i in 0 .. c {
let (pool_currency_id, reward_currency_id) = currency_ids[i as usize];
create_reward_schedule::<T>(pool_currency_id, reward_currency_id);
}

Farming::<T>::on_initialize(1u32.into());
System::<T>::set_block_number(block_number);
}: {
Farming::<T>::on_initialize(System::<T>::block_number());
}

update_reward_schedule {
let pool_currency_id = CurrencyId::LpToken(LpToken::Token(DOT), LpToken::Token(IBTC));
let reward_currency_id = CurrencyId::Token(INTR);
let reward_schedule = default_reward_schedule::<T>(reward_currency_id);

}: _(RawOrigin::Root, pool_currency_id, reward_currency_id, reward_schedule.period_count, reward_schedule.total().unwrap())

remove_reward_schedule {
let (pool_currency_id, reward_currency_id) = create_default_reward_schedule::<T>();

}: _(RawOrigin::Root, pool_currency_id, reward_currency_id)

deposit {
let origin: T::AccountId = account("Origin", 0, 0);
let (pool_currency_id, _) = create_default_reward_schedule::<T>();
assert_ok!(T::MultiCurrency::deposit(
pool_currency_id,
&origin,
100u32.into(),
));

}: _(RawOrigin::Signed(origin), pool_currency_id)

withdraw {
let origin: T::AccountId = account("Origin", 0, 0);
let (pool_currency_id, _) = create_default_reward_schedule::<T>();
let amount = 100u32.into();
deposit_lp_tokens::<T>(pool_currency_id, &origin, amount);

}: _(RawOrigin::Signed(origin), pool_currency_id, amount)

claim {
let origin: T::AccountId = account("Origin", 0, 0);
let (pool_currency_id, reward_currency_id) = create_default_reward_schedule::<T>();
let amount = 100u32.into();
deposit_lp_tokens::<T>(pool_currency_id, &origin, amount);
assert_ok!(T::RewardPools::distribute_reward(&pool_currency_id, reward_currency_id, amount));

}: _(RawOrigin::Signed(origin), pool_currency_id, reward_currency_id)
}

impl_benchmark_test_suite!(Farming, crate::mock::ExtBuilder::build(), crate::mock::Test);
Loading