Skip to content
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
4 changes: 2 additions & 2 deletions pallets/minter-reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ pub mod pallet {
MaximumVtokenMinted::<T>::get();

let last_block_diff = n.saturating_sub(last_max_minted_block);
let start_block_diff = n.saturating_sub(started_block_num);

if (last_block_diff >= T::RewardWindow::get() && started_block_num > Zero::zero()) ||
(last_block_diff < T::RewardWindow::get() &&
last_block_diff >= max_extended_period &&
start_block_diff >= max_extended_period &&
started_block_num > Zero::zero())
{
let start_block_diff = n.saturating_sub(started_block_num);
let period = BalanceOf::<T>::from(start_block_diff.saturated_into::<u32>());

let total_reward = period.saturating_mul(RewardPerBlock::<T>::get());
Expand Down
18 changes: 17 additions & 1 deletion pallets/minter-reward/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,21 @@ fn minter_reward_should_work() {
(12, 56, CurrencyId::VToken(TokenSymbol::DOT))
);

run_to_block(41);
// start block is 2, max extended block is 20, block 22 should still be the last block of
// maximum_vtoken(12, 56, CurrencyId::VToken(TokenSymbol::DOT))
run_to_block(22);
assert_eq!(
MinterReward::maximum_vtoken_minted(),
(12, 56, CurrencyId::VToken(TokenSymbol::DOT))
);

// 23-2=21 >20, so the previous round will be ended and new round will be started.
run_to_block(23);
assert_eq!(MinterReward::current_round_start_at(), 0);
assert_eq!(
MinterReward::maximum_vtoken_minted(),
(0, 0, CurrencyId::Native(TokenSymbol::BNC))
);

run_to_block(42);
assert_ok!(VtokenMint::mint(Origin::signed(ALICE), vDOT, to_sell_vdot + 20));
Expand All @@ -160,5 +173,8 @@ fn minter_reward_should_work() {
// 60 blocks to be a halving reward cycle
run_to_block(61);
assert_eq!(MinterReward::reward_per_block(), 150);

// 42+20=62. When block number reaches 63, the previous round will be ended, since no new
// minting action is taken
});
}