Skip to content

πŸ›‘οΈ Real-time DeFi monitoring & whale tracking platform for Stacks blockchain, powered by Chainhooks. Track swaps, liquidity events, and large transactions with live alerts.

License

Notifications You must be signed in to change notification settings

serayd61/stacks-defi-sentinel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

147 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ Stacks DeFi Sentinel

Real-time DeFi monitoring & whale tracking platform for the Stacks blockchain, powered by Chainhooks and Reown AppKit.

Stacks TypeScript React WalletConnect License: MIT

🌐 Live Demo

πŸ† Stacks Builder Challenge

This project is built for the Stacks Builder Challenge and demonstrates:

  • βœ… WalletKit SDK / Reown AppKit integration
  • βœ… On-chain smart contracts with real users and fees
  • βœ… Active GitHub development with multiple contributions

✨ Features

Core Features

  • πŸ”— Real-time Event Streaming - Uses Chainhooks to monitor blockchain events
  • πŸ’± DEX Swap Tracking - Monitor swaps across Velar, Arkadiko, ALEX
  • πŸ’§ Liquidity Pool Analytics - Track liquidity events and pool TVL
  • πŸ‹ Whale Alerts - Large transaction notifications (10K+ STX)
  • πŸ“Š Live Dashboard - Beautiful, responsive UI with real-time updates

Web3 Integration

  • πŸ” Reown AppKit / WalletConnect - Connect with any Stacks wallet
  • πŸ“± Multi-wallet Support - Xverse, Leather, Hiro Wallet, OKX
  • ⚑ Mobile Wallet Support - WalletConnect QR code for mobile

Subscription System

  • πŸ’³ On-chain Subscriptions - Pay with STX for premium features
  • 🎟️ Basic Plan - 1 STX/month for standard alerts
  • πŸ‘‘ Premium Plan - 2.5 STX/month for whale alerts + API access

SENTINEL Token (SNTL)

  • πŸͺ™ Governance Token - Vote on platform decisions
  • πŸ“ˆ Staking Rewards - Earn SNTL by staking
  • 🎁 Airdrops - Early adopter rewards
  • πŸ”’ Team Vesting - 6-month cliff, 12-month vesting

NEW: Advanced DeFi Features

  • 🏦 Lending Protocol - Collateralized borrowing with STX
  • πŸ“ˆ Price Oracle - Real-time price feeds for STX, sBTC, SNTL
  • πŸ” Multisig Treasury - N-of-M signature DAO treasury
  • πŸ’° Token Sale (ICO) - 3-tier pricing with 50M SNTL supply
  • ⚑ Liquidation Engine - Automatic unhealthy loan liquidation
  • πŸ† Builder Leaderboard - Track your rank in Stacks Builder Challenge
  • πŸ’Ό Portfolio Tracker - Monitor your tokens and NFTs
  • πŸ—³οΈ DAO Voting - On-chain governance proposals
  • 🎁 Referral System - Earn rewards by inviting friends

πŸ“œ Smart Contracts (Mainnet)

Contract Address Description
defi-sentinel SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB Subscription & alerts
sentinel-token SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB SNTL token (SIP-010)
sentinel-staking-v2 SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB Staking with tiered APY
sentinel-dao-v2 SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB DAO governance voting
token-sale-v8 SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB ICO with 3-tier pricing
sentinel-lending SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB Collateralized lending
sentinel-oracle SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB Price feeds for STX/sBTC/SNTL
sentinel-multisig-v2 SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB Multi-sig treasury

Contract Functions

defi-sentinel:

(define-public (subscribe)) ;; Subscribe for 1 STX/month
(define-public (subscribe-premium)) ;; Premium for 2.5 STX/month
(define-read-only (is-subscribed (user principal)))
(define-read-only (get-subscription (user principal)))

sentinel-token:

(define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))))
(define-public (mint (amount uint) (to principal))) ;; Owner only
(define-public (init-vesting)) ;; Start team vesting
(define-public (claim-vested)) ;; Claim vested tokens

