From 463e082c45249ba0d3b6ae7bbc4a2fbb0518d5f0 Mon Sep 17 00:00:00 2001 From: lowkeynicc <85139158+lowkeynicc@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:54:45 -0500 Subject: [PATCH] v2 params iteration (#555) --- src/index.ts | 2 +- src/utils/utils.ts | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index f3ae323..bb36107 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1050,7 +1050,7 @@ const main = async (): Promise => { } }); - const inputParams = createMarketBasedAuctionParams(auctionParamsInput); + const inputParams = createMarketBasedAuctionParams(auctionParamsInput, undefined, apiVersion); const result = await mapToMarketOrderParams( inputParams, diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 0f093d2..fdea26d 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -678,7 +678,8 @@ export const selectMostRecentBySlot = ( export function createMarketBasedAuctionParams( args: AuctionParamArgs, - overrideDefaults?: Partial + overrideDefaults?: Partial, + version: number = 1 ): AuctionParamArgs { // Determine if this is a major market (PERP with marketIndex 0, 1, or 2) const isMajorMarket = @@ -705,8 +706,8 @@ export function createMarketBasedAuctionParams( // Set market-specific defaults (only used if values are undefined) const marketSpecificDefaults: Partial = { ...DEFAULT_AUCTION_PARAMS, - auctionStartPriceOffsetFrom: isMajorMarket ? 'mark' : 'bestOffer', - auctionStartPriceOffset: isMajorMarket ? 0 : -0.1, + auctionStartPriceOffsetFrom: isMajorMarket && version === 1 ? 'mark' : 'bestOffer', + auctionStartPriceOffset: isMajorMarket && version === 1 ? 0 : -0.1, }; // Apply custom overrides if provided @@ -1186,7 +1187,8 @@ export const mapToMarketOrderParams = async ( driftClient, l2Formatted, startPrice, - estimatedPrices.worstPrice + estimatedPrices.worstPrice, + apiVersion ); } } else { @@ -1392,7 +1394,8 @@ export const calculateDynamicSlippage = ( driftClient: DriftClient, l2Formatted: L2OrderBook, startPrice: BN, - worstPrice: BN + worstPrice: BN, + apiVersion?: number ): number => { // Determine if this is a major market (PERP with marketIndex 0, 1, or 2) const isPerp = marketType.toLowerCase() === 'perp'; @@ -1474,7 +1477,14 @@ export const calculateDynamicSlippage = ( const minSlippage = parseFloat(process.env.DYNAMIC_SLIPPAGE_MIN || '0.035'); // 0.035% minimum const maxSlippage = parseFloat(process.env.DYNAMIC_SLIPPAGE_MAX || '5'); // 5% maximum - return Math.min(Math.max(dynamicSlippage, minSlippage), maxSlippage); + let finalSlippage = Math.min(Math.max(dynamicSlippage, minSlippage), maxSlippage); + + // Apply 10% boost for API v2 + if (apiVersion === 2) { + finalSlippage = finalSlippage * 1.1; + } + + return finalSlippage; }; /**