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

404 add pooled reward pallet #415

Merged
merged 50 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
582f234
WIP adapting pool rewards and calling from other parts of the runtime…
gianfra-t Oct 6, 2023
0ca6ba9
pallet pooled rewards configured and connected to pallet nomination
gianfra-t Oct 9, 2023
1a86542
rename CurrencyId type of pooled-reward pallet to avoid conflict with…
gianfra-t Oct 10, 2023
af57fd3
remove tight coupling of pallet pooled rewards to nomination
gianfra-t Oct 10, 2023
9121dfa
remove coupling of vault registry to new pallet pooled rewards
gianfra-t Oct 10, 2023
1927a98
format
gianfra-t Oct 10, 2023
2756421
missing implementation of new pallet pooled-reward in replace mock
gianfra-t Oct 10, 2023
9e95a0b
call reward pool in vault-registry
gianfra-t Oct 10, 2023
112659f
added pooled-rewards to vault-registry mock runtime
gianfra-t Oct 10, 2023
4b4bfd5
implementing only one reward pallet
gianfra-t Oct 11, 2023
9b551ce
set reward staking to be equal to total stake (pallet stake)
gianfra-t Oct 12, 2023
30741b6
remove basecurrency from fee, conversion
gianfra-t Oct 12, 2023
f568071
remove comments
gianfra-t Oct 12, 2023
ab0fa4f
fix incorrect vault_id update
gianfra-t Oct 12, 2023
c126287
comments, fmt
gianfra-t Oct 12, 2023
06f3fa5
merge with branch main
gianfra-t Oct 12, 2023
ef50a31
WIP reward-distribution hook and percentage caculation
gianfra-t Oct 12, 2023
496197f
WIP base implementation
gianfra-t Oct 13, 2023
9283202
rewards distribution api with fee connection
gianfra-t Oct 13, 2023
4d2bf4e
better error handling in on initialize
gianfra-t Oct 13, 2023
4610683
remove temporary price api, added OracleApi from oracle module. Added…
gianfra-t Oct 13, 2023
5950f2f
set up basic tests for distribution
gianfra-t Oct 13, 2023
bd9d6c3
added more pallet tests for reward-distribution logic
gianfra-t Oct 16, 2023
d779185
print cleanups, added mock for security chain
gianfra-t Oct 16, 2023
6e9079c
wip commit
gianfra-t Oct 16, 2023
543ccf3
added collect extrinsic, added dependency of currecies config, remove…
gianfra-t Oct 17, 2023
b5f1391
wip
gianfra-t Oct 17, 2023
000d0c0
modified mock configs due to changes in reward-distribution, removed …
gianfra-t Oct 17, 2023
718345e
added benchmarks for collect extrinsic and on initialize function
gianfra-t Oct 17, 2023
90276fd
removed reward distribution logic from fee pallet
gianfra-t Oct 18, 2023
1cdeaa8
moved withdraw_all_rewards_from_vault to new pallet, added logic to h…
gianfra-t Oct 18, 2023
9c96d54
added new store to hold all reward currencies in stake pallet, modifi…
gianfra-t Oct 18, 2023
60dc317
fix configs for new Staking value
gianfra-t Oct 18, 2023
d789ef3
addressed comments and fixes
gianfra-t Oct 18, 2023
4af8e86
fix broken tests for staking pallet
gianfra-t Oct 18, 2023
92f4ca8
fix critical bug in reward collection
gianfra-t Oct 19, 2023
3ab1a2b
change currency id back to associated type
gianfra-t Oct 23, 2023
4f3f0ba
get the relevant block numbers in reward-distribution pallet from sec…
gianfra-t Oct 23, 2023
6f248b4
optimization on distribute_rewards loop
gianfra-t Oct 23, 2023
beace26
change wrongly modified extrinsic indexes
gianfra-t Oct 23, 2023
dd4f8ed
added pool staking manager interface
gianfra-t Oct 24, 2023
05b2bed
native currency reward tracking and check
gianfra-t Oct 24, 2023
cb3cf16
comments and fixes
gianfra-t Oct 25, 2023
70f9a1a
review fixes and changes
gianfra-t Oct 26, 2023
cd448b0
existential deposit check in collect extrinsic
gianfra-t Oct 27, 2023
ca39753
solved conflicts with base
gianfra-t Oct 27, 2023
ff1bf21
regenerated standalone metadata
gianfra-t Oct 30, 2023
580d606
clippy changes
gianfra-t Oct 30, 2023
4ae51f1
Merge branch 'main' into 404-add-pooled-reward-pallet
gianfra-t Oct 31, 2023
be5625e
Update pallets/reward-distribution/src/lib.rs
gianfra-t Oct 31, 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
51 changes: 47 additions & 4 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
"pallets/fee",
"pallets/nomination",
"pallets/oracle",
"pallets/reward",
"pallets/pooled-rewards",
"pallets/reward-distribution",
"pallets/staking",
"pallets/stellar-relay",
Expand Down
3 changes: 2 additions & 1 deletion pallets/currency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ pub mod pallet {
+ FullCodec
+ Copy
+ Default
+ Debug;
+ Debug
+ From<u64>;

/// Relay chain currency e.g. DOT/KSM
#[pallet::constant]
Expand Down
23 changes: 23 additions & 0 deletions pallets/currency/src/testing_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ pub const DEFAULT_WRAPPED_CURRENCY: CurrencyId = CurrencyId::AlphaNum4(
],
);

