@drift-labs/sdk 2.43.0-beta.14 → 2.43.0-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/VERSION CHANGED
@@ -1 +1 @@
1
- 2.43.0-beta.14
1
+ 2.43.0-beta.16
@@ -275,7 +275,7 @@ export declare class DriftClient {
275
275
  * @param makerInfo
276
276
  * @param txParams
277
277
  * @param bracketOrdersParams
278
- * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same market. Intended use is to auto-cancel TP/SL orders when closing a position
278
+ * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP
279
279
  * @returns
280
280
  */
281
281
  sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo, cancelExistingOrders?: boolean): Promise<{
@@ -1366,7 +1366,7 @@ class DriftClient {
1366
1366
  * @param makerInfo
1367
1367
  * @param txParams
1368
1368
  * @param bracketOrdersParams
1369
- * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same market. Intended use is to auto-cancel TP/SL orders when closing a position
1369
+ * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP
1370
1370
  * @returns
1371
1371
  */
1372
1372
  async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo, cancelExistingOrders) {
@@ -1384,7 +1384,7 @@ class DriftClient {
1384
1384
  }, makerInfo, referrerInfo);
1385
1385
  let cancelOrdersIx;
1386
1386
  let cancelExistingOrdersTx;
1387
- if (cancelExistingOrders) {
1387
+ if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
1388
1388
  cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null);
1389
1389
  //@ts-ignore
1390
1390
  cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion);
