From 576af18a0bb4c6a1bea58cafde3a6beb3d0822d4 Mon Sep 17 00:00:00 2001 From: Steven Valeri Date: Thu, 2 May 2024 20:29:14 -0400 Subject: [PATCH] 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);