mirror of
https://github.com/0xfnzero/solana-streamer.git
synced 2026-08-17 19:08:05 +00:00
add meteora dlmm account event
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
use crate::streaming::event_parser::common::EventMetadata;
|
||||
use crate::streaming::event_parser::protocols::meteora_dlmm::types::LbPair;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
/// LbPair 账户事件
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct MeteoraDlmmLbPairAccountEvent {
|
||||
pub metadata: EventMetadata,
|
||||
pub pubkey: Pubkey,
|
||||
pub executable: bool,
|
||||
pub lamports: u64,
|
||||
pub owner: Pubkey,
|
||||
pub rent_epoch: u64,
|
||||
pub lb_pair: LbPair,
|
||||
}
|
||||
|
||||
/// 事件鉴别器常量
|
||||
pub mod discriminators {
|
||||
// 账户鉴别器
|
||||
pub const LB_PAIR: &[u8] = &[33, 11, 49, 98, 181, 101, 177, 13];
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod events;
|
||||
pub mod parser;
|
||||
pub mod types;
|
||||
|
||||
pub use events::*;
|
||||
@@ -0,0 +1,25 @@
|
||||
use crate::streaming::event_parser::protocols::meteora_dlmm::discriminators;
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
/// Meteora DLMM 程序ID
|
||||
pub const METEORA_DLMM_PROGRAM_ID: Pubkey =
|
||||
solana_sdk::pubkey!("LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo");
|
||||
|
||||
/// 解析 Meteora DLMM 账户数据
|
||||
///
|
||||
/// 根据判别器路由到具体的账户解析函数
|
||||
pub fn parse_meteora_dlmm_account_data(
|
||||
discriminator: &[u8],
|
||||
account: &crate::streaming::grpc::AccountPretty,
|
||||
metadata: crate::streaming::event_parser::common::EventMetadata,
|
||||
) -> Option<crate::streaming::event_parser::DexEvent> {
|
||||
match discriminator {
|
||||
discriminators::LB_PAIR => {
|
||||
crate::streaming::event_parser::protocols::meteora_dlmm::types::lb_pair_parser(
|
||||
account,
|
||||
metadata,
|
||||
)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
use borsh::BorshDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
use crate::streaming::{
|
||||
event_parser::{
|
||||
common::{EventMetadata, EventType},
|
||||
protocols::meteora_dlmm::MeteoraDlmmLbPairAccountEvent,
|
||||
DexEvent,
|
||||
},
|
||||
grpc::AccountPretty,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct StaticParameters {
|
||||
pub base_factor: u16,
|
||||
pub filter_period: u16,
|
||||
pub decay_period: u16,
|
||||
pub reduction_factor: u16,
|
||||
pub variable_fee_control: u32,
|
||||
pub max_volatility_accumulator: u32,
|
||||
pub min_bin_id: i32,
|
||||
pub max_bin_id: i32,
|
||||
pub protocol_share: u16,
|
||||
pub base_fee_power_factor: u8,
|
||||
pub padding: [u8; 5],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct VariableParameters {
|
||||
pub volatility_accumulator: u32,
|
||||
pub volatility_reference: u32,
|
||||
pub index_reference: i32,
|
||||
pub padding: [u8; 4],
|
||||
pub last_update_timestamp: i64,
|
||||
pub padding1: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct ProtocolFee {
|
||||
pub amount_x: u64,
|
||||
pub amount_y: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct RewardInfo {
|
||||
pub mint: Pubkey,
|
||||
pub vault: Pubkey,
|
||||
pub funder: Pubkey,
|
||||
pub reward_duration: u64,
|
||||
pub reward_duration_end: u64,
|
||||
pub reward_rate: u128,
|
||||
pub last_update_time: u64,
|
||||
pub cumulative_seconds_with_empty_liquidity_reward: u64,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, BorshDeserialize)]
|
||||
pub struct LbPair {
|
||||
pub parameters: StaticParameters,
|
||||
pub v_parameters: VariableParameters,
|
||||
pub bump_seed: [u8; 1],
|
||||
pub bin_step_seed: [u8; 2],
|
||||
pub pair_type: u8,
|
||||
pub active_id: i32,
|
||||
pub bin_step: u16,
|
||||
pub status: u8,
|
||||
pub require_base_factor_seed: u8,
|
||||
pub base_factor_seed: [u8; 2],
|
||||
pub activation_type: u8,
|
||||
pub creator_pool_on_off_control: u8,
|
||||
pub token_x_mint: Pubkey,
|
||||
pub token_y_mint: Pubkey,
|
||||
pub reserve_x: Pubkey,
|
||||
pub reserve_y: Pubkey,
|
||||
pub protocol_fee: ProtocolFee,
|
||||
pub padding1: [u8; 32],
|
||||
pub reward_infos: [RewardInfo; 2],
|
||||
pub oracle: Pubkey,
|
||||
pub bin_array_bitmap: [u64; 16],
|
||||
pub last_updated_at: i64,
|
||||
pub padding2: [u8; 32],
|
||||
pub pre_activation_swap_address: Pubkey,
|
||||
pub base_key: Pubkey,
|
||||
pub activation_point: u64,
|
||||
pub pre_activation_duration: u64,
|
||||
pub padding3: [u8; 8],
|
||||
pub padding4: u64,
|
||||
pub creator: Pubkey,
|
||||
pub token_mint_x_program_flag: u8,
|
||||
pub token_mint_y_program_flag: u8,
|
||||
pub reserved: [u8; 22],
|
||||
}
|
||||
|
||||
pub const LB_PAIR_SIZE: usize = std::mem::size_of::<LbPair>();
|
||||
|
||||
pub fn lb_pair_decode(data: &[u8]) -> Option<LbPair> {
|
||||
if data.len() < LB_PAIR_SIZE {
|
||||
return None;
|
||||
}
|
||||
borsh::from_slice::<LbPair>(&data[..LB_PAIR_SIZE]).ok()
|
||||
}
|
||||
|
||||
pub fn lb_pair_parser(account: &AccountPretty, mut metadata: EventMetadata) -> Option<DexEvent> {
|
||||
metadata.event_type = EventType::AccountMeteoraDlmmLbPair;
|
||||
|
||||
if account.data.len() < LB_PAIR_SIZE + 8 {
|
||||
return None;
|
||||
}
|
||||
if let Some(lb_pair) = lb_pair_decode(&account.data[8..LB_PAIR_SIZE + 8]) {
|
||||
Some(DexEvent::MeteoraDlmmLbPairAccountEvent(
|
||||
MeteoraDlmmLbPairAccountEvent {
|
||||
metadata,
|
||||
pubkey: account.pubkey,
|
||||
executable: account.executable,
|
||||
lamports: account.lamports,
|
||||
owner: account.owner,
|
||||
rent_epoch: account.rent_epoch,
|
||||
lb_pair,
|
||||
},
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod block;
|
||||
pub mod bonk;
|
||||
pub mod meteora_damm_v2;
|
||||
pub mod meteora_dlmm;
|
||||
pub mod pumpfun;
|
||||
pub mod pumpswap;
|
||||
pub mod raydium_amm_v4;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::streaming::event_parser::protocols::{
|
||||
bonk::parser::BONK_PROGRAM_ID, meteora_damm_v2::parser::METEORA_DAMM_V2_PROGRAM_ID,
|
||||
pumpfun::parser::PUMPFUN_PROGRAM_ID, pumpswap::parser::PUMPSWAP_PROGRAM_ID,
|
||||
raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID, raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID,
|
||||
raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID,
|
||||
meteora_dlmm::parser::METEORA_DLMM_PROGRAM_ID, pumpfun::parser::PUMPFUN_PROGRAM_ID,
|
||||
pumpswap::parser::PUMPSWAP_PROGRAM_ID, raydium_amm_v4::parser::RAYDIUM_AMM_V4_PROGRAM_ID,
|
||||
raydium_clmm::parser::RAYDIUM_CLMM_PROGRAM_ID, raydium_cpmm::parser::RAYDIUM_CPMM_PROGRAM_ID,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
@@ -17,6 +17,7 @@ pub enum Protocol {
|
||||
RaydiumClmm,
|
||||
RaydiumAmmV4,
|
||||
MeteoraDammV2,
|
||||
MeteoraDlmm,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
@@ -29,6 +30,7 @@ impl Protocol {
|
||||
Protocol::RaydiumClmm => vec![RAYDIUM_CLMM_PROGRAM_ID],
|
||||
Protocol::RaydiumAmmV4 => vec![RAYDIUM_AMM_V4_PROGRAM_ID],
|
||||
Protocol::MeteoraDammV2 => vec![METEORA_DAMM_V2_PROGRAM_ID],
|
||||
Protocol::MeteoraDlmm => vec![METEORA_DLMM_PROGRAM_ID],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +45,7 @@ impl std::fmt::Display for Protocol {
|
||||
Protocol::RaydiumClmm => write!(f, "RaydiumClmm"),
|
||||
Protocol::RaydiumAmmV4 => write!(f, "RaydiumAmmV4"),
|
||||
Protocol::MeteoraDammV2 => write!(f, "MeteoraDammV2"),
|
||||
Protocol::MeteoraDlmm => write!(f, "MeteoraDlmm"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,6 +62,7 @@ impl std::str::FromStr for Protocol {
|
||||
"raydiumclmm" => Ok(Protocol::RaydiumClmm),
|
||||
"raydiumammv4" => Ok(Protocol::RaydiumAmmV4),
|
||||
"meteoradamm_v2" => Ok(Protocol::MeteoraDammV2),
|
||||
"meteoradlmm" => Ok(Protocol::MeteoraDlmm),
|
||||
_ => Err(anyhow!("Unsupported protocol: {}", s)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user