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

emit DistributeRewards even when amount is 0 #427

Merged
merged 4 commits into from
Nov 3, 2024
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
2 changes: 2 additions & 0 deletions contracts/RewardsDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ contract RewardsDistributor is IRewardsDistributor, Initializable, OwnableUpgrad
SQToken.safeTransfer(treasury, rewardsReturn);
emit ReturnRewards(runner, rewardsReturn, commission - cappedCommission);
}
} else {
emit DistributeRewards(runner, rewardInfo.lastClaimEra, 0, 0);
}
return rewardInfo.lastClaimEra;
}
Expand Down
2 changes: 1 addition & 1 deletion test/RewardsBooster_migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ describe('RewardsBooster Contract', () => {
// 3 block passed (upgrade, migrateDeploymentBoost, collectAllocationReward) since we queried alReward0,
// and 1 of them counts on old rewards, so we should get 500.5 SQT * 103 (availabe secs) / 1003 (total secs) = 51.397308075772681954
// sometimes the test takes longer than 3 sec for 3 blocks, so result may become 52291
expect(evts[0].amount.div((1e15).toString()).toNumber()).to.within(51397, 52291);
expect(evts[0].amount.div((1e15).toString()).toNumber()).to.be.within(51397, 52291);
// 1 block(collectAllocationReward) passed for new reward pool, so we should get 1.25 SQT more
expect(evts[1].amount).to.lt(etherParse('1.25'));
await blockTravel(999);
Expand Down
10 changes: 6 additions & 4 deletions test/StateChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ describe('StateChannel Contract', () => {
// reward distribution should be skipped due to total stake is 0
tx = await rewardsHelper.connect(runner).indexerCatchup(runner.address);
evt = await eventFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evt).to.be.undefined;
expect(evt.rewards).to.eq(0);
});

/**
Expand Down Expand Up @@ -695,16 +695,18 @@ describe('StateChannel Contract', () => {
await stateChannel.claim(channelId);
balanceAfter = await token.balanceOf(consumer.address);
expect(balanceBefore.sub(balanceAfter)).to.eq(etherParse('0.4'));
let evt = await eventFrom(tx, stateChannel, 'ChannelLabor2(uint256,bytes32,address,uint256)');
const evt = await eventFrom(tx, stateChannel, 'ChannelLabor2(uint256,bytes32,address,uint256)');
expect(evt.amount).to.be.eq(etherParse('0.4'));

// start new era so we can try collect the channel reward
await startNewEra(eraManager);

// reward distribution should be skipped due to total stake is 0
tx = await rewardsHelper.connect(runner).indexerCatchup(runner.address);
evt = await eventFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evt.rewards).to.eq(etherParse('0.4'));
const evts = await eventsFrom(tx, rewardsDistributor, 'DistributeRewards(address,uint256,uint256,uint256)');
expect(evts.length).to.eq(2);
expect(evts[0].rewards).to.eq(0);
expect(evts[1].rewards).to.eq(etherParse('0.4'));

// delegator
const delegatorRewards = await rewardsDistributor.userRewards(runner.address, delegator.address);
Expand Down
Loading