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

3rdparty rewards - schedules limit adjustment #655

Merged
merged 3 commits into from
Dec 13, 2023
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
14 changes: 13 additions & 1 deletion pallets/proof-of-stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ pub mod pallet {
CurrencyIdOf<T>,
BalanceOf<T>,
),
ThirdPartySuccessfulPoolPromotion(
T::AccountId,
CurrencyIdOf<T>,
CurrencyIdOf<T>,
BalanceOf<T>,
),
}

#[pallet::storage]
Expand Down Expand Up @@ -1471,7 +1477,6 @@ impl<T: Config> Pallet<T> {

pub(crate) fn reward_pool_impl(
sender: T::AccountId,

pool: (CurrencyIdOf<T>, CurrencyIdOf<T>),
token_id: CurrencyIdOf<T>,
amount: BalanceOf<T>,
Expand Down Expand Up @@ -1552,6 +1557,13 @@ impl<T: Config> Pallet<T> {
_ => {}, // invariant assures this will never happen
}

Pallet::<T>::deposit_event(Event::ThirdPartySuccessfulPoolPromotion(
sender,
liquidity_token_id,
token_id,
amount,
));

Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions pallets/proof-of-stake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ impl ExtBuilder {
}
}

pub(crate) fn events() -> Vec<pallet::Event<Test>> {
System::events()
.into_iter()
.map(|r| r.event)
.filter_map(|e| if let RuntimeEvent::ProofOfStake(inner) = e { Some(inner) } else { None })
.collect::<Vec<_>>()
}

/// Compares the system events with passed in events
/// Prints highlighted diff iff assert_eq fails
#[macro_export]
Expand Down
27 changes: 27 additions & 0 deletions pallets/proof-of-stake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4492,3 +4492,30 @@ fn test_amount_of_rewards_when_activation_happens_after_schedule_was_processed_i
assert_eq!((alice_rewards + bob_rewards + 1), 100_000_000_000_000_000_000_000_000);
});
}

#[test]
#[serial]
fn test_event_is_emmited_when_pool_is_rewarded() {
ExtBuilder::new()
.issue(ALICE, LIQUIDITY_TOKEN, 100_000_000_000u128)
.issue(BOB, REWARD_TOKEN, 100_000_000_000_000_000_000_000_000u128)
.issue(BOB, LIQUIDITY_TOKEN, 500_000_000_000u128)
.execute_with_default_mocks(|| {
forward_to_block::<Test>(36);
ProofOfStake::reward_pool(
RuntimeOrigin::signed(BOB),
REWARDED_PAIR,
REWARD_TOKEN,
100_000_000_000_000_000_000_000_000u128,
7u32.into(),
)
.unwrap();

assert_event_emitted!(Event::<Test>::ThirdPartySuccessfulPoolPromotion(
BOB,
LIQUIDITY_TOKEN,
REWARD_TOKEN,
100_000_000_000_000_000_000_000_000u128
));
});
}
8 changes: 4 additions & 4 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,10 +1477,10 @@ where
use super::*;

parameter_types! {
pub const RewardsSchedulesLimit: u32 = 100_000u32;
// TODO: allign properly
pub const Min3rdPartyRewardValutationPerSession: u128 = 100 * 30_000 * currency::DOLLARS;
pub const Min3rdPartyRewardVolume: u128 = 100 * 30_000 * currency::DOLLARS;
pub const RewardsSchedulesLimit: u32 = 10_000u32;
// NOTE: 1725 is how much USDT you get for one MGX as of 12.2023
pub const Min3rdPartyRewardValutationPerSession: u128 = 10 * 1725 * currency::DOLLARS;
pub const Min3rdPartyRewardVolume: u128 = 10_000 * 1725 * currency::DOLLARS;
pub const SchedulesPerBlock: u32 = 5;
}
}
Expand Down
Loading