Skip to content

Commit

Permalink
valuate MGX rewards properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszaaa committed Sep 26, 2023
1 parent 9ce2c48 commit 5047104
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pallets/proof-of-stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub mod pallet {
impl<T> PoSBenchmarkingConfig for T {}

#[cfg(not(feature = "runtime-benchmarks"))]
pub trait ValutationApiTrait:
pub trait ValutationApiTrait<T: Config>:
Valuate<Balance = mangata_types::Balance, CurrencyId = mangata_types::TokenId>
{
}
Expand Down Expand Up @@ -521,7 +521,9 @@ pub mod pallet {

ensure!(
<T as Config>::ValuationApi::valuate_liquidity_token(liquidity_token_id, amount) >=
T::MinRewardsPerSession::get(),
T::MinRewardsPerSession::get() ||
((token_id == Into::<u32>::into(Self::native_token_id())) &&
amount_per_session >= T::MinRewardsPerSession::get()),
Error::<T>::TooLittleRewardsPerSession
);

Expand Down Expand Up @@ -1305,5 +1307,6 @@ impl<T: Config> LiquidityMiningApi for Pallet<T> {
}
}

// TODO: valuate rewards in MGX
// TODO: dedicated ensures for every activation kind
// TODO: clean up test setup
// TODO: test schedule rewards without liquidity mining rewards
29 changes: 29 additions & 0 deletions pallets/proof-of-stake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,35 @@ fn reject_schedule_with_too_little_rewards_per_session() {
});
}

#[test]
#[serial]
fn accept_schedule_valuated_in_native_token() {
new_test_ext().execute_with(|| {
System::set_block_number(1);
let get_liquidity_asset_mock = MockValuationApi::get_liquidity_asset_context();
get_liquidity_asset_mock.expect().return_const(Ok(10u32));
let valuate_liquidity_token_mock = MockValuationApi::valuate_liquidity_token_context();
valuate_liquidity_token_mock.expect().return_const(1u128);

let token_id = TokensOf::<Test>::create(&ALICE, MILLION).unwrap();
TokensOf::<Test>::mint(ProofOfStake::native_token_id(), &ALICE, 10).unwrap();
let pair: (TokenId, TokenId) = (0u32.into(), 4u32.into());

roll_to_session(4);

assert_ok!(
ProofOfStake::reward_pool(
RuntimeOrigin::signed(ALICE),
pair,
ProofOfStake::native_token_id(),
10,
5u32.into()
),
// Error::<Test>::TooLittleRewardsPerSession
);
});
}

#[test]
#[serial]
fn user_can_claim_3rdparty_rewards() {
Expand Down

0 comments on commit 5047104

Please sign in to comment.