A Python module for interacting with Solana's Pump.fun tokens
Project description
PumpSwap
PumpSwap is a Python module for interacting with Solana's Pump.fun tokens. Automatically build instructions for your transaction, or simply use built-in functions to make Pump.fun swaps.
More information here: https://github.com/FLOCK4H/pump_swap
Usage
Example script:
from pump_swap import PumpSwap, usd_to_lamports, lamports_to_tokens, usd_to_microlamports
from decimal import Decimal
import asyncio, aiohttp, json
PRIV_KEY = ""
WALLET = ""
STAKED_API = "" # e.g. staked helius
# Create a PumpSwap object
async def main():
session = aiohttp.ClientSession()
priv_key = PRIV_KEY # str
rpc_endpoint = STAKED_API # str
debug = True
pump_swap = PumpSwap(session=session, priv_key=priv_key, rpc_endpoint=rpc_endpoint, debug=debug)
solana_price = pump_swap.get_solana_price_usd()
solana_price = Decimal(solana_price)
mint_address = "2MWw9bXmevKxuof49uRFb59dAaFAtAydsrXzR4jNpump"
bonding_curve, ass_bonding_curve = await pump_swap.get_bonding_curve_pda(mint_address)
token_price = Decimal("0.0000000280") # Token price can be calculated using vsr/vtr formula.
amount = input("Enter the amount of USD to spend: ")
sol_to_spend = await usd_to_lamports(int(amount.strip()), solana_price)
sol_to_tokens = await lamports_to_tokens(sol_to_spend, token_price)
should_simulate = False
fee = await usd_to_microlamports(0.1, solana_price, 50_000) # 0.1$ per 50k compute units
buy_sig = await pump_swap.pump_buy(
mint_address=mint_address,
bonding_curve_pda=bonding_curve,
sol_amount=sol_to_spend,
token_amount=sol_to_tokens,
sim=should_simulate,
priority_micro_lamports=fee,
slippage=1.5 # e.g. 50% slippage
)
# Here we get signature of the transaction
result_json = buy_sig.to_json()
transaction_id = json.loads(result_json).get('result')
print("Buy: ", transaction_id)
# Then we can use it to verify if we got success
verify = await pump_swap.getTransaction(transaction_id, session)
print(f"{json.dumps(verify, indent=2)}")
await asyncio.sleep(5)
sell_sig = await pump_swap.pump_sell(
mint_address=mint_address,
bonding_curve_pda=bonding_curve,
token_amount=sol_to_tokens,
sim=should_simulate,
priority_micro_lamports=fee,
)
result_json = sell_sig.to_json()
transaction_id = json.loads(result_json).get('result')
print("Sell: ", transaction_id)
verify = await pump_swap.getTransaction(transaction_id, session)
print(f"{json.dumps(verify, indent=2)}")
# Close all instances when done
await pump_swap.close()
if __name__ == "__main__":
asyncio.run(main())
Features
- Create, sign, and send Solana transactions for Pump.fun tokens.
- Fetch wallet balances and Solana price in USD.
- Automatically derive bonding curve and associated token addresses.
- Utility functions for converting USD to lamports and tokens.
Installation
Install via pip:
pip install pump_swap
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pump_swap-0.7.0.tar.gz
(8.0 kB
view details)
Built Distribution
File details
Details for the file pump_swap-0.7.0.tar.gz
.
File metadata
- Download URL: pump_swap-0.7.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
67d772b860ac3e6c3c8598996f24dd6d78b112e26e2efc0569f572aa0d5ddcff
|
|
MD5 |
d2f60a799ba827bccdb2e6f6e0a9b65f
|
|
BLAKE2b-256 |
10d0ff8e92e88fd9d0c74005d2c965761d2af88a0231f1fd41ac501c71952904
|
File details
Details for the file pump_swap-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: pump_swap-0.7.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
8fd4e8dbadd59da694018d4df9a7cbceecd681aa3ab359b260e80e84137315bd
|
|
MD5 |
a17fba6621cfbe4542d56aae53711c98
|
|
BLAKE2b-256 |
8fcd49cd93665f63045de7f863ba89a94081ed974dc1ff7ccf716d14e01f6663
|