Metadata-Version: 2.4
Name: pumpswap-python
Version: 0.1.0
Summary: Direct Pump AMM (pAMMBay) + legacy PumpSwap swaps in Python. Build raw Solana instructions, no Jupiter.
Project-URL: Homepage, https://github.com/JinUltimate1995/pumpswap-python
Project-URL: Repository, https://github.com/JinUltimate1995/pumpswap-python
Project-URL: Issues, https://github.com/JinUltimate1995/pumpswap-python/issues
Project-URL: Commercial License, https://github.com/JinUltimate1995/pumpswap-python/blob/main/COMMERCIAL.md
Author: JinUltimate1995
License: Required Notice: Copyright (c) 2026 JinUltimate1995
        
        ---
        
        # PolyForm Noncommercial License 1.0.0
        
        <https://polyformproject.org/licenses/noncommercial/1.0.0>
        
        ## Acceptance
        
        In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
        
        ## Copyright License
        
        The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose.  However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
        
        ## Distribution License
        
        The licensor grants you an additional copyright license to distribute copies of the software.  Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
        
        ## Notices
        
        You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software.  For example:
        
        > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
        
        ## Changes and New Works License
        
        The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
        
        ## Patent License
        
        The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
        
        ## Noncommercial Purposes
        
        Any noncommercial purpose is a permitted purpose.
        
        ## Personal Uses
        
        Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
        
        ## Noncommercial Organizations
        
        Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
        
        ## Fair Use
        
        You may have "fair use" rights for the software under the law. These terms do not limit them.
        
        ## No Other Rights
        
        These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else.  These terms do not imply any other licenses.
        
        ## Patent Defense
        
        If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
        
        ## Violations
        
        The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice.  Otherwise, all your licenses end immediately.
        
        ## No Liability
        
        ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
        
        ## Definitions
        
        The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
        
        **You** refers to the individual or entity agreeing to these terms.
        
        **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization.  **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise.  Control can be direct or indirect.
        
        **Your licenses** are all the licenses granted to you for the software under these terms.
        
        **Use** means anything you do with the software requiring one of your licenses.
License-File: LICENSE.md
Keywords: amm,async,crypto,defi,dex,pammbay,pump-amm,pumpfun,pumpswap,python,solana,trading
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: solders>=0.21
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# pumpswap-python

**Direct Pump AMM (`pAMMBay…`) + legacy PumpSwap swaps. From Python. No Jupiter.**

