# PermissionedLendingPool

## PermissionedLendingPool

The `PermissionedLendingPool` contract is the main contract adding the "permissions" layer to Aave Arc. It exposes all the user-oriented actions that can be invoked using either Solidity or Web3 libraries.

The source code can be found on Github [here](https://github.com/aave/protocol-v2/blob/feat/permissioned-market/contracts/protocol/lendingpool/PermissionedLendingPool.sol).

{% hint style="info" %}
Pool methods `deposit`, `borrow`, `withdraw` and `repay` are only for ERC20. For ETH , use [PermissionedWETHGateway](https://aave-arc.gitbook.io/docs/contracts-interacting-with-protocol/permissionedwethgateway)
{% endhint %}

## Contract API reference

### Write Methods

#### **deposit()**

Allows [whitelisted depositors](https://aave-arc.gitbook.io/docs/permissionmanager#users) to deposit `amount` of an `asset` into the market, minting the same `amount` of corresponding aTokens, and transferring them to the `onBehalfOf` address.

{% hint style="info" %}
`OnBehalfOf` must be whitelisted for [`DEPOSITOR`](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.

`permissionAdmin` that whitelisted `onBehalfOf` must be still valid.
{% endhint %}

{% hint style="info" %}
When depositing, the `PermissionedLendingPool` contract must have `allowance`to spend funds on behalf of `msg.sender` at-least for `amount` of the `asset` being deposited. This can be done via the standard ERC20 `approve()` method.
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="10d456b1331445c4ab7f0d68c797e81b" label="address" color="blue"></option><option value="eca1c805462e4f2b9d35a7b53ebf23df" label="uint256" color="blue"></option><option value="2dc3c2d192d2400fa6e65338033860fa" label="uint16" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>asset</td><td><span data-option="10d456b1331445c4ab7f0d68c797e81b">address</span></td><td>address of the underlying asset</td></tr><tr><td>amount</td><td><span data-option="eca1c805462e4f2b9d35a7b53ebf23df">uint256</span></td><td>amount deposited, expressed in wei units</td></tr><tr><td>onBehalfOf</td><td><span data-option="10d456b1331445c4ab7f0d68c797e81b">address</span></td><td>address whom will receive the aTokens. Use msg.sender when the aTokens should be sent to the caller.</td></tr><tr><td>referralCode</td><td><span data-option="2dc3c2d192d2400fa6e65338033860fa">uint16</span></td><td>referral code for 3rd party referral program integration. Use 0 for no referral.</td></tr></tbody></table>

#### **withdraw()**

Allows [whitelisted depositors](https://www.notion.so/PermissionManager-0a65a35ef157405385beb75809ddd999) to withdraw `amount` of the underlying `asset`, i.e. burn aToken to redeem the underlying token.

{% hint style="info" %}
`msg.sender` must be whitelisted for [DEPOSITOR](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.
{% endhint %}

{% hint style="info" %}
When withdrawing `to` another address, `msg.sender`should have `aToken` that will be burned by lendingPool .
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="4236673fc20a4f1ea055f90688bf3311" label="address" color="blue"></option><option value="381fd83a05bf4f7f829650763bf1fe9e" label="uint256" color="blue"></option><option value="f9d184ab092042d3b16490162bc5843e" label="" color="blue"></option><option value="7db609310f0b444a9871d9cc533cc564" label="" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>asset</td><td><span data-option="4236673fc20a4f1ea055f90688bf3311">address</span></td><td>address of the underlying asset, not the aToken</td></tr><tr><td>amount</td><td><span data-option="381fd83a05bf4f7f829650763bf1fe9e">uint256</span></td><td>amount deposited, expressed in wei units. Use type(uint).max to withdraw the entire balance.</td></tr><tr><td>to</td><td><span data-option="4236673fc20a4f1ea055f90688bf3311">address</span></td><td>address that will receive the asset</td></tr></tbody></table>

#### borrow()

Allows [whitelisted Borrowers](https://aave-arc.gitbook.io/docs/permissionmanager#users) `amount` of `asset` with `interestRateMode`, sending the borrowed `amount` to `msg.sender` and the debt incurred by `onBehalfOf`.

{% hint style="info" %}
`msg.sender` and `onBehalfOf` must be whitelisted for [`BORROWER`](https://aave-arc.gitbook.io/docs/permissionmanager#users) role. `permissionAdmin` that whitelisted `onBehalfOf` must be still valid.
{% endhint %}

{% hint style="info" %}
`onBehalfOf` must have enough collateral supplied to the pool via deposit() or have delegated credit to `msg.sender` via [approveDelegation()](https://aave-arc.gitbook.io/docs/permissioned-debt-tokens#approving-delegation)
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="22250b30f22c42668bef62f4c1754229" label="address" color="blue"></option><option value="6f377c154465436c8b3762cc46283790" label="uint256" color="blue"></option><option value="dba86fc8fb354b8e94926696239e195e" label="uint16" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>asset</td><td><span data-option="22250b30f22c42668bef62f4c1754229">address</span></td><td>address of the underlying asset</td></tr><tr><td>amount</td><td><span data-option="6f377c154465436c8b3762cc46283790">uint256</span></td><td>amount to be borrowed, expressed in wei units</td></tr><tr><td>interestRateMode</td><td><span data-option="6f377c154465436c8b3762cc46283790">uint256</span></td><td>the type of borrow debt. Stable: 1, Variable: 2</td></tr><tr><td>referralCode</td><td><span data-option="dba86fc8fb354b8e94926696239e195e">uint16</span></td><td>referral code for our referral program. Use 0 for no referral code.</td></tr><tr><td>onBehalfOh</td><td><span data-option="22250b30f22c42668bef62f4c1754229">address</span></td><td>address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user.</td></tr></tbody></table>

#### repay()

Repays `onBehalfOf`'s debt`amount` of `asset` which has a `rateMode`.

{% hint style="info" %}
`OnBehalfOf` must be whitelisted for [BORROWER](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.

`permissionAdmin` that whitelisted `onBehalfOf` must be still valid.
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="26edf1bfeeaa4e1cb781dee91fc0c050" label="address" color="blue"></option><option value="08abf5dd02d04262880836c98589f9e6" label="uint256" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>asset</td><td><span data-option="26edf1bfeeaa4e1cb781dee91fc0c050">address</span></td><td>address of the underlying asset</td></tr><tr><td>amount</td><td><span data-option="08abf5dd02d04262880836c98589f9e6">uint256</span></td><td>amount to be borrowed, expressed in wei units. Use uint(-1) to repay the entire debt,  ONLY when the repayment is not executed on behalf of a 3rd party.  In case of repayments on behalf of another user, it's recommended to send an _amount slightly higher than the current borrowed amount.</td></tr><tr><td>rateMode</td><td><span data-option="08abf5dd02d04262880836c98589f9e6">uint256</span></td><td>the type of borrow debt. Stable: 1, Variable: 2</td></tr><tr><td>onBehalfOf</td><td><span data-option="26edf1bfeeaa4e1cb781dee91fc0c050">address</span></td><td>address of user who will incur the debt. Use msg.sender when not calling on behalf of a different user.</td></tr></tbody></table>

#### swapBorrowRateMode()

Swaps the `msg.sender`'s borrow rate modes between stable and variable.

{% hint style="info" %}
`msg.sender` must be whitelisted for [BORROWER](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.

`permissionAdmin` that whitelisted `msg.sender` must be still valid.
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="cb9ac3d4a02147c6b40d839a82255379" label="address" color="blue"></option><option value="56b5217aa8044770a8daec97aa51ed84" label="uint256" color="blue"></option></select></th><th></th></tr></thead><tbody><tr><td>asset</td><td><span data-option="cb9ac3d4a02147c6b40d839a82255379">address</span></td><td>address of the underlying asset</td></tr><tr><td>rateMode</td><td><span data-option="56b5217aa8044770a8daec97aa51ed84">uint256</span></td><td>the rate mode the user is swapping from. Stable: 1, Variable: 2</td></tr></tbody></table>

#### setUserUseReserveAsCollateral()

Sets the `asset` of `msg.sender` to be used as collateral or not.

{% hint style="info" %}
`msg.sender` must be whitelisted for [DEPOSITOR](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.

`permissionAdmin` that whitelisted `msg.sender` must be still valid.
{% endhint %}

<table><thead><tr><th>Params</th><th>Type<select><option value="f7dcf9dc706044ac90bc0b628b378c37" label="address" color="blue"></option><option value="ecb7d74c760545fa991054c9265523f0" label="bool" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>asset</td><td><span data-option="f7dcf9dc706044ac90bc0b628b378c37">address</span></td><td>address of the underlying asset</td></tr><tr><td>useAsCollateral</td><td><span data-option="ecb7d74c760545fa991054c9265523f0">bool</span></td><td><code>true</code> if the asset should be used as collateral</td></tr></tbody></table>

#### liquidationCall()

Allows, whitelisted liquidators to liquidate positions with health factor below 1.

{% hint style="info" %}
`msg.sender` must be whitelisted for [LIQUIDATOR](https://aave-arc.gitbook.io/docs/permissionmanager#users) role.

`permissionAdmin` that whitelisted `msg.sender` must be still valid.
{% endhint %}

Also, see our [Liquidations guide](https://docs.aave.com/developers/guides/liquidations) and [LendingPool liquidationCall](https://docs.aave.com/developers/the-core-protocol/lendingpool#liquidationcall) for more details.

## Error Codes

In order to reduce gas usage and code size, Aave contracts return numbered errors. If you are making calls to the protocol and receive numbered errors, you can use our [error code reference guide](https://docs.aave.com/developers/guides/troubleshooting-errors#error-codes) to know what the error number means. Alternatively, you can also find what the numbers represent by checking the [Errors.sol](https://github.com/aave/protocol-v2/blob/master/contracts/protocol/libraries/helpers/Errors.sol)
