Skip to main content
The LP token is a token that represents the liquidity in the pool. It is minted when liquidity is added to the pool and burned when liquidity is removed from the pool. The LP token is used to track the liquidity in the pool and to receive the LP fees. It conforms to an ERC721 enumerable token. It tracks 2 key variables: wj and rj. wj is the amount of liquidity provided by the liquidity provider. rj is the amount of revenue last claimed by the liquidity provider.

Minting

When liquidity is added to the pool, the LP token is minted to the liquidity provider. The amount of liquidity provided is the amount of liquidity added to the pool. The amount of revenue last claimed is set to hn which is the revenue parameter of the pool associated with the LP token.

Withdrawal

/**
 * @dev This is the function to withdraw liquidity from the pool.
 * @param tokenId The tokenId owned by the liquidity provider.
 * @param uj The amount of liquidity being withdrawn
 */
function withdrawLiquidity(uint256 tokenId, uint256 uj) external
When liquidity is removed from the pool, a parameter uj is passed in along with the token ID. uj is the desired amount of liquidity that an LP would like to withdraw from their position. A parameter q is produced dividing uj by w. In order to ensure an equal amount of LPs out, we calculate the amount of xTokens owed as q _ (xmax - x). The amount of xTokens owed is then subtracted from the pool’s x value. Concurrently for the amount of y tokens owed, we calculate the amount of y tokens owed as q _ (Dn - L). The amount of y tokens owed is then subtracted from the pool’s y value. If wj is less than uj, then this means that there is insufficient liquidity to withdraw and the transaction reverts. If wj is greater than uj, then uj is simply subtracted from wj, indicating that the LP is withdrawing a portion of their liquidity. If wj is equal to uj, then the LP token is burned and the liquidity is removed from the pool. After the amounts have been calculated, the pool’s state is updated with a new value of h and w and the parameter Zn on the curve is updated to ensure proper accounting.

Revenue Claiming

Revenue withdrawal is initiated in the ALTBC by the function withdrawRevenue.
function withdrawRevenue(uint256 tokenId, uint256 Q) external returns (uint256 revenue)
Q represents the amount of revenue being withdrawn. If Q is greater than the revenue available, the transaction reverts. A new value of revenue last claimed is then calculated as rj + Q/wj. Upon revenue being claimed, the updated rj is updated to add the amount of revenue claimed. The amount of revenue claimed is the amount of revenue that is being withdrawn. The amount of revenue being withdrawn is the amount of revenue that is being withdrawn from the pool.