Skip to content

Commit

Permalink
Refactor deposit logic to enforce a minimum deposit amount and update…
Browse files Browse the repository at this point in the history
… corresponding tests.
  • Loading branch information
ylv-io committed Feb 6, 2025
1 parent 665ac00 commit 36a5599
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/apps/SealedBidTokenSale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ contract SealedBidTokenSale is Ownable, ReentrancyGuard {
error CapNotReached();
/// @notice Thrown when attempting withdrawals if cap is reached
error CapReached();
/// @notice Thrown when attempting to deposit zero amount
error ZeroDeposit();
/// @notice Thrown when user has no funds to withdraw
error NothingToWithdraw(address user);
/// @notice Thrown when attempting to claim tokens more than once
Expand All @@ -63,6 +61,8 @@ contract SealedBidTokenSale is Ownable, ReentrancyGuard {
error InvalidProof(bytes32[] proof, bytes32 leaf);
/// @notice Thrown when attempting claims before Merkle root is set
error MerkleRootNotSet();
/// @notice Thrown when attempting to deposit less than MIN_DEPOSIT
error MinDeposit(uint256 amount);

/* ============ Events ============ */

Expand Down Expand Up @@ -97,7 +97,12 @@ contract SealedBidTokenSale is Ownable, ReentrancyGuard {
/// @param newPrice New max price value
event MaxPriceUpdated(address indexed user, uint256 oldPrice, uint256 newPrice);

/* ============ Immutable Parameters ============ */
/* ============ Constant ============ */

/// @notice Token being sold in the sale
uint256 public constant MIN_DEPOSIT = 250 * 1e6;

/* ============ Immutable ============ */

/// @notice Token being sold in the sale
IERC20 public immutable saleToken;
Expand Down Expand Up @@ -173,7 +178,7 @@ contract SealedBidTokenSale is Ownable, ReentrancyGuard {
// Verify sale is active and deposit is valid
if (block.timestamp < startTime) revert SaleNotStarted(block.timestamp, startTime);
if (saleEnded) revert SaleAlreadyEnded(block.timestamp);
if (amount == 0) revert ZeroDeposit();
if (amount < MIN_DEPOSIT) revert MinDeposit(amount);

// Update deposit accounting
deposits[msg.sender] += amount;
Expand Down
8 changes: 4 additions & 4 deletions test/unit/apps/SealedBidTokenSale.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,21 @@ contract SealedBidTokenSaleTest is SharedSetup {
sale.deposit(amount, maxPrice);
}

function testDeposit_RevertWhen_ZeroAmount() public {
function testDeposit_RevertWhen_MinAmount() public {
// Advance time to start of sale
vm.warp(startTime + 1);

// Try to deposit zero amount
vm.prank(alice);
vm.expectRevert(SealedBidTokenSale.ZeroDeposit.selector);
sale.deposit(0, maxPrice);
vm.expectRevert(abi.encodeWithSelector(SealedBidTokenSale.MinDeposit.selector, 250 * 1e6 - 1));
sale.deposit(250 * 1e6 - 1, maxPrice);
}

function testDeposit_MultipleDeposits() public {
// Advance time to start of sale
vm.warp(startTime + 1);

uint256 firstAmount = 1000 * 1e6;
uint256 firstAmount = 250 * 1e6;
uint256 secondAmount = 2000 * 1e6;
uint256 totalAmount = firstAmount + secondAmount;

Expand Down

0 comments on commit 36a5599

Please sign in to comment.