Skip to content

Commit

Permalink
removed unnecessary nfpmutils contract
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnoGeek01 committed Mar 17, 2024
1 parent 6db59ac commit 1a53eb8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 85 deletions.
33 changes: 15 additions & 18 deletions contracts/e721-farms/camelotV3/CamelotV3Farm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {ExpirableFarm} from "../../features/ExpirableFarm.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {INFPM, ICamelotV3Factory, ICamelotV3TickSpacing} from "./interfaces/ICamelotV3.sol";
import {INFPMUtils, Position} from "./interfaces/ICamelotV3NonfungiblePositionManagerUtils.sol";
import {Deposit} from "../../interfaces/DataTypes.sol";
import {OperableDeposit} from "../../features/OperableDeposit.sol";

Expand All @@ -54,7 +53,6 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {
int24 public tickUpperAllowed;
address public camelotPool;
address public camelotV3Factory;
address public nfpmUtils; // Camelot INonfungiblePositionManagerUtils (NonfungiblePositionManager helper) contract

event PoolFeeCollected(address indexed recipient, uint256 tokenId, uint256 amt0Recv, uint256 amt1Recv);

Expand All @@ -76,7 +74,6 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {
/// @param _rwdTokenData - init data for reward tokens.
/// @param _camelotV3Factory - Factory contract of Camelot V3.
/// @param _nftContract - NFT contract's address (NFPM).
/// @param _nfpmUtils - address of our custom camelot nonfungible position manager utils contract.
function initialize(
string calldata _farmId,
uint256 _farmStartTime,
Expand All @@ -85,12 +82,10 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {
CamelotPoolData memory _camelotPoolData,
RewardTokenData[] memory _rwdTokenData,
address _camelotV3Factory,
address _nftContract,
address _nfpmUtils
address _nftContract
) external initializer {
_validateNonZeroAddr(_camelotV3Factory);
_validateNonZeroAddr(_nftContract);
_validateNonZeroAddr(_nfpmUtils);

// initialize camelot related data
camelotPool = ICamelotV3Factory(_camelotV3Factory).poolByPair(_camelotPoolData.tokenA, _camelotPoolData.tokenB);
Expand All @@ -103,7 +98,6 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {
tickUpperAllowed = _camelotPoolData.tickUpperAllowed;
camelotV3Factory = _camelotV3Factory;
nftContract = _nftContract;
nfpmUtils = _nfpmUtils;
_setupFarm(_farmId, _farmStartTime, _cooldownPeriod, _rwdTokenData);
_setupFarmExpiry(_farmStartTime, _farmRegistry);
}
Expand All @@ -123,15 +117,16 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {

address pm = nftContract;
uint256 tokenId = depositToTokenId[_depositId];
Position memory positions = INFPMUtils(nfpmUtils).positions(pm, tokenId);

(uint96 nonce,, address token0, address token1,,,,,,,) = INFPM(pm).positions(tokenId);

// Transfer tokens from user to the contract.
IERC20(positions.token0).safeTransferFrom(msg.sender, address(this), _amounts[0]);
IERC20(positions.token1).safeTransferFrom(msg.sender, address(this), _amounts[1]);
IERC20(token0).safeTransferFrom(msg.sender, address(this), _amounts[0]);
IERC20(token1).safeTransferFrom(msg.sender, address(this), _amounts[1]);

// Approve token to the NFPM contract.
IERC20(positions.token0).forceApprove(pm, _amounts[0]);
IERC20(positions.token1).forceApprove(pm, _amounts[1]);
IERC20(token0).forceApprove(pm, _amounts[0]);
IERC20(token1).forceApprove(pm, _amounts[1]);

// Increases liquidity in the current range
(uint128 liquidity, uint256 amount0, uint256 amount1) = INFPM(pm).increaseLiquidity(
Expand All @@ -149,10 +144,10 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {

// Return the excess tokens to the user.
if (amount0 < _amounts[0]) {
IERC20(positions.token0).safeTransfer(msg.sender, _amounts[0] - amount0);
IERC20(token0).safeTransfer(msg.sender, _amounts[0] - amount0);
}
if (amount1 < _amounts[1]) {
IERC20(positions.token1).safeTransfer(msg.sender, _amounts[1] - amount1);
IERC20(token1).safeTransfer(msg.sender, _amounts[1] - amount1);
}
}

Expand Down Expand Up @@ -237,20 +232,22 @@ contract CamelotV3Farm is E721Farm, ExpirableFarm, OperableDeposit {
/// @dev Only allow specific pool token to be staked.
function _getLiquidity(uint256 _tokenId) internal view override returns (uint256) {
/// @dev Get the info of the required token
Position memory positions = INFPMUtils(nfpmUtils).positions(nftContract, _tokenId);

(,, address token0, address token1, int24 tickLower, int24 tickUpper, uint128 liquidity,,,,) =
INFPM(nftContract).positions(_tokenId);

/// @dev Check if the token belongs to correct pool

if (camelotPool != ICamelotV3Factory(camelotV3Factory).poolByPair(positions.token0, positions.token1)) {
if (camelotPool != ICamelotV3Factory(camelotV3Factory).poolByPair(token0, token1)) {
revert IncorrectPoolToken();
}

/// @dev Check if the token adheres to the tick range
if (positions.tickLower != tickLowerAllowed || positions.tickUpper != tickUpperAllowed) {
if (tickLower != tickLowerAllowed || tickUpper != tickUpperAllowed) {
revert IncorrectTickRange();
}

return uint256(positions.liquidity);
return uint256(liquidity);
}

function _validateTickRange(int24 _tickLower, int24 _tickUpper) private view {
Expand Down
17 changes: 4 additions & 13 deletions contracts/e721-farms/camelotV3/CamelotV3FarmDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,20 @@ contract CamelotV3FarmDeployer is FarmDeployer, ReentrancyGuard {

address public immutable CAMELOT_V3_FACTORY; // Camelot V3 factory
address public immutable NFPM; // Camelot NonfungiblePositionManager contract
address public immutable CAMELOT_NFPM_UTILS; // Camelot INonfungiblePositionManagerUtils (NonfungiblePositionManager helper) contract

/// @notice Constructor of the contract
/// @param _farmRegistry Address of the Demeter Farm Registry
/// @param _farmId Id of the farm
/// @param _camelotV3Factory Address of CamelotV3 factory
/// @param _nfpm Address of Camelot NonfungiblePositionManager contract
/// @param _nfpmUtils Address of Camelot INonfungiblePositionManagerUtils (NonfungiblePositionManager helper) contract
constructor(
address _farmRegistry,
string memory _farmId,
address _camelotV3Factory,
address _nfpm,
address _nfpmUtils
) FarmDeployer(_farmRegistry, _farmId) {
constructor(address _farmRegistry, string memory _farmId, address _camelotV3Factory, address _nfpm)
FarmDeployer(_farmRegistry, _farmId)
{
_validateNonZeroAddr(_camelotV3Factory);
_validateNonZeroAddr(_nfpm);
_validateNonZeroAddr(_nfpmUtils);

CAMELOT_V3_FACTORY = _camelotV3Factory;
NFPM = _nfpm;
CAMELOT_NFPM_UTILS = _nfpmUtils;
farmImplementation = address(new CamelotV3Farm());
}

Expand All @@ -86,8 +78,7 @@ contract CamelotV3FarmDeployer is FarmDeployer, ReentrancyGuard {
_camelotPoolData: _data.camelotPoolData,
_rwdTokenData: _data.rewardData,
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_NFPM_UTILS
_nftContract: NFPM
});
farmInstance.transferOwnership(_data.farmAdmin);
address farm = address(farmInstance);
Expand Down

This file was deleted.

48 changes: 15 additions & 33 deletions test/e721-farms/camelotV3/CamelotV3Farm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
INFPM,
OperableDeposit
} from "../../../contracts/e721-farms/camelotV3/CamelotV3Farm.sol";
import {
INFPMUtils,
Position
} from "../../../contracts/e721-farms/camelotV3/interfaces/ICamelotV3NonfungiblePositionManagerUtils.sol";
import "@cryptoalgebra/v1.9-periphery/contracts/interfaces/ISwapRouter.sol";

// import tests
Expand Down Expand Up @@ -75,9 +71,7 @@ abstract contract CamelotV3FarmTest is E721FarmTest {

// Deploy and register farm deployer
FarmRegistry registry = FarmRegistry(FARM_REGISTRY);
camelotV3FarmDeployer = new CamelotV3FarmDeployer(
FARM_REGISTRY, FARM_ID, CAMELOT_V3_FACTORY, NFPM, CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
);
camelotV3FarmDeployer = new CamelotV3FarmDeployer(FARM_REGISTRY, FARM_ID, CAMELOT_V3_FACTORY, NFPM);
registry.registerFarmDeployer(address(camelotV3FarmDeployer));

// Configure rewardTokens
Expand Down Expand Up @@ -153,9 +147,9 @@ abstract contract CamelotV3FarmTest is E721FarmTest {
return (_tokenId, nfpm());
}

function getLiquidity(uint256 tokenId) public view override returns (uint256 liquidity) {
Position memory positions = INFPMUtils(CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS).positions(nfpm(), tokenId);
return uint256(positions.liquidity);
function getLiquidity(uint256 tokenId) public view override returns (uint256) {
(,,,,,, uint128 liquidity,,,,) = INFPM(NFPM).positions(tokenId);
return uint256(liquidity);
}

function createFarm(uint256 startTime, bool lockup)
Expand Down Expand Up @@ -275,8 +269,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

// Fails for _tickLower < -887272
Expand All @@ -294,8 +287,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

if (spacing > 1) {
Expand All @@ -314,8 +306,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

// Fails for _tickUpper % spacing != 0
Expand All @@ -333,8 +324,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});
}

Expand All @@ -353,8 +343,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});
}

Expand All @@ -373,8 +362,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

vm.expectRevert(abi.encodeWithSelector(CamelotV3Farm.InvalidCamelotPoolConfig.selector));
Expand All @@ -391,8 +379,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

vm.expectRevert(abi.encodeWithSelector(CamelotV3Farm.InvalidCamelotPoolConfig.selector));
Expand All @@ -409,8 +396,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

vm.expectRevert(abi.encodeWithSelector(CamelotV3Farm.InvalidCamelotPoolConfig.selector));
Expand All @@ -427,8 +413,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

vm.expectRevert(abi.encodeWithSelector(CamelotV3Farm.InvalidCamelotPoolConfig.selector));
Expand All @@ -445,8 +430,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});
}

Expand All @@ -465,8 +449,7 @@ abstract contract InitializeTest is CamelotV3FarmTest {
}),
_rwdTokenData: generateRewardTokenData(),
_camelotV3Factory: CAMELOT_V3_FACTORY,
_nftContract: NFPM,
_nfpmUtils: CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS
_nftContract: NFPM
});

assertEq(CamelotV3Farm(farmProxy).farmId(), FARM_ID);
Expand All @@ -479,7 +462,6 @@ abstract contract InitializeTest is CamelotV3FarmTest {
assertEq(CamelotV3Farm(farmProxy).farmId(), FARM_ID);
assertEq(CamelotV3Farm(farmProxy).camelotV3Factory(), CAMELOT_V3_FACTORY);
assertEq(CamelotV3Farm(farmProxy).nftContract(), NFPM);
assertEq(CamelotV3Farm(farmProxy).nfpmUtils(), CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS);
}
}

Expand Down
1 change: 0 additions & 1 deletion test/utils/networkConfig/Arbitrum.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ abstract contract Arbitrum is BaseSetup, INetworkConfig {
address public constant CAMELOT_V3_FACTORY = 0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B;
address public constant CAMELOT_V3_NFPM = 0x00c7f3082833e796A5b3e4Bd59f6642FF44DCD15;
address public constant CAMELOT_V3_SWAP_ROUTER = 0x1F721E2E82F6676FCE4eA07A5958cF098D339e18;
address public constant CAMELOT_V3_NONFUNGIBLE_POSITION_MANAGER_UTILS = 0xaB39C3d042BA31978087a4b946baBc8C80d868a4;

function fundFeeToken() public useKnownActor(owner) {
uint256 amt = 1e22;
Expand Down

0 comments on commit 1a53eb8

Please sign in to comment.