ArrakisV2

ERC20 vault smart contract at the heart of this LP management system.

ArrakisV2 instances cannot be arbitrarily trusted. ArrakisV2 is the core tokenized vault contract that can be flexibly configured for multiple use-cases (by anyone, via the ArrakisV2Factory). There are trust assumptions on privileged roles owner & manager.Only certain implementations of these roles would provide trustless guarantees for all shareholders (i.e. where no party has a way to drain funds deposited into the vault by others)

Constant/Immutable Properties

Public Properties

Internal Properties

Structs

Range

PositionLiquidity

SwapPayload

Rebalance

External Functions

mint

mint shares of an ArrakisV2 ERC20 LP token by depositing token0 and token1 in correct proportion. MUST approve ArrakisV2 contract to spend enough token0/token1 before call.

Don't call this method naively - it requires additional checks on-chain to be safe from sandwich attacks!

parameters :

returns :

modifiers :

  • reentrancy protection.

checks :

  • mintAmount should be higher than 0.

  • restrictedMint should be address(0), else restrictedMint must be the msg.sender.

events :

  • LogMint(address indexed receiver, uint256 mintAmount, uint256 amount0In, uint256 amount1In)

rebalance

This is the low-level entry point for manager to rebalance the vault. Has sensitive calldata that either needs to be checked on-chain in the manager contract implementation, or else manager must be otherwise trusted by the LP(s) to pass non-manipulable calldata.

ArrakisV2 vault holdings and liquidity can be rebalanced by manager account at any time. This function may do all or some of these operations:

  1. remove token0/token1 liquidity from existing Uniswap V3 Positions of choice into vault

  2. swap vault holdings (in either direction on the token pair) on any whitelisted swap router

  3. add token0/token1 from vault as liquidity into Uniswap V3 Positions of choice

parameters :

modifiers :

  • only manager.

  • reentrancy protection.

checks :

  • if swapping, check swap router against whitelisted routers.

  • check that amounts withdrawn are not below minBurn amounts.

  • check that amounts deposited are not below minDeposit amounts.

events:

  • LogCollectedFees(uint256 fee0, uint256 fee1)

burn

burn ArrakisV2 ERC20 LP token shares to receive underlying token0 and token1

parameters :

returns :

modifiers :

  • reentrancy protection.

checks :

  • check total supply is greater than 0.

  • if leftover on the vault is smaller than the amount0 and amount1, check burns array is not empty (need to burn some ranges to be able to send back amount0 and amount1 to receiver).

events :

  • LogCollectedFees(uint256 fee0, uint256 fee1)

  • LPBurned(address indexed user, uint256 burnAmount0, uint256 burnAmount1)

  • LogBurn(address indexed receiver, uint256 burnAmount, uint256 amount0Out, uint256 amount1Out)

withdrawManagerBalanace

Sends accrued manager balances of token0 and token1 to the manager account.

Note that owner has the ability to expropriate earned but uncollected fees of a manager by resetting the manager role. (Easy to eliminate this in the periphery, if it is not a desired feature)

events :

  • LogWithdrawManagerBalance(uint256 amount0, uint256 amount1)

getRanges

view the set of ranges where the vault has active Uniswap V3 positions

returns :

getPools

view the Uniswap V3 pools whitelisted for use by manager (when adding liquidity in rebalance method)

returns :

getRouters

view the "swap router" contracts whitelisted for use by manager (when swapping in rebalance method)

returns :

addPools

whitelist UniswapV3 pools of the desired fee tiers

parameters :

modifiers :

  • onlyOwner.

checks :

  • checks pool addresses on uniswap v3 factory from feeTier, token0, token1.

  • check that pool addresses are not zero address.

  • check that pool addresses are not already whitelisted.

events :

  • LogAddPools(uint24[] feeTiers)

removePools

remove Uniswap V3 pools from the whitelist

parameters :

modifiers :

  • should only be called by the owner.

checks :

  • check pools addresses are not equal to zero address.

  • check pools addresses are whitelisted pools.

events :

  • LogRemovePools(address[] pools)

whitelistRouters

add contract addresses to the whitelist of swap routers.

parameters :

modifiers :

  • only owner.

checks :

  • check that router address is not token0 or token1.

  • check that router addresses are not already whitelisted.

events :

  • LogWhitelistRouters(address[] routers)

blacklistRouters

remove contract addresses from swap router whitelist

parameters :

modifiers :

  • only owner

checks :

  • router addresses should be whitelisted.

events :

  • LogBlacklistRouters(address[] routers)

setInits

set token ratios for the initial mint of ArrakisV2 shares

parameters :

checks:

  • checks that init0 or init1 is greater than zero

  • checks that totalSupply is 0

  • checks that caller is owner (if restrictedMint is unset) or else is restrictedMint address

events :

  • LogSetInits(uint256 init0, uint256 init1)

setManager

set the manager account that is permitted to call rebalance function and manage liquidity positions

parameters :

modifiers :

  • only owner

events :

  • LogSetManager(address newManager)

setRestrictedMint

set restrictedMint account which (when set to non-zero address) is only account permitted to call mint function

parameters :

modifiers :

  • only owner

events :

  • LogRestrictedMint(address minter)

setManagerFeeBPS

set a percentage of Uniswap fees earned aside to accrue to the manager.

parameters :

events:

  • LogSetManagerFeeBPS(uint16 managerFeeBPS)

uniswapV3MintCallback

Uniswap V3 callback function, calls us back on all IUniswapV3Pool.mint calls

parameters :

checks :

  • check msg.sender is one of the whitelisted pools

initialize

initialize a new ArrakisV2 instance (called by ArrakisV2Factory on deployVault)

parameters :

modifiers :

  • initializer (only callable once)

checks :

  • check that at least one uniswap fee tier is set

  • check that tokens are not address(0)

  • check token0/token1 ordering

  • check that manager is not address(0)

  • check that init0 or init1 is greater than 0

events :

  • LogSetInits(uint256 init0, uint256 init1)

  • LogSetManager(address newManager)

  • LogAddPools(uint24[] feeTiers)

  • LogSetBurnBuffer(uint16 newBurnBuffer)

Inherited Standard Interfaces:

  • Ownable (transferOwnership)

  • ERC20 (transfer, approve, transferFrom, balanceOf etc)

Last updated