2024-12-31 16:51:58 +08:00
# PumpFun Rust SDK
A comprehensive Rust SDK for seamless interaction with the PumpFun Solana program. This SDK provides a robust set of tools and interfaces to integrate PumpFun functionality into your applications.
# Explanation
2025-01-14 19:18:48 +08:00
1. Add `logs_filters` to parse the logs.
1. Add `logs_parser` to process the logs.
2. Add `logs_data` to define the data structure of the logs.
2025-02-21 16:14:36 +08:00
4. Add `trade events` to define the event of the logs.
2025-01-14 19:18:48 +08:00
3. Add `logs_subscribe` to subscribe the logs of the PumpFun program.
6. Add `jito` to send transaction with Jito.
2025-02-21 16:14:36 +08:00
7. Add `yellowstone grpc` to subscribe the logs of the PumpFun program.
2025-01-03 11:14:39 +08:00
## Usage
### logs subscription for token create and trade transaction
```rust
2025-01-24 14:01:56 +08:00
use mai3_pumpfun_sdk ::common ::{
2025-01-03 11:14:39 +08:00
logs_events ::DexEvent ,
logs_subscribe ::{ tokens_subscription , stop_subscription }
};
2025-01-23 17:48:10 +08:00
use solana_sdk ::commitment_config ::CommitmentConfig ;
2025-01-03 11:14:39 +08:00
2025-01-03 11:27:51 +08:00
println! ( "Starting token subscription..." );
2025-01-03 11:14:39 +08:00
2025-01-03 11:27:51 +08:00
// wss
2025-01-03 11:14:39 +08:00
let ws_url = "wss://api.mainnet-beta.solana.com" ;
2025-01-03 11:27:51 +08:00
2025-01-03 11:14:39 +08:00
// Set commitment
let commitment = CommitmentConfig ::confirmed ();
// Define callback function
let callback = | event : DexEvent | {
match event {
DexEvent ::NewToken ( token_info ) => {
println! ( "Received new token event: {:?} " , token_info );
},
2025-01-14 19:18:48 +08:00
DexEvent ::NewUserTrade ( trade_info ) => {
2025-01-03 11:14:39 +08:00
println! ( "Received new trade event: {:?} " , trade_info );
},
2025-01-03 17:06:19 +08:00
DexEvent ::NewBotTrade ( trade_info ) => {
println! ( "Received new bot trade event: {:?} " , trade_info );
}
2025-01-03 11:14:39 +08:00
DexEvent ::Error ( err ) => {
println! ( "Received error: {} " , err );
}
}
};
// Start subscription
let subscription = tokens_subscription (
ws_url ,
commitment ,
2025-01-03 17:06:19 +08:00
callback ,
None
2025-01-03 11:14:39 +08:00
). await . unwrap ();
tokio ::time ::sleep ( tokio ::time ::Duration ::from_secs ( 60 )). await ;
// Stop subscription
stop_subscription ( subscription ). await ;
2025-01-03 11:27:51 +08:00
println! ( "Ended token subscription." );
2025-01-03 11:14:39 +08:00
```
### pumpfun Create, Buy, Sell
```rust
2025-01-23 17:48:10 +08:00
use solana_sdk ::{
native_token ::LAMPORTS_PER_SOL ,
signature ::{ Keypair , Signature },
signer ::Signer ,
2025-01-03 11:14:39 +08:00
};
2025-01-23 17:48:10 +08:00
2025-01-03 11:14:39 +08:00
use mai3_pumpfun_sdk ::{ accounts ::BondingCurveAccount , utils ::CreateTokenMetadata , PriorityFee , PumpFun };
// Create a new PumpFun client
let payer : Keypair = Keypair ::new ();
2025-01-03 15:26:44 +08:00
let client : PumpFun = PumpFun ::new ( Cluster ::Mainnet , None , & payer , None , None );
2025-01-03 11:14:39 +08:00
// Mint keypair
let mint : Keypair = Keypair ::new ();
// Token metadata
let metadata : CreateTokenMetadata = CreateTokenMetadata {
2025-02-21 16:14:36 +08:00
name : "Elon Doge" . to_string (),
symbol : "EDOGE" . to_string (),
description : "Elon Musk Doge" . to_string (),
2025-01-03 11:14:39 +08:00
file : "/path/to/image.png" . to_string (),
twitter : None ,
telegram : None ,
website : Some ( "https://example.com" . to_string ()),
};
// Optional priority fee to expedite transaction processing (e.g., 100 LAMPORTS per compute unit, equivalent to a 0.01 SOL priority fee)
let fee : Option < PriorityFee > = Some ( PriorityFee {
limit : Some ( 100_000 ),
price : Some ( 100_000_000 ),
});
// Create token with metadata
let signature : Signature = client . create ( & mint , metadata . clone (), fee ). await ? ;
println! ( "Created token: {} " , signature );
// Print amount of SOL and LAMPORTS
let amount_sol : u64 = 1 ;
let amount_lamports : u64 = LAMPORTS_PER_SOL * amount_sol ;
println! ( "Amount in SOL: {} " , amount_sol );
println! ( "Amount in LAMPORTS: {} " , amount_lamports );
// Create and buy tokens with metadata
let signature : Signature = client . create_and_buy ( & mint , metadata . clone (), amount_lamports , None , fee ). await ? ;
println! ( "Created and bought tokens: {} " , signature );
// Print the curve
let curve : BondingCurveAccount = client . get_bonding_curve_account ( & mint . pubkey ()) ? ;
println! ( " {:?} " , curve );
// Buy tokens (ATA will be created automatically if needed)
let signature : Signature = client . buy ( & mint . pubkey (), amount_lamports , None , fee ). await ? ;
println! ( "Bought tokens: {} " , signature );
// Sell tokens (sell all tokens)
let signature : Signature = client . sell ( & mint . pubkey (), None , None , fee ). await ? ;
println! ( "Sold tokens: {} " , signature );
```