pumpfun-toolkit 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. pumpfun_toolkit-0.1.1/.gitignore +31 -0
  2. pumpfun_toolkit-0.1.1/CHANGELOG.md +43 -0
  3. pumpfun_toolkit-0.1.1/LICENSE +21 -0
  4. pumpfun_toolkit-0.1.1/PKG-INFO +290 -0
  5. pumpfun_toolkit-0.1.1/README.md +257 -0
  6. pumpfun_toolkit-0.1.1/docs/api.md +160 -0
  7. pumpfun_toolkit-0.1.1/docs/idl-provenance.md +66 -0
  8. pumpfun_toolkit-0.1.1/examples/decode_transaction.py +56 -0
  9. pumpfun_toolkit-0.1.1/examples/inspect_token.py +85 -0
  10. pumpfun_toolkit-0.1.1/pyproject.toml +74 -0
  11. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/__init__.py +79 -0
  12. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/borsh.py +68 -0
  13. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/constants.py +27 -0
  14. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/curve.py +147 -0
  15. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/errors.py +44 -0
  16. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/events.py +260 -0
  17. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/fees.py +64 -0
  18. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/mint.py +134 -0
  19. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/py.typed +0 -0
  20. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/redact.py +138 -0
  21. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/risk.py +375 -0
  22. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/rpc.py +422 -0
  23. pumpfun_toolkit-0.1.1/src/pumpfun_toolkit/text.py +12 -0
  24. pumpfun_toolkit-0.1.1/tests/__init__.py +0 -0
  25. pumpfun_toolkit-0.1.1/tests/conftest.py +18 -0
  26. pumpfun_toolkit-0.1.1/tests/fakes.py +134 -0
  27. pumpfun_toolkit-0.1.1/tests/fixtures/pump_logs.json +280 -0
  28. pumpfun_toolkit-0.1.1/tests/helpers.py +173 -0
  29. pumpfun_toolkit-0.1.1/tests/test_curve.py +100 -0
  30. pumpfun_toolkit-0.1.1/tests/test_events.py +246 -0
  31. pumpfun_toolkit-0.1.1/tests/test_examples.py +75 -0
  32. pumpfun_toolkit-0.1.1/tests/test_fees_and_text.py +56 -0
  33. pumpfun_toolkit-0.1.1/tests/test_mint.py +85 -0
  34. pumpfun_toolkit-0.1.1/tests/test_package.py +64 -0
  35. pumpfun_toolkit-0.1.1/tests/test_redaction.py +324 -0
  36. pumpfun_toolkit-0.1.1/tests/test_risk.py +216 -0
  37. pumpfun_toolkit-0.1.1/tests/test_rpc.py +195 -0
