Skip to main content

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 medianApy field in protocol endpoint
  • Logos: icons.llama.fi/{slug}.png

Protocol Metadata

The PROTOCOL_META array defines all supported Stacks DeFi protocols with their metadata and fallback values:
array
Array of protocol configuration objects

Example Protocol Entry

Main Function

fetchAllProtocolData()

Fetches live TVL and APY data for all protocols in parallel.
function
Returns enriched protocol data with live or fallback values
Returns: Promise<Array<ProtocolData>>
object
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’s medianApy field with fallback:

Error Handling

Uses Promise.allSettled() to ensure partial failures don’t break entire data fetch:

TVL Formatting

The service includes a formatTVL() helper that converts raw USD values to readable strings:

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

useProtocolData Hook

React hook wrapper with auto-refresh

Portfolio Protocols

Detect user positions in protocols