Query lending rates, compare yield, get bridge and swap quotes — across protocols and chains, from a single CLI.
Built for AI agents and scripts. Stable JSON output, canonical identifiers (CAIP-2/CAIP-19), and deterministic exit codes make it easy to pipe into any workflow.
- Lending — query markets and rates from Aave, Morpho, and more (with DefiLlama fallback).
- Yield — compare opportunities across protocols and chains, filter by TVL and APY.
- Bridging — get cross-chain quotes (Across, LiFi) and bridge analytics (volume, chain breakdown).
- Swapping — get on-chain swap quotes (1inch, Uniswap).
- Chains & protocols — browse top chains by TVL, inspect chain TVL by asset, discover protocols, resolve asset identifiers.
- Automation-friendly — JSON-first output, field selection (
--select), strict mode, and a machine-readable schema export.
Installs the latest tagged release from GitHub:
curl -fsSL https://raw.githubusercontent.com/ggonzalez94/defi-cli/main/scripts/install.sh | shInstall a specific version (accepted: latest, stable, vX.Y.Z, X.Y.Z):
curl -fsSL https://raw.githubusercontent.com/ggonzalez94/defi-cli/main/scripts/install.sh | sh -s -- v0.1.1go install github.com/ggonzalez94/defi-cli/cmd/defi@latest- Download the right archive from GitHub Releases:
- Linux/macOS:
defi_<version>_<os>_<arch>.tar.gz - Windows:
defi_<version>_windows_<arch>.zip
- Linux/macOS:
- Verify checksums with
checksums.txt. - Extract and move
defiinto yourPATH.
go build -o defi ./cmd/defiVerify install:
defi version --longdefi providers list --results-only
defi chains top --limit 10 --results-only --select rank,chain,tvl_usd
defi chains assets --chain 1 --asset USDC --results-only # Requires DEFI_DEFILLAMA_API_KEY
defi assets resolve --chain base --symbol USDC --results-only
defi lend markets --protocol aave --chain 1 --asset USDC --results-only
defi lend rates --protocol morpho --chain 1 --asset USDC --results-only
defi yield opportunities --chain base --asset USDC --limit 20 --results-only
defi yield opportunities --chain 1 --asset USDC --providers aave,morpho --limit 10 --results-only
defi bridge list --limit 10 --results-only # Requires DEFI_DEFILLAMA_API_KEY
defi bridge details --bridge layerzero --results-only # Requires DEFI_DEFILLAMA_API_KEY
defi bridge quote --from 1 --to 8453 --asset USDC --amount 1000000 --results-onlyyield opportunities --providers accepts provider names from defi providers list (e.g. defillama,aave,morpho).
Bridge quote examples:
defi bridge quote --from 1 --to 8453 --asset USDC --amount 1000000 --results-only # Defaults to Across
defi bridge quote --provider lifi --from 1 --to 8453 --asset USDC --amount 1000000 --results-onlySwap quote example (1inch requires API key):
export DEFI_1INCH_API_KEY=...
defi swap quote --provider 1inch --chain 1 --from-asset USDC --to-asset DAI --amount 1000000 --results-onlyMost commands do not require provider API keys.
When a provider requires authentication, bring your own key:
defi swap quote --provider 1inch->DEFI_1INCH_API_KEYdefi swap quote --provider uniswap->DEFI_UNISWAP_API_KEYdefi chains assets->DEFI_DEFILLAMA_API_KEYdefi bridge list->DEFI_DEFILLAMA_API_KEYdefi bridge details->DEFI_DEFILLAMA_API_KEY
defi providers list includes both provider-level key metadata and capability-level key metadata (capability_auth).
DEFI_1INCH_API_KEY(required forswap quote --provider 1inch)DEFI_UNISWAP_API_KEY(required forswap quote --provider uniswap)DEFI_DEFILLAMA_API_KEY(required forchains assets,bridge list, andbridge details)
Configure keys with environment variables (recommended):
export DEFI_1INCH_API_KEY=...
export DEFI_UNISWAP_API_KEY=...
export DEFI_DEFILLAMA_API_KEY=...For persistent shell setup, add exports to your shell profile (for example ~/.zshrc).
If a keyed provider is used without a key, CLI exits with code 10.
Most users only need env vars for provider keys. Use config when you want persistent non-secret defaults (output mode, timeout/retries, cache behavior).
Config precedence is:
flags > env > config file > defaults
Default config path:
${XDG_CONFIG_HOME:-~/.config}/defi/config.yaml
Default cache paths:
${XDG_CACHE_HOME:-~/.cache}/defi/cache.db${XDG_CACHE_HOME:-~/.cache}/defi/cache.lock
Example optional config:
output: json
strict: false
timeout: 10s
retries: 2
cache:
enabled: true
max_stale: 5m- Command TTLs are fixed in code (
chains/protocols/chains assets:5m,lend markets:60s,lend rates:30s,yield:60s,bridge/swap quotes:15s). - Cache entries are served directly only while fresh (
age <= ttl). - After TTL expiry, the CLI fetches provider data immediately.
cache.max_stale/--max-staleis only a temporary provider-failure fallback window (currentlyunavailable/rate_limited).- If fallback is disabled (
--no-staleor--max-stale 0s) or stale data exceeds the budget, the CLI exits with code14. - Metadata commands (
version,schema,providers list) bypass cache initialization.
- Morpho can surface extreme APY values on very small markets. Prefer
--min-tvl-usdwhen ranking yield. chains assetsrequiresDEFI_DEFILLAMA_API_KEYbecause DefiLlama chain asset TVL is key-gated.bridge listandbridge detailsrequireDEFI_DEFILLAMA_API_KEY; quote providers (across,lifi) do not.- Category rankings from
protocols categoriesare deterministic and sorted bytvl_usd, then protocol count, then name. --chainnormalization supports additional EVM aliases and IDs includingmantle,megaeth/mega eth/mega-eth,ink,scroll,berachain,gnosis/xdai,linea,sonic,blast,fraxtal,world-chain,celo,taiko/taiko alethia, andzksync.- MegaETH bootstrap symbol parsing currently supports
MEGA,WETH, andUSDT(USDTmaps to the chain'sUSDT0contract address). Official Mega token list currently has no Ethereum L1MEGAtoken entry. - For chains without bootstrap symbol entries, pass token address or CAIP-19 via
--asset/--from-asset/--to-assetfor deterministic resolution. - For
lend/yield, unresolved asset symbols skip DefiLlama-based symbol matching and may disable fallback/provider selection to avoid unsafe broad matches.
0: success1: internal error2: usage/validation error10: auth required/failed11: rate limited12: provider unavailable13: unsupported input/provider pair14: stale data beyond SLA15: partial results in strict mode16: blocked by command allowlist
cmd/
defi/main.go # CLI entrypoint
internal/
app/runner.go # command wiring, routing, cache flow
providers/ # external adapters
aave/ morpho/ # direct lending + yield
defillama/ # normalization + fallback + bridge analytics
across/ lifi/ # bridge quotes
oneinch/ uniswap/ # swap
types.go # provider interfaces
config/ # file/env/flags precedence
cache/ # sqlite cache + file lock
id/ # CAIP + amount normalization
model/ # envelope + domain models
out/ # renderers
errors/ # typed errors / exit codes
schema/ # machine-readable CLI schema
policy/ # command allowlist
httpx/ # shared HTTP client
.github/workflows/ci.yml # CI (test/vet/build)
AGENTS.md # contributor guide for agents
go test ./...