From a0dd2f273cf033fc06894b9fa708dfb3452918c3 Mon Sep 17 00:00:00 2001 From: Nick Caradonna Date: Tue, 18 Nov 2025 16:42:53 -0500 Subject: [PATCH 1/2] fix exactOut swaps --- sdk/src/driftClient.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 2823b3213..5fee0d5d3 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -6321,7 +6321,6 @@ export class DriftClient { const inMarket = this.getSpotMarketAccount(inMarketIndex); const isExactOut = swapMode === 'ExactOut'; - const exactOutBufferedAmountIn = amount.muln(1001).divn(1000); // Add 10bp buffer const preInstructions: TransactionInstruction[] = []; @@ -6377,11 +6376,25 @@ export class DriftClient { } } + let amountInForBeginSwap: BN; + if (isExactOut) { + if (quote || v6?.quote) { + amountInForBeginSwap = v6?.quote + ? new BN(v6.quote.inAmount) + : new BN(quote!.inAmount); + } else { + // Fallback to old behavior if no quote available + amountInForBeginSwap = amount.muln(1001).divn(1000); + } + } else { + amountInForBeginSwap = amount; + } + // Get drift swap instructions for begin and end const { beginSwapIx, endSwapIx } = await this.getSwapIx({ outMarketIndex, inMarketIndex, - amountIn: isExactOut ? exactOutBufferedAmountIn : amount, + amountIn: amountInForBeginSwap, inTokenAccount: finalInAssociatedTokenAccount, outTokenAccount: finalOutAssociatedTokenAccount, reduceOnly, From 0f2c91147758c2d1f2aa72c5096de05dc706f408 Mon Sep 17 00:00:00 2001 From: Nick Caradonna Date: Tue, 18 Nov 2025 17:22:37 -0500 Subject: [PATCH 2/2] rm comment --- sdk/src/driftClient.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index 5fee0d5d3..c822ce688 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -6383,7 +6383,6 @@ export class DriftClient { ? new BN(v6.quote.inAmount) : new BN(quote!.inAmount); } else { - // Fallback to old behavior if no quote available amountInForBeginSwap = amount.muln(1001).divn(1000); } } else {