All pages
Powered by GitBook
1 of 5

Loading...

Loading...

Loading...

Loading...

Loading...

E721 Farms

E721 farms include all the farms built for pools in which the liquidity provider has an NFT (ERC721) position.

CamelotV3Farm

Git Source

Inherits: E721Farm, OperableDeposit, ClaimableFee

Author: Sperax Foundation.

This contract is the implementation of the Camelot V3 farm.

State Variables

tickLowerAllowed

tickUpperAllowed

camelotPool

camelotV3Factory

camelotUtils

nfpmUtils

MIN_TICK

MAX_TICK

Functions

initialize

Initializer function of this farm.

Parameters

Name
Type
Description

increaseDeposit

Allow user to increase liquidity for a deposit.

Parameters

Name
Type
Description

decreaseDeposit

Withdraw liquidity partially from an existing deposit.

Parameters

Name
Type
Description

getTokenAmounts

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

Returns

Name
Type
Description

_claimPoolFee

Claim pool fee implementation from ClaimableFee feature.

Parameters

Name
Type
Description

_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.

Parameters

Name
Type
Description

Returns

Name
Type
Description

_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.

Parameters

Name
Type
Description

Errors

InvalidCamelotPoolConfig

IncorrectPoolToken

IncorrectTickRange

InvalidTickRange

InvalidAmount

_input

InitializeInput

A struct having all the input params.

_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.

_depositId

uint256

Deposit index for the user.

_liquidityToWithdraw

uint128

Amount to be withdrawn.

_minAmounts

uint256[2]

Minimum amount of tokens to be received.

<none>

address[]

tokens An array of token addresses.

<none>

uint256[]

amounts An array of token amounts.

_depositId

uint256

Deposit ID of the deposit in the farm.

_tokenId

uint256

The tokenId of the position.

<none>

uint256

The liquidity of the position.

_tickLower

int24

The lower tick of the range.

_tickUpper

int24

The upper tick of the range.

int24 public tickLowerAllowed;
int24 public tickUpperAllowed;
address public camelotPool;
address public camelotV3Factory;
address public camelotUtils;
address public nfpmUtils;
int256 internal constant MIN_TICK = -887272;
int256 internal constant MAX_TICK = 887272;
function initialize(InitializeInput calldata _input) external;
function increaseDeposit(uint256 _depositId, uint256[2] calldata _amounts, uint256[2] calldata _minAmounts)
    external
    nonReentrant;
function decreaseDeposit(uint256 _depositId, uint128 _liquidityToWithdraw, uint256[2] calldata _minAmounts)
    external
    nonReentrant;
function getTokenAmounts() external view override returns (address[] memory, uint256[] memory);
function _claimPoolFee(uint256 _depositId)
    internal
    override
    returns (uint256 tokenId, uint256 amt0Recv, uint256 amt1Recv);
function _getLiquidity(uint256 _tokenId) internal view override returns (uint256);
function _validateTickRange(int24 _tickLower, int24 _tickUpper) private view;
error InvalidCamelotPoolConfig();
error IncorrectPoolToken();
error IncorrectTickRange();
error InvalidTickRange();
error InvalidAmount();

Camelot V3

Pools in camelot V3 are very similar to Uniswap V3. When a liquidity provider supplies assets to the pool, the LP receives an NFT position in return.

Next, you can see the specification for Camelot V3 farm and Camelot V3 farm deployer.

E721Farm

Git Source

Inherits: Farm, IERC721Receiver

Author: Sperax Foundation.

This contract contains the core logic for E721 farms.

State Variables

nftContract

depositToTokenId

Functions

onERC721Received

Function is called when user transfers the NFT to this farm.

Parameters

Name
Type
Description

Returns

Name
Type
Description

withdraw

Function to withdraw a deposit from the farm.

Parameters

Name
Type
Description

_getLiquidity

Function to get the liquidity. Must be defined by the farm.

This function should be overridden to add the respective logic.

Parameters

Name
Type
Description

Returns

Name
Type
Description

Errors

UnauthorisedNFTContract

NoData

<none>

address

_from

address

The address of the owner.

_tokenId

uint256

NFT Id generated by other protocol (e.g. Camelot or Uniswap).

_data

bytes

The data should be the lockup flag (bool).

<none>

bytes4

bytes4 The onERC721Received selector.

_depositId

uint256

The id of the deposit to be withdrawn.

_tokenId

uint256

The nft tokenId.

<none>

uint256

The liquidity of the nft position.

address public nftContract;
mapping(uint256 => uint256) public depositToTokenId;
function onERC721Received(address, address _from, uint256 _tokenId, bytes calldata _data)
    external
    override
    returns (bytes4);
function withdraw(uint256 _depositId) external override nonReentrant;
function _getLiquidity(uint256 _tokenId) internal view virtual returns (uint256);
error UnauthorisedNFTContract();
error NoData();

CamelotV3FarmDeployer

Git Source

Inherits: FarmDeployer

Author: Sperax Foundation.

This contract allows anyone to calculate fees, pay fees and create farms.

State Variables

CAMELOT_V3_FACTORY

NFPM

CAMELOT_UTILS

CAMELOT_NFPM_UTILS

Functions

constructor

Constructor of the contract.

Parameters

Name
Type
Description

createFarm

Deploys a new CamelotV3 farm.

The caller of this function should approve feeAmount to this contract before calling this function.

Parameters

Name
Type
Description

Returns

Name
Type
Description

Structs

FarmData

_camelotUtils

address

Address of CamelotUtils (Camelot helper) contract.

_nfpmUtils

address

Address of Camelot INonfungiblePositionManagerUtils (NonfungiblePositionManager helper) contract.

_farmRegistry

address

Address of the Farm Registry.

_farmId

string

Id of the farm.

_camelotV3Factory

address

Address of CamelotV3 factory.

_nfpm

address

Address of Camelot NonfungiblePositionManager contract.

_data

FarmData

Data for deployment.

<none>

address

Address of the deployed farm.

address public immutable CAMELOT_V3_FACTORY;
address public immutable NFPM;
address public immutable CAMELOT_UTILS;
address public immutable CAMELOT_NFPM_UTILS;
constructor(
    address _farmRegistry,
    string memory _farmId,
    address _camelotV3Factory,
    address _nfpm,
    address _camelotUtils,
    address _nfpmUtils
) FarmDeployer(_farmRegistry, _farmId);
function createFarm(FarmData memory _data) external nonReentrant returns (address);
struct FarmData {
    address farmAdmin;
    uint256 farmStartTime;
    uint256 cooldownPeriod;
    CamelotPoolData camelotPoolData;
    RewardTokenData[] rewardData;
}