Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ tests/

**Output:** Use `render(data, json_mode)` for all output — returns `True` if it emitted JSON (non-TTY or `--json`), `False` in TTY mode. Commands use `if not render(...):` to branch into human-readable output. Use `error(msg, hint, exit_code)` for failures — prints to stderr and raises `SystemExit`. Never use `print()`.

**Sending:** a command that sends a transaction waits for its outcome by default and takes `--fast` to skip that; wire both through `commands/sending.py` (`fast_option`, the hidden legacy `confirm_option`, `wait_for_outcome`) and pass `confirm=` to core. Core results always carry `confirmed`, and human output wraps its summary line in `outcome()` so an unconfirmed send never reads as done. `RpcClient` waits until the transaction lands, fails (`TransactionFailedError`) or can no longer land (`TransactionExpiredError`); commands catch `RuntimeError` for all of them. Never tell the user to run another command to learn an outcome.

**Error handling:** `error()` raises `SystemExit` — code after it is unreachable. Core functions return `dict` with `"error"` key for expected failures (graduated tokens, not found, slippage exceeded, insufficient_balance). Catch `ValueError` for wrong wallet password in every command that decrypts. Buy/sell functions perform pre-trade balance validation — SOL for fees and rent, the quote asset for the spend, token balance for sells with specific amounts.

**Auto-routing:** `_route` in `commands/trade.py` picks the venue from the errors core returns: `{"error": "graduated"}` from `buy_token` / `sell_token` retries on PumpSwap, `{"error": "not_found"}` retries on LaunchLab (`buy_launchlab` / `sell_launchlab`), and LaunchLab's `graduated` retries on Raydium CPMM (`buy_cpmm` / `sell_cpmm`). `--force-amm` tries PumpSwap and falls back to CPMM only when PumpSwap reports no pool (`pool_missing`); PumpSwap's error stands unless CPMM recognises the coin as LaunchLab's. Never suppress or swallow those errors in core — the routing decision belongs in the command layer. `info` falls back to LaunchLab, and to its CPMM pool, the same way in `core/info.py`.
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ The wallet is stored encrypted in `~/.config/pumpfun-cli/wallet.enc`, and the co
```bash
pumpfun info <mint> # where it trades, price, quote asset
pumpfun buy <mint> 0.1 --dry-run # preview: nothing is sent
pumpfun buy <mint> 0.1 --confirm # spend exactly 0.1 of the coin's quote asset
pumpfun sell <mint> all --confirm
pumpfun buy <mint> 0.1 # spend exactly 0.1 of the coin's quote asset
pumpfun sell <mint> all
pumpfun tx-status <signature> # did it land?
```

`--json` makes any command answer in JSON; it is on automatically when the output is piped.

Every command that sends a transaction waits for it to land and reports what happened on chain: the amounts, or the error it failed with. A transaction that can no longer land (its blockhash expired) is reported as such; it cost nothing and is safe to send again. `--fast` sends without waiting, for when latency matters more than knowing the result: the output then says the transaction was sent but not confirmed (`"confirmed": false`). `wallet drain` always waits.

### 5. Launch a coin

