Skip to content

Commit

Permalink
fix: 🐛 farming boost
Browse files Browse the repository at this point in the history
  • Loading branch information
yooml committed Oct 16, 2024
1 parent a7d294c commit 515196c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pallets/farming/src/boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl<T: Config> Pallet<T> {
ensure!(BoostWhitelist::<T>::iter_keys().count() != 0, Error::<T>::WhitelistEmpty);
}

boost_pool_info.round_length = round_length;
Self::send_boost_rewards(&boost_pool_info)?;
let current_block_number: BlockNumberFor<T> = frame_system::Pallet::<T>::block_number();
boost_pool_info.start_round = current_block_number;
boost_pool_info.round_length = round_length;
boost_pool_info.end_round = current_block_number.saturating_add(round_length);
boost_pool_info.total_votes = Zero::zero();
BoostPoolInfos::<T>::set(boost_pool_info);
Expand Down
5 changes: 5 additions & 0 deletions pallets/farming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,11 @@ pub mod pallet {
T::ControlOrigin::ensure_origin(origin)?;
whitelist.iter().for_each(|pid| {
BoostWhitelist::<T>::insert(pid, ());
BoostVotingPools::<T>::mutate_exists(pid, |maybe_total_votes| {
if maybe_total_votes.is_none() {
*maybe_total_votes = Some(Zero::zero());
}
})
});
Ok(())
}
Expand Down
20 changes: 16 additions & 4 deletions pallets/farming/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ fn start_boost_round() {
#[test]
fn vote() {
ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| {
env_logger::try_init().unwrap_or(());

BbBNC::set_incentive(0, Some(7 * 86400 / 12), Some(ALICE.clone()));

let (pid, _tokens) = init_gauge();
Expand All @@ -512,17 +514,16 @@ fn vote() {
whitelist.clone()
));

let charge_rewards = vec![(KSM, 300000)];
assert_ok!(Farming::charge_boost(RuntimeOrigin::signed(BOB), charge_rewards));
let charge_rewards = vec![(KSM, 300_000)];
assert_ok!(Farming::charge_boost(RuntimeOrigin::signed(CHARLIE), charge_rewards));
assert_eq!(BoostVotingPools::<Runtime>::iter().count(), 1);
assert_ok!(Farming::start_boost_round(RuntimeOrigin::signed(ALICE), 100));
let boost_pool_info =
BoostPoolInfo { total_votes: 0, end_round: 100, start_round: 0, round_length: 100 };
assert_eq!(BoostPoolInfos::<Runtime>::get(), boost_pool_info);

assert_ok!(Farming::vote(RuntimeOrigin::signed(ALICE), vote_list.clone()));
assert_eq!(BoostVotingPools::<Runtime>::iter().count(), 1);
assert_ok!(Farming::vote(RuntimeOrigin::signed(BOB), vote_list.clone()));
assert_eq!(BoostVotingPools::<Runtime>::iter().count(), 1);
assert_ok!(Farming::vote(RuntimeOrigin::signed(CHARLIE), vote_list.clone()));
assert_eq!(BoostVotingPools::<Runtime>::iter().count(), 1);
assert_eq!(UserBoostInfos::<Runtime>::iter().count(), 3);
Expand All @@ -544,6 +545,17 @@ fn vote() {
// vote again to refresh the vote amount of CHARLIE
assert_ok!(Farming::vote(RuntimeOrigin::signed(CHARLIE), vote_list.clone()));
assert_eq!(BoostPoolInfos::<Runtime>::get().total_votes, 124645248000);

assert_eq!(BoostBasicRewards::<Runtime>::get(pid, KSM), Some(3000));
Farming::on_initialize(0);
Farming::on_initialize(1);
Farming::on_initialize(2);
assert_ok!(Farming::claim(RuntimeOrigin::signed(ALICE), pid));
assert_eq!(Tokens::free_balance(KSM, &ALICE), 10000);
System::set_block_number(System::block_number() + 100);
assert_ok!(Farming::claim(RuntimeOrigin::signed(ALICE), pid));
assert_eq!(Tokens::free_balance(KSM, &ALICE), 11519);

assert_ok!(Farming::end_boost_round(RuntimeOrigin::signed(ALICE)));
assert_eq!(BoostPoolInfos::<Runtime>::get().end_round, 0);
})
Expand Down

0 comments on commit 515196c

Please sign in to comment.