refactor: restructure trading modules and add price calculation utilities
- Remove redundant pool.rs files from trading protocols - Consolidate protocol logic into common.rs files - Add comprehensive price calculation utilities for all protocols - Add decimals constants module - Restructure utils module for better organization - Update documentation with price utilities information Breaking changes: - Removed bonding_curve.rs from pumpfun module - Consolidated trading logic across protocols - Refactored utils module structure
This commit is contained in:
+11
-10
@@ -5,16 +5,17 @@ use spl_associated_token_account::instruction::create_associated_token_account_i
|
||||
use spl_token::instruction::close_account;
|
||||
|
||||
use crate::{
|
||||
constants::bonk::{accounts, BUY_EXECT_IN_DISCRIMINATOR, SELL_EXECT_IN_DISCRIMINATOR},
|
||||
constants::trade::trade::DEFAULT_SLIPPAGE,
|
||||
trading::bonk::{
|
||||
common::{get_amount_out, get_pool_pda, get_vault_pda},
|
||||
pool::Pool,
|
||||
constants::{
|
||||
bonk::{accounts, BUY_EXECT_IN_DISCRIMINATOR, SELL_EXECT_IN_DISCRIMINATOR},
|
||||
trade::trade::DEFAULT_SLIPPAGE,
|
||||
},
|
||||
trading::common::utils::get_token_balance,
|
||||
trading::core::{
|
||||
params::{BonkParams, BuyParams, SellParams},
|
||||
traits::InstructionBuilder,
|
||||
trading::{
|
||||
bonk::common::{fetch_pool_state, get_amount_out, get_pool_pda, get_vault_pda},
|
||||
common::utils::get_token_balance,
|
||||
core::{
|
||||
params::{BonkParams, BuyParams, SellParams},
|
||||
traits::InstructionBuilder,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -70,7 +71,7 @@ impl BonkInstructionBuilder {
|
||||
let mut real_quote = protocol_params.real_quote.unwrap_or(0);
|
||||
|
||||
if virtual_base == 0 || virtual_quote == 0 || real_base == 0 || real_quote == 0 {
|
||||
let pool = Pool::fetch(params.rpc.as_ref().unwrap(), &pool_state).await?;
|
||||
let pool = fetch_pool_state(params.rpc.as_ref().unwrap(), &pool_state).await?;
|
||||
virtual_base = pool.virtual_base as u128;
|
||||
virtual_quote = pool.virtual_quote as u128;
|
||||
real_base = pool.real_base as u128;
|
||||
|
||||
@@ -20,9 +20,7 @@ use crate::{
|
||||
pumpswap::{
|
||||
self,
|
||||
common::{
|
||||
coin_creator_vault_ata, coin_creator_vault_authority, fee_recipient_ata, find_pool,
|
||||
get_global_volume_accumulator_pda, get_token_amount,
|
||||
get_user_volume_accumulator_pda, get_wsol_amount,
|
||||
coin_creator_vault_ata, coin_creator_vault_authority, fee_recipient_ata, fetch_pool, find_pool, get_global_volume_accumulator_pda, get_token_amount, get_user_volume_accumulator_pda, get_wsol_amount
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -138,7 +136,7 @@ impl PumpSwapInstructionBuilder {
|
||||
let rpc = params.rpc.as_ref().unwrap().clone();
|
||||
// Find pool
|
||||
let pool = find_pool(rpc.as_ref(), ¶ms.mint).await?;
|
||||
let pool_data = pumpswap::pool::Pool::fetch(rpc.as_ref(), &pool).await?;
|
||||
let pool_data = fetch_pool(rpc.as_ref(), &pool).await?;
|
||||
let pool_base_token_reserves =
|
||||
get_token_balance(rpc.as_ref(), &pool, &pool_data.base_mint).await?;
|
||||
let pool_quote_token_reserves =
|
||||
@@ -169,7 +167,7 @@ impl PumpSwapInstructionBuilder {
|
||||
let rpc = params.rpc.as_ref().unwrap().clone();
|
||||
// Find pool
|
||||
let pool = find_pool(rpc.as_ref(), ¶ms.mint).await?;
|
||||
let pool_data = pumpswap::pool::Pool::fetch(rpc.as_ref(), &pool).await?;
|
||||
let pool_data = fetch_pool(rpc.as_ref(), &pool).await?;
|
||||
let pool_base_token_reserves =
|
||||
get_token_balance(rpc.as_ref(), &pool, &pool_data.base_mint).await?;
|
||||
let pool_quote_token_reserves =
|
||||
|
||||
Reference in New Issue
Block a user