> For the complete documentation index, see [llms.txt](https://uliquid.gitbook.io/uliquid_v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uliquid.gitbook.io/uliquid_v1/core-contracts/liquidator.md).

# Liquidator

## Liquidator

The Uliquid V1 protocol has two primary types of Liquidation contracts, the AaveLiquidator.sol contract and the CompoundLiquidator.sol contract. Liquidation contracts deployed for Aave or Compound forks inherit either of these two contracts.

## AaveLiquidator

## Structs

### liquidateArgs

| Param name         | Type         | Description                                                            |
| ------------------ | ------------ | ---------------------------------------------------------------------- |
| lendingPool        | ILendingPool | Aave lending pool                                                      |
| priceOracle        | IPriceOracle | Aave price oracle                                                      |
| debt               | address      | address of the debt to be repaid                                       |
| collateral         | address      | address of the collateral to be liquidated                             |
| aTokenCollateral   | address      | address of the collateral AToken                                       |
| debtAmount         | uint         | amount of debt to be repaid                                            |
| stableDebtAmount   | uint         | amount of stable debt to be repaid                                     |
| variableDebtAmount | uint         | amount of variable debt to be repaid                                   |
| collateralAmount   | uint         | amount of collateral to be withdrawn from user                         |
| debtDecimals       | uint         | decimals of debt token                                                 |
| collateralDecimals | uint         | decimals of collateral token                                           |
| feePlusSlippage    | uint         | percentage of fee plus allowed slippage, scaled by 10^6                |
| minSwapOut         | uint         | min amount of debt token received after collateral is swapped for debt |
| swapData           | bytes        | encoded data required for swap                                         |

## Write methods

### liquidate

#### function liquidate(liquidateArgs memory args)

Executes the liquidation of a user's collateral for debt repayment

{% hint style="info" %}
Caller must have approved Liquidator contract to spend collateral
{% endhint %}

| Param Name | Type          | Description                                       |
| ---------- | ------------- | ------------------------------------------------- |
| args       | liquidateArgs | Contains all arguments required for a liquidation |

### executeOperation

#### function executeOperation(address\[] memory assets, uint256\[] memory amounts, uint256\[] memory premiums, address sender, bytes memory data)

executeOperation is called by the Aave lending pool along with flashloaned funds required for a liquidation

| Param Name | Type              | Description                                                |
| ---------- | ----------------- | ---------------------------------------------------------- |
| assets     | address\[] memory | address \[] of flashloaned tokens                          |
| amounts    | uint256\[] memory | amounts of flashloaned tokens                              |
| premiums   | uint256\[] memory | amounts of premiums to be paid for each flashloaned tokens |
| sender     | address           | address of the sender                                      |
| data       | bytes memory      | encoded data required for completing a liquidation         |

### setSwapper

#### function setSwapper(address payable \_swapper)

Sets a new swapper contract

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type            | Description                            |
| ---------- | --------------- | -------------------------------------- |
| \_swapper  | address payable | address of the new Liquidation Swapper |

### setFee

#### function setFee(uint \_fee)

Sets a new liquidation fee

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type | Description                                 |
| ---------- | ---- | ------------------------------------------- |
| \_fee      | uint | liquidation fee percentage scaled by 10 ^ 6 |

### setTreasury

#### function setTreasury(address \_treasury)

Sets a new treasury

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| \_treasury | address | new Treasury address |

### setAdmin

#### function setAdmin(address \_admin)&#x20;

Sets a new admin

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description              |
| ---------- | ------- | ------------------------ |
| \_admin    | address | address of the new admin |

### approveLendingPool

#### function approveLendingPool(address pool)

approves an Aave (or fork) lending pool

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| pool       | address | lending pool address |

### disapproveLendingPool

#### function disapproveLendingPool(address pool)

disapproves an Aave (or fork) lending pool

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| pool       | address | lending pool address |

### getCash

#### function getCash(address \_token)

withdraws stray token amounts to admin

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_token    | address | address of an ERC20 token |

### getCashSend

#### function getCashSend(address \_token, address to)

withdraws stray token amounts to a specified address

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_token    | address | address of an ERC20 token |
| to         | address | address of the receiver   |

## CompoundLiquidator

### Structs

### aaveLiquidateArgs

| Param Name               | Type         | Description                                                            |
| ------------------------ | ------------ | ---------------------------------------------------------------------- |
| lendingPool              | ILendingPool | Aave lending pool                                                      |
| priceOracle              | IPriceOracle | Compound price oracle                                                  |
| cTokenDebt               | address      | address of debt CToken                                                 |
| cTokenCollateral         | address      | address of collateral CToken                                           |
| debt                     | address      | address of the debt to be repaid                                       |
| collateral               | address      | address of the collateral to be repaid                                 |
| debtAmount               | uint         | amount of debt to be repaid                                            |
| collateralAmount         | uint         | amount of collateral equivalent to the collateralCTokenAmount          |
| collateralCTokenAmount   | uint         | amount of CToken collateral to be withdrawn from user                  |
| collateralCTokenDecimals | uint         | decimals of collateral CToken                                          |
| feePlusSlippage          | uint         | percentage of fee plus allowed slippage, scaled by 10^6                |
| minSwapOut               | uint         | min amount of debt token received after collateral is swapped for debt |
| swapData                 | bytes        | encoded data required for swap                                         |

### v2LiquidateArgs

| Param Name               | Type         | Description                                                            |
| ------------------------ | ------------ | ---------------------------------------------------------------------- |
| IUniswapV2Pair           | pool         | A Uniswap V2 Pool                                                      |
| debtIsToken0             | bool         | specifies if debt is token0 of the pool                                |
| repayToken               | address      | address specifying the token being repaid to the Uniswap V2 Pool       |
| priceOracle              | IPriceOracle | Compound price oracle                                                  |
| cTokenDebt               | address      | address of debt CToken                                                 |
| cTokenCollateral         | address      | address of collateral CToken                                           |
| debt                     | address      | address of the debt to be repaid                                       |
| collateral               | address      | address of the collateral to be repaid                                 |
| debtAmount               | uint         | amount of debt to be repaid                                            |
| collateralAmount         | uint         | amount of collateral equivalent to the collateralCTokenAmount          |
| collateralCTokenAmount   | uint         | amount of CToken collateral to be withdrawn from user                  |
| collateralCTokenDecimals | uint         | decimals of collateral CToken                                          |
| feePlusSlippage          | uint         | percentage of fee plus allowed slippage, scaled by 10^6                |
| minSwapOut               | uint         | min amount of debt token received after collateral is swapped for debt |
| swapData                 | bytes        | encoded data required for swap                                         |

### validateArgs

| Param Name               | Type         | Description                                                   |
| ------------------------ | ------------ | ------------------------------------------------------------- |
| priceOracle              | IPriceOracle | Compound price oracle                                         |
| cTokenDebt               | address      | address of the debt CToken                                    |
| cTokenCollateral         | address      | address of the collateral CToken                              |
| debtAmount               | uint         | amount of debt to be repaid                                   |
| collateralAmount         | uint         | amount of collateral equivalent to the collateralCTokenAmount |
| collateralCTokenAmount   | uint         | amount of collateral CToken to be withdrawn from the user     |
| collateralCTokenDecimals | uint         | decimals of the collateral CToken                             |
| feePlusSlippage          | uint         | percentage of fee plus allowed slippage, scaled by 10^6       |

### Write Methods

### liquidate

#### function liquidate(aaveLiquidateArgs memory args)

Executes the liquidation of a user's collateral for debt repayment

{% hint style="info" %}
Caller must have approved Liquidator contract to spend collateral CToken&#x20;
{% endhint %}

| Param Name | Type              | Description                                                          |
| ---------- | ----------------- | -------------------------------------------------------------------- |
| args       | aaveLiquidateArgs | Contains all arguments required for a Compound (or fork) liquidation |

### v2Liquidate

#### function v2Liquidate(v2LiquidateArgs memory args)

Executes the liquidation of a user's collateral for debt repayment. Flashloan source for this liquidation is Uniswap V2

{% hint style="info" %}
Caller must have approved Liquidator contract to spend collateral CToken
{% endhint %}

| Param Name | Type            | Description                                                          |
| ---------- | --------------- | -------------------------------------------------------------------- |
| args       | v2LiquidateArgs | Contains all arguments required for a Compound (or fork) liquidation |

### executeOperation

#### function executeOperation(address\[] memory assets, uint256\[] memory amounts, uint256\[] memory premiums, address sender, bytes memory data)

executeOperation is called by the Aave lending pool along with flashloaned funds required for a liquidation

| Param Name | Type              | Description                                                |
| ---------- | ----------------- | ---------------------------------------------------------- |
| assets     | address\[] memory | address \[] of flashloaned tokens                          |
| amounts    | uint256\[] memory | amounts of flashloaned tokens                              |
| premiums   | uint256\[] memory | amounts of premiums to be paid for each flashloaned tokens |
| sender     | address           | address of the sender                                      |
| data       | bytes memory      | encoded data required for completing a liquidation         |

### setSwapper

function setSwapper(address payable \_swapper)

Sets a new swapper contract

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type            | Description                            |
| ---------- | --------------- | -------------------------------------- |
| \_swapper  | address payable | address of the new Liquidation Swapper |

### setFee

#### function setFee(uint \_fee)

Sets a new liquidation fee

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type | Description                                 |
| ---------- | ---- | ------------------------------------------- |
| \_fee      | uint | liquidation fee percentage scaled by 10 ^ 6 |

### setTreasury

#### function setTreasury(address \_treasury)

Sets a new treasury

{% hint style="info" %}
Only callable by Admin&#x20;
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| \_treasury | address | new Treasury address |

### setAdmin

#### function setAdmin(address \_admin)

Sets a new admin

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description              |
| ---------- | ------- | ------------------------ |
| \_admin    | address | address of the new admin |

### approveLendingPool

#### function approveLendingPool(address pool)

approves an Aave (or fork) lending pool

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| pool       | address | lending pool address |

### disapproveLendingPool

#### function disapproveLendingPool(address pool)

disapproves an Aave (or fork) lending pool

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description          |
| ---------- | ------- | -------------------- |
| pool       | address | lending pool address |

### getCash

function getCash(address \_token)

withdraws stray token amounts to admin

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_token    | address | address of an ERC20 token |

### getCashSend

function getCashSend(address \_token, address to)

withdraws stray token amounts to a specified address

{% hint style="info" %}
Only callable by Admin
{% endhint %}

| Param Name | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_token    | address | address of an ERC20 token |
| to         | address | address of the receiver   |