sentinel-staking:

(define-public (stake (amount uint) (lock-period uint) (referrer (optional principal))))
(define-public (claim-rewards)) ;; Claim staking rewards
(define-public (unstake)) ;; Withdraw staked tokens
(define-public (add-to-stake (additional-amount uint))) ;; Add more tokens
(define-read-only (get-stake (staker principal))) ;; Get stake info
(define-read-only (calculate-pending-rewards (staker principal))) ;; Calculate rewards

sentinel-dao:

(define-public (create-proposal (title ...) (description ...) (proposal-type uint)))
(define-public (cast-vote (proposal-id uint) (vote-for bool)))
(define-public (execute-proposal (proposal-id uint)))
(define-public (delegate-voting-power (delegate principal)))

sentinel-lending:

(define-public (borrow (collateral-stx uint) (borrow-amount uint))) ;; Deposit STX, borrow SNTL
(define-public (add-collateral (amount uint))) ;; Add more collateral
(define-public (record-repayment (repay-amount uint))) ;; Repay loan
(define-public (liquidate (borrower principal))) ;; Liquidate unhealthy position
(define-read-only (get-health-factor (user principal))) ;; Check loan health
(define-read-only (get-max-borrow (collateral-stx uint))) ;; Max borrowable amount

sentinel-oracle:

(define-public (submit-prices (stx-price uint) (sbtc-price uint) (sntl-price uint)))
(define-read-only (get-stx-price)) ;; Get STX/USD price
(define-read-only (get-sbtc-price)) ;; Get sBTC/USD price
(define-read-only (get-all-prices)) ;; Get all prices
(define-read-only (is-price-fresh (asset-id uint))) ;; Check if price is fresh

sentinel-multisig:

(define-public (propose-stx-transfer (recipient principal) (amount uint) (memo ...)))
(define-public (sign-transaction (tx-id uint))) ;; Sign pending tx
(define-public (execute-transaction (tx-id uint))) ;; Execute when threshold met
(define-read-only (can-execute (tx-id uint))) ;; Check if ready to execute

πŸ“¦ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Stacks Node    │────▢│   Chainhooks     │────▢│  DeFi Monitor   β”‚
β”‚  (Blockchain)   β”‚     β”‚   (Event Stream) β”‚     β”‚    (Backend)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                          β”‚
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚                                 β”‚                                 β”‚
                        β–Ό                                 β–Ό                                 β–Ό
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚  REST API    β”‚                β”‚  WebSocket   β”‚                 β”‚   Frontend   β”‚
                 β”‚  Endpoints   β”‚                β”‚   Server     β”‚                 β”‚  Dashboard   β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                                          β”‚
                                                                                          β–Ό
                                                                                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                                                 β”‚ Reown AppKit β”‚
                                                                                 β”‚ WalletConnectβ”‚
                                                                                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

  • Frontend: React, Vite, TypeScript, Tailwind CSS
  • Backend: Fastify, Node.js, TypeScript
  • Blockchain: Stacks, Clarity Smart Contracts
  • Wallet: @stacks/connect, Reown AppKit, WalletConnect
  • Deployment: Vercel (frontend), Railway (backend)
  • Monitoring: Hiro Chainhooks

πŸš€ Quick Start

1. Clone and Install

git clone https://github.com/serayd61/stacks-defi-sentinel.git
cd stacks-defi-sentinel/defi-monitor
npm install

2. Configure Environment

Create a .env file:

# Chainhooks API Configuration
CHAINHOOKS_API_KEY=your-api-key-here

# Server Configuration
PORT=4000
HOST=0.0.0.0

# Network
STACKS_NETWORK=mainnet

# Webhook URL
WEBHOOK_BASE_URL=https://your-server.com

# Alert Thresholds
WHALE_ALERT_THRESHOLD_STX=100000
LARGE_SWAP_THRESHOLD_USD=50000

3. Start the Backend

npm run dev

4. Start the Frontend

