Manage Farming Positions

A position is managed through 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, etc.) interanlly use the struct FarmingPosition.

FarmingPositionRequest Struct

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 address(0) 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.

FarmingPosition Struct

The FarmingPosition struct contains all data of the position of a farmer in a setup and is populated and modified automatically through the position management functions (openPosition, addLiquidity, withdrawLiquidity and withdrawReward). It is composed as follows:

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

  • setupIndex -> Index of the chosen farming setup.

  • creationBlock -> current block when position created.

  • liquidityPoolTokenAmount -> LP token amount.

  • mainTokenAmount -> represent the main token amount corresponding to the amount of liquidity added to a position.

  • reward -> the rewards for the position. It's updated when an addLiquidity on an already existing Farming position is executed.

Last updated