Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove is capped #15

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 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_256 = 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,16 @@ 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_256) {
if (_amount + _token.balanceOf(address(this)) > cap) {
revert DepositExceedsCap();
}
}

_token.safeTransferFrom(msg.sender, address(this), _amount);
Expand Down Expand Up @@ -218,10 +222,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