Skip to content

Commit

Permalink
sdk: fix bug reading swapMode of undefined object (#1148)
Browse files Browse the repository at this point in the history
* sdk: optional chain quote.swapMode for swap ix

* sdk: move quote fetch around for swap ixes
  • Loading branch information
evanpipta committed Jul 18, 2024
1 parent a522386 commit 725b418
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4310,10 +4310,6 @@ export class DriftClient {
const outMarket = this.getSpotMarketAccount(outMarketIndex);
const inMarket = this.getSpotMarketAccount(inMarketIndex);

const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
const amountIn = new BN(quote.inAmount);
const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer

if (!quote) {
const fetchedQuote = await jupiterClient.getQuote({
inputMint: inMarket.mint,
Expand All @@ -4331,6 +4327,10 @@ export class DriftClient {
throw new Error("Could not fetch Jupiter's quote. Please try again.");
}

const isExactOut = swapMode === 'ExactOut' || quote.swapMode === 'ExactOut';
const amountIn = new BN(quote.inAmount);
const exactOutBufferedAmountIn = amountIn.muln(1001).divn(1000); // Add 10bp buffer

const transaction = await jupiterClient.getSwap({
quote,
userPublicKey: this.provider.wallet.publicKey,
Expand Down

0 comments on commit 725b418

Please sign in to comment.