# CamelotV3Farm

[Git Source](https://github.com/Sperax/Demeter-Protocol/blob/cc93b9106874316d6dd016cdace652e2ca4ef8e1/contracts/e721-farms/camelotV3/CamelotV3Farm.sol)

**Inherits:** E721Farm, OperableDeposit, ClaimableFee

**Author:** Sperax Foundation.

This contract is the implementation of the Camelot V3 farm.

## State Variables

### tickLowerAllowed

```solidity
int24 public tickLowerAllowed;
```

### tickUpperAllowed

```solidity
int24 public tickUpperAllowed;
```

### camelotPool

```solidity
address public camelotPool;
```

### camelotV3Factory

```solidity
address public camelotV3Factory;
```

### camelotUtils

```solidity
address public camelotUtils;
```

### nfpmUtils

```solidity
address public nfpmUtils;
```

### MIN\_TICK

```solidity
int256 internal constant MIN_TICK = -887272;
```

### MAX\_TICK

```solidity
int256 internal constant MAX_TICK = 887272;
```

## Functions

### initialize

Initializer function of this farm.

```solidity
function initialize(InitializeInput calldata _input) external;
```

**Parameters**

| Name     | Type              | Description                           |
| -------- | ----------------- | ------------------------------------- |
| `_input` | `InitializeInput` | A struct having all the input params. |

### increaseDeposit

Allow user to increase liquidity for a deposit.

```solidity
function increaseDeposit(uint256 _depositId, uint256[2] calldata _amounts, uint256[2] calldata _minAmounts)
    external
    nonReentrant;
```

**Parameters**

| Name          | Type         | Description                                        |
| ------------- | ------------ | -------------------------------------------------- |
| `_depositId`  | `uint256`    | The id of the deposit to be increased.             |
| `_amounts`    | `uint256[2]` | Desired amount of tokens to be increased.          |
| `_minAmounts` | `uint256[2]` | Minimum amount of tokens to be added as liquidity. |

### decreaseDeposit

Withdraw liquidity partially from an existing deposit.

```solidity
function decreaseDeposit(uint256 _depositId, uint128 _liquidityToWithdraw, uint256[2] calldata _minAmounts)
    external
    nonReentrant;
```

**Parameters**

| Name                   | Type         | Description                              |
| ---------------------- | ------------ | ---------------------------------------- |
| `_depositId`           | `uint256`    | Deposit index for the user.              |
| `_liquidityToWithdraw` | `uint128`    | Amount to be withdrawn.                  |
| `_minAmounts`          | `uint256[2]` | Minimum amount of tokens to be received. |

### getTokenAmounts

Function to be called by Rewarder to get tokens and amounts associated with the farm's liquidity.

```solidity
function getTokenAmounts() external view override returns (address[] memory, uint256[] memory);
```

**Returns**

| Name     | Type        | Description                         |
| -------- | ----------- | ----------------------------------- |
| `<none>` | `address[]` | tokens An array of token addresses. |
| `<none>` | `uint256[]` | amounts An array of token amounts.  |

### \_claimPoolFee

Claim pool fee implementation from `ClaimableFee` feature.

```solidity
function _claimPoolFee(uint256 _depositId)
    internal
    override
    returns (uint256 tokenId, uint256 amt0Recv, uint256 amt1Recv);
```

**Parameters**

| Name         | Type      | Description                            |
| ------------ | --------- | -------------------------------------- |
| `_depositId` | `uint256` | Deposit ID of the deposit in the farm. |

### \_getLiquidity

Validate the position for the pool and get Liquidity.

*The position must adhere to the price ranges.*

*Only allow specific pool token to be staked.*

```solidity
function _getLiquidity(uint256 _tokenId) internal view override returns (uint256);
```

**Parameters**

| Name       | Type      | Description                  |
| ---------- | --------- | ---------------------------- |
| `_tokenId` | `uint256` | The tokenId of the position. |

**Returns**

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `<none>` | `uint256` | The liquidity of the position. |

### \_validateTickRange

Validate the ticks (upper and lower).

*Get the info of the required token.*

*Check if the token belongs to correct pool.*

*Check if the token adheres to the tick range.*

*The ticks must be within the max range and must be multiple of tickSpacing.*

```solidity
function _validateTickRange(int24 _tickLower, int24 _tickUpper) private view;
```

**Parameters**

| Name         | Type    | Description                  |
| ------------ | ------- | ---------------------------- |
| `_tickLower` | `int24` | The lower tick of the range. |
| `_tickUpper` | `int24` | The upper tick of the range. |

## Errors

### InvalidCamelotPoolConfig

```solidity
error InvalidCamelotPoolConfig();
```

### IncorrectPoolToken

```solidity
error IncorrectPoolToken();
```

### IncorrectTickRange

```solidity
error IncorrectTickRange();
```

### InvalidTickRange

```solidity
error InvalidTickRange();
```

### InvalidAmount

```solidity
error InvalidAmount();
```
