2025-01-03 00:38:45 +08:00
|
|
|
use mai3_pumpfun_sdk::instruction::logs_subscribe::tokens_subscription;
|
|
|
|
|
use mai3_pumpfun_sdk::instruction::logs_events::DexEvent;
|
|
|
|
|
use mai3_pumpfun_sdk::instruction::logs_subscribe::stop_subscription;
|
|
|
|
|
use anchor_client::solana_sdk::commitment_config::CommitmentConfig;
|
|
|
|
|
|
2025-01-02 19:44:38 +08:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
use tokio::signal;
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
start_token_subscription().await?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn start_token_subscription() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
println!("Starting token subscription\n");
|
|
|
|
|
|
|
|
|
|
let ws_url = "wss://api.mainnet-beta.solana.com";
|
2025-01-03 00:38:45 +08:00
|
|
|
|
|
|
|
|
// Program address
|
|
|
|
|
let program_address = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
|
|
|
|
|
|
|
|
|
|
// Set commitment
|
2025-01-02 19:44:38 +08:00
|
|
|
let commitment = CommitmentConfig::confirmed();
|
2025-01-03 00:38:45 +08:00
|
|
|
|
|
|
|
|
// Define callback function
|
|
|
|
|
let callback = |event: DexEvent| {
|
|
|
|
|
match event {
|
|
|
|
|
DexEvent::NewToken(token_info) => {
|
|
|
|
|
println!("Received new token event: {:?}", token_info);
|
|
|
|
|
},
|
|
|
|
|
DexEvent::NewTrade(trade_info) => {
|
|
|
|
|
println!("Received new trade event: {:?}", trade_info);
|
|
|
|
|
},
|
|
|
|
|
DexEvent::Error(err) => {
|
|
|
|
|
println!("Received error: {}", err);
|
|
|
|
|
}
|
2025-01-02 19:44:38 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-03 00:38:45 +08:00
|
|
|
// Start subscription
|
|
|
|
|
let subscription = tokens_subscription(
|
2025-01-02 19:44:38 +08:00
|
|
|
ws_url,
|
2025-01-03 00:38:45 +08:00
|
|
|
program_address,
|
2025-01-02 19:44:38 +08:00
|
|
|
commitment,
|
2025-01-03 00:38:45 +08:00
|
|
|
callback
|
2025-01-02 19:44:38 +08:00
|
|
|
).await.unwrap();
|
|
|
|
|
|
2025-01-03 00:38:45 +08:00
|
|
|
// Wait for a while to receive events
|
|
|
|
|
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
|
2025-01-02 19:44:38 +08:00
|
|
|
|
2025-01-03 00:38:45 +08:00
|
|
|
// Stop subscription
|
|
|
|
|
stop_subscription(subscription).await;
|
2025-01-02 19:44:38 +08:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|