Liquidation Solvers

This guide covers building liquidation solvers (also called "path finders") - off-chain infrastructure that monitors at-risk positions, calculates optimal liquidation routes, and executes liquidations

Overview

The Path Finding Challenge

RUJI supports multiple collateral types within its borrowing system. Each Credit Account can hold various assets (BTC, ETH, XRP, DOGE, etc.) as collateral against different debt positions. When liquidation is needed, each collateral type requires a unique swap path through RUJI Trade to convert it to the debt token.

The challenge: Calculating optimal multi-hop swap routes across multiple collateral types is computationally intensive - too expensive for on-chain execution. This creates an opportunity for external solvers.

How Solvers Earn

┌─────────────────────────────────────────────────────────┐
│                    Solver Workflow                      │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. Monitor Credit Accounts for LTV >= 100%             │
│                                                         │
│  2. Analyze underwater position:                        │
│     - Multiple collateral types (BTC, ETH, DOGE, etc.)  │
│     - Debt denominated in USDC, USDT, etc.              │
│     - User liquidation preferences                      │
│                                                         │
│  3. Calculate optimal liquidation path:                 │
│     - Query RUJI Trade pools for liquidity              │
│     - Find best swap routes per collateral              │
│     - Respect preference order constraints              │
│     - Minimize slippage across all swaps                │
│                                                         │
│  4. Execute liquidation on-chain                        │
│     - Submit optimized route via ExecuteMsg::Liquidate  │
│     - Earn 0.5% of repaid debt as fee                   │
│                                                         │
└─────────────────────────────────────────────────────────┘

Permissionless Participation

Anyone can build and run a liquidation solver. There's no whitelist or approval process, the protocol is open to all participants. Competition drives better execution for the protocol and users.


Fee Structure

Fee
Rate
Recipient

Liquidation Fee

1% of repaid debt

50% Protocol, 50% THORChain

Solver Fee

0.5% of repaid debt

You (the liquidator)

Example: Liquidating a position with 10,000 USDC debt earns ~50 USDC for the solver.


Contract Addresses

Contract
Address

Ghost Credit

thor1ekkt8wfls055t7f7yznj07j0s4mtndkq546swutzv2de7sfcxptq27duyt

RUJI Trade (BTC/USDC)

thor1dwsnlqw3lfhamc5dz3r57hlsppx3a2n2d7kppccxfdhfazjh06rs5077sz

RUJI Trade (ETH/USDC)

thor1tnd06uswj8033d0kzd5d7zre73u3uc44r2vvez26z5m4kr68vtusf2snva

Note: For the full list of RUJI Trade pairs, check https://rujira.network/developer/deploymentarrow-up-right and look for rujira-fin.


Querying Liquidatable Positions

Find All Accounts (Paginated)

Check Single Account

Account Response Structure


Path Finding Strategy

Multi-Collateral Accounts

A typical underwater account might look like:

Route Optimization Goals

  1. Minimize total slippage across all swaps

  2. Respect user preferences (mandatory)

  3. Maximize your profit (fee - gas costs)

  4. Ensure LTV drops below liquidation threshold

Querying RUJI Trade Liquidity

For each collateral type, query the corresponding RUJI Trade pool:

Building Multi-Hop Routes

For exotic collateral types, you may need multi-hop swaps:


Executing Liquidations

Liquidate Message Structure

LiquidateMsg Types

Example: Multi-Collateral Liquidation


Handling User Preferences

Preference Order

Users can specify liquidation order constraints:

Preference Messages

Users can pre-define swap routes. These execute BEFORE your messages:

Important: User preference messages use reply_always - if they fail, liquidation continues with your messages. Don't assume preferences will succeed.


Validation Rules

Your liquidation must satisfy:

1. Position Must Be Underwater

2. No Over-Liquidation

After liquidation:

Liquidate only enough to bring LTV below 100%, not all the way to 0%.

3. Slippage Limit

Default liquidation_max_slip is 30%. Bad routes that exceed this will fail.

4. Preference Order Respected

Violating user preference order causes immediate failure.


Building a Liquidation Bot

Architecture

Monitor Service

Analyze Service

Execute Service

Main Loop


Profitability Calculation


Error Handling

Common Errors

Error
Cause
Solution

Safe

Account LTV < 100%

Position not liquidatable (yet)

Unsafe

Final LTV still >= 100%

Liquidation route insufficient

LiquidationMaxSlipExceeded

Slippage > 30%

Find better swap routes

Invalid liquidation attempted {coin} before {before}

Preference violated

Reorder collateral liquidation

Retry Strategy


Message Reference

Liquidate (Execute)


Configuration Parameters

Query the Ghost Credit config for current parameters:

Parameter
Description
Typical Value

liquidation_threshold

LTV triggering liquidation

1.0 (100%)

adjustment_threshold

Min LTV after liquidation

0.9 (90%)

liquidation_max_slip

Max allowed slippage

0.3 (30%)

fee_liquidation

Protocol fee

0.01 (1%)

fee_liquidator

Your fee

0.005 (0.5%)

collateral_ratios

Collateral factors

varies

Last updated