Skip to content

Commit

Permalink
add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrell-code committed Jun 13, 2022
1 parent cdfe7c8 commit 416e892
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
13 changes: 7 additions & 6 deletions modules/support/src/incentives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ pub enum PoolId {
}

pub trait IncentivesManager<AccountId, Balance, CurrencyId, PoolId> {
/// Gets reward amount for the given reward currency added per period
fn get_incentive_reward_amount(pool_id: PoolId, currency_id: CurrencyId) -> Balance;

/// Gets fixed reward rate for `PoolId::Dex` per period
fn get_dex_reward_rate(pool_id: PoolId) -> Rate;

/// Stake LP token to add shares to pool
fn deposit_dex_share(who: &AccountId, lp_currency_id: CurrencyId, amount: Balance) -> DispatchResult;

/// Unstake LP token to remove shares from pool
fn withdraw_dex_share(who: &AccountId, lp_currency_id: CurrencyId, amount: Balance) -> DispatchResult;

/// Claim all available rewards for specific `PoolId`
fn claim_rewards(who: AccountId, pool_id: PoolId) -> DispatchResult;

/// Gets deduction reate for claiming reward early
fn get_claim_reward_deduction_rate(pool_id: PoolId) -> Rate;

/// Gets the pending rewards for a pool, for an account
fn get_pending_rewards(pool_id: PoolId, who: AccountId, reward_currency: Vec<CurrencyId>) -> Vec<Balance>;
}

Expand Down
41 changes: 34 additions & 7 deletions runtime/common/src/precompile/incentives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ use primitives::{Balance, CurrencyId};
use sp_runtime::{traits::Convert, FixedPointNumber, RuntimeDebug};
use sp_std::{marker::PhantomData, prelude::*};

/// The Incentives precompile
///
/// `input` data starts with `action`.
///
/// Actions:
/// - GetIncentiveRewardAmount `input` bytes: `pool`, `pool_currency_id`, `reward_currency_id`.
/// - GetDexRewardAmount `input` bytes: `lp_currency_id`.
/// - DepositDexShare `input` bytes: `who`, `lp_currency_id`, `amount`.
/// - WithdrawDexShare `input` bytes: `who`, `lp_currency_id`, `amount`.
/// - ClaimRewards `input` bytes: `who`, `pool`, `pool_currency_id`.
/// - GetClaimRewardDeductionRate `input` bytes: `pool`, `pool_currency_id`.
/// - GetPendingRewards `input` bytes: `reward_currencies`, `pool`, `pool_currency_id`, `who`.
pub struct IncentivesPrecompile<R>(PhantomData<R>);

#[module_evm_utility_macro::generate_function_selector]
Expand Down Expand Up @@ -386,7 +398,10 @@ mod tests {
vec![(PoolId::Loans(DOT), vec![(DOT, 100)])]
));

// 0x7469000d
// getIncetiveRewardAmount(PoolId,address,addres) => 0x7469000d
// pool
// pool_currency_id
// reward_currency_id
let input = hex! {"
7469000d
00000000000000000000000000000000 00000000000000000000000000000000
Expand Down Expand Up @@ -419,7 +434,8 @@ mod tests {
vec![(PoolId::Dex(LP_ACA_AUSD), FixedU128::saturating_from_rational(1, 10))]
));

// 0x7ec93136
// getDexRewardRate(address) => 0x7ec93136
// lp_currency_id
let input = hex! {"
7ec93136
000000000000000000000000 0000000000000000000200000000000000000001
Expand Down Expand Up @@ -447,7 +463,10 @@ mod tests {

assert_ok!(Currencies::deposit(LP_ACA_AUSD, &alice(), 1_000_000_000));

// 0x8e78b279
// depositDexShare(address,address,uint128) => 0x8e78b279
// who
// lp_currency_id
// amount
let input = hex! {"
8e78b279
000000000000000000000000 1000000000000000000000000000000000000001
Expand Down Expand Up @@ -488,7 +507,10 @@ mod tests {
100_000
));

// 0x6b1c730c
// withdrawDexShare(address,address,uint128) => 0x6b1c730c
// who
// lp_currency_id
// amount
let input = hex! {"
6b1c730c
000000000000000000000000 1000000000000000000000000000000000000001
Expand Down Expand Up @@ -544,7 +566,10 @@ mod tests {
}
);

// 0xe12eab9b
// claimRewards(address,PoolId,address) => 0xe12eab9b
// who
// pool
// pool_currency_id
let input = hex! {"
e12eab9b
000000000000000000000000 1000000000000000000000000000000000000001
Expand Down Expand Up @@ -583,7 +608,9 @@ mod tests {
vec![(PoolId::Dex(LP_ACA_AUSD), FixedU128::saturating_from_rational(1, 10))]
));

// 0xa2e2fc8e
// getClaimRewardDeductionRate(PoolId,address) => 0xa2e2fc8e
// pool
// pool_currency_id
let input = hex! {"
a2e2fc8e
00000000000000000000000000000000 00000000000000000000000000000001
Expand Down Expand Up @@ -630,7 +657,7 @@ mod tests {
vec![1000, 500]
);

// getPendingRewards(address[],PoolId,address,address) -> 0xeb797b1
// getPendingRewards(address[],PoolId,address,address) -> 0x0eb797b1
// offset
// pool_id
// pool_currency_id
Expand Down

0 comments on commit 416e892

Please sign in to comment.