Back to Blog
·14 min

Building a DeFi Yield Farming Dashboard: Track APY, TVL, and Positions

Yield farming is one of the most complex DeFi areas. Building a dashboard that aggregates positions across protocols requires integrating with various smart contracts and subgraphs.

Data Architecture for Yield Farming

interface FarmingPosition {
  protocol: string; pool: string
  totalValueUsd: number; apr: number; apy: number; il: number
  rewards: Array<{ token: string; amount: number; valueUsd: number }>
}

interface YieldSummary {
  totalDeployed: number; totalValueUsd: number
  weightedApr: number; dailyEarnings: number
}

Fetching On-Chain Data via Subgraphs

import { gql, request } from 'graphql-request'
const UNISWAP_SUBGRAPH = 'https://api.thegraph.com/subgraphs/name/uniswap/v3'
const POSITIONS_QUERY = gql`
  query Positions($owner: String!) {
    positions(where: { owner: $owner }) {
      id, liquidity, depositedToken0, depositedToken1
      pool { token0 { symbol } token1 { symbol } }
    }
  }
`

Impermanent Loss Calculator

function calculateIL(entryPrice0: number, entryPrice1: number, currentPrice0: number, currentPrice1: number): number {
  const priceRatio = (currentPrice0 / currentPrice1) / (entryPrice0 / entryPrice1)
  return (2 * Math.sqrt(priceRatio) / (1 + priceRatio) - 1) * 100
}

The Bottom Line

The DeFi Dashboard from BreafIO provides portfolio tracking and APY comparisons. The DeFi Lending UI covers lending. The Crypto Portfolio Tracker gives a simpler view. The Analytics Dashboard offers charting, and the SaaS Starter Kit is great for yield farming SaaS.

Ready to Build?

Get started with our production-ready starter kits and ship your project faster.

Browse Starter Kits