Query and act on DeFi lending, yield, bridge, and swap — 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/rates from Aave/Morpho/Kamino, account positions from Aave/Morpho, and execute loan actions (
lend supply|withdraw|borrow|repay). - Yield — compare opportunities, query positions, fetch historical series, and execute deposit/withdraw flows (Aave, Morpho).
- Bridging — get cross-chain quotes (Across, LiFi, Bungee), bridge analytics, and execute bridge plans (Across, LiFi).
- Swapping — get swap quotes (1inch, Uniswap, Jupiter, TaikoSwap, Fibrous, Bungee) and execute swap plans (TaikoSwap).
- Approvals, transfers & rewards — ERC-20 approvals/transfers and Aave rewards claim/compound flows.
- Chains & protocols — browse chains by TVL, inspect chain TVL by asset, discover protocols, resolve asset identifiers.
- Automation-friendly — JSON-first output, field selection (
--select), structured JSON/file input (--input-json,--input-file), and a machine-readable schema export with required flags, enums, auth, and request/response metadata.
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.4.0go 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 lend markets --provider aave --chain 1 --asset USDC --results-only
defi lend positions --provider aave --chain 1 --address 0xYourEOA --type all --results-only
defi yield opportunities --chain 1 --asset USDC --providers aave,morpho --limit 10 --results-only
defi yield history --chain 1 --asset USDC --providers aave --metrics apy_total --interval day --window 7d --limit 1 --results-only
defi bridge quote --provider across --from 1 --to 8453 --asset USDC --amount 1000000 --results-only
defi swap quote --provider taikoswap --chain taiko --from-asset USDC --to-asset WETH --amount 1000000 --results-only# Plan a swap (dry-run, no signer needed)
defi swap plan --provider taikoswap --chain taiko --from-asset USDC --to-asset WETH --amount 1000000 --from-address 0xYourEOA --results-only
# Execute a planned action (requires signer)
export DEFI_PRIVATE_KEY_FILE=~/.config/defi/key.hex
defi swap submit --action-id <action_id> --results-only
# Structured input for agents
defi lend supply plan --input-json '{"provider":"aave","chain":"1","asset":"USDC","amount":"1000000","from_address":"0xYourEOA"}' --results-only
# Inspect actions
defi actions list --results-only
defi actions estimate --action-id <action_id> --results-onlyswap plan|submit|status(TaikoSwap)bridge plan|submit|status(Across, LiFi)lend supply|withdraw|borrow|repay plan|submit|status(Aave, Morpho)yield deposit|withdraw plan|submit|status(Aave, Morpho)rewards claim|compound plan|submit|status(Aave)approvals plan|submit|statustransfer plan|submit|statusactions list|show|estimate
All plan commands support --rpc-url to override chain default RPCs.
plan and submit accept --input-json / --input-file for structured input; explicit flags override JSON values.
--providers flags accept provider names from defi providers list (e.g. aave,morpho,kamino).
defi swap quote --provider 1inch --chain 1 --from-asset USDC --to-asset DAI --amount 1000000 --results-only # requires DEFI_1INCH_API_KEY
defi swap quote --provider uniswap --chain 1 --from-asset USDC --to-asset DAI --amount 1000000 --from-address 0xYourEOA --results-only # requires DEFI_UNISWAP_API_KEY
defi swap quote --provider uniswap --chain 1 --from-asset USDC --to-asset DAI --type exact-output --amount-out 1000000000000000000 --from-address 0xYourEOA --results-only
defi bridge quote --provider lifi --from 1 --to 8453 --asset USDC --amount 1000000 --from-amount-for-gas 100000 --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_KEYdefi swap quote --provider taikoswap-> no API key required
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.
Execution submit commands currently support a local key signer.
Key input precedence:
--private-key(hex string, one-off override; less safe)- env/file/keystore inputs below (when
--private-keyis not provided)
Key env/file inputs (in precedence order when --key-source auto and --private-key is unset):
DEFI_PRIVATE_KEY(hex string, supported but less safe)DEFI_PRIVATE_KEY_FILE(preferred explicit key-file path)- default key file:
~/.config/defi/key.hex(or$XDG_CONFIG_HOME/defi/key.hexwhenXDG_CONFIG_HOMEis set) DEFI_KEYSTORE_PATH+ (DEFI_KEYSTORE_PASSWORDorDEFI_KEYSTORE_PASSWORD_FILE)
You can force source selection with --key-source env|file|keystore.
submit commands support optional --from-address as an explicit signer-address guard.
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
execution:
actions_path: ~/.cache/defi/actions.db
actions_lock_path: ~/.cache/defi/actions.lock
providers:
uniswap:
api_key_env: DEFI_UNISWAP_API_KEYswap quote (on-chain quote providers) and execution plan --rpc-url flags override chain default RPCs for that invocation.
submit/status commands use stored per-step RPC URLs from the persisted action.
internal/registry: canonical execution endpoints/contracts/ABI fragments and default chain RPC map used when no--rpc-urlis provided.internal/providers/*/client.go: provider quote/read API base URLs and external source URLs.internal/id/id.go: bootstrap token symbol/address registry used for deterministic symbol parsing.
- Command TTLs are fixed in code (
chains/protocols/chains assets:5m,lend markets:60s,lend rates:30s,lend positions:30s,yield opportunities:60s,yield positions:30s,yield history:5m,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. - Execution commands (
swap|bridge|approvals|transfer|lend|yield|rewards ... plan|submit|status,actions list|show|estimate) bypass cache reads/writes.
- Morpho can surface extreme APY values on very small markets; use
--min-tvl-usdwhen ranking. yield opportunitiesreturnsapy_total,tvl_usd,liquidity_usd, andbacking_assets(objective metrics only).yield history --metricssupportsapy_totalandtvl_usd; Aave currently supportsapy_totalonly. Use--windowfor Aave history.lend positions --type allreturns disjoint rows:supply,collateral, andborrow.- For chains without bootstrap symbol entries, pass token address or CAIP-19 for deterministic resolution.
--chainsupports CAIP-2, numeric IDs, and aliases (mantle,megaeth,taiko,gnosis,linea,zksync,hyperevm,monad,citrea, and more).
swap quote --typedefaults toexact-input;exact-outputis Uniswap-only (--amount-out/--amount-out-decimal).- Uniswap requires
--from-address;--slippage-pctis optional (default: provider auto). fibrouscurrently supportsbase,hyperevm, andcitrea.- Bungee dedicated backend requires both
DEFI_BUNGEE_API_KEYandDEFI_BUNGEE_AFFILIATE.
yieldandlendare split by intent:yieldfor passive deposits/withdrawals,lendfor loan lifecycle.- Morpho:
yield deposit|withdrawtargets vaults (--vault-address),lendtargets markets (--market-id). - Aave execution auto-resolves pool addresses on Ethereum, Optimism, Polygon, Base, Arbitrum, and Avalanche; use
--pool-addresson other chains. - Bridge execution waits for destination settlement; adjust
--step-timeoutfor slower routes. - Pre-sign checks enforce bounded ERC-20 approvals by default; use
--allow-max-approvalto opt in to larger approvals. - Bridge pre-sign checks validate settlement endpoints; use
--unsafe-provider-txto bypass. - All
submitcommands broadcast signed transactions. --provideris required for multi-provider flows (no implicit defaults).
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 allowlist20: action plan validation failed21: action simulation failed22: execution rejected by policy23: action timed out while waiting for confirmation24: signer unavailable or signing failed
cmd/
defi/main.go # CLI entrypoint
internal/
app/runner.go # command wiring, routing, cache flow
providers/ # external adapters
aave/ morpho/ # lending + yield (read + execution)
defillama/ # normalization + fallback + bridge analytics
across/ lifi/ # bridge quotes + lifi execution planning
oneinch/ uniswap/ taikoswap/ # swap (quote + taikoswap execution planning)
types.go # provider interfaces
execution/ # action store + planner helpers + signer + executor
registry/ # canonical execution endpoints/contracts/ABI fragments
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)
.github/workflows/nightly-execution-smoke.yml # nightly live execution planning smoke
docs/ # Mintlify docs site (docs.json + MDX pages)
AGENTS.md # contributor guide for agents
go test ./...
go test -race ./...
go vet ./...
bash scripts/nightly_execution_smoke.shThe docs/ directory contains a Mintlify docs site (docs.json + .mdx pages).
cd docs
npx --yes mint@4.2.378 dev --no-open # local preview
npx --yes mint@4.2.378 validate # validate before publishing
npx --yes mint@4.2.378 broken-links
npx --yes mint@4.2.378 a11yProduction docs deploy from the docs-live branch, which the release workflow syncs on stable (non-prerelease) tags.
