Free Farming Positions

The following section presents all the operations that a user can perform on a Free Farming Multi-AMM setup:

Open a Farming Position

The openPosition function is used to open a new farming position. It can be called only if the setup is already active. This function requires, as input, the FarmingPositionRequest struct.

function openPosition(FarmingPositionRequest memory request) public override payable activeSetupOnly(request.setupIndex) returns(uint256 positionId)

At the moment of creation, a positionID that represents the position is generated:

positionId = uint256(keccak256(abi.encode(uniqueOwner);

Each id is generated encoding the uniqueOwner (owner's position) address in a free setup. This means that each address can correspond to one and only one position within each setup, so there can be no multiple positions related to an address in a free setup.

Add Liquidity to an Existing Position

In a free setup position, more liquidity can be added to an already open position through theaddLiquidityfunction. This function requires, as input:

function addLiquidity(uint256 positionId, FarmingPositionRequest memory request) public override payable activeSetupOnly(request.setupIndex) byPositionOwner(positionId)
  • positionId -> Id of the corresponding farming position.

  • FarmingPositionRequest struct.

To withdraw the position reward, thewithdrawRewardfunction is used. It requires, as input:

function withdrawReward(uint256 positionId) public byPositionOwner(positionId) 
  • positionId -> id corresponding to the position to be transferred

Withdraw Reward

To withdraw the position reward, thewithdrawRewardfunction is used. It requires, as input:

function withdrawReward(uint256 positionId) public byPositionOwner(positionId) 
  • positionId -> id corresponding to the position to be transferred

It can be called at any time to withdraw the amount of reward thus far accumulated.

If there is a claimable reward amount, the function transfers the amount to the position owner's address.

The withdrawn reward amount is considered and added to the rewardPaid of the position that represent the total amount of reward already claimed from the position:

_rewardPaid[farmingPosition.setupIndex] += reward;

Please note that withdrawReward can be either be called directly or it is internally called when the withdrawLiquidity function is used in a Free setup.

Withdraw Liquidity

To withdraw a position's liquidity, withdrawLiquidity is used. This function can be called at any time.

This function requires, as input:

function withdrawLiquidity(uint256 positionId, uint256 objectId, bool unwrapPair, uint256 removedLiquidity) public 
  • positionId -> id corresponding to the position to be transferred

  • unwrapPair -> boolean value representing if the required liquidity to be withdrawn is wanted in LP tokens (true) or in pair tokens (false).

  • removedLiquidity -> amount of liquidity to be removed. Therefore in a free setup it is possible to remove at any time any amount of liquidity from one's position (not necessarily all of the liquidity)

Please note: as mentioned above, the withdrawLiquidity function also internally calls the withdrawReward method on the position's rewards accumulated until that moment.

If the liquidity withdrawn is equal to the entire amount of liquidity of the position (and therefore the remaining liquidity is 0), the position is automatically deleted from the setup and from the contract memory:

if (remainingLiquidity == 0) {
   delete _positions[positionId];} 

When the last position is closed and the setup goes inactive (see the Activate / Disactivate farming setup section to learn more), the entire setup is deleted from the memory of the contract.

Last updated