Skip to content

G-UNI Pools are managed ERC20 Wrappers around Uniswap V3 Liquidity Positions

Notifications You must be signed in to change notification settings

Axis-Fi/g-uni-v1-core

 
 

Repository files navigation

CircleCI Coverage Status

G-UNI v1 Core

A shared fungible (ERC20) position for Uniswap V3 passive liquidity providers. G-UNI pools are auto-compounded by gelato network to reinvest accrued fees into the position. The position bounds are static and immutable by default, unless creating a "managed" pool, in which case an executiveRebalance can be performed by the governance/manager account which will redeposit liquidity into a new range (see docs for more info).

G-UNI Pool Overview

mint

    function mint(uint256 mintAmount, address receiver)
        external
        nonReentrant
        returns (
            uint256 amount0,
            uint256 amount1,
            uint128 liquidityMinted
        )

Arguments:

  • mintAmount amount of G-UNI tokens to mint
  • receiver account that receives the G-UNI tokens

Returns:

  • amount0 amount of token0 actually deposited into G-UNI
  • amount1 amount of token1 actually deposited into G-UNI
  • liquidityMinted amount of liqudiity added to G-UNI position

Note: to find out the amount of token0 and token1 you would owe by minting that many G-UNI tokens use getMintAmounts method.

burn

    function burn(uint256 _burnAmount, address _receiver)
        external
        nonReentrant
        returns (
            uint256 amount0,
            uint256 amount1,
            uint128 liquidityBurned
        )

Arguments:

  • _burnAmount number of G-UNI tokens to burn
  • _receiver account that receives the remitted token0 and token1

Returns:

  • amount0 amount of token0 remitted to _receiver
  • amount1 amount of token1 remitted to _receiver
  • liquidityBurned amount of liquidity burned from G-UNI positon

getMintAmounts (view call)

    function getMintAmounts(uint256 amount0Max, uint256 amount1Max)
        external
        view
        returns (
            uint256 amount0,
            uint256 amount1,
            uint256 mintAmount
        )

Arguments:

  • amount0Max maximum amount of token0 to deposit into G-UNI
  • amount1Max maximum amount of token1 to deposit into G-UNI

Returns:

  • amount0 actual amount of token0 to deposit into G-UNI
  • amount1 actual amount of token1 to deposit into G-UNI
  • mintAmount amount of G-UNI tokens to pass to mint function (will cost exactly amount0 and amount1)

rebalance

    function rebalance(
        uint160 _swapThresholdPrice,
        uint256 _swapAmountBPS,
        uint256 _feeAmount,
        address _paymentToken
    ) external gelatofy(_feeAmount, _paymentToken) {

Arguments:

  • _swapThresholdPrice a sqrtPriceX96 which is used as the slippage parameter in uniswap v3 swaps.
  • _swapAmountBPS amount to swap passed as basis points of current amount of leftover token held (e.g. "swap 50% of balance" would be a value of 5000)
  • _feeAmount amount that gelato will take as a fee (GelatoDiamond checks against gas consumption so bot is not allowed to overcharge)
  • _paymentToken the token in which _feeAmount is collected

Note: This method can only be called by gelato executors

executiveRebalance (for managed pools)

If governance/admin wants to change bounds of the underlying position, or wants to force a rebalance for any other reason, they are allowed to call this executive rebalance function.

    function executiveRebalance(
        int24 _newLowerTick,
        int24 _newUpperTick,
        uint160 _swapThresholdPrice,
        uint256 _swapAmountBPS,
        bool _zeroForOne
    ) external onlyOwner {

Arguments:

  • _newLowerTick the tick to use as position lower bound on reinvestment
  • _newUpperTick the tick to use as position upper bound on reinvestment
  • _swapThresholdPrice a sqrtPriceX96 which is used as the slippage parameter in uniswap v3 swaps.
  • _swapAmountBPS amount to swap passed as basis points of current amount of leftover token held (e.g. "swap 50% of balance" would be a value of 5000)
  • _zeroForOne which token to input into the swap (true = token0, false = token1)

test

yarn

yarn test

Setup

yarn install

Set up environment variables:

  • Copy .env.example to .env
  • Fill out environment variables

Deployment

  1. Ensure that the Gelato, GelatoDevMultiSig and UniswapV3Factory addresses are set in src/addresses.ts for the target chain.

  2. Deploy the GUniPool, as that will serve as input to the GUniFactory:

    HARDHAT_NETWORK="<chain name>" yarn run deploy:pool
  3. Copy the address of the GUniPool (output to the terminal) into the value of the GUniImplementation key in src/addresses.ts for the target chain.

  4. Deploy the GUniFactory:

    HARDHAT_NETWORK="<chain name>" yarn run deploy:factory

Note that these scripts will not deploy to a particular chain if there have been no changes to the contracts since the last deployment on that chain. To override this, pass the --reset flag.

Verification

  1. Verify the contracts:

    HARDHAT_NETWORK="<chain name>" yarn run verify
    • If hardhat reports that a network is not supported, specify the API url using --api-url <url>

NOTE: The GUniFactory contract will require additional steps to enable it to be viewed as a proxy.

About

G-UNI Pools are managed ERC20 Wrappers around Uniswap V3 Liquidity Positions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 52.8%
  • TypeScript 46.8%
  • Other 0.4%