pumpswap-python-sdk 1.0.0__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. pumpswap_python_sdk-1.0.0/LICENSE +21 -0
  2. pumpswap_python_sdk-1.0.0/MANIFEST.in +16 -0
  3. pumpswap_python_sdk-1.0.0/PKG-INFO +399 -0
  4. pumpswap_python_sdk-1.0.0/README.md +343 -0
  5. pumpswap_python_sdk-1.0.0/examples/basic_swap.py +174 -0
  6. pumpswap_python_sdk-1.0.0/examples/liquidity_management.py +242 -0
  7. pumpswap_python_sdk-1.0.0/pump_swap_sdk/__init__.py +37 -0
  8. pumpswap_python_sdk-1.0.0/pump_swap_sdk/constants.py +30 -0
  9. pumpswap_python_sdk-1.0.0/pump_swap_sdk/exceptions.py +83 -0
  10. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/fees.py +171 -0
  11. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/liquidity_operations.py +328 -0
  12. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/online_pump_amm_sdk.py +431 -0
  13. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/pda.py +231 -0
  14. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/pump_amm_admin_sdk.py +303 -0
  15. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/pump_amm_sdk.py +503 -0
  16. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/swap_operations.py +302 -0
  17. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/token_incentives.py +254 -0
  18. pumpswap_python_sdk-1.0.0/pump_swap_sdk/sdk/utils.py +273 -0
  19. pumpswap_python_sdk-1.0.0/pump_swap_sdk/types/amm_types.py +153 -0
  20. pumpswap_python_sdk-1.0.0/pump_swap_sdk/types/sdk_types.py +193 -0
  21. pumpswap_python_sdk-1.0.0/pump_swap_sdk/validators.py +315 -0
  22. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/PKG-INFO +399 -0
  23. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/SOURCES.txt +35 -0
  24. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/dependency_links.txt +1 -0
  25. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/entry_points.txt +2 -0
  26. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/not-zip-safe +1 -0
  27. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/requires.txt +27 -0
  28. pumpswap_python_sdk-1.0.0/pumpswap_python_sdk.egg-info/top_level.txt +1 -0
  29. pumpswap_python_sdk-1.0.0/pyproject.toml +163 -0
  30. pumpswap_python_sdk-1.0.0/requirements-dev.txt +20 -0
  31. pumpswap_python_sdk-1.0.0/requirements.txt +5 -0
  32. pumpswap_python_sdk-1.0.0/setup.cfg +4 -0
  33. pumpswap_python_sdk-1.0.0/setup.py +107 -0
  34. pumpswap_python_sdk-1.0.0/tests/conftest.py +194 -0
  35. pumpswap_python_sdk-1.0.0/tests/test_liquidity_operations.py +381 -0
  36. pumpswap_python_sdk-1.0.0/tests/test_swap_operations.py +322 -0
  37. pumpswap_python_sdk-1.0.0/tests/test_utils.py +222 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Pump.fun
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,16 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include requirements-dev.txt
5
+ include pyproject.toml
6
+
7
+ recursive-include pump_swap_sdk *.py
8
+ recursive-include tests *.py
9
+ recursive-include docs *.md *.rst
10
+ recursive-include examples *.py *.md
11
+
12
+ global-exclude *.pyc
13
+ global-exclude __pycache__
14
+ global-exclude .DS_Store
15
+ global-exclude *.so
16
+ global-exclude .git*
@@ -0,0 +1,399 @@
1
+ Metadata-Version: 2.4
2
+ Name: pumpswap-python-sdk
3
+ Version: 1.0.0
4
+ Summary: Python SDK for interacting with Pump Swap AMM protocol on Solana
5
+ Home-page: https://github.com/pump-fun/pump-swap-sdk-python
6
+ Author: PumpSwap Python SDK Contributors
7
+ Author-email: PumpSwap Python SDK Contributors <dev@pump.fun>
8
+ Maintainer-email: PumpSwap Team <dev@pump.fun>
9
+ License: MIT
10
+ Project-URL: Documentation, https://docs.pump.fun/sdk/python
11
+ Project-URL: Repository, https://github.com/pump-fun/pump-swap-sdk-python
12
+ Project-URL: Issues, https://github.com/pump-fun/pump-swap-sdk-python/issues
13
+ Project-URL: Homepage, https://pump.fun
14
+ Keywords: solana,blockchain,defi,amm,swap,liquidity,pump,cryptocurrency,trading
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: Office/Business :: Financial :: Investment
26
+ Classifier: Topic :: System :: Networking
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: solders>=0.20.0
31
+ Requires-Dist: solana>=0.32.0
32
+ Requires-Dist: construct>=2.10.0
33
+ Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
37
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
38
+ Requires-Dist: black>=23.0.0; extra == "dev"
39
+ Requires-Dist: isort>=5.0.0; extra == "dev"
40
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
41
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
42
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
43
+ Provides-Extra: docs
44
+ Requires-Dist: sphinx>=6.0.0; extra == "docs"
45
+ Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == "docs"
46
+ Requires-Dist: myst-parser>=1.0.0; extra == "docs"
47
+ Provides-Extra: testing
48
+ Requires-Dist: pytest>=7.0.0; extra == "testing"
49
+ Requires-Dist: pytest-cov>=4.0.0; extra == "testing"
50
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "testing"
51
+ Requires-Dist: responses>=0.23.0; extra == "testing"
52
+ Dynamic: author
53
+ Dynamic: home-page
54
+ Dynamic: license-file
55
+ Dynamic: requires-python
56
+
57
+ # PumpSwap SDK Python
58
+
59
+ A complete Python SDK for interacting with the Pump Swap AMM protocol on Solana. This SDK provides both high-level and low-level interfaces for creating pools, performing swaps, managing liquidity, and collecting fees.
60
+
61
+ ## Features
62
+
63
+ - 🔄 **Token Swaps**: Buy and sell tokens using constant product AMM formula
64
+ - 💧 **Liquidity Management**: Add and remove liquidity from pools
65
+ - 🏭 **Pool Creation**: Create new AMM pools with custom parameters
66
+ - 💰 **Fee Collection**: Collect protocol and creator fees
67
+ - 🎁 **Token Incentives**: Claim trading rewards and incentives
68
+ - 📊 **Real-time Data**: Fetch live pool data and user balances
69
+ - 🔧 **Admin Functions**: Protocol administration and configuration
70
+ - ✅ **Full Validation**: Comprehensive input validation and error handling
71
+
72
+ ## Installation
73
+
74
+ ```bash
75
+ pip install pumpswap-python-sdk
76
+ ```
77
+
78
+ For development:
79
+
80
+ ```bash
81
+ pip install pumpswap-python-sdk[dev]
82
+ ```
83
+
84
+ ## Quick Start
85
+
86
+ ### Basic Usage
87
+
88
+ ```python
89
+ from pump_swap_sdk import PumpAmmSdk, OnlinePumpAmmSdk
90
+ from solana.rpc.api import Client
91
+ from solders.pubkey import Pubkey
92
+
93
+ # Initialize SDK with blockchain connection
94
+ connection = Client("https://api.mainnet-beta.solana.com")
95
+ sdk = OnlinePumpAmmSdk(connection=connection)
96
+
97
+ # Get pool state for swaps
98
+ pool_address = Pubkey.from_string("YOUR_POOL_ADDRESS")
99
+ user_address = Pubkey.from_string("YOUR_WALLET_ADDRESS")
100
+
101
+ swap_state = sdk.swap_solana_state(pool_address, user_address)
102
+
103
+ # Calculate swap amounts
104
+ result = sdk.buy_base_input(
105
+ swap_state=swap_state,
106
+ base=1_000_000, # 1 token (6 decimals)
107
+ slippage=100 # 1% slippage
108
+ )
109
+
110
+ print(f"Quote needed: {result.ui_quote}")
111
+ print(f"Max quote with slippage: {result.max_quote}")
112
+ ```
113
+
114
+ ### Creating a Pool
115
+
116
+ ```python
117
+ from pump_swap_sdk import OnlinePumpAmmSdk
118
+ from solders.keypair import Keypair
119
+
120
+ # Initialize with your keypair
121
+ creator_keypair = Keypair.from_secret_key(your_secret_key)
122
+ sdk = OnlinePumpAmmSdk(connection=connection)
123
+
124
+ # Create pool state
125
+ create_state = sdk.create_pool_solana_state(
126
+ index=0,
127
+ creator=creator_keypair.pubkey(),
128
+ base_mint=Pubkey.from_string("BASE_TOKEN_MINT"),
129
+ quote_mint=Pubkey.from_string("QUOTE_TOKEN_MINT")
130
+ )
131
+
132
+ # Build creation instructions
133
+ instructions = sdk.create_pool_instructions(
134
+ create_pool_state=create_state,
135
+ base_in=1_000_000_000, # Initial base tokens
136
+ quote_in=1_000_000_000 # Initial quote tokens
137
+ )
138
+ ```
139
+
140
+ ### Managing Liquidity
141
+
142
+ ```python
143
+ # Get liquidity state
144
+ liquidity_state = sdk.liquidity_solana_state(pool_address, user_address)
145
+
146
+ # Add liquidity with base token amount
147
+ deposit_result = sdk.deposit_base_input(
148
+ liquidity_state=liquidity_state,
149
+ base=1_000_000, # Base token amount
150
+ slippage=100 # 1% slippage
151
+ )
152
+
153
+ print(f"Quote needed: {deposit_result.quote}")
154
+ print(f"LP tokens to receive: {deposit_result.lp_token}")
155
+
156
+ # Remove liquidity
157
+ withdraw_result = sdk.withdraw_inputs(
158
+ liquidity_state=liquidity_state,
159
+ lp_amount=500_000, # LP tokens to burn
160
+ slippage=100 # 1% slippage
161
+ )
162
+
163
+ print(f"Base tokens to receive: {withdraw_result.base}")
164
+ print(f"Quote tokens to receive: {withdraw_result.quote}")
165
+ ```
166
+
167
+ ## Advanced Usage
168
+
169
+ ### Offline SDK (No Blockchain Connection)
170
+
171
+ ```python
172
+ from pump_swap_sdk import PumpAmmSdk
173
+
174
+ # Use offline SDK for calculations without network calls
175
+ offline_sdk = PumpAmmSdk()
176
+
177
+ # You'll need to provide the state data manually
178
+ from pump_swap_sdk.types import SwapSolanaState, Pool, GlobalConfig
179
+
180
+ # Build state with your data
181
+ swap_state = SwapSolanaState(
182
+ pool=your_pool_data,
183
+ global_config=your_global_config,
184
+ pool_base_amount=base_reserve,
185
+ pool_quote_amount=quote_reserve,
186
+ # ... other required fields
187
+ )
188
+
189
+ # Perform calculations
190
+ result = offline_sdk.buy_base_input(swap_state, 1_000_000, 100)
191
+ ```
192
+
193
+ ### Fee Calculations
194
+
195
+ ```python
196
+ from pump_swap_sdk.sdk.fees import compute_fees_bps
197
+
198
+ # Calculate current fee rates
199
+ fees = compute_fees_bps(
200
+ global_config=global_config,
201
+ fee_config=fee_config,
202
+ market_cap=current_market_cap
203
+ )
204
+
205
+ print(f"LP Fee: {fees.lp_fee_bps} bps")
206
+ print(f"Protocol Fee: {fees.protocol_fee_bps} bps")
207
+ print(f"Creator Fee: {fees.creator_fee_bps} bps")
208
+ print(f"Total Fee: {fees.total_fee_bps} bps")
209
+ ```
210
+
211
+ ### Token Incentives
212
+
213
+ ```python
214
+ # Check unclaimed rewards
215
+ unclaimed = sdk.get_total_unclaimed_tokens(user_address)
216
+ print(f"Unclaimed tokens: {unclaimed}")
217
+
218
+ # Check today's earned rewards
219
+ today_rewards = sdk.get_current_day_tokens(user_address)
220
+ print(f"Today's rewards: {today_rewards}")
221
+ ```
222
+
223
+ ## SDK Architecture
224
+
225
+ ### Core Classes
226
+
227
+ - **`PumpAmmSdk`**: High-level offline SDK for calculations
228
+ - **`OnlinePumpAmmSdk`**: Online SDK with blockchain connectivity
229
+ - **`PumpAmmAdminSdk`**: Admin SDK for protocol management
230
+
231
+ ### Key Modules
232
+
233
+ - **`swap_operations`**: Buy/sell token calculations
234
+ - **`liquidity_operations`**: Deposit/withdraw liquidity calculations
235
+ - **`fees`**: Fee calculation utilities
236
+ - **`token_incentives`**: Trading reward calculations
237
+ - **`pda`**: Program Derived Address utilities
238
+ - **`utils`**: Mathematical and utility functions
239
+
240
+ ## Mathematical Formulas
241
+
242
+ The SDK implements a **constant product AMM** using the formula `x * y = k`:
243
+
244
+ ### Swap Calculations
245
+
246
+ **Buy tokens (base input)**:
247
+ ```
248
+ quote_needed = ceil_div(quote_reserve * base_amount, base_reserve - base_amount)
249
+ ```
250
+
251
+ **Sell tokens (base input)**:
252
+ ```
253
+ quote_received = floor_div(quote_reserve * base_amount, base_reserve + base_amount)
254
+ ```
255
+
256
+ ### Liquidity Calculations
257
+
258
+ **LP tokens for deposit**:
259
+ ```
260
+ lp_tokens = min(
261
+ base_amount * total_lp_supply / base_reserve,
262
+ quote_amount * total_lp_supply / quote_reserve
263
+ )
264
+ ```
265
+
266
+ **Tokens from LP withdrawal**:
267
+ ```
268
+ base_amount = lp_amount * base_reserve / total_lp_supply
269
+ quote_amount = lp_amount * quote_reserve / total_lp_supply
270
+ ```
271
+
272
+ ## Error Handling
273
+
274
+ The SDK provides comprehensive error handling:
275
+
276
+ ```python
277
+ from pump_swap_sdk.exceptions import (
278
+ InsufficientLiquidityError,
279
+ SlippageExceededError,
280
+ ValidationError
281
+ )
282
+
283
+ try:
284
+ result = sdk.buy_base_input(swap_state, amount, slippage)
285
+ except InsufficientLiquidityError:
286
+ print("Not enough liquidity for this trade")
287
+ except SlippageExceededError:
288
+ print("Price moved beyond slippage tolerance")
289
+ except ValidationError as e:
290
+ print(f"Invalid input: {e}")
291
+ ```
292
+
293
+ ## Configuration
294
+
295
+ ### Environment Variables
296
+
297
+ ```bash
298
+ # Solana RPC endpoint
299
+ SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
300
+
301
+ # Program ID (optional, defaults to mainnet)
302
+ PUMP_AMM_PROGRAM_ID=6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P
303
+ ```
304
+
305
+ ### Custom Configuration
306
+
307
+ ```python
308
+ from pump_swap_sdk import OnlinePumpAmmSdk
309
+ from solders.pubkey import Pubkey
310
+
311
+ # Use custom program ID
312
+ custom_program_id = Pubkey.from_string("YOUR_PROGRAM_ID")
313
+ sdk = OnlinePumpAmmSdk(
314
+ connection=connection,
315
+ program_id=custom_program_id
316
+ )
317
+ ```
318
+
319
+ ## Testing
320
+
321
+ Run the test suite:
322
+
323
+ ```bash
324
+ # Install development dependencies
325
+ pip install -e .[dev]
326
+
327
+ # Run tests
328
+ pytest
329
+
330
+ # Run with coverage
331
+ pytest --cov=pump_swap_sdk --cov-report=html
332
+
333
+ # Run specific test categories
334
+ pytest -m unit # Unit tests only
335
+ pytest -m integration # Integration tests only
336
+ ```
337
+
338
+ ## Examples
339
+
340
+ Check out the `examples/` directory for complete working examples:
341
+
342
+ - **`basic_swap.py`**: Simple token swap
343
+ - **`liquidity_management.py`**: Add/remove liquidity
344
+ - **`pool_creation.py`**: Create a new AMM pool
345
+ - **`fee_calculation.py`**: Calculate trading fees
346
+ - **`admin_operations.py`**: Protocol administration
347
+
348
+ ## Contributing
349
+
350
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
351
+
352
+ ### Development Setup
353
+
354
+ ```bash
355
+ # Clone the repository
356
+ git clone https://github.com/pump-fun/pump-swap-sdk-python.git
357
+ cd pump-swap-sdk-python
358
+
359
+ # Create virtual environment
360
+ python -m venv venv
361
+ source venv/bin/activate # Linux/Mac
362
+ # or
363
+ venv\\Scripts\\activate # Windows
364
+
365
+ # Install in development mode
366
+ pip install -e .[dev]
367
+
368
+ # Install pre-commit hooks
369
+ pre-commit install
370
+
371
+ # Run tests
372
+ pytest
373
+ ```
374
+
375
+ ## Documentation
376
+
377
+ - [Full API Documentation](https://docs.pump.fun/sdk/python)
378
+ - [Protocol Documentation](https://docs.pump.fun)
379
+ - [Examples](./examples/)
380
+
381
+ ## Support
382
+
383
+ - [GitHub Issues](https://github.com/pump-fun/pump-swap-sdk-python/issues)
384
+ - [Discord Community](https://discord.gg/pump)
385
+ - [Documentation](https://docs.pump.fun)
386
+
387
+ ## License
388
+
389
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
390
+
391
+ ## Related Projects
392
+
393
+ - [Pump Swap TypeScript SDK](https://github.com/pump-fun/pump-swap-sdk)
394
+ - [Pump.fun Frontend](https://pump.fun)
395
+ - [Solana Program](https://github.com/pump-fun/pump-swap-program)
396
+
397
+ ---
398
+
399
+ Built with ❤️ by the Pump.fun team