UniV4StandardModule

Git Source

Inherits: ReentrancyGuardUpgradeable, PausableUpgradeable, IArrakisLPModule, IArrakisLPModuleID, IUniV4StandardModule, IUnlockCallback

this module can only set uni v4 pool that have generic hook, that don't require specific action to become liquidity provider.

due to native coin standard difference between uni V4 and arrakis, we are assuming that all inputed amounts are using arrakis vault token0/token1 as reference. Internal logic of UniV4StandardModule will handle the conversion or use the poolKey to interact with the poolManager.

State Variables

poolManager

function used to get the uniswap v4 pool manager.

IPoolManager public immutable poolManager;

_guardian

address internal immutable _guardian;

metaVault

module's metaVault as IArrakisMetaVault.

IArrakisMetaVault public metaVault;

token0

module's token0 as IERC20Metadata.

IERC20Metadata public token0;

token1

module's token1 as IERC20Metadata.

IERC20Metadata public token1;

isInversed

boolean to know if the poolKey's currencies pair are inversed.

bool public isInversed;

managerFeePIPS

manager fees share.

uint256 public managerFeePIPS;

oracle

oracle that will be used to proctect rebalances against attacks.

IOracleWrapper public oracle;

maxSlippage

max slippage that can occur during swap rebalance.

uint24 public maxSlippage;

poolKey

pool's key of the module.

PoolKey public poolKey;

ethWithdrawers

list of allowed addresses to withdraw eth.

mapping(address => uint256) public ethWithdrawers;

_init0

uint256 internal _init0;

_init1

uint256 internal _init1;

_ranges

Range[] internal _ranges;

_activeRanges

mapping(bytes32 => bool) internal _activeRanges;

Functions

onlyManager

modifier onlyManager();

onlyMetaVault

modifier onlyMetaVault();

onlyGuardian

modifier onlyGuardian();

constructor

constructor(address poolManager_, address guardian_);

pause

function used to pause the module.

only callable by guardian

function pause() external whenNotPaused onlyGuardian;

unpause

function used to unpause the module.

only callable by guardian

function unpause() external whenPaused onlyGuardian;

initialize

initialize function to delegate call onced the beacon proxy is deployed, for initializing the uniswap v4 standard module.

function initialize(
    uint256 init0_,
    uint256 init1_,
    bool isInversed_,
    PoolKey calldata poolKey_,
    IOracleWrapper oracle_,
    uint24 maxSlippage_,
    address metaVault_
) external initializer;

Parameters

NameTypeDescription
init0_uint256initial amount of token0 to provide to uniswap standard module.
init1_uint256initial amount of token1 to provide to uniswap standard module.
isInversed_boolboolean to check if the poolKey's currencies pair are inversed, compared to the module's tokens pair.
poolKey_PoolKeypool key of the uniswap v4 pool that will be used by the module.
oracle_IOracleWrapperaddress of the oracle used by the uniswap v4 standard module.
maxSlippage_uint24allowed to manager for rebalancing the inventory using swap.
metaVault_addressaddress of the meta vault.

initializePosition

function used to initialize the module when a module switch happen

check if the pool is initialized.

function initializePosition(
    bytes calldata
) external virtual onlyMetaVault;

withdrawEth

left over will sit on the module.

function withdrawEth(
    uint256 amount_
) external nonReentrant whenNotPaused;

approve

function approve(
    address spender_,
    uint256 amount0_,
    uint256 amount1_
) external nonReentrant whenNotPaused;

setPool

function used to set the pool for the module.

function setPool(
    PoolKey calldata poolKey_,
    LiquidityRange[] calldata liquidityRanges_,
    SwapPayload calldata swapPayload_,
    uint256 minBurn0_,
    uint256 minBurn1_,
    uint256 minDeposit0_,
    uint256 minDeposit1_
) external onlyManager nonReentrant whenNotPaused;

Parameters

NameTypeDescription
poolKey_PoolKeypool key of the uniswap v4 pool that will be used by the module.
liquidityRanges_LiquidityRange[]list of liquidity ranges to be used by the module on the new pool.
swapPayload_SwapPayloadswap payload to be used during rebalance.
minBurn0_uint256minimum amount of token0 to burn.
minBurn1_uint256minimum amount of token1 to burn.
minDeposit0_uint256minimum amount of token0 to deposit.
minDeposit1_uint256minimum amount of token1 to deposit.

withdraw

function used by metaVault to withdraw tokens from the strategy.

check if the pool is initialized.

function withdraw(
    address receiver_,
    uint256 proportion_
)
    public
    virtual
    onlyMetaVault
    nonReentrant
    returns (uint256 amount0, uint256 amount1);

Parameters

NameTypeDescription
receiver_addressaddress that will receive tokens.
proportion_uint256number of share needed to be withdrawn.

Returns

