From 576af18a0bb4c6a1bea58cafde3a6beb3d0822d4 Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Thu, 2 May 2024 20:29:14 -0400 Subject: [PATCH 1/3] feat: remove is capped --- contracts/PointTokenVault.sol | 15 +++++++-------- contracts/test/PointTokenVault.t.sol | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index fd6f5f6..176854f 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -25,6 +25,8 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall bytes32 public constant REDEMPTION_RIGHTS_PREFIX = keccak256("REDEMPTION_RIGHTS"); bytes32 public constant MERKLE_UPDATER_ROLE = keccak256("MERKLE_UPDATER_ROLE"); bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); + + uint256 public constant MAX_UINT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; // Deposit asset balancess. mapping(address => mapping(ERC20 => uint256)) public balances; // user => point-earning token => balance @@ -40,7 +42,6 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall mapping(bytes32 => RedemptionParams) public redemptions; // pointsId => redemptionParams mapping(address => uint256) public caps; // asset => deposit cap - bool public isCapped; struct Claim { bytes32 pointsId; @@ -82,13 +83,15 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall __AccessControl_init(); __Multicall_init(); _grantRole(DEFAULT_ADMIN_ROLE, _admin); - isCapped = true; } // Rebasing and fee-on-transfer tokens must be wrapped before depositing. function deposit(ERC20 _token, uint256 _amount, address _receiver) public { - if (isCapped && (_amount + _token.balanceOf(address(this)) > caps[address(_token)])) { - revert DepositExceedsCap(); + uint256 cap = caps[address(_token)]; + if (cap != MAX_UINT) { + if (_amount + _token.balanceOf(address(this)) > cap) { + revert DepositExceedsCap(); + } } _token.safeTransferFrom(msg.sender, address(this), _amount); @@ -218,10 +221,6 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall emit CapSet(_token, _cap); } - function setIsCapped(bool _isCapped) external onlyRole(OPERATOR_ROLE) { - isCapped = _isCapped; - } - // Can be used to unlock reward token redemption (can also modify a live redemption, so use with care). function setRedemption(bytes32 _pointsId, ERC20 _rewardToken, uint256 _rewardsPerPToken, bool _isMerkleBased) external diff --git a/contracts/test/PointTokenVault.t.sol b/contracts/test/PointTokenVault.t.sol index 05a4ee8..24fdb1e 100644 --- a/contracts/test/PointTokenVault.t.sol +++ b/contracts/test/PointTokenVault.t.sol @@ -123,9 +123,9 @@ contract PointTokenVaultTest is Test { assertEq(pointTokenVault.balances(vitalik, newMockToken), 1e18); - // Remove the cap + // Set deposit cap to max vm.prank(operator); - pointTokenVault.setIsCapped(false); + pointTokenVault.setCap(address(newMockToken), 2**256 - 1); // Approve and deposit more than the previous cap vm.startPrank(vitalik); From 471bfb01f46348734c6b3ff9c35cb09becbca5ff Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Thu, 2 May 2024 20:34:32 -0400 Subject: [PATCH 2/3] feat: update constant name --- contracts/PointTokenVault.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index 176854f..55eb849 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -26,7 +26,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall bytes32 public constant MERKLE_UPDATER_ROLE = keccak256("MERKLE_UPDATER_ROLE"); bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); - uint256 public constant MAX_UINT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; + uint256 public constant MAX_UINT_256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; // Deposit asset balancess. mapping(address => mapping(ERC20 => uint256)) public balances; // user => point-earning token => balance @@ -88,7 +88,8 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall // Rebasing and fee-on-transfer tokens must be wrapped before depositing. function deposit(ERC20 _token, uint256 _amount, address _receiver) public { uint256 cap = caps[address(_token)]; - if (cap != MAX_UINT) { + + if (cap != MAX_UINT_256) { if (_amount + _token.balanceOf(address(this)) > cap) { revert DepositExceedsCap(); } From 4e0ff492563ee8ccdab157383545da8b4677f2b0 Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Fri, 3 May 2024 16:35:38 -0400 Subject: [PATCH 3/3] feat: move max_uint to type(...).max --- contracts/PointTokenVault.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/contracts/PointTokenVault.sol b/contracts/PointTokenVault.sol index 55eb849..89db0ca 100644 --- a/contracts/PointTokenVault.sol +++ b/contracts/PointTokenVault.sol @@ -25,8 +25,6 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall bytes32 public constant REDEMPTION_RIGHTS_PREFIX = keccak256("REDEMPTION_RIGHTS"); bytes32 public constant MERKLE_UPDATER_ROLE = keccak256("MERKLE_UPDATER_ROLE"); bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE"); - - uint256 public constant MAX_UINT_256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; // Deposit asset balancess. mapping(address => mapping(ERC20 => uint256)) public balances; // user => point-earning token => balance @@ -89,7 +87,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall function deposit(ERC20 _token, uint256 _amount, address _receiver) public { uint256 cap = caps[address(_token)]; - if (cap != MAX_UINT_256) { + if (cap != type(uint256).max) { if (_amount + _token.balanceOf(address(this)) > cap) { revert DepositExceedsCap(); }