@drift-labs/sdk 2.31.1-beta.22 → 2.31.1-beta.23
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 +0 -1
- package/lib/driftClient.js +7 -11
- package/lib/idl/drift.json +1 -1
- package/lib/orderParams.d.ts +14 -1
- package/lib/orderParams.js +17 -1
- package/package.json +1 -1
- package/src/driftClient.ts +7 -16
- package/src/idl/drift.json +1 -1
- package/src/orderParams.ts +31 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.23
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -273,7 +273,6 @@ export declare class DriftClient {
|
|
|
273
273
|
signedFillTx: Transaction;
|
|
274
274
|
}>;
|
|
275
275
|
placePerpOrder(orderParams: OptionalOrderParams, txParams?: TxParams): Promise<TransactionSignature>;
|
|
276
|
-
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
277
276
|
getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
278
277
|
updateAMMs(marketIndexes: number[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
279
278
|
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -53,6 +53,7 @@ const fetch_1 = require("./accounts/fetch");
|
|
|
53
53
|
const spotMarket_1 = require("./math/spotMarket");
|
|
54
54
|
const memcmp_1 = require("./memcmp");
|
|
55
55
|
const marinade_1 = require("./marinade");
|
|
56
|
+
const orderParams_1 = require("./orderParams");
|
|
56
57
|
/**
|
|
57
58
|
* # DriftClient
|
|
58
59
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
@@ -1393,13 +1394,8 @@ class DriftClient {
|
|
|
1393
1394
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1394
1395
|
return txSig;
|
|
1395
1396
|
}
|
|
1396
|
-
getOrderParams(optionalOrderParams, marketType) {
|
|
1397
|
-
return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams, {
|
|
1398
|
-
marketType,
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
1397
|
async getPlacePerpOrderIx(orderParams) {
|
|
1402
|
-
orderParams =
|
|
1398
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
1403
1399
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1404
1400
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1405
1401
|
userAccounts: [this.getUserAccount()],
|
|
@@ -1699,7 +1695,7 @@ class DriftClient {
|
|
|
1699
1695
|
return txSig;
|
|
1700
1696
|
}
|
|
1701
1697
|
async getPlaceSpotOrderIx(orderParams) {
|
|
1702
|
-
orderParams =
|
|
1698
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
1703
1699
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1704
1700
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1705
1701
|
userAccounts: [this.getUserAccount()],
|
|
@@ -2212,7 +2208,7 @@ class DriftClient {
|
|
|
2212
2208
|
return txSig;
|
|
2213
2209
|
}
|
|
2214
2210
|
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo) {
|
|
2215
|
-
orderParams =
|
|
2211
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
2216
2212
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2217
2213
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2218
2214
|
makerInfo = Array.isArray(makerInfo)
|
|
@@ -2273,7 +2269,7 @@ class DriftClient {
|
|
|
2273
2269
|
return txSig;
|
|
2274
2270
|
}
|
|
2275
2271
|
async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo) {
|
|
2276
|
-
orderParams =
|
|
2272
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
2277
2273
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2278
2274
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2279
2275
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2313,7 +2309,7 @@ class DriftClient {
|
|
|
2313
2309
|
return txSig;
|
|
2314
2310
|
}
|
|
2315
2311
|
async getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
2316
|
-
orderParams =
|
|
2312
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
2317
2313
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2318
2314
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2319
2315
|
const userAccounts = [this.getUserAccount()];
|
|
@@ -2372,7 +2368,7 @@ class DriftClient {
|
|
|
2372
2368
|
return txSig;
|
|
2373
2369
|
}
|
|
2374
2370
|
async getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
|
|
2375
|
-
orderParams =
|
|
2371
|
+
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
2376
2372
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2377
2373
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2378
2374
|
const remainingAccounts = this.getRemainingAccounts({
|
package/lib/idl/drift.json
CHANGED
package/lib/orderParams.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OptionalOrderParams, OrderTriggerCondition } from './types';
|
|
1
|
+
import { OptionalOrderParams, OrderParams, OrderTriggerCondition } from './types';
|
|
2
2
|
import { BN } from '@coral-xyz/anchor';
|
|
3
3
|
export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, 'orderType'> & {
|
|
4
4
|
price: BN;
|
|
@@ -13,3 +13,16 @@ export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderPar
|
|
|
13
13
|
price: BN;
|
|
14
14
|
}): OptionalOrderParams;
|
|
15
15
|
export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, 'orderType'>): OptionalOrderParams;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an OrderParams object with the given OptionalOrderParams and any params to override.
|
|
18
|
+
*
|
|
19
|
+
* example:
|
|
20
|
+
* ```
|
|
21
|
+
* const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param optionalOrderParams
|
|
25
|
+
* @param overridingParams
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function getOrderParams(optionalOrderParams: OptionalOrderParams, overridingParams?: Record<string, any>): OrderParams;
|
package/lib/orderParams.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
|
|
3
|
+
exports.getOrderParams = exports.getMarketOrderParams = exports.getTriggerLimitOrderParams = exports.getTriggerMarketOrderParams = exports.getLimitOrderParams = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
function getLimitOrderParams(params) {
|
|
6
6
|
return Object.assign({}, params, {
|
|
@@ -26,3 +26,19 @@ function getMarketOrderParams(params) {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
exports.getMarketOrderParams = getMarketOrderParams;
|
|
29
|
+
/**
|
|
30
|
+
* Creates an OrderParams object with the given OptionalOrderParams and any params to override.
|
|
31
|
+
*
|
|
32
|
+
* example:
|
|
33
|
+
* ```
|
|
34
|
+
* const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param optionalOrderParams
|
|
38
|
+
* @param overridingParams
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
function getOrderParams(optionalOrderParams, overridingParams = {}) {
|
|
42
|
+
return Object.assign({}, types_1.DefaultOrderParams, optionalOrderParams, overridingParams);
|
|
43
|
+
}
|
|
44
|
+
exports.getOrderParams = getOrderParams;
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
MakerInfo,
|
|
28
28
|
TakerInfo,
|
|
29
29
|
OptionalOrderParams,
|
|
30
|
-
DefaultOrderParams,
|
|
31
30
|
OrderType,
|
|
32
31
|
ReferrerInfo,
|
|
33
32
|
MarketType,
|
|
@@ -118,6 +117,7 @@ import { JupiterClient, Route, SwapMode } from './jupiter/jupiterClient';
|
|
|
118
117
|
import { getNonIdleUserFilter } from './memcmp';
|
|
119
118
|
import { UserStatsSubscriptionConfig } from './userStatsConfig';
|
|
120
119
|
import { getMarinadeDepositIx, getMarinadeFinanceProgram } from './marinade';
|
|
120
|
+
import { getOrderParams } from './orderParams';
|
|
121
121
|
|
|
122
122
|
type RemainingAccountParams = {
|
|
123
123
|
userAccounts: UserAccount[];
|
|
@@ -2522,19 +2522,10 @@ export class DriftClient {
|
|
|
2522
2522
|
return txSig;
|
|
2523
2523
|
}
|
|
2524
2524
|
|
|
2525
|
-
getOrderParams(
|
|
2526
|
-
optionalOrderParams: OptionalOrderParams,
|
|
2527
|
-
marketType: MarketType
|
|
2528
|
-
): OrderParams {
|
|
2529
|
-
return Object.assign({}, DefaultOrderParams, optionalOrderParams, {
|
|
2530
|
-
marketType,
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
|
-
|
|
2534
2525
|
public async getPlacePerpOrderIx(
|
|
2535
2526
|
orderParams: OptionalOrderParams
|
|
2536
2527
|
): Promise<TransactionInstruction> {
|
|
2537
|
-
orderParams =
|
|
2528
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
2538
2529
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2539
2530
|
|
|
2540
2531
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -3031,7 +3022,7 @@ export class DriftClient {
|
|
|
3031
3022
|
public async getPlaceSpotOrderIx(
|
|
3032
3023
|
orderParams: OptionalOrderParams
|
|
3033
3024
|
): Promise<TransactionInstruction> {
|
|
3034
|
-
orderParams =
|
|
3025
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
3035
3026
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3036
3027
|
|
|
3037
3028
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -3891,7 +3882,7 @@ export class DriftClient {
|
|
|
3891
3882
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
3892
3883
|
referrerInfo?: ReferrerInfo
|
|
3893
3884
|
): Promise<TransactionInstruction> {
|
|
3894
|
-
orderParams =
|
|
3885
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
3895
3886
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
3896
3887
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3897
3888
|
|
|
@@ -3987,7 +3978,7 @@ export class DriftClient {
|
|
|
3987
3978
|
takerInfo: TakerInfo,
|
|
3988
3979
|
referrerInfo?: ReferrerInfo
|
|
3989
3980
|
): Promise<TransactionInstruction> {
|
|
3990
|
-
orderParams =
|
|
3981
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
3991
3982
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3992
3983
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3993
3984
|
|
|
@@ -4059,7 +4050,7 @@ export class DriftClient {
|
|
|
4059
4050
|
makerInfo?: MakerInfo,
|
|
4060
4051
|
referrerInfo?: ReferrerInfo
|
|
4061
4052
|
): Promise<TransactionInstruction> {
|
|
4062
|
-
orderParams =
|
|
4053
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
4063
4054
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
4064
4055
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
4065
4056
|
|
|
@@ -4157,7 +4148,7 @@ export class DriftClient {
|
|
|
4157
4148
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
4158
4149
|
referrerInfo?: ReferrerInfo
|
|
4159
4150
|
): Promise<TransactionInstruction> {
|
|
4160
|
-
orderParams =
|
|
4151
|
+
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
4161
4152
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4162
4153
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
4163
4154
|
|
package/src/idl/drift.json
CHANGED
package/src/orderParams.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DefaultOrderParams,
|
|
3
|
+
OptionalOrderParams,
|
|
4
|
+
OrderParams,
|
|
5
|
+
OrderTriggerCondition,
|
|
6
|
+
OrderType,
|
|
7
|
+
} from './types';
|
|
2
8
|
import { BN } from '@coral-xyz/anchor';
|
|
3
9
|
|
|
4
10
|
export function getLimitOrderParams(
|
|
@@ -39,3 +45,27 @@ export function getMarketOrderParams(
|
|
|
39
45
|
orderType: OrderType.MARKET,
|
|
40
46
|
});
|
|
41
47
|
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates an OrderParams object with the given OptionalOrderParams and any params to override.
|
|
51
|
+
*
|
|
52
|
+
* example:
|
|
53
|
+
* ```
|
|
54
|
+
* const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param optionalOrderParams
|
|
58
|
+
* @param overridingParams
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
export function getOrderParams(
|
|
62
|
+
optionalOrderParams: OptionalOrderParams,
|
|
63
|
+
overridingParams: Record<string, any> = {}
|
|
64
|
+
): OrderParams {
|
|
65
|
+
return Object.assign(
|
|
66
|
+
{},
|
|
67
|
+
DefaultOrderParams,
|
|
68
|
+
optionalOrderParams,
|
|
69
|
+
overridingParams
|
|
70
|
+
);
|
|
71
|
+
}
|