# Interactions

The **pTokens** contract handles core asset management operations such as supplying, borrowing, repaying, withdrawing, and liquidating. These functions form the backbone of user interaction with the lending protocol.

#### **deposit**

Supply assets to receive pTokens representing your share in the liquidity pool.

The sender supplies assets into the market, and in return, the minter receives pTokens as a representation of their deposit.

```solidity
function deposit(uint256 mintAmount, address receiver)
    external
    returns (uint256);
```

| **Name**     | **Type**  | **Description**                              |
| ------------ | --------- | -------------------------------------------- |
| `mintAmount` | `uint256` | The amount of the underlying asset to supply |
| `receiver`   | `address` | User whom the supply will be attributed to   |

User whom the supply will be attributed to

**Returns**

| **Name** | **Type**  | **Description**         |
| -------- | --------- | ----------------------- |
| `none`   | `uint256` | amount of minted tokens |

#### **borrow**

Borrow assets against your collateral.

Sender borrows assets from the protocol to their own address

```solidity
function borrow(uint256 borrowAmount) external;
```

**Parameters**

| **Name**       | **Type**  | **Description**                              |
| -------------- | --------- | -------------------------------------------- |
| `borrowAmount` | `uint256` | The amount of the underlying asset to borrow |

#### **repayBorrow**

Repay borrowed assets to reduce your outstanding debt.

Sender repays their own borrow

```solidity
function repayBorrow(uint256 repayAmount) external;
```

**Parameters**

| **Name**      | **Type**  | **Description**                                                           |
| ------------- | --------- | ------------------------------------------------------------------------- |
| `repayAmount` | `uint256` | The amount to repay, or type(uint256).max for the full outstanding amount |

#### **withdraw**

Sender redeems pTokens in exchange for a specified amount of underlying asset

*Accrues interest whether or not the operation succeeds, unless reverted*

```solidity
function withdraw(uint256 redeemAmount, address receiver, address owner)
    external
    returns (uint256);
```

**Parameters**

| **Name**       | **Type**  | **Description**                                  |
| -------------- | --------- | ------------------------------------------------ |
| `redeemAmount` | `uint256` | The amount of underlying to redeem               |
| `receiver`     | `address` | The address to receive underlying redeemed asset |
| `owner`        | `address` | The address which account for redeem tokens      |

**Returns**

| **Name** | **Type**  | **Description**        |
| -------- | --------- | ---------------------- |
| `none`   | `uint256` | amount of burnt tokens |

#### **mint**

Similar to `deposit`, but lets you specify the amount of pTokens to mint.

The sender supplies assets into the market and receives pTokens in exchange

```solidity
function mint(uint256 tokenAmount, address receiver)
    external
    returns (uint256);
```

**Parameters**

| **Name**      | **Type**  | **Description**                            |
| ------------- | --------- | ------------------------------------------ |
| `tokenAmount` | `uint256` | The amount of token to mint for supply     |
| `receiver`    | `address` | User whom the supply will be attributed to |

**Returns**

| **Name**       | **Type**  | **Description**                     |
| -------------- | --------- | ----------------------------------- |
| `&lt;none&gt;` | `uint256` | amount of supplied underlying asset |

#### **redeem**

The sender redeems pTokens in exchange for the underlying asset

```solidity
function redeem(uint256 redeemTokens, address receiver, address owner)
    external
    returns (uint256);
```

**Parameters**

| **Name**       | **Type**  | **Description**                                  |
| -------------- | --------- | ------------------------------------------------ |
| `redeemTokens` | `uint256` | The number of pTokens to redeem into underlying  |
| `receiver`     | `address` | The address to receive underlying redeemed asset |
| `owner`        | `address` | The address which account for redeem tokens      |

**Returns**

| **Name**       | **Type**  | **Description**                     |
| -------------- | --------- | ----------------------------------- |
| `&lt;none&gt;` | `uint256` | amount of redeemed underlying asset |

#### **borrowOnBehalfOf**

The sender borrows assets on behalf of some other address. This function is only available for senders, explicitly marked as delegates of the borrower using `riskEngine.updateDelegate`

```solidity
function borrowOnBehalfOf(address onBehalfOf, uint256 borrowAmount)
    external;
```

**Parameters**

| **Name**       | **Type**  | **Description**                              |
| -------------- | --------- | -------------------------------------------- |
| `onBehalfOf`   | `address` | The borrower, on behalf of whom to borrow    |
| `borrowAmount` | `uint256` | The amount of the underlying asset to borrow |

#### **repayBorrowOnBehalfOf**

