feat(bonk): Update BONK protocol support and fee handling
- Add system program and associated account support - Update instruction builder with platform/creator accounts - Implement associated account helper functions - Upgrade SDK to 0.4.6 and dependencies - Repla
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "sol-trade-sdk"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
edition = "2021"
|
||||
authors = ["William <byteblock6@gmail.com>", "sgxiang <sgxiang@gmail.com>", "wei <1415121722@qq.com>"]
|
||||
repository = "https://github.com/0xfnzero/sol-trade-sdk"
|
||||
@@ -13,7 +13,7 @@ readme = "README.md"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
solana-streamer-sdk = "0.3.6"
|
||||
solana-streamer-sdk = "0.3.9"
|
||||
solana-sdk = "2.3.0"
|
||||
solana-client = "2.3.6"
|
||||
solana-program = "2.3.0"
|
||||
|
||||
@@ -33,14 +33,14 @@ Add the dependency to your `Cargo.toml`:
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.4.5" }
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.4.6" }
|
||||
```
|
||||
|
||||
### Use crates.io
|
||||
|
||||
```toml
|
||||
# Add to your Cargo.toml
|
||||
sol-trade-sdk = "0.4.5"
|
||||
sol-trade-sdk = "0.4.6"
|
||||
```
|
||||
|
||||
## Usage Examples
|
||||
|
||||
+2
-2
@@ -33,14 +33,14 @@ git clone https://github.com/0xfnzero/sol-trade-sdk
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.4.5" }
|
||||
sol-trade-sdk = { path = "./sol-trade-sdk", version = "0.4.6" }
|
||||
```
|
||||
|
||||
### 使用 crates.io
|
||||
|
||||
```toml
|
||||
# 添加到您的 Cargo.toml
|
||||
sol-trade-sdk = "0.4.5"
|
||||
sol-trade-sdk = "0.4.6"
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
@@ -22,11 +22,11 @@ pub mod accounts {
|
||||
|
||||
pub const AUTHORITY: Pubkey = pubkey!("WLHv2UAZm6z4KyaaELi5pjdbJh6RESMva1Rnn8pJVVh");
|
||||
pub const GLOBAL_CONFIG: Pubkey = pubkey!("6s1xP3hpbAfFoNtUNF8mfHsjr2Bd97JxFJRWLbL6aHuX");
|
||||
pub const PLATFORM_CONFIG: Pubkey = pubkey!("FfYek5vEz23cMkWsdJwG2oa6EphsvXSHrGpdALN4g6W1");
|
||||
pub const TOKEN_PROGRAM: Pubkey = spl_token::ID;
|
||||
pub const EVENT_AUTHORITY: Pubkey = pubkey!("2DPAtwB8L12vrMRExbLuyGnC7n2J5LNoZQSejeQGpwkr");
|
||||
pub const WSOL_TOKEN_ACCOUNT: Pubkey = pubkey!("So11111111111111111111111111111111111111112");
|
||||
pub const BONK: Pubkey = pubkey!("LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj");
|
||||
pub const SYSTEM_PROGRAM: Pubkey = solana_sdk::system_program::ID;
|
||||
|
||||
pub const PLATFORM_FEE_RATE: u128 = 100; // 1%
|
||||
pub const PROTOCOL_FEE_RATE: u128 = 25; // 0.25%
|
||||
|
||||
@@ -125,7 +125,7 @@ impl BonkInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new(params.payer.pubkey(), true), // Payer (signer)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::AUTHORITY, false), // Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::GLOBAL_CONFIG, false), // Global Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::PLATFORM_CONFIG, false), // Platform Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(protocol_params.platform_onfig, false), // Platform Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new(pool_state, false), // Pool State
|
||||
solana_sdk::instruction::AccountMeta::new(user_base_token_account, false), // User Base Token
|
||||
solana_sdk::instruction::AccountMeta::new(user_quote_token_account, false), // User Quote Token
|
||||
@@ -140,6 +140,9 @@ impl BonkInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Quote Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::EVENT_AUTHORITY, false), // Event Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::BONK, false), // Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::SYSTEM_PROGRAM, false), // System Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new(protocol_params.platform_associated_account, false), // Platform Associated Account
|
||||
solana_sdk::instruction::AccountMeta::new(protocol_params.creator_associated_account, false), // Creator Associated Account
|
||||
];
|
||||
// Create instruction data
|
||||
let mut data = vec![];
|
||||
@@ -249,7 +252,7 @@ impl BonkInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new(params.payer.pubkey(), true), // Payer (signer)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::AUTHORITY, false), // Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::GLOBAL_CONFIG, false), // Global Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::PLATFORM_CONFIG, false), // Platform Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(protocol_params.platform_onfig, false), // Platform Config (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new(pool_state, false), // Pool State
|
||||
solana_sdk::instruction::AccountMeta::new(user_base_token_account, false), // User Base Token
|
||||
solana_sdk::instruction::AccountMeta::new(user_quote_token_account, false), // User Quote Token
|
||||
@@ -264,6 +267,9 @@ impl BonkInstructionBuilder {
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::TOKEN_PROGRAM, false), // Quote Token Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::EVENT_AUTHORITY, false), // Event Authority (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::BONK, false), // Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new_readonly(accounts::SYSTEM_PROGRAM, false), // System Program (readonly)
|
||||
solana_sdk::instruction::AccountMeta::new(protocol_params.platform_associated_account, false), // Platform Associated Account
|
||||
solana_sdk::instruction::AccountMeta::new(protocol_params.creator_associated_account, false), // Creator Associated Account
|
||||
];
|
||||
|
||||
// Create instruction data
|
||||
|
||||
@@ -120,6 +120,20 @@ pub fn get_vault_pda(pool_state: &Pubkey, mint: &Pubkey) -> Option<Pubkey> {
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
|
||||
pub fn get_platform_associated_account(platform_config: &Pubkey) -> Option<Pubkey> {
|
||||
let seeds: &[&[u8]; 2] = &[platform_config.as_ref(), accounts::WSOL_TOKEN_ACCOUNT.as_ref()];
|
||||
let program_id: &Pubkey = &constants::bonk::accounts::BONK;
|
||||
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
|
||||
pub fn get_creator_associated_account(creator: &Pubkey) -> Option<Pubkey> {
|
||||
let seeds: &[&[u8]; 2] = &[creator.as_ref(), accounts::WSOL_TOKEN_ACCOUNT.as_ref()];
|
||||
let program_id: &Pubkey = &constants::bonk::accounts::BONK;
|
||||
let pda: Option<(Pubkey, u8)> = Pubkey::try_find_program_address(seeds, program_id);
|
||||
pda.map(|pubkey| pubkey.0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::constants::bonk::accounts::{PLATFORM_FEE_RATE, PROTOCOL_FEE_RATE, SHARE_FEE_RATE};
|
||||
|
||||
@@ -17,7 +17,10 @@ use crate::constants::bonk::accounts::{
|
||||
use crate::solana_streamer_sdk::streaming::event_parser::common::EventType;
|
||||
use crate::solana_streamer_sdk::streaming::event_parser::protocols::bonk::BonkTradeEvent;
|
||||
use crate::swqos::SwqosClient;
|
||||
use crate::trading::bonk::common::{get_amount_in, get_amount_in_net, get_amount_out};
|
||||
use crate::trading::bonk::common::{
|
||||
get_amount_in, get_amount_in_net, get_amount_out, get_creator_associated_account,
|
||||
get_platform_associated_account,
|
||||
};
|
||||
use crate::trading::common::get_multi_token_balances;
|
||||
use crate::trading::pumpswap::common::get_token_balances;
|
||||
use crate::trading::raydium_cpmm::common::get_pool_token_balances;
|
||||
@@ -237,6 +240,9 @@ pub struct BonkParams {
|
||||
/// Token program ID
|
||||
/// Specifies the program used by the token, usually spl_token::ID or spl_token_2022::ID
|
||||
pub mint_token_program: Pubkey,
|
||||
pub platform_onfig: Pubkey,
|
||||
pub platform_associated_account: Pubkey,
|
||||
pub creator_associated_account: Pubkey,
|
||||
pub auto_handle_wsol: bool,
|
||||
}
|
||||
|
||||
@@ -251,6 +257,9 @@ impl BonkParams {
|
||||
real_base: trade_info.real_base_after as u128,
|
||||
real_quote: trade_info.real_quote_after as u128,
|
||||
mint_token_program: trade_info.base_token_program,
|
||||
platform_onfig: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
}
|
||||
}
|
||||
@@ -298,6 +307,9 @@ impl BonkParams {
|
||||
real_base: real_base,
|
||||
real_quote: real_quote,
|
||||
mint_token_program: trade_info.base_token_program,
|
||||
platform_onfig: trade_info.platform_config,
|
||||
platform_associated_account: trade_info.platform_associated_account,
|
||||
creator_associated_account: trade_info.creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
}
|
||||
}
|
||||
@@ -311,12 +323,20 @@ impl BonkParams {
|
||||
.unwrap();
|
||||
let pool_data = crate::trading::bonk::common::fetch_pool_state(rpc, &pool_address).await?;
|
||||
let token_account = rpc.get_account(&pool_data.base_mint).await?;
|
||||
let platform_associated_account =
|
||||
get_platform_associated_account(&pool_data.platform_config);
|
||||
let creator_associated_account = get_creator_associated_account(&pool_data.creator);
|
||||
let platform_associated_account = platform_associated_account.unwrap();
|
||||
let creator_associated_account = creator_associated_account.unwrap();
|
||||
Ok(Self {
|
||||
virtual_base: pool_data.virtual_base as u128,
|
||||
virtual_quote: pool_data.virtual_quote as u128,
|
||||
real_base: pool_data.real_base as u128,
|
||||
real_quote: pool_data.real_quote as u128,
|
||||
mint_token_program: token_account.owner,
|
||||
platform_onfig: pool_data.platform_config,
|
||||
platform_associated_account,
|
||||
creator_associated_account,
|
||||
auto_handle_wsol: true,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user