From 0cd072473ab2516627606b7f4241b57a256cddf7 Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Mon, 2 Sep 2024 14:20:47 -0400 Subject: [PATCH 1/3] Feat/mapping comment update (#18) * feat: update mapping comments * feat: clean comment * Update contracts/PointTokenVault.sol Co-authored-by: Josh Levine <24902242+jparklev@users.noreply.github.com> --------- Co-authored-by: Josh Levine <24902242+jparklev@users.noreply.github.com> --- contracts/PointTokenVault.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index 991b462..c3497b8 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -32,8 +32,8 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall // Merkle root distribution. bytes32 public currRoot; bytes32 public prevRoot; - mapping(address => mapping(bytes32 => uint256)) public claimedPTokens; // user => pointsId => claimed - mapping(address => mapping(bytes32 => uint256)) public claimedRedemptionRights; // user => pointsId => claimed + mapping(address => mapping(bytes32 => uint256)) public claimedPTokens; // user => pointsId => PTokens claimed + mapping(address => mapping(bytes32 => uint256)) public claimedRedemptionRights; // user => pointsId => Rewards redeemed mapping(bytes32 => PToken) public pTokens; // pointsId => pTokens From 62d37063f1d401be8ab520d096298633bd0bc386 Mon Sep 17 00:00:00 2001 From: Josh Levine Date: Mon, 2 Sep 2024 13:30:22 -0700 Subject: [PATCH 2/3] fix: separate deposit cap tracking from contract balance changes --- contracts/PointTokenVault.sol | 6 +++- contracts/test/PointTokenVault.t.sol | 41 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index c3497b8..25b81ed 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -43,6 +43,8 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall mapping(address => mapping(address => bool)) public trustedClaimers; // owner => delegate => trustedClaimers + mapping(address => uint256) public totalDeposited; // token => total deposited amount + // Fees uint256 public mintFee; uint256 public redemptionFee; @@ -115,7 +117,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall uint256 cap = caps[address(_token)]; if (cap != type(uint256).max) { - if (_amount + _token.balanceOf(address(this)) > cap) { + if (totalDeposited[address(_token)] + _amount > cap) { revert DepositExceedsCap(); } } @@ -123,12 +125,14 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall _token.safeTransferFrom(msg.sender, address(this), _amount); balances[_receiver][_token] += _amount; + totalDeposited[address(_token)] += _amount; emit Deposit(msg.sender, _receiver, address(_token), _amount); } function withdraw(ERC20 _token, uint256 _amount, address _receiver) public { balances[msg.sender][_token] -= _amount; + totalDeposited[address(_token)] -= _amount; _token.safeTransfer(_receiver, _amount); diff --git a/contracts/test/PointTokenVault.t.sol b/contracts/test/PointTokenVault.t.sol index f870d6f..c366da5 100644 --- a/contracts/test/PointTokenVault.t.sol +++ b/contracts/test/PointTokenVault.t.sol @@ -150,6 +150,47 @@ contract PointTokenVaultTest is Test { assertEq(pointTokenVault.balances(vitalik, newMockToken), 2e18); // Total 2 tokens deposited } + function test_DepositCapRewardSameAsDeposit() public { + // Set up an 18 decimal token as both deposit and reward token + MockERC20 token = new MockERC20("Example Token", "EX", 18); + + vm.startPrank(operator); + // Set deposit cap for token to 5000 + pointTokenVault.setCap(address(token), 5000e18); + + // Set token as reward token with 1:1 ratio + pointTokenVault.setRedemption(eigenPointsId, token, 1e18, false); + vm.stopPrank(); + + // Mint tokens to users + token.mint(vitalik, 5000e18); + token.mint(toly, 2000e18); + + // Vitalik deposits 4000 tokens + vm.startPrank(vitalik); + token.approve(address(pointTokenVault), 4000e18); + pointTokenVault.deposit(token, 4000e18, vitalik); + vm.stopPrank(); + + // Toly converts 2000 tokens to pTokens + vm.startPrank(toly); + token.approve(address(pointTokenVault), 2000e18); + pointTokenVault.convertRewardsToPTokens(toly, eigenPointsId, 2000e18); + vm.stopPrank(); + + // Assert current token balance in vault + assertEq(token.balanceOf(address(pointTokenVault)), 6000e18); + + // Try to deposit 1000 tokens, which should succeed + vm.startPrank(vitalik); + token.approve(address(pointTokenVault), 1000e18); + pointTokenVault.deposit(token, 1000e18, vitalik); + vm.stopPrank(); + + // Assert that 5000 tokens have been deposited + assertEq(pointTokenVault.balances(vitalik, token), 5000e18); + } + function test_DeployPToken() public { // Can't deploy the same token twice vm.expectRevert(PointTokenVault.PTokenAlreadyDeployed.selector); From daad4da1583d291422dc287a0b1f6268b2ef0757 Mon Sep 17 00:00:00 2001 From: Josh Levine Date: Tue, 3 Sep 2024 11:57:38 -0700 Subject: [PATCH 3/3] chore: move interaction below effects for deposit --- contracts/PointTokenVault.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index 25b81ed..a66a661 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -112,7 +112,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall _setFeeCollector(_feeCollector); } - // Rebasing and fee-on-transfer tokens must be wrapped before depositing. + // Rebasing and fee-on-transfer tokens must be wrapped before depositing. ie, they are not supported natively. function deposit(ERC20 _token, uint256 _amount, address _receiver) public { uint256 cap = caps[address(_token)]; @@ -122,11 +122,11 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall } } - _token.safeTransferFrom(msg.sender, address(this), _amount); - balances[_receiver][_token] += _amount; totalDeposited[address(_token)] += _amount; + _token.safeTransferFrom(msg.sender, address(this), _amount); + emit Deposit(msg.sender, _receiver, address(_token), _amount); }