# MoneyMarketHook

## View Functions

### CORE

InitCore contract address.

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

### POS\_MANAGER

PosManager contract address.

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

### lastPosIds

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

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

### initPosIds

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

```solidity
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.&#x20;

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

```solidity
function execute(OperationParams calldata _params) external payable returns (uint256 posId, uint256 initPosId, bytes[] memory results);
```

```solidity
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:

| Name      | Type              | Description                        |
| --------- | ----------------- | ---------------------------------- |
| `_params` | `OperationParams` | parameters to execute the fucntion |

Returns:

| Name        | Type      | Description                                              |
| ----------- | --------- | -------------------------------------------------------- |
| `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                         |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.init.capital/contract-references/moneymarkethook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
