FarmingCenter

Algebra main farming contract

Developer note: Manages farmings and performs entry, exit and other actions.

Variables

contract IAlgebraLimitFarming limitFarming immutable

contract IAlgebraEternalFarming eternalFarming immutable

contract INonfungiblePositionManager nonfungiblePositionManager immutable

The nonfungible position manager with which this farming contract is compatible

contract IFarmingCenterVault farmingCenterVault immutable

mapping(uint256 => struct FarmingCenter.Deposit) deposits

Developer note: deposits[tokenId] => Deposit

mapping(uint256 => struct FarmingCenter.L2Nft) l2Nfts

Functions

constructor

constructor(contract IAlgebraLimitFarming _limitFarming, contract IAlgebraEternalFarming _eternalFarming, contract INonfungiblePositionManager _nonfungiblePositionManager, contract IFarmingCenterVault _farmingCenterVault) public public

NameTypeDescription
_limitFarmingcontract IAlgebraLimitFarming
_eternalFarmingcontract IAlgebraEternalFarming
_nonfungiblePositionManagercontract INonfungiblePositionManager
_farmingCenterVaultcontract IFarmingCenterVault

onERC721Received

function onERC721Received(address, address from, uint256 tokenId, bytes) external returns (bytes4) external

Upon receiving a Algebra ERC721, creates the token deposit setting owner to `from`. *Developer note: Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} by `operator` from `from`, this function is called.

It must return its Solidity selector to confirm the token transfer. If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.

The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.*

NameTypeDescription
address
fromaddress
tokenIduint256
bytes

Returns:

NameTypeDescription
[0]bytes4

enterFarming

function enterFarming(struct IIncentiveKey.IncentiveKey key, uint256 tokenId, uint256 tokensLocked, bool isLimit) external external

Enters in incentive (time-limited or eternal farming) with NFT-position token Developer note: token must be deposited in FarmingCenter

NameTypeDescription
keystruct IIncentiveKey.IncentiveKeyThe incentive event key
tokenIduint256The id of position NFT
tokensLockeduint256Amount of tokens to lock for liquidity multiplier (if tiers are used)
isLimitboolIs incentive time-limited or eternal

exitFarming

function exitFarming(struct IIncentiveKey.IncentiveKey key, uint256 tokenId, bool isLimit) external external

Exits from incentive (time-limited or eternal farming) with NFT-position token

NameTypeDescription
keystruct IIncentiveKey.IncentiveKeyThe incentive event key
tokenIduint256The id of position NFT
isLimitboolIs incentive time-limited or eternal

collect

function collect(struct INonfungiblePositionManager.CollectParams params) external returns (uint256 amount0, uint256 amount1) external

Collects up to a maximum amount of fees owed to a specific position to the recipient Developer note: "proxies" to NonfungiblePositionManager

NameTypeDescription
paramsstruct INonfungiblePositionManager.CollectParamstokenId The ID of the NFT for which tokens are being collected,

recipient The account that should receive the tokens, amount0Max The maximum amount of token0 to collect, amount1Max The maximum amount of token1 to collect |

Returns:

NameTypeDescription
amount0uint256The amount of fees collected in token0
amount1uint256The amount of fees collected in token1

collectRewards

function collectRewards(struct IIncentiveKey.IncentiveKey key, uint256 tokenId) external returns (uint256 reward, uint256 bonusReward) external

Used to collect reward from eternal farming. Then reward can be claimed.

NameTypeDescription
keystruct IIncentiveKey.IncentiveKeyThe incentive event key
tokenIduint256The id of position NFT

Returns:

NameTypeDescription
rewarduint256The amount of collected reward
bonusRewarduint256The amount of collected bonus reward

claimReward

function claimReward(contract IERC20Minimal rewardToken, address to, uint256 amountRequestedIncentive, uint256 amountRequestedEternal) external returns (uint256 reward) external

Used to claim and send rewards from farming(s) Developer note: can be used via static call to get current rewards for user

NameTypeDescription
rewardTokencontract IERC20MinimalThe token that is a reward
toaddressThe address to be rewarded
amountRequestedIncentiveuint256Amount to claim in incentive (limit) farming
amountRequestedEternaluint256Amount to claim in eternal farming

Returns:

NameTypeDescription
rewarduint256The summary amount of claimed rewards

connectVirtualPool

function connectVirtualPool(contract IAlgebraPool pool, address newVirtualPool) external external

Updates activeIncentive in AlgebraPool Developer note: only farming can do it

NameTypeDescription
poolcontract IAlgebraPoolThe AlgebraPool for which farming was created
newVirtualPooladdress

withdrawToken

function withdrawToken(uint256 tokenId, address to, bytes data) external external

Withdraw Algebra NFT-position token Developer note: can be used via static call to get current rewards for user

NameTypeDescription
tokenIduint256The id of position NFT
toaddressNew owner of position NFT
databytesThe additional data for NonfungiblePositionManager

cross

function cross(int24 nextTick, bool zeroToOne) external external

Developer note: This function is called by the main pool when an initialized tick is crossed and two farmings are active at same time.

NameTypeDescription
nextTickint24The crossed tick
zeroToOneboolThe direction

increaseCumulative

function increaseCumulative(uint32 blockTimestamp) external returns (enum IAlgebraVirtualPool.Status status) external

Developer note: This function is called by the main pool at start of the swap if two farmings are active at same time.

NameTypeDescription
blockTimestampuint32The current block timestamp, truncated

Returns:

NameTypeDescription
statusenum IAlgebraVirtualPool.StatusThe current farming(s) status

virtualPoolAddresses

function virtualPoolAddresses(address pool) external view returns (address limitVP, address eternalVP) view external

NameTypeDescription
pooladdress

Returns:

NameTypeDescription
limitVPaddress
eternalVPaddress

getApproved

function getApproved(uint256 tokenId) public view returns (address) view public

*Developer note: Returns the account approved for `tokenId` token.

Requirements:

  • `tokenId` must exist.*
NameTypeDescription
tokenIduint256

Returns:

NameTypeDescription
[0]address