[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: PolyForm NC](https://img.shields.io/badge/license-PolyForm%20Noncommercial-orange.svg)](LICENSE.md)
[![Typed](https://img.shields.io/badge/typed-py.typed-blue.svg)](https://peps.python.org/pep-0561/)

When a pump.fun token graduates off its bonding curve, it moves to an AMM pool —
today that's **Pump AMM**, the `pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA`
program. Jupiter can route through it, but you pay an extra hop of latency and
you're at the mercy of its routing. This library builds the **raw on-chain swap
instructions directly**, so you control exactly what lands on chain.

There's plenty of bonding-curve tooling out there. A complete, current Pump AMM
swap builder in Python — handling the 23/21-account layouts, reversed base/quote
pools, coin-creator vaults, volume accumulators, Token-2022, and WSOL
wrap/unwrap — was missing. This is that.

> Building against the bonding curve (pre-graduation)? See the companion package
> **[pumpfun-python](https://github.com/JinUltimate1995/pumpfun-python)**.

---

## Install

```bash
pip install pumpswap-python
```

Only two runtime deps: [`solders`](https://github.com/kevinheavey/solders) and
[`httpx`](https://www.python-httpx.org/). No SDK bloat.

---

## Quick start

`build_buy` / `build_sell` read the pool, do the math, and hand you an ordered
list of **unsigned** instructions plus a quote. You sign and send — the library
never touches your keys.

```python
import asyncio
import httpx
from solders.keypair import Keypair
from solders.transaction import VersionedTransaction
from pumpswap import build_buy, build_message, fetch_latest_blockhash

RPC = "https://api.mainnet-beta.solana.com"   # use your own (Helius/QuickNode) for real volume
wallet = Keypair()                            # load your real keypair
MINT = "TokenMintAddress..."
POOL = "PumpAmmPoolAddress..."

async def main():
    async with httpx.AsyncClient() as client:
        plan = await build_buy(
            RPC, wallet.pubkey(), MINT, POOL,
            sol_lamports=100_000_000,   # 0.1 SOL
            slippage_bps=500,           # 5%
            http_client=client,
        )
        blockhash = await fetch_latest_blockhash(RPC, http_client=client)

    print(f"venue={plan.venue} expected_tokens={plan.expected_tokens:,} max_sol={plan.max_sol_in}")

    msg = build_message(wallet.pubkey(), plan.instructions, blockhash)
    tx = VersionedTransaction(msg, [wallet])   # ← you sign
    # ... send `tx` with your RPC's sendTransaction

asyncio.run(main())
```

Selling is symmetric:

```python
plan = await build_sell(RPC, wallet.pubkey(), MINT, POOL, token_amount=1_000_000, http_client=client)
print(plan.expected_sol_out, plan.min_sol_out)
```

### Just want the quote / math? No RPC needed.

```python
from pumpswap import calculate_swap_output

amount_out, fee = calculate_swap_output(
    amount_in=100_000_000,
    reserve_in=5_000_000_000,
    reserve_out=1_000_000_000_000,
    lp_fee_bps=20,
    protocol_fee_bps=5,
)
```

---

## API

### High-level (read pool → unsigned instructions)

| Function | Returns |
|---|---|
| `build_buy(rpc_url, user, token_mint, pool, sol_lamports, *, slippage_bps=500)` | `BuyPlan` |
| `build_sell(rpc_url, user, token_mint, pool, token_amount, *, slippage_bps=500)` | `SellPlan` |

`BuyPlan` / `SellPlan` carry `.instructions`, `.fee`, `.venue`, and the quote
fields (`expected_tokens` / `expected_sol_out`, etc.).

### State readers

`fetch_pool_state` · `fetch_amm_config` · `fetch_vault_balances` · `read_pool_reserves`

### Pump AMM primitives (pure — no RPC)

`calculate_swap_output` · `build_amm_buy_instruction` (23 accounts) ·
`build_amm_sell_instruction` (21 accounts)

### Legacy PumpSwap

`build_legacy_swap_instruction` (13 accounts)

### SPL + tx helpers

`build_create_ata_idempotent` · `build_sol_transfer` · `build_sync_native` ·
`build_close_account` · `build_message` · `prepend_compute_budget` ·
`fetch_latest_blockhash`

### PDAs & constants

`get_associated_token_address` · `get_coin_creator_vault_authority` ·
`get_user_volume_accumulator`; all program IDs and discriminators are exported.

---

## Layout notes (the parts that bite)

- **Program `buy` vs `sell` ≠ user buy/sell.** The instructions are relative to
  the pool's base/quote. `build_buy`/`build_sell` translate intent for you.
- **Reversed pools.** Some Pump AMM pools are `base_mint = SOL`, `quote_mint =
  TOKEN`. `PoolState.base_is_sol` flags it; a user "buy" then maps to a program
  `sell`, and vice-versa.
- **`buy` has 23 accounts, `sell` has 21.** Buy carries the global + user volume
  accumulators; sell does not.
- **Coin-creator vault.** Derived from `coin_creator`, which can legitimately be
  the zero pubkey — don't substitute the pool `creator`, or the on-chain
  constraint fails.
- **Token-2022.** New mints are usually Token-2022; the token program is
  auto-detected per mint.

---

## Also by the author

- **[pumpfun-python](https://github.com/JinUltimate1995/pumpfun-python)** — PumpFun bonding-curve buy/sell.
- **[jupiter-swap-python](https://github.com/JinUltimate1995/jupiter-swap-python)** — Jupiter swap client.
- **[solana-rpc-resilient](https://github.com/JinUltimate1995/solana-rpc-resilient)** — fault-tolerant RPC client.
- **[dexscreener-python](https://github.com/JinUltimate1995/dexscreener-python)** — DexScreener API client.

---

## License

**Free for noncommercial use** under the [PolyForm Noncommercial License 1.0.0](LICENSE.md)
— personal projects, research, education, non-profits.

**Commercial use requires a license** (trading for profit, products/services,
multi-user apps, use inside a company). See **[COMMERCIAL.md](COMMERCIAL.md)**.

---

## Disclaimer

Trading on-chain carries financial risk and these instructions move real funds.
This software is provided "as is", without warranty of any kind. You are
responsible for what you sign and send. Always test with small amounts first.
