mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-17 02:48:05 +00:00
feat: Add account event parser and protocol type definitions
- Add account event parser (account_event_parser.rs) for account-level event handling - Introduce type definitions for pumpfun, pumpswap, raydium_amm_v4, raydium_clmm, raydium_cpmm protocols - Enhance event processor to support account event processing alongside transactions - Improve subscription system with separate transaction and account filters - Optimize parser configuration using Option types for cleaner code structure - Update examples and documentation to reflect new capabilities Changes include: - 6 new types.rs files for protocol-specific data structures - Updated event processor for account, transaction, and block meta events - Refactored subscription manager with account filtering support - Enhanced metrics and batch processing logic
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::streaming::event_parser::protocols::bonk::types::{
|
||||
CurveParams, MintParams, PoolStatus, TradeDirection, VestingParams,
|
||||
};
|
||||
use crate::streaming::event_parser::protocols::bonk::{GlobalConfig, PlatformConfig, PoolState};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -231,6 +232,45 @@ pub struct BonkMigrateToCpswapEvent {
|
||||
// Macro to generate UnifiedEvent implementation, specifying the fields to be merged
|
||||
impl_unified_event!(BonkMigrateToCpswapEvent,);
|
||||
|
||||
/// 池状态
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkPoolStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
impl_unified_event!(BonkPoolStateAccountEvent,);
|
||||
|
||||
/// 全局配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkGlobalConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub global_config: GlobalConfig,
|
||||
}
|
||||
impl_unified_event!(BonkGlobalConfigAccountEvent,);
|
||||
|
||||
/// 平台配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BonkPlatformConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub platform_config: PlatformConfig,
|
||||
}
|
||||
impl_unified_event!(BonkPlatformConfigAccountEvent,);
|
||||
|
||||
/// Event discriminator constants
|
||||
pub mod discriminators {
|
||||
// Event discriminators
|
||||
@@ -245,4 +285,9 @@ pub mod discriminators {
|
||||
pub const INITIALIZE: &[u8] = &[175, 175, 109, 31, 13, 152, 155, 237];
|
||||
pub const MIGRATE_TO_AMM: &[u8] = &[207, 82, 192, 145, 254, 207, 145, 223];
|
||||
pub const MIGRATE_TO_CP_SWAP: &[u8] = &[136, 92, 200, 103, 28, 218, 144, 140];
|
||||
|
||||
// 账户鉴别器
|
||||
pub const POOL_STATE_ACCOUNT: &[u8] = &[247, 237, 227, 245, 215, 195, 222, 70];
|
||||
pub const GLOBAL_CONFIG_ACCOUNT: &[u8] = &[149, 8, 156, 202, 160, 252, 176, 217];
|
||||
pub const PLATFORM_CONFIG_ACCOUNT: &[u8] = &[160, 78, 128, 0, 248, 83, 230, 160];
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_EXACT_IN,
|
||||
event_type: EventType::BonkBuyExactIn,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_exact_in_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_buy_exact_in_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -48,8 +48,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_EXACT_OUT,
|
||||
event_type: EventType::BonkBuyExactOut,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_exact_out_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_buy_exact_out_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -57,8 +57,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_EXACT_IN,
|
||||
event_type: EventType::BonkSellExactIn,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_exact_in_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_sell_exact_in_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -66,8 +66,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_EXACT_OUT,
|
||||
event_type: EventType::BonkSellExactOut,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_exact_out_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_sell_exact_out_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -75,8 +75,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: discriminators::POOL_CREATE_EVENT,
|
||||
instruction_discriminator: discriminators::INITIALIZE,
|
||||
event_type: EventType::BonkInitialize,
|
||||
inner_instruction_parser: Self::parse_pool_create_inner_instruction,
|
||||
instruction_parser: Self::parse_initialize_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_pool_create_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_initialize_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -84,8 +84,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::MIGRATE_TO_AMM,
|
||||
event_type: EventType::BonkMigrateToAmm,
|
||||
inner_instruction_parser: Self::parse_migrate_to_amm_inner_instruction,
|
||||
instruction_parser: Self::parse_migrate_to_amm_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_migrate_to_amm_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: BONK_PROGRAM_ID,
|
||||
@@ -93,8 +93,8 @@ impl BonkEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::MIGRATE_TO_CP_SWAP,
|
||||
event_type: EventType::BonkMigrateToCpswap,
|
||||
inner_instruction_parser: Self::parse_migrate_to_cpswap_inner_instruction,
|
||||
instruction_parser: Self::parse_migrate_to_cpswap_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_migrate_to_cpswap_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -117,22 +117,6 @@ impl BonkEventParser {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse migrate to AMM event
|
||||
fn parse_migrate_to_amm_inner_instruction(
|
||||
_data: &[u8],
|
||||
_metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Parse migrate to CP Swap event
|
||||
fn parse_migrate_to_cpswap_inner_instruction(
|
||||
_data: &[u8],
|
||||
_metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Parse trade event
|
||||
fn parse_trade_inner_instruction(
|
||||
data: &[u8],
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::bonk::{BonkGlobalConfigAccountEvent, BonkPlatformConfigAccountEvent, BonkPoolStateAccountEvent},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub enum TradeDirection {
|
||||
@@ -62,8 +72,165 @@ pub enum CurveParams {
|
||||
|
||||
impl Default for CurveParams {
|
||||
fn default() -> Self {
|
||||
Self::Constant {
|
||||
data: ConstantCurve::default(),
|
||||
}
|
||||
Self::Constant { data: ConstantCurve::default() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct VestingSchedule {
|
||||
pub total_locked_amount: u64,
|
||||
pub cliff_period: u64,
|
||||
pub unlock_period: u64,
|
||||
pub start_time: u64,
|
||||
pub allocated_share_amount: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PoolState {
|
||||
pub epoch: u64,
|
||||
pub auth_bump: u8,
|
||||
pub status: u8,
|
||||
pub base_decimals: u8,
|
||||
pub quote_decimals: u8,
|
||||
pub migrate_type: u8,
|
||||
pub supply: u64,
|
||||
pub total_base_sell: u64,
|
||||
pub virtual_base: u64,
|
||||
pub virtual_quote: u64,
|
||||
pub real_base: u64,
|
||||
pub real_quote: u64,
|
||||
pub total_quote_fund_raising: u64,
|
||||
pub quote_protocol_fee: u64,
|
||||
pub platform_fee: u64,
|
||||
pub migrate_fee: u64,
|
||||
pub vesting_schedule: VestingSchedule,
|
||||
pub global_config: Pubkey,
|
||||
pub platform_config: Pubkey,
|
||||
pub base_mint: Pubkey,
|
||||
pub quote_mint: Pubkey,
|
||||
pub base_vault: Pubkey,
|
||||
pub quote_vault: Pubkey,
|
||||
pub creator: Pubkey,
|
||||
pub padding: [u64; 8],
|
||||
}
|
||||
|
||||
pub const POOL_STATE_SIZE: usize = 8 + 1 * 5 + 8 * 10 + 32 * 7 + 8 * 8 + 8 * 5;
|
||||
|
||||
pub fn pool_state_decode(data: &[u8]) -> Option<PoolState> {
|
||||
if data.len() < POOL_STATE_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<PoolState>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn pool_state_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(BonkPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct GlobalConfig {
|
||||
pub epoch: u64,
|
||||
pub curve_type: u8,
|
||||
pub index: u16,
|
||||
pub migrate_fee: u64,
|
||||
pub trade_fee_rate: u64,
|
||||
pub max_share_fee_rate: u64,
|
||||
pub min_base_supply: u64,
|
||||
pub max_lock_rate: u64,
|
||||
pub min_base_sell_rate: u64,
|
||||
pub min_base_migrate_rate: u64,
|
||||
pub min_quote_fund_raising: u64,
|
||||
pub quote_mint: Pubkey,
|
||||
pub protocol_fee_owner: Pubkey,
|
||||
pub migrate_fee_owner: Pubkey,
|
||||
pub migrate_to_amm_wallet: Pubkey,
|
||||
pub migrate_to_cpswap_wallet: Pubkey,
|
||||
pub padding: [u64; 16],
|
||||
}
|
||||
|
||||
pub const GLOBAL_CONFIG_SIZE: usize = 8 + 1 + 2 + 8 * 8 + 32 * 5 + 8 * 16;
|
||||
|
||||
pub fn global_config_decode(data: &[u8]) -> Option<GlobalConfig> {
|
||||
if data.len() < GLOBAL_CONFIG_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<GlobalConfig>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn global_config_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(global_config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(BonkGlobalConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
global_config,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PlatformConfig {
|
||||
pub epoch: u64,
|
||||
pub platform_fee_wallet: Pubkey,
|
||||
pub platform_nft_wallet: Pubkey,
|
||||
pub platform_scale: u64,
|
||||
pub creator_scale: u64,
|
||||
pub burn_scale: u64,
|
||||
pub fee_rate: u64,
|
||||
pub name: Vec<u8>,
|
||||
pub web: Vec<u8>,
|
||||
pub img: Vec<u8>,
|
||||
pub padding: Vec<u8>,
|
||||
}
|
||||
|
||||
pub const PLATFORM_CONFIG_SIZE: usize = 8 + 32 * 2 + 8 * 4 + 8 * 64 + 8 * 256 + 8 * 256 + 8 * 256;
|
||||
|
||||
pub fn platform_config_decode(data: &[u8]) -> Option<PlatformConfig> {
|
||||
if data.len() < PLATFORM_CONFIG_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<PlatformConfig>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn platform_config_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(platform_config) =
|
||||
platform_config_decode(&account.data[8..PLATFORM_CONFIG_SIZE + 8])
|
||||
{
|
||||
Some(Box::new(BonkPlatformConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
platform_config,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::streaming::event_parser::protocols::pumpfun::types::{BondingCurve, Global};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpFunCreateTokenEvent {
|
||||
@@ -177,6 +178,35 @@ impl_unified_event!(
|
||||
pool
|
||||
);
|
||||
|
||||
/// 铸币曲线
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpFunBondingCurveAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub bonding_curve: BondingCurve,
|
||||
}
|
||||
|
||||
impl_unified_event!(PumpFunBondingCurveAccountEvent,);
|
||||
|
||||
/// 全局配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpFunGlobalAccountEvent {
|
||||
#[borsh(skip)]
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub global: Global,
|
||||
}
|
||||
impl_unified_event!(PumpFunGlobalAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 事件鉴别器
|
||||
@@ -189,4 +219,8 @@ pub mod discriminators {
|
||||
pub const BUY_IX: &[u8] = &[102, 6, 61, 18, 1, 218, 235, 234];
|
||||
pub const SELL_IX: &[u8] = &[51, 230, 133, 164, 1, 127, 131, 173];
|
||||
pub const MIGRATE_IX: &[u8] = &[155, 234, 231, 146, 236, 158, 162, 30];
|
||||
|
||||
// 账户鉴别器
|
||||
pub const BONDING_CURVE_ACCOUNT: &[u8] = &[23, 183, 248, 55, 96, 216, 172, 96];
|
||||
pub const GLOBAL_ACCOUNT: &[u8] = &[167, 232, 232, 177, 200, 108, 114, 127];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::PumpFunEventParser;
|
||||
@@ -37,8 +37,8 @@ impl PumpFunEventParser {
|
||||
inner_instruction_discriminator: discriminators::CREATE_TOKEN_EVENT,
|
||||
instruction_discriminator: discriminators::CREATE_TOKEN_IX,
|
||||
event_type: EventType::PumpFunCreateToken,
|
||||
inner_instruction_parser: Self::parse_create_token_inner_instruction,
|
||||
instruction_parser: Self::parse_create_token_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_create_token_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_create_token_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPFUN_PROGRAM_ID,
|
||||
@@ -46,8 +46,8 @@ impl PumpFunEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_IX,
|
||||
event_type: EventType::PumpFunBuy,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_buy_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPFUN_PROGRAM_ID,
|
||||
@@ -55,8 +55,8 @@ impl PumpFunEventParser {
|
||||
inner_instruction_discriminator: discriminators::TRADE_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_IX,
|
||||
event_type: EventType::PumpFunSell,
|
||||
inner_instruction_parser: Self::parse_trade_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_trade_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_sell_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPFUN_PROGRAM_ID,
|
||||
@@ -64,8 +64,8 @@ impl PumpFunEventParser {
|
||||
inner_instruction_discriminator: discriminators::COMPLETE_PUMP_AMM_MIGRATION_EVENT,
|
||||
instruction_discriminator: discriminators::MIGRATE_IX,
|
||||
event_type: EventType::PumpFunMigrate,
|
||||
inner_instruction_parser: Self::parse_migrate_inner_instruction,
|
||||
instruction_parser: Self::parse_migrate_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_migrate_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_migrate_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::pumpfun::{PumpFunBondingCurveAccountEvent, PumpFunGlobalAccountEvent},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct BondingCurve {
|
||||
pub virtual_token_reserves: u64,
|
||||
pub virtual_sol_reserves: u64,
|
||||
pub real_token_reserves: u64,
|
||||
pub real_sol_reserves: u64,
|
||||
pub token_total_supply: u64,
|
||||
pub complete: bool,
|
||||
pub creator: Pubkey,
|
||||
}
|
||||
|
||||
pub const BONDING_CURVE_SIZE: usize = 8 * 5 + 1 + 32;
|
||||
|
||||
pub fn bonding_curve_decode(data: &[u8]) -> Option<BondingCurve> {
|
||||
if data.len() < BONDING_CURVE_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<BondingCurve>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn bonding_curve_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(bonding_curve) = bonding_curve_decode(&account.data[8..BONDING_CURVE_SIZE + 8]) {
|
||||
Some(Box::new(PumpFunBondingCurveAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
bonding_curve,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct Global {
|
||||
pub initialized: bool,
|
||||
pub authority: Pubkey,
|
||||
pub fee_recipient: Pubkey,
|
||||
pub initial_virtual_token_reserves: u64,
|
||||
pub initial_virtual_sol_reserves: u64,
|
||||
pub initial_real_token_reserves: u64,
|
||||
pub token_total_supply: u64,
|
||||
pub fee_basis_points: u64,
|
||||
pub withdraw_authority: Pubkey,
|
||||
pub enable_migrate: bool,
|
||||
pub pool_migration_fee: u64,
|
||||
pub creator_fee_basis_points: u64,
|
||||
pub fee_recipients: [Pubkey; 7],
|
||||
pub set_creator_authority: Pubkey,
|
||||
pub admin_set_creator_authority: Pubkey,
|
||||
}
|
||||
|
||||
pub const GLOBAL_SIZE: usize = 1 + 32 * 2 + 8 * 5 + 32 + 1 + 8 * 2 + 32 * 7 + 32 * 2;
|
||||
|
||||
pub fn global_decode(data: &[u8]) -> Option<Global> {
|
||||
if data.len() < GLOBAL_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<Global>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn global_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(global) = global_decode(&account.data[8..GLOBAL_SIZE + 8]) {
|
||||
Some(Box::new(PumpFunGlobalAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
global,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@ use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::streaming::event_parser::protocols::pumpswap::types::{GlobalConfig, Pool};
|
||||
|
||||
/// 买入事件
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
@@ -309,6 +310,32 @@ impl_unified_event!(
|
||||
user_pool_token_account
|
||||
);
|
||||
|
||||
/// 全局配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpSwapGlobalConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub global_config: GlobalConfig,
|
||||
}
|
||||
impl_unified_event!(PumpSwapGlobalConfigAccountEvent,);
|
||||
|
||||
/// 池
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PumpSwapPoolAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub pool: Pool,
|
||||
}
|
||||
impl_unified_event!(PumpSwapPoolAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 事件鉴别器
|
||||
@@ -324,4 +351,8 @@ pub mod discriminators {
|
||||
pub const CREATE_POOL_IX: &[u8] = &[233, 146, 209, 142, 207, 104, 64, 188];
|
||||
pub const DEPOSIT_IX: &[u8] = &[242, 35, 198, 137, 82, 225, 242, 182];
|
||||
pub const WITHDRAW_IX: &[u8] = &[183, 18, 70, 156, 148, 109, 161, 34];
|
||||
|
||||
// 账户鉴别器
|
||||
pub const GLOBAL_CONFIG_ACCOUNT: &[u8] = &[149, 8, 156, 202, 160, 252, 176, 217];
|
||||
pub const POOL_ACCOUNT: &[u8] = &[241, 154, 109, 4, 17, 177, 109, 188];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::PumpSwapEventParser;
|
||||
pub use parser::PumpSwapEventParser;
|
||||
|
||||
@@ -38,8 +38,8 @@ impl PumpSwapEventParser {
|
||||
inner_instruction_discriminator: discriminators::BUY_EVENT,
|
||||
instruction_discriminator: discriminators::BUY_IX,
|
||||
event_type: EventType::PumpSwapBuy,
|
||||
inner_instruction_parser: Self::parse_buy_inner_instruction,
|
||||
instruction_parser: Self::parse_buy_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_buy_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_buy_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPSWAP_PROGRAM_ID,
|
||||
@@ -47,8 +47,8 @@ impl PumpSwapEventParser {
|
||||
inner_instruction_discriminator: discriminators::SELL_EVENT,
|
||||
instruction_discriminator: discriminators::SELL_IX,
|
||||
event_type: EventType::PumpSwapSell,
|
||||
inner_instruction_parser: Self::parse_sell_inner_instruction,
|
||||
instruction_parser: Self::parse_sell_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_sell_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_sell_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPSWAP_PROGRAM_ID,
|
||||
@@ -56,8 +56,8 @@ impl PumpSwapEventParser {
|
||||
inner_instruction_discriminator: discriminators::CREATE_POOL_EVENT,
|
||||
instruction_discriminator: discriminators::CREATE_POOL_IX,
|
||||
event_type: EventType::PumpSwapCreatePool,
|
||||
inner_instruction_parser: Self::parse_create_pool_inner_instruction,
|
||||
instruction_parser: Self::parse_create_pool_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_create_pool_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_create_pool_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPSWAP_PROGRAM_ID,
|
||||
@@ -65,8 +65,8 @@ impl PumpSwapEventParser {
|
||||
inner_instruction_discriminator: discriminators::DEPOSIT_EVENT,
|
||||
instruction_discriminator: discriminators::DEPOSIT_IX,
|
||||
event_type: EventType::PumpSwapDeposit,
|
||||
inner_instruction_parser: Self::parse_deposit_inner_instruction,
|
||||
instruction_parser: Self::parse_deposit_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_deposit_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_deposit_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: PUMPSWAP_PROGRAM_ID,
|
||||
@@ -74,8 +74,8 @@ impl PumpSwapEventParser {
|
||||
inner_instruction_discriminator: discriminators::WITHDRAW_EVENT,
|
||||
instruction_discriminator: discriminators::WITHDRAW_IX,
|
||||
event_type: EventType::PumpSwapWithdraw,
|
||||
inner_instruction_parser: Self::parse_withdraw_inner_instruction,
|
||||
instruction_parser: Self::parse_withdraw_instruction,
|
||||
inner_instruction_parser: Some(Self::parse_withdraw_inner_instruction),
|
||||
instruction_parser: Some(Self::parse_withdraw_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::pumpswap::{
|
||||
parser::PUMPSWAP_PROGRAM_ID, PumpSwapGlobalConfigAccountEvent, PumpSwapPoolAccountEvent,
|
||||
},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct GlobalConfig {
|
||||
pub admin: Pubkey,
|
||||
pub lp_fee_basis_points: u64,
|
||||
pub protocol_fee_basis_points: u64,
|
||||
pub disable_flags: u8,
|
||||
pub protocol_fee_recipients: [Pubkey; 8],
|
||||
pub coin_creator_fee_basis_points: u64,
|
||||
pub admin_set_coin_creator_authority: Pubkey,
|
||||
}
|
||||
|
||||
pub const GLOBAL_CONFIG_SIZE: usize = 32 + 8 + 8 + 1 + 32 * 8 + 8 + 32;
|
||||
|
||||
pub fn global_config_decode(data: &[u8]) -> Option<GlobalConfig> {
|
||||
if data.len() < GLOBAL_CONFIG_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<GlobalConfig>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn global_config_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(PumpSwapGlobalConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
global_config: config,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct Pool {
|
||||
pub pool_bump: u8,
|
||||
pub index: u16,
|
||||
pub creator: Pubkey,
|
||||
pub base_mint: Pubkey,
|
||||
pub quote_mint: Pubkey,
|
||||
pub lp_mint: Pubkey,
|
||||
pub pool_base_token_account: Pubkey,
|
||||
pub pool_quote_token_account: Pubkey,
|
||||
pub lp_supply: u64,
|
||||
pub coin_creator: Pubkey,
|
||||
}
|
||||
|
||||
pub const POOL_SIZE: usize = 1 + 2 + 32 * 6 + 8 + 32;
|
||||
|
||||
pub fn pool_decode(data: &[u8]) -> Option<Pool> {
|
||||
if data.len() < POOL_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<Pool>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn pool_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if let Some(pool) = pool_decode(&account.data[8..POOL_SIZE + 8]) {
|
||||
Some(Box::new(PumpSwapPoolAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool: pool,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::{
|
||||
impl_unified_event, streaming::event_parser::protocols::raydium_amm_v4::types::AmmInfo,
|
||||
};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -151,6 +153,19 @@ pub struct RaydiumAmmV4WithdrawPnlEvent {
|
||||
}
|
||||
impl_unified_event!(RaydiumAmmV4WithdrawPnlEvent,);
|
||||
|
||||
/// 池信息
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumAmmV4AmmInfoAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_info: AmmInfo,
|
||||
}
|
||||
impl_unified_event!(RaydiumAmmV4AmmInfoAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 指令鉴别器
|
||||
@@ -160,4 +175,7 @@ pub mod discriminators {
|
||||
pub const INITIALIZE2: &[u8] = &[01];
|
||||
pub const WITHDRAW: &[u8] = &[04];
|
||||
pub const WITHDRAW_PNL: &[u8] = &[07];
|
||||
|
||||
/// 池信息鉴别器
|
||||
pub const AMM_INFO: &[u8] = &[6];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::RaydiumAmmV4EventParser;
|
||||
|
||||
@@ -38,8 +38,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_IN,
|
||||
event_type: EventType::RaydiumAmmV4SwapBaseIn,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_input_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_input_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -47,8 +47,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_OUT,
|
||||
event_type: EventType::RaydiumAmmV4SwapBaseOut,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_output_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_output_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -56,8 +56,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::DEPOSIT,
|
||||
event_type: EventType::RaydiumAmmV4Deposit,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_deposit_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_deposit_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -65,8 +65,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::INITIALIZE2,
|
||||
event_type: EventType::RaydiumAmmV4Initialize2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_initialize2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_initialize2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -74,8 +74,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::WITHDRAW,
|
||||
event_type: EventType::RaydiumAmmV4Withdraw,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_withdraw_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_withdraw_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
@@ -83,8 +83,8 @@ impl RaydiumAmmV4EventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::WITHDRAW_PNL,
|
||||
event_type: EventType::RaydiumAmmV4WithdrawPnl,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_withdraw_pnl_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_withdraw_pnl_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -93,10 +93,6 @@ impl RaydiumAmmV4EventParser {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
fn empty_parse(_data: &[u8], _metadata: EventMetadata) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// 解析提现指令事件
|
||||
fn parse_withdraw_pnl_instruction(
|
||||
_data: &[u8],
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata, protocols::raydium_amm_v4::RaydiumAmmV4AmmInfoAccountEvent,
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct Fees {
|
||||
pub min_separate_numerator: u64,
|
||||
pub min_separate_denominator: u64,
|
||||
pub trade_fee_numerator: u64,
|
||||
pub trade_fee_denominator: u64,
|
||||
pub pnl_numerator: u64,
|
||||
pub pnl_denominator: u64,
|
||||
pub swap_fee_numerator: u64,
|
||||
pub swap_fee_denominator: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct OutPutData {
|
||||
pub need_take_pnl_coin: u64,
|
||||
pub need_take_pnl_pc: u64,
|
||||
pub total_pnl_pc: u64,
|
||||
pub total_pnl_coin: u64,
|
||||
pub pool_open_time: u64,
|
||||
pub punish_pc_amount: u64,
|
||||
pub punish_coin_amount: u64,
|
||||
pub orderbook_to_init_time: u64,
|
||||
pub swap_coin_in_amount: u128,
|
||||
pub swap_pc_out_amount: u128,
|
||||
pub swap_take_pc_fee: u64,
|
||||
pub swap_pc_in_amount: u128,
|
||||
pub swap_coin_out_amount: u128,
|
||||
pub swap_take_coin_fee: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct AmmInfo {
|
||||
pub status: u64,
|
||||
pub nonce: u64,
|
||||
pub order_num: u64,
|
||||
pub depth: u64,
|
||||
pub coin_decimals: u64,
|
||||
pub pc_decimals: u64,
|
||||
pub state: u64,
|
||||
pub reset_flag: u64,
|
||||
pub min_size: u64,
|
||||
pub vol_max_cut_ratio: u64,
|
||||
pub amount_wave: u64,
|
||||
pub coin_lot_size: u64,
|
||||
pub pc_lot_size: u64,
|
||||
pub min_price_multiplier: u64,
|
||||
pub max_price_multiplier: u64,
|
||||
pub sys_decimal_value: u64,
|
||||
pub fees: Fees,
|
||||
pub out_put: OutPutData,
|
||||
pub token_coin: Pubkey,
|
||||
pub token_pc: Pubkey,
|
||||
pub coin_mint: Pubkey,
|
||||
pub pc_mint: Pubkey,
|
||||
pub lp_mint: Pubkey,
|
||||
pub open_orders: Pubkey,
|
||||
pub market: Pubkey,
|
||||
pub serum_dex: Pubkey,
|
||||
pub target_orders: Pubkey,
|
||||
pub withdraw_queue: Pubkey,
|
||||
pub token_temp_lp: Pubkey,
|
||||
pub amm_owner: Pubkey,
|
||||
pub lp_amount: u64,
|
||||
pub client_order_id: u64,
|
||||
pub padding: [u64; 2],
|
||||
}
|
||||
|
||||
pub const AMM_INFO_SIZE: usize = 752;
|
||||
|
||||
pub fn amm_info_decode(data: &[u8]) -> Option<AmmInfo> {
|
||||
borsh::from_slice::<AmmInfo>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn amm_info_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < AMM_INFO_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(amm_info) = amm_info_decode(&account.data[..AMM_INFO_SIZE]) {
|
||||
Some(Box::new(RaydiumAmmV4AmmInfoAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_info: amm_info,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
// use borsh::BorshDeserialize;
|
||||
use crate::streaming::event_parser::protocols::raydium_clmm::types::{PoolState, TickArrayState};
|
||||
use crate::{
|
||||
impl_unified_event, streaming::event_parser::protocols::raydium_clmm::types::AmmConfig,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
@@ -217,6 +219,45 @@ pub struct RaydiumClmmOpenPositionV2Event {
|
||||
}
|
||||
impl_unified_event!(RaydiumClmmOpenPositionV2Event,);
|
||||
|
||||
/// 池配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmAmmConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_config: AmmConfig,
|
||||
}
|
||||
impl_unified_event!(RaydiumClmmAmmConfigAccountEvent,);
|
||||
|
||||
/// 池状态
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmPoolStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
impl_unified_event!(RaydiumClmmPoolStateAccountEvent,);
|
||||
|
||||
/// 池状态
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RaydiumClmmTickArrayStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub tick_array_state: TickArrayState,
|
||||
}
|
||||
impl_unified_event!(RaydiumClmmTickArrayStateAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 指令鉴别器
|
||||
@@ -228,4 +269,9 @@ pub mod discriminators {
|
||||
pub const CREATE_POOL: &[u8] = &[233, 146, 209, 142, 207, 104, 64, 188];
|
||||
pub const OPEN_POSITION_WITH_TOKEN_22_NFT: &[u8] = &[77, 255, 174, 82, 125, 29, 201, 46];
|
||||
pub const OPEN_POSITION_V2: &[u8] = &[77, 184, 74, 214, 112, 86, 241, 199];
|
||||
|
||||
// 账号鉴别器
|
||||
pub const AMM_CONFIG: &[u8] = &[218, 244, 33, 104, 203, 203, 43, 111];
|
||||
pub const POOL_STATE: &[u8] = &[247, 237, 227, 245, 215, 195, 222, 70];
|
||||
pub const TICK_ARRAY_STATE: &[u8] = &[192, 155, 85, 205, 49, 249, 129, 42];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::RaydiumClmmEventParser;
|
||||
|
||||
@@ -43,8 +43,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP,
|
||||
event_type: EventType::RaydiumClmmSwap,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -52,8 +52,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_V2,
|
||||
event_type: EventType::RaydiumClmmSwapV2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_v2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_v2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -61,8 +61,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::CLOSE_POSITION,
|
||||
event_type: EventType::RaydiumClmmClosePosition,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_close_position_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_close_position_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -70,8 +70,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::DECREASE_LIQUIDITY_V2,
|
||||
event_type: EventType::RaydiumClmmDecreaseLiquidityV2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_decrease_liquidity_v2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_decrease_liquidity_v2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -79,8 +79,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::CREATE_POOL,
|
||||
event_type: EventType::RaydiumClmmCreatePool,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_create_pool_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_create_pool_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -88,8 +88,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::INCREASE_LIQUIDITY_V2,
|
||||
event_type: EventType::RaydiumClmmIncreaseLiquidityV2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_increase_liquidity_v2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_increase_liquidity_v2_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -97,8 +97,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::OPEN_POSITION_WITH_TOKEN_22_NFT,
|
||||
event_type: EventType::RaydiumClmmOpenPositionWithToken22Nft,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_open_position_with_token_22_nft_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_open_position_with_token_22_nft_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CLMM_PROGRAM_ID,
|
||||
@@ -106,8 +106,8 @@ impl RaydiumClmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::OPEN_POSITION_V2,
|
||||
event_type: EventType::RaydiumClmmOpenPositionV2,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_open_position_v2_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_open_position_v2_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -116,10 +116,6 @@ impl RaydiumClmmEventParser {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
fn empty_parse(_data: &[u8], _metadata: EventMetadata) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// 解析打开仓位V2指令事件
|
||||
fn parse_open_position_v2_instruction(
|
||||
data: &[u8],
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::raydium_clmm::{
|
||||
RaydiumClmmAmmConfigAccountEvent, RaydiumClmmPoolStateAccountEvent,
|
||||
RaydiumClmmTickArrayStateAccountEvent,
|
||||
},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct AmmConfig {
|
||||
pub bump: u8,
|
||||
pub index: u16,
|
||||
pub owner: Pubkey,
|
||||
pub protocol_fee_rate: u32,
|
||||
pub trade_fee_rate: u32,
|
||||
pub tick_spacing: u16,
|
||||
pub fund_fee_rate: u32,
|
||||
pub padding_u32: u32,
|
||||
pub fund_owner: Pubkey,
|
||||
pub padding: [u64; 3],
|
||||
}
|
||||
|
||||
pub const AMM_CONFIG_SIZE: usize = 1 + 2 + 32 + 4 * 2 + 2 + 4 * 2 + 32 + 8 * 3;
|
||||
|
||||
pub fn amm_config_decode(data: &[u8]) -> Option<AmmConfig> {
|
||||
borsh::from_slice::<AmmConfig>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn amm_config_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < AMM_CONFIG_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumClmmAmmConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_config: amm_config,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RewardInfo {
|
||||
pub reward_state: u8,
|
||||
pub open_time: u64,
|
||||
pub end_time: u64,
|
||||
pub last_update_time: u64,
|
||||
pub emissions_per_second_x64: u128,
|
||||
pub reward_total_emissioned: u64,
|
||||
pub reward_claimed: u64,
|
||||
pub token_mint: Pubkey,
|
||||
pub token_vault: Pubkey,
|
||||
pub authority: Pubkey,
|
||||
pub reward_growth_global_x64: u128,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PoolState {
|
||||
pub bump: [u8; 1],
|
||||
pub amm_config: Pubkey,
|
||||
pub owner: Pubkey,
|
||||
pub token_mint0: Pubkey,
|
||||
pub token_mint1: Pubkey,
|
||||
pub token_vault0: Pubkey,
|
||||
pub token_vault1: Pubkey,
|
||||
pub observation_key: Pubkey,
|
||||
pub mint_decimals0: u8,
|
||||
pub mint_decimals1: u8,
|
||||
pub tick_spacing: u16,
|
||||
pub liquidity: u128,
|
||||
pub sqrt_price_x64: u128,
|
||||
pub tick_current: i32,
|
||||
pub padding3: u16,
|
||||
pub padding4: u16,
|
||||
pub fee_growth_global0_x64: u128,
|
||||
pub fee_growth_global1_x64: u128,
|
||||
pub protocol_fees_token0: u64,
|
||||
pub protocol_fees_token1: u64,
|
||||
pub swap_in_amount_token0: u128,
|
||||
pub swap_out_amount_token1: u128,
|
||||
pub swap_in_amount_token1: u128,
|
||||
pub swap_out_amount_token0: u128,
|
||||
pub status: u8,
|
||||
pub padding: [u8; 7],
|
||||
pub reward_infos: [RewardInfo; 3],
|
||||
pub tick_array_bitmap: [u64; 16],
|
||||
pub total_fees_token0: u64,
|
||||
pub total_fees_claimed_token0: u64,
|
||||
pub total_fees_token1: u64,
|
||||
pub total_fees_claimed_token1: u64,
|
||||
pub fund_fees_token0: u64,
|
||||
pub fund_fees_token1: u64,
|
||||
pub open_time: u64,
|
||||
pub recent_epoch: u64,
|
||||
pub padding1: [u64; 24],
|
||||
pub padding2: [u64; 32],
|
||||
}
|
||||
|
||||
pub const POOL_STATE_SIZE: usize = 1536;
|
||||
|
||||
pub fn pool_state_decode(data: &[u8]) -> Option<PoolState> {
|
||||
borsh::from_slice::<PoolState>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn pool_state_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < POOL_STATE_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumClmmPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state: pool_state,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct TickState {
|
||||
pub tick: i32,
|
||||
pub liquidity_net: i128,
|
||||
pub liquidity_gross: u128,
|
||||
pub fee_growth_outside0_x64: u128,
|
||||
pub fee_growth_outside1_x64: u128,
|
||||
pub reward_growths_outside_x64: [u128; 3],
|
||||
pub padding: [u32; 13],
|
||||
}
|
||||
|
||||
impl Default for TickState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tick: 0,
|
||||
liquidity_net: 0,
|
||||
liquidity_gross: 0,
|
||||
fee_growth_outside0_x64: 0,
|
||||
fee_growth_outside1_x64: 0,
|
||||
reward_growths_outside_x64: [0; 3],
|
||||
padding: [0; 13],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct TickArrayState {
|
||||
pub pool_id: Pubkey,
|
||||
pub start_tick_index: i32,
|
||||
#[serde(with = "serde_big_array::BigArray")]
|
||||
pub ticks: [TickState; 60],
|
||||
pub initialized_tick_count: u8,
|
||||
pub recent_epoch: u64,
|
||||
#[serde(with = "serde_big_array::BigArray")]
|
||||
pub padding: [u8; 107],
|
||||
}
|
||||
|
||||
impl Default for TickArrayState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pool_id: Pubkey::default(),
|
||||
start_tick_index: 0,
|
||||
ticks: core::array::from_fn(|_| TickState::default()),
|
||||
initialized_tick_count: 0,
|
||||
recent_epoch: 0,
|
||||
padding: [0u8; 107],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const TICK_ARRAY_STATE_SIZE: usize = 10232;
|
||||
|
||||
pub fn tick_array_state_decode(data: &[u8]) -> Option<TickArrayState> {
|
||||
borsh::from_slice::<TickArrayState>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn tick_array_state_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < TICK_ARRAY_STATE_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(tick_array_state) =
|
||||
tick_array_state_decode(&account.data[8..TICK_ARRAY_STATE_SIZE + 8])
|
||||
{
|
||||
Some(Box::new(RaydiumClmmTickArrayStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
tick_array_state: tick_array_state,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
use crate::impl_unified_event;
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::streaming::event_parser::protocols::raydium_cpmm::types::PoolState;
|
||||
use crate::{
|
||||
impl_unified_event, streaming::event_parser::protocols::raydium_cpmm::types::AmmConfig,
|
||||
};
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -107,6 +110,32 @@ pub struct RaydiumCpmmWithdrawEvent {
|
||||
}
|
||||
impl_unified_event!(RaydiumCpmmWithdrawEvent,);
|
||||
|
||||
/// 池配置
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmAmmConfigAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub amm_config: AmmConfig,
|
||||
}
|
||||
impl_unified_event!(RaydiumCpmmAmmConfigAccountEvent,);
|
||||
|
||||
/// 池状态
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RaydiumCpmmPoolStateAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: String,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: String,
|
||||
pub rent_epoch: u64,
|
||||
pub pool_state: PoolState,
|
||||
}
|
||||
impl_unified_event!(RaydiumCpmmPoolStateAccountEvent,);
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 指令鉴别器
|
||||
@@ -115,4 +144,8 @@ pub mod discriminators {
|
||||
pub const DEPOSIT: &[u8] = &[242, 35, 198, 137, 82, 225, 242, 182];
|
||||
pub const INITIALIZE: &[u8] = &[175, 175, 109, 31, 13, 152, 155, 237];
|
||||
pub const WITHDRAW: &[u8] = &[183, 18, 70, 156, 148, 109, 161, 34];
|
||||
|
||||
// 账号鉴别器
|
||||
pub const AMM_CONFIG: &[u8] = &[218, 244, 33, 104, 203, 203, 43, 111];
|
||||
pub const POOL_STATE: &[u8] = &[247, 237, 227, 245, 215, 195, 222, 70];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
pub use parser::RaydiumCpmmEventParser;
|
||||
|
||||
@@ -38,8 +38,8 @@ impl RaydiumCpmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_IN,
|
||||
event_type: EventType::RaydiumCpmmSwapBaseInput,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_input_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_input_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CPMM_PROGRAM_ID,
|
||||
@@ -47,8 +47,8 @@ impl RaydiumCpmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::SWAP_BASE_OUT,
|
||||
event_type: EventType::RaydiumCpmmSwapBaseOutput,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_swap_base_output_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_swap_base_output_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CPMM_PROGRAM_ID,
|
||||
@@ -56,8 +56,8 @@ impl RaydiumCpmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::DEPOSIT,
|
||||
event_type: EventType::RaydiumCpmmDeposit,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_deposit_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_deposit_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CPMM_PROGRAM_ID,
|
||||
@@ -65,8 +65,8 @@ impl RaydiumCpmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::INITIALIZE,
|
||||
event_type: EventType::RaydiumCpmmInitialize,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_initialize_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_initialize_instruction),
|
||||
},
|
||||
GenericEventParseConfig {
|
||||
program_id: RAYDIUM_CPMM_PROGRAM_ID,
|
||||
@@ -74,8 +74,8 @@ impl RaydiumCpmmEventParser {
|
||||
inner_instruction_discriminator: "",
|
||||
instruction_discriminator: discriminators::WITHDRAW,
|
||||
event_type: EventType::RaydiumCpmmWithdraw,
|
||||
inner_instruction_parser: Self::empty_parse,
|
||||
instruction_parser: Self::parse_withdraw_instruction,
|
||||
inner_instruction_parser: None,
|
||||
instruction_parser: Some(Self::parse_withdraw_instruction),
|
||||
},
|
||||
];
|
||||
|
||||
@@ -84,10 +84,6 @@ impl RaydiumCpmmEventParser {
|
||||
Self { inner }
|
||||
}
|
||||
|
||||
fn empty_parse(_data: &[u8], _metadata: EventMetadata) -> Option<Box<dyn UnifiedEvent>> {
|
||||
None
|
||||
}
|
||||
|
||||
/// 解析提款指令事件
|
||||
fn parse_withdraw_instruction(
|
||||
data: &[u8],
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::EventMetadata,
|
||||
protocols::raydium_cpmm::{
|
||||
RaydiumCpmmAmmConfigAccountEvent, RaydiumCpmmPoolStateAccountEvent,
|
||||
},
|
||||
UnifiedEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct AmmConfig {
|
||||
pub bump: u8,
|
||||
pub disable_create_pool: bool,
|
||||
pub index: u16,
|
||||
pub trade_fee_rate: u64,
|
||||
pub protocol_fee_rate: u64,
|
||||
pub fund_fee_rate: u64,
|
||||
pub create_pool_fee: u64,
|
||||
pub protocol_owner: Pubkey,
|
||||
pub fund_owner: Pubkey,
|
||||
pub padding: [u64; 16],
|
||||
}
|
||||
|
||||
pub const AMM_CONFIG_SIZE: usize = 228;
|
||||
|
||||
pub fn amm_config_decode(data: &[u8]) -> Option<AmmConfig> {
|
||||
borsh::from_slice::<AmmConfig>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn amm_config_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < AMM_CONFIG_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumCpmmAmmConfigAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
amm_config: amm_config,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct PoolState {
|
||||
pub amm_config: Pubkey,
|
||||
pub pool_creator: Pubkey,
|
||||
pub token0_vault: Pubkey,
|
||||
pub token1_vault: Pubkey,
|
||||
pub lp_mint: Pubkey,
|
||||
pub token0_mint: Pubkey,
|
||||
pub token1_mint: Pubkey,
|
||||
pub token0_program: Pubkey,
|
||||
pub token1_program: Pubkey,
|
||||
pub observation_key: Pubkey,
|
||||
pub auth_bump: u8,
|
||||
pub status: u8,
|
||||
pub lp_mint_decimals: u8,
|
||||
pub mint0_decimals: u8,
|
||||
pub mint1_decimals: u8,
|
||||
pub lp_supply: u64,
|
||||
pub protocol_fees_token0: u64,
|
||||
pub protocol_fees_token1: u64,
|
||||
pub fund_fees_token0: u64,
|
||||
pub fund_fees_token1: u64,
|
||||
pub open_time: u64,
|
||||
pub recent_epoch: u64,
|
||||
pub padding: [u64; 31],
|
||||
}
|
||||
|
||||
pub const POOL_STATE_SIZE: usize = 629;
|
||||
|
||||
pub fn pool_state_decode(data: &[u8]) -> Option<PoolState> {
|
||||
borsh::from_slice::<PoolState>(&data).ok()
|
||||
}
|
||||
|
||||
pub fn pool_state_parser(
|
||||
account: &AccountPretty,
|
||||
metadata: EventMetadata,
|
||||
) -> Option<Box<dyn UnifiedEvent>> {
|
||||
if account.data.len() < POOL_STATE_SIZE {
|
||||
return None;
|
||||
}
|
||||
if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {
|
||||
Some(Box::new(RaydiumCpmmPoolStateAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey.to_string(),
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner.to_string(),
|
||||
rent_epoch: account.rent_epoch,
|
||||
pool_state: pool_state,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user