nvm
This commit is contained in:
Generated
+29
-5414
File diff suppressed because it is too large
Load Diff
@@ -10,15 +10,6 @@ futures-util = "0.3.33"
|
|||||||
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
serde = { version = "1.0.229", features = ["derive", "serde_derive"] }
|
||||||
serde_json = "1.0.151"
|
serde_json = "1.0.151"
|
||||||
|
|
||||||
wincode = "=0.5.5"
|
|
||||||
|
|
||||||
solana-client = "=4.0.0"
|
|
||||||
solana-sdk = "=4.0.0"
|
|
||||||
solana-program = "=4.0.0"
|
|
||||||
|
|
||||||
spl-token = "=9.0.0"
|
|
||||||
spl-associated-token-account = "=8.0.0"
|
|
||||||
|
|
||||||
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread"] }
|
||||||
tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] }
|
tokio-tungstenite = { version = "0.30.0", features = ["native-tls"] }
|
||||||
log = "0.4.33"
|
log = "0.4.33"
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pub struct Executor {
|
||||||
|
pub api_key: String,
|
||||||
|
pub public_key: String,
|
||||||
|
pub private_key: String,
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
pub mod pump_fun;
|
|
||||||
|
|
||||||
use solana_sdk::pubkey::Pubkey;
|
|
||||||
|
|
||||||
#[allow(async_fn_in_trait)]
|
|
||||||
pub trait Executor {
|
|
||||||
async fn buy(&self, token: Pubkey, amount: u64) -> anyhow::Result<()>;
|
|
||||||
async fn sell(&self, token: Pubkey, amount: u64) -> anyhow::Result<()>;
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
use solana_sdk::{
|
|
||||||
instruction::{AccountMeta, Instruction},
|
|
||||||
pubkey::Pubkey,
|
|
||||||
};
|
|
||||||
|
|
||||||
use spl_associated_token_account::ID as ASSOCIATED_TOKEN_PROGRAM_ID;
|
|
||||||
use spl_token::ID as TOKEN_PROGRAM_ID;
|
|
||||||
|
|
||||||
macro_rules! declare_id {
|
|
||||||
($name:ident = $l:literal) => {
|
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
|
||||||
#[doc = r" The const program ID."]
|
|
||||||
pub const $name: solana_sdk::pubkey::Pubkey =
|
|
||||||
solana_sdk::pubkey::Pubkey::from_str_const($l);
|
|
||||||
#[cfg(target_arch = "bpf")]
|
|
||||||
#[doc = r" The const program ID."]
|
|
||||||
pub static $name: solana_sdk::pubkey::Pubkey =
|
|
||||||
solana_sdk::pubkey::Pubkey::from_str_const($l);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
declare_id!(PUMP_FUN_PROGRAM_ID = "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5AMX787Nz");
|
|
||||||
declare_id!(GLOBAL_ACCOUNT = "4wTV1YmiEkRvAtN4S7mJP2bXax2p18e4LK8LCHWwEQ2F");
|
|
||||||
declare_id!(FEE_RECIPIENT = "CebN5WG3QfR6EPEDZgbu6wN6sfg92v7S759DcGTR8b61");
|
|
||||||
declare_id!(EVENT_AUTHORITY = "Ce6TQqeHC9p8KBAayQr27Pyy6wJaCdE7wXw8msu3vA8Q");
|
|
||||||
declare_id!(SYS_PROGRAM_ID = "11111111111111111111111111111111");
|
|
||||||
|
|
||||||
const BUY_DISCRIMINATOR: [u8; 8] = [102, 139, 25, 211, 85, 210, 149, 228];
|
|
||||||
|
|
||||||
pub struct PumpFun;
|
|
||||||
|
|
||||||
impl PumpFun {
|
|
||||||
pub fn bonding_curve(mint: &Pubkey) -> (Pubkey, Pubkey) {
|
|
||||||
let (curve, _) =
|
|
||||||
Pubkey::find_program_address(&[b"bonding-curve", mint.as_ref()], &PUMP_FUN_PROGRAM_ID);
|
|
||||||
|
|
||||||
let (curve_ata, _) = Pubkey::find_program_address(
|
|
||||||
&[curve.as_ref(), TOKEN_PROGRAM_ID.as_ref(), mint.as_ref()],
|
|
||||||
&ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
||||||
);
|
|
||||||
|
|
||||||
(curve, curve_ata)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn buy(
|
|
||||||
payer: Pubkey,
|
|
||||||
mint: Pubkey,
|
|
||||||
user_token_account: Pubkey,
|
|
||||||
amount: u64,
|
|
||||||
max_sol_cost: u64,
|
|
||||||
) -> Instruction {
|
|
||||||
let (bonding_curve, bonding_curve_token) = Self::bonding_curve(&mint);
|
|
||||||
|
|
||||||
Instruction {
|
|
||||||
program_id: PUMP_FUN_PROGRAM_ID,
|
|
||||||
accounts: Self::buy_accounts(
|
|
||||||
payer,
|
|
||||||
mint,
|
|
||||||
user_token_account,
|
|
||||||
bonding_curve,
|
|
||||||
bonding_curve_token,
|
|
||||||
),
|
|
||||||
data: Self::buy_data(amount, max_sol_cost),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn buy_data(token_amount: u64, max_sol_cost: u64) -> Vec<u8> {
|
|
||||||
let mut data = Vec::with_capacity(24);
|
|
||||||
|
|
||||||
data.extend_from_slice(&BUY_DISCRIMINATOR);
|
|
||||||
data.extend_from_slice(&token_amount.to_le_bytes());
|
|
||||||
data.extend_from_slice(&max_sol_cost.to_le_bytes());
|
|
||||||
|
|
||||||
data
|
|
||||||
}
|
|
||||||
|
|
||||||
fn buy_accounts(
|
|
||||||
payer: Pubkey,
|
|
||||||
mint: Pubkey,
|
|
||||||
user_token_account: Pubkey,
|
|
||||||
bonding_curve: Pubkey,
|
|
||||||
bonding_curve_token: Pubkey,
|
|
||||||
) -> Vec<AccountMeta> {
|
|
||||||
vec![
|
|
||||||
AccountMeta::new_readonly(GLOBAL_ACCOUNT, false),
|
|
||||||
AccountMeta::new(FEE_RECIPIENT, false),
|
|
||||||
AccountMeta::new_readonly(mint, false),
|
|
||||||
AccountMeta::new(bonding_curve, false),
|
|
||||||
AccountMeta::new(bonding_curve_token, false),
|
|
||||||
AccountMeta::new(user_token_account, false),
|
|
||||||
AccountMeta::new(payer, true),
|
|
||||||
AccountMeta::new_readonly(SYS_PROGRAM_ID, false),
|
|
||||||
AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
|
|
||||||
AccountMeta::new_readonly(solana_sdk::sysvar::rent::ID, false),
|
|
||||||
AccountMeta::new_readonly(EVENT_AUTHORITY, false),
|
|
||||||
AccountMeta::new_readonly(PUMP_FUN_PROGRAM_ID, false),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-35
@@ -1,8 +1,5 @@
|
|||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PumpDevEvent {
|
pub enum PumpDevEvent {
|
||||||
@@ -61,9 +58,9 @@ impl<'de> Deserialize<'de> for PumpDevEvent {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct NewToken {
|
pub struct NewToken {
|
||||||
pub mint: PublicKeyParseable,
|
pub mint: String,
|
||||||
#[serde(rename = "traderPublicKey")]
|
#[serde(rename = "traderPublicKey")]
|
||||||
pub trader_public_key: PublicKeyParseable,
|
pub trader_public_key: String,
|
||||||
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
@@ -73,33 +70,3 @@ pub struct NewToken {
|
|||||||
#[serde(rename = "solAmount")]
|
#[serde(rename = "solAmount")]
|
||||||
pub sol_amount: f64,
|
pub sol_amount: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Deref for PublicKeyParseable {
|
|
||||||
type Target = Pubkey;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::ops::DerefMut for PublicKeyParseable {
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct PublicKeyParseable(pub Pubkey);
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for PublicKeyParseable {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
let value = String::deserialize(deserializer)?;
|
|
||||||
|
|
||||||
Pubkey::from_str(&value)
|
|
||||||
.map(PublicKeyParseable)
|
|
||||||
.map_err(serde::de::Error::custom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user