Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand Down Expand Up @@ -6377,11 +6376,24 @@ 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 {
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,
Expand Down
Loading