# pool

The Pool contract is the main interface for users and integrations.

Typical user actions:

* supply
* withdraw
* borrow
* repay
* toggle collateral usage
* liquidate
* flash loans

### Write methods

#### supply

```solidity
function supply(
  address asset,
  uint256 amount,
  address onBehalfOf,
  uint16 referralCode
) external;
```

Deposits an asset into Orchid and mints oTokens to `onBehalfOf`.

Notes:

* You must approve the Pool to spend the underlying token first
* `referralCode` can be `0` if not used

***

#### supplyWithPermit

```solidity
function supplyWithPermit(
  address asset,
  uint256 amount,
  address onBehalfOf,
  uint16 referralCode,
  uint256 deadline,
  uint8 v,
  bytes32 r,
  bytes32 s
) external;
```

Supply using an ERC-2612 permit signature so users do not need a separate approval transaction.

***

#### withdraw

```solidity
function withdraw(
  address asset,
  uint256 amount,
  address to
) external returns (uint256);
```

Notes:

* If your collateral backs debt, withdrawals are limited to keep your account safe
* Use `type(uint256).max` to withdraw full balance

***

#### borrow

```solidity
function borrow(
  address asset,
  uint256 amount,
  uint256 interestRateMode,
  uint16 referralCode,
  address onBehalfOf
) external;
```

Borrows an asset if the account has sufficient collateral and borrowing power.

Notes:

* Orchid may support only variable rate mode. If so, pass the correct constant for variable mode as defined in the protocol

***

#### repay

```solidity
function repay(
  address asset,
  uint256 amount,
  uint256 interestRateMode,
  address onBehalfOf
) external returns (uint256);
```

Repays debt for `onBehalfOf` and burns the debt tokens.

Notes:

* Approve the Pool to spend the underlying token first
* Use `type(uint256).max` to repay all debt for yourself

***

#### repayWithPermit

```solidity
function repayWithPermit(
  address asset,
  uint256 amount,
  uint256 interestRateMode,
  address onBehalfOf,
  uint256 deadline,
  uint8 v,
  bytes32 r,
  bytes32 s
) external returns (uint256);
```

Repay using ERC-2612 permit approval.

***

#### setUserUseReserveAsCollateral

```solidity
function setUserUseReserveAsCollateral(
  address asset,
  bool useAsCollateral
) external;
```

Enables or disables an asset as collateral for the caller.

Notes:

* Orchid will block disabling collateral if doing so makes the account liquidatable

***

#### liquidationCall

```solidity
function liquidationCall(
  address collateralAsset,
  address debtAsset,
  address user,
  uint256 debtToCover,
) external;
```

Allows anyone to liquidate an unhealthy position.

* liquidator repays a portion of `debtAsset`
* liquidator receives discounted `collateralAsset`

***

#### flashLoan

```solidity
function flashLoan(
  address receiverAddress,
  address[] calldata assets,
  uint256[] calldata amounts,
  uint256[] calldata interestRateModes,
  address onBehalfOf,
  bytes calldata params,
  uint16 referralCode
) external;
```

Borrows liquidity that must be returned in the same transaction plus fee, otherwise the transaction reverts.
