Liquidity Mining Overview
Introduction
After the user has provided liquidity for a certain range, he receives an ERC-721 token tied to this range. This token can be used, not only as a proof of the provided liquidity, but also as a tool for yield-farming.
To receive rewards, a liquidity provider can participate in one of the farming Campaigns. We have two types of farming: limit and eternal.
Limit farming
Limit campaign is a time-limited, pool-based incentive program that contains a certain amount of reward tokens. To participate in the Campaign, one needs to send an ERC-721 token to the farming contract, which will be stored on it until the end of the Campaign. If there is an opportunity to increase the amount of liquidity in farming, the user can additionally lock the specified token and get a multiplier of their liquidity, and therefore receive more rewards.
After the end of the Campaign, all reward tokens will be distributed among the liquidity providers who participated in the Campaign, and all ERC-721 tokens will be returned back. The amount of the reward that a particular liquidity provider will receive depends on the time while her liquidity was in the price range in which the trades took place.
For proper reward calculation for each Campaign participant we invented an entity called a Virtual pool. A Virtual pool is a simplified copy of a real pool; it is used to track the time while the liquidity of different providers is active. The calculation of the time when liquidity was active for a certain period is performed as follows:
đ đđđđđđ đđđđŋđđđĸđđđđĄđĻ = đđđđđđđđđđđđ đŧđđ đđđ / đđđđđđŋđđđĸđđđđĄđĻ
Where rangeSecondsInside is the time while the price was at the range of provided liquidity, and rangeLiquidity is all of the liquidity on that range.
The time while liquidity was active on a given range is calculated as:
đđđ đđĄđđđđđđđđđđ đŧđđ đđđ = đ đđđđđđ đđđđŋđđđĸđđđđĄđĻ * đđđ đđĄđđđđŋđđđĸđđđđĄđĻ
Where positionLiquidity is the value that represents positionâs liquidity.
Now, knowing the time while the liquidity was active, we can calculate the reward for the given Campaign participant:
đđđ¤đđđ = đĄđđĄđđđ
đđ¤đđđ * đđđ đđĄđđđđđđđđđđ đŧđđ đđđ / đđđđđđđđđˇđĸđđđĄđđđ
Every time there is a swap in the real pool the Virtual pool recalculates the rewards for each participant of the Campaign.
Eternal Farming
Eternal farming is more like classic liquidity mining, the user can exit or enter farming at any time. It uses a logic similar to limit farming. Only the distribution mechanism differs. The number of distributed rewards is set using the rate (number of tokens per second) and can be changed during farming.
Dev part
Incentive Maker
Since in the current implementation only one farming of every type can be active for one pool and it is possible to increase / decrease the number of rewards, the ability to create farms and manage rewards has been moved to a separate role that can be set by the contract owner.
Contracts
There are three main contracts:
FarmingCenter contract on which users' NFTs are stored is used as a "proxy" for the interaction of the main and virtual pools. Interacts with contracts of limit and eternal farmings, allows to participate in two farmings at the same time.
To enter farming you need to transfer an NFT to the farming center to receive an Algebra Farming NFT-V2. After that you can participate in any type of farming for the pool, you provided liquidity to. After transfer, you need to call
After the enter, your liquidity will be recorded in the farming virtual pool and you will start earning rewards. While an NFT stays on the Farming Center, you can collect fees by calling the function
if the position is in an eternal farming, rewards can be collected by calling
To exit the eternal farming or finished limit farming you can call function
The rewards are not automatically accrued upon exit. To receive rewards you need to call
After the exit from all farmings, you can withdraw your position from Farming Center by calling
AlgebraEternalFarming and AlgebraLimitFarming contracts used to create farms, deploy virtual pools and calculate rewards.
Graph
In order to get a list of active farmings or positions, we use a subgraph. Farming graph contains all the entities necessary for this:
LimitFarming - contains information about the start and the end of farming, rewards and tiers. EternalFarming - contains information about virtual pools, rewards, rewards rates and tiers. Deposit - contains farmings keys in which the position takes part and information about locked tokens amounts. Reward - contain information about rewards amounts. Token - Ņontains basic information about tokens that are used in farmings.
Query Examples
Query for fetching all limit farmings:
Query for fetching all eternal farmings:
Query for fetching all active deposits in eternal farming: