ValantisModule

Git Source

Inherits: IArrakisLPModule, IValantisHOTModule, PausableUpgradeable, ReentrancyGuardUpgradeable

BeaconProxy be careful for changing implementation with upgrade.

State Variables

metaVault

IArrakisMetaVault public metaVault;

pool

ISovereignPool public pool;

alm

IHOT public alm;

token0

IERC20Metadata public token0;

token1

IERC20Metadata public token1;

maxSlippage

should we change it to mutable state variable, and settable by who?

uint24 public maxSlippage;

oracle

IOracleWrapper public oracle;

_guardian

address internal immutable _guardian;

_init0

uint256 internal _init0;

_init1

uint256 internal _init1;

_managerFeePIPS

uint256 internal _managerFeePIPS;

Functions

onlyMetaVault

modifier onlyMetaVault();

onlyManager

modifier onlyManager();

onlyGuardian

modifier onlyGuardian();

constructor

constructor(address guardian_);

initialize

initialize function to delegate call onced the beacon proxy is deployed, for initializing the valantis module. who can call deposit and withdraw functions.

function initialize(
    address pool_,
    uint256 init0_,
    uint256 init1_,
    uint24 maxSlippage_,
    address metaVault_
) external initializer;

Parameters

NameTypeDescription
pool_addressaddress of the valantis sovereign pool.
init0_uint256initial amount of token0 to provide to valantis module.
init1_uint256initial amount of token1 to provide to valantis 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

function initializePosition(bytes calldata data_)
    external
    virtual
    onlyMetaVault;

Parameters

NameTypeDescription
data_bytesbytes that contain information to initialize the position.

pause

function used to pause the module.

only callable by guardian

function pause() external onlyGuardian;

unpause

function used to unpause the module.

only callable by guardian

function unpause() external onlyGuardian;

setALMAndManagerFees

set HOT, oracle (wrapper of HOT) and init manager fees function.

function setALMAndManagerFees(
    address alm_,
    address oracle_
) external;

Parameters

NameTypeDescription
alm_addressaddress of the valantis HOT ALM.
oracle_addressaddress of the oracle used by the valantis HOT module.

withdraw

function used by metaVault to withdraw tokens from the strategy.

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

Parameters

NameTypeDescription
receiver_addressaddress that will receive tokens.
proportion_uint256the proportion of the total position that need to be withdrawn.

Returns

NameTypeDescription
amount0uint256amount of token0 withdrawn.
amount1uint256amount of token1 withdrawn.

withdrawManagerBalance

function used by metaVault or manager to get manager fees.

function withdrawManagerBalance()
    external
    whenNotPaused
    nonReentrant
    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.

function setManagerFeePIPS(uint256 newFeePIPS_)
    external
    whenNotPaused
    onlyManager;

Parameters

NameTypeDescription
newFeePIPS_uint256new fee that will be applied.

setPriceBounds

fucntion used to set range on valantis AMM

function setPriceBounds(
    uint160 sqrtPriceLowX96_,
    uint160 sqrtPriceHighX96_,
    uint160 expectedSqrtSpotPriceUpperX96_,
    uint160 expectedSqrtSpotPriceLowerX96_
) external onlyManager;

Parameters

NameTypeDescription
sqrtPriceLowX96_uint160lower bound of the range in sqrt price.
sqrtPriceHighX96_uint160upper bound of the range in sqrt price.
expectedSqrtSpotPriceUpperX96_uint160expected lower limit of current spot price (to prevent sandwich attack and manipulation).
expectedSqrtSpotPriceLowerX96_uint160expected upper limit of current spot price (to prevent sandwich attack and manipulation).

swap

function to swap token0->token1 or token1->token0 and then change inventory.

function swap(
    bool zeroForOne_,
    uint256 expectedMinReturn_,
    uint256 amountIn_,
    address router_,
    uint160 expectedSqrtSpotPriceUpperX96_,
    uint160 expectedSqrtSpotPriceLowerX96_,
    bytes calldata payload_
) external onlyManager whenNotPaused;

Parameters

NameTypeDescription
zeroForOne_boolboolean if true token0->token1, if false token1->token0.
expectedMinReturn_uint256minimum amount of tokenOut expected.
amountIn_uint256amount of tokenIn used during swap.
router_addressaddress of smart contract that will execute swap.
expectedSqrtSpotPriceUpperX96_uint160upper bound of current price.
expectedSqrtSpotPriceLowerX96_uint160lower bound of current price.
payload_bytesdata payload used for swapping.

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 fees0);

Returns

NameTypeDescription
fees0uint256amount 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 fees1);

Returns

NameTypeDescription
fees1uint256amount of token1 that manager earned.

validateRebalance

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

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

Parameters

NameTypeDescription
oracle_IOracleWrapperonchain oracle to check the current amm price against.
maxDeviation_uint24maximum deviation tolerated by management.

managerFeePIPS

function used to get manager fees.

function managerFeePIPS() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256managerFeePIPS amount of token1 that manager earned.

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, uint256);

Returns

NameTypeDescription
<none>uint256amount0 the amount of token0 sitting on the position.
<none>uint256amount1 the 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, uint256);

Parameters

NameTypeDescription
priceX96_uint160price at which we want to simulate our tokens composition

Returns

NameTypeDescription
<none>uint256amount0 the amount of token0 sitting on the position for priceX96.
<none>uint256amount1 the amount of token1 sitting on the position for priceX96.

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.

_initializePosition

function _initializePosition() internal;

_checkMinReturn

function _checkMinReturn(
    bool zeroForOne_,
    uint256 expectedMinReturn_,
    uint256 amountIn_,
    uint8 decimals0_,
    uint8 decimals1_
) internal view;