You can use any erc20 token to pair with your tokenized asset, USDC is only used as an example in this documentation.
Architecture Overview
Core Components
Lending Market
The main contract handling all lending operations:| Function | Description |
|---|---|
addLiquidity | Deposit USDC, receive LP shares |
removeLiquidity | Burn shares, withdraw USDC |
openLoan | Deposit collateral, borrow USDC |
repay | Pay back debt, reduce interest |
liquidate | Seize collateral from unhealthy positions |
Price Oracle
Provides real-time collateral valuations:- Supports signed price updates (gasless for users)
- Configurable staleness thresholds
- Multiple authorized price signers
- Fallback to external price feeds
Interest Rate Model
Calculates borrow and supply rates based on utilization: Above a configurable “kink” (typically 80% utilization), rates increase sharply to encourage repayments.Insurance Fund
Absorbs losses from failed liquidations:- Funded by protocol fees (portion of interest revenue)
- Covers bad debt when liquidation proceeds fall short
- Automatically replenishes during normal operation
Liquidation Router
Routes liquidated collateral to trading venues for sale:- Receives seized collateral from markets
- Forwards to configured trading venues
- Returns USDC proceeds to lending pool
- Supports multiple markets through single deployment
Access Control Roles
Admin
DEFAULT_ADMIN_ROLE
- Pause/unpause market
- Configure insurance fund
- Upgrade contract logic
- Grant/revoke other roles
Issuer
ISSUER_ROLE
- Update market configuration
- Set liquidation contract
- Authorize oracle signers
- Approve whitelabel access
Liquidator
LIQUIDATOR_ROLE
- Trigger liquidations
- Settle Dutch auctions
- Handle timeout scenarios
Market Configuration
Markets are highly configurable to match your risk appetite and regulatory requirements:Risk Parameters
| Parameter | Description | Typical Range |
|---|---|---|
| Collateral Factor | Maximum LTV for borrowing | 65-80% |
| Liquidation Threshold | LTV triggering liquidation | 80-90% |
| Liquidation Penalty | Bonus for liquidators | 3-10% |
| Close Factor | Max % liquidatable per tx | 25-50% |
| Min Borrow Amount | Minimum loan size | $100+ |
Supply Caps
Limit exposure at market and user levels:| Cap Type | Purpose |
|---|---|
| Max Total Collateral | Limits total market size |
| Max User Collateral | Prevents concentration risk |
Auction Settings
For Dutch auction liquidations:| Setting | Description |
|---|---|
| Auction Duration | Time from start to minimum price |
| Start Premium | Initial price above oracle (e.g., 130%) |
| Minimum Premium | Floor price (e.g., 95% of oracle) |
Security Model
Upgradeability
Markets use the UUPS (Universal Upgradeable Proxy Standard) pattern:- Logic upgrades require Admin role
- Proxy address stays constant
- State preserved across upgrades
- Emergency fixes possible without redeployment
Reentrancy Protection
All state-changing functions protected against reentrancy attacks. External calls (token transfers, liquidation callbacks) happen after state updates.Pausability
Admins can pause markets during emergencies:- Stops new loans and borrows
- Repayments still allowed (users can exit)
- Liquidations continue (protecting the pool)
- Liquidity withdrawals permitted
Price Staleness
Oracle prices include timestamp validation:- Configurable maximum age (default: 24 hours)
- Stale prices block new borrows
- Protects against manipulation using old data
Contract Interactions
Opening a Loan
Liquidation Flow
Setup Guide
Deploy your first lending market
Liquidation Details
Liquidation modes and external integration
