Overview
The DefiLlama service integrates with DefiLlama’s API to fetch real-time Total Value Locked (TVL) and Annual Percentage Yield (APY) data for Stacks DeFi protocols. Location:src/services/defiLlamaService.js
API Strategy
Data Sources
- TVL:
api.llama.fi/protocol/{slug}- Works for all Stacks protocols - APY: Fetched from
medianApyfield in protocol endpoint - Logos:
icons.llama.fi/{slug}.png
Protocol Metadata
ThePROTOCOL_META array defines all supported Stacks DeFi protocols with their metadata and fallback values:
Array of protocol configuration objects
Example Protocol Entry
Main Function
fetchAllProtocolData()
Fetches live TVL and APY data for all protocols in parallel.Returns enriched protocol data with live or fallback values
Promise<Array<ProtocolData>>
Extended protocol object with live data
Usage Example
Implementation Details
TVL Fetching
The service prioritizes Stacks-specific chain TVL over total protocol TVL:APY Resolution
APY is sourced from DefiLlama’smedianApy field with fallback:
Error Handling
UsesPromise.allSettled() to ensure partial failures don’t break entire data fetch:
TVL Formatting
The service includes aformatTVL() helper that converts raw USD values to readable strings:
| Raw Value | Formatted |
|---|---|
| 1,234,567,890 | $1.23B |
| 45,600,000 | $45.60M |
| 431,000 | $431.0K |
| 850 | $850 |
Supported Protocols
StackingDAO
Liquid stacking protocol for STX
Zest Protocol
Bitcoin-backed lending with sBTC
ALEX Lab
Decentralized exchange and AMM
Bitflow
Liquidity pools and swaps
Hermetica
Yield optimization strategies
Velar
DEX with advanced trading features
Granite
Bitcoin-collateralized borrowing
Related
useProtocolData Hook
React hook wrapper with auto-refresh
Portfolio Protocols
Detect user positions in protocols