Skip to content

VolumeFi/cellars

Repository files navigation

Uniswap v3 Cellars

Sommelier Ethereum Cellars for Uniswap v3 Work in Progress

Testing and Development on testnet

Dependencies

  • nodejs - >=v8, tested with version v14.15.4
  • python3 from version 3.6 to 3.8, python3-dev
  • brownie - tested with version 1.14.6
  • ganache-cli

Run Ganache-cli mainnet-fork environment

ganache-cli --fork https://mainnet.infura.io/v3/#{YOUR_INFURA_KEY} -p 7545

Add local network setting to brownie

brownie networks add Development local host=http://127.0.0.1 accounts=10 evm_version=istanbul fork=mainnet port=7545 mnemonic=brownie cmd=ganache-cli timeout=300

Deploy on local ganache-cli network

brownie run scripts/deploy.py --network local

Running the Tests

brownie test

Get input amount ratio

brownie run scripts/check_input_ratio.py

If this amount is division by zero or 0, only one token exists in the cellar.

Tests Suite Files

Test Description Expected Failures File
Add liquidity to the Cellar Test - Test add liquidity using 1 ETH and 3,000 USDC 3 times for 2 users and compare their balances.
- Test add liquidity using 1 WETH and 3,000 USDC 3 times for 2 users and compare their balances.
Their balances should be the same. Otherwise, the test is failure test_00_add_liquidity.py
Transfer liquidity Test transfer and approve liquidity after adding liquidity using 1 ETH and 3,000 USDC 3 times. Approve / Transfer / TransferFrom should work as a standard ERC20. Otherwise, the test is failure. test_01_transfer.py
Remove liquidity Test remove 1/3 liquidity in Uniswap version 3 after adding liquidity using 1 ETH and 3,000 USDC 3 times and compare to decreased balance. Decreased balance should be the same as the balance for removed liquidity. test_02_remove_liquidity.py
Reinvest liquidity Test reinvest after adding liquidity using 1 ETH and 3,000 USDC 3 times, confirm account balance is empty after removing liquidity. The account balance should be empty. test_03_reinvest.py
Rebalance liquidity Test rebalance after adding liquidity using 1 ETH and 3,000 USDC 3 times, confirm balance of account is 0 after rebalance and removing liquidity. The account balance should be empty. test_04_rebalance.py
Weight Management Test liquidities of NFLP in the contract after adding liquidity using 1 ETH and 1,000 USDC, 1 ETH and 5,000 USDC. The liquidities' ratio should be the approximately same as weight. Accuracy is accurater than 1 millionth test_05_weight.py

Libraries Used

Library Name Library Description Source URL or additional documentation
TickMath Uniswap Math library for computing sqrt prices from ticks and vice versa. Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports prices between 2**-128 and 2**128 Uniswap v3 Core
LiquidityAmounts Liquidity amount functions provides functions for computing liquidity amounts from token amounts and prices Uniswap v3 periphery
SafeMath Zeppelin Solidity Library for Math operations with safety checks throws on error OpenZeppelin
Address Collection of functions related to the address type. Returns true if account is a contract. OpenZeppelin
SafeERC20 Zeppelin Solidity wrapper around the interface that eliminates the need to handle boolean return OpenZeppelin
FixedPoint96 A library for handling binary fixed point numbers Uniswap Core
FullMath Contains 512-bit math functions. Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision. Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits Uniswap libraries

External functions

Function Name Parameters Description
transfer address recipient, uint256 amount
approve address spender, uint256 amount
transferFrom address sender,address recipient,uint256 amount
addLiquidityForUniV3 CellarAddParams calldata cellarParams Add liquidity with both tokens to Uniswap v3 pool
addLiquidityEthForUniV3 CellarAddParams calldata Add liquidity with Eth and the other token to Uniswap v3 pool
removeLiquidityEthFromUniV3 CellarRemoveParams calldata cellarParams Remove liquidity to Eth and the other token from Uniswap v3 pool
removeLiquidityFromUniV3 CellarRemoveParams calldata cellarParams Remove liquidity to both tokens from the Uniswap v3 pool
reinvest Collect swap fee and re-add liquidity. Some amounts go to owner as "Use Fee"
rebalance CellarTickInfo[] memory _cellarTickInfo Update NFLP positions of the Uniswap v3 pool
setValidator address _validator, bool value
transferOwnership address, newOwner
setFee uint16, newFee Set Use Fee ratio to owner
owner
name
symbol
decimals
totalSupply
balanceOf address account
allowance address owner_, address spender

Internal functions

Function Name Parameters Description
getWeightInfo CellarTickInfo[] memory _cellarTickInfo Get weights of Token0 and Token1 to add liquidity per NFLP
modifyWeightInfo CellarTickInfo[] memory _cellarTickInfo,uint256 amount0Desired,uint256 amount1Desired,uint256 weightSum0,uint256 weightSum1,uint256[] memory weight0,uint256[] memory weight1 Calculate Sum of weights of token0 and token1 to add exact weighted-liquidity
addLiquidity CellarAddParams memory cellarParams Add liquidity to NFLP
removeLiquidity CellarRemoveParams memory cellarParams Remove liquidity from NFLP

Other internal functions are taken from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.1-solc-0.7-2/contracts/token/ERC20/ERC20.sol Common ERC-20 interfaces. Please use as reference.

Audit Report

Last Audit provided by Quantstamp on November 4, 2021

Disclaimer

Neither does VolumeFi nor Sommelier manage any portfolios. You must make an independent judgment as to whether to add liquidity to portfolios. Users of this repo should familiarize themselves with smart contracts to further consider the risks associated with smart contracts before adding liquidity to any portfolios or deployed smart contract. These smart contracts are non-custodial and come with no warranties. VolumeFi does not endorse any pools in any of the smart contracts found in this repo. VolumeFi and Sommelier are not giving you investment advice with this software and neither firm has control of your funds. All our smart contract software is alpha, works in progress and are undergoing daily updates that may result in errors or other issues.