Real-time DeFi Position Monitoring & Automated Rescue System for Somnia Networks
RescueStream is a comprehensive DeFi position monitoring platform that provides real-time health tracking, automated rescue capabilities, and an intuitive dashboard for managing lending positions on Somnia blockchain networks. Built with production-ready smart contracts, a robust relayer service, and a modern React frontend.

RescueStream monitors DeFi lending positions in real-time, calculating health factors, tracking liquidation risks, and providing automated rescue mechanisms to protect user positions. The platform integrates with Somnia Data Streams for real-time updates and uses Chainlink oracles and DEX price feeds for accurate position valuation.
- π Real-time Position Monitoring: Live health factor tracking with instant updates via Somnia Streams
- π Automated Alerts: Browser notifications and audio alerts for at-risk positions
- π€ Rescue Bot: Automated position rescue system with configurable thresholds
- π Price Oracle Integration: Chainlink and DEX price feeds with fallback mechanisms
- πΌ Wallet Integration: Seamless wallet connection via RainbowKit (MetaMask, WalletConnect)
- π¨ Modern UI: Responsive dashboard with position analytics, charts, and transaction history
- π Security First: Audited OpenZeppelin contracts with reentrancy protection and access controls
Monorepo structure:
- contracts (Hardhat Solidity):
LendingAdapter,RescueHelper - relayer (Node.js TypeScript): listens to on-chain
PositionUpdated, computes health, writes to Streams - frontend (React + Vite): streams dashboard, alerts, and rescue UX
flowchart LR
subgraph Contracts
LA[LendingAdapter]
RH[RescueHelper]
LA -- setHelper --> RH
RH -. authorized .-> LA
end
EV[PositionUpdated events]:::evt
LA -- emits --> EV
subgraph Relayer
RL[ethers provider\nhealth calc\nstreams writer]
end
EV --> RL
RL -- set(schema,data) --> ST[(Streams)]
subgraph Frontend
UI[React App]
end
ST --> UI
UI -- wallet --> RH
RH --> LA
classDef evt fill:#eef,stroke:#77f,color:#222;
Key flows:
- Positions are updated by protocol owner or
RescueHelperviaLendingAdapter.setPosition(helper is ACLβd). PositionUpdatedevents feed the relayer which computes health and pushes normalized rows to Streams.- The UI polls Streams for the latest rows, renders risk, and can trigger
rescueTopUponRescueHelper.
- LendingAdapter: Flexible position management with owner and helper authorization
- RescueHelper: Secure rescue mechanism with non-decreasing collateral enforcement
- Access Control: Role-based permissions with OpenZeppelin Ownable
- Reentrancy Protection: Safe contract interactions with ReentrancyGuard
- Event Listening: Real-time blockchain event monitoring with WebSocket support
- Health Calculation: Advanced position health computation with liquidation thresholds
- Price Oracle: Multi-source price feeds (Chainlink, Uniswap V2/V3, fallback)
- Circuit Breaker: Automatic fallback when price feeds fail
- Rescue Bot: Automated rescue execution with rate limiting
- REST API: Comprehensive API for metrics, bot control, and transaction history
- Real-time Streaming: Live position updates via Somnia Data Streams
- Health Factor Visualization: Interactive charts and sparklines
- Position Analytics: Detailed metrics including liquidation price and thresholds
- Transaction History: Complete rescue transaction tracking
- Bot Configuration: Dynamic bot settings management
- Alert System: Audio and browser notifications with configurable cooldowns
- Responsive Design: Optimized for desktop and mobile devices
- Performance Optimized: Virtualized lists for large datasets
Prereqs: Node 18+, npm, Git.
- Install (avoid OneDrive locking):
npm ci --ignore-scripts
npm rebuild esbuild
- Compile contracts:
npx hardhat compile
- Start local chain (keep running):
npx hardhat node
- Deploy to localhost:
npx hardhat run deploy/deploy.ts --network localhost
Note deployed addresses printed to console; deploy/deploy.ts also wires setHelper.
- Start relayer (new terminal):
cd relayer
SOMNIA_RPC_URL=http://127.0.0.1:8545 \
LENDING_ADDR=<LendingAdapter address> \
PRIVATE_KEY=0xac0974be...ff80 \
LOG_LEVEL=info \
PORT=8080 \
npx ts-node src/index.ts
- Start frontend (new terminal):
cd frontend
VITE_SOMNIA_RPC_URL=http://127.0.0.1:8545 \
VITE_RESCUE_HELPER_ADDRESS=<RescueHelper address> \
VITE_POSITION_SCHEMA_ID=0x00...00 \
VITE_POSITION_PUBLISHER=0x0000000000000000000000000000000000000000 \
npm run dev
See DEPLOYMENT.md for complete production deployment instructions.
cd frontend
vercel login
vercel --prodSet environment variables in Vercel dashboard:
VITE_SOMNIA_RPC_URLVITE_RESCUE_HELPER_ADDRESSVITE_POSITION_SCHEMA_IDVITE_POSITION_PUBLISHERVITE_RELAYER_URL(optional)VITE_WALLETCONNECT_ID(optional)
- Contracts: configure
maxTopUpDelta, and set helper viasetHelper(RescueHelper)post-deploy. - Relayer: replace stub pricing with oracle feeds; persist last processed block.
- Frontend: set real Streams
schemaIdandpublisherand configure WalletConnect ID. - All hardcoded localhost URLs have been removed - use environment variables.
- Smart Contracts: Solidity, Hardhat, OpenZeppelin
- Relayer: Node.js, TypeScript, Express, Ethers.js
- Frontend: React, TypeScript, Vite, RainbowKit, Wagmi, Viem
- Data Streaming: Somnia Data Streams SDK
- Testing: Jest, Vitest, React Testing Library
- Security: Slither, MythX (CI/CD integrated)
- Deployment: Vercel (frontend), Railway/Render (relayer)
- DEPLOYMENT.md: Complete production deployment guide
- docs/api.md: Relayer REST API documentation
- SECURITY.md: Security policy and best practices
rescuestream/
βββ contracts/ # Solidity smart contracts
β βββ LendingAdapter.sol
β βββ RescueHelper.sol
βββ relayer/ # Node.js TypeScript relayer service
β βββ src/
β β βββ index.ts # Main relayer entry point
β β βββ bot.ts # Automated rescue bot
β β βββ priceOracle.ts # Price feed integration
β β βββ computeHealth.ts
β βββ test/ # Unit tests
βββ frontend/ # React frontend application
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Route pages
β β βββ hooks/ # Custom React hooks
β β βββ main.tsx # Entry point
β βββ dist/ # Build output
βββ docs/ # Documentation
- Node.js 18+
- npm or yarn
- Git
# Clone the repository
git clone https://github.com/0xsupremedev/rescuestream.git
cd rescuestream
# Install dependencies
npm install
# Compile contracts
npx hardhat compileSee Local Development section for detailed setup instructions.
The system follows a three-tier architecture:
- Smart Contracts Layer: On-chain position management and rescue logic
- Relayer Layer: Event monitoring, health computation, and data streaming
- Frontend Layer: User interface, real-time updates, and wallet interaction
Data flows from blockchain events β relayer β Somnia Streams β frontend, enabling real-time position monitoring with minimal latency.
- Smart contracts use battle-tested OpenZeppelin libraries
- Comprehensive input validation and access controls
- Reentrancy protection on all state-changing functions
- Security scanning integrated into CI/CD pipeline
- See SECURITY.md for detailed security information
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
0xsupremedev
- GitHub: @0xsupremedev
- Email: 0xsupremedev@gmail.com
- OpenZeppelin for secure smart contract libraries
- Somnia Network for data streaming infrastructure
- RainbowKit and Wagmi for wallet integration
- Chainlink and Uniswap for price oracle feeds