cd frontend
npm install
npm run dev

Open http://localhost:3000 to view the dashboard!

πŸ“‘ Active Chainhooks

Hook Name Status Description
USDA Stablecoin Tracker βœ… Active Track USDA transfers
VELAR Token Tracker βœ… Active Monitor VELAR activity
DeFi Sentinel Subscriptions βœ… Active Track subscription events
Arkadiko Swaps βœ… Active Monitor Arkadiko DEX
ALEX DEX Swaps βœ… Active Monitor ALEX DEX
NFT Transfer Monitor βœ… Active Track NFT transfers
Liquidity Pool Events βœ… Active Monitor liquidity
DEX Swap Monitor βœ… Active General DEX tracking

πŸ“Š API Endpoints

Dashboard & Analytics

Endpoint Description
GET /api/dashboard Aggregated statistics
GET /api/volume Trading volume by period

Swaps & Liquidity

Endpoint Description
GET /api/swaps Recent swap transactions
GET /api/liquidity Liquidity events
GET /api/pools Top pools by TVL

Tokens & Alerts

Endpoint Description
GET /api/tokens Top tokens by volume
GET /api/transfers Token transfers
GET /api/alerts Whale activity alerts

WebSocket

Connect to /ws for real-time updates:

const ws = new WebSocket('wss://stacks-defi-sentinel-production.up.railway.app/ws');

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Event:', data);
};

πŸ” Security

  1. API Key Protection - Never expose Chainhooks API key
  2. Webhook Verification - Validate webhook payloads
  3. Rate Limiting - Implemented for public endpoints
  4. Smart Contract Auditing - Clarity best practices

πŸ—ΊοΈ Roadmap

Phase 1 - Core βœ…

  • Real-time dashboard
  • Chainhooks integration
  • Multi-wallet support
  • Subscription system
  • SENTINEL token
  • Reown AppKit integration

Phase 2 - Advanced Features βœ…

  • Builder Challenge Leaderboard
  • Portfolio Tracker with NFT support
  • Gas/Fee Tracker
  • DAO Governance Voting
  • Referral Reward System
  • Advanced Staking Contract
  • DEX Aggregator

Phase 3 - Expansion πŸš€

  • Telegram/Discord bot notifications
  • DEX listing (ALEX, Velar)
  • Mobile app (React Native)
  • Cross-chain analytics
  • AI-powered alerts

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE for details.

πŸ”— Links


Built with ❀️ for the Stacks ecosystem | Stacks Builder Challenge 2024


December 30, 2024 Update

New Contracts Deployed

  • airdrop, referral, token-burn, whitelist
  • reputation, achievement-badge, token-vesting, treasury

Total: 22+ mainnet contracts!


πŸ† Week 3 Builder Challenge Features

Chainhooks Integration

Real-time blockchain event monitoring using Hiro Chainhooks:

  • Token Transfer Monitoring - Track SENTINEL token movements
  • Staking Events - Real-time staking deposits/withdrawals
  • Whale Alerts - Large transaction detection
  • WebSocket Streaming - Live data to connected clients

WalletConnect Support

Full WalletConnect integration for seamless wallet connections:

  • βœ… Xverse Wallet
  • βœ… Leather Wallet
  • βœ… OKX Wallet
  • βœ… Asigna Multisig

Chainhook Predicates

Located in /chainhooks/predicates/:

{
  "scope": "contract_call",
  "contract_identifier": "SP2PEBKJ2W1ZDDF2QQ6Y4FXKZEDPT9J9R2NKD9WJB.sentinel-token",
  "method": "transfer"
}

Real-time Dashboard

  • Live transaction feed
  • Instant balance updates
  • Whale alert notifications
  • Block explorer integration

Built with ❀️ for Stacks Builder Challenge 2024

About

πŸ›‘οΈ Real-time DeFi monitoring & whale tracking platform for Stacks blockchain, powered by Chainhooks. Track swaps, liquidity events, and large transactions with live alerts.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •