MoneyMarketHook

View Functions

CORE

InitCore contract address.

function CORE() external view returns (address initCore);

POS_MANAGER

PosManager contract address.

function POS_MANAGER() external view returns (address posManager);

lastPosIds

Last opened position id (increasing from 0) of a user.

function lastPosIds(address _user) external view returns (uint256 lastPosId);

initPosIds

Mapped user's position id on money market hook to InitCore's position id.

function initPosIds(address _user, uint256 _posId) external view returns (uint256 initPosId);

External Functions

execute

Main function to interact with the contract to handle interactions to InitCore.

The function:

  1. Create a position, if not existed

  2. Perform multicall to InitCore, which performs:

    1. Decollateralize inToken from the position and redeem token in lending pool

    2. Withdraw from lending pool

    3. Change position mode, if specified

    4. Borrow tokens from lending pool

    5. Mint inToken from lending pool and collateralize to the position

  3. Unwrap rebase tokens, if specified

  4. Unwrap wrapped native token to native token, if specified

function execute(OperationParams calldata _params) external payable returns (uint256 posId, uint256 initPosId, bytes[] memory results);
struct RebaseHelperParams {
    address helper; // wrap helper address if address(0) then not wrap
    address tokenIn; // token to use in rebase helper
}

// NOTE: there is 3 types of deposit
// 1. deposit native token use msg.value for native token
// if amt > 0 mean user want to use wNative too
// 2. wrap rebase token to non-rebase token and deposit (using rebase helper)
// 3. deposit normal erc20 token
struct DepositParams {
    address pool; // lending pool to deposit
    uint amt; // token amount to deposit
    RebaseHelperParams rebaseHelperParams; // wrap params
}

struct WithdrawParams {
    address pool; // lending pool to withdraw
    uint shares; // shares to withdraw
    RebaseHelperParams rebaseHelperParams; // wrap params
    address to; // receiver to receive withdraw tokens
}

struct RepayParams {
    address pool; // lending pool to repay
    uint shares; // shares to repay
}

struct BorrowParams {
    address pool; // lending pool to borrow
    uint amt; // token amount to borrow
    address to; // receiver to receive borrow tokens
}

struct OperationParams {
    uint posId; //  position id to execute (0 to create new position)
    address viewer; // address to view position
    uint16 mode; // position mode to be used
    DepositParams[] depositParams; // deposit parameters
    WithdrawParams[] withdrawParams; // withdraw parameters
    BorrowParams[] borrowParams; // borrow parameters
    RepayParams[] repayParams; // repay parameters
    uint minHealth_e18; // minimum health to maintain after execute
    bool returnNative; // return native token or not (using balanceOf(address(this)))
}

Parameters:

NameTypeDescription

_params

OperationParams

parameters to execute the fucntion

Returns:

NameTypeDescription

posId

uint256

running position id (per each user) on money market hook

initPosId

uint256

position id on InitCore

results[]

bytes

results of multicall to InitCore

Last updated