ArrakisPublicVaultRouter

Git Source

Inherits: IArrakisPublicVaultRouter, ReentrancyGuard, Ownable, Pausable

State Variables

nativeToken

address public immutable nativeToken;

permit2

IPermit2 public immutable permit2;

factory

IArrakisMetaVaultFactory public immutable factory;

weth

IWETH9 public immutable weth;

swapper

IRouterSwapExecutor public swapper;

Functions

onlyPublicVault

modifier onlyPublicVault(address vault_);

constructor

constructor(
    address nativeToken_,
    address permit2_,
    address owner_,
    address factory_,
    address weth_
);

pause

function used to pause the router.

only callable by owner

function pause() external onlyOwner;

unpause

function used to unpause the router.

only callable by owner

function unpause() external onlyOwner;

updateSwapExecutor

function updateSwapExecutor(address swapper_)
    external
    whenNotPaused
    onlyOwner;

addLiquidity

addLiquidity adds liquidity to meta vault of interest (mints L tokens)

function addLiquidity(AddLiquidityData memory params_)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.vault)
    returns (uint256 amount0, uint256 amount1, uint256 sharesReceived);

Parameters

NameTypeDescription
params_AddLiquidityDataAddLiquidityData struct containing data for adding liquidity

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver

swapAndAddLiquidity

swapAndAddLiquidity transfer tokens to and calls RouterSwapExecutor

function swapAndAddLiquidity(SwapAndAddData memory params_)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.addData.vault)
    returns (
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

Parameters

NameTypeDescription
params_SwapAndAddDataSwapAndAddData struct containing data for swap

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver
amount0Diffuint256token0 balance difference post swap
amount1Diffuint256token1 balance difference post swap

removeLiquidity

removeLiquidity removes liquidity from vault and burns LP tokens

function removeLiquidity(RemoveLiquidityData memory params_)
    external
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.vault)
    returns (uint256 amount0, uint256 amount1);

Parameters

NameTypeDescription
params_RemoveLiquidityDataRemoveLiquidityData struct containing data for withdrawals

Returns

NameTypeDescription
amount0uint256actual amount of token0 transferred to receiver for burning burnAmount
amount1uint256actual amount of token1 transferred to receiver for burning burnAmount

addLiquidityPermit2

addLiquidityPermit2 adds liquidity to public vault of interest (mints LP tokens)

function addLiquidityPermit2(AddLiquidityPermit2Data memory params_)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.addData.vault)
    returns (uint256 amount0, uint256 amount1, uint256 sharesReceived);

Parameters

NameTypeDescription
params_AddLiquidityPermit2DataAddLiquidityPermit2Data struct containing data for adding liquidity

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver

swapAndAddLiquidityPermit2

swapAndAddLiquidityPermit2 transfer tokens to and calls RouterSwapExecutor

function swapAndAddLiquidityPermit2(
    SwapAndAddPermit2Data memory params_
)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.swapAndAddData.addData.vault)
    returns (
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

Parameters

NameTypeDescription
params_SwapAndAddPermit2DataSwapAndAddPermit2Data struct containing data for swap

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver
amount0Diffuint256token0 balance difference post swap
amount1Diffuint256token1 balance difference post swap

removeLiquidityPermit2

removeLiquidityPermit2 removes liquidity from vault and burns LP tokens

function removeLiquidityPermit2(
    RemoveLiquidityPermit2Data memory params_
)
    external
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.removeData.vault)
    returns (uint256 amount0, uint256 amount1);

Parameters

NameTypeDescription
params_RemoveLiquidityPermit2DataRemoveLiquidityPermit2Data struct containing data for withdrawals

Returns

NameTypeDescription
amount0uint256actual amount of token0 transferred to receiver for burning burnAmount
amount1uint256actual amount of token1 transferred to receiver for burning burnAmount

wrapAndAddLiquidity

wrapAndAddLiquidity wrap eth and adds liquidity to meta vault of interest (mints L tokens)

function wrapAndAddLiquidity(AddLiquidityData memory params_)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.vault)
    returns (uint256 amount0, uint256 amount1, uint256 sharesReceived);

Parameters

NameTypeDescription
params_AddLiquidityDataAddLiquidityData struct containing data for adding liquidity

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver

wrapAndSwapAndAddLiquidity

wrapAndSwapAndAddLiquidity wrap eth and transfer tokens to and calls RouterSwapExecutor

function wrapAndSwapAndAddLiquidity(SwapAndAddData memory params_)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.addData.vault)
    returns (
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

Parameters

NameTypeDescription
params_SwapAndAddDataSwapAndAddData struct containing data for swap

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver
amount0Diffuint256token0 balance difference post swap
amount1Diffuint256token1 balance difference post swap

wrapAndAddLiquidityPermit2

wrapAndAddLiquidityPermit2 wrap eth and adds liquidity to public vault of interest (mints LP tokens)

hack to get rid of stack too depth

function wrapAndAddLiquidityPermit2(
    AddLiquidityPermit2Data memory params_
)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.addData.vault)
    returns (uint256 amount0, uint256 amount1, uint256 sharesReceived);

