Skip to main content

liquidate_obligation_and_redeem_reserve_collateral

Liquidate an unhealthy obligation by repaying some of its debt and receiving collateral at a discount.

Signature

pub fn liquidate_obligation_and_redeem_reserve_collateral_v2(
    ctx: Context<LiquidateObligationAndRedeemReserveCollateralV2>,
    liquidity_amount: u64,
    min_acceptable_received_liquidity_amount: u64,
    max_allowed_ltv_override_percent: u64
) -> Result<()>
Use the v2 variant which includes farming support. The v1 variant is deprecated.

Parameters

liquidity_amount
u64
required
The amount of debt to repay. The actual amount may be reduced based on liquidation rules and available collateral.
min_acceptable_received_liquidity_amount
u64
required
The minimum amount of collateral liquidity the liquidator is willing to receive. Protects against slippage.
max_allowed_ltv_override_percent
u64
required
LTV override percentage. Only used in staging environment when liquidator is the obligation owner. Set to 0 normally.

Accounts

liquidation_accounts.liquidator
Signer
required
The liquidator performing the liquidation.
liquidation_accounts.obligation
AccountLoader<Obligation>
required
The unhealthy obligation to liquidate.
  • Must be mutable
liquidation_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
liquidation_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
liquidation_accounts.repay_reserve
AccountLoader<Reserve>
required
The reserve for the debt being repaid.
  • Must be mutable
liquidation_accounts.repay_reserve_liquidity_mint
InterfaceAccount<Mint>
required
The repay reserve’s liquidity token mint.
liquidation_accounts.repay_reserve_liquidity_supply
InterfaceAccount<TokenAccount>
required
The repay reserve’s liquidity supply vault.
  • Must be mutable
liquidation_accounts.withdraw_reserve
AccountLoader<Reserve>
required
The reserve for the collateral being liquidated.
  • Must be mutable
liquidation_accounts.withdraw_reserve_liquidity_mint
InterfaceAccount<Mint>
required
The withdraw reserve’s liquidity token mint.
liquidation_accounts.withdraw_reserve_collateral_mint
InterfaceAccount<Mint>
required
The withdraw reserve’s collateral token mint.
  • Must be mutable
liquidation_accounts.withdraw_reserve_collateral_supply
InterfaceAccount<TokenAccount>
required
The withdraw reserve’s collateral supply vault.
  • Must be mutable
liquidation_accounts.withdraw_reserve_liquidity_supply
InterfaceAccount<TokenAccount>
required
The withdraw reserve’s liquidity supply vault.
  • Must be mutable
liquidation_accounts.withdraw_reserve_liquidity_fee_receiver
InterfaceAccount<TokenAccount>
required
The withdraw reserve’s fee receiver vault.
  • Must be mutable
liquidation_accounts.user_source_liquidity
InterfaceAccount<TokenAccount>
required
The liquidator’s source liquidity token account (for repayment).
  • Must be mutable
liquidation_accounts.user_destination_collateral
InterfaceAccount<TokenAccount>
required
The liquidator’s destination collateral token account (receives collateral).
  • Must be mutable
liquidation_accounts.user_destination_liquidity
InterfaceAccount<TokenAccount>
required
The liquidator’s destination liquidity token account (receives redeemed liquidity).
  • Must be mutable
liquidation_accounts.collateral_token_program
Program<Token>
required
The SPL Token program.
liquidation_accounts.repay_liquidity_token_program
Interface<TokenInterface>
required
The token program for repay liquidity.
liquidation_accounts.withdraw_liquidity_token_program
Interface<TokenInterface>
required
The token program for withdraw liquidity.
liquidation_accounts.instruction_sysvar_account
AccountInfo
required
The Solana instructions sysvar.
collateral_farms_accounts
OptionalObligationFarmsAccounts
required
Optional farming accounts for collateral (v2 only).
debt_farms_accounts
OptionalObligationFarmsAccounts
required
Optional farming accounts for debt (v2 only).
farms_program
Program<Farms>
required
The Kamino Farms program (v2 only).

Remaining Accounts

All deposit reserves for the obligation (to calculate total collateral value).

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • ObligationHealthy: Cannot liquidate a healthy obligation
  • LiquidationTooSmall: Liquidation amount is too small
  • LiquidationRewardTooSmall: Received amount is less than minimum acceptable
  • CollateralNonLiquidatable: The collateral has LTV=0 and cannot be liquidated
  • LiquidationBorrowFactorPriority: Must prioritize debt with highest borrow factor
  • LiquidationLowestLiquidationLtvPriority: Must prioritize collateral with lowest liquidation LTV
  • InsufficientRepayAmount: Repay amount is less than required by liquidation rules

Liquidation Rules

The instruction enforces several rules:
  1. Obligation must be unhealthy: LTV exceeds liquidation threshold
  2. Borrow factor priority: Must liquidate the debt with the highest borrow factor first (can be bypassed with min_value_skip_liquidation_bf_checks)
  3. Collateral LTV priority: Must liquidate the collateral with the lowest liquidation LTV first (can be bypassed with min_value_skip_liquidation_ltv_checks)
  4. Close factor: Can only liquidate up to a percentage of total debt (configured in market)
  5. Full liquidation threshold: If debt value is below threshold, must fully liquidate
  6. Liquidation bonus: Liquidator receives collateral at a discount based on configuration

mark_obligation_for_deleveraging

Mark an unhealthy obligation for automatic deleveraging. Only callable by the lending market owner.

Signature

pub fn mark_obligation_for_deleveraging(
    ctx: Context<MarkObligationForDeleveraging>,
    autodeleverage_target_ltv_pct: u8
) -> Result<()>

Parameters

autodeleverage_target_ltv_pct
u8
required
The target LTV percentage to deleverage the obligation down to (1-100).

Accounts

lending_market_owner
Signer
required
The owner of the lending market.
obligation
AccountLoader<Obligation>
required
The obligation to mark for deleveraging.
  • Must be mutable
lending_market
AccountLoader<LendingMarket>
required
The lending market.
  • Must have lending_market_owner matching signer
  • Must have autodeleverage_enabled set to true

Returns

Returns Ok(()) on success. The obligation is marked with a timestamp and target LTV for deleveraging.

Errors

  • ObligationHealthy: Obligation is not unhealthy enough to deleverage
  • ObligationCurrentlyMarkedForDeleveraging: Obligation is already marked for deleveraging
  • Market owner validation errors if signer is not the market owner

Usage

This instruction is used when an obligation cannot be liquidated normally (e.g., due to lack of liquidity) and needs to be gradually deleveraged through a special process. After marking, the obligation can be deleveraged through specific deleveraging operations that bypass normal LTV checks.

Build docs developers (and LLMs) love