> For the complete documentation index, see [llms.txt](https://dev.init.capital/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.init.capital/contract-references/posmanager.md).

# PosManager

Position manager is responsible for managing individual positions, including debt shares and collaterals.&#x20;

## View Functions

### nextNonces

Get a user's next nonce for calculating the creation of position id.

```solidity
function nextNonces(address _user) external view returns (uint256 nonce);
```

### core

InitCore contract address.

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

### maxCollCount

Max collateral count allowed.

```solidity
function maxCollCount() external view returns (uint8 count);
```

### pendingRewards

Position's pending reward token amounts.

```solidity
function pendingRewards(uint256 _posId, address _rewardToken) external view returns (uint256 rewardAmount);
```

### isCollateralized

Get whether the wrapped LP token id is already collateralized to the position.

```solidity
function isCollateralized(address _wLp, uint _tokenId) external view returns (bool collateralized);
```

### getPosBorrInfo

Get a position's borrow information.

```solidity
function getPosBorrInfo(uint _posId) external view returns (address[] memory pools, uint[] memory debtShares);
```

Parameters:

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `_posId` | `uint256` | position id to get borrow info |

Returns:

| Name         | Type        | Description                                                    |
| ------------ | ----------- | -------------------------------------------------------------- |
| `pools`      | `address[]` | array of lending pool addresses that the position borrows from |
| `debtShares` | `uint256[]` | array of debt shares of each borrow token                      |

### getPosBorrExtraInfo

Get a position's borrow extra information.&#x20;

{% hint style="warning" %}
`totalInterest` may not be exact. Use with caution.
{% endhint %}

```solidity
function getPosBorrExtraInfo(uint _posId, address _pool) external view returns (uint totalInterest, uint lastDebtAmt);
```

Parameters:

| Name     | Type      | Description                                   |
| -------- | --------- | --------------------------------------------- |
| `_posId` | `uint256` | position id to get borrow extra info          |
| `_pool`  | `address` | lending pool address to get borrow extra info |

Returns:

| Name            | Type      | Description                                                      |
| --------------- | --------- | ---------------------------------------------------------------- |
| `totalInterest` | `uint256` | total interest that the lending pool has accrued borrow interest |
| `lastDebtAmt`   | `uint256` | the last known debt amount                                       |

### getPosCollInfo

Get a position's collateral information.

```solidity
function getPosCollInfo(uint _posId) external view returns (address[] memory pools, uint[] memory amts, address[] memory wLps, uint[][] memory ids, uint[][] memory wLpAmts);
```

Parameters:

| Name     | Type      | Description                        |
| -------- | --------- | ---------------------------------- |
| `_posId` | `uint256` | position id to get collateral info |

Returns:

| Name      | Type          | Description                                                     |
| --------- | ------------- | --------------------------------------------------------------- |
| `pools`   | `address[]`   | array of lending addresses that the position puts as collateral |
| `amts`    | `uint256[]`   | array of lending pool collateralization amounts                 |
| `wLps`    | `address[]`   | array of wrapped LP addresses                                   |
| `ids`     | `uint256[][]` | array of array of wrapped LP's token ids                        |
| `wLpAmts` | `uint256[][]` | array of array of wrapped LP's token amount for each token id   |

### getCollAmt

Get a position's collateral amount of the specified lending pool.

```solidity
function getCollAmt(uint _posId, address _pool) external view returns (uint amt);
```

Parameters:

| Name     | Type      | Description                           |
| -------- | --------- | ------------------------------------- |
| `_posId` | `uint256` | position id to get collateral amount  |
| `_pool`  | `address` | lending pool to get collateral amount |

Returns:

| Name  | Type      | Description       |
| ----- | --------- | ----------------- |
| `amt` | `uint256` | collateral amount |

### getCollWLpAmt

Get a position's collateral amount of the specified wrapped LP.

```solidity
function getCollWLpAmt(uint _posId, address _wLp, uint _tokenId) external view returns (uint amt);
```

&#x20;Parameters:

| Name       | Type      | Description                                          |
| ---------- | --------- | ---------------------------------------------------- |
| `_posId`   | `uint256` | position id to get collateral wLp amount             |
| `_wLp`     | `address` | wrapped LP contract address to get collateral amount |
| `_tokenId` | `uint256` | wrapped LP token id to get collateral amount         |

Returns:

| Name  | Type      | Description       |
| ----- | --------- | ----------------- |
| `amt` | `uint256` | collateral amount |

### getPosCollCount

Get a position's collateral count of a given position id.&#x20;

{% hint style="info" %}
This count does not include wLp collaterals.
{% endhint %}

```solidity
function getPosCollCount(uint _posId) external view returns (uint8 count);
```

Parameters:

| Name     | Type      | Description                         |
| -------- | --------- | ----------------------------------- |
| `_posId` | `uint256` | position id to get collateral count |

Returns:

| Name    | Type    | Description      |
| ------- | ------- | ---------------- |
| `count` | `uint8` | collateral count |

### getPosCollWLpCount

Get a position's wrapped LP collateral count of a given position id.&#x20;

{% hint style="info" %}
This count does not include regular lending pool collaterals.
{% endhint %}

```solidity
function getPosCollWLpCount(uint _posId) external view returns (uint8 count);
```

Parameters:

| Name     | Type      | Description                             |
| -------- | --------- | --------------------------------------- |
| `_posId` | `uint256` | position id to get wLp collateral count |

Returns:

| Name    | Type    | Description      |
| ------- | ------- | ---------------- |
| `count` | `uint8` | collateral count |

### getPosInfo

Get a position's general information.

{% hint style="info" %}
If the position does not exist, the viewer will be `address(0)` and mode will be 0.
{% endhint %}

```solidity
function getPosInfo(uint _posId) external view returns (address viewer, uint16 mode);
```

Parameters:

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `_posId` | `uint256` | position id to get information |

Returns:

| Name     | Type      | Description                    |
| -------- | --------- | ------------------------------ |
| `viewer` | `address` | viewer address of the position |
| `mode`   | `uint16`  | position's current mode        |

### getPosMode

Get a position's mode.

{% hint style="info" %}
If a position does not exist, the mode will be 0.
{% endhint %}

```solidity
function getPosMode(uint _posId) external view returns (uint16 mode);
```

Parameters:

| Name     | Type      | Description             |
| -------- | --------- | ----------------------- |
| `_posId` | `uint256` | position id to get mode |

Returns:

| Name   | Type     | Description   |
| ------ | -------- | ------------- |
| `mode` | `uint16` | position mode |

### getPosDebtShares

Get a position's debt shares (without borrow interest accrual).

```solidity
function getPosDebtShares(uint _posId, address _pool) external view returns (uint debtShares);
```

Parameters:

| Name     | Type      | Description                                |
| -------- | --------- | ------------------------------------------ |
| `_posId` | `uint256` | position id to get debt shares information |
| `_pool`  | `address` | lending pool address to get debt shares of |

Returns:

| Name         | Type      | Description                              |
| ------------ | --------- | ---------------------------------------- |
| `debtShares` | `uint256` | lending pool debt shares of the position |

### getViewerPosIdsAt

Get a reverse-mapping lookup for the specified viewer address and the array index.

{% hint style="info" %}
If the index can be out-of-bounds if it exceeds the array length.
{% endhint %}

```solidity
function getViewerPosIdsAt(address _viewer, uint _index) external view returns (uint posId);
```

Parameters:

| Name      | Type      | Description                       |
| --------- | --------- | --------------------------------- |
| `_viewer` | `address` | viewer address to get position id |
| `_index`  | `uint256` | array index to query              |

Returns:

| Name    | Type      | Description |
| ------- | --------- | ----------- |
| `posId` | `uint256` | position id |

### getViewerPosIdsLength

Get a reverse-mapping lookup array length for the specified viewer address.

```solidity
function getViewerPosIdsLength(address _viewer) external view returns (uint length);
```

Parameters:

| Name      | Type      | Description                             |
| --------- | --------- | --------------------------------------- |
| `_viewer` | `address` | viewer address to get position id count |

Returns:

| Name     | Type      | Description                                   |
| -------- | --------- | --------------------------------------------- |
| `length` | `uint256` | position id count corresponding to the viewer |

### isAuthorized

Check whether the account is authorized for modifying the position.

```solidity
function isAuthorized(address _account, uint _posId) external view returns (bool);
```

Parameters:

| Name       | Type      | Description                        |
| ---------- | --------- | ---------------------------------- |
| `_account` | `address` | address to check authorization     |
| `_posId`   | `uint256` | position id to check authorization |

Returns:

| Name           | Type   | Description                                                 |
| -------------- | ------ | ----------------------------------------------------------- |
| `isAuthorized` | `bool` | whether the account is authorized to modify the position id |

## External Functions

### harvestTo

Harvest reward tokens of the specified wrapped LP to the target address.&#x20;

{% hint style="info" %}
Can only be called by an authorized party of the position.
{% endhint %}

```solidity
function harvestTo(uint _posId, address _wLp, uint _tokenId, address _to) external returns (address[] memory tokens, uint[] memory amts);
```

Parameters:

| Name       | Type      | Description                                    |
| ---------- | --------- | ---------------------------------------------- |
| `_posId`   | `uint256` | position id to harvest rewards from            |
| `_wLp`     | `address` | wrapped LP contract address to harvest rewards |
| `_tokenId` | `uint256` | wrapped LP token id to harvest rewards         |
| `_to`      | `address` | address to receive the reward tokens           |

Returns:

| Name     | Type        | Description                               |
| -------- | ----------- | ----------------------------------------- |
| `tokens` | `address[]` | array of reward token addresses           |
| `amts`   | `uint256[]` | array of reward token amounts transferred |

### claimPendingRewards

Claim pending reward tokens from the position.

{% hint style="info" %}
This function is intended to be called in cases when the position gets liquidated, and reward tokens get accrued in the position.
{% endhint %}

```solidity
function claimPendingRewards(uint _posId, address[] calldata _tokens, address _to) external returns (uint[] memory amts);
```

Parameters:

| Name      | Type        | Description                          |
| --------- | ----------- | ------------------------------------ |
| `_posId`  | `uint256`   | position id to claim pending rewards |
| `_tokens` | `address[]` | array of reward tokens to claim      |
| `_to`     | `address`   | address to receive the reward tokens |

Returns:

| Name   | Type        | Description                   |
| ------ | ----------- | ----------------------------- |
| `amts` | `uint256[]` | array of reward token amounts |

### setPosViewer

Set a new viewer to the position.

{% hint style="info" %}
Can only be called by an authorized party of the position.
{% endhint %}

```solidity
function setPosViewer(uint _posId, address _viewer) external;
```

Parameters:

| Name      | Type      | Description                           |
| --------- | --------- | ------------------------------------- |
| `_posId`  | `uint256` | position id to set new viewer address |
| `_viewer` | `address` | new viewer address to set             |
