LendCore

Lending ProtocolSepolia LiveNext.js Frontend

A decentralized isolated lending protocol built with Solidity 0.8.30 and Foundry, featuring UUPS upgradeable contracts, multi-sig governance with Timelock, health factor-based liquidations, ERC-4626 vault integration, and a real-time event-driven indexer backed by Supabase with a Next.js monitoring dashboard.

Core Features

Multi-Collateral Support

Whitelisted ERC20 tokens as collateral with health factor-based system preventing over-leveraging. Isolated markets keep risk contained per market pair.

Jump Rate Model

Dynamic interest rates (2%–60% APR) based on utilization. Base 2% → Optimal 80% kink → Steep 60% slope after kink, with 10% protocol fee on interest revenue.

Automated Liquidations

5% liquidation bonus protects lenders. Bad debt is isolated and tracked separately. Underwater positions can be liquidated atomically by any caller.

ERC-4626 Vaults

Standard-compliant vault tokens for yield bearing. Each market has its own Vault for lender deposits, with market-controlled borrowing and share-based accounting.

OracleRouter

Chainlink + TWAP price aggregation with staleness checks, confidence scoring, and 18-decimal internal normalization supporting 6/8/18 decimal tokens safely.

Real-Time Monitoring

Event-driven indexer (viem polling) writes market snapshots every 60s to Supabase. Next.js dashboard surfaces TVL, utilization, borrow rates, and oracle confidence in real time.

Frontend & Monitoring

A Next.js 16 app deployed on Vercel provides a full monitoring and interaction layer over the on-chain protocol. All data flows through a REST API backed by Prisma + Supabase.

Dashboard & Deposit UI

  • Market overview — TVL, total borrows, per-market severity
  • Deposit collateral and borrow against it per market
  • Per-user position tracking with live health factors
  • Recent liquidation event feed

Monitoring Sub-Pages

  • /monitoring/liquidity — Liquidity depth ratio over time
  • /monitoring/utilization — Utilization vs. optimal kink
  • /monitoring/rates — Borrow & lending APR history
  • /monitoring/oracle — Oracle confidence & price feeds

API Reference

EndpointMethodDescription
/api/vaultsGETAll markets with latest snapshot (TVL, utilization, severity)
/api/metrics?vault=<addr>GETCurrent metrics for a specific market
/api/history?signal=<type>&range=<r>GETTime-series data. Signals: liquidity, utilization, borrowRate, oracle. Ranges: 24h, 7d, 30d, 90d
/api/positions?user=<addr>GETUser positions across all markets (latest per market)
/api/liquidations?limit=<n>GETRecent liquidation events (default 20, max 100)
/api/indexerGET / POSTIndexer status; start/stop via POST {"action":"start"|"stop"}

Event-Driven Indexer

The indexer (frontend/src/lib/indexer/) bridges on-chain state to the Supabase database via viem event polling at a 15-second interval. Market snapshots are written every 60 seconds; user positions and liquidations update on each relevant event.

Event Listener

  • Polls MarketV1 via viem.watchContractEvent
  • CollateralDeposited / CollateralWithdrawn
  • Borrowed / Repaid / Liquidated
  • GlobalBorrowIndexUpdated

Snapshot Generator

  • Multicall reads on every event or 60s tick
  • Computes liquidityDepthRatio, distanceToKink
  • 4-level severity scoring (liquidity, APR, oracle)
  • Writes MarketSnapshot to Supabase

Position & Liquidation Tracker

  • Calls getUserPosition(user) on each user event
  • Stores collateral value, debt, health factor, borrowing power
  • Liquidation events upserted idempotently on (txHash, logIndex)

Database Schema

  • Market — static market registry
  • MarketSnapshot — periodic state (~1 row/market/60s)
  • UserPositionSnapshot — per-user health factor history
  • LiquidationEvent — on-chain liquidation records

Upgradeability & Governance

UUPS Proxy Pattern

  • ERC1967 compliant proxy contracts
  • 49-slot storage gap for safe future upgrades
  • Separated storage layout (MarketStorageV1)
  • Upgrade authorization enforced in implementation

Timelock Governance

  • TimelockController with 2-day delay on all owner actions
  • Emergency Guardian for instant borrow-only pause
  • Deposits, withdrawals, and repayments unaffected by pause
  • Multi-sig ready (Gnosis Safe compatible)
RoleCapabilitiesDelay
OwnerUpgrade contract, set parameters, add collateral2 days (via Timelock)
GuardianPause borrowing only (emergency)Instant
TimelockHolds ownership, enforces delay on all owner actions2 days
MultisigProposes and executes timelock operations

Sepolia Testnet Deployment

All contracts are deployed and verified on Sepolia testnet. The monitoring frontend is live on Vercel.

ContractAddress
MarketV1 (Proxy)0xC223...E907
Vault (ERC-4626)0xE554...D3B
OracleRouter0xaA6B...8bD7
InterestRateModel0x9997...7E0
MarketTimelock0xF36B...D838

Test Assets (Mock Tokens)

TokenAddress
USDC0x4949E3c0fBA71d2A0031D9a648A17632E65ae495
WETH0x4F61DeD7391d6F7EbEb8002481aFEc2ebd1D535c
WBTC0x773269dE75Ec35Bd786337407af9E725e0E32dD5

Security Architecture

Safety Mechanisms

  • ReentrancyGuard on all state-changing functions
  • Emergency Guardian for instant borrow-only pause
  • Oracle staleness checks prevent stale price exploitation
  • 18-decimal internal accounting prevents rounding errors
  • Storage Gaps (49 slots) for safe future upgrades

Risk Mitigation

  • Health factor prevents over-leveraging (LLTV 85%)
  • 5% liquidation bonus protects lenders
  • Bad debt isolated and tracked separately
  • 2-day Timelock on all governance actions
  • High utilization drives rates up, discouraging bank runs

Testing & Validation

91+ passing Foundry tests across unit, integration, governance, and upgrade scenarios. Complete NatSpec documentation throughout.

Test CategoryFocus
Market Unit TestsCollateral, borrowing, repayment, liquidations, health factors, emergency pause
Vault / ERC-4626Standard compliance, market-controlled borrows, share pricing
OraclePrice feed management, staleness checks, decimal normalization
GovernanceTimelock delays, guardian pause, role-based access, risk proposals
IntegrationFull lending cycles, price crash liquidation, bad debt scenarios
Upgrade SimulationUUPS proxy upgrade safety, storage layout compatibility