Skip to content

Commit

Permalink
test: basic NAYM reward compounding
Browse files Browse the repository at this point in the history
  • Loading branch information
amarinkovic committed Dec 3, 2024
1 parent a410f8d commit a7dcd65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/libs/LibTokenizedVaultStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,13 @@ library LibTokenizedVaultStaking {

uint256 rewardAmount;
uint256 rewardCount = rewards.currencies.length;
for (uint64 i = 0; i <= rewardCount; i++) {
if (rewards.currencies[i] == tokenId) {
rewardAmount = rewards.amounts[i];
break;

if (rewardCount > 0) {
for (uint64 i = 0; i <= rewardCount; i++) {
if (rewards.currencies[i] == tokenId) {
rewardAmount = rewards.amounts[i];
break;
}
}
}

Expand Down
11 changes: 6 additions & 5 deletions test/T06Staking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,9 @@ contract T06Staking is D03ProtocolDefaults {
assertStakedAmount(bob.entityId, bobStakeAmount, "Bob's stake should increase");
c.log(" ~ [%s] Bob staked".blue(), currentInterval());

vm.expectRevert("No reward to compound");
nayms.compoundRewards(nlf.entityId);

vm.warp(startStaking + 61 days);

assertEq(nayms.lastPaidInterval(nlf.entityId), 0, "Last interval paid should be 0");
Expand All @@ -788,12 +791,10 @@ contract T06Staking is D03ProtocolDefaults {

vm.warp(startStaking + 181 days);

uint256 balanceBeforeClaim = nayms.internalBalanceOf(bob.entityId, NAYM_ID);

startPrank(bob);
// (bytes32[] memory currencies, uint256[] memory amounts) = nayms.getRewardsBalance(bob.entityId, nlf.entityId);
nayms.collectRewards(nlf.entityId);
assertEq(nayms.internalBalanceOf(bob.entityId, NAYM_ID), balanceBeforeClaim + 10_000, "Bob should have NAYM in his balance");
nayms.compoundRewards(nlf.entityId);
assertStakedAmount(bob.entityId, bobStakeAmount + 10_000, "Bob's stake should increase");
c.log(" ~ [%s] Reward1 compound".blue(), currentInterval());
}

function test_twoStakingRewardCurrencies() public {
Expand Down

0 comments on commit a7dcd65

Please sign in to comment.