pub const DEFAULT_WRAPPED_CURRENCY_2: CurrencyId = CurrencyId::AlphaNum4(
*b"USDT",
[
20, 209, 150, 49, 176, 55, 23, 217, 171, 154, 54, 110, 16, 50, 30, 226, 102, 231, 46, 199,
108, 171, 97, 144, 240, 161, 51, 109, 72, 34, 159, 139,
],
);
pub const DEFAULT_WRAPPED_CURRENCY_3: CurrencyId = CurrencyId::AlphaNum4(
*b"MXN\0",
[
20, 209, 150, 49, 176, 55, 23, 217, 171, 154, 54, 110, 16, 50, 30, 226, 102, 231, 46, 199,
108, 171, 97, 144, 240, 161, 51, 109, 72, 34, 159, 139,
],
);

pub const DEFAULT_WRAPPED_CURRENCY_4: CurrencyId = CurrencyId::AlphaNum4(
*b"ARST",
[
44, 123, 1, 49, 176, 55, 23, 123, 171, 123, 54, 155, 16, 50, 30, 226, 155, 231, 46, 199, 1,
11, 4, 144, 240, 123, 51, 33, 72, 34, 159, 33,
],
);

pub fn get_wrapped_currency_id() -> CurrencyId {
DEFAULT_WRAPPED_CURRENCY
}
10 changes: 8 additions & 2 deletions pallets/fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "p
# Parachain dependencies
currency = { path = "../currency", default-features = false }
security = { path = "../security", default-features = false }
reward = { path = "../reward", default-features = false }
pooled-rewards = { path = "../pooled-rewards", default-features = false }
staking = { path = "../staking", default-features = false }
reward-distribution = { path = "../reward-distribution", default-features = false }
oracle = { path = "../oracle", default-features = false }

primitives = { package = "spacewalk-primitives", path = "../../primitives", default-features = false }


[dev-dependencies]
mocktopus = "0.8.0"
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.40", default-features = false }
Expand Down Expand Up @@ -58,12 +62,14 @@ std = [
"pallet-balances/std",
"currency/std",
"security/std",
"reward/std",
"staking/std",
"primitives/std",
"pooled-rewards/std",
"orml-currencies/std",
"orml-tokens/std",
"orml-traits/std",
"reward-distribution/std",
"oracle/std",
]
runtime-benchmarks = [
"frame-benchmarking",
Expand Down
7 changes: 0 additions & 7 deletions pallets/fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;

use currency::getters::get_native_currency_id;
use primitives::VaultId;

#[cfg(test)]
use crate::Pallet as Fee;

Expand All @@ -18,10 +15,6 @@ fn get_fee<T: crate::Config>() -> UnsignedFixedPoint<T> {
}

benchmarks! {
withdraw_rewards {
let nominator: T::AccountId = account("recipient", 0, SEED);
let vault_id: VaultId<_, CurrencyId<T>> = VaultId::new(nominator.clone(), get_native_currency_id::<T>(), get_native_currency_id::<T>());
}: _(RawOrigin::Signed(nominator), vault_id, None)

set_issue_fee {
let caller: T::AccountId = account("caller", 0, SEED);
Expand Down
17 changes: 17 additions & 0 deletions pallets/fee/src/ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[cfg(test)]
use mocktopus::macros::mockable;

#[cfg_attr(test, mockable)]
pub(crate) mod reward_distribution {
use crate::DispatchError;
use currency::Amount;
use reward_distribution::DistributeRewards;

pub fn distribute_rewards<T: crate::Config>(
reward: &Amount<T>,
) -> Result<Amount<T>, DispatchError> {
let undistributed_balance =
T::RewardDistribution::distribute_rewards(reward.amount(), reward.currency())?;
Ok(Amount::<T>::new(undistributed_balance, reward.currency()))
}
}
Loading