diff --git a/README.md b/README.md index 47fdb27..eba47e1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # LP Agent CLI -`lpagent` is the command-line interface for [LP Agent](https://lpagent.io). Manage Solana LP positions, discover pools, and generate liquidity transactions from your terminal or through AI agents. +`lpagent` is the command-line interface for [LP Agent](https://lpagent.io). Manage LP positions on Solana (Meteora, Orca) and the Robinhood chain (Uniswap v3/v4), discover pools, and generate liquidity transactions from your terminal or through AI agents. - Works standalone or as a Claude agent skill - Single binary, no runtime dependencies @@ -46,41 +46,64 @@ make build # Positions lpagent positions open --owner # Open positions lpagent positions open -o table --native # Table view in SOL +lpagent positions open --chain ROBINHOOD --owner <0xaddr> # Open positions on Robinhood lpagent positions historical --owner --from 2025-01-01 # Closed positions lpagent positions overview -o table --native # Portfolio metrics lpagent positions logs --position # Transaction logs +lpagent positions logs --chain ROBINHOOD --owner <0xaddr> # Logs for a Robinhood wallet lpagent positions get --position # Position details lpagent positions revenue # Revenue data # Pools -lpagent pools discover --chain SOL --sort-by tvl # Discover pools +lpagent pools discover --chain SOL --sort-by tvl # Discover pools (Solana) +lpagent pools discover --chain ROBINHOOD --sort-by tvl # Discover Uniswap v3/v4 pools on Robinhood lpagent pools info # Pool details lpagent pools positions --status Open # Positions in a pool lpagent pools onchain-stats # TVL, volume, fees lpagent pools top-lpers # Top LPs -# Zap-In (add liquidity) +# Zap-In (add liquidity) - Solana only lpagent pools add-tx --owner --strategy Spot --input-sol 1 lpagent pools landing-add-tx --file signed-tx.json -# Zap-Out (remove liquidity) +# Zap-Out (remove liquidity) - Solana only lpagent tx zap-out-estimates --position-id --bps 10000 # real payout per output option, after swap + fee lpagent tx decrease-tx --position-id --bps 10000 --owner --slippage-bps 500 lpagent tx landing-decrease-tx --file signed-tx.json +# Claim fees (position stays open) - Solana only +lpagent tx claim-fee-tx --position-id --owner # add --swap-to-sol to get the fees in SOL +lpagent tx landing-claim-fee-tx --file signed-tx.json + # Token lpagent token balance --owner +lpagent token balance --chain ROBINHOOD --owner <0xaddr> # Raw API access lpagent api get /lp-positions/opening --query "owner=" lpagent api post /position/zap-out-estimates --data '{"position_id":"...","bps":5000}' ``` +## Chains + +| Chain | `--chain` | Protocols | Native token | +|-----------|-------------|-------------------------------------|--------------| +| Solana | `SOL` (default) | Meteora DLMM, Meteora DAMM v2, Orca | SOL | +| Robinhood | `ROBINHOOD` | Uniswap v3, Uniswap v4 | ETH | + +Read commands take `--chain SOL` (default) or `--chain ROBINHOOD`: `positions open`, `historical`, +`overview`, `logs` and `revenue`, `token balance`, `pools discover` and `pools positions`. +`positions get`, `pools onchain-stats` and `pools top-lpers` read the chain from the id you pass. + +`pools info` and every command that builds or sends a transaction (`add-tx`, `zap-out-estimates`, +`decrease-tx`, `claim-fee-tx` and their `landing-` commands) are Solana only. +See [Chain Support](https://docs.lpagent.io/ai-api-guide#chain-support). + ## Output Formats All commands support `--output` / `-o`: `json` (default), `table`, `quiet`. -Use `--native` on `positions open` and `positions overview` to show values in SOL instead of USD. +Use `--native` on `positions open` and `positions overview` to show values in the native token (SOL on Solana, ETH on Robinhood) instead of USD. ## Configuration diff --git a/internal/cli/root.go b/internal/cli/root.go index ae9e43b..8f10ec8 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -21,10 +21,10 @@ var ( func newRootCmd() *cobra.Command { cmd := &cobra.Command{ Use: "lpagent", - Short: "LP Agent CLI — manage Solana LP positions from the terminal", + Short: "LP Agent CLI - manage Solana and Robinhood LP positions from the terminal", Long: `LP Agent CLI is a command-line interface for the LP Agent Open API. -It provides access to LP position management, pool discovery, and -transaction generation for Solana DeFi protocols. +It tracks LP positions and discovers pools on Solana and Robinhood Chain, +and generates liquidity and fee-claim transactions on Solana. Get started: lpagent auth set-key Set your API key diff --git a/internal/commands/pools.go b/internal/commands/pools.go index a05c0b2..b1216f6 100644 --- a/internal/commands/pools.go +++ b/internal/commands/pools.go @@ -58,6 +58,7 @@ func newPoolsDiscoverCmd() *cobra.Command { Short: "Discover and filter liquidity pools", Example: ` lpagent pools discover lpagent pools discover --chain SOL --sort-by tvl --page-size 20 -o table + lpagent pools discover --chain ROBINHOOD --sort-by tvl -o table lpagent pools discover --search "SOL" --min-liquidity 10000`, RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) @@ -137,7 +138,7 @@ func newPoolsDiscoverCmd() *cobra.Command { }, } - cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") cmd.Flags().StringVar(&sortBy, "sort-by", "mcap", "Sort by: mcap, created_at, vol_24h, tvl, fee_tvl_ratio, volatility") cmd.Flags().StringVar(&sortOrder, "sort-order", "desc", "Sort order: asc, desc") cmd.Flags().IntVar(&page, "page", 1, "Page number") @@ -185,6 +186,7 @@ func newPoolsInfoCmd() *cobra.Command { func newPoolsPositionsCmd() *cobra.Command { var ( owner string + chain string status string page int pageSize int @@ -202,7 +204,9 @@ func newPoolsPositionsCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) - params := map[string]string{} + params := map[string]string{ + "chain": chain, + } if owner != "" { params["owner"] = owner } @@ -242,6 +246,7 @@ func newPoolsPositionsCmd() *cobra.Command { } cmd.Flags().StringVar(&owner, "owner", "", "Filter by wallet address") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") cmd.Flags().StringVar(&status, "status", "", "Filter by status: Open, Close") cmd.Flags().IntVar(&page, "page", 0, "Page number") cmd.Flags().IntVar(&pageSize, "page-size", 0, "Items per page (max 20)") diff --git a/internal/commands/positions.go b/internal/commands/positions.go index 48301c3..3829e5f 100644 --- a/internal/commands/positions.go +++ b/internal/commands/positions.go @@ -35,6 +35,7 @@ func NewPositionsCmd() *cobra.Command { func newPositionsOpeningCmd() *cobra.Command { var ( owner string + chain string native bool ) @@ -44,7 +45,8 @@ func newPositionsOpeningCmd() *cobra.Command { Short: "List open LP positions for an owner", Example: ` lpagent positions open --owner 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM lpagent positions open -o table - lpagent positions open -o table --native`, + lpagent positions open -o table --native + lpagent positions open --chain ROBINHOOD --owner 0xYourWallet -o table`, RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) resolved, err := app.Config.ResolveOwner(owner) @@ -54,6 +56,7 @@ func newPositionsOpeningCmd() *cobra.Command { data, err := app.Client.Get("/lp-positions/opening", map[string]string{ "owner": resolved, + "chain": chain, }) if err != nil { return err @@ -75,10 +78,10 @@ func newPositionsOpeningCmd() *cobra.Command { output.PrintWithOpts(data, app.Format, &output.TableOptions{ Columns: columns, RowFunc: func(row map[string]any) []string { - return formatOpeningRow(row, native) + return formatOpeningRow(row, native, nativeSymbol(chain)) }, SummaryFunc: func(rows []map[string]any) string { - return formatOpeningSummary(rows, native) + return formatOpeningSummary(rows, native, nativeSymbol(chain)) }, }) return nil @@ -86,14 +89,15 @@ func newPositionsOpeningCmd() *cobra.Command { } cmd.Flags().StringVar(&owner, "owner", "", "Wallet address of the position owner") - cmd.Flags().BoolVar(&native, "native", false, "Show values in native token (SOL) instead of USD") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") + cmd.Flags().BoolVar(&native, "native", false, "Show values in native token (SOL on Solana, ETH on Robinhood) instead of USD") return cmd } -func formatOpeningRow(row map[string]any, native bool) []string { +func formatOpeningRow(row map[string]any, native bool, symbol string) []string { // Pair pairName := fmt.Sprintf("%v", row["pairName"]) - tokenName1 := "SOL" + tokenName1 := symbol if t1, ok := row["token1Info"].(map[string]any); ok { if sym, ok := t1["token_symbol"].(string); ok { tokenName1 = sym @@ -124,7 +128,7 @@ func formatOpeningRow(row map[string]any, native bool) []string { // Value var value string if native { - value = output.FormatSOL(row["valueNative"]) + value = output.FormatNative(row["valueNative"], symbol) } else { value = output.FormatUSD(row["value"]) } @@ -132,7 +136,7 @@ func formatOpeningRow(row map[string]any, native bool) []string { // Claimed Fee var claimedFee string if native { - claimedFee = output.FormatFloat(row["collectedFeeNative"], 2) + " SOL" + claimedFee = output.FormatFloat(row["collectedFeeNative"], 2) + " " + symbol } else { claimedFee = output.FormatUSD(row["collectedFee"]) } @@ -140,7 +144,7 @@ func formatOpeningRow(row map[string]any, native bool) []string { // Unclaim Fee var unclaimFee string if native { - unclaimFee = output.FormatFloat(row["unCollectedFeeNative"], 2) + " SOL" + unclaimFee = output.FormatFloat(row["unCollectedFeeNative"], 2) + " " + symbol } else { unclaimFee = output.FormatUSD(row["unCollectedFee"]) } @@ -152,7 +156,7 @@ func formatOpeningRow(row map[string]any, native bool) []string { if native { pnlVal, _ = output.ToFloatPublic(safeGet(pnlMap, "valueNative")) pnlPct, _ := output.ToFloatPublic(safeGet(pnlMap, "percentNative")) - pnlValueStr = fmt.Sprintf("%.2f SOL", pnlVal) + pnlValueStr = fmt.Sprintf("%.2f %s", pnlVal, symbol) pnlPctStr = fmt.Sprintf("(%.2f%%)", pnlPct) } else { pnlVal, _ = output.ToFloatPublic(safeGet(pnlMap, "value")) @@ -183,7 +187,7 @@ func formatOpeningRow(row map[string]any, native bool) []string { return []string{displayPair, pool, age, value, claimedFee, unclaimFee, upnl, dpr, inRange, protocol} } -func formatOpeningSummary(rows []map[string]any, native bool) string { +func formatOpeningSummary(rows []map[string]any, native bool, symbol string) string { var totalValue, totalUPnL, totalPnLPct, totalClaimed, totalUnclaimed float64 for _, row := range rows { if native { @@ -234,10 +238,10 @@ func formatOpeningSummary(rows []map[string]any, native bool) string { var valStr, upnlStr, claimedStr, unclaimedStr string if native { - valStr = fmt.Sprintf("%.4f SOL", totalValue) - upnlStr = fmt.Sprintf("%.2f SOL (%.2f%%)", totalUPnL, totalPnLPct) - claimedStr = fmt.Sprintf("%.2f SOL", totalClaimed) - unclaimedStr = fmt.Sprintf("%.2f SOL", totalUnclaimed) + valStr = fmt.Sprintf("%.4f %s", totalValue, symbol) + upnlStr = fmt.Sprintf("%.2f %s (%.2f%%)", totalUPnL, symbol, totalPnLPct) + claimedStr = fmt.Sprintf("%.2f %s", totalClaimed, symbol) + unclaimedStr = fmt.Sprintf("%.2f %s", totalUnclaimed, symbol) } else { valStr = output.FormatUSD(totalValue) upnlStr = fmt.Sprintf("%s (%.2f%%)", output.FormatUSD(totalUPnL), totalPnLPct) @@ -249,6 +253,14 @@ func formatOpeningSummary(rows []map[string]any, native bool) string { return fmt.Sprintf("Total\t\t\t%s\t%s\t%s\t%s\t\t\t", valStr, claimedStr, unclaimedStr, upnlStr) } +// nativeSymbol is the chain's native token, the unit of every *Native field. +func nativeSymbol(chain string) string { + if strings.EqualFold(chain, "ROBINHOOD") { + return "ETH" + } + return "SOL" +} + func safeGet(m map[string]any, key string) any { if m == nil { return nil @@ -259,6 +271,7 @@ func safeGet(m map[string]any, key string) any { func newPositionsHistoricalCmd() *cobra.Command { var ( owner string + chain string fromDate string toDate string page int @@ -269,7 +282,8 @@ func newPositionsHistoricalCmd() *cobra.Command { Use: "historical", Short: "List historical (closed) LP positions", Example: ` lpagent positions historical --owner 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM - lpagent positions historical --owner --from 2025-01-01 --to 2025-09-01 --limit 50`, + lpagent positions historical --owner --from 2025-01-01 --to 2025-09-01 --limit 50 + lpagent positions historical --chain ROBINHOOD --owner 0xYourWallet`, RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) resolved, err := app.Config.ResolveOwner(owner) @@ -279,6 +293,7 @@ func newPositionsHistoricalCmd() *cobra.Command { params := map[string]string{ "owner": resolved, + "chain": chain, } if fromDate != "" { params["from_date"] = fromDate @@ -290,7 +305,7 @@ func newPositionsHistoricalCmd() *cobra.Command { params["page"] = strconv.Itoa(page) } if limit > 0 { - params["limit"] = strconv.Itoa(limit) + params["pageSize"] = strconv.Itoa(limit) } data, err := app.Client.Get("/lp-positions/historical", params) @@ -311,6 +326,7 @@ func newPositionsHistoricalCmd() *cobra.Command { } cmd.Flags().StringVar(&owner, "owner", "", "Wallet address") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") cmd.Flags().StringVar(&fromDate, "from", "", "Start date (ISO 8601)") cmd.Flags().StringVar(&toDate, "to", "", "End date (ISO 8601)") cmd.Flags().IntVar(&page, "page", 0, "Page number") @@ -321,6 +337,7 @@ func newPositionsHistoricalCmd() *cobra.Command { func newPositionsOverviewCmd() *cobra.Command { var ( owner string + chain string protocol string native bool ) @@ -329,7 +346,8 @@ func newPositionsOverviewCmd() *cobra.Command { Use: "overview", Short: "Get aggregated metrics for an owner's LP activity", Example: ` lpagent positions overview --owner 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM - lpagent positions overview --owner -o table --native`, + lpagent positions overview --owner -o table --native + lpagent positions overview --chain ROBINHOOD --owner 0xYourWallet -o table`, RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) resolved, err := app.Config.ResolveOwner(owner) @@ -337,16 +355,23 @@ func newPositionsOverviewCmd() *cobra.Command { return err } - data, err := app.Client.Get("/lp-positions/overview", map[string]string{ - "owner": resolved, - "protocol": protocol, - }) + params := map[string]string{ + "owner": resolved, + "chain": chain, + } + // The meteora default only means something on Solana. Elsewhere, send a + // protocol only when asked, so the API covers every protocol on the chain. + if strings.EqualFold(chain, "SOL") || cmd.Flags().Changed("protocol") { + params["protocol"] = protocol + } + + data, err := app.Client.Get("/lp-positions/overview", params) if err != nil { return err } if app.Format == "table" { - printOverviewTable(data, native) + printOverviewTable(data, native, nativeSymbol(chain)) return nil } @@ -356,12 +381,13 @@ func newPositionsOverviewCmd() *cobra.Command { } cmd.Flags().StringVar(&owner, "owner", "", "Wallet address") - cmd.Flags().StringVar(&protocol, "protocol", "meteora", "Protocol filter") - cmd.Flags().BoolVar(&native, "native", false, "Show values in native token (SOL) instead of USD") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") + cmd.Flags().StringVar(&protocol, "protocol", "meteora", "Protocol filter (on ROBINHOOD: every Uniswap version unless set)") + cmd.Flags().BoolVar(&native, "native", false, "Show values in native token (SOL on Solana, ETH on Robinhood) instead of USD") return cmd } -func printOverviewTable(data json.RawMessage, native bool) { +func printOverviewTable(data json.RawMessage, native bool, symbol string) { var resp struct { Status string `json:"status"` Data []map[string]any `json:"data"` @@ -387,7 +413,7 @@ func printOverviewTable(data json.RawMessage, native bool) { fmtVal := func(v float64) string { if native { - return fmt.Sprintf("%.2f SOL", v) + return fmt.Sprintf("%.2f %s", v, symbol) } return output.FormatUSD(v) } @@ -479,7 +505,7 @@ func newPositionsLogsCmd() *cobra.Command { } cmd.Flags().StringVar(&position, "position", "", "Position ID (token ID)") - cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain chain") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain chain: SOL or ROBINHOOD") cmd.Flags().StringVar(&owner, "owner", "", "Wallet address") return cmd } @@ -490,6 +516,7 @@ func newPositionsGetCmd() *cobra.Command { cmd := &cobra.Command{ Use: "get", Short: "Get details for a specific position", + Long: "Get details for a specific position. Works with a Solana position address or a Robinhood position ID; the chain is read from the ID.", Example: ` lpagent positions get --position Ep22EwKegXis3bTC6P8JLgsHaT5J2beM2TncKe2Hmv24`, RunE: func(cmd *cobra.Command, args []string) error { if position == "" { @@ -516,6 +543,7 @@ func newPositionsGetCmd() *cobra.Command { func newPositionsRevenueCmd() *cobra.Command { var ( + chain string period string rangeVal string protocol string @@ -530,7 +558,9 @@ func newPositionsRevenueCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) - params := map[string]string{} + params := map[string]string{ + "chain": chain, + } if period != "" { params["period"] = period } @@ -551,6 +581,7 @@ func newPositionsRevenueCmd() *cobra.Command { }, } + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") cmd.Flags().StringVar(&period, "period", "", "Period filter") cmd.Flags().StringVar(&rangeVal, "range", "", "Range filter: 7D, 1M") cmd.Flags().StringVar(&protocol, "protocol", "", "Protocol filter") diff --git a/internal/commands/positions_test.go b/internal/commands/positions_test.go new file mode 100644 index 0000000..74a7b76 --- /dev/null +++ b/internal/commands/positions_test.go @@ -0,0 +1,35 @@ +package commands + +import ( + "strings" + "testing" +) + +func TestNativeSymbol(t *testing.T) { + for chain, want := range map[string]string{"SOL": "SOL", "": "SOL", "ROBINHOOD": "ETH", "robinhood": "ETH"} { + if got := nativeSymbol(chain); got != want { + t.Errorf("nativeSymbol(%q) = %q, want %q", chain, got, want) + } + } +} + +func TestFormatOpeningRowNativeUnit(t *testing.T) { + row := map[string]any{ + "pairName": "WETH/USDG", + "token1Info": map[string]any{"token_symbol": "USDG"}, + "valueNative": 1.5, + "collectedFeeNative": 0.02, + "unCollectedFeeNative": 0.01, + "pnl": map[string]any{"valueNative": 0.1, "percentNative": 7.0}, + } + + got := strings.Join(formatOpeningRow(row, true, "ETH"), " | ") + for _, want := range []string{"1.5000 ETH", "0.02 ETH", "0.01 ETH", "0.10 ETH"} { + if !strings.Contains(got, want) { + t.Errorf("row is missing %q: %s", want, got) + } + } + if strings.Contains(got, "SOL") { + t.Errorf("Robinhood row still says SOL: %s", got) + } +} diff --git a/internal/commands/token.go b/internal/commands/token.go index 3c692bc..27a189a 100644 --- a/internal/commands/token.go +++ b/internal/commands/token.go @@ -21,6 +21,7 @@ func NewTokenCmd() *cobra.Command { func newTokenBalanceCmd() *cobra.Command { var ( owner string + chain string ca string ) @@ -28,7 +29,8 @@ func newTokenBalanceCmd() *cobra.Command { Use: "balance", Short: "Get token balances for a wallet", Example: ` lpagent token balance --owner 9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM - lpagent token balance --owner --ca So11111111111111111111111111111111111111112 -o table`, + lpagent token balance --owner --ca So11111111111111111111111111111111111111112 -o table + lpagent token balance --chain ROBINHOOD --owner 0xYourWallet -o table`, RunE: func(cmd *cobra.Command, args []string) error { app := appctx.FromContext(cmd.Context()) resolved, err := app.Config.ResolveOwner(owner) @@ -38,6 +40,7 @@ func newTokenBalanceCmd() *cobra.Command { params := map[string]string{ "owner": resolved, + "chain": chain, } if ca != "" { params["ca"] = ca @@ -60,6 +63,7 @@ func newTokenBalanceCmd() *cobra.Command { } cmd.Flags().StringVar(&owner, "owner", "", "Wallet address (required)") + cmd.Flags().StringVar(&chain, "chain", "SOL", "Blockchain network: SOL or ROBINHOOD") cmd.Flags().StringVar(&ca, "ca", "", "Comma-separated token addresses to filter") return cmd diff --git a/internal/commands/tx.go b/internal/commands/tx.go index fbcbd97..ef2b4bc 100644 --- a/internal/commands/tx.go +++ b/internal/commands/tx.go @@ -14,13 +14,15 @@ import ( func NewTxCmd() *cobra.Command { cmd := &cobra.Command{ Use: "tx", - Short: "Position transaction operations (zap-out)", + Short: "Position transaction operations (zap-out, claim fees)", } cmd.AddCommand( newTxZapOutEstimatesCmd(), newTxDecreaseTxCmd(), newTxLandingDecreaseTxCmd(), + newTxClaimFeeTxCmd(), + newTxLandingClaimFeeTxCmd(), ) return cmd @@ -41,9 +43,9 @@ func newTxZapOutEstimatesCmd() *cobra.Command { Aliases: []string{"decrease-quotes"}, Short: "Estimate what withdrawing liquidity pays out, per output option", Long: `Estimates each decrease-tx output option (allToken0, allToken1, both, allBaseToken): -what the wallet ends up with after the swap and LP Agent's fee, priced on the -same route decrease-tx uses, plus the market value / swap cost / fee split. -Run it before decrease-tx to see the real payout. Meteora DLMM only.`, +what the wallet ends up with after the swap and fees, priced on the same route +decrease-tx uses, next to the same withdrawal valued at the pool price before any +swap. Run it before decrease-tx to see the real payout. Meteora DLMM only.`, Example: ` lpagent tx zap-out-estimates --position-id --bps 10000 lpagent tx zap-out-estimates --position-id --bps 10000 --payouts allToken1 -o table`, RunE: func(cmd *cobra.Command, args []string) error { @@ -98,8 +100,6 @@ type zapOutEstimate struct { } `json:"receive"` ValueUsd float64 `json:"valueUsd"` MarketValueUsd float64 `json:"marketValueUsd"` - CommissionUsd float64 `json:"commissionUsd"` - SwapCostUsd float64 `json:"swapCostUsd"` PriceImpactPct *float64 `json:"priceImpactPct"` } @@ -119,8 +119,7 @@ func printZapOutEstimates(data []byte) { {Header: "YOU GET"}, {Header: "VALUE"}, {Header: "MARKET"}, - {Header: "SWAP COST"}, - {Header: "FEE"}, + {Header: "EXIT COST"}, {Header: "IMPACT"}, } var rows [][]string @@ -142,8 +141,9 @@ func printZapOutEstimates(data []byte) { strings.Join(parts, " + "), fmt.Sprintf("$%.2f", e.ValueUsd), fmt.Sprintf("$%.2f", e.MarketValueUsd), - fmt.Sprintf("$%.2f", e.SwapCostUsd), - fmt.Sprintf("$%.2f", e.CommissionUsd), + // The estimate gives the payout and the pool-price value, not a split + // of what lies between them: swap and fees show up as one total. + fmt.Sprintf("$%.2f", e.MarketValueUsd-e.ValueUsd), impact, }) } @@ -267,3 +267,98 @@ func newTxLandingDecreaseTxCmd() *cobra.Command { return cmd } + +func newTxClaimFeeTxCmd() *cobra.Command { + var ( + positionId string + owner string + slippageBps int + swapToSol bool + provider string + poolType string + ) + + cmd := &cobra.Command{ + Use: "claim-fee-tx", + Short: "Generate transactions to claim a position's unclaimed fees", + Long: `Generates serialized claim-fee transactions for a Meteora DLMM or DAMM V2 position. +The position stays open. With --swap-to-sol, also returns swap transactions that turn +the claimed fees into SOL. Sign them and submit with landing-claim-fee-tx.`, + Example: ` lpagent tx claim-fee-tx --position-id --owner + lpagent tx claim-fee-tx --position-id --owner --swap-to-sol --slippage-bps 300`, + RunE: func(cmd *cobra.Command, args []string) error { + if positionId == "" { + return fmt.Errorf("--position-id is required") + } + + app := appctx.FromContext(cmd.Context()) + resolvedOwner, err := app.Config.ResolveOwner(owner) + if err != nil { + return err + } + + body := map[string]any{ + "position_id": positionId, + "owner": resolvedOwner, + "slippage_bps": slippageBps, + "swapToNative": swapToSol, + "type": poolType, + } + if provider != "" { + body["provider"] = provider + } + + data, err := app.Client.Post("/position/claim-fee-tx", body) + if err != nil { + return err + } + + output.Print(data, app.Format, nil) + return nil + }, + } + + cmd.Flags().StringVar(&positionId, "position-id", "", "Position ID (required)") + cmd.Flags().StringVar(&owner, "owner", "", "Owner wallet address") + cmd.Flags().IntVar(&slippageBps, "slippage-bps", 500, "Slippage tolerance in basis points for --swap-to-sol (0-10000)") + cmd.Flags().BoolVar(&swapToSol, "swap-to-sol", false, "Also return swap transactions that turn the claimed fees into SOL") + cmd.Flags().StringVar(&provider, "provider", "", "Swap provider for --swap-to-sol: OKX, JUPITER_ULTRA") + cmd.Flags().StringVar(&poolType, "type", "meteora", "Pool type: meteora, meteora_damm_v2") + + return cmd +} + +func newTxLandingClaimFeeTxCmd() *cobra.Command { + var file string + + cmd := &cobra.Command{ + Use: "landing-claim-fee-tx", + Short: "Submit signed claim-fee transactions via Jito", + Long: `Submit signed claim-fee transactions, and the swap-to-SOL ones when built with +--swap-to-sol, via Jito bundles for on-chain execution. The JSON file holds +lastValidBlockHeight, claimTxsWithJito and swapTxsWithJito from claim-fee-tx, signed.`, + Example: ` lpagent tx landing-claim-fee-tx --file signed-tx.json + cat signed-tx.json | lpagent tx landing-claim-fee-tx --file -`, + RunE: func(cmd *cobra.Command, args []string) error { + app := appctx.FromContext(cmd.Context()) + + body, err := readJSONInput(file) + if err != nil { + return err + } + + data, err := app.Client.Post("/position/landing-claim-fee-tx", body) + if err != nil { + return err + } + + output.Print(data, app.Format, nil) + return nil + }, + } + + cmd.Flags().StringVar(&file, "file", "", "Path to JSON file (use - for stdin)") + _ = cmd.MarkFlagRequired("file") + + return cmd +} diff --git a/internal/commands/tx_test.go b/internal/commands/tx_test.go index f9ea7c7..58aef3f 100644 --- a/internal/commands/tx_test.go +++ b/internal/commands/tx_test.go @@ -26,13 +26,13 @@ func TestPrintZapOutEstimatesTable(t *testing.T) { // Trimmed from a real /open-api/v1/position/zap-out-estimates answer. body := []byte(`{"status":"success","data":{"estimates":[ {"output":"allToken1","ok":true,"receive":[{"address":"So11111111111111111111111111111111111111112","uiAmount":1.123593898}], - "valueUsd":113.03,"marketValueUsd":114.52,"commissionUsd":0.49,"swapCostUsd":1.0,"priceImpactPct":-0.05}, + "valueUsd":113.03,"marketValueUsd":114.52,"priceImpactPct":-0.05}, {"output":"allToken0","ok":false,"error":"No swap route: insufficient liquidity"} ]}}`) out := captureStdout(t, func() { printZapOutEstimates(body) }) - for _, want := range []string{"OUTPUT", "allToken1", "1.12359 SOL", "$113.03", "$114.52", "$0.49", "-0.05%", "unavailable: No swap route: insufficient liquidity"} { + for _, want := range []string{"OUTPUT", "EXIT COST", "allToken1", "1.12359 SOL", "$113.03", "$114.52", "$1.49", "-0.05%", "unavailable: No swap route: insufficient liquidity"} { if !strings.Contains(out, want) { t.Errorf("table is missing %q:\n%s", want, out) } diff --git a/internal/output/table.go b/internal/output/table.go index 55111f8..c9e306a 100644 --- a/internal/output/table.go +++ b/internal/output/table.go @@ -230,12 +230,12 @@ func FormatUSD(v any) string { return fmt.Sprintf("$%.2f", f) } -func FormatSOL(v any) string { +func FormatNative(v any, symbol string) string { f, ok := toFloat(v) if !ok { return "-" } - return fmt.Sprintf("%.4f SOL", f) + return fmt.Sprintf("%.4f %s", f, symbol) } func TruncAddr(s string, prefixLen, suffixLen int) string { diff --git a/skills/lpagent/SKILL.md b/skills/lpagent/SKILL.md index 70e4587..12ea9eb 100644 --- a/skills/lpagent/SKILL.md +++ b/skills/lpagent/SKILL.md @@ -1,29 +1,58 @@ --- name: lpagent description: | - LP Agent CLI — query and manage Solana liquidity pool positions, discover pools, - check token balances, and generate add/remove liquidity transactions via the - LP Agent Open API. + LP Agent CLI - query and manage liquidity pool positions on Solana (Meteora, Orca) + and the Robinhood chain (Uniswap v3/v4), discover pools, check token balances, + and generate add/remove liquidity transactions via the LP Agent Open API. triggers: - LP positions - liquidity pool - pool discovery - DeFi portfolio - Solana LP + - Robinhood LP + - Uniswap v4 + - EVM LP - meteora positions - zap-in - zap-out - add liquidity - remove liquidity + - claim fees - token balance - LP Agent --- # LP Agent -A command-line interface for the LP Agent Open API. Manages Solana LP positions, +A command-line interface for the LP Agent Open API. Manages LP positions on Solana +(Meteora DLMM / DAMM v2, Orca) and on the Robinhood chain (Uniswap v3 / v4), discovers pools, and generates transactions for adding/removing liquidity. +## Chains + +| Chain | `--chain` value | Protocols | Native token | Address / position id | +| --- | --- | --- | --- | --- | +| Solana | `SOL` (default) | Meteora DLMM, Meteora DAMM v2, Orca | SOL | base58 pubkey / position pubkey | +| Robinhood | `ROBINHOOD` | Uniswap v3, Uniswap v4 | ETH | `0x…` hex / NFT `tokenId` | + +Read commands take `--chain` (`SOL` by default): `positions open/historical/ +overview/logs/revenue`, `token balance`, `pools discover` and `pools positions`. +Pass `--chain ROBINHOOD` with a `0x` wallet or pool, or the lookup runs on Solana. +`positions get`, `pools onchain-stats` and `pools top-lpers` read the chain from +the id itself. Native values are SOL on Solana and ETH on Robinhood. + +`pools info` and every transaction command (`add-tx`, `zap-out-estimates`, +`decrease-tx`, `claim-fee-tx` and the `landing-` ones) are **Solana only**: do not +pass a Robinhood address to them. + +```bash +lpagent pools discover --chain ROBINHOOD --sort-by tvl -o table +lpagent positions open --chain ROBINHOOD --owner 0xYourWallet -o table --native +lpagent positions logs --chain ROBINHOOD --owner 0xYourWallet +lpagent token balance --chain ROBINHOOD --owner 0xYourWallet +``` + ## Installation ### Quick install (macOS / Linux) @@ -108,6 +137,7 @@ lpagent token balance --owner --ca So1111111111111111111111111111111111 ### Discover pools ```bash lpagent pools discover --chain SOL --sort-by tvl -o table +lpagent pools discover --chain ROBINHOOD --sort-by tvl -o table lpagent pools discover --search "SOL" --min-liquidity 10000 ``` @@ -118,12 +148,18 @@ lpagent pools onchain-stats lpagent pools top-lpers ``` -### Generate add liquidity transaction (Zap-In) +### View position activity logs +```bash +lpagent positions logs --position +lpagent positions logs --chain ROBINHOOD --owner 0xYourWallet +``` + +### Generate add liquidity transaction (Zap-In) - Solana only ```bash lpagent pools add-tx --owner --strategy Spot --input-sol 1 ``` -### Generate remove liquidity transaction (Zap-Out) +### Generate remove liquidity transaction (Zap-Out) - Solana only Estimate first: `zap-out-estimates` returns, per output option (allToken0, allToken1, both, allBaseToken), what the wallet ends up with after the swap and LP Agent's fee, priced on the same route `decrease-tx` uses. Pick the `--output-type` from it. @@ -132,6 +168,16 @@ lpagent tx zap-out-estimates --position-id --bps 10000 lpagent tx decrease-tx --position-id --bps 10000 --owner --slippage-bps 500 --output-type allToken1 ``` +### Claim fees without closing the position - Solana only +`claim-fee-tx` returns `claimTxsWithJito` (and `swapTxsWithJito` with `--swap-to-sol`, +which turns the claimed fees into SOL). Sign them, keep `lastValidBlockHeight`, and +submit the same JSON shape with `landing-claim-fee-tx`. +```bash +lpagent tx claim-fee-tx --position-id --owner +lpagent tx claim-fee-tx --position-id --owner --swap-to-sol --slippage-bps 300 +lpagent tx landing-claim-fee-tx --file signed-tx.json +``` + ### Raw API access ```bash lpagent api get /lp-positions/opening --query "owner=" @@ -141,12 +187,12 @@ lpagent api post /position/zap-out-estimates --data '{"position_id":"...","bps": ## Output Formats All commands support `--output` / `-o` flag: -- `json` (default) — full JSON response, best for piping and AI agents -- `table` — human-readable table format -- `quiet` — IDs only, one per line +- `json` (default): full JSON response, best for piping and AI agents +- `table`: human-readable table format +- `quiet`: IDs only, one per line ## Environment Variables -- `LPAGENT_API_KEY` — API key (overrides config file) -- `LPAGENT_API_URL` — Base URL (overrides default) -- `LPAGENT_DEFAULT_OWNER` — Default wallet owner +- `LPAGENT_API_KEY`: API key (overrides config file) +- `LPAGENT_API_URL`: Base URL (overrides default) +- `LPAGENT_DEFAULT_OWNER`: Default wallet owner