Liquidity Provision

  • Mint

    • Function: mint

    • Pull liquidity of a token pair from msg.sender (should have approved enough amount), provide liquidity to Uniswap v3 pool, keep the liquidity position NFT in Particle contract. At the same time, create LiquidityPosition.Info to bookkeep the ownership of tokenId to msg.sender.

  • Increase liquidity

    • Function: increaseLiquidity

    • Increase liquidity to existing tokenId via Uniswap’s NonfungiblePositionManager.

    • Note: there are two internal functions of increaseLiquidity. The external facing one (takes lps storage as calldata input) authenticates the caller. The inner function is used in two cases: (1) this external facing function for an LP to add liquidity and (2) returning liquidity back to LP when closing a position in _closePosition.

  • Decrease liquidity

    • Function: decreaseLiquidity

    • Decrease liquidity from existing tokenId via Uniswap’s NonfungiblePositionManager.

    • Note: the decreased liquidity is stored in owed tokens. Withdrawing the actual amount needs the collectLiquidity function below.

    • Note: similar to increaseLiquidity, there are two internal functions of decreaseLiquidity. The external one (takes lps storage as calldata input) authenticates the caller. The inner function is used in two cases: (1) this external facing function for an LP to decrease liquidity and (2) borrowing liquidity from an LP position in openPosition.

  • Collect liquidity

    • Function: collectLiquidity

    • Collect fees and liquidity from owed tokens to the caller (LP) wallet.

    • Note: there are two internal functions of collectLiquidity. The external one (takes lps storage as calldata input) authenticates the caller. The inner function is used in two cases: (1) this external facing function for an LP to collect fees and (2) borrowing liquidity from an LP position in openPosition.

    • Note: this function imposes amountMax such that borrowing liquidity wouldn’t withdraw more amounts than requested.

Last updated