@@ -1600,7 +1600,7 @@ class DriftClient {
1600
1600
  const userAccountPublicKey = await this.getUserAccountPublicKey();
1601
1601
  let readablePerpMarketIndex = undefined;
1602
1602
  let readableSpotMarketIndexes = undefined;
1603
- if (marketIndex) {
1603
+ if (typeof marketIndex === 'number') {
1604
1604
  if (marketType && (0, types_1.isVariant)(marketType, 'perp')) {
1605
1605
  readablePerpMarketIndex = marketIndex;
1606
1606
  }
@@ -2120,6 +2120,9 @@ class DriftClient {
2120
2120
  });
2121
2121
  quote = fetchedQuote;
2122
2122
  }
2123
+ if (!quote) {
2124
+ throw new Error("Could not fetch Jupiter's quote. Please try again.");
2125
+ }
2123
2126
  const transaction = await jupiterClient.getSwap({
2124
2127
  quote,
2125
2128
  userPublicKey: this.provider.wallet.publicKey,
@@ -65,6 +65,9 @@ class JupiterClient {
65
65
  * @param slippageBps the slippage tolerance in basis points
66
66
  */
67
67
  async getSwap({ quote, userPublicKey, slippageBps = 50, }) {
68
+ if (!quote) {
69
+ throw new Error('Jupiter swap quote not provided. Please try again.');
70
+ }
68
71
  const resp = await (await (0, node_fetch_1.default)(`${this.url}/v6/swap`, {
69
72
  method: 'POST',
70
73
  headers: {
@@ -77,8 +80,13 @@ class JupiterClient {
77
80
  }),
78
81
  })).json();
79
82
  const { swapTransaction } = resp;
80
- const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
81
- return web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
83
+ try {
84
+ const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
85
+ return web3_js_1.VersionedTransaction.deserialize(swapTransactionBuf);
86
+ }
87
+ catch (err) {
88
+ throw new Error('Something went wrong with creating the Jupiter swap transaction. Please try again.');
89
+ }
82
90
  }
83
91
  /**
84
92
  * ** @deprecated - use getSwap
@@ -20,7 +20,12 @@ class FastSingleTxSender extends baseTxSender_1.BaseTxSender {
20
20
  }
21
21
  startBlockhashRefreshLoop() {
22
22
  setInterval(async () => {
23
- this.recentBlockhash = (await this.connection.getLatestBlockhash(this.opts)).blockhash;
23
+ try {
24
+ this.recentBlockhash = (await this.connection.getLatestBlockhash(this.opts)).blockhash;
25
+ }
26
+ catch (e) {
27
+ console.error('Error in startBlockhashRefreshLoop: ', e);
28
+ }
24
29
  }, this.blockhashRefreshInterval);
25
30
  }
26
31
  async prepareTx(tx, additionalSigners, opts) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.43.0-beta.14",
3
+ "version": "2.43.0-beta.16",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -2448,7 +2448,7 @@ export class DriftClient {
2448
2448
  * @param makerInfo
2449
2449
  * @param txParams
2450
2450
  * @param bracketOrdersParams
2451
- * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same market. Intended use is to auto-cancel TP/SL orders when closing a position
2451
+ * @param cancelExistingOrders - Builds and returns an extra transaciton to cancel the existing orders in the same perp market. Intended use is to auto-cancel TP/SL orders when closing a position. Ignored if orderParams.marketType is not MarketType.PERP
2452
2452
  * @returns
2453
2453
  */
2454
2454
  public async sendMarketOrderAndGetSignedFillTx(
@@ -2491,7 +2491,7 @@ export class DriftClient {
2491
2491
 
2492
2492
  let cancelOrdersIx: TransactionInstruction;
2493
2493
  let cancelExistingOrdersTx: Transaction;
2494
- if (cancelExistingOrders) {
2494
+ if (cancelExistingOrders && isVariant(orderParams.marketType, 'perp')) {
2495
2495
  cancelOrdersIx = await this.getCancelOrdersIx(
2496
2496
  orderParams.marketType,
2497
2497
  orderParams.marketIndex,
@@ -2896,7 +2896,8 @@ export class DriftClient {
2896
2896
 
2897
2897
  let readablePerpMarketIndex = undefined;
2898
2898
  let readableSpotMarketIndexes = undefined;
2899
- if (marketIndex) {
2899
+
2900
+ if (typeof marketIndex === 'number') {
2900
2901
  if (marketType && isVariant(marketType, 'perp')) {
2901
2902
  readablePerpMarketIndex = marketIndex;
2902
2903
  } else if (marketType && isVariant(marketType, 'spot')) {
@@ -3733,6 +3734,10 @@ export class DriftClient {
3733
3734
  quote = fetchedQuote;
3734
3735
  }
3735
3736
 
3737
+ if (!quote) {
3738
+ throw new Error("Could not fetch Jupiter's quote. Please try again.");
3739
+ }
3740
+
3736
3741
  const transaction = await jupiterClient.getSwap({
3737
3742
  quote,
3738
3743
  userPublicKey: this.provider.wallet.publicKey,
@@ -319,6 +319,10 @@ export class JupiterClient {
319
319
  userPublicKey: PublicKey;
320
320
  slippageBps?: number;
321
321
  }): Promise<VersionedTransaction> {
322
+ if (!quote) {
323
+ throw new Error('Jupiter swap quote not provided. Please try again.');
324
+ }
325
+
322
326
  const resp = await (
323
327
  await fetch(`${this.url}/v6/swap`, {
324
328
  method: 'POST',
@@ -334,8 +338,14 @@ export class JupiterClient {
334
338
  ).json();
335
339
  const { swapTransaction } = resp;
336
340
 
337
- const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
338
- return VersionedTransaction.deserialize(swapTransactionBuf);
341
+ try {
342
+ const swapTransactionBuf = Buffer.from(swapTransaction, 'base64');
343
+ return VersionedTransaction.deserialize(swapTransactionBuf);
344
+ } catch (err) {
345
+ throw new Error(
346
+ 'Something went wrong with creating the Jupiter swap transaction. Please try again.'
347
+ );
348
+ }
339
349
  }
340
350
 
341
351
  /**
@@ -54,9 +54,13 @@ export class FastSingleTxSender extends BaseTxSender {
54
54
 
55
55
  startBlockhashRefreshLoop(): void {
56
56
  setInterval(async () => {
57
- this.recentBlockhash = (
58
- await this.connection.getLatestBlockhash(this.opts)
59
- ).blockhash;
57
+ try {
58
+ this.recentBlockhash = (
59
+ await this.connection.getLatestBlockhash(this.opts)
60
+ ).blockhash;
61
+ } catch (e) {
62
+ console.error('Error in startBlockhashRefreshLoop: ', e);
63
+ }
60
64
  }, this.blockhashRefreshInterval);
61
65
  }
62
66