Skip to content

Commit

Permalink
fix: round up for burn
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed Apr 22, 2024
1 parent 997e37e commit 7a91c15
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions contracts/PointTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {ERC20} from "solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol";

import {LibString} from "solady/utils/LibString.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";

import {PToken} from "./PToken.sol";

Expand Down Expand Up @@ -146,8 +147,8 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall
_verifyClaimAndUpdateClaimed(_claim, claimHash, msg.sender, claimedRedemptionRights);
}

// Will fail if the user doesn't also have enough point tokens.
pTokens[pointsId].burn(msg.sender, amountToClaim * 1e18 / rewardsPerPToken);
// Will fail if the user doesn't also have enough point tokens. Assume rewardsPerPToken is 18 decimals.
pTokens[pointsId].burn(msg.sender, FixedPointMathLib.mulWadUp(amountToClaim, rewardsPerPToken)); // Round up for burn.
rewardToken.safeTransfer(_receiver, amountToClaim);
emit RewardsClaimed(msg.sender, _receiver, pointsId, amountToClaim);
}
Expand Down
25 changes: 25 additions & 0 deletions contracts/test/PointTokenVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ contract PointTokenVaultTest is Test {
assertEq(rewardToken.balanceOf(vitalik), 2e18);
}

function test_RedeemRounding() public {
bytes32 root = 0x4e40a10ce33f33a4786960a8bb843fe0e170b651acd83da27abc97176c4bed3c;

bytes32[] memory proof = new bytes32[](1);
proof[0] = 0x6d0fcb8de12b1f57f81e49fa18b641487b932cdba4f064409fde3b05d3824ca2;

vm.prank(merkleUpdater);
pointTokenVault.updateRoot(root);

vm.prank(vitalik);
pointTokenVault.claimPTokens(PointTokenVault.Claim(eigenPointsId, 1e18, 1e18, proof), vitalik);

rewardToken.mint(address(pointTokenVault), 3e18);

vm.prank(operator);
pointTokenVault.setRedemption(eigenPointsId, rewardToken, 2e18, false);

bytes32[] memory empty = new bytes32[](0);
vm.prank(vitalik);
pointTokenVault.redeemRewards(PointTokenVault.Claim(eigenPointsId, 2e18, 1, empty), vitalik);

assertEq(rewardToken.balanceOf(vitalik), 1);
assertEq(pointTokenVault.pTokens(eigenPointsId).balanceOf(vitalik), 1e18 - 2); // round up for burn.
}

event RewardsClaimed(address indexed owner, address indexed receiver, bytes32 indexed pointsId, uint256 amount);

function test_MerkleBasedRedemption() public {
Expand Down

0 comments on commit 7a91c15

Please sign in to comment.