This repository contains the Soroban smart contracts and related resources for the StellarLend protocol.
Contents:
- Overview
- Modules and Features
- Admin Operations
- Monitoring & Analytics
- Upgrade & Configuration
- Event Indexing
- Cross-Chain Bridge
- Social Recovery & Multisig
StellarLend is a lending and borrowing protocol built on Soroban. It features cross-asset accounting, risk management, governance, AMM integration, flash loans, and more.
- Borrow Function Tests - Comprehensive test suite documentation for the borrow functionality, covering all validation paths, edge cases, interest accrual, pause functionality, events, and security scenarios.
- Event Indexing Guide - Catalog of contract events, indexing options for RPC, Mercury, and SubQuery, and the current status of
stellar-lend/indexing_system/. - Upgrade Mechanism - Runbook for planned and emergency upgrades, rollback handling, and storage compatibility guidance.
- Interest rate model with smoothing
- Risk config and scoring
- Cross-asset positions and oracle support
- Flash loans with configurable fees
- AMM integration hooks (swap, add/remove liquidity)
- Cross-chain bridge interface with fees and events
- Analytics: global and per-user metrics, daily snapshots
- Monitoring: health, performance, and security alerts
- Social recovery: guardians, timelock approvals, execution
- Multisig for admin min-collateral changes
- Upgrade tracking and approval manager in
contracts/lending; seeupgrade-mechanism.mdfor current scope and limitations - Data management: generic data store, backup/restore, migration
- Configuration: versioned param store with backup/restore
Key admin entrypoints (see contract for full list):
initialize(admin)set_min_collateral_ratio(caller, ratio)set_risk_params(...),set_pause_switches(...)set_price_cache_ttl(caller, ttl)register_bridge(caller, network_id, bridge, fee_bps)set_bridge_fee(caller, network_id, fee_bps)upgrade_propose/approve/execute/rollbackin the separate lending workspace upgrade managerconfig_set/config_backup/config_restorems_set_admins,ms_propose_set_min_cr,ms_approve,ms_execute
record_user_action(user, action)updates risk and emits events- Analytics auto-update on deposit/borrow/repay/withdraw
- Monitoring entrypoints:
monitor_report_health/performance/security,monitor_get - Event indexing details, topic layouts, and decoding examples are documented in event-indexing.md
get_protocol_report()&get_user_report(address)surface typed structs (ProtocolReport,UserReport) containing current metrics, active-user counts, and the latest activity feed snapshot time.get_asset_report(asset)returnsAssetReportwith per-asset analytics and historical bucketed data.get_recent_activity(limit)supplies anActivityFeedwith newest-first entries, atotal_availablecounter (capped at 1,000 retained records), and thegenerated_atledger timestamp for indexers.- Activity entries include
user,activity_type,amount, optionalasset, and a metadata map for extended tags. - Example payloads:
protocol_report.jsonanduser_report.jsondemonstrate the serialized shape returned by the contract. Monetary totals are raw integers in the protocol’s smallest units, and percentage-style fields (e.g., utilization, success rate, health score) are exported as fixed-point integers scaled by1e6(333333≈ 33.3333%). - Field hints:
total_value_locked,total_deposits,total_borrows, etc. are cumulative atomic units across all assets.- Percentage-like values (e.g.,
avg_utilization_rate,protocol_risk_score,uptime_percentage,collateralization_ratio) use the same1e6scaling; divide by 1_000_000 to obtain human-readable percentages. - User analytics expose running totals plus derived scores (
activity_score,loyalty_tier) that map to reward tiers.
- Example Soroban call:
Returns a feed where
soroban contract invoke \ --id <contract-id> \ --fn get_recent_activity \ --arg limit=50
entries[0]is the most recent action; setlimitto0for metadata-only responses.
- The separate lending workspace ships an
UpgradeManagerwith proposal, approval, execute, and rollback metadata tracking upgrade_statusreturns tracked version state for that manager- See upgrade-mechanism.md for the exact process and the current limitation that code swaps are not automated by the manager itself
- Config supports version bumps, validation, and easy backup/restore
event-indexing.mdcovers the currenthello-worldevent surface, additional workspace contracts, testnet/mainnet indexing choices, and whystellar-lend/indexing_system/should currently be treated as deprecated prototype code
- Register networks and fees, and use
bridge_deposit/bridge_withdrawto move balances with transparent fees
- Set guardians per-user and execute timelocked recoveries
- Multisig supports proposing and executing admin changes with threshold