Skip to content

Commit

Permalink
Fix farming boost (#969)
Browse files Browse the repository at this point in the history
* fix: 🐛 set_next_round_whitelist

* add refresh_voting

* fix

* fix test
  • Loading branch information
yooml authored May 10, 2023
1 parent 0e12789 commit 0d58be5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pallets/farming/src/boost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ impl<T: Config> Pallet<T> {
ensure!(round_length != Zero::zero(), Error::<T>::RoundLengthNotSet);
let mut boost_pool_info = Self::boost_pool_infos();
ensure!(boost_pool_info.end_round == Zero::zero(), Error::<T>::RoundNotOver);
let whitelist_iter = BoostWhitelist::<T>::iter_keys();

// Update whitelist
if BoostNextRoundWhitelist::<T>::iter().count() != 0 {
if BoostNextRoundWhitelist::<T>::iter_keys().count() != 0 {
let _ = BoostWhitelist::<T>::clear(u32::max_value(), None);
whitelist_iter.for_each(|pid| {
BoostNextRoundWhitelist::<T>::iter_keys().for_each(|pid| {
BoostWhitelist::<T>::insert(pid, ());
});
let _ = BoostNextRoundWhitelist::<T>::clear(u32::max_value(), None);
} else {
ensure!(whitelist_iter.count() != 0, Error::<T>::WhitelistEmpty);
ensure!(BoostWhitelist::<T>::iter_keys().count() != 0, Error::<T>::WhitelistEmpty);
}

Self::send_boost_rewards(&boost_pool_info)?;
Expand Down
10 changes: 7 additions & 3 deletions pallets/farming/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{mock::*, *};
use bifrost_asset_registry::AssetMetadata;
use bifrost_runtime_common::milli;
use bifrost_ve_minting::VeMintingInterface;
use frame_support::{assert_err, assert_ok};
use frame_support::{assert_err, assert_noop, assert_ok};
use node_primitives::TokenInfo;

fn asset_registry() {
Expand Down Expand Up @@ -77,12 +77,16 @@ fn boost() {
assert_ok!(Farming::claim(RuntimeOrigin::signed(CHARLIE), pid));
assert_eq!(Tokens::free_balance(KSM, &CHARLIE), 999999999000);

let whitelist: Vec<PoolId> = vec![pid];
let vote_list: Vec<(u32, Percent)> = vec![(pid, Percent::from_percent(100))];
let charge_list = vec![(KSM, 1000)];
assert_ok!(Farming::add_boost_pool_whitelist(RuntimeOrigin::signed(ALICE), whitelist));
assert_ok!(Farming::add_boost_pool_whitelist(RuntimeOrigin::signed(ALICE), vec![2]));
assert_ok!(Farming::set_next_round_whitelist(RuntimeOrigin::signed(ALICE), vec![pid]));
assert_ok!(Farming::start_boost_round(RuntimeOrigin::signed(ALICE), 100));
assert_ok!(Farming::charge_boost(RuntimeOrigin::signed(ALICE), charge_list));
assert_noop!(
Farming::vote(RuntimeOrigin::signed(CHARLIE), vec![(2, Percent::from_percent(100))]),
Error::<Runtime>::NotInWhitelist
);
assert_ok!(Farming::vote(RuntimeOrigin::signed(CHARLIE), vote_list));
assert_eq!(Farming::boost_basic_rewards(pid, KSM), None);
assert_ok!(Farming::claim(RuntimeOrigin::signed(CHARLIE), pid));
Expand Down
2 changes: 1 addition & 1 deletion runtime/bifrost-polkadot/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod currency {
type Balance = Balance;
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = base_tx_fee::<Runtime>() * 10;
let p = base_tx_fee::<Runtime>() * 580;
let q = Balance::from(ExtrinsicBaseWeight::get().ref_time());
smallvec![WeightToFeeCoefficient {
degree: 1,
Expand Down

0 comments on commit 0d58be5

Please sign in to comment.