NameTypeDescription
amount0uint256amount of token0 withdrawn.
amount1uint256amount of token1 withdrawn.

rebalance

function used to rebalance the inventory of the module.

function rebalance(
    LiquidityRange[] memory liquidityRanges_,
    SwapPayload memory swapPayload_,
    uint256 minBurn0_,
    uint256 minBurn1_,
    uint256 minDeposit0_,
    uint256 minDeposit1_
)
    public
    onlyManager
    nonReentrant
    whenNotPaused
    returns (
        uint256 amount0Minted,
        uint256 amount1Minted,
        uint256 amount0Burned,
        uint256 amount1Burned
    );

Parameters

NameTypeDescription
liquidityRanges_LiquidityRange[]list of liquidity ranges to be used by the module.
swapPayload_SwapPayloadswap payload to be used during rebalance..
minBurn0_uint256minimum amount of token0 to burn.
minBurn1_uint256minimum amount of token1 to burn.
minDeposit0_uint256minimum amount of token0 to deposit.
minDeposit1_uint256minimum amount of token1 to deposit.

Returns

NameTypeDescription
amount0Minteduint256amount of token0 minted.
amount1Minteduint256amount of token1 minted.
amount0Burneduint256amount of token0 burned.
amount1Burneduint256amount of token1 burned.

withdrawManagerBalance

function used by metaVault or manager to get manager fees.

function withdrawManagerBalance()
    public
    nonReentrant
    whenNotPaused
    returns (uint256 amount0, uint256 amount1);

Returns

NameTypeDescription
amount0uint256amount of token0 sent to manager.
amount1uint256amount of token1 sent to manager.

setManagerFeePIPS

function used to set manager fees.

default swapPayload, no swap happens here. swapPayload will be empty. And will use it to do rebalance and collect fees.

function setManagerFeePIPS(
    uint256 newFeePIPS_
) external onlyManager whenNotPaused;

Parameters

NameTypeDescription
newFeePIPS_uint256new fee that will be applied.

receive

receive() external payable;

guardian

function used to get the address that can pause the module.

function guardian() external view returns (address);

Returns

NameTypeDescription
<none>addressguardian address of the pauser.

getRanges

function used to get the list of active ranges.

function getRanges() external view returns (Range[] memory ranges);

Returns

NameTypeDescription
rangesRange[]active ranges

getInits

function used to get the initial amounts needed to open a position.

function getInits()
    external
    view
    returns (uint256 init0, uint256 init1);

Returns

NameTypeDescription
init0uint256the amount of token0 needed to open a position.
init1uint256the amount of token1 needed to open a position.

totalUnderlying

function used to get the amount of token0 and token1 sitting on the position.

function totalUnderlying()
    external
    view
    returns (uint256 amount0, uint256 amount1);

Returns

NameTypeDescription
amount0uint256the amount of token0 sitting on the position.
amount1uint256the amount of token1 sitting on the position.

totalUnderlyingAtPrice

function used to get the amounts of token0 and token1 sitting on the position for a specific price.

function totalUnderlyingAtPrice(
    uint160 priceX96_
) external view returns (uint256 amount0, uint256 amount1);

Parameters

NameTypeDescription
priceX96_uint160price at which we want to simulate our tokens composition

Returns

NameTypeDescription
amount0uint256the amount of token0 sitting on the position for priceX96.
amount1uint256the amount of token1 sitting on the position for priceX96.

validateRebalance

function used to validate if module state is not manipulated before rebalance.

function validateRebalance(
    IOracleWrapper oracle_,
    uint24 maxDeviation_
) external view;

Parameters

NameTypeDescription
oracle_IOracleWrapperoracle that will used to check internal state.
maxDeviation_uint24maximum deviation allowed. rebalance can happen.

managerBalance0

function used to get manager token0 balance.

amount of fees in token0 that manager have not taken yet.

function managerBalance0()
    external
    view
    returns (uint256 managerFee0);

Returns

NameTypeDescription
managerFee0uint256amount of token0 that manager earned.

managerBalance1

function used to get manager token1 balance.

amount of fees in token1 that manager have not taken yet.

function managerBalance1()
    external
    view
    returns (uint256 managerFee1);

Returns

NameTypeDescription
managerFee1uint256amount of token1 that manager earned.

_unlockCallback

function _unlockCallback(
    Action action_,
    bytes memory data_
) internal returns (bytes memory);

_internalRebalance

function _internalRebalance(
    LiquidityRange[] memory liquidityRanges_,
    SwapPayload memory swapPayload_
)
    internal
    returns (
        uint256 amount0Minted,
        uint256 amount1Minted,
        uint256 amount0Burned,
        uint256 amount1Burned
    );

Enums

Action

enum Action {
    WITHDRAW,
    REBALANCE,
    DEPOSIT_FUND
}