# Running a Liquidator Bot

### Background & Reference

Echelons liquidation accounting is inspired by Compound V2, so most Compound V2 concepts apply.

### **How Liquidations work on Echelon**

A vault is composed of collaterals and liabilities.

A vault becomes liquidatable when:

\- 100% > health factor = account margin / liability value.

\- account margin = sum(collateral value \* Liquidation Threshold).

\- let's say the vault has $10,000 worth of APT and $20,000 worth of USDC. APT liquidation threshold = 74% while USDC liquidation threshold = 82%. The account's margin = 10k \* 74% + 20k \* 82% = $23,800.

\- All asset price are quoted from [Oracles](/echelon/core/oracles.md)

\
Liquidators are encouraged to call `liquidate` to repay part of the liability and seize collateral at discount (`close_factor` determines the max one can repay, and `liquidation_incentives` determines the discount).&#x20;

Given a vault could have M collateral assets and N liability assets, it is up to liquidators to decide what asset to repay and what asset to seize (M\*N combinations). Hence the interface:

```
public fun liquidate<CoinType>
    liquidator: &signer,
    borrower_addr: address,
    borrow_market_obj: Object<Market>,
    collateral_market_obj: Object<Market>,
    repay_asset: Coin<CoinType>,
    min_shares_out: u64) { ... }
```

\
Note that `min_shares_out` is a liquidator-friendly check that guarantees the minimal shares to seize, which otherwise aborts the liqudation transaction.

### **Parameters and Data**

#### Protocol parameters

\- close factor: 50%

\- liquidation incentives: 107%

\- liquidation fee: 2.5%

#### Market addresses

\- zUSDT: `0x447b3b516546f28e8c4f6825a6287b09161659e7c500c599c29c28a8492844b8`

\- zUSDC: `0xa9c51ca3bcd93978d0c4aada7c4cf47c0791caced3cdc4e15f2c8e0797d1f93c`

\- MOD:  `0xef2ae89796725d0eb363326ecb7df159feb949f6d1f400f76deeeebccbac00f1`

\- THL:  `0x127ea5b4c450be695e488da1c3bc013e2e93d8cf00270ef90385189844bc9755`

\- APT:  `0x761a97787fa8b3ae0cef91ebc2d96e56cc539df5bc88dadabee98ae00363a831`

\- sthAPT: `0xed6bf9fe7e3f42c6831ffac91824a545c4b8bfcb40a59b3f4ccfe203cafb7f42`

\- whUSDC:`0xa76ebfb432982c864783fdb33cdf5a9edb18ac1b950deb8037f5cf8c984da3d2`

\- zWETH: `0x548cf587bd918a0005b3372a1d23e64b18ace3c61962f087a21eac52cf228504`

\- whWETH:`0x114ee519ffa1e8697784bd1a350822cb37601a1476289051b8295165597a4538`

\- CAKE:  `0x41b039e5518b1a3786ee798d895e0ddf3141fbbc20009284323fa51ea279c819`

\- stAPT: `0xc3c9cc885a52004e0490f6a8291b3bc5854f0e42d931fb124736bd189c9f0f45`

\- aBTC: `0xacb7262b33a147b47b950a3a26d7699e1a58bcaa475ef636cb0fea53fa0eb872`

\- SBTC: `0x754114c656e26498a8c0b20fa24af663fed5e4b24acb471c103daea0f7006b40`

\- STONE: `0x75c39f18c7bc00ac0f81a0f9ab7e319e23790d7d8c3df968d84a23699584bd9`

#### Market parameters

You can check market-level parameters in the above address by looking into a Market resource. For example: [APT market parameters](https://aptoscan.com/objects/0x761a97787fa8b3ae0cef91ebc2d96e56cc539df5bc88dadabee98ae00363a831#resources)<br>

#### Vault addresses

Index `SupplyEvent` and `account_addr` is the vault 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.echelon.market/echelon/integrations/running-a-liquidator-bot.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.
