Skip to content

Commit

Permalink
Merge branch 'master' into 8-implement-minimum-deposit-enforce-withdr…
Browse files Browse the repository at this point in the history
…awal-period-regardless-of-positional-size
  • Loading branch information
sandybradley committed Aug 25, 2024
2 parents d5f2941 + 193fa60 commit f894ee3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
26 changes: 26 additions & 0 deletions script/FoldCaptiveStaking.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "forge-std/Script.sol";
import "src/FoldCaptiveStaking.sol";

contract FoldCaptiveStakingScript is Script {
INonfungiblePositionManager public positionManager =
INonfungiblePositionManager(0xC36442b4a4522E871399CD717aBDD847Ab11FE88);
IUniswapV3Pool public pool = IUniswapV3Pool(0x5eCEf3b72Cb00DBD8396EBAEC66E0f87E9596e97);
WETH public weth = WETH(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));
ERC20 public fold = ERC20(0xd084944d3c05CD115C09d072B9F44bA3E0E45921);


function run() public {
vm.startBroadcast();
FoldCaptiveStaking foldCaptiveStaking =
new FoldCaptiveStaking(address(positionManager), address(pool), address(weth), address(fold));

fold.transfer(address(foldCaptiveStaking), 1_000_000);
weth.transfer(address(foldCaptiveStaking), 1_000_000);

foldCaptiveStaking.initialize();
vm.stopBroadcast();
}
}
10 changes: 10 additions & 0 deletions script/deploy-fork.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

source .env

forge script script/FoldCaptiveStaking.s.sol:FoldCaptiveStakingScript \
--chain-id 1 \
--fork-url $RPC_MAINNET \
--broadcast \
--private-key $PRIVATE_KEY \
-vvv
12 changes: 12 additions & 0 deletions script/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

source .env

forge script script/FoldCaptiveStaking.s.sol:FoldCaptiveStakingScript \
--chain-id 1 \
--rpc-url $RPC_MAINNET \
--broadcast \
--private-key $PRIVATE_KEY \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY \
-vvv
2 changes: 2 additions & 0 deletions test/BaseCaptiveTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ contract BaseCaptiveTest is Test {
error WithdrawFailed();
error DepositAmountBelowMinimum();
error WithdrawalCooldownPeriodNotMet();
error WithdrawProRata();
error DepositCapReached();

FoldCaptiveStaking public foldCaptiveStaking;

Expand Down
30 changes: 30 additions & 0 deletions test/UnitTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "test/interfaces/ISwapRouter.sol";
contract UnitTests is BaseCaptiveTest {
ISwapRouter public router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);

/// @dev Ensure that balances and state variables are updated correctly.
function testAddLiquidity() public {
fold.transfer(User01, 1_000 ether);

Expand All @@ -26,6 +27,7 @@ contract UnitTests is BaseCaptiveTest {
assertEq(token1FeeDebt, 0);
}

/// @dev Ensure that balances and state variables are updated correctly.
function testRemoveLiquidity() public {
testAddLiquidity();

Expand All @@ -52,6 +54,7 @@ contract UnitTests is BaseCaptiveTest {
assertEq(amount, liq / 4);
}

/// @dev Ensure fees are accrued correctly and distributed proportionately.
function testFeesAccrue() public {
testAddLiquidity();

Expand Down Expand Up @@ -100,6 +103,7 @@ contract UnitTests is BaseCaptiveTest {
assertGt(foldCaptiveStaking.token1FeesPerLiquidity(), 0);
}

/// @dev Ensure fees are compounded correctly and state variables are updated.
function testCanCompoundFees() public {
testAddLiquidity();

Expand Down Expand Up @@ -147,6 +151,7 @@ contract UnitTests is BaseCaptiveTest {
assertGt(newAmount, amount);
}

/// @dev Ensure new users can't steal fees accrued by others.
function testNewUsersDontStealFees() public {
testFeesAccrue();

Expand Down Expand Up @@ -194,6 +199,7 @@ contract UnitTests is BaseCaptiveTest {
stakingTwo.depositRewards();
}

/// @dev Ensure rewards are added and collected correctly.
function testCanAddRewards() public {
testAddLiquidity();

Expand Down Expand Up @@ -222,6 +228,7 @@ contract UnitTests is BaseCaptiveTest {
foldCaptiveStaking.withdraw(liq / 3);
}

/// @dev Ensure the owner can claim insurance correctly.
function testClaimInsurance() public {
testAddLiquidity();

Expand All @@ -248,6 +255,7 @@ contract UnitTests is BaseCaptiveTest {
assertEq(amount, 0);
}

/// @dev Ensure the contract is protected against reentrancy attacks.
function testReentrancy() public {
testAddLiquidity();

Expand All @@ -273,6 +281,28 @@ contract UnitTests is BaseCaptiveTest {
// Expect revert due to minimum deposit requirement
vm.expectRevert(DepositAmountBelowMinimum.selector);
foldCaptiveStaking.deposit(0.5 ether, 0.5 ether, 0);
}

/// @dev Deposit Cap Enforcement: Test to ensure the deposit cap is respected.
function testDepositCap() public {
uint256 cap = 100 ether;
foldCaptiveStaking.setDepositCap(cap);

fold.transfer(User01, 2000 ether);

vm.deal(User01, 2000 ether);
vm.startPrank(User01);

weth.deposit{value: 2000 ether}();
weth.approve(address(foldCaptiveStaking), type(uint256).max);
fold.approve(address(foldCaptiveStaking), type(uint256).max);

// First deposit should succeed
foldCaptiveStaking.deposit(1_000 ether, 1_000 ether, 0);

// Second deposit should revert due to cap
vm.expectRevert(DepositCapReached.selector);
foldCaptiveStaking.deposit(1_000 ether, 1_000 ether, 0);

vm.stopPrank();
}
Expand Down

0 comments on commit f894ee3

Please sign in to comment.