update readme

This commit is contained in:
William
2025-04-09 13:36:15 +08:00
parent dfcdf12a7e
commit 716611475b
2 changed files with 153 additions and 51 deletions
+85 -23
View File
@@ -25,8 +25,7 @@ pumpfun-sdk = { path = "./pumpfun-sdk", version = "2.4.3" }
### logs subscription for token create and trade transaction ### logs subscription for token create and trade transaction
```rust ```rust
use std::sync::{Arc, OnceLock}; use pumpfun_sdk::{common::logs_events::PumpfunEvent, grpc::YellowstoneGrpc};
use pumpfun_sdk::grpc::YellowstoneGrpc;
// create grpc client // create grpc client
let grpc_url = "http://127.0.0.1:10000"; let grpc_url = "http://127.0.0.1:10000";
@@ -59,30 +58,80 @@ client.subscribe_pumpfun(callback, Some(payer_keypair.pubkey())).await?;
``` ```
### pumpfun Create, Buy, Sell ### Init Pumpfun instance for configs
```rust ```rust
use std::sync::{Arc, OnceLock}; use std::sync::Arc;
use solana_sdk::{ use pumpfun_sdk::{common::{Cluster, PriorityFee}, PumpFun};
signature::Keypair, use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair, signer::Signer};
commitment_config::CommitmentConfig,
};
use pumpfun_sdk::PumpFun;
use pumpfun_sdk::common::{Cluster, PriorityFee};
let payer = Keypair::from_base58_string(&settings.dex.payer.clone()); let priority_fee = PriorityFee{
let cluster = Cluster::new( unit_limit: 72000,
rpc_url.clone(), unit_price: 1000000,
jito_url.clone(), buy_tip_fee: 0.001,
nextblock_url.clone(), sell_tip_fee: 0.0001,
nextblock_auth_token.clone(), };
zeroslot_url.clone(),
zeroslot_auth_token.clone(), let cluster = Cluster {
rpc_url: "https://api.mainnet-beta.solana.com".to_string(),
block_engine_url: "https://block-engine.example.com".to_string(),
nextblock_url: "https://nextblock.example.com".to_string(),
nextblock_auth_token: "nextblock_api_token".to_string(),
zeroslot_url: "https://zeroslot.example.com".to_string(),
zeroslot_auth_token: "zeroslot_api_token".to_string(),
use_jito: true,
use_nextblock: false,
use_zeroslot: false,
priority_fee, priority_fee,
CommitmentConfig::processed(), commitment: CommitmentConfig::processed(),
use_jito, };
use_nextblock,
use_zeroslot, // create pumpfun instance
); let payer = Keypair::from_base58_string("your private key");
let pumpfun = PumpFun::new(
Arc::new(payer),
&cluster,
).await;
```
### pumpfun Create Token
```rust
use std::sync::Arc;
use pumpfun_sdk::{ipfs, PumpFun};
use solana_sdk::{native_token::sol_to_lamports, signature::Keypair, signer::Signer};
// create pumpfun instance
let pumpfun = PumpFun::new(Arc::new(payer), &cluster).await;
// Mint keypair
let mint_pubkey: Keypair = Keypair::new();
let metadata = ipfs::CreateTokenMetadata {
name: "Doge".to_string(),
symbol: "DOGE".to_string(),
description: "Dogecoin".to_string(),
file: "/Users/joseph/Desktop/doge.png".to_string(),
twitter: None,
telegram: None,
website: None,
metadata_uri: None,
};
// ipfs_api_key for https://api.pinata.cloud
let ipfs_metadata = ipfs::create_token_metadata(metadata, &"".to_string()).await?;
println!("ipfs_metadata: {:?}", ipfs_metadata);
pumpfun.create_and_buy(
mint,
ipfs_metadata,
sol_to_lamports(0.1),
None,
).await?;
```
### pumpfun Buy token
```rust
use pumpfun_sdk::PumpFun;
use solana_sdk::{native_token::sol_to_lamports, signature::Keypair, signer::Signer};
// create pumpfun instance // create pumpfun instance
let pumpfun = PumpFun::new(Arc::new(payer), &cluster).await; let pumpfun = PumpFun::new(Arc::new(payer), &cluster).await;
@@ -93,6 +142,19 @@ let mint_pubkey: Keypair = Keypair::new();
// buy token with tip // buy token with tip
pumpfun.buy_with_tip(mint_pubkey, 10000, None).await?; pumpfun.buy_with_tip(mint_pubkey, 10000, None).await?;
```
### pumpfun Sell token
```rust
use pumpfun_sdk::PumpFun;
use solana_sdk::{native_token::sol_to_lamports, signature::Keypair, signer::Signer};
// create pumpfun instance
let pumpfun = PumpFun::new(Arc::new(payer), &cluster).await;
// sell token with tip
pumpfun.sell_with_tip(mint_pubkey, 100000, None).await?;
// sell token by percent with tip // sell token by percent with tip
pumpfun.sell_by_percent_with_tip(mint_pubkey, 100, None).await?; pumpfun.sell_by_percent_with_tip(mint_pubkey, 100, None).await?;
+68 -28
View File
@@ -1,52 +1,92 @@
use pumpfun_sdk::common::{ use std::sync::Arc;
logs_events::PumpfunEvent, use pumpfun_sdk::{common::{logs_events::PumpfunEvent, Cluster, PriorityFee}, grpc::YellowstoneGrpc, ipfs, PumpFun};
logs_subscribe::{tokens_subscription, stop_subscription} use solana_sdk::{commitment_config::CommitmentConfig, native_token::sol_to_lamports, signature::Keypair, signer::Signer};
};
use solana_sdk::commitment_config::CommitmentConfig;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Starting token subscription\n"); // create grpc client
let grpc_url = "http://127.0.0.1:10000";
let client = YellowstoneGrpc::new(grpc_url.to_string());
let ws_url = "wss://api.mainnet-beta.solana.com";
// Set commitment
let commitment = CommitmentConfig::confirmed();
// Define callback function // Define callback function
let callback = |event: PumpfunEvent| { let callback = |event: PumpfunEvent| {
match event { match event {
PumpfunEvent::NewDevTrade(trade_info) => {
println!("Received new dev trade event: {:?}", trade_info);
},
PumpfunEvent::NewToken(token_info) => { PumpfunEvent::NewToken(token_info) => {
println!("Received new token event: {:?}", token_info); println!("Received new token event: {:?}", token_info);
}, },
PumpfunEvent::NewDevTrade(trade_info) => {
println!("Received dev trade event: {:?}", trade_info);
},
PumpfunEvent::NewUserTrade(trade_info) => { PumpfunEvent::NewUserTrade(trade_info) => {
println!("Received new trade event: {:?}", trade_info); println!("Received new trade event: {:?}", trade_info);
}, },
PumpfunEvent::NewBotTrade(trade_info) => { PumpfunEvent::NewBotTrade(trade_info) => {
println!("Received new bot trade event: {:?}", trade_info); println!("Received new bot trade event: {:?}", trade_info);
}, }
PumpfunEvent::Error(err) => { PumpfunEvent::Error(err) => {
println!("Received error: {}", err); println!("Received error: {}", err);
} }
} }
}; };
// Start subscription let payer_keypair = Keypair::from_base58_string("your private key");
let subscription = tokens_subscription( client.subscribe_pumpfun(callback, Some(payer_keypair.pubkey())).await?;
ws_url,
commitment,
callback,
None
).await.unwrap();
// Wait for a while to receive events
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
// Stop subscription
stop_subscription(subscription).await;
Ok(()) Ok(())
}
async fn create_and_buy() -> Result<(), Box<dyn std::error::Error>> {
let priority_fee = PriorityFee{
unit_limit: 72000,
unit_price: 1000000,
buy_tip_fee: 0.001,
sell_tip_fee: 0.0001,
};
let cluster = Cluster {
rpc_url: "https://api.mainnet-beta.solana.com".to_string(),
block_engine_url: "https://block-engine.example.com".to_string(),
nextblock_url: "https://nextblock.example.com".to_string(),
nextblock_auth_token: "nextblock_api_token".to_string(),
zeroslot_url: "https://zeroslot.example.com".to_string(),
zeroslot_auth_token: "zeroslot_api_token".to_string(),
use_jito: true,
use_nextblock: false,
use_zeroslot: false,
priority_fee,
commitment: CommitmentConfig::processed(),
};
// create pumpfun instance
let payer = Keypair::new();
let pumpfun = PumpFun::new(
Arc::new(payer),
&cluster,
).await;
let metadata = ipfs::CreateTokenMetadata {
name: "Doge".to_string(),
symbol: "DOGE".to_string(),
description: "Dogecoin".to_string(),
file: "/Users/joseph/Desktop/doge.png".to_string(),
twitter: None,
telegram: None,
website: None,
metadata_uri: None,
};
// ipfs_api_key for https://api.pinata.cloud
let ipfs_metadata = ipfs::create_token_metadata(metadata, &"".to_string()).await?;
println!("ipfs_metadata: {:?}", ipfs_metadata);
let mint = Keypair::new();
pumpfun.create_and_buy(
mint,
ipfs_metadata,
sol_to_lamports(0.1),
None,
).await?;
Ok(()) // 添加返回值
} }