11# DeFi CLI
22
3- Rust CLI for interacting with 60+ DeFi protocols on HyperEVM. Agent-first design with JSON output, schema introspection, and MCP server.
3+ Rust CLI for interacting with DeFi protocols on HyperEVM. Agent-first design with JSON output, schema introspection, and MCP server.
44
55## Install
66
77``` bash
8- # From source
9- cargo install --path crates/defi-cli
10-
11- # Or build
128cargo build --release
139./target/release/defi --help
1410```
@@ -25,14 +21,20 @@ defi lending rates --protocol hyperlend --asset USDC --json
2521# Compare yields across protocols
2622defi yield compare --asset USDC --json
2723
28- # Build a swap transaction (dry-run by default)
29- defi dex swap --protocol hyperswap-v3 --token-in WHYPE --token-out USDC --amount 1.0 --json
24+ # Query asset prices from oracles
25+ defi price --asset WHYPE --json
26+
27+ # Check health factor / lending position
28+ defi lending position --protocol hyperlend --address 0x... --json
3029
31- # Supply to lending pool (dry-run)
32- defi lending supply --protocol hyperlend --asset USDC --amount 100.0 --json
30+ # Felix CDP trove info
31+ defi cdp info --protocol felix --position < trove_id > --json
3332
34- # Stake HYPE for kHYPE (dry-run)
35- defi staking stake --protocol kinetiq --amount 10.0 --json
33+ # Staking info (exchange rate, TVL)
34+ defi staking info --protocol kinetiq --json
35+
36+ # Build a swap transaction (dry-run by default)
37+ defi dex swap --protocol hyperswap-v2 --token-in WHYPE --token-out USDC --amount 1.0 --json
3638
3739# Actually broadcast (requires DEFI_PRIVATE_KEY)
3840export DEFI_PRIVATE_KEY=0x...
@@ -43,68 +45,127 @@ defi lending supply --protocol hyperlend --asset USDC --amount 100.0 --broadcast
4345
4446| Command | Description |
4547| ---------| -------------|
46- | ` status ` | Chain info and protocol list ( ` --verify ` for on-chain check) |
48+ | ` status ` | Chain info and protocol list |
4749| ` schema ` | JSON Schema for any action (agent-friendly) |
4850| ` dex ` | ` swap ` , ` quote ` , ` compare ` |
4951| ` lending ` | ` supply ` , ` borrow ` , ` repay ` , ` withdraw ` , ` rates ` , ` position ` |
5052| ` cdp ` | ` open ` , ` adjust ` , ` close ` , ` info ` |
51- | ` bridge ` | ` send ` , ` quote ` |
5253| ` staking ` | ` stake ` , ` unstake ` , ` info ` |
5354| ` vault ` | ` deposit ` , ` withdraw ` , ` info ` |
55+ | ` gauge ` | ` deposit ` , ` withdraw ` , ` claim ` , ` lock ` , ` vote ` (ve(3,3)) |
5456| ` yield ` | ` compare ` , ` optimize ` |
55- | ` wallet ` | ` balance ` |
57+ | ` price ` | Oracle and DEX price queries |
5658| ` token ` | ` balance ` , ` approve ` , ` allowance ` , ` transfer ` |
59+ | ` wallet ` | ` balance ` |
5760| ` agent ` | JSON stdin batch mode for AI agents |
5861
59- ## Output Modes
60-
61- ``` bash
62- --json # JSON output
63- --ndjson # Newline-delimited JSON
64- --fields a,b # Filter output fields
65- ```
66-
67- ## Safety
68-
69- - All mutation operations default to ` --dry-run `
70- - Use ` --broadcast ` to actually send transactions
71- - Requires ` DEFI_PRIVATE_KEY ` environment variable for broadcast
72-
73- ## Agent Mode
74-
75- Send JSON commands via stdin:
76-
77- ``` bash
78- echo ' {"action":"dex.swap","params":{"protocol":"hyperswap-v3","token_in":"WHYPE","token_out":"USDC","amount":"1.0"}}' | defi agent
79- ```
80-
81- Available actions: ` status ` , ` list_protocols ` , ` schema ` , ` dex.swap ` , ` dex.quote ` , ` lending.supply ` , ` lending.borrow ` , ` lending.repay ` , ` lending.withdraw ` , ` staking.stake ` , ` staking.unstake ` , ` vault.deposit ` , ` vault.withdraw ` , ` cdp.open `
82-
83- ## MCP Server
84-
85- Run as an MCP server for AI agent integration:
86-
87- ``` bash
88- defi-mcp
89- ```
90-
91- Exposes 7 tools: ` defi_status ` , ` defi_list_protocols ` , ` defi_dex_swap ` , ` defi_lending_supply ` , ` defi_lending_rates ` , ` defi_staking_stake ` , ` defi_vault_deposit `
92-
93- ## Supported Protocols (60)
94-
95- | Category | Count | Protocols |
96- | ----------| -------| -----------|
97- | DEX | 15 | HyperSwap V3/V2, Project X, KittenSwap, NEST, Curve, Balancer V3, Ring Few, Ramses CL/HL, WOOFi, Valantis, Wombat, Hybra, Hyperliquid Spot |
98- | Lending | 8 | HyperLend, Morpho, Euler V2, HypurrFi, TermMax, Hyperdrive, HypurrFi Isolated, Teller |
99- | Liquid Staking | 4 | Kinetiq (kHYPE), stHYPE, Hyperbeat LST, Kintsu |
100- | CDP | 2 | Felix, Parallel |
101- | Bridge | 4 | Hyperliquid Bridge, Hyperlane, SoDEX, Symbiosis |
102- | Yield Source | 10 | Pendle, Spectra, Penpie, Felix USDhl, Equilibria, Looped Hype, GrowiHF, Harmonix, HyperWave, Wrapped HLP |
103- | Yield Aggregator | 4 | Beefy, Hyperbeat Earn, Kinetiq Earn, Lazy Summer |
104- | Vault | 4 | Veda, Upshift, Felix Vaults, D2 Finance |
105- | Derivatives | 3 | Hyperliquid HLP, Derive V2, Kinetiq Markets |
106- | Options | 2 | Rysk V12, Hypersurface |
107- | Other | 4 | Steer, Liminal, Altura, Rumpel |
62+ ## Supported Protocols
63+
64+ ### DEX (15) — all LIVE
65+
66+ | Protocol | Interface | App | Contracts |
67+ | ----------| -----------| -----| -----------|
68+ | HyperSwap V3 | uniswap_v3 | — | router: ` 0x4E2960a8cd19B467b82d26D83fAcb0fAE26b094D ` |
69+ | HyperSwap V2 | uniswap_v2 | — | router: ` 0xb4a9C4e6Ea8E2191d2FA5B380452a634Fb21240A ` |
70+ | KittenSwap Algebra | algebra_v3 | [ kittenswap.finance] ( https://kittenswap.finance ) | router: ` 0x4e73E421480a7E0C24fB3c11019254edE194f736 ` |
71+ | NEST V1 | algebra_v3 | [ app.nest.exchange] ( https://app.nest.exchange ) | router: ` 0xaA26B8e5Cadd04430c32787eCC3AA325e99681e9 ` |
72+ | Project X | uniswap_v3 | — | router: ` 0x1EbDFC75FfE3ba3de61E7138a3E8706aC841Af9B ` |
73+ | Ramses CL | solidly_cl | [ app.ramses.exchange] ( https://app.ramses.exchange ) | router: ` 0x76D91074B46fF76E04FE59a90526a40009943fd2 ` |
74+ | Ramses HL | solidly_v2 | [ app.ramses.exchange] ( https://app.ramses.exchange ) | router: ` 0xdcC44285fBc236457A5cd91C2f77AD8421B0D8ED ` |
75+ | Ring Few | solidly_v2 | — | router: ` 0x701D1d675415efA2d2429fB122ccC6dD4FCcA959 ` |
76+ | Curve DEX | curve_stableswap | [ curve.fi] ( https://curve.fi ) | factory: ` 0x5eeE3091f747E60a045a2E715a4c71e600e31F6E ` |
77+ | Balancer V3 | balancer_v3 | [ balancer.fi] ( https://balancer.fi ) | vault: ` 0xbA1333333333a1BA1108E8412f11850A5C319bA9 ` |
78+ | WOOFi Swap | woofi | [ fi.woo.org] ( https://fi.woo.org ) | router: ` 0x4c4AF8DBc524681930a27b2F1Af5bcC8062E6fB7 ` |
79+ | Valantis STEX | valantis | — | router: ` 0x5Abe35DDb420703bA6Dd7226ACDCb24be71192e5 ` |
80+ | Wombat Exchange | wombat | — | router: ` 0x7Afa6bEecBdfA7b8c9d0E1F2a3B4C5D6E7F8a9b0 ` |
81+ | Hybra V4 | hybra | — | router: ` 0xCAfDa2b3E5c2B5E30f6d67FEFa5AfFD3f6a93b0a ` |
82+ | Hyperliquid Spot | orderbook_api | [ app.hyperliquid.xyz] ( https://app.hyperliquid.xyz ) | — |
83+
84+ ### Lending (8)
85+
86+ | Protocol | Interface | Status | App | Key Contract |
87+ | ----------| -----------| --------| -----| -------------|
88+ | HyperLend | aave_v3 | LIVE | [ app.hyperlend.finance] ( https://app.hyperlend.finance ) | pool: ` 0x00A89d7a5A02160f20150EbEA7a2b5E4879A1A8b ` |
89+ | HypurrFi Pooled | aave_v3 | LIVE | [ app.hypurr.fi] ( https://app.hypurr.fi ) | pool: ` 0xceCcE0EB9DD2Ef7996e01e25DD70e461F918A14b ` |
90+ | Felix Morpho | morpho_blue | LIVE | [ usefelix.xyz/lend] ( https://www.usefelix.xyz/lend ) | morpho: ` 0x68e37dE8d93d3496ae143F2E900490f6280C57cD ` |
91+ | Euler V2 | euler_v2 | LIVE | [ app.euler.finance] ( https://app.euler.finance ) | evk_vault: ` 0xac207ffa0bfce194db18d1820902d48a2d948968 ` |
92+ | HypurrFi Isolated | aave_v3 | LIVE | [ app.hypurr.fi/markets/isolated] ( https://app.hypurr.fi/markets/isolated ) | — (Fraxlend fork, addresses TBD) |
93+ | TermMax | termmax | — | — | — |
94+ | Hyperdrive HL | hyperdrive | — | — | — |
95+ | Teller | teller | — | — | — |
96+
97+ ### Liquid Staking (4) — all LIVE
98+
99+ | Protocol | Interface | App | Key Contract |
100+ | ----------| -----------| -----| -------------|
101+ | Kinetiq | kinetiq_staking | [ kinetiq.xyz] ( https://kinetiq.xyz ) | staking: ` 0x393D0B87Ed38fc779FD9611144aE649BA6082109 ` , kHYPE: ` 0xfD739d4e423301CE9385c1fb8850539D657C296D ` |
102+ | stHYPE | sthype_staking | — | staking: ` 0xB96f07367e69e86d6e9C3F29215885104813eeAE ` , stHYPE: ` 0xfFaa4a3D97fE9107Cef8a3F48c069F577Ff76cC1 ` |
103+ | Hyperbeat LST | hyperbeat_lst | — | staking: ` 0xCeaD893b162D38e714D82d06a7fe0b0dc3c38E0b ` , beHYPE: ` 0xd8FC8F0b03eBA61F64D08B0bef69d80916E5DdA9 ` |
104+ | Kintsu | kintsu | — | staking: ` 0xDDC126c12F9F8DF5a6fC273f6D43C1E21b4d2945 ` , sHYPE: ` 0xBeF0142A0955a7d5dcCe5C2A13Fb84E332669D2d ` |
105+
106+ ### CDP (2)
107+
108+ | Protocol | Interface | Status | App | Key Contract |
109+ | ----------| -----------| --------| -----| -------------|
110+ | Felix | liquity_v2 | LIVE | [ usefelix.xyz/borrow] ( https://www.usefelix.xyz/borrow ) | borrower_ops: ` 0xadfba621a75beced7dd1727b2067047b7eeedc8b ` , trove_mgr: ` 0x58446c58caa8a6f6cc8be343f812ebf0b997c001 ` , feUSD: ` 0x02c6a2fA58cC01A18B8D9E00eA48d65E4dF26c70 ` |
111+ | Parallel Protocol V3 | parallel | — | — | — |
112+
113+ ### Vault (4)
114+
115+ | Protocol | Interface | Status | App | Key Contract |
116+ | ----------| -----------| --------| -----| -------------|
117+ | Felix Vaults | erc4626 | LIVE | [ usefelix.xyz/lend] ( https://www.usefelix.xyz/lend ) | feHYPE: ` 0x2900ABd73631b2f60747e687095537B673c06A76 ` , feUSDC: ` 0x8A862fD6c12f9ad34C9c2ff45AB2b6712e8CEa27 ` |
118+ | Upshift | erc4626 | LIVE | [ app.upshift.fi] ( https://app.upshift.fi ) | — (addresses TBD) |
119+ | Veda | erc4626 | LIVE (infra) | — | Powers Kinetiq Earn / Mizu vaults |
120+ | D2 Finance | erc4626 | LIVE | [ d2.finance] ( https://d2.finance ) | — (addresses TBD) |
121+
122+ ### Yield Source (10)
123+
124+ | Protocol | Interface | Status | App | Key Contract |
125+ | ----------| -----------| --------| -----| -------------|
126+ | Pendle | pendle_v2 | LIVE | [ app.pendle.finance] ( https://app.pendle.finance ) | router: ` 0x888888888889758F76e7103c6CbF23ABbF58F946 ` |
127+ | Spectra V2 | spectra | LIVE | [ app.spectra.finance] ( https://app.spectra.finance ) | 5 pools (dnHYPE, USDT0, wVLP, hbHYPE, WHYPE) |
128+ | Penpie | penpie | — | — | — |
129+ | Felix USDhl | erc4626 | — | — | — |
130+ | Equilibria | equilibria | — | — | — |
131+ | Looped Hype | erc4626 | — | — | — |
132+ | GrowiHF | growi | — | — | — |
133+ | Harmonix Finance | harmonix | — | — | — |
134+ | HyperWave | erc4626 | — | — | — |
135+ | Wrapped HLP | erc4626 | — | — | — |
136+
137+ ### Yield Aggregator (4)
138+
139+ | Protocol | Interface | Status | App |
140+ | ----------| -----------| --------| -----|
141+ | Beefy | beefy_vault | LIVE | [ app.beefy.com] ( https://app.beefy.com ) |
142+ | Lazy Summer | erc4626 | LIVE | [ summer.fi] ( https://summer.fi ) |
143+ | Hyperbeat Earn | erc4626 | — | — |
144+ | Kinetiq Earn | erc4626 | — | — |
145+
146+ ### Derivatives (3)
147+
148+ | Protocol | Interface | Status | App | Key Contract |
149+ | ----------| -----------| --------| -----| -------------|
150+ | Kinetiq Markets | kinetiq_markets | LIVE | [ kinetiq.xyz] ( https://kinetiq.xyz ) | kmHYPE: ` 0x360C140E5344A1A0593D44B4ea6Fc7C3DAf0C473 ` |
151+ | Derive V2 | derive_v2 | LIVE (bridge vault) | [ derive.xyz] ( https://derive.xyz ) | Core on Derive Chain |
152+ | Hyperliquid HLP | hlp_vault | — | — | — |
153+
154+ ### Options (2)
155+
156+ | Protocol | Interface | Status |
157+ | ----------| -----------| --------|
158+ | Rysk V12 | rysk | — |
159+ | Hypersurface | hypersurface | — |
160+
161+ ### Other (4)
162+
163+ | Protocol | Interface | Status |
164+ | ----------| -----------| --------|
165+ | Steer Protocol | steer | — |
166+ | Liminal | liminal | — |
167+ | Altura | altura | — |
168+ | Rumpel Labs | rumpel | — |
108169
109170## Architecture
110171
@@ -114,41 +175,38 @@ defi-cli/
114175 config/ # TOML protocol registry (compiled in)
115176 crates/
116177 defi-core/ # Traits, types, registry, provider
117- defi-protocols/ # Protocol adapters (23 implementations)
178+ defi-protocols/ # Protocol adapters
118179 defi-cli/ # CLI binary
119180 defi-mcp/ # MCP server binary
120- SKILL.md # AI agent usage guide
121181```
122182
123- ## Tech Stack
183+ ## Gas Optimization
124184
125- | Role | Choice |
126- | ------| --------|
127- | Language | Rust |
128- | EVM | alloy (` sol! ` macro for compile-time ABI) |
129- | CLI | clap (derive) |
130- | Async | tokio |
131- | Serialization | serde + serde_json |
132- | Config | TOML (embedded at compile time) |
133- | Error | thiserror |
185+ - EIP-1559 gas pricing (auto-fetches baseFee + priorityFee)
186+ - 20% gas buffer on estimates to prevent out-of-gas
187+ - Dynamic ` eth_estimateGas ` in both simulation and broadcast modes
134188
135- ## Development
189+ ## Safety
136190
137- ``` bash
138- # Build
139- cargo build
191+ - All mutation operations default to ` --dry-run `
192+ - Use ` --broadcast ` to actually send transactions
193+ - Requires ` DEFI_PRIVATE_KEY ` environment variable for broadcast
194+ - Transaction simulation via ` eth_call ` before broadcast
140195
141- # Check
142- cargo check
196+ ## Agent Mode
143197
144- # Lint
145- cargo clippy
198+ ``` bash
199+ echo ' {"action":"dex.swap","params":{"protocol":"hyperswap-v2","token_in":"WHYPE","token_out":"USDC","amount":"1.0"}}' | defi agent
200+ ```
146201
147- # Test on fork
148- anvil --fork-url https://rpc.hyperliquid.xyz/evm --port 8546
149- # Then update config/chains.toml rpc_url to http://localhost:8546
202+ ## MCP Server
203+
204+ ``` bash
205+ defi-mcp
150206```
151207
208+ Exposes tools: ` defi_status ` , ` defi_list_protocols ` , ` defi_dex_swap ` , ` defi_lending_supply ` , ` defi_lending_rates ` , ` defi_staking_stake ` , ` defi_vault_deposit `
209+
152210## License
153211
154212MIT
0 commit comments