Manage Farming Positions

A position is managed through just two different structs. The first one is the FarmingPositionRequest, used to open a new position or to add liquidity to an existing position (with the latter only available for Free setups).

All other position management operations (transfer a position, withdraw the reward, withdraw the liquidity, unlock locked position, etc.) use the struct FarmingPosition.

The FarmingPositionRequest is structured as follow:

struct FarmingPositionRequest {
    uint256 setupIndex; 
    uint256 amount; 
    bool amountIsLiquidityPool;  
    address positionOwner; 
  • setupIndex -> Index of the chosen farming setup

  • amount -> amount chosen to open the position or to add to an existing Free position in case of AddLiquidity

  • amountIsLiquidityPool -> boolean value representing if the sent amount is of LP tokens (true) or pair tokens (false)

  • positionOwner -> position owner address. Pass position owner either as 0x0000000000000000000000000000000000000000 to represent the msg.sender, or use another address of your choice. This means that by using the OpenPosition function, you can also open a position for another address.

The FarmingPosition struct contains all data of the position of a farmer in a setup and is populated and modified through the position management functions. It is composed as follows:

struct FarmingPosition {
    address uniqueOwner; 
    uint256 setupIndex; 
    uint256 creationBlock; 
    uint256 liquidityPoolTokenAmount; 
    uint256 mainTokenAmount; 
    uint256 reward; 
    uint256 lockedRewardPerBlock; 
  • uniqueOwner -> address representing the position owner address

  • setupIndex -> Index of the chosen farming setup

  • creationBlock -> current block when position created

  • liquidityPoolTokenAmount -> LP token amount added via _addLiquidity using the AMM Aggregator

  • mainTokenAmount -> used only in Locked setup to represent the main token amount corresponding to the amount of liquidity added to a position. It's an unpopulated parameter in a free setup position

  • reward -> the rewards for the position. For Locked setup positions, it is a precise, fixed figure calculated even before the position was staked. For Free setup positions, it is initially unpopulated , and subsequently repopulated block-to-block as rewards are calculated on a pro rata basis.

  • lockedRewardPerBlock -> the calculated reward per block for a Locked position. It is populated when the position is opened, and represents the fixed reward per block for that position. It is calculated based on the amount of liquidity (in the main token) staked by the farmer relative to the setups' maxStakeable amount. It is an unpopulated parameter in a free setup position

Last updated