refactor: improve trading params API and fix bonk calculation bug
- Bump version to 0.4.0 with breaking API changes - Standardize dex params to Box<T> instead of Option<Box<T>> - Add convenient factory methods for all trading params - Fix critical bug in bonk sell calculation (virtual_base logic) - Update documentation and examples with new API usage - Improve ergonomics by removing manual params construction
This commit is contained in:
+6
-6
@@ -219,7 +219,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
slippage_basis_points,
|
||||
recent_blockhash,
|
||||
None,
|
||||
// 经过 rpc,增加耗时,可以通过from_buy_trade或者自行初始化PumpSwapParams参数来优化耗时
|
||||
// Through RPC call, adds latency. Can optimize by using from_buy_trade or manually initializing PumpSwapParams
|
||||
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
|
||||
None,
|
||||
)
|
||||
@@ -238,7 +238,7 @@ async fn test_pumpswap() -> AnyResult<()> {
|
||||
recent_blockhash,
|
||||
None,
|
||||
false,
|
||||
// 经过 rpc,增加耗时,可以通过from_sell_trade或者自行初始化PumpSwapParams参数来优化耗时
|
||||
// Through RPC call, adds latency. Can optimize by using from_sell_trade or manually initializing PumpSwapParams
|
||||
Box::new(PumpSwapParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?),
|
||||
None,
|
||||
)
|
||||
@@ -363,7 +363,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
slippage_basis_points,
|
||||
recent_blockhash,
|
||||
None,
|
||||
// 经过 rpc,增加耗时,可以通过from_trade或者自行初始化BonkParams参数来优化耗时
|
||||
// Through RPC call, adds latency. Can optimize by using from_trade or manually initializing BonkParams
|
||||
Box::new(BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?),
|
||||
None,
|
||||
)
|
||||
@@ -382,7 +382,7 @@ async fn test_bonk() -> Result<(), Box<dyn std::error::Error>> {
|
||||
recent_blockhash,
|
||||
None,
|
||||
false,
|
||||
// 经过 rpc,增加耗时,可以通过from_trade或者自行初始化BonkParams参数来优化耗时
|
||||
// Through RPC call, adds latency. Can optimize by using from_trade or manually initializing BonkParams
|
||||
Box::new(BonkParams::from_mint_by_rpc(&client.rpc, &mint_pubkey).await?),
|
||||
None,
|
||||
)
|
||||
@@ -411,7 +411,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
|
||||
slippage_basis_points,
|
||||
recent_blockhash,
|
||||
None,
|
||||
// 经过 rpc,增加耗时,或者自行初始化RaydiumCpmmParams参数
|
||||
// Through RPC call, adds latency, or manually initialize RaydiumCpmmParams
|
||||
Box::new(
|
||||
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?,
|
||||
),
|
||||
@@ -432,7 +432,7 @@ async fn test_raydium_cpmm() -> Result<(), Box<dyn std::error::Error>> {
|
||||
recent_blockhash,
|
||||
None,
|
||||
false,
|
||||
// 经过 rpc,增加耗时,或者自行初始化RaydiumCpmmParams参数
|
||||
// Through RPC call, adds latency, or manually initialize RaydiumCpmmParams
|
||||
Box::new(
|
||||
RaydiumCpmmParams::from_pool_address_by_rpc(&client.rpc, &pool_address).await?,
|
||||
),
|
||||
|
||||
@@ -83,7 +83,7 @@ pub fn get_sell_sol_amount_from_token_amount(
|
||||
let amount_in_u128 = amount_in as u128;
|
||||
|
||||
// For sell operation, input_reserve is token reserves, output_reserve is SOL reserves
|
||||
let input_reserve = virtual_base.checked_add(real_base).unwrap();
|
||||
let input_reserve = virtual_base.checked_sub(real_base).unwrap();
|
||||
let output_reserve = virtual_quote.checked_add(real_quote).unwrap();
|
||||
|
||||
// Use constant product formula to calculate SOL amount received from selling tokens
|
||||
|
||||
Reference in New Issue
Block a user