mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-15 01:48:05 +00:00
grpc optimization
This commit is contained in:
@@ -1,127 +1,108 @@
|
||||
# PumpFun Rust SDK
|
||||
# GrpcParsed
|
||||
|
||||
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.
|
||||
A gRPC client implementation for subscribing to and processing Solana transaction data.
|
||||
|
||||
## Features
|
||||
|
||||
# Explanation
|
||||
1. Add `create, buy, sell` for pump.fun.
|
||||
2. Add `logs_subscribe` to subscribe the logs of the PumpFun program.
|
||||
3. Add `yellowstone grpc` to subscribe the logs of the PumpFun program.
|
||||
4. Add `jito` to send transaction with Jito.
|
||||
5. Add `nextblock` to send transaction with nextblock.
|
||||
6. Add `0slot` to send transaction with 0slot.
|
||||
7. Submit a transaction using Jito, Nextblock, and 0slot simultaneously; the fastest one will succeed, while the others will fail.
|
||||
- Real-time subscription to Solana transaction data via gRPC
|
||||
- Support for processing transaction entries and transactions
|
||||
- Asynchronous transaction data processing
|
||||
- Custom callback function support for transaction events
|
||||
- Built-in error handling mechanism
|
||||
|
||||
## Usage
|
||||
```shell
|
||||
cd `your project root directory`
|
||||
git clone https://github.com/0xfnzero/pumpfun-sdk
|
||||
```
|
||||
## Installation
|
||||
|
||||
Add the following to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
# add to your Cargo.toml
|
||||
pumpfun-sdk = { path = "./pumpfun-sdk", version = "2.4.3" }
|
||||
[dependencies]
|
||||
grpc-parsed = { path = ".", version = "0.1.0" }
|
||||
```
|
||||
|
||||
### logs subscription for token create and trade transaction
|
||||
## Usage Examples
|
||||
|
||||
### 1. Initializing the Client
|
||||
|
||||
```rust
|
||||
use pumpfun_sdk::{common::logs_events::PumpfunEvent, grpc::YellowstoneGrpc};
|
||||
use grpc_parsed::grpc::YellowstoneGrpc;
|
||||
|
||||
// create grpc client
|
||||
let grpc_url = "http://127.0.0.1:10000";
|
||||
let client = YellowstoneGrpc::new(grpc_url);
|
||||
async fn setup_client() -> Result<YellowstoneGrpc, Box<dyn std::error::Error>> {
|
||||
let endpoint = "https://solana-yellowstone-grpc.publicnode.com:443";
|
||||
let client = YellowstoneGrpc::new(endpoint.to_string(), None)?;
|
||||
Ok(client)
|
||||
}
|
||||
```
|
||||
|
||||
// Define callback function
|
||||
let callback = |event: PumpfunEvent| {
|
||||
match event {
|
||||
PumpfunEvent::NewToken(token_info) => {
|
||||
println!("Received new token event: {:?}", token_info);
|
||||
},
|
||||
PumpfunEvent::NewDevTrade(trade_info) => {
|
||||
println!("Received dev trade event: {:?}", trade_info);
|
||||
},
|
||||
PumpfunEvent::NewUserTrade(trade_info) => {
|
||||
println!("Received new trade event: {:?}", trade_info);
|
||||
},
|
||||
PumpfunEvent::NewBotTrade(trade_info) => {
|
||||
println!("Received new bot trade event: {:?}", trade_info);
|
||||
### 2. Subscribing to Transaction Data
|
||||
|
||||
```rust
|
||||
use grpc_parsed::common::logs_events::PumpfunEvent;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
async fn subscribe_to_transactions() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let client = YellowstoneGrpc::new(
|
||||
"https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
|
||||
None,
|
||||
)?;
|
||||
|
||||
let callback = |event: PumpfunEvent| {
|
||||
match event {
|
||||
PumpfunEvent::NewToken(token_info) => {
|
||||
println!("Received new token event: {:?}", token_info);
|
||||
},
|
||||
PumpfunEvent::NewDevTrade(trade_info) => {
|
||||
println!("Received new dev trade event: {:?}", trade_info);
|
||||
},
|
||||
PumpfunEvent::NewUserTrade(trade_info) => {
|
||||
println!("Received new trade event: {:?}", trade_info);
|
||||
},
|
||||
PumpfunEvent::NewBotTrade(trade_info) => {
|
||||
println!("Received new bot trade event: {:?}", trade_info);
|
||||
},
|
||||
PumpfunEvent::Error(err) => {
|
||||
println!("Received error: {}", err);
|
||||
}
|
||||
}
|
||||
PumpfunEvent::Error(err) => {
|
||||
println!("Received error: {}", err);
|
||||
};
|
||||
|
||||
// Optional: Specify bot wallet address for filtering
|
||||
let bot_wallet = None;
|
||||
client.subscribe_pumpfun(callback, bot_wallet).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling
|
||||
|
||||
```rust
|
||||
use grpc_parsed::grpc::YellowstoneGrpc;
|
||||
|
||||
async fn handle_errors() {
|
||||
match YellowstoneGrpc::new(
|
||||
"https://solana-yellowstone-grpc.publicnode.com:443".to_string(),
|
||||
None,
|
||||
) {
|
||||
Ok(client) => {
|
||||
println!("Client initialized successfully");
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("Failed to initialize client: {}", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let payer_keypair = Keypair::from_base58_string("your private key");
|
||||
client.subscribe_pumpfun(callback, Some(payer_keypair.pubkey())).await?;
|
||||
}
|
||||
```
|
||||
|
||||
### Init pumpfun instance for configs
|
||||
```rust
|
||||
use std::sync::Arc;
|
||||
use pumpfun_sdk::{common::{Cluster, PriorityFee}, PumpFun};
|
||||
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair, signer::Signer};
|
||||
## Important Notes
|
||||
|
||||
let priority_fee = PriorityFee{
|
||||
unit_limit: 190000,
|
||||
unit_price: 1000000,
|
||||
buy_tip_fee: 0.001,
|
||||
sell_tip_fee: 0.0001,
|
||||
};
|
||||
- Ensure the gRPC server address is correct and accessible
|
||||
- Callback functions should be thread-safe (Send + Sync)
|
||||
- Implement appropriate error retry mechanisms in production environments
|
||||
- Be mindful of memory usage when processing large volumes of transaction data
|
||||
|
||||
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(),
|
||||
};
|
||||
## License
|
||||
|
||||
// create pumpfun instance
|
||||
let payer = Keypair::from_base58_string("your private key");
|
||||
let pumpfun = PumpFun::new(
|
||||
Arc::new(payer),
|
||||
&cluster,
|
||||
).await;
|
||||
```
|
||||
|
||||
### pumpfun buy 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;
|
||||
|
||||
// Mint keypair
|
||||
let mint_pubkey: Keypair = Keypair::new();
|
||||
|
||||
// buy token with tip
|
||||
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
|
||||
pumpfun.sell_by_percent_with_tip(mint_pubkey, 100, None).await?;
|
||||
|
||||
```
|
||||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
### Telegram group:
|
||||
https://t.me/fnzero_group
|
||||
|
||||
Reference in New Issue
Block a user