From 7a91c15b2c002fe1ce57d399b3babc5bcadeb123 Mon Sep 17 00:00:00 2001 From: Josh Levine Date: Mon, 22 Apr 2024 14:13:35 -0400 Subject: [PATCH] fix: round up for burn --- contracts/PointTokenVault.sol | 5 +++-- contracts/test/PointTokenVault.t.sol | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index df46ccc..0bad664 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -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"; @@ -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); } diff --git a/contracts/test/PointTokenVault.t.sol b/contracts/test/PointTokenVault.t.sol index 6f93375..2a76247 100644 --- a/contracts/test/PointTokenVault.t.sol +++ b/contracts/test/PointTokenVault.t.sol @@ -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 {