Parameters

NameTypeDescription
params_AddLiquidityPermit2DataAddLiquidityPermit2Data struct containing data for adding liquidity

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver

wrapAndSwapAndAddLiquidityPermit2

wrapAndSwapAndAddLiquidityPermit2 wrap eth and transfer tokens to and calls RouterSwapExecutor

function wrapAndSwapAndAddLiquidityPermit2(
    SwapAndAddPermit2Data memory params_
)
    external
    payable
    nonReentrant
    whenNotPaused
    onlyPublicVault(params_.swapAndAddData.addData.vault)
    returns (
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

Parameters

NameTypeDescription
params_SwapAndAddPermit2DataSwapAndAddPermit2Data struct containing data for swap

Returns

NameTypeDescription
amount0uint256amount of token0 transferred from msg.sender to mint mintAmount
amount1uint256amount of token1 transferred from msg.sender to mint mintAmount
sharesReceiveduint256amount of public vault tokens transferred to receiver
amount0Diffuint256token0 balance difference post swap
amount1Diffuint256token1 balance difference post swap

receive

hack to get rid of stack too depth

receive() external payable;

getMintAmounts

getMintAmounts used to get the shares we can mint from some max amounts.

function getMintAmounts(
    address vault_,
    uint256 maxAmount0_,
    uint256 maxAmount1_
)
    external
    view
    returns (
        uint256 shareToMint,
        uint256 amount0ToDeposit,
        uint256 amount1ToDeposit
    );

Parameters

NameTypeDescription
vault_addressmeta vault address.
maxAmount0_uint256maximum amount of token0 user want to contribute.
maxAmount1_uint256maximum amount of token1 user want to contribute.

Returns

NameTypeDescription
shareToMintuint256maximum amount of share user can get for 'maxAmount0*' and 'maxAmount1*'.
amount0ToDeposituint256amount of token0 user should deposit into the vault for minting 'shareToMint'.
amount1ToDeposituint256amount of token1 user should deposit into the vault for minting 'shareToMint'.

_addLiquidity

function _addLiquidity(
    address vault_,
    uint256 amount0_,
    uint256 amount1_,
    uint256 shares_,
    address receiver_,
    address token0_,
    address token1_
) internal;

_swapAndAddLiquidity

function _swapAndAddLiquidity(
    SwapAndAddData memory params_,
    address token0_,
    address token1_
)
    internal
    returns (
        uint256 amount0Use,
        uint256 amount1Use,
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

_swapAndAddLiquiditySendBackLeftOver

function _swapAndAddLiquiditySendBackLeftOver(
    SwapAndAddData memory params_,
    address token0_,
    address token1_
)
    internal
    returns (
        uint256 amount0,
        uint256 amount1,
        uint256 sharesReceived,
        uint256 amount0Diff,
        uint256 amount1Diff
    );

_removeLiquidity

function _removeLiquidity(RemoveLiquidityData memory params_)
    internal
    returns (uint256 amount0, uint256 amount1);

_permit2AddLengthOne

function _permit2AddLengthOne(
    AddLiquidityPermit2Data memory params_,
    address token0_,
    address token1_,
    uint256 amount0_,
    uint256 amount1_
) internal;

_permit2AddLengthOneOrTwo

function _permit2AddLengthOneOrTwo(
    AddLiquidityPermit2Data memory params_,
    address token0_,
    address token1_,
    uint256 amount0_,
    uint256 amount1_
) internal;

_permit2Add

function _permit2Add(
    uint256 permittedLength_,
    AddLiquidityPermit2Data memory params_,
    address token0_,
    address token1_,
    uint256 amount0_,
    uint256 amount1_
) internal;

_permit2SwapAndAddLengthOne

function _permit2SwapAndAddLengthOne(
    SwapAndAddPermit2Data memory params_,
    address token0_,
    address token1_
) internal;

_permit2SwapAndAddLengthOneOrTwo

function _permit2SwapAndAddLengthOneOrTwo(
    SwapAndAddPermit2Data memory params_,
    address token0_,
    address token1_
) internal;

_permit2SwapAndAdd

function _permit2SwapAndAdd(
    uint256 permittedLength_,
    SwapAndAddPermit2Data memory params_,
    address token0_,
    address token1_
) internal;

_getMintAmounts

function _getMintAmounts(
    address vault_,
    uint256 maxAmount0_,
    uint256 maxAmount1_
)
    internal
    view
    returns (
        uint256 shareToMint,
        uint256 amount0ToDeposit,
        uint256 amount1ToDeposit
    );