```bash
Expand All @@ -93,20 +95,20 @@ Token info (requires RPC):
pumpfun info <mint> [--timeout S] Venue, price, bonding progress, reserves

Trading (requires RPC + wallet):
pumpfun buy <mint> <amount> [--slippage N] [--force-amm] [--dry-run] [--confirm]
pumpfun sell <mint> <amount|all> [--slippage N] [--force-amm] [--dry-run] [--confirm]
pumpfun migrate <mint> [--confirm]
pumpfun claim-cashback [--quote-mint M] [--confirm]
pumpfun collect-creator-fee [--quote-mint M] [--confirm]
pumpfun close-volume-acc [--confirm]
pumpfun buy <mint> <amount> [--slippage N] [--force-amm] [--dry-run] [--fast]
pumpfun sell <mint> <amount|all> [--slippage N] [--force-amm] [--dry-run] [--fast]
pumpfun migrate <mint> [--fast]
pumpfun claim-cashback [--quote-mint M] [--fast]
pumpfun collect-creator-fee [--quote-mint M] [--fast]
pumpfun close-volume-acc [--fast]

Transaction inspection (requires RPC):
pumpfun tx-status <signature> Confirmation status, slot, fee, errors

Token launch (requires RPC + wallet):
pumpfun launch --name X --ticker Y [--uri U | --desc D --image P] [--buy N]
[--quote-mint M] [--creator-fee-bps N] [--holder-reward]
[--mayhem] [--slippage N] [--confirm]
[--mayhem] [--slippage N] [--fast]

Token discovery (price and progress added when an RPC is set):
pumpfun tokens trending [--limit N] pump.fun's movers board
Expand Down Expand Up @@ -174,7 +176,7 @@ A sell that empties the coin's token account (`all`, or exactly the balance) clo

### Amounts in JSON output

An exact amount comes twice: in whole units for reading (`tokens_sold`) and as the integer in raw units (`tokens_sold_raw`). Use the `_raw` field for anything that has to add up; the float can drop a unit. An amount known only as an estimate has no `_raw` twin: `quote_received`, the `collect-creator-fee` totals, and `tokens_received` unless the buy ran with `--confirm`, in which case it is read from the confirmed transaction. If that transaction cannot be read back, a confirmed buy also reports the estimate without `tokens_received_raw`, so check for the field. Dry-run fields (`expected_tokens_raw`, `expected_quote_raw`, `min_*_out_raw`) are exact integers of the quote the transaction would be built from, not executed amounts.
An exact amount comes twice: in whole units for reading (`tokens_sold`) and as the integer in raw units (`tokens_sold_raw`). Use the `_raw` field for anything that has to add up; the float can drop a unit. An amount known only as an estimate has no `_raw` twin: the `collect-creator-fee` totals, and a trade's `tokens_received` or `quote_received` after `--fast`. Otherwise a trade reads what it received from the confirmed transaction; if that transaction cannot be read back, it reports the estimate without the `_raw` field, so check for it. Dry-run fields (`expected_tokens_raw`, `expected_quote_raw`, `min_*_out_raw`) are exact integers of the quote the transaction would be built from, not executed amounts.

An error comes back as `{"error": <message>, "hint": ..., "exit_code": ...}` with a non-zero exit status.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pumpfun-cli"
version = "0.3.7"
version = "0.4.0"
description = "CLI for pump.fun and Raydium LaunchLab on Solana — trade, launch, and browse tokens"
readme = "README.md"
license = {text = "Apache-2.0"}
Expand Down
2 changes: 1 addition & 1 deletion src/pumpfun_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""pumpfun-cli — CLI for pump.fun on Solana."""

__version__ = "0.3.7"
__version__ = "0.4.0"
7 changes: 5 additions & 2 deletions src/pumpfun_cli/commands/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import typer

from pumpfun_cli.commands.sending import confirm_option, fast_option, outcome, wait_for_outcome
from pumpfun_cli.core.launch import launch_token
from pumpfun_cli.output import error, render

Expand Down Expand Up @@ -41,9 +42,11 @@ def launch(
slippage: int = typer.Option(
15, "--slippage", help="Slippage tolerance percent for the opening buy (default: 15)"
),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Launch a new token on pump.fun (create_v2 + extend_account)."""
confirm = wait_for_outcome(fast, confirm)
state = ctx.obj
if not name.strip():
error("Token name cannot be empty.", exit_code=2)
Expand Down Expand Up @@ -99,7 +102,7 @@ def launch(
if result.get("error"):
error(result["message"])
if not render(result, state.json_mode):
typer.echo("Token launched!")
typer.echo(outcome(result, "Token launched."))
typer.echo(f" Name: {result['name']}")
typer.echo(f" Ticker: {result['ticker']}")
typer.echo(f" Mint: {result['mint']}")
Expand Down
35 changes: 35 additions & 0 deletions src/pumpfun_cli/commands/sending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Options and wording shared by every command that sends a transaction.

A command waits for its transaction's outcome by default and reports what
happened on chain. `--fast` sends without waiting, for when latency matters
more than knowing the result.
"""

import typer

from pumpfun_cli.output import error

FAST_HELP = "Send without waiting for the outcome: fastest, but whether it landed isn't checked"


def fast_option() -> bool:
return typer.Option(False, "--fast", help=FAST_HELP)


def confirm_option() -> bool:
# Waiting is the default now; the flag stays so existing scripts keep working.
return typer.Option(False, "--confirm", hidden=True)


def wait_for_outcome(fast: bool, confirm: bool) -> bool:
"""Whether to wait for the transaction's outcome."""
if fast and confirm:
error("--fast and --confirm contradict each other; pass one.", exit_code=2)
return not fast


def outcome(result: dict, summary: str) -> str:
"""`summary` once the transaction landed; otherwise, that it was only sent."""
if result.get("confirmed"):
return summary
return f"Sent, not confirmed (--fast). Expected: {summary}"
46 changes: 33 additions & 13 deletions src/pumpfun_cli/commands/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import typer

from pumpfun_cli.commands.sending import confirm_option, fast_option, outcome, wait_for_outcome
from pumpfun_cli.core.cpmm import buy_cpmm, sell_cpmm
from pumpfun_cli.core.launchlab import buy_launchlab, sell_launchlab
from pumpfun_cli.core.pumpswap import buy_pumpswap, sell_pumpswap
Expand Down Expand Up @@ -110,12 +111,14 @@ def buy(
"--force-amm",
help="Skip the bonding curve, buy in the pool (PumpSwap, or CPMM for LaunchLab coins)",
),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
dry_run: bool = typer.Option(
False, "--dry-run", help="Simulate trade without sending transaction"
),
):
"""Buy tokens, spending an exact amount of the coin's quote asset."""
confirm = wait_for_outcome(fast, confirm)
_validate_mint(mint)
if amount <= 0:
error("Amount must be greater than 0.", hint=f"Got: {amount}", exit_code=2)
Expand Down Expand Up @@ -168,8 +171,11 @@ def buy(
state = ctx.obj
if not render(result, state.json_mode):
typer.echo(
f"Bought {result['tokens_received']:.2f} tokens"
f" for {result['quote_spent']} {result['quote_symbol']}"
outcome(
result,
f"Bought {result['tokens_received']:.2f} tokens"
f" for {result['quote_spent']} {result['quote_symbol']}",
)
)
typer.echo(f"TX: {result['explorer']}")

Expand All @@ -186,12 +192,14 @@ def sell(
"--force-amm",
help="Skip the bonding curve, sell in the pool (PumpSwap, or CPMM for LaunchLab coins)",
),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
dry_run: bool = typer.Option(
False, "--dry-run", help="Simulate trade without sending transaction"
),
):
"""Sell tokens for the coin's quote asset (SOL for most coins)."""
confirm = wait_for_outcome(fast, confirm)
_validate_mint(mint)
_validate_slippage(slippage)
rpc, keyfile, password = _require_rpc_and_wallet(ctx)
Expand Down Expand Up @@ -245,8 +253,11 @@ def sell(
state = ctx.obj
if not render(result, state.json_mode):
typer.echo(
f"Sold {result['tokens_sold']:.2f} tokens"
f" for {result['quote_received']:.6f} {result['quote_symbol']}"
outcome(
result,
f"Sold {result['tokens_sold']:.2f} tokens"
f" for {result['quote_received']:.6f} {result['quote_symbol']}",
)
)
if "tokens_kept" in result:
typer.echo(
Expand All @@ -267,9 +278,11 @@ def sell(
def claim_cashback(
ctx: typer.Context,
quote_mint: str | None = typer.Option(None, "--quote-mint", help=_QUOTE_MINT_HELP),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Claim volume-based cashback rewards in one quote asset."""
confirm = wait_for_outcome(fast, confirm)
rpc, keyfile, password = _require_rpc_and_wallet(ctx)
overrides = _get_overrides(ctx)
try:
Expand All @@ -282,15 +295,17 @@ def claim_cashback(
error(result["message"])
state = ctx.obj
if not render(result, state.json_mode):
typer.echo("Cashback claimed!")
typer.echo(outcome(result, "Cashback claimed."))
typer.echo(f"TX: {result['explorer']}")


def close_volume_acc(
ctx: typer.Context,
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Close volume accumulator account, recover rent."""
confirm = wait_for_outcome(fast, confirm)
rpc, keyfile, password = _require_rpc_and_wallet(ctx)
overrides = _get_overrides(ctx)
try:
Expand All @@ -303,16 +318,18 @@ def close_volume_acc(
error(result["message"])
state = ctx.obj
if not render(result, state.json_mode):
typer.echo("Volume accumulator closed, rent recovered.")
typer.echo(outcome(result, "Volume accumulator closed, rent recovered."))
typer.echo(f"TX: {result['explorer']}")


def migrate(
ctx: typer.Context,
mint: str = typer.Argument(..., help="Token mint address"),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Trigger migration from bonding curve to PumpSwap AMM."""
confirm = wait_for_outcome(fast, confirm)
_validate_mint(mint)
rpc, keyfile, password = _require_rpc_and_wallet(ctx)
overrides = _get_overrides(ctx)
Expand All @@ -326,16 +343,18 @@ def migrate(
error(result["message"])
state = ctx.obj
if not render(result, state.json_mode):
typer.echo(f"Migrated {result['mint']} to PumpSwap!")
typer.echo(outcome(result, f"Migrated {result['mint']} to PumpSwap."))
typer.echo(f"TX: {result['explorer']}")


def collect_creator_fee(
ctx: typer.Context,
quote_mint: str | None = typer.Option(None, "--quote-mint", help=_QUOTE_MINT_HELP),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Collect creator fees in one quote asset from pump.fun and PumpSwap vaults."""
confirm = wait_for_outcome(fast, confirm)
rpc, keyfile, password = _require_rpc_and_wallet(ctx)
overrides = _get_overrides(ctx)
try:
Expand All @@ -351,6 +370,7 @@ def collect_creator_fee(
state = ctx.obj
if not render(result, state.json_mode):
symbol = result["quote_symbol"]
typer.echo(outcome(result, "Creator fees collected."))
typer.echo(f"Pump.fun fees: {result['pump_recovered']:.6f} {symbol}")
typer.echo(f"PumpSwap fees: {result['pumpswap_recovered']:.6f} {symbol}")
if result.get("sweep_warning"):
Expand Down
29 changes: 21 additions & 8 deletions src/pumpfun_cli/commands/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import typer

from pumpfun_cli.commands.sending import confirm_option, fast_option, outcome, wait_for_outcome
from pumpfun_cli.core.config import get_config_dir, resolve_value
from pumpfun_cli.core.wallet import (
close_empty_atas,
Expand Down Expand Up @@ -213,9 +214,11 @@ def wallet_transfer(
recipient: str = typer.Argument(..., help="Recipient public key"),
amount: str = typer.Argument(..., help="Amount to send (or 'all' to send max)"),
mint: str = typer.Option(None, "--mint", help="Token mint address (omit for SOL transfer)"),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Transfer SOL or tokens to another wallet."""
confirm = wait_for_outcome(fast, confirm)
if amount.lower() != "all":
try:
value = float(amount)
Expand Down Expand Up @@ -270,24 +273,26 @@ def wallet_transfer(
rpc, path, password, recipient, float(amount), confirm=confirm, **overrides
)
)
except ValueError as exc:
except (ValueError, RuntimeError) as exc:
error(str(exc))
if result.get("error"):
error(result["message"])
if not render(result, ctx.obj and ctx.obj.json_mode):
if mint:
typer.echo(f"Sent {result['amount']} tokens to {result['to']}")
typer.echo(outcome(result, f"Sent {result['amount']} tokens to {result['to']}"))
else:
typer.echo(f"Sent {result['sol_amount']} SOL to {result['to']}")
typer.echo(outcome(result, f"Sent {result['sol_amount']} SOL to {result['to']}"))
typer.echo(f"TX: {result['explorer']}")


@app.command("close-atas")
def wallet_close_atas(
ctx: typer.Context,
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
fast: bool = fast_option(),
confirm: bool = confirm_option(),
):
"""Close empty token accounts and recover rent SOL."""
confirm = wait_for_outcome(fast, confirm)
path = _get_keystore_path(ctx)
if not Path(path).exists():
error("No wallet found.", hint="Run: pumpfun wallet create")
Expand All @@ -309,8 +314,11 @@ def wallet_close_atas(
typer.echo("No empty token accounts to close.")
else:
typer.echo(
f"Closed {result['closed']} empty account(s),"
f" recovered {sol_text(result['recovered_sol_raw'])} SOL"
outcome(
result,
f"Closed {result['closed']} empty account(s),"
f" recovered {sol_text(result['recovered_sol_raw'])} SOL",
)
)
for sig in result["signatures"]:
typer.echo(f"TX: https://solscan.io/tx/{sig}")
Expand All @@ -331,9 +339,12 @@ def _echo_skipped(skipped: list[dict]) -> None:
def wallet_drain(
ctx: typer.Context,
recipient: str = typer.Argument(..., help="Recipient address for remaining SOL"),
confirm: bool = typer.Option(False, "--confirm", help="Wait for transaction confirmation"),
confirm: bool = confirm_option(),
):
"""Close empty ATAs, then transfer all remaining SOL to recipient."""
# Always waits: the closes have to land before the SOL moves, and the
# transfer's outcome is the point of the command.
confirm = True
state = ctx.obj
rpc = _require_rpc(ctx)
path = _get_keystore_path(ctx)
Expand All @@ -354,6 +365,8 @@ def wallet_drain(
)
except ValueError:
error("Wrong wallet password.")
except RuntimeError as exc:
error(str(exc))

if result.get("error"):
error(result["message"])
Expand Down
Loading
Loading