# BorrowLiquidation

## Write Functions

### liquidateBorrowPosition

```solidity
function liquidateBorrowPosition(
        address user,
        uint64 index,
        uint64 currentEthPrice,
        IBorrowing.LiquidationType liquidationType,
        uint256 _lastCumulativeRate
) external payable
```

| Param Name         | Type            | Description                       |
| ------------------ | --------------- | --------------------------------- |
| user               | address         | Address of the borrower.          |
| index              | uint64          | Index of the borrower's position. |
| currentEthPrice    | uint64          | Current ETH price.                |
| liquidationType    | LiquidationType | How to liquidate the psoition.    |
| lastCumulativeRate | uint256         | Cumulative rate.                  |

Liquidate the the borrower's position, if the current ETH price is below or equal to deposited LTV of deposited ETH price. Here the borrowed amount of USDa is burned, 10% of protected amount is going to ABOND USDa pool if the liquidated collateral is ETH. This function can only be called by borrowing contract.

{% hint style="info" %}
Here, the CDS users who opted for liquidation gains are liquidators.
{% endhint %}

### liquidationType1

```solidity
function liquidationType1(
    address user,
    uint64 index,
    uint64 currentEthPrice,
    uint256 lastCumulativeRate
) internal
```

| Param Name         | Type    | Description                       |
| ------------------ | ------- | --------------------------------- |
| user               | address | Address of the borrower.          |
| index              | uint64  | Index of the borrower's position. |
| currentEthPrice    | uint64  | Current ETH price.                |
| lastCumulativeRate | uint256 | Cumulative rate.                  |

Here the borrowed amount of USDa is burned, 10% of protected amount is going to ABOND USDa pool if the liquidated collateral is ETH.

### liquidationType2

```solidity
function liquidationType1(
    address user,
    uint64 index,
    uint64 currentEthPrice
) internal
```

| Param Name      | Type    | Description                       |
| --------------- | ------- | --------------------------------- |
| user            | address | Address of the borrower.          |
| index           | uint64  | Index of the borrower's position. |
| currentEthPrice | uint64  | Current ETH price.                |

Here the 50% of the deposited amount is transfer to synthetix for taking short position with 1X leverage.

### closeThePositionInSynthetix

```solidity
function closeThePositionInSynthetix() external
```

Submit the order to close the above opened short position in synthetix.

### executeOrdersInSynthetix

```solidity
function executeOrdersInSynthetix(
    bytes[] calldata priceUpdateData
) external 
```

Execute the submitted orders in synthetix.

### setTreasury

```solidity
function setTreasury(address _treasury)
```

| Param Name | Type    | Description               |
| ---------- | ------- | ------------------------- |
| \_treasury | address | Treasury contract addess. |

Sets treasury contract interface.

### setAdmin

```solidity
function setTreasury(address adminAddress)
```

| Param Name   | Type    | Description      |
| ------------ | ------- | ---------------- |
| adminAddress | address | Admin's address. |

Sets admin's address.


---

# 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.nondollar.life/autonomint/blockchain-docs/core-contracts/borrowliquidation.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.