@@ -0,0 +1,31 @@
1
+ # Secrets - never commit
2
+ .env
3
+ .env.*
4
+ !.env.example
5
+ *.pem
6
+ *.key
7
+ *keypair*.json
8
+ id.json
9
+
10
+ # Python
11
+ __pycache__/
12
+ *.py[cod]
13
+ .venv/
14
+ .venv-*/
15
+ venv/
16
+ build/
17
+ dist/
18
+ *.egg-info/
19
+ .pytest_cache/
20
+ .ruff_cache/
21
+ .mypy_cache/
22
+ .coverage
23
+ .coverage.*
24
+ coverage.xml
25
+ htmlcov/
26
+
27
+ # Editors and OS
28
+ .vscode/
29
+ .idea/
30
+ Thumbs.db
31
+ .DS_Store
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.1] - 2026-11-29
10
+
11
+ First release on PyPI. The library code is unchanged from 0.1.0.
12
+
13
+ ### Added
14
+
15
+ - Release workflow that builds the package once and publishes it to TestPyPI and
16
+ PyPI with Trusted Publishing (OIDC), without a stored API token.
17
+
18
+ ### Changed
19
+
20
+ - README links are absolute, so they also work on the PyPI project page.
21
+ - Installation instructions now use `pip install pumpfun-toolkit`.
22
+
23
+ ## [0.1.0] - 2026-11-29
24
+
25
+ ### Added
26
+
27
+ - Event decoding for `CreateEvent`, `TradeEvent` and `CompleteEvent`, with
28
+ invocation-stack tracking against forged `Program data` lines.
29
+ - Bonding curve account decoding, PDA derivation and constant-product curve math.
30
+ - SPL Token and Token-2022 mint parsing, including extension detection.
31
+ - Heuristic token risk assessment (`pumpfun_toolkit.risk`).
32
+ - Read-only async Solana JSON-RPC client with retries and URL redaction.
33
+ - API keys in RPC URLs are kept out of the request log of `httpx`: the client's own
34
+ HTTP client only sees the redacted URL, and a caller's HTTP client gets a narrow
35
+ log filter (`pumpfun_toolkit.redact`, `redact_url`, `SolanaRpcClient.endpoint`).
36
+ - `InvalidRpcUrlError` for endpoints that are not absolute http(s) URLs;
37
+ `user:password@` in the URL is sent as a Basic auth header.
38
+ - Fee arithmetic and unit conversion helpers.
39
+ - Layouts checked against Pump.fun IDL commit `e244b35` (2026-11-27).
40
+
41
+ [Unreleased]: https://github.com/abidihassanreza12-svg/pumpfun-toolkit/compare/v0.1.1...HEAD
42
+ [0.1.1]: https://github.com/abidihassanreza12-svg/pumpfun-toolkit/compare/v0.1.0...v0.1.1
43
+ [0.1.0]: https://github.com/abidihassanreza12-svg/pumpfun-toolkit/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 abidihassanreza12-svg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,290 @@
1
+ Metadata-Version: 2.5
2
+ Name: pumpfun-toolkit
3
+ Version: 0.1.1
4
+ Summary: Read-only Python tools for the Pump.fun program on Solana: event decoding, bonding curve math, mint inspection and heuristic risk checks.
5
+ Project-URL: Homepage, https://github.com/abidihassanreza12-svg/pumpfun-toolkit
6
+ Project-URL: Documentation, https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/docs/api.md
7
+ Project-URL: Issues, https://github.com/abidihassanreza12-svg/pumpfun-toolkit/issues
8
+ Project-URL: Changelog, https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/CHANGELOG.md
9
+ Author: abidihassanreza12-svg
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: anchor,bonding-curve,borsh,pump.fun,pumpfun,solana,token-2022
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: httpx<1,>=0.28
26
+ Requires-Dist: solders<1,>=0.29
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
29
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
30
+ Requires-Dist: pytest>=8; extra == 'dev'
31
+ Requires-Dist: ruff>=0.8; extra == 'dev'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # pumpfun-toolkit
35
+
36
+ [![CI](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/actions/workflows/ci.yml)
37
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/LICENSE)
38
+ ![Python 3.10–3.13](https://img.shields.io/badge/python-3.10%E2%80%933.13-blue.svg)
39
+
40
+ Read-only Python tools for the [Pump.fun](https://pump.fun) program on Solana.
41
+
42
+ - **Decode program events** (`CreateEvent`, `TradeEvent`, `CompleteEvent`) from
43
+ transaction logs, with protection against events forged by other programs.
44
+ - **Decode bonding curve accounts** and compute price, market cap, progress,
45
+ buy/sell quotes and price impact with exact integer arithmetic.
46
+ - **Inspect SPL Token and Token-2022 mints** for active mint/freeze authorities
47
+ and dangerous extensions (transfer hooks, permanent delegates, pausable, …).
48
+ - **Run a heuristic risk check** over facts you collect.
49
+ - **A small async Solana RPC client** that only allows read-only methods and
50
+ keeps the API key in your endpoint URL out of errors and log lines, including
51
+ the request log of `httpx` (see [API keys and logging](#api-keys-and-logging)).
52
+
53
+ The package **never signs or sends transactions** and never handles private keys.
54
+
55
+ > **Disclaimer.** This project is not affiliated with, endorsed by or sponsored by
56
+ > Pump.fun. It is a technical library, not financial advice. Most tokens launched
57
+ > on Pump.fun lose value; a clean result from the risk check does **not** mean a
58
+ > token is safe to buy.
59
+
60
+ ## Status
61
+
62
+ Alpha (`0.1.1`). The public API may still change. Field layouts follow the official
63
+ Pump.fun IDL at commit
64
+ [`e244b35`](https://github.com/pump-fun/pump-public-docs/blob/e244b35ba70864c029411e81ed1bbd4dee4d2926/idl/pump.json)
65
+ (2026-11-27). See [docs/idl-provenance.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/docs/idl-provenance.md).
66
+
67
+ ## Installation
68
+
69
+ Requires Python 3.10 or newer. Install the release from PyPI:
70
+
71
+ ```bash
72
+ python -m pip install pumpfun-toolkit
73
+ ```
74
+
75
+ or a tagged release straight from GitHub:
76
+
77
+ ```bash
78
+ python -m pip install "pumpfun-toolkit @ git+https://github.com/abidihassanreza12-svg/pumpfun-toolkit.git@v0.1.1"
79
+ ```
80
+
81
+ or from a local clone:
82
+
83
+ ```bash
84
+ git clone https://github.com/abidihassanreza12-svg/pumpfun-toolkit.git
85
+ cd pumpfun-toolkit
86
+ python -m venv .venv
87
+ # Windows: .venv\Scripts\activate macOS/Linux: source .venv/bin/activate
88
+ python -m pip install .
89
+ ```
90
+
91
+ Runtime dependencies: [`solders`](https://github.com/kevinheavey/solders) (public
92
+ key handling and PDA derivation) and [`httpx`](https://www.python-httpx.org/)
93
+ (HTTP client for the RPC module).
94
+
95
+ ## Quick start
96
+
97
+ ### Decode the events of a transaction
98
+
99
+ ```python
100
+ import asyncio
101
+
102
+ from pumpfun_toolkit import CreateEvent, SolanaRpcClient, TradeEvent, decode_logs
103
+
104
+
105
+ async def main() -> None:
106
+ async with SolanaRpcClient("https://api.mainnet-beta.solana.com") as rpc:
107
+ logs = await rpc.get_transaction_logs("<transaction signature>")
108
+ events, failures = decode_logs(logs or [])
109
+ for event in events:
110
+ if isinstance(event, CreateEvent):
111
+ print("created", event.name, event.mint)
112
+ elif isinstance(event, TradeEvent):
113
+ print("buy" if event.is_buy else "sell", event.sol_amount, "lamports")
114
+
115
+
116
+ asyncio.run(main())
117
+ ```
118
+
119
+ You can also feed log lines from a `logsSubscribe` WebSocket notification straight
120
+ into `decode_logs`; no RPC client is needed for decoding.
121
+
122
+ ### Price a bonding curve
123
+
124
+ ```python
125
+ from pumpfun_toolkit import bonding_curve_address, decode_bonding_curve
126
+
127
+ curve_address = bonding_curve_address(mint) # PDA, computed offline
128
+ owner, data = await rpc.get_account_data(curve_address)
129
+ curve = decode_bonding_curve(data)
130
+
131
+ state = curve.state
132
+ state.price_sol # Decimal, SOL per whole token
133
+ state.market_cap_sol # Decimal
134
+ state.tokens_out_for_sol(100_000_000) # quote for 0.1 SOL, fees excluded
135
+ state.price_impact(1_000_000_000) # about 0.0333 (3.3 %) on a fresh curve
136
+ ```
137
+
138
+ ### Inspect a mint
139
+
140
+ ```python
141
+ from pumpfun_toolkit import parse_mint
142
+ from pumpfun_toolkit.mint import DANGEROUS_EXTENSIONS, EXTENSION_NAMES
143
+
144
+ owner, data = await rpc.get_account_data(mint)
145
+ info = parse_mint(owner, data)
146
+
147
+ info.mint_authority # None once revoked
148
+ info.freeze_authority # None once revoked
149
+ for kind in info.extensions:
150
+ print(EXTENSION_NAMES.get(kind, kind), DANGEROUS_EXTENSIONS.get(kind, ""))
151
+ ```
152
+
153
+ ### Heuristic risk check
154
+
155
+ ```python
156
+ from pumpfun_toolkit import SecurityInputs, assess
157
+
158
+ result = assess(SecurityInputs(mint=mint, mint_info=info, curve=curve, token=..., holders=...))
159
+ result.verdict # "blocked", "risky" or "passed"
160
+ result.score # 0..100
161
+ result.findings # list of Finding(code, severity, message, penalty)
162
+ result.missing # information that was not available (blocks the verdict)
163
+ ```
164
+
165
+ `TokenFacts` and `HolderFacts` describe trading activity you observed yourself,
166
+ for example by decoding `TradeEvent`s since the token's creation. The rules,
167
+ penalties and thresholds are documented assumptions and **have not been validated
168
+ against market data**. Missing information always blocks.
169
+
170
+ Runnable versions of these snippets live in [`examples/`](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/tree/main/examples).
171
+
172
+ ## API overview
173
+
174
+ | Module | Main objects | Purpose |
175
+ |---|---|---|
176
+ | `pumpfun_toolkit.events` | `decode_logs`, `decode_event`, `extract_program_data`, `CreateEvent`, `TradeEvent`, `CompleteEvent` | Event decoding from log lines |
177
+ | `pumpfun_toolkit.curve` | `decode_bonding_curve`, `bonding_curve_address`, `CurveState`, `BondingCurveAccount` | Curve account and constant-product math |
178
+ | `pumpfun_toolkit.mint` | `parse_mint`, `MintInfo`, `EXTENSION_NAMES`, `DANGEROUS_EXTENSIONS` | SPL Token / Token-2022 mint parsing |
179
+ | `pumpfun_toolkit.risk` | `assess`, `SecurityInputs`, `TokenFacts`, `HolderFacts`, `Assessment`, `Finding` | Heuristic risk rules (pure function) |
180
+ | `pumpfun_toolkit.rpc` | `SolanaRpcClient`, `READ_ONLY_METHODS` | Read-only async JSON-RPC client |
181
+ | `pumpfun_toolkit.redact` | `redact_url` | Mask API keys in endpoint URLs |
182
+ | `pumpfun_toolkit.fees` | `estimate_fee`, `typical_priority_price`, `lamports_to_sol`, `sol_to_lamports`, `lamports_to_fiat` | Fee arithmetic and unit conversion |
183
+ | `pumpfun_toolkit.borsh` | `BorshReader` | Bounds-checked Borsh reader |
184
+ | `pumpfun_toolkit.text` | `clean_text` | Strip control characters from untrusted token names |
185
+ | `pumpfun_toolkit.errors` | `PumpfunToolkitError`, `DecodeError`, `MintDecodeError`, `SolanaRpcError`, `MethodNotAllowedError`, `InvalidRpcUrlError` | Exception hierarchy |
186
+
187
+ All amounts are integers in base units (lamports, raw token units); derived values
188
+ are `decimal.Decimal`. All data classes are frozen. The full reference with every
189
+ function signature is in [docs/api.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/docs/api.md).
190
+
191
+ ## Design notes
192
+
193
+ **Forged events.** Any Solana program can write a `Program data:` line. If a
194
+ decoder accepts every such line, another program in the same transaction can fake
195
+ a Pump.fun `CreateEvent`. `extract_program_data` follows the
196
+ `invoke [n]` / `success` / `failed` lines of the runtime and only returns data
197
+ written while the Pump.fun program itself is executing.
198
+
199
+ **Forward compatibility.** Pump.fun appends fields to its events and accounts. The
200
+ decoders read the fields they need and ignore trailing bytes, so newer layouts keep
201
+ decoding. Older, shorter layouts are recognised as well (for example trade events
202
+ without a quote mint, which means SOL).
203
+
204
+ **Untrusted input.** Strings are length-limited (2 KiB), booleans must be 0 or 1,
205
+ vectors have plausibility bounds, and every read is bounds-checked. Malformed data
206
+ raises `DecodeError` instead of returning partial results. Token names and symbols
207
+ are chosen by token creators; pass them through `clean_text` before printing them
208
+ to a terminal or log.
209
+
210
+ **Read-only RPC client.** Methods that change chain state (`sendTransaction`,
211
+ `requestAirdrop`, …) are rejected before any request is made.
212
+
213
+ ## API keys and logging
214
+
215
+ RPC providers put API keys into the endpoint URL: into the query
216
+ (`https://mainnet.helius-rpc.com/?api-key=…`), into the path
217
+ (`…/v2/<key>`) or into the user info (`https://user:token@host`).
218
+ `SolanaRpcClient` protects such URLs as follows:
219
+
220
+ | Where | What you see |
221
+ |---|---|
222
+ | `SolanaRpcError` messages and `details`, exception chains, tracebacks | no URL at all |
223
+ | `repr(rpc)`, `rpc.endpoint` | the redacted form, e.g. `https://mainnet.helius-rpc.com/***` |
224
+ | log lines of `pumpfun_toolkit` | no URL at all |
225
+ | request log of `httpx` (`HTTP Request: POST …`, level INFO) | the redacted form |
226
+ | error messages returned by the node | URL and key masked if the node echoes them |
227
+ | an invalid URL | `InvalidRpcUrlError`, which does not repeat the URL |
228
+
229
+ How this works depends on who creates the HTTP client:
230
+
231
+ - **No `http` argument (recommended).** The client creates its own
232
+ `httpx.AsyncClient`, and that client only ever sees the redacted URL. A private
233
+ transport puts the real URL in at the last step, just before the request goes
234
+ to the network. Your logging configuration is not touched. `user:password@` in
235
+ the URL is sent as a Basic auth header. This HTTP client does not read proxy
236
+ environment variables (`HTTPS_PROXY`, …); pass your own client if you need a
237
+ proxy.
238
+ - **Your own `httpx.AsyncClient`.** Your client has to receive the real URL, so
239
+ `httpx` would log it. The RPC client therefore adds one filter to the `httpx`
240
+ logger. It only rewrites records that contain a URL or key registered by a
241
+ `SolanaRpcClient` and leaves all other records, levels and handlers as they
242
+ are. Your own event hooks, transports and middleware still see the real URL.
243
+
244
+ Use `rpc.endpoint` or `pumpfun_toolkit.redact_url(url)` when you want to log
245
+ which endpoint is in use; never log the URL itself.
246
+
247
+ Recommended logging settings for applications:
248
+
249
+ ```python
250
+ import logging
251
+
252
+ logging.basicConfig(level=logging.INFO)
253
+ # Request logs are noisy and rarely needed in production. The key is masked
254
+ # either way; this only reduces volume.
255
+ logging.getLogger("httpx").setLevel(logging.WARNING)
256
+ logging.getLogger("httpcore").setLevel(logging.WARNING)
257
+ ```
258
+
259
+ Limits: the host name is shown, so an endpoint whose host name itself is secret
260
+ is not masked. Error trackers that record the local variables of stack frames
261
+ (for example Sentry with `include_local_variables`) can still capture the URL
262
+ from inside the transport; turn that off or scrub it there. Keep the key in an
263
+ environment variable or a secret store, not in source code.
264
+
265
+ ## Development
266
+
267
+ ```bash
268
+ python -m venv .venv
269
+ python -m pip install -e ".[dev]"
270
+ python -m pytest # tests, no network access
271
+ python -m pytest --cov # with coverage
272
+ python -m ruff check .
273
+ python -m ruff format --check .
274
+ ```
275
+
276
+ The tests run entirely offline: RPC calls go to an in-process fake node or to a
277
+ small HTTP server on `127.0.0.1` started by the tests, and the decoder is also
278
+ checked against real mainnet log captures stored in
279
+ `tests/fixtures/pump_logs.json`.
280
+
281
+ See [CONTRIBUTING.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/CONTRIBUTING.md) for guidelines and
282
+ [SECURITY.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/SECURITY.md) for reporting vulnerabilities.
283
+
284
+ ## License
285
+
286
+ [MIT](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/LICENSE).
287
+
288
+ The Pump.fun IDL is not redistributed in this repository; the decoders are an
289
+ independent implementation of the published layout. "Pump.fun" is used only to
290
+ describe compatibility.
@@ -0,0 +1,257 @@
1
+ # pumpfun-toolkit
2
+
3
+ [![CI](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/actions/workflows/ci.yml/badge.svg)](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/actions/workflows/ci.yml)
4
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/LICENSE)
5
+ ![Python 3.10–3.13](https://img.shields.io/badge/python-3.10%E2%80%933.13-blue.svg)
6
+
7
+ Read-only Python tools for the [Pump.fun](https://pump.fun) program on Solana.
8
+
9
+ - **Decode program events** (`CreateEvent`, `TradeEvent`, `CompleteEvent`) from
10
+ transaction logs, with protection against events forged by other programs.
11
+ - **Decode bonding curve accounts** and compute price, market cap, progress,
12
+ buy/sell quotes and price impact with exact integer arithmetic.
13
+ - **Inspect SPL Token and Token-2022 mints** for active mint/freeze authorities
14
+ and dangerous extensions (transfer hooks, permanent delegates, pausable, …).
15
+ - **Run a heuristic risk check** over facts you collect.
16
+ - **A small async Solana RPC client** that only allows read-only methods and
17
+ keeps the API key in your endpoint URL out of errors and log lines, including
18
+ the request log of `httpx` (see [API keys and logging](#api-keys-and-logging)).
19
+
20
+ The package **never signs or sends transactions** and never handles private keys.
21
+
22
+ > **Disclaimer.** This project is not affiliated with, endorsed by or sponsored by
23
+ > Pump.fun. It is a technical library, not financial advice. Most tokens launched
24
+ > on Pump.fun lose value; a clean result from the risk check does **not** mean a
25
+ > token is safe to buy.
26
+
27
+ ## Status
28
+
29
+ Alpha (`0.1.1`). The public API may still change. Field layouts follow the official
30
+ Pump.fun IDL at commit
31
+ [`e244b35`](https://github.com/pump-fun/pump-public-docs/blob/e244b35ba70864c029411e81ed1bbd4dee4d2926/idl/pump.json)
32
+ (2026-11-27). See [docs/idl-provenance.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/docs/idl-provenance.md).
33
+
34
+ ## Installation
35
+
36
+ Requires Python 3.10 or newer. Install the release from PyPI:
37
+
38
+ ```bash
39
+ python -m pip install pumpfun-toolkit
40
+ ```
41
+
42
+ or a tagged release straight from GitHub:
43
+
44
+ ```bash
45
+ python -m pip install "pumpfun-toolkit @ git+https://github.com/abidihassanreza12-svg/pumpfun-toolkit.git@v0.1.1"
46
+ ```
47
+
48
+ or from a local clone:
49
+
50
+ ```bash
51
+ git clone https://github.com/abidihassanreza12-svg/pumpfun-toolkit.git
52
+ cd pumpfun-toolkit
53
+ python -m venv .venv
54
+ # Windows: .venv\Scripts\activate macOS/Linux: source .venv/bin/activate
55
+ python -m pip install .
56
+ ```
57
+
58
+ Runtime dependencies: [`solders`](https://github.com/kevinheavey/solders) (public
59
+ key handling and PDA derivation) and [`httpx`](https://www.python-httpx.org/)
60
+ (HTTP client for the RPC module).
61
+
62
+ ## Quick start
63
+
64
+ ### Decode the events of a transaction
65
+
66
+ ```python
67
+ import asyncio
68
+
69
+ from pumpfun_toolkit import CreateEvent, SolanaRpcClient, TradeEvent, decode_logs
70
+
71
+
72
+ async def main() -> None:
73
+ async with SolanaRpcClient("https://api.mainnet-beta.solana.com") as rpc:
74
+ logs = await rpc.get_transaction_logs("<transaction signature>")
75
+ events, failures = decode_logs(logs or [])
76
+ for event in events:
77
+ if isinstance(event, CreateEvent):
78
+ print("created", event.name, event.mint)
79
+ elif isinstance(event, TradeEvent):
80
+ print("buy" if event.is_buy else "sell", event.sol_amount, "lamports")
81
+
82
+
83
+ asyncio.run(main())
84
+ ```
85
+
86
+ You can also feed log lines from a `logsSubscribe` WebSocket notification straight
87
+ into `decode_logs`; no RPC client is needed for decoding.
88
+
89
+ ### Price a bonding curve
90
+
91
+ ```python
92
+ from pumpfun_toolkit import bonding_curve_address, decode_bonding_curve
93
+
94
+ curve_address = bonding_curve_address(mint) # PDA, computed offline
95
+ owner, data = await rpc.get_account_data(curve_address)
96
+ curve = decode_bonding_curve(data)
97
+
98
+ state = curve.state
99
+ state.price_sol # Decimal, SOL per whole token
100
+ state.market_cap_sol # Decimal
101
+ state.tokens_out_for_sol(100_000_000) # quote for 0.1 SOL, fees excluded
102
+ state.price_impact(1_000_000_000) # about 0.0333 (3.3 %) on a fresh curve
103
+ ```
104
+
105
+ ### Inspect a mint
106
+
107
+ ```python
108
+ from pumpfun_toolkit import parse_mint
109
+ from pumpfun_toolkit.mint import DANGEROUS_EXTENSIONS, EXTENSION_NAMES
110
+
111
+ owner, data = await rpc.get_account_data(mint)
112
+ info = parse_mint(owner, data)
113
+
114
+ info.mint_authority # None once revoked
115
+ info.freeze_authority # None once revoked
116
+ for kind in info.extensions:
117
+ print(EXTENSION_NAMES.get(kind, kind), DANGEROUS_EXTENSIONS.get(kind, ""))
118
+ ```
119
+
120
+ ### Heuristic risk check
121
+
122
+ ```python
123
+ from pumpfun_toolkit import SecurityInputs, assess
124
+
125
+ result = assess(SecurityInputs(mint=mint, mint_info=info, curve=curve, token=..., holders=...))
126
+ result.verdict # "blocked", "risky" or "passed"
127
+ result.score # 0..100
128
+ result.findings # list of Finding(code, severity, message, penalty)
129
+ result.missing # information that was not available (blocks the verdict)
130
+ ```
131
+
132
+ `TokenFacts` and `HolderFacts` describe trading activity you observed yourself,
133
+ for example by decoding `TradeEvent`s since the token's creation. The rules,
134
+ penalties and thresholds are documented assumptions and **have not been validated
135
+ against market data**. Missing information always blocks.
136
+
137
+ Runnable versions of these snippets live in [`examples/`](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/tree/main/examples).
138
+
139
+ ## API overview
140
+
141
+ | Module | Main objects | Purpose |
142
+ |---|---|---|
143
+ | `pumpfun_toolkit.events` | `decode_logs`, `decode_event`, `extract_program_data`, `CreateEvent`, `TradeEvent`, `CompleteEvent` | Event decoding from log lines |
144
+ | `pumpfun_toolkit.curve` | `decode_bonding_curve`, `bonding_curve_address`, `CurveState`, `BondingCurveAccount` | Curve account and constant-product math |
145
+ | `pumpfun_toolkit.mint` | `parse_mint`, `MintInfo`, `EXTENSION_NAMES`, `DANGEROUS_EXTENSIONS` | SPL Token / Token-2022 mint parsing |
146
+ | `pumpfun_toolkit.risk` | `assess`, `SecurityInputs`, `TokenFacts`, `HolderFacts`, `Assessment`, `Finding` | Heuristic risk rules (pure function) |
147
+ | `pumpfun_toolkit.rpc` | `SolanaRpcClient`, `READ_ONLY_METHODS` | Read-only async JSON-RPC client |
148
+ | `pumpfun_toolkit.redact` | `redact_url` | Mask API keys in endpoint URLs |
149
+ | `pumpfun_toolkit.fees` | `estimate_fee`, `typical_priority_price`, `lamports_to_sol`, `sol_to_lamports`, `lamports_to_fiat` | Fee arithmetic and unit conversion |
150
+ | `pumpfun_toolkit.borsh` | `BorshReader` | Bounds-checked Borsh reader |
151
+ | `pumpfun_toolkit.text` | `clean_text` | Strip control characters from untrusted token names |
152
+ | `pumpfun_toolkit.errors` | `PumpfunToolkitError`, `DecodeError`, `MintDecodeError`, `SolanaRpcError`, `MethodNotAllowedError`, `InvalidRpcUrlError` | Exception hierarchy |
153
+
154
+ All amounts are integers in base units (lamports, raw token units); derived values
155
+ are `decimal.Decimal`. All data classes are frozen. The full reference with every
156
+ function signature is in [docs/api.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/docs/api.md).
157
+
158
+ ## Design notes
159
+
160
+ **Forged events.** Any Solana program can write a `Program data:` line. If a
161
+ decoder accepts every such line, another program in the same transaction can fake
162
+ a Pump.fun `CreateEvent`. `extract_program_data` follows the
163
+ `invoke [n]` / `success` / `failed` lines of the runtime and only returns data
164
+ written while the Pump.fun program itself is executing.
165
+
166
+ **Forward compatibility.** Pump.fun appends fields to its events and accounts. The
167
+ decoders read the fields they need and ignore trailing bytes, so newer layouts keep
168
+ decoding. Older, shorter layouts are recognised as well (for example trade events
169
+ without a quote mint, which means SOL).
170
+
171
+ **Untrusted input.** Strings are length-limited (2 KiB), booleans must be 0 or 1,
172
+ vectors have plausibility bounds, and every read is bounds-checked. Malformed data
173
+ raises `DecodeError` instead of returning partial results. Token names and symbols
174
+ are chosen by token creators; pass them through `clean_text` before printing them
175
+ to a terminal or log.
176
+
177
+ **Read-only RPC client.** Methods that change chain state (`sendTransaction`,
178
+ `requestAirdrop`, …) are rejected before any request is made.
179
+
180
+ ## API keys and logging
181
+
182
+ RPC providers put API keys into the endpoint URL: into the query
183
+ (`https://mainnet.helius-rpc.com/?api-key=…`), into the path
184
+ (`…/v2/<key>`) or into the user info (`https://user:token@host`).
185
+ `SolanaRpcClient` protects such URLs as follows:
186
+
187
+ | Where | What you see |
188
+ |---|---|
189
+ | `SolanaRpcError` messages and `details`, exception chains, tracebacks | no URL at all |
190
+ | `repr(rpc)`, `rpc.endpoint` | the redacted form, e.g. `https://mainnet.helius-rpc.com/***` |
191
+ | log lines of `pumpfun_toolkit` | no URL at all |
192
+ | request log of `httpx` (`HTTP Request: POST …`, level INFO) | the redacted form |
193
+ | error messages returned by the node | URL and key masked if the node echoes them |
194
+ | an invalid URL | `InvalidRpcUrlError`, which does not repeat the URL |
195
+
196
+ How this works depends on who creates the HTTP client:
197
+
198
+ - **No `http` argument (recommended).** The client creates its own
199
+ `httpx.AsyncClient`, and that client only ever sees the redacted URL. A private
200
+ transport puts the real URL in at the last step, just before the request goes
201
+ to the network. Your logging configuration is not touched. `user:password@` in
202
+ the URL is sent as a Basic auth header. This HTTP client does not read proxy
203
+ environment variables (`HTTPS_PROXY`, …); pass your own client if you need a
204
+ proxy.
205
+ - **Your own `httpx.AsyncClient`.** Your client has to receive the real URL, so
206
+ `httpx` would log it. The RPC client therefore adds one filter to the `httpx`
207
+ logger. It only rewrites records that contain a URL or key registered by a
208
+ `SolanaRpcClient` and leaves all other records, levels and handlers as they
209
+ are. Your own event hooks, transports and middleware still see the real URL.
210
+
211
+ Use `rpc.endpoint` or `pumpfun_toolkit.redact_url(url)` when you want to log
212
+ which endpoint is in use; never log the URL itself.
213
+
214
+ Recommended logging settings for applications:
215
+
216
+ ```python
217
+ import logging
218
+
219
+ logging.basicConfig(level=logging.INFO)
220
+ # Request logs are noisy and rarely needed in production. The key is masked
221
+ # either way; this only reduces volume.
222
+ logging.getLogger("httpx").setLevel(logging.WARNING)
223
+ logging.getLogger("httpcore").setLevel(logging.WARNING)
224
+ ```
225
+
226
+ Limits: the host name is shown, so an endpoint whose host name itself is secret
227
+ is not masked. Error trackers that record the local variables of stack frames
228
+ (for example Sentry with `include_local_variables`) can still capture the URL
229
+ from inside the transport; turn that off or scrub it there. Keep the key in an
230
+ environment variable or a secret store, not in source code.
231
+
232
+ ## Development
233
+
234
+ ```bash
235
+ python -m venv .venv
236
+ python -m pip install -e ".[dev]"
237
+ python -m pytest # tests, no network access
238
+ python -m pytest --cov # with coverage
239
+ python -m ruff check .
240
+ python -m ruff format --check .
241
+ ```
242
+
243
+ The tests run entirely offline: RPC calls go to an in-process fake node or to a
244
+ small HTTP server on `127.0.0.1` started by the tests, and the decoder is also
245
+ checked against real mainnet log captures stored in
246
+ `tests/fixtures/pump_logs.json`.
247
+
248
+ See [CONTRIBUTING.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/CONTRIBUTING.md) for guidelines and
249
+ [SECURITY.md](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/SECURITY.md) for reporting vulnerabilities.
250
+
251
+ ## License
252
+
253
+ [MIT](https://github.com/abidihassanreza12-svg/pumpfun-toolkit/blob/main/LICENSE).
254
+
255
+ The Pump.fun IDL is not redistributed in this repository; the decoders are an
256
+ independent implementation of the published layout. "Pump.fun" is used only to
257
+ describe compatibility.