defillama

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package defillama is the library behind the defillama command line: the HTTP client, request shaping, and the typed data models for the DeFi Llama API.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every main request is built from.

View Source
const DefaultUserAgent = "defillama-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to DeFi Llama.

View Source
const Host = "api.llama.fi"

Host is the primary API host.

View Source
const StablecoinsURL = "https://stablecoins.llama.fi"

StablecoinsURL is the stablecoins subdomain.

View Source
const YieldsURL = "https://yields.llama.fi"

YieldsURL is the yields subdomain.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	Name   string  `json:"name"`
	Symbol string  `json:"symbol"`
	TVL    float64 `json:"tvl"`
}

Chain is a blockchain network.

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the DeFi Llama API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig returns a Client configured from cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches a URL and returns the response body.

func (*Client) GetProtocol

func (c *Client) GetProtocol(ctx context.Context, slug string) (*Protocol, error)

GetProtocol fetches a single protocol by slug.

func (*Client) ListChains

func (c *Client) ListChains(ctx context.Context, limit int) ([]*Chain, error)

ListChains fetches all chains sorted by TVL.

func (*Client) ListProtocols

func (c *Client) ListProtocols(ctx context.Context, category, chain string, limit int) ([]*Protocol, error)

ListProtocols fetches all protocols and applies optional filters.

func (*Client) ListStablecoins

func (c *Client) ListStablecoins(ctx context.Context, limit int) ([]*Stablecoin, error)

ListStablecoins fetches all stablecoins sorted by circulating USD.

func (*Client) ListYields

func (c *Client) ListYields(ctx context.Context, minAPY float64, chain, project string, stablecoinOnly bool, limit int) ([]*YieldPool, error)

ListYields fetches yield pools with optional filters.

type Config

type Config struct {
	BaseURL        string
	StablecoinsURL string
	YieldsURL      string
	UserAgent      string
	Rate           time.Duration
	Timeout        time.Duration
	Retries        int
}

Config holds the client configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the DeFi Llama driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity a host reuses for help and version.

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every DeFi Llama operation onto app.

type Protocol

type Protocol struct {
	Name     string  `json:"name"`
	Symbol   string  `json:"symbol"`
	Chain    string  `json:"chain"`
	Category string  `json:"category"`
	TVL      float64 `json:"tvl"`
	Change1D float64 `json:"change_1d"`
	Change7D float64 `json:"change_7d"`
	URL      string  `json:"url"`
}

Protocol is a DeFi protocol with TVL data.

type Stablecoin

type Stablecoin struct {
	Name      string  `json:"name"`
	Symbol    string  `json:"symbol"`
	PegType   string  `json:"peg_type"`
	Mechanism string  `json:"mechanism"`
	CircUSD   float64 `json:"circulating_usd"`
	Price     float64 `json:"price"`
}

Stablecoin is a pegged digital asset.

type YieldPool

type YieldPool struct {
	Chain      string  `json:"chain"`
	Project    string  `json:"project"`
	Symbol     string  `json:"symbol"`
	TVLUsd     float64 `json:"tvl_usd"`
	APY        float64 `json:"apy"`
	PoolID     string  `json:"pool_id"`
	Stablecoin bool    `json:"stablecoin"`
}

YieldPool is a DeFi yield farming pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL