@drift-labs/sdk 2.43.0-beta.15 → 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 +1 -1
- package/lib/driftClient.d.ts +1 -1
- package/lib/driftClient.js +6 -3
- package/lib/jupiter/jupiterClient.js +10 -2
- package/package.json +1 -1
- package/src/driftClient.ts +8 -3
- package/src/jupiter/jupiterClient.ts +12 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.43.0-beta.
|
|
1
|
+
2.43.0-beta.16
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -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<{
|
package/lib/driftClient.js
CHANGED
|
@@ -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
|
-
|
|
81
|
-
|
|
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
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
338
|
-
|
|
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
|
/**
|