Liquidation Function

Liquidate


This function allows you to liquidate an obligation account that has unhealthy condition. Anyone can perform the liquidation if the obligation is in unhealthy condition. Additionally, you need to update the oracle price before proceeding with the liquidation.

public fun liquidate<DebtType, CollateralType>(
  version: &Version,
  obligation: &mut Obligation,
  market: &mut Market,
  available_repay_coin: Coin<DebtType>,
  coin_decimals_registry: &CoinDecimalsRegistry,
  x_oracle: &XOracle,
  clock: &Clock,
  ctx: &mut TxContext,
): (Coin<DebtType>, Coin<CollateralType>) { }

Modules:

Parameters

Name

Type

Description

version

Version

The version control object, contract version must match with this

obligation

Obligation

The obligation id object

market

Market

The Scallop market object, it contains base assets, and related protocol configs

available_repay_coin

Coin

Coin object that used to repay the debt of obligation.

coin_decimals_registry

CoinDecimalsRegistry

The package that has decimal coin of base assets.

x_oracle

XOracle

The x-oracle object which provides the price of assets

clock

Clock

The SUI system clock object

Return Values

NameTypeDescription

Coin

Coin

The remaining base asset

Coin

Coin

The liquidated collateral

Events

  • LiquidateEventV2 is emited when ****the supply tx success

Errors

  • 770: Means current obligation is locked and need to unstake first from borrow incentive

  • 1537: Unable liquidated because liq amount is not lower than or equal 0

Example:

module protocol::foo {

  use sui::coin::{Self, Coin};

  use scallop_protocol::mint::mint;
  use scallop_protocol::Market as ScallopMarket;
  use scallop_protocol::Version as ScallopVersion;
  use scallop_protocol::Obligation;
  use scallop_protocol::CoinDecimalsRegistry;
  use scallop_protocol::XOracle;

  public fun doFoo<T>(
    scallop_version: &Version,
    obligation: &mut Obligation,
    scallop_market: &mut Market,
    available_repay_coin: Coin<DebtType>,
    coin_decimals_registry: &CoinDecimalsRegistry,
    x_oracle: &XOracle,
    clock: &Clock,
    ctx: &mut TxContext
  ): Coin<MarketCoin<T>> {
    scallop_protocol::liquidate::liquidate<T>(
      scallop_version,
      scallop_market,
      available_repay_coin,
      coin_decimals_registry,
      x_oracle,
      clock,
      ctx,
    )
 }
}

Check here the example how to do update price x_oracle

We recommend you to call this function using our Scallop SDK, so before calling any function related to liquidation, you need to call update price in the beginning of the PTB (Programmable Transaction Block).

Here what your PTB should looks like:

PTB for calling function that have to run liquidate function:
- update price (you get this from SDK)
- your function that call liquidate

Last updated