Sender repays a borrow belonging to borrower

```solidity
function repayBorrowOnBehalfOf(address onBehalfOf, uint256 repayAmount)
    external;
```

| **Name**      | **Type**  | **Description**                                                           |
| ------------- | --------- | ------------------------------------------------------------------------- |
| `onBehalfOf`  | `address` | the account with the debt being payed off                                 |
| `repayAmount` | `uint256` | The amount to repay, or type(uint256).max for the full outstanding amount |

#### **liquidateBorrow**

The sender liquidates the borrower's collateral. The collateral seized is transferred to the liquidator.

```solidity
function liquidateBorrow(address borrower, uint256 repayAmount, IPToken pTokenCollateral)
    external;
```

**Parameters**

| **Name**           | **Type**  | **Description**                                           |
| ------------------ | --------- | --------------------------------------------------------- |
| `borrower`         | `address` | The borrower of this pToken to be liquidated              |
| `repayAmount`      | `uint256` | The amount of the underlying borrowed asset to repay      |
| `pTokenCollateral` | `IPToken` | The market in which to seize collateral from the borrower |

#### reduceReservesEmergency

Accrues interest and reduces reserves by transferring to emergency guardian

```solidity

function reduceReservesEmergency(uint256 reduceAmount) external;

```

**Parameters**

| Name           | Type      | Description                           |
| -------------- | --------- | ------------------------------------- |
| `reduceAmount` | `uint256` | Amount of reduction to total reserves |

#### reduceReservesOwner

Accrues interest and reduces reserves by transferring to protocol owner

```solidity

function reduceReservesOwner(uint256 reduceAmount) external;

```

**Parameters**

| Name           | Type      | Description                           |
| -------------- | --------- | ------------------------------------- |
| `reduceAmount` | `uint256` | Amount of reduction to owner reserves |

#### reduceReservesConfigurator

Accrues interest and reduces reserves by transferring to governor

```solidity

function reduceReservesConfigurator(uint256 reduceAmount) external;
```

**Parameters**

| Name           | Type      | Description                                  |
| -------------- | --------- | -------------------------------------------- |
| `reduceAmount` | `uint256` | Amount of reduction to configurator reserves |

#### sweepToken

A public function to sweep accidental ERC-20 transfers to this contract. Tokens are sent to admin (timelock)

```solidity

function sweepToken(IERC20 token) external;

```

**Parameters**

| Name    | Type     | Description                              |
| ------- | -------- | ---------------------------------------- |
| `token` | `IERC20` | The address of the ERC-20 token to sweep |

#### setReserveFactor

***Admin Functions***

accrues interest and sets a new reserve factor for the protocol

*Admin function to accrue interest and set a new reserve factor*

```solidity

function setReserveFactor(uint256 newReserveFactorMantissa) external;

```

#### setProtocolSeizeShare

sets a new seize share for the protocol

*Admin function to set a new seize share*

```solidity

function setProtocolSeizeShare(uint256 newProtocolSeizeShareMantissa) external;

```

#### configureInterestRateModel

Configures the parameters for the interest rate model of the protocol.

*This function sets the base rate, multipliers, and kink points for the interest rate model. All annualized rates are converted to per-second rates for internal calculations. Only callable by the configurator.*

```solidity

function configureInterestRateModel(
    uint256 baseRatePerYear,
    uint256 multiplierPerYear,
    uint256 firstJumpMultiplierPerYear,
    uint256 secondJumpMultiplierPerYear,
    uint256 firstKink,
    uint256 secondKink
) external;

```

**Parameters**

| Name                          | Type      | Description                                                                                                               |
| ----------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------- |
| `baseRatePerYear`             | `uint256` | The base interest rate per year (scaled by 1e18) before utilization hits the first kink.                                  |
| `multiplierPerYear`           | `uint256` | The multiplier per year (scaled by 1e18) that increases the interest rate as utilization increases before the first kink. |
| `firstJumpMultiplierPerYear`  | `uint256` | The additional multiplier applied after the first kink point (scaled by 1e18).                                            |
| `secondJumpMultiplierPerYear` | `uint256` | The additional multiplier applied after second kink point (scaled by 1e18).                                               |
| `firstKink`                   | `uint256` | The utilization rate (scaled by 1e18) at which the interest rate "jumps" according to the first jump multiplier.          |
| `secondKink`                  | `uint256` | The utilization rate (scaled by 1e18) at which the interest rate "jumps" according to the second jump multiplier.         |


---

# 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://docs.pike.finance/developer-docs/smart-contracts/ptokens/interactions.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.
