@drift-labs/sdk 2.40.0-beta.5 → 2.40.0-beta.7
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 +2 -1
- package/lib/driftClient.js +2 -1
- package/lib/jupiter/jupiterClient.d.ts +3 -1
- package/lib/jupiter/jupiterClient.js +3 -1
- package/lib/user.d.ts +2 -2
- package/lib/user.js +5 -5
- package/package.json +1 -1
- package/src/driftClient.ts +3 -0
- package/src/jupiter/jupiterClient.ts +3 -0
- package/src/user.ts +7 -5
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.40.0-beta.
|
|
1
|
+
2.40.0-beta.7
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -319,7 +319,7 @@ export declare class DriftClient {
|
|
|
319
319
|
* @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
|
|
320
320
|
* @param txParams
|
|
321
321
|
*/
|
|
322
|
-
swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, }: {
|
|
322
|
+
swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, onlyDirectRoutes, }: {
|
|
323
323
|
jupiterClient: JupiterClient;
|
|
324
324
|
outMarketIndex: number;
|
|
325
325
|
inMarketIndex: number;
|
|
@@ -331,6 +331,7 @@ export declare class DriftClient {
|
|
|
331
331
|
route?: Route;
|
|
332
332
|
reduceOnly?: SwapReduceOnly;
|
|
333
333
|
txParams?: TxParams;
|
|
334
|
+
onlyDirectRoutes?: boolean;
|
|
334
335
|
v6?: {
|
|
335
336
|
quote?: QuoteResponse;
|
|
336
337
|
};
|
package/lib/driftClient.js
CHANGED
|
@@ -1975,7 +1975,7 @@ class DriftClient {
|
|
|
1975
1975
|
* @param reduceOnly specify if In or Out token on the drift account must reduceOnly, checked at end of swap
|
|
1976
1976
|
* @param txParams
|
|
1977
1977
|
*/
|
|
1978
|
-
async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, }) {
|
|
1978
|
+
async swap({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, route, reduceOnly, txParams, v6, onlyDirectRoutes = false, }) {
|
|
1979
1979
|
let ixs;
|
|
1980
1980
|
let lookupTables;
|
|
1981
1981
|
if (v6) {
|
|
@@ -1990,6 +1990,7 @@ class DriftClient {
|
|
|
1990
1990
|
swapMode,
|
|
1991
1991
|
quote: v6.quote,
|
|
1992
1992
|
reduceOnly,
|
|
1993
|
+
onlyDirectRoutes,
|
|
1993
1994
|
});
|
|
1994
1995
|
ixs = res.ixs;
|
|
1995
1996
|
lookupTables = res.lookupTables;
|
|
@@ -229,10 +229,12 @@ export declare class JupiterClient {
|
|
|
229
229
|
* @param swapMode the swap mode (ExactIn or ExactOut)
|
|
230
230
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
231
231
|
*/
|
|
232
|
-
getQuote({ inputMint, outputMint, amount,
|
|
232
|
+
getQuote({ inputMint, outputMint, amount, maxAccounts, // 52 is an estimated amount with buffer
|
|
233
|
+
slippageBps, swapMode, onlyDirectRoutes, }: {
|
|
233
234
|
inputMint: PublicKey;
|
|
234
235
|
outputMint: PublicKey;
|
|
235
236
|
amount: BN;
|
|
237
|
+
maxAccounts?: number;
|
|
236
238
|
slippageBps?: number;
|
|
237
239
|
swapMode?: SwapMode;
|
|
238
240
|
onlyDirectRoutes?: boolean;
|
|
@@ -43,7 +43,8 @@ class JupiterClient {
|
|
|
43
43
|
* @param swapMode the swap mode (ExactIn or ExactOut)
|
|
44
44
|
* @param onlyDirectRoutes whether to only return direct routes
|
|
45
45
|
*/
|
|
46
|
-
async getQuote({ inputMint, outputMint, amount,
|
|
46
|
+
async getQuote({ inputMint, outputMint, amount, maxAccounts = 52, // 52 is an estimated amount with buffer
|
|
47
|
+
slippageBps = 50, swapMode = 'ExactIn', onlyDirectRoutes = false, }) {
|
|
47
48
|
const params = new URLSearchParams({
|
|
48
49
|
inputMint: inputMint.toString(),
|
|
49
50
|
outputMint: outputMint.toString(),
|
|
@@ -51,6 +52,7 @@ class JupiterClient {
|
|
|
51
52
|
slippageBps: slippageBps.toString(),
|
|
52
53
|
swapMode,
|
|
53
54
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
55
|
+
maxAccounts: maxAccounts.toString(),
|
|
54
56
|
}).toString();
|
|
55
57
|
const quote = await (await (0, node_fetch_1.default)(`${this.url}/v6/quote?${params}`)).json();
|
|
56
58
|
return quote;
|
package/lib/user.d.ts
CHANGED
|
@@ -180,14 +180,14 @@ export declare class User {
|
|
|
180
180
|
* calculates current user leverage which is (total liability size) / (net asset value)
|
|
181
181
|
* @returns : Precision TEN_THOUSAND
|
|
182
182
|
*/
|
|
183
|
-
getLeverage(): BN;
|
|
183
|
+
getLeverage(includeOpenOrders?: boolean): BN;
|
|
184
184
|
calculateLeverageFromComponents({ perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue, }: {
|
|
185
185
|
perpLiabilityValue: BN;
|
|
186
186
|
perpPnl: BN;
|
|
187
187
|
spotAssetValue: BN;
|
|
188
188
|
spotLiabilityValue: BN;
|
|
189
189
|
}): BN;
|
|
190
|
-
getLeverageComponents(): {
|
|
190
|
+
getLeverageComponents(includeOpenOrders?: boolean): {
|
|
191
191
|
perpLiabilityValue: BN;
|
|
192
192
|
perpPnl: BN;
|
|
193
193
|
spotAssetValue: BN;
|
package/lib/user.js
CHANGED
|
@@ -822,8 +822,8 @@ class User {
|
|
|
822
822
|
* calculates current user leverage which is (total liability size) / (net asset value)
|
|
823
823
|
* @returns : Precision TEN_THOUSAND
|
|
824
824
|
*/
|
|
825
|
-
getLeverage() {
|
|
826
|
-
return this.calculateLeverageFromComponents(this.getLeverageComponents());
|
|
825
|
+
getLeverage(includeOpenOrders = true) {
|
|
826
|
+
return this.calculateLeverageFromComponents(this.getLeverageComponents(includeOpenOrders));
|
|
827
827
|
}
|
|
828
828
|
calculateLeverageFromComponents({ perpLiabilityValue, perpPnl, spotAssetValue, spotLiabilityValue, }) {
|
|
829
829
|
const totalLiabilityValue = perpLiabilityValue.add(spotLiabilityValue);
|
|
@@ -834,10 +834,10 @@ class User {
|
|
|
834
834
|
}
|
|
835
835
|
return totalLiabilityValue.mul(numericConstants_1.TEN_THOUSAND).div(netAssetValue);
|
|
836
836
|
}
|
|
837
|
-
getLeverageComponents() {
|
|
838
|
-
const perpLiability = this.getTotalPerpPositionValue(undefined, undefined,
|
|
837
|
+
getLeverageComponents(includeOpenOrders = true) {
|
|
838
|
+
const perpLiability = this.getTotalPerpPositionValue(undefined, undefined, includeOpenOrders);
|
|
839
839
|
const perpPnl = this.getUnrealizedPNL(true);
|
|
840
|
-
const { totalAssetValue: spotAssetValue, totalLiabilityValue: spotLiabilityValue, } = this.getSpotMarketAssetAndLiabilityValue(undefined, undefined, undefined,
|
|
840
|
+
const { totalAssetValue: spotAssetValue, totalLiabilityValue: spotLiabilityValue, } = this.getSpotMarketAssetAndLiabilityValue(undefined, undefined, undefined, includeOpenOrders);
|
|
841
841
|
return {
|
|
842
842
|
perpLiabilityValue: perpLiability,
|
|
843
843
|
perpPnl,
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -3424,6 +3424,7 @@ export class DriftClient {
|
|
|
3424
3424
|
reduceOnly,
|
|
3425
3425
|
txParams,
|
|
3426
3426
|
v6,
|
|
3427
|
+
onlyDirectRoutes = false,
|
|
3427
3428
|
}: {
|
|
3428
3429
|
jupiterClient: JupiterClient;
|
|
3429
3430
|
outMarketIndex: number;
|
|
@@ -3436,6 +3437,7 @@ export class DriftClient {
|
|
|
3436
3437
|
route?: Route;
|
|
3437
3438
|
reduceOnly?: SwapReduceOnly;
|
|
3438
3439
|
txParams?: TxParams;
|
|
3440
|
+
onlyDirectRoutes?: boolean;
|
|
3439
3441
|
v6?: {
|
|
3440
3442
|
quote?: QuoteResponse;
|
|
3441
3443
|
};
|
|
@@ -3455,6 +3457,7 @@ export class DriftClient {
|
|
|
3455
3457
|
swapMode,
|
|
3456
3458
|
quote: v6.quote,
|
|
3457
3459
|
reduceOnly,
|
|
3460
|
+
onlyDirectRoutes,
|
|
3458
3461
|
});
|
|
3459
3462
|
ixs = res.ixs;
|
|
3460
3463
|
lookupTables = res.lookupTables;
|
|
@@ -275,6 +275,7 @@ export class JupiterClient {
|
|
|
275
275
|
inputMint,
|
|
276
276
|
outputMint,
|
|
277
277
|
amount,
|
|
278
|
+
maxAccounts = 52, // 52 is an estimated amount with buffer
|
|
278
279
|
slippageBps = 50,
|
|
279
280
|
swapMode = 'ExactIn',
|
|
280
281
|
onlyDirectRoutes = false,
|
|
@@ -282,6 +283,7 @@ export class JupiterClient {
|
|
|
282
283
|
inputMint: PublicKey;
|
|
283
284
|
outputMint: PublicKey;
|
|
284
285
|
amount: BN;
|
|
286
|
+
maxAccounts?: number;
|
|
285
287
|
slippageBps?: number;
|
|
286
288
|
swapMode?: SwapMode;
|
|
287
289
|
onlyDirectRoutes?: boolean;
|
|
@@ -293,6 +295,7 @@ export class JupiterClient {
|
|
|
293
295
|
slippageBps: slippageBps.toString(),
|
|
294
296
|
swapMode,
|
|
295
297
|
onlyDirectRoutes: onlyDirectRoutes.toString(),
|
|
298
|
+
maxAccounts: maxAccounts.toString(),
|
|
296
299
|
}).toString();
|
|
297
300
|
const quote = await (await fetch(`${this.url}/v6/quote?${params}`)).json();
|
|
298
301
|
return quote;
|
package/src/user.ts
CHANGED
|
@@ -1465,8 +1465,10 @@ export class User {
|
|
|
1465
1465
|
* calculates current user leverage which is (total liability size) / (net asset value)
|
|
1466
1466
|
* @returns : Precision TEN_THOUSAND
|
|
1467
1467
|
*/
|
|
1468
|
-
public getLeverage(): BN {
|
|
1469
|
-
return this.calculateLeverageFromComponents(
|
|
1468
|
+
public getLeverage(includeOpenOrders = true): BN {
|
|
1469
|
+
return this.calculateLeverageFromComponents(
|
|
1470
|
+
this.getLeverageComponents(includeOpenOrders)
|
|
1471
|
+
);
|
|
1470
1472
|
}
|
|
1471
1473
|
|
|
1472
1474
|
calculateLeverageFromComponents({
|
|
@@ -1491,7 +1493,7 @@ export class User {
|
|
|
1491
1493
|
return totalLiabilityValue.mul(TEN_THOUSAND).div(netAssetValue);
|
|
1492
1494
|
}
|
|
1493
1495
|
|
|
1494
|
-
getLeverageComponents(): {
|
|
1496
|
+
getLeverageComponents(includeOpenOrders = true): {
|
|
1495
1497
|
perpLiabilityValue: BN;
|
|
1496
1498
|
perpPnl: BN;
|
|
1497
1499
|
spotAssetValue: BN;
|
|
@@ -1500,7 +1502,7 @@ export class User {
|
|
|
1500
1502
|
const perpLiability = this.getTotalPerpPositionValue(
|
|
1501
1503
|
undefined,
|
|
1502
1504
|
undefined,
|
|
1503
|
-
|
|
1505
|
+
includeOpenOrders
|
|
1504
1506
|
);
|
|
1505
1507
|
const perpPnl = this.getUnrealizedPNL(true);
|
|
1506
1508
|
|
|
@@ -1511,7 +1513,7 @@ export class User {
|
|
|
1511
1513
|
undefined,
|
|
1512
1514
|
undefined,
|
|
1513
1515
|
undefined,
|
|
1514
|
-
|
|
1516
|
+
includeOpenOrders
|
|
1515
1517
|
);
|
|
1516
1518
|
|
|
1517
1519
|
return {
|