Coming Soon - This feature is currently under development. Stay tuned!
This document introduces how to use ChainStream to monitor DeFi protocol activities, including liquidity changes, large trades, yield tracking, and risk alerts.
Supported DeFi Protocols
DEX (Decentralized Exchanges)
Protocol Chains Supported Features Uniswap V2/V3 Ethereum, Polygon, Arbitrum, Base Trading, LP, Pool data PancakeSwap BSC Trading, LP, Pool data SushiSwap Multi-chain Trading, LP Raydium Solana Trading, LP Jupiter Solana Aggregated trading Curve Ethereum, Multi-chain Stablecoin trading, LP
Lending Protocols
Protocol Chains Supported Features Aave V3 Ethereum, Polygon, Arbitrum Lending, Liquidation, Rates Compound V3 Ethereum, Base Lending, Liquidation Venus BSC Lending, Liquidation Morpho Ethereum Lending optimization
Yield Aggregators
Protocol Chains Supported Features Yearn Finance Ethereum Vault strategies, Yields Convex Finance Ethereum Curve LP enhancement Beefy Finance Multi-chain Auto-compounding
Liquid Staking
Protocol Chains Supported Features Lido Ethereum ETH staking Rocket Pool Ethereum ETH staking Marinade Solana SOL staking
Monitoring Dimensions
1. Liquidity Monitoring
Monitored Events
Event Description Importance pool_createdNew pool creation Discover new opportunities liquidity_addAdd liquidity Confidence indicator liquidity_removeRemove liquidity ⚠️ Rug pull warning pool_updatePool parameter changes Protocol governance
Key Metrics
Metric Description Healthy Standard TVL Total Value Locked Stable or growing TVL Change Rate 24h/7d TVL change > -10%/day LP Holder Count LP Token holder distribution Dispersed is better Liquidity Depth Liquidity within ±2% price range Greater depth is better
Rug Pull Risk Signals
🔴 High Risk
🟡 Medium Risk
🟢 Low Risk
Single withdrawal > 30% of pool
24h cumulative withdrawal > 50%
LP concentrated in few addresses (< 5)
Single withdrawal > 10% of pool
LP lock expiring soon
Project team addresses start withdrawing
LP widely distributed
LP lock period > 6 months
TVL stable growth
2. Trading Monitoring
Real-time Trading Flow
Subscribe to real-time trades via WebSocket:
Event Type Description Data Fields swapDEX trade token_in, token_out, amount, price large_tradeLarge trade threshold, trade_details arbitrageArbitrage trade profit, path mevMEV-related trade type, extracted_value
// Subscribe to DEX trading flow
ws . subscribe ( 'defi_trades' , {
protocol: 'uniswap_v3' ,
chain: 'ethereum' ,
min_amount_usd: 10000
}, ( trade ) => {
console . log ( ` ${ trade . type } : ${ trade . token_in } → ${ trade . token_out } ` );
});
Trading Analysis Dimensions
Analysis Dimension Metric Significance Buy/Sell Pressure Buy volume/Sell volume ratio > 1 bullish Volume Trend Volume moving average Activity level Whale Behavior Large trade percentage Market impact Pair Popularity Trading frequency ranking Market attention
3. Yield Tracking
Tracked Content
Yield Type Description Calculation Method LP Mining Trading fees from providing liquidity Fees × Share percentage Lending Interest Deposit/borrow interest Principal × APY Staking Rewards Protocol token rewards Staked amount × Reward rate Airdrop Yields Protocol airdrops Snapshot holdings
Yield Metrics
Metric Description Notes APY Annual Percentage Yield (with compounding) Actual yield reference APR Annual Percentage Rate (without compounding) Base yield Impermanent Loss LP loss relative to holding Important risk factor Net Yield Yield - Gas - Impermanent Loss Final yield
Impermanent Loss Estimation
Impermanent Loss Formula Impermanent Loss = 2 × √(Price Ratio) / (1 + Price Ratio) - 1
Price Change Impermanent Loss ±10% -0.11% ±25% -0.64% ±50% -2.02% ±100% -5.72% ±200% -13.4%
4. Risk Alerts
Protocol-Level Risks
Risk Type Description Alert Trigger Large Withdrawal Significant liquidity reduction Single > 5% of pool TVL Plunge Rapid protocol TVL decline > 20% decline in 1h Flash Loan Attack Flash loan pattern detected Auto-detection Governance Attack Abnormal proposals or votes Auto-detection Oracle Anomaly Abnormal price data Deviation > 5%
Position-Level Risks
Risk Type Description Alert Trigger Liquidation Risk Lending position near liquidation Health factor < 1.2 Impermanent Loss LP impermanent loss expanding Loss > 5% Yield Decline Significant APY drop Decline > 50%
Alert Configuration Example
{
"alert_type" : "liquidity_remove" ,
"protocol" : "uniswap_v3" ,
"pool" : "0x..." ,
"threshold" : {
"type" : "percentage" ,
"value" : 10
},
"notification" : {
"webhook" : "https://your-server.com/webhook" ,
"email" : "alert@example.com"
}
}
Monitoring Scenarios
Scenario 1: New Pool Discovery
Goal : Discover newly created trading pools as early as possible
ws . subscribe ( 'pool_created' , {
chain: 'ethereum' ,
min_liquidity_usd: 10000
}, async ( pool ) => {
// Check token safety
const risk = await checkTokenRisk ( pool . token_address );
if ( risk . score > 60 ) {
notify ( `New pool found: ${ pool . pair_name } , Liquidity: $ ${ pool . liquidity_usd } ` );
}
});
Scenario 2: Rug Pull Warning
Goal : Monitor rug pull risk for held pools
Add Monitoring
Add target pool to monitoring list
Set Threshold
Set withdrawal threshold (e.g., single > 10%)
Receive Alerts
Receive real-time alerts
Adjust Position
Adjust position promptly
ws . subscribe ( 'liquidity_remove' , {
pool: '0x...' ,
threshold_percentage: 10
}, ( event ) => {
alert ( `⚠️ Rug pull warning: ${ event . percentage } % liquidity removed` );
});
Scenario 3: Arbitrage Opportunity Discovery
Goal : Discover cross-DEX price differences
Subscribe Price Feeds
Subscribe to price feeds from multiple DEXs
Calculate Spread
Calculate spread percentage
Cost Evaluation
Consider Gas and slippage costs
Send Alert
Alert when net profit > threshold
// Listen to prices from multiple DEXs
const prices = {};
ws . subscribe ( 'token_price' , {
token: 'WETH' ,
dex: [ 'uniswap' , 'sushiswap' , 'curve' ]
}, ( data ) => {
prices [ data . dex ] = data . price ;
checkArbitrage ( prices );
});
function checkArbitrage ( prices ) {
const maxPrice = Math . max ( ... Object . values ( prices ));
const minPrice = Math . min ( ... Object . values ( prices ));
const spread = ( maxPrice - minPrice ) / minPrice ;
if ( spread > 0.005 ) { // 0.5% spread
notify ( `Arbitrage opportunity: ${ spread * 100 } % spread` );
}
}
Scenario 4: Liquidation Monitoring
Goal : Monitor lending position health
Get Position
Get lending position for target address
Calculate Health Factor
Calculate real-time health factor
Warning
Warn when health factor < 1.5
Urgent Alert
Urgent alert when health factor < 1.2
async function monitorLiquidationRisk ( address : string ) {
const position = await getDefiPosition ( address , 'aave_v3' );
if ( position . health_factor < 1.2 ) {
urgentAlert ( `🚨 Liquidation risk! Health factor: ${ position . health_factor } ` );
} else if ( position . health_factor < 1.5 ) {
warnAlert ( `⚠️ Low health factor: ${ position . health_factor } ` );
}
}
Data Latency
Data Type Latency Description Real-time Trades < 3s Pushed after block confirmation TVL Data < 1min Minute-level updates APY Data < 5min Calculated from recent trades Holder Data < 1h Hourly snapshots
API Endpoints
Function Endpoint Get Protocol TVL GET /v1/defi/{protocol}/tvlGet Pool Info GET /v1/defi/{protocol}/pools/{pool_id}Get User Positions GET /v1/defi/{protocol}/positions/{address}Get Yield Data GET /v1/defi/{protocol}/yields
Arbitrage Scanner Build an arbitrage scanning tool
Price Alert Bot Build a price alert system