RUJI Lend & Borrow

This guide covers integrating RUJI Lending (supply-side) and RUJI Credit (borrow-side CDP loans) into your application.

Overview

The RUJI Money Market consists of two core contract types:

Contract
Purpose
User Actions

Ghost Vault (rujira-ghost-vault)

Lending pools for each asset

Deposit, Withdraw

Ghost Credit (rujira-ghost-credit)

CDP loan management

Create Account, Borrow, Repay, Manage Collateral

Architecture

┌─────────────────┐     ┌─────────────────┐
│   Ghost Vault   │     │   Ghost Vault   │
│      (BTC)      │     │     (USDC)      │  ... per asset
└────────┬────────┘     └────────┬────────┘
         │                       │
         │    Borrows from       │
         ▼                       ▼
┌─────────────────────────────────────────┐
│            Ghost Credit                 │
│  (Manages Credit Accounts / CDPs)       │
└─────────────────────────────────────────┘

                    │ Creates

┌─────────────────────────────────────────┐
│          Credit Account                 │
│   (User's isolated margin account)      │
│   - Holds collateral                    │
│   - Tracks debt positions               │
└─────────────────────────────────────────┘

Contract Addresses

Mainnet

Contract
Address

Ghost Credit

thor1ekkt8wfls055t7f7yznj07j0s4mtndkq546swutzv2de7sfcxptq27duyt

Ghost Vault (BTC)

thor18e6gxcvmqfn06l09gurgwh3urlj9xztqagaslgspl2l74ejuujnqqlzzun

Ghost Vault (ETH)

thor1xufzny7n3565jy3rvglacengpn6eufw7lk5y9h4zxludkfe96q4s9j5uln

Ghost Vault (USDC)

thor1hs6wzyk4tf25ujd7lu07hhnkj4tl38m3wpp6qqw50y5r3e3x7zksnvj3qr

Ghost Vault (USDT)

thor1smdzjdm5q5e5kf6farvcgmxe44uhga2ety68veu2nupf5dzx55xsn3u4rj

Ghost Vault (BCH)

thor1km2sgadhmev34v40evf8qh2yw77hxecakn9nu0g35zdtsf905ehqhqk76r

Ghost Vault (DOGE)

thor1drfu6vrn06gam7fdk07xqmavthgy6rnmnmm2mh4fa047qsny52aqvxuck9

Ghost Vault (LTC)

thor1633kq6mxwn24ezdn38xpngksx8wlu458yesdqf3xhs2cfaan96cs2c3gdz

Ghost Vault (XRP)

thor1cvry7e7uzd89dv4hls5rg5m4xykczzu2qvj8dq5e93c75566tk9q7cya3l

Note: For the full list of lending vaults, check https://rujira.network/developer/deploymentarrow-up-right and look for rujira-ghost-vault.

Stagenet (Testnet)

Contract
Address

Ghost Credit

sthor16p65kngn6wtyxrngh2fkwtth4lr9eysvq7atsxt9qhnkknanw8yqza6pqa

Ghost Vault (USDT)

sthor165wfwxnw3vrp35h3ttf23vd0zgs3mt34r8rll50qe0jffun5ts8sdjp38e


Supported Assets

All amounts use 8 decimal places (THORChain standard).

Asset
Denom
Collateral Ratio
Lending Vault Receipt Token

BTC

BTC-BTC

70%

x/ghost-vault/BTC-BTC

ETH

ETH-ETH

70%

x/ghost-vault/ETH-ETH

USDC

ETH-USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48

70%

x/ghost-vault/ETH-USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48

USDT

ETH-USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7

70%

x/ghost-vault/ETH-USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7

BCH

BCH-BCH

70%

x/ghost-vault/BCH-BCH

DOGE

DOGE-DOGE

70%

x/ghost-vault/DOGE-DOGE

LTC

LTC-LTC

70%

x/ghost-vault/LTC-LTC

XRP

XRP-XRP

70%

x/ghost-vault/XRP-XRP

Note: Collateral ratios are configurable via governance. Query the Ghost Credit contract configuration ({"config": {}}) for full list of supported collaterals and their current collateral ratio values.


Part 1: Lending Integration (Ghost Vault)

Lenders deposit assets into Ghost Vault contracts and receive receipt tokens that accrue interest over time.

1.1 Query: Get Vault Status

Returns current rates, utilization, and pool sizes.

Response:

Field Explanations:

  • utilization_ratio: Percentage of deposits currently borrowed (0.65 = 65%)

  • debt_rate: Annual borrow APR (0.08 = 8%)

  • lend_rate: Annual supply APY (0.052 = 5.2%)

  • deposit_pool.ratio: Value of 1 receipt token in underlying asset

1.2 Query: Get Vault Config

Returns the underlying asset denom and interest rate parameters.

Response:

1.3 Calculate User Position Value

To display a user's lending position value:

1.4 Execute: Deposit

Deposit assets to receive interest-bearing receipt tokens.

What happens:

  1. User sends underlying asset (e.g., BTC)

  2. Contract mints receipt tokens based on current deposit_pool.ratio

  3. Receipt tokens are sent to user's wallet

1.5 Execute: Withdraw

Burn receipt tokens to retrieve underlying assets plus accrued interest.

What happens:

  1. User sends receipt tokens

  2. Contract burns receipt tokens

  3. Underlying asset (including accrued interest) is returned

Note: Withdrawals may fail if utilization is at 100%. The contract ensures liquidity by incentivizing deposits when utilization is high.


Part 2: Borrowing Integration (Ghost Credit)

Borrowers create Credit Accounts, deposit collateral, and borrow against it.

2.1 Query: Get Credit Config

Returns collateral ratios, liquidation thresholds, and fee parameters.

Response:

Field Explanations:

  • collateral_ratios: Maximum borrowing power per collateral type (0.7 = can borrow up to 70% of value)

  • liquidation_threshold: LTV at which liquidation is triggered (1.0 = 100%)

  • adjustment_threshold: Maximum LTV users can manually adjust to (0.9 = 90%)

  • fee_liquidation: Protocol fee on liquidations (1%)

  • fee_liquidator: Fee paid to liquidation executors (0.5%)

2.2 Query: Get User's Credit Accounts

Response:

Field Explanations:

  • account: The Credit Account contract address (holds collateral)

  • ltv: Current loan-to-value ratio (debt / adjusted collateral value)

  • value_full: Full USD value of collateral

  • value_adjusted: USD value after applying collateral ratio

  • debts[].current: Current debt amount including accrued interest

2.3 Query: Single Credit Account

2.4 Query: Predict Account Address

Get the deterministic address for a new Credit Account before creation.

2.5 Execute: Create Credit Account

2.6 Execute: Deposit Collateral & Borrow

All Credit Account operations are batched in a single account message:

Full flow to deposit collateral and borrow:

2.7 Execute: Repay Debt

2.8 Execute: Withdraw Collateral

2.9 Execute: Close Position (Repay All & Withdraw)


Part 3: Displaying Data in UI

3.1 Lending Position

3.2 Borrow Position

3.3 Risk Indicators

Display clear risk levels based on LTV:

LTV Range
Health Status
Color

0% - 50%

Safe

Green

50% - 75%

Moderate

Yellow

75% - 90%

At Risk

Orange

90% - 100%

Danger

Red

> 100%

Liquidatable

Red (flashing)


Part 4: Interest Rate Model

The protocol uses a kinked interest rate model:

Example Calculation

With parameters: base_rate=3%, target=80%, step1=10%, step2=200% , fee=10%

Utilization
Borrow Rate
Supply Rate

0%

3.0%

0.0%

40%

8.0%

2.9%

80%

13.0%

9.4%

90%

113.0%

91.5%

100%

213.0%

191.7%

Supply Rate = Borrow Rate × Utilization × (1 - Protocol Fee)


Part 5: Fees

Protocol Fees

Fee Type
Rate
Distribution

Interest Fee

10% of borrow interest

50% Protocol, 50% THORChain

Liquidation Fee

1% of repaid debt

50% Protocol, 50% THORChain

Liquidator Fee

0.5% of repaid debt

Liquidation executor

Fee parameters are configurable via governance. Query contract config for current values.


Part 6: Error Handling

Common Errors

Error
Cause
Solution

Unauthorized

Not the account owner

Verify sender matches account owner

Unsafe

Operation would exceed LTV limit

Reduce borrow amount or add collateral

ZeroDebt

Repaying when no debt exists

Check debt balance first

InvalidCollateral

Asset not in collateral whitelist

Use only supported collateral types

Transaction Simulation

Always simulate transactions before broadcasting:


Part 7: Code Examples

Complete Lending Flow (TypeScript)

Complete Borrowing Flow (TypeScript)


Appendix A: Message Reference

Ghost Vault Execute Messages

Ghost Vault Query Messages

Ghost Credit Execute Messages

Ghost Credit Query Messages


Appendix B: Response Types

StatusResponse (Ghost Vault)

AccountResponse (Ghost Credit)

Last updated