Skip to content

Commit

Permalink
feat: remove is capped
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvaleri committed May 3, 2024
1 parent e757804 commit 576af18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions contracts/PointTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/PointTokenVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 576af18

Please sign in to comment.