Skip to content

Commit

Permalink
rollover minQueueDeposit
Browse files Browse the repository at this point in the history
  • Loading branch information
3xHarry committed May 10, 2023
1 parent d6fab17 commit 9c65916
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/v2/Carousel/Carousel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ contract Carousel is VaultV2 {
uint256 _epochId,
uint256 _shares,
address _receiver
) public epochIdExists(_epochId) minRequiredDeposit(_shares, _epochId) {
) public epochIdExists(_epochId) {
// check if sender is approved by owner
if (
msg.sender != _receiver &&
Expand All @@ -237,6 +237,10 @@ contract Carousel is VaultV2 {
// check if user has enough balance
if (balanceOf(_receiver, _epochId) < _shares)
revert InsufficientBalance();
// to prevent spamming rollover queue and to ensure relayerFee can be payed,
// shares rolled over must be worth at least minQueueDeposit
if (!epochResolved[_epochId] && (_shares < minQueueDeposit)) revert MinDeposit();
else if (epochResolved[_epochId] && (previewWithdraw(_epochId, _shares) < minQueueDeposit)) revert MinDeposit();

// check if user has already queued up a rollover
if (ownerToRollOverQueueIndex[_receiver] != 0) {
Expand Down Expand Up @@ -830,8 +834,9 @@ contract Carousel is VaultV2 {
MODIFIERS
//////////////////////////////////////////////////////////////*/

/** @notice checks if deposit is greater than relayer fee
/** @notice checks if deposit is at least min required
* @param _assets amount of assets to deposit
* @param _epochId epoch id
*/
modifier minRequiredDeposit(uint256 _assets, uint256 _epochId) {
if (_epochId == 0 && _assets < minQueueDeposit) revert MinDeposit();
Expand Down
8 changes: 7 additions & 1 deletion test/V2/Carousel/CarouselTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ contract CarouselTest is Helper {

vm.startPrank(USER);
IERC20(UNDERLYING).approve(address(vault), 10 ether);
vm.expectRevert(Carousel.MinDeposit.selector);
vault.deposit(0, 900000000000000000, USER); // 0.9 ether

vault.deposit(0, 10 ether, USER);
vm.stopPrank();

Expand Down Expand Up @@ -165,11 +168,14 @@ contract CarouselTest is Helper {
// enlist in rollover for next epoch
vm.startPrank(USER);
//_epochId == epoch user is depositing in / amount of shares he wants to rollover
vm.expectRevert(Carousel.MinDeposit.selector);
vault.enlistInRollover(_epochId, 900000000000000000, USER); // 0.9 ether

vault.enlistInRollover(_epochId, 8 ether, USER);
vault.delistInRollover(USER);
vault.enlistInRollover(_epochId, 2 ether, USER);

assertEq(vault.getRolloverQueueLenght(), 1);
assertEq(vault.getRolloverQueueLength(), 1);

bool isEnlisted = vault.isEnlistedInRolloverQueue(USER);
(uint256 enlistedAmount,) = vault.getRolloverPosition(USER);
Expand Down

0 comments on commit 9c65916

Please sign in to comment.