diff --git a/Cargo.toml b/Cargo.toml index 5245402..bfc3991 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solana-streamer-sdk" -version = "0.3.7" +version = "0.3.8" edition = "2021" authors = ["William ", "sgxiang ", "wei <1415121722@qq.com>"] repository = "https://github.com/0xfnzero/solana-streamer" diff --git a/README.md b/README.md index 56c7c9e..cde54a7 100755 --- a/README.md +++ b/README.md @@ -45,14 +45,14 @@ Add the dependency to your `Cargo.toml`: ```toml # Add to your Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "0.3.7" } +solana-streamer-sdk = { path = "./solana-streamer", version = "0.3.8" } ``` ### Use crates.io ```toml # Add to your Cargo.toml -solana-streamer-sdk = "0.3.7" +solana-streamer-sdk = "0.3.8" ``` ## Usage Examples diff --git a/README_CN.md b/README_CN.md index b1ef89f..7a43120 100644 --- a/README_CN.md +++ b/README_CN.md @@ -45,14 +45,14 @@ git clone https://github.com/0xfnzero/solana-streamer ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = { path = "./solana-streamer", version = "0.3.7" } +solana-streamer-sdk = { path = "./solana-streamer", version = "0.3.8" } ``` ### 使用 crates.io ```toml # 添加到您的 Cargo.toml -solana-streamer-sdk = "0.3.7" +solana-streamer-sdk = "0.3.8" ``` ## 使用示例 diff --git a/src/streaming/event_parser/protocols/bonk/types.rs b/src/streaming/event_parser/protocols/bonk/types.rs index e3b453d..476f3ae 100755 --- a/src/streaming/event_parser/protocols/bonk/types.rs +++ b/src/streaming/event_parser/protocols/bonk/types.rs @@ -136,6 +136,9 @@ pub fn pool_state_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < POOL_STATE_SIZE + 8 { + return None; + } if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) { Some(Box::new(BonkPoolStateAccountEvent { metadata, @@ -184,6 +187,9 @@ pub fn global_config_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < GLOBAL_CONFIG_SIZE + 8 { + return None; + } if let Some(global_config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) { Some(Box::new(BonkGlobalConfigAccountEvent { metadata, @@ -227,6 +233,9 @@ pub fn platform_config_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < PLATFORM_CONFIG_SIZE + 8 { + return None; + } if let Some(platform_config) = platform_config_decode(&account.data[8..PLATFORM_CONFIG_SIZE + 8]) { diff --git a/src/streaming/event_parser/protocols/pumpfun/types.rs b/src/streaming/event_parser/protocols/pumpfun/types.rs index 7dc3f69..c2ffdf1 100644 --- a/src/streaming/event_parser/protocols/pumpfun/types.rs +++ b/src/streaming/event_parser/protocols/pumpfun/types.rs @@ -35,6 +35,9 @@ pub fn bonding_curve_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < BONDING_CURVE_SIZE + 8 { + return None; + } if let Some(bonding_curve) = bonding_curve_decode(&account.data[8..BONDING_CURVE_SIZE + 8]) { Some(Box::new(PumpFunBondingCurveAccountEvent { metadata, @@ -82,6 +85,9 @@ pub fn global_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < GLOBAL_SIZE + 8 { + return None; + } if let Some(global) = global_decode(&account.data[8..GLOBAL_SIZE + 8]) { Some(Box::new(PumpFunGlobalAccountEvent { metadata, diff --git a/src/streaming/event_parser/protocols/pumpswap/types.rs b/src/streaming/event_parser/protocols/pumpswap/types.rs index 83b26da..b58c0dc 100644 --- a/src/streaming/event_parser/protocols/pumpswap/types.rs +++ b/src/streaming/event_parser/protocols/pumpswap/types.rs @@ -37,6 +37,9 @@ pub fn global_config_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < GLOBAL_CONFIG_SIZE + 8 { + return None; + } if let Some(config) = global_config_decode(&account.data[8..GLOBAL_CONFIG_SIZE + 8]) { Some(Box::new(PumpSwapGlobalConfigAccountEvent { metadata, @@ -79,6 +82,9 @@ pub fn pool_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { + if account.data.len() < POOL_SIZE + 8 { + return None; + } if let Some(pool) = pool_decode(&account.data[8..POOL_SIZE + 8]) { Some(Box::new(PumpSwapPoolAccountEvent { metadata, diff --git a/src/streaming/event_parser/protocols/raydium_amm_v4/types.rs b/src/streaming/event_parser/protocols/raydium_amm_v4/types.rs index 7f87faa..63fac73 100644 --- a/src/streaming/event_parser/protocols/raydium_amm_v4/types.rs +++ b/src/streaming/event_parser/protocols/raydium_amm_v4/types.rs @@ -80,6 +80,9 @@ pub struct AmmInfo { pub const AMM_INFO_SIZE: usize = 752; pub fn amm_info_decode(data: &[u8]) -> Option { + if data.len() < AMM_INFO_SIZE { + return None; + } borsh::from_slice::(&data[..AMM_INFO_SIZE]).ok() } @@ -134,5 +137,8 @@ pub struct MarketState { pub const MARKET_STATE_SIZE: usize = 388; pub fn market_state_decode(data: &[u8]) -> Option { + if data.len() < MARKET_STATE_SIZE { + return None; + } borsh::from_slice::(&data[..MARKET_STATE_SIZE]).ok() } diff --git a/src/streaming/event_parser/protocols/raydium_clmm/types.rs b/src/streaming/event_parser/protocols/raydium_clmm/types.rs index 7d663d4..06cc524 100644 --- a/src/streaming/event_parser/protocols/raydium_clmm/types.rs +++ b/src/streaming/event_parser/protocols/raydium_clmm/types.rs @@ -31,6 +31,9 @@ pub struct AmmConfig { 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 { + if data.len() < AMM_CONFIG_SIZE { + return None; + } borsh::from_slice::(&data[..AMM_CONFIG_SIZE]).ok() } @@ -38,7 +41,7 @@ pub fn amm_config_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { - if account.data.len() < AMM_CONFIG_SIZE { + if account.data.len() < AMM_CONFIG_SIZE + 8 { return None; } if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) { @@ -116,6 +119,9 @@ pub struct PoolState { pub const POOL_STATE_SIZE: usize = 1536; pub fn pool_state_decode(data: &[u8]) -> Option { + if data.len() < POOL_STATE_SIZE { + return None; + } borsh::from_slice::(&data[..POOL_STATE_SIZE]).ok() } @@ -123,7 +129,7 @@ pub fn pool_state_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { - if account.data.len() < POOL_STATE_SIZE { + if account.data.len() < POOL_STATE_SIZE + 8 { return None; } if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) { @@ -194,6 +200,9 @@ impl Default for TickArrayState { pub const TICK_ARRAY_STATE_SIZE: usize = 10232; pub fn tick_array_state_decode(data: &[u8]) -> Option { + if data.len() < TICK_ARRAY_STATE_SIZE { + return None; + } borsh::from_slice::(&data[..TICK_ARRAY_STATE_SIZE]).ok() } @@ -201,7 +210,7 @@ pub fn tick_array_state_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { - if account.data.len() < TICK_ARRAY_STATE_SIZE { + if account.data.len() < TICK_ARRAY_STATE_SIZE + 8 { return None; } if let Some(tick_array_state) = diff --git a/src/streaming/event_parser/protocols/raydium_cpmm/types.rs b/src/streaming/event_parser/protocols/raydium_cpmm/types.rs index c4981e6..29555c7 100644 --- a/src/streaming/event_parser/protocols/raydium_cpmm/types.rs +++ b/src/streaming/event_parser/protocols/raydium_cpmm/types.rs @@ -30,6 +30,9 @@ pub struct AmmConfig { pub const AMM_CONFIG_SIZE: usize = 228; pub fn amm_config_decode(data: &[u8]) -> Option { + if data.len() < AMM_CONFIG_SIZE { + return None; + } borsh::from_slice::(&data[..AMM_CONFIG_SIZE]).ok() } @@ -37,7 +40,7 @@ pub fn amm_config_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { - if account.data.len() < AMM_CONFIG_SIZE { + if account.data.len() < AMM_CONFIG_SIZE + 8 { return None; } if let Some(amm_config) = amm_config_decode(&account.data[8..AMM_CONFIG_SIZE + 8]) { @@ -85,6 +88,9 @@ pub struct PoolState { pub const POOL_STATE_SIZE: usize = 629; pub fn pool_state_decode(data: &[u8]) -> Option { + if data.len() < POOL_STATE_SIZE { + return None; + } borsh::from_slice::(&data[..POOL_STATE_SIZE]).ok() } @@ -92,7 +98,7 @@ pub fn pool_state_parser( account: &AccountPretty, metadata: EventMetadata, ) -> Option> { - if account.data.len() < POOL_STATE_SIZE { + if account.data.len() < POOL_STATE_SIZE + 8 { return None; } if let Some(pool_state) = pool_state_decode(&account.data[8..POOL_STATE_SIZE + 8]) {