Overview
TomoX Lending is a decentralized lending and borrowing protocol built on top of TomoX DEX. It enables users to create collateralized loans with configurable terms and interest rates, all executed on-chain.Key Features
Collateralized Lending
- Over-collateralization: Loans require collateral exceeding the borrowed amount
- Multiple Collateral Types: Support for various token types as collateral
- Dynamic Pricing: Oracle-based price feeds for collateral valuation
- Liquidation Protection: Automatic liquidation when collateral value drops
Flexible Terms
- Configurable Loan Periods: From 60 seconds to custom durations
- Interest Rates: Market-determined rates through order matching
- Auto Top-Up: Optional automatic collateral additions
- Early Repayment: Loans can be repaid before term expiry
Architecture
Lending State Database
Similar to TomoX DEX, lending maintains its own state:tomoxlending/tomoxlending.go:38
Lending Order Structure
tomoxlending/tomoxlending.go:123
How It Works
For Lenders
- Create Lending Order: Specify token, amount, interest rate, and term
- Wait for Match: Order sits in the lending book until matched
- Loan Execution: When matched, tokens are locked in the protocol
- Collect Repayment: Receive principal + interest at term end
For Borrowers
- Create Borrow Order: Specify token, amount, collateral, interest rate, and term
- Deposit Collateral: Lock collateral tokens in the protocol
- Receive Loan: Get lending tokens when order matches
- Repay or Liquidate: Repay before term end or risk liquidation
Order Processing
Lending orders are processed similarly to trading orders:tomoxlending/tomoxlending.go:103
Order Matching
Lending and borrowing orders are matched when:- Token Match: Same lending token and term
- Interest Agreement: Rates are compatible
- Collateral Valid: Sufficient collateral provided
- Price Current: Collateral valuation is up-to-date
Collateral Management
Collateral Configuration
Collateral is configured via smart contract:contracts/tomox/contract/LendingRegistration.sol:31
Collateral Rates
- Deposit Rate: Minimum collateral ratio (e.g., 150% = 150)
- Liquidation Rate: Auto-liquidation trigger (e.g., 125%)
- Recall Rate: Warning threshold (e.g., 175%)
- Deposit Rate: 150% (need 100 loan)
- Liquidation Rate: 125% (liquidated if collateral drops to $125)
- Recall Rate: 175% (warning if collateral exceeds $175)
Price Oracles
Collateral prices are updated by oracle feeders:contracts/tomox/contract/LendingRegistration.sol:126
ILO Collaterals
Initial Lending Offering (ILO) tokens can be used as collateral:- Issued by relayers or token creators
- Self-managed price feeds (token issuer updates prices)
- Must be registered separately from standard collaterals
contracts/tomox/contract/LendingRegistration.sol:150
Lending Relayers
Lending relayers operate lending markets:contracts/tomox/contract/LendingRegistration.sol:18
Relayer Configuration
Lending relayers must:- Be registered as a TomoX relayer first
- Configure lending tokens (base tokens)
- Set supported loan terms (minimum 60 seconds)
- Specify accepted collaterals (or 0x0 for all)
- Set trade fee (0-10%)
Loan Lifecycle
1. Order Creation
Users create lending or borrowing orders with:- Lending token and amount
- Interest rate (annual percentage)
- Loan term (duration)
- Collateral token (for borrowers)
- Auto top-up preference
2. Order Matching
The protocol matches compatible orders:- Lender’s minimum rate ≤ Borrower’s maximum rate
- Same token and term
- Valid collateral and price
3. Loan Active
During the loan period:- Collateral is locked
- Borrower has use of borrowed tokens
- Collateral value is monitored
- Auto top-up adds collateral if enabled
4. Loan Completion
At term end:- Repayment: Borrower repays principal + interest, gets collateral back
- Liquidation: If not repaid, collateral is transferred to lender
- Recall: Lender can recall if collateral ratio drops below recall rate
Interest Calculation
Interest is specified in basis points (1/100th of a percent):- 10% APR = 1000 basis points
- 0.5% APR = 50 basis points
- 25% APR = 2500 basis points
Liquidation Process
Liquidation occurs when:- Collateral Value Drops: Price falls below liquidation rate
- Loan Expires Unpaid: Term ends without repayment
- Recall Triggered: Lender recalls loan at recall rate
API Access
tomoxlending/api.go:18
Configuration
Base Tokens (Lending Tokens)
Moderately add lending tokens:contracts/tomox/contract/LendingRegistration.sol:175
Terms (Loan Periods)
Add supported loan terms:contracts/tomox/contract/LendingRegistration.sol:184
Common terms:
- 7 days: 604800 seconds
- 30 days: 2592000 seconds
- 90 days: 7776000 seconds
Risk Management
For Lenders
- Collateral Risk: Token value may drop rapidly
- Liquidation Gap: Slippage between liquidation and actual price
- Oracle Risk: Price feed delays or manipulation
- Term Risk: Tokens locked for loan duration
For Borrowers
- Liquidation Risk: Must maintain collateral ratio
- Interest Cost: Must generate returns exceeding interest
- Price Volatility: Collateral and borrowed token price swings
- Repayment Obligation: Must repay or lose collateral
Integration with TomoX DEX
Lending relies on DEX for price discovery:tomox/tomox.go:294
This integration ensures:
- Accurate collateral valuation
- Market-based interest rates
- Consistent pricing across protocols
What prevents liquidation cascades?
What prevents liquidation cascades?
The protocol has several protective mechanisms:
- Recall rate warnings before liquidation
- Auto top-up functionality to add collateral automatically
- Multiple collateral rate thresholds (deposit > liquidation)
- 2-second block time allows quick responses
- Oracle price updates before liquidation checks
Can I repay a loan early?
Can I repay a loan early?
Yes, borrowers can repay loans at any time before the term expires. Early repayment:
- Returns collateral immediately
- Charges interest only for the period used
- Has no penalties or prepayment fees
- Frees up capital for other uses
How are interest rates determined?
How are interest rates determined?
Interest rates are market-determined through order matching:
- Lenders specify minimum acceptable rate
- Borrowers specify maximum willing rate
- Orders match when rates overlap
- Competitive market ensures efficient pricing
- Higher risk (lower collateral ratio) may command higher rates
What happens if the oracle stops updating prices?
What happens if the oracle stops updating prices?
The protocol requires recent price updates:
- Each price has a block number timestamp
- Stale prices prevent new loan creation
- Existing loans continue but can’t be liquidated with stale prices
- Multiple oracle feeders can be configured for redundancy
- Token issuers can update ILO collateral prices directly
See Also
- TomoX DEX - Underlying trading protocol
- TRC21 Tokens - Gasless token standard
- Smart Contracts - Contract integration