Skip to content

Commit

Permalink
update getTotalTimeBasedRewardsBalance and test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkernell committed Nov 4, 2022
1 parent c39e2b9 commit 56031c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/TellorFlex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ contract TellorFlex {
* @return uint256 amount of trb
*/
function getTotalTimeBasedRewardsBalance() external view returns (uint256) {
return token.balanceOf(address(this)) - (totalStakeAmount + stakingRewardsBalance);
return token.balanceOf(address(this)) - (totalStakeAmount + stakingRewardsBalance + toWithdraw);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions test/e2eTests2.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,21 @@ describe("TellorFlex - e2e Tests Two", function() {
expectedStakerBalance2 += BigInt(h.toWei("100"))
assert(await token.balanceOf(accounts[3].address) == expectedStakerBalance2, "staker balance should be correct")
})

it("Time based rewards don't steal from stakes pending withdrawal", async function() {
await token.mint(accounts[0].address, h.toWei("10000"))
await token.approve(tellor.address, h.toWei("10000"))
await tellor.depositStake(h.toWei("1000"))
assert(await tellor.getTotalTimeBasedRewardsBalance() == 0, "total time based rewards balance should be 0")
assert(await tellor.toWithdraw() == 0, "toWithdraw should be 0")
await tellor.requestStakingWithdraw(h.toWei("100"))
assert(await tellor.getTotalTimeBasedRewardsBalance() == 0, "total time based rewards balance should be 0")
assert(await tellor.toWithdraw() == h.toWei("100"), "toWithdraw should be correct")

await tellor.submitValue(h.hash(h.uintTob32(1)), h.uintTob32(1000), 0, h.uintTob32(1))
await tellor.connect(govSigner).slashReporter(accounts[0].address, governance.address)

assert(await tellor.getTotalTimeBasedRewardsBalance() == 0, "total time based rewards balance should be 0")
assert(await tellor.toWithdraw() == 0, "toWithdraw should be correct")
})
})

0 comments on commit 56031c8

Please sign in to comment.