An interest rate monitoring and reimbursement service for Morpho protocol markets. This service tracks borrower positions across Morpho markets, calculates interest above configurable APR caps, and manages reimbursements to borrowers.
Company operates vaults that supply liquidity to Morpho markets. When borrowers pay interest rates above a defined cap, Company reimburses them for the excess amount. This service:
- Monitors borrower positions across 3 Morpho markets (Polygon)
- Tracks interest accrued by vaults (Company's earnings) and borrowers (their debt)
- Calculates interest amounts above APR caps
- Manages reimbursement pool and pending reimbursements
- Provides a dashboard for monitoring and alerting
┌─────────────────────────────────────────────────────────────┐
│ MORPHO PROTOCOL │
│ (On-chain markets, vault contracts, borrower positions) │
└────────────────────┬────────────────────────────────────────┘
│ GraphQL API + RPC
↓
┌─────────────────────────────────────────────────────────────┐
│ BACKEND SERVICE │
│ • Node.js/TypeScript/Express │
│ • PostgreSQL database │
│ • Daily scheduler (node-cron) │
│ • REST APIs for metrics & reimbursements │
└────────────────────┬────────────────────────────────────────┘
│ REST API
↓
┌─────────────────────────────────────────────────────────────┐
│ FRONTEND DASHBOARD │
│ • React + Vite │
│ • Real-time metrics display │
│ • Borrower tracking & alerts │
└─────────────────────────────────────────────────────────────┘
- wstETH/WETH (91.5% LLTV) - APR cap: 12%
- WBTC/USDC (86% LLTV) - APR cap: 10%
- WPOL/USDC (77% LLTV) - APR cap: 15%
- Compound WETH - Supplies WETH to wstETH/WETH market
- Compound USDT - Supplies USDC to WBTC/USDC market
- Steakhouse High Yield USDC - Supplies USDC to WPOL/USDC market
- Node.js 20.10+ with TypeScript
- Express for REST APIs
- PostgreSQL for data persistence
- ethers.js for Ethereum interactions
- node-cron for scheduled jobs
morphoService.ts
- Interfaces with Morpho GraphQL API and contracts
- Fetches market data (rates, total supply/borrow)
- Syncs borrower positions and vault allocations
- Seeds initial configuration (markets + vaults)
interestService.ts
- Processes daily borrower debt interest
- Calculates interest above APR caps
- Creates reimbursement records for borrowers
- Updates position debt balances
vaultSupplyService.ts
- Processes daily vault supply interest (Company's earnings)
- Tracks interest earned above caps
- Provides token-specific summaries (WETH, USDC)
reimbursementService.ts
- Queries reimbursement data by address
- Tracks pending borrower reimbursements
- Calculates vault reimbursement pool
- Processes reimbursement payments (stub for on-chain execution)
schedulerService.ts
- Runs daily at midnight UTC
- Orchestrates vault supply and borrower interest processing
- Provides manual trigger capability
Metrics API (/api/metrics)
GET /dashboard- Overview metrics (borrowers, vaults, rates)GET /borrowers- Paginated list of borrowersGET /above-cap- Positions exceeding APR capsGET /alerts- Rate alerts (critical/high thresholds)
Reimbursements API (/api/reimbursements)
GET /pending- Borrowers owed reimbursementsGET /vault-reimbursement-pool- Vault excess interest by tokenGET /address/:address- Reimbursement summary for any addressGET /address/:address/history- Historical reimbursements
Processing API (/api/reimbursement-processing)
POST /process-pending- Trigger reimbursement processing (simulated)GET /summary- Processing statistics
Admin API
POST /api/admin/trigger-daily-job- Manually trigger daily interest job
Core Tables:
markets- Tracked Morpho markets with APR capsvaults- Company-owned vault contractsvault_allocations- Vault supply positions per marketborrowers- Individual borrower addressesborrower_positions- Active borrowing positionsinterest_snapshots- Daily interest calculationsreimbursements- Reimbursement records with statusvault_supply_snapshots- Daily vault earnings tracking
1. Service Startup
↓
2. Check DB for markets/vaults
↓
3. Seed if needed (minimal: markets + vaults only)
↓
4. Sync vault allocations from Morpho API
↓
5. Start scheduler (midnight UTC)
↓
6. Daily Job Triggers:
├─ Fetch current market rates from Morpho
├─ Process vault supply interest
│ ├─ Calculate interest earned
│ └─ Track excess above cap
├─ Process borrower debt interest
│ ├─ Calculate interest accrued
│ ├─ Determine excess above cap
│ └─ Create reimbursement records
└─ Update all positions
# 1. Install dependencies
cd backend
npm install
# 2. Setup PostgreSQL
createdb company
# 3. Run migrations
npm run migrate:fresh
npm run migrate:vaults
npm run migrate:vault-supply
npm run migrate:loan-assets
# 4. Configure environment
# Create backend/.env with:
# DATABASE_URL=postgresql://localhost/company
# POLYGON_RPC=<your-polygon-rpc-url>
# 5. Start server (auto-initializes on first run)
npm run dev
# Server runs on http://localhost:3000
# Scheduler starts automatically
# Syncs vault allocations from Morpho API on startup# Test Morpho API connection
npm run test:morpho
# Manually seed markets/vaults
npm run seed:morpho
# Sync borrowers from Morpho
npm run sync:borrowers
# Run daily interest calculation
npm run daily:interest
# Process pending reimbursements
npm run process:reimbursements
# Test APR cap update
npm run test:cap-update
# Clean database (remove non-tracked markets)
npm run cleanup:db- React 18 with TypeScript
- Vite for fast dev server and builds
- Native CSS (no frameworks)
- Real borrower count across markets
- Active vault count
- Borrowers above/below APR caps
- Vaults with excess interest
- Today's earnings by token
- Individual market statistics
- Current borrow rates vs. caps
- Total borrowed amounts
- Borrower counts per market
- Paginated borrower directory
- Current debt and rates
- Market associations
- Status indicators
- Critical alerts (≥3x cap) - Red
- High alerts (2-3x cap) - Orange
- Rate multiplier badges
- Market-specific warnings
- Detailed view of over-cap positions
- Rate comparison (current vs. cap)
- Excess interest calculations
- Color-coded severity
- Pending Reimbursements: Borrowers owed money
- Vault Reimbursement Pool: Excess by token (WETH, USDC)
- Total reimbursable amounts
- Market breakdown
# 1. Install dependencies
cd frontend
npm install
# 2. Start dev server
npm run dev
# Dashboard runs on http://localhost:5173
# Connects to backend at http://localhost:3000cd frontend
npm run build
npm run previewEach market has a configured APR cap (e.g., 12% for wstETH/WETH). When the actual borrow rate exceeds this cap, borrowers are reimbursed for the excess.
Example:
- Market rate: 18% APR
- APR cap: 12%
- Excess: 6% APR
- Borrower owes 18% but pays net 12% (after reimbursement)
Company's vaults earn interest on supplied capital. The service tracks:
- Total interest earned per token
- Interest earned above the cap (excess that will be reimbursed to borrowers)
- Net earnings (total - excess)
- Daily job calculates interest above cap for each borrower
- Creates
pendingreimbursement records in database - Vault reimbursement pool tracks total owed by token
- On-chain execution (TODO): Vault contracts transfer tokens to borrowers
- Reimbursement status updates to
processed
Different markets use different loan assets:
- wstETH/WETH: Borrows and reimburses in WETH
- WBTC/USDC: Borrows and reimburses in USDC
- WPOL/USDC: Borrows and reimburses in USDC
All interest and reimbursement amounts are tracked and displayed with their respective token units.
DATABASE_URL=postgresql://localhost/company
POLYGON_RPC=https://polygon-rpc.com
PORT=3000VITE_API_URL=http://localhost:3000-
Start Backend:
cd backend && npm run dev- Server auto-initializes (seeds if needed, syncs allocations)
- Scheduler starts automatically
- APIs available at
http://localhost:3000
-
Start Frontend:
cd frontend && npm run dev- Dashboard available at
http://localhost:5173 - Auto-refreshes on code changes
- Dashboard available at
-
Test Daily Job:
POST http://localhost:3000/api/admin/trigger-daily-job -
Monitor Logs: Watch backend terminal for processing updates
cd backend
npm run build
npm startcd frontend
npm run build
# Serve dist/ with nginx, Vercel, or Netlify- Use managed PostgreSQL (AWS RDS, DigitalOcean, etc.)
- Run migrations on production database
- Ensure connection string is secure
- Backend logs include detailed processing summaries
- Health check endpoint:
GET /health - Consider adding Sentry or similar error tracking
- On-chain reimbursement execution: Implement actual vault contract calls to transfer tokens
- Email/Slack alerts: Notify when rates exceed thresholds
- Historical charts: Visualize rate trends over time
- Multi-chain support: Extend to Ethereum mainnet, Base, etc.
- Gas optimization: Batch reimbursements to reduce transaction costs
- Admin UI: Web interface for updating APR caps and configurations
MIT
For questions or issues, contact the Company team.