@drift-labs/sdk 2.28.0 → 2.29.0
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/dlob_read.ts +155 -0
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -0
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +3 -0
- package/lib/accounts/types.d.ts +1 -0
- package/lib/driftClient.d.ts +68 -33
- package/lib/driftClient.js +50 -46
- package/lib/idl/drift.json +24 -2
- package/lib/types.d.ts +12 -2
- package/lib/types.js +8 -3
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +4 -0
- package/src/accounts/types.ts +2 -0
- package/src/driftClient.ts +114 -77
- package/src/idl/drift.json +25 -3
- package/src/types.ts +8 -3
- package/src/assert/assert.js +0 -9
- package/src/token/index.js +0 -38
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/dlob_read.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import {
|
|
3
|
+
BASE_PRECISION,
|
|
4
|
+
BulkAccountLoader,
|
|
5
|
+
configs,
|
|
6
|
+
convertToNumber,
|
|
7
|
+
DLOBSubscriber,
|
|
8
|
+
DriftClient,
|
|
9
|
+
getMarketsAndOraclesForSubscription,
|
|
10
|
+
MarketType,
|
|
11
|
+
PRICE_PRECISION,
|
|
12
|
+
SlotSubscriber,
|
|
13
|
+
UserMap,
|
|
14
|
+
Wallet,
|
|
15
|
+
} from './src/index';
|
|
16
|
+
import {
|
|
17
|
+
DLOBApiClient,
|
|
18
|
+
} from './src/dlob/DLOBApiClient';
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
|
|
22
|
+
const driftConfig = configs['mainnet-beta'];
|
|
23
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
24
|
+
|
|
25
|
+
const accountLoader = new BulkAccountLoader(
|
|
26
|
+
connection,
|
|
27
|
+
'confirmed',
|
|
28
|
+
10000
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const { perpMarketIndexes, spotMarketIndexes, oracleInfos } = getMarketsAndOraclesForSubscription('mainnet-beta');
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const driftClient = new DriftClient({
|
|
35
|
+
connection: connection,
|
|
36
|
+
wallet: new Wallet(new Keypair()),
|
|
37
|
+
programID: new PublicKey(driftConfig.DRIFT_PROGRAM_ID),
|
|
38
|
+
accountSubscription: {
|
|
39
|
+
type: 'polling',
|
|
40
|
+
accountLoader: accountLoader,
|
|
41
|
+
},
|
|
42
|
+
perpMarketIndexes,
|
|
43
|
+
spotMarketIndexes,
|
|
44
|
+
oracleInfos,
|
|
45
|
+
userStats: true,
|
|
46
|
+
env: 'mainnet-beta',
|
|
47
|
+
});
|
|
48
|
+
console.log(`driftClientSubscribed: ${await driftClient.subscribe()}`);
|
|
49
|
+
|
|
50
|
+
const slotSubscriber = new SlotSubscriber(connection);
|
|
51
|
+
await slotSubscriber.subscribe();
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// Alternatively, you can also use the UserMap class, which loads the DLOB via RPC calls.
|
|
55
|
+
// const userMap = new UserMap(driftClient, driftClient.userAccountSubscriptionConfig, false);
|
|
56
|
+
|
|
57
|
+
// This loads the DLOB from a server hosted by Drift.
|
|
58
|
+
const dlobAPI = new DLOBApiClient({
|
|
59
|
+
url: 'https://dlob.drift.trade/orders/idlWithSlot',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const dlobSubscriber = new DLOBSubscriber({
|
|
63
|
+
dlobSource: dlobAPI,
|
|
64
|
+
slotSource: slotSubscriber,
|
|
65
|
+
driftClient: driftClient,
|
|
66
|
+
updateFrequency: 10000,
|
|
67
|
+
});
|
|
68
|
+
await dlobSubscriber.subscribe();
|
|
69
|
+
|
|
70
|
+
const l2 = dlobSubscriber.getL2({
|
|
71
|
+
marketIndex: 0,
|
|
72
|
+
marketType: MarketType.PERP,
|
|
73
|
+
});
|
|
74
|
+
console.log("Level 2 order book:");
|
|
75
|
+
|
|
76
|
+
console.log("Asks:");
|
|
77
|
+
const asks = l2.asks.slice().reverse();
|
|
78
|
+
for (let i = 0; i < asks.length; i++) {
|
|
79
|
+
const ask = asks[i];
|
|
80
|
+
console.log(` [${asks.length - i - 1}] ${convertToNumber(ask.size, BASE_PRECISION)} @ $${convertToNumber(ask.price, PRICE_PRECISION)}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log("Bids:");
|
|
84
|
+
const bids = l2.bids;
|
|
85
|
+
for (let i = 0; i < bids.length; i++) {
|
|
86
|
+
const bid = bids[i];
|
|
87
|
+
console.log(` [${i}] ${convertToNumber(bid.size, BASE_PRECISION)} @ $${convertToNumber(bid.price, PRICE_PRECISION)}`);
|
|
88
|
+
}
|
|
89
|
+
console.log("");
|
|
90
|
+
console.log("");
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
Level 2 order book:
|
|
94
|
+
Asks:
|
|
95
|
+
[9] 664.8 @ $21.3248
|
|
96
|
+
[8] 3.5 @ $21.288301
|
|
97
|
+
[7] 3.5 @ $21.287237
|
|
98
|
+
[6] 3.5 @ $21.283129
|
|
99
|
+
[5] 0.1 @ $21.2825
|
|
100
|
+
[4] 1937.6 @ $21.2748
|
|
101
|
+
[3] 1 @ $21.26
|
|
102
|
+
[2] 2015 @ $21.2589
|
|
103
|
+
[1] 503.7 @ $21.2483
|
|
104
|
+
[0] 377.8 @ $21.243
|
|
105
|
+
Bids:
|
|
106
|
+
[0] 1168.2 @ $21.2464
|
|
107
|
+
[1] 136.7 @ $21.2461
|
|
108
|
+
[2] 2570.2 @ $21.2426
|
|
109
|
+
[3] 0.1 @ $21.2419
|
|
110
|
+
[4] 47 @ $21.216188
|
|
111
|
+
[5] 327.8 @ $21.211
|
|
112
|
+
[6] 437 @ $21.2057
|
|
113
|
+
[7] 47 @ $21.205592
|
|
114
|
+
[8] 1748.3 @ $21.1951
|
|
115
|
+
[9] 187 @ $21.1792
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
const l3 = dlobSubscriber.getL3({
|
|
119
|
+
marketIndex: 0,
|
|
120
|
+
marketType: MarketType.PERP,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
console.log("Level 3 order book:");
|
|
124
|
+
console.log("Asks:");
|
|
125
|
+
const l3asks = l3.asks.slice().reverse();
|
|
126
|
+
for (let i = 0; i < l3asks.length; i++) {
|
|
127
|
+
const ask = l3asks[i];
|
|
128
|
+
console.log(` [${l3asks.length - i - 1}] ${ask.maker.toBase58()} ${convertToNumber(ask.size, BASE_PRECISION)} @ $${convertToNumber(ask.price, PRICE_PRECISION)}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
console.log("Bids:");
|
|
132
|
+
const l3bids = l3.bids;
|
|
133
|
+
for (let i = 0; i < l3bids.length; i++) {
|
|
134
|
+
const bid = l3bids[i];
|
|
135
|
+
console.log(` [${i}] ${bid.maker.toBase58()} ${convertToNumber(bid.size, BASE_PRECISION)} @ $${convertToNumber(bid.price, PRICE_PRECISION)}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
Level 3 order book:
|
|
140
|
+
Asks:
|
|
141
|
+
...
|
|
142
|
+
[3] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 1 @ $21.26
|
|
143
|
+
[2] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 2015 @ $21.2589
|
|
144
|
+
[1] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 503.7 @ $21.2483
|
|
145
|
+
[0] C13FZykQfLXKuMAMh2iuG7JxhQqd8otujNRAgVETU6id 377.8 @ $21.243
|
|
146
|
+
Bids:
|
|
147
|
+
[0] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 1168.2 @ $21.2464
|
|
148
|
+
[1] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 2570.2 @ $21.2464
|
|
149
|
+
[2] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 136.7 @ $21.2461
|
|
150
|
+
[3] FrEFAwxdrzHxgc7S4cuFfsfLmcg8pfbxnkCQW83euyCS 2570.2 @ $21.2426
|
|
151
|
+
...
|
|
152
|
+
*/
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
main().catch(console.error);
|
|
@@ -53,4 +53,5 @@ export declare class PollingDriftClientAccountSubscriber implements DriftClientA
|
|
|
53
53
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
54
54
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
55
55
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
56
|
+
updateAccountLoaderPollingFrequency(pollingFrequency: number): void;
|
|
56
57
|
}
|
|
@@ -274,5 +274,8 @@ class PollingDriftClientAccountSubscriber {
|
|
|
274
274
|
}
|
|
275
275
|
return this.oracles.get(oraclePublicKey.toString());
|
|
276
276
|
}
|
|
277
|
+
updateAccountLoaderPollingFrequency(pollingFrequency) {
|
|
278
|
+
this.accountLoader.updatePollingFrequency(pollingFrequency);
|
|
279
|
+
}
|
|
277
280
|
}
|
|
278
281
|
exports.PollingDriftClientAccountSubscriber = PollingDriftClientAccountSubscriber;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface DriftClientAccountSubscriber {
|
|
|
40
40
|
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
41
41
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
42
42
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
43
|
+
updateAccountLoaderPollingFrequency?: (pollingFrequency: number) => void;
|
|
43
44
|
}
|
|
44
45
|
export interface UserAccountEvents {
|
|
45
46
|
userAccountUpdate: (payload: UserAccount) => void;
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -314,22 +314,23 @@ export declare class DriftClient {
|
|
|
314
314
|
modifyPerpOrderByUserOrderId(userOrderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
|
|
315
315
|
/**
|
|
316
316
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
317
|
-
* @param orderId: The open order to modify
|
|
318
|
-
* @param newDirection: The new direction for the order
|
|
319
|
-
* @param newBaseAmount: The new base amount for the order
|
|
320
|
-
* @param newLimitPice: The new limit price for the order
|
|
321
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
322
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
323
|
-
* @param auctionDuration:
|
|
324
|
-
* @param auctionStartPrice:
|
|
325
|
-
* @param auctionEndPrice:
|
|
326
|
-
* @param reduceOnly:
|
|
327
|
-
* @param postOnly:
|
|
328
|
-
* @param immediateOrCancel:
|
|
329
|
-
* @param
|
|
317
|
+
* @param orderParams.orderId: The open order to modify
|
|
318
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
319
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
320
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
321
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
322
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
323
|
+
* @param orderParams.auctionDuration:
|
|
324
|
+
* @param orderParams.auctionStartPrice:
|
|
325
|
+
* @param orderParams.auctionEndPrice:
|
|
326
|
+
* @param orderParams.reduceOnly:
|
|
327
|
+
* @param orderParams.postOnly:
|
|
328
|
+
* @param orderParams.immediateOrCancel:
|
|
329
|
+
* @param orderParams.policy:
|
|
330
|
+
* @param orderParams.maxTs:
|
|
330
331
|
* @returns
|
|
331
332
|
*/
|
|
332
|
-
modifyOrder(
|
|
333
|
+
modifyOrder(orderParams: {
|
|
333
334
|
orderId: number;
|
|
334
335
|
newDirection?: PositionDirection;
|
|
335
336
|
newBaseAmount?: BN;
|
|
@@ -344,27 +345,61 @@ export declare class DriftClient {
|
|
|
344
345
|
postOnly?: boolean;
|
|
345
346
|
immediateOrCancel?: boolean;
|
|
346
347
|
maxTs?: BN;
|
|
347
|
-
|
|
348
|
-
}): Promise<TransactionSignature>;
|
|
349
|
-
getModifyOrderIx(orderId
|
|
348
|
+
policy?: ModifyOrderParams;
|
|
349
|
+
}, txParams?: TxParams): Promise<TransactionSignature>;
|
|
350
|
+
getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }: {
|
|
351
|
+
orderId: number;
|
|
352
|
+
newDirection?: PositionDirection;
|
|
353
|
+
newBaseAmount?: BN;
|
|
354
|
+
newLimitPrice?: BN;
|
|
355
|
+
newOraclePriceOffset?: number;
|
|
356
|
+
newTriggerPrice?: BN;
|
|
357
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
358
|
+
auctionDuration?: number;
|
|
359
|
+
auctionStartPrice?: BN;
|
|
360
|
+
auctionEndPrice?: BN;
|
|
361
|
+
reduceOnly?: boolean;
|
|
362
|
+
postOnly?: boolean;
|
|
363
|
+
immediateOrCancel?: boolean;
|
|
364
|
+
maxTs?: BN;
|
|
365
|
+
policy?: ModifyOrderParams;
|
|
366
|
+
}): Promise<TransactionInstruction>;
|
|
350
367
|
/**
|
|
351
368
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
352
|
-
* @param userOrderId: The open order to modify
|
|
353
|
-
* @param newDirection: The new direction for the order
|
|
354
|
-
* @param newBaseAmount: The new base amount for the order
|
|
355
|
-
* @param newLimitPice: The new limit price for the order
|
|
356
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
357
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
358
|
-
* @param auctionDuration: Only required if order type changed to market from something else
|
|
359
|
-
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
360
|
-
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
361
|
-
* @param reduceOnly:
|
|
362
|
-
* @param postOnly:
|
|
363
|
-
* @param immediateOrCancel:
|
|
364
|
-
* @param
|
|
369
|
+
* @param orderParams.userOrderId: The open order to modify
|
|
370
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
371
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
372
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
373
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
374
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
375
|
+
* @param orderParams.auctionDuration: Only required if order type changed to market from something else
|
|
376
|
+
* @param orderParams.auctionStartPrice: Only required if order type changed to market from something else
|
|
377
|
+
* @param orderParams.auctionEndPrice: Only required if order type changed to market from something else
|
|
378
|
+
* @param orderParams.reduceOnly:
|
|
379
|
+
* @param orderParams.postOnly:
|
|
380
|
+
* @param orderParams.immediateOrCancel:
|
|
381
|
+
* @param orderParams.policy:
|
|
382
|
+
* @param orderParams.maxTs:
|
|
365
383
|
* @returns
|
|
366
384
|
*/
|
|
367
|
-
modifyOrderByUserOrderId(
|
|
385
|
+
modifyOrderByUserOrderId(orderParams: {
|
|
386
|
+
userOrderId: number;
|
|
387
|
+
newDirection?: PositionDirection;
|
|
388
|
+
newBaseAmount?: BN;
|
|
389
|
+
newLimitPrice?: BN;
|
|
390
|
+
newOraclePriceOffset?: number;
|
|
391
|
+
newTriggerPrice?: BN;
|
|
392
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
393
|
+
auctionDuration?: number;
|
|
394
|
+
auctionStartPrice?: BN;
|
|
395
|
+
auctionEndPrice?: BN;
|
|
396
|
+
reduceOnly?: boolean;
|
|
397
|
+
postOnly?: boolean;
|
|
398
|
+
immediateOrCancel?: boolean;
|
|
399
|
+
policy?: ModifyOrderParams;
|
|
400
|
+
maxTs?: BN;
|
|
401
|
+
}, txParams?: TxParams): Promise<TransactionSignature>;
|
|
402
|
+
getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }: {
|
|
368
403
|
userOrderId: number;
|
|
369
404
|
newDirection?: PositionDirection;
|
|
370
405
|
newBaseAmount?: BN;
|
|
@@ -378,10 +413,10 @@ export declare class DriftClient {
|
|
|
378
413
|
reduceOnly?: boolean;
|
|
379
414
|
postOnly?: boolean;
|
|
380
415
|
immediateOrCancel?: boolean;
|
|
416
|
+
policy?: ModifyOrderParams;
|
|
381
417
|
maxTs?: BN;
|
|
382
418
|
txParams?: TxParams;
|
|
383
|
-
}): Promise<
|
|
384
|
-
getModifyOrderByUserIdIx(userOrderId: number, orderParams: ModifyOrderParams): Promise<TransactionInstruction>;
|
|
419
|
+
}): Promise<TransactionInstruction>;
|
|
385
420
|
settlePNLs(users: {
|
|
386
421
|
settleeUserAccountPublicKey: PublicKey;
|
|
387
422
|
settleeUserAccount: UserAccount;
|
package/lib/driftClient.js
CHANGED
|
@@ -2273,22 +2273,32 @@ class DriftClient {
|
|
|
2273
2273
|
}
|
|
2274
2274
|
/**
|
|
2275
2275
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
2276
|
-
* @param orderId: The open order to modify
|
|
2277
|
-
* @param newDirection: The new direction for the order
|
|
2278
|
-
* @param newBaseAmount: The new base amount for the order
|
|
2279
|
-
* @param newLimitPice: The new limit price for the order
|
|
2280
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
2281
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
2282
|
-
* @param auctionDuration:
|
|
2283
|
-
* @param auctionStartPrice:
|
|
2284
|
-
* @param auctionEndPrice:
|
|
2285
|
-
* @param reduceOnly:
|
|
2286
|
-
* @param postOnly:
|
|
2287
|
-
* @param immediateOrCancel:
|
|
2288
|
-
* @param
|
|
2276
|
+
* @param orderParams.orderId: The open order to modify
|
|
2277
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
2278
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
2279
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
2280
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
2281
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
2282
|
+
* @param orderParams.auctionDuration:
|
|
2283
|
+
* @param orderParams.auctionStartPrice:
|
|
2284
|
+
* @param orderParams.auctionEndPrice:
|
|
2285
|
+
* @param orderParams.reduceOnly:
|
|
2286
|
+
* @param orderParams.postOnly:
|
|
2287
|
+
* @param orderParams.immediateOrCancel:
|
|
2288
|
+
* @param orderParams.policy:
|
|
2289
|
+
* @param orderParams.maxTs:
|
|
2289
2290
|
* @returns
|
|
2290
2291
|
*/
|
|
2291
|
-
async modifyOrder(
|
|
2292
|
+
async modifyOrder(orderParams, txParams) {
|
|
2293
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderIx(orderParams), txParams), [], this.opts);
|
|
2294
|
+
return txSig;
|
|
2295
|
+
}
|
|
2296
|
+
async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }) {
|
|
2297
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2298
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
2299
|
+
userAccounts: [this.getUserAccount()],
|
|
2300
|
+
useMarketLastSlotCache: true,
|
|
2301
|
+
});
|
|
2292
2302
|
const orderParams = {
|
|
2293
2303
|
baseAssetAmount: newBaseAmount || null,
|
|
2294
2304
|
direction: newDirection || null,
|
|
@@ -2302,17 +2312,9 @@ class DriftClient {
|
|
|
2302
2312
|
reduceOnly: reduceOnly || null,
|
|
2303
2313
|
postOnly: postOnly || null,
|
|
2304
2314
|
immediateOrCancel: immediateOrCancel || null,
|
|
2315
|
+
policy: policy || null,
|
|
2305
2316
|
maxTs: maxTs || null,
|
|
2306
2317
|
};
|
|
2307
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderIx(orderId, orderParams), txParams), [], this.opts);
|
|
2308
|
-
return txSig;
|
|
2309
|
-
}
|
|
2310
|
-
async getModifyOrderIx(orderId, orderParams) {
|
|
2311
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2312
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
2313
|
-
userAccounts: [this.getUserAccount()],
|
|
2314
|
-
useMarketLastSlotCache: true,
|
|
2315
|
-
});
|
|
2316
2318
|
return await this.program.instruction.modifyOrder(orderId, orderParams, {
|
|
2317
2319
|
accounts: {
|
|
2318
2320
|
state: await this.getStatePublicKey(),
|
|
@@ -2325,22 +2327,32 @@ class DriftClient {
|
|
|
2325
2327
|
}
|
|
2326
2328
|
/**
|
|
2327
2329
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
2328
|
-
* @param userOrderId: The open order to modify
|
|
2329
|
-
* @param newDirection: The new direction for the order
|
|
2330
|
-
* @param newBaseAmount: The new base amount for the order
|
|
2331
|
-
* @param newLimitPice: The new limit price for the order
|
|
2332
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
2333
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
2334
|
-
* @param auctionDuration: Only required if order type changed to market from something else
|
|
2335
|
-
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
2336
|
-
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
2337
|
-
* @param reduceOnly:
|
|
2338
|
-
* @param postOnly:
|
|
2339
|
-
* @param immediateOrCancel:
|
|
2340
|
-
* @param
|
|
2330
|
+
* @param orderParams.userOrderId: The open order to modify
|
|
2331
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
2332
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
2333
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
2334
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
2335
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
2336
|
+
* @param orderParams.auctionDuration: Only required if order type changed to market from something else
|
|
2337
|
+
* @param orderParams.auctionStartPrice: Only required if order type changed to market from something else
|
|
2338
|
+
* @param orderParams.auctionEndPrice: Only required if order type changed to market from something else
|
|
2339
|
+
* @param orderParams.reduceOnly:
|
|
2340
|
+
* @param orderParams.postOnly:
|
|
2341
|
+
* @param orderParams.immediateOrCancel:
|
|
2342
|
+
* @param orderParams.policy:
|
|
2343
|
+
* @param orderParams.maxTs:
|
|
2341
2344
|
* @returns
|
|
2342
2345
|
*/
|
|
2343
|
-
async modifyOrderByUserOrderId(
|
|
2346
|
+
async modifyOrderByUserOrderId(orderParams, txParams) {
|
|
2347
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderByUserIdIx(orderParams), txParams), [], this.opts);
|
|
2348
|
+
return txSig;
|
|
2349
|
+
}
|
|
2350
|
+
async getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }) {
|
|
2351
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2352
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
2353
|
+
userAccounts: [this.getUserAccount()],
|
|
2354
|
+
useMarketLastSlotCache: true,
|
|
2355
|
+
});
|
|
2344
2356
|
const orderParams = {
|
|
2345
2357
|
baseAssetAmount: newBaseAmount || null,
|
|
2346
2358
|
direction: newDirection || null,
|
|
@@ -2354,17 +2366,9 @@ class DriftClient {
|
|
|
2354
2366
|
reduceOnly: reduceOnly || null,
|
|
2355
2367
|
postOnly: postOnly || null,
|
|
2356
2368
|
immediateOrCancel: immediateOrCancel || null,
|
|
2369
|
+
policy: policy || null,
|
|
2357
2370
|
maxTs: maxTs || null,
|
|
2358
2371
|
};
|
|
2359
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderByUserIdIx(userOrderId, orderParams), txParams), [], this.opts);
|
|
2360
|
-
return txSig;
|
|
2361
|
-
}
|
|
2362
|
-
async getModifyOrderByUserIdIx(userOrderId, orderParams) {
|
|
2363
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
2364
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
2365
|
-
userAccounts: [this.getUserAccount()],
|
|
2366
|
-
useMarketLastSlotCache: true,
|
|
2367
|
-
});
|
|
2368
2372
|
return await this.program.instruction.modifyOrderByUserId(userOrderId, orderParams, {
|
|
2369
2373
|
accounts: {
|
|
2370
2374
|
state: await this.getStatePublicKey(),
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.29.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4736,7 +4736,7 @@
|
|
|
4736
4736
|
"name": "orderTickSize",
|
|
4737
4737
|
"docs": [
|
|
4738
4738
|
"Spot orders must be a multiple of the tick size",
|
|
4739
|
-
"precision:
|
|
4739
|
+
"precision: PRICE_PRECISION"
|
|
4740
4740
|
],
|
|
4741
4741
|
"type": "u64"
|
|
4742
4742
|
},
|
|
@@ -5565,6 +5565,14 @@
|
|
|
5565
5565
|
"type": {
|
|
5566
5566
|
"option": "i64"
|
|
5567
5567
|
}
|
|
5568
|
+
},
|
|
5569
|
+
{
|
|
5570
|
+
"name": "policy",
|
|
5571
|
+
"type": {
|
|
5572
|
+
"option": {
|
|
5573
|
+
"defined": "ModifyOrderPolicy"
|
|
5574
|
+
}
|
|
5575
|
+
}
|
|
5568
5576
|
}
|
|
5569
5577
|
]
|
|
5570
5578
|
}
|
|
@@ -7237,6 +7245,20 @@
|
|
|
7237
7245
|
]
|
|
7238
7246
|
}
|
|
7239
7247
|
},
|
|
7248
|
+
{
|
|
7249
|
+
"name": "ModifyOrderPolicy",
|
|
7250
|
+
"type": {
|
|
7251
|
+
"kind": "enum",
|
|
7252
|
+
"variants": [
|
|
7253
|
+
{
|
|
7254
|
+
"name": "TryModify"
|
|
7255
|
+
},
|
|
7256
|
+
{
|
|
7257
|
+
"name": "MustModify"
|
|
7258
|
+
}
|
|
7259
|
+
]
|
|
7260
|
+
}
|
|
7261
|
+
},
|
|
7240
7262
|
{
|
|
7241
7263
|
"name": "TwapPeriod",
|
|
7242
7264
|
"type": {
|
package/lib/types.d.ts
CHANGED
|
@@ -480,8 +480,8 @@ export declare class LiquidationType {
|
|
|
480
480
|
static readonly PERP_BANKRUPTCY: {
|
|
481
481
|
perpBankruptcy: {};
|
|
482
482
|
};
|
|
483
|
-
static readonly
|
|
484
|
-
|
|
483
|
+
static readonly SPOT_BANKRUPTCY: {
|
|
484
|
+
spotBankruptcy: {};
|
|
485
485
|
};
|
|
486
486
|
static readonly LIQUIDATE_SPOT: {
|
|
487
487
|
liquidateSpot: {};
|
|
@@ -932,7 +932,17 @@ export type OptionalOrderParams = {
|
|
|
932
932
|
} & NecessaryOrderParams;
|
|
933
933
|
export type ModifyOrderParams = {
|
|
934
934
|
[Property in keyof OrderParams]?: OrderParams[Property] | null;
|
|
935
|
+
} & {
|
|
936
|
+
policy?: ModifyOrderPolicy;
|
|
935
937
|
};
|
|
938
|
+
export declare class ModifyOrderPolicy {
|
|
939
|
+
static readonly MUST_MODIFY: {
|
|
940
|
+
mustModify: {};
|
|
941
|
+
};
|
|
942
|
+
static readonly TRY_MODIFY: {
|
|
943
|
+
tryModify: {};
|
|
944
|
+
};
|
|
945
|
+
}
|
|
936
946
|
export declare const DefaultOrderParams: OrderParams;
|
|
937
947
|
export type MakerInfo = {
|
|
938
948
|
maker: PublicKey;
|
package/lib/types.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultOrderParams = exports.PostOnlyParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
3
|
+
exports.DefaultOrderParams = exports.ModifyOrderPolicy = exports.PostOnlyParams = exports.LiquidationType = exports.LPAction = exports.TradeSide = exports.getVariant = exports.isOneOfVariant = exports.isVariant = exports.StakeAction = exports.SpotFulfillmentConfigStatus = exports.SettlePnlExplanation = exports.DepositExplanation = exports.SpotFulfillmentStatus = exports.SpotFulfillmentType = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderStatus = exports.MarketType = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.SpotBalanceType = exports.SwapDirection = exports.AssetTier = exports.ContractTier = exports.ContractType = exports.UserStatus = exports.MarketStatus = exports.ExchangeStatus = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
// # Utility Types / Enums / Constants
|
|
6
6
|
var ExchangeStatus;
|
|
@@ -230,8 +230,8 @@ LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
|
230
230
|
LiquidationType.PERP_BANKRUPTCY = {
|
|
231
231
|
perpBankruptcy: {},
|
|
232
232
|
};
|
|
233
|
-
LiquidationType.
|
|
234
|
-
|
|
233
|
+
LiquidationType.SPOT_BANKRUPTCY = {
|
|
234
|
+
spotBankruptcy: {},
|
|
235
235
|
};
|
|
236
236
|
LiquidationType.LIQUIDATE_SPOT = {
|
|
237
237
|
liquidateSpot: {},
|
|
@@ -242,6 +242,11 @@ exports.PostOnlyParams = PostOnlyParams;
|
|
|
242
242
|
PostOnlyParams.NONE = { none: {} };
|
|
243
243
|
PostOnlyParams.MUST_POST_ONLY = { mustPostOnly: {} }; // Tx fails if order can't be post only
|
|
244
244
|
PostOnlyParams.TRY_POST_ONLY = { tryPostOnly: {} }; // Tx succeeds and order not placed if can't be post only
|
|
245
|
+
class ModifyOrderPolicy {
|
|
246
|
+
}
|
|
247
|
+
exports.ModifyOrderPolicy = ModifyOrderPolicy;
|
|
248
|
+
ModifyOrderPolicy.MUST_MODIFY = { mustModify: {} };
|
|
249
|
+
ModifyOrderPolicy.TRY_MODIFY = { tryModify: {} };
|
|
245
250
|
exports.DefaultOrderParams = {
|
|
246
251
|
orderType: OrderType.MARKET,
|
|
247
252
|
marketType: MarketType.PERP,
|
package/package.json
CHANGED
|
@@ -435,4 +435,8 @@ export class PollingDriftClientAccountSubscriber
|
|
|
435
435
|
|
|
436
436
|
return this.oracles.get(oraclePublicKey.toString());
|
|
437
437
|
}
|
|
438
|
+
|
|
439
|
+
public updateAccountLoaderPollingFrequency(pollingFrequency: number): void {
|
|
440
|
+
this.accountLoader.updatePollingFrequency(pollingFrequency);
|
|
441
|
+
}
|
|
438
442
|
}
|
package/src/accounts/types.ts
CHANGED
|
@@ -59,6 +59,8 @@ export interface DriftClientAccountSubscriber {
|
|
|
59
59
|
getOraclePriceDataAndSlot(
|
|
60
60
|
oraclePublicKey: PublicKey
|
|
61
61
|
): DataAndSlot<OraclePriceData> | undefined;
|
|
62
|
+
|
|
63
|
+
updateAccountLoaderPollingFrequency?: (pollingFrequency: number) => void;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export interface UserAccountEvents {
|
package/src/driftClient.ts
CHANGED
|
@@ -3807,22 +3807,54 @@ export class DriftClient {
|
|
|
3807
3807
|
|
|
3808
3808
|
/**
|
|
3809
3809
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
3810
|
-
* @param orderId: The open order to modify
|
|
3811
|
-
* @param newDirection: The new direction for the order
|
|
3812
|
-
* @param newBaseAmount: The new base amount for the order
|
|
3813
|
-
* @param newLimitPice: The new limit price for the order
|
|
3814
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
3815
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3816
|
-
* @param auctionDuration:
|
|
3817
|
-
* @param auctionStartPrice:
|
|
3818
|
-
* @param auctionEndPrice:
|
|
3819
|
-
* @param reduceOnly:
|
|
3820
|
-
* @param postOnly:
|
|
3821
|
-
* @param immediateOrCancel:
|
|
3822
|
-
* @param
|
|
3810
|
+
* @param orderParams.orderId: The open order to modify
|
|
3811
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
3812
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
3813
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
3814
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
3815
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3816
|
+
* @param orderParams.auctionDuration:
|
|
3817
|
+
* @param orderParams.auctionStartPrice:
|
|
3818
|
+
* @param orderParams.auctionEndPrice:
|
|
3819
|
+
* @param orderParams.reduceOnly:
|
|
3820
|
+
* @param orderParams.postOnly:
|
|
3821
|
+
* @param orderParams.immediateOrCancel:
|
|
3822
|
+
* @param orderParams.policy:
|
|
3823
|
+
* @param orderParams.maxTs:
|
|
3823
3824
|
* @returns
|
|
3824
3825
|
*/
|
|
3825
|
-
public async modifyOrder(
|
|
3826
|
+
public async modifyOrder(
|
|
3827
|
+
orderParams: {
|
|
3828
|
+
orderId: number;
|
|
3829
|
+
newDirection?: PositionDirection;
|
|
3830
|
+
newBaseAmount?: BN;
|
|
3831
|
+
newLimitPrice?: BN;
|
|
3832
|
+
newOraclePriceOffset?: number;
|
|
3833
|
+
newTriggerPrice?: BN;
|
|
3834
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
3835
|
+
auctionDuration?: number;
|
|
3836
|
+
auctionStartPrice?: BN;
|
|
3837
|
+
auctionEndPrice?: BN;
|
|
3838
|
+
reduceOnly?: boolean;
|
|
3839
|
+
postOnly?: boolean;
|
|
3840
|
+
immediateOrCancel?: boolean;
|
|
3841
|
+
maxTs?: BN;
|
|
3842
|
+
policy?: ModifyOrderParams;
|
|
3843
|
+
},
|
|
3844
|
+
txParams?: TxParams
|
|
3845
|
+
): Promise<TransactionSignature> {
|
|
3846
|
+
const { txSig } = await this.sendTransaction(
|
|
3847
|
+
await this.buildTransaction(
|
|
3848
|
+
await this.getModifyOrderIx(orderParams),
|
|
3849
|
+
txParams
|
|
3850
|
+
),
|
|
3851
|
+
[],
|
|
3852
|
+
this.opts
|
|
3853
|
+
);
|
|
3854
|
+
return txSig;
|
|
3855
|
+
}
|
|
3856
|
+
|
|
3857
|
+
public async getModifyOrderIx({
|
|
3826
3858
|
orderId,
|
|
3827
3859
|
newDirection,
|
|
3828
3860
|
newBaseAmount,
|
|
@@ -3837,7 +3869,7 @@ export class DriftClient {
|
|
|
3837
3869
|
postOnly,
|
|
3838
3870
|
immediateOrCancel,
|
|
3839
3871
|
maxTs,
|
|
3840
|
-
|
|
3872
|
+
policy,
|
|
3841
3873
|
}: {
|
|
3842
3874
|
orderId: number;
|
|
3843
3875
|
newDirection?: PositionDirection;
|
|
@@ -3853,8 +3885,15 @@ export class DriftClient {
|
|
|
3853
3885
|
postOnly?: boolean;
|
|
3854
3886
|
immediateOrCancel?: boolean;
|
|
3855
3887
|
maxTs?: BN;
|
|
3856
|
-
|
|
3857
|
-
}): Promise<
|
|
3888
|
+
policy?: ModifyOrderParams;
|
|
3889
|
+
}): Promise<TransactionInstruction> {
|
|
3890
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3891
|
+
|
|
3892
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
3893
|
+
userAccounts: [this.getUserAccount()],
|
|
3894
|
+
useMarketLastSlotCache: true,
|
|
3895
|
+
});
|
|
3896
|
+
|
|
3858
3897
|
const orderParams: ModifyOrderParams = {
|
|
3859
3898
|
baseAssetAmount: newBaseAmount || null,
|
|
3860
3899
|
direction: newDirection || null,
|
|
@@ -3868,31 +3907,10 @@ export class DriftClient {
|
|
|
3868
3907
|
reduceOnly: reduceOnly || null,
|
|
3869
3908
|
postOnly: postOnly || null,
|
|
3870
3909
|
immediateOrCancel: immediateOrCancel || null,
|
|
3910
|
+
policy: policy || null,
|
|
3871
3911
|
maxTs: maxTs || null,
|
|
3872
3912
|
};
|
|
3873
3913
|
|
|
3874
|
-
const { txSig } = await this.sendTransaction(
|
|
3875
|
-
await this.buildTransaction(
|
|
3876
|
-
await this.getModifyOrderIx(orderId, orderParams),
|
|
3877
|
-
txParams
|
|
3878
|
-
),
|
|
3879
|
-
[],
|
|
3880
|
-
this.opts
|
|
3881
|
-
);
|
|
3882
|
-
return txSig;
|
|
3883
|
-
}
|
|
3884
|
-
|
|
3885
|
-
public async getModifyOrderIx(
|
|
3886
|
-
orderId: number,
|
|
3887
|
-
orderParams: ModifyOrderParams
|
|
3888
|
-
): Promise<TransactionInstruction> {
|
|
3889
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3890
|
-
|
|
3891
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
3892
|
-
userAccounts: [this.getUserAccount()],
|
|
3893
|
-
useMarketLastSlotCache: true,
|
|
3894
|
-
});
|
|
3895
|
-
|
|
3896
3914
|
return await this.program.instruction.modifyOrder(orderId, orderParams, {
|
|
3897
3915
|
accounts: {
|
|
3898
3916
|
state: await this.getStatePublicKey(),
|
|
@@ -3906,22 +3924,54 @@ export class DriftClient {
|
|
|
3906
3924
|
|
|
3907
3925
|
/**
|
|
3908
3926
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
3909
|
-
* @param userOrderId: The open order to modify
|
|
3910
|
-
* @param newDirection: The new direction for the order
|
|
3911
|
-
* @param newBaseAmount: The new base amount for the order
|
|
3912
|
-
* @param newLimitPice: The new limit price for the order
|
|
3913
|
-
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
3914
|
-
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3915
|
-
* @param auctionDuration: Only required if order type changed to market from something else
|
|
3916
|
-
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
3917
|
-
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
3918
|
-
* @param reduceOnly:
|
|
3919
|
-
* @param postOnly:
|
|
3920
|
-
* @param immediateOrCancel:
|
|
3921
|
-
* @param
|
|
3927
|
+
* @param orderParams.userOrderId: The open order to modify
|
|
3928
|
+
* @param orderParams.newDirection: The new direction for the order
|
|
3929
|
+
* @param orderParams.newBaseAmount: The new base amount for the order
|
|
3930
|
+
* @param orderParams.newLimitPice: The new limit price for the order
|
|
3931
|
+
* @param orderParams.newOraclePriceOffset: The new oracle price offset for the order
|
|
3932
|
+
* @param orderParams.newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
3933
|
+
* @param orderParams.auctionDuration: Only required if order type changed to market from something else
|
|
3934
|
+
* @param orderParams.auctionStartPrice: Only required if order type changed to market from something else
|
|
3935
|
+
* @param orderParams.auctionEndPrice: Only required if order type changed to market from something else
|
|
3936
|
+
* @param orderParams.reduceOnly:
|
|
3937
|
+
* @param orderParams.postOnly:
|
|
3938
|
+
* @param orderParams.immediateOrCancel:
|
|
3939
|
+
* @param orderParams.policy:
|
|
3940
|
+
* @param orderParams.maxTs:
|
|
3922
3941
|
* @returns
|
|
3923
3942
|
*/
|
|
3924
|
-
public async modifyOrderByUserOrderId(
|
|
3943
|
+
public async modifyOrderByUserOrderId(
|
|
3944
|
+
orderParams: {
|
|
3945
|
+
userOrderId: number;
|
|
3946
|
+
newDirection?: PositionDirection;
|
|
3947
|
+
newBaseAmount?: BN;
|
|
3948
|
+
newLimitPrice?: BN;
|
|
3949
|
+
newOraclePriceOffset?: number;
|
|
3950
|
+
newTriggerPrice?: BN;
|
|
3951
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
3952
|
+
auctionDuration?: number;
|
|
3953
|
+
auctionStartPrice?: BN;
|
|
3954
|
+
auctionEndPrice?: BN;
|
|
3955
|
+
reduceOnly?: boolean;
|
|
3956
|
+
postOnly?: boolean;
|
|
3957
|
+
immediateOrCancel?: boolean;
|
|
3958
|
+
policy?: ModifyOrderParams;
|
|
3959
|
+
maxTs?: BN;
|
|
3960
|
+
},
|
|
3961
|
+
txParams?: TxParams
|
|
3962
|
+
): Promise<TransactionSignature> {
|
|
3963
|
+
const { txSig } = await this.sendTransaction(
|
|
3964
|
+
await this.buildTransaction(
|
|
3965
|
+
await this.getModifyOrderByUserIdIx(orderParams),
|
|
3966
|
+
txParams
|
|
3967
|
+
),
|
|
3968
|
+
[],
|
|
3969
|
+
this.opts
|
|
3970
|
+
);
|
|
3971
|
+
return txSig;
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3974
|
+
public async getModifyOrderByUserIdIx({
|
|
3925
3975
|
userOrderId,
|
|
3926
3976
|
newDirection,
|
|
3927
3977
|
newBaseAmount,
|
|
@@ -3936,7 +3986,7 @@ export class DriftClient {
|
|
|
3936
3986
|
postOnly,
|
|
3937
3987
|
immediateOrCancel,
|
|
3938
3988
|
maxTs,
|
|
3939
|
-
|
|
3989
|
+
policy,
|
|
3940
3990
|
}: {
|
|
3941
3991
|
userOrderId: number;
|
|
3942
3992
|
newDirection?: PositionDirection;
|
|
@@ -3951,9 +4001,17 @@ export class DriftClient {
|
|
|
3951
4001
|
reduceOnly?: boolean;
|
|
3952
4002
|
postOnly?: boolean;
|
|
3953
4003
|
immediateOrCancel?: boolean;
|
|
4004
|
+
policy?: ModifyOrderParams;
|
|
3954
4005
|
maxTs?: BN;
|
|
3955
4006
|
txParams?: TxParams;
|
|
3956
|
-
}): Promise<
|
|
4007
|
+
}): Promise<TransactionInstruction> {
|
|
4008
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
4009
|
+
|
|
4010
|
+
const remainingAccounts = this.getRemainingAccounts({
|
|
4011
|
+
userAccounts: [this.getUserAccount()],
|
|
4012
|
+
useMarketLastSlotCache: true,
|
|
4013
|
+
});
|
|
4014
|
+
|
|
3957
4015
|
const orderParams: ModifyOrderParams = {
|
|
3958
4016
|
baseAssetAmount: newBaseAmount || null,
|
|
3959
4017
|
direction: newDirection || null,
|
|
@@ -3967,31 +4025,10 @@ export class DriftClient {
|
|
|
3967
4025
|
reduceOnly: reduceOnly || null,
|
|
3968
4026
|
postOnly: postOnly || null,
|
|
3969
4027
|
immediateOrCancel: immediateOrCancel || null,
|
|
4028
|
+
policy: policy || null,
|
|
3970
4029
|
maxTs: maxTs || null,
|
|
3971
4030
|
};
|
|
3972
4031
|
|
|
3973
|
-
const { txSig } = await this.sendTransaction(
|
|
3974
|
-
await this.buildTransaction(
|
|
3975
|
-
await this.getModifyOrderByUserIdIx(userOrderId, orderParams),
|
|
3976
|
-
txParams
|
|
3977
|
-
),
|
|
3978
|
-
[],
|
|
3979
|
-
this.opts
|
|
3980
|
-
);
|
|
3981
|
-
return txSig;
|
|
3982
|
-
}
|
|
3983
|
-
|
|
3984
|
-
public async getModifyOrderByUserIdIx(
|
|
3985
|
-
userOrderId: number,
|
|
3986
|
-
orderParams: ModifyOrderParams
|
|
3987
|
-
): Promise<TransactionInstruction> {
|
|
3988
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
3989
|
-
|
|
3990
|
-
const remainingAccounts = this.getRemainingAccounts({
|
|
3991
|
-
userAccounts: [this.getUserAccount()],
|
|
3992
|
-
useMarketLastSlotCache: true,
|
|
3993
|
-
});
|
|
3994
|
-
|
|
3995
4032
|
return await this.program.instruction.modifyOrderByUserId(
|
|
3996
4033
|
userOrderId,
|
|
3997
4034
|
orderParams,
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.29.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -4736,7 +4736,7 @@
|
|
|
4736
4736
|
"name": "orderTickSize",
|
|
4737
4737
|
"docs": [
|
|
4738
4738
|
"Spot orders must be a multiple of the tick size",
|
|
4739
|
-
"precision:
|
|
4739
|
+
"precision: PRICE_PRECISION"
|
|
4740
4740
|
],
|
|
4741
4741
|
"type": "u64"
|
|
4742
4742
|
},
|
|
@@ -5565,6 +5565,14 @@
|
|
|
5565
5565
|
"type": {
|
|
5566
5566
|
"option": "i64"
|
|
5567
5567
|
}
|
|
5568
|
+
},
|
|
5569
|
+
{
|
|
5570
|
+
"name": "policy",
|
|
5571
|
+
"type": {
|
|
5572
|
+
"option": {
|
|
5573
|
+
"defined": "ModifyOrderPolicy"
|
|
5574
|
+
}
|
|
5575
|
+
}
|
|
5568
5576
|
}
|
|
5569
5577
|
]
|
|
5570
5578
|
}
|
|
@@ -7237,6 +7245,20 @@
|
|
|
7237
7245
|
]
|
|
7238
7246
|
}
|
|
7239
7247
|
},
|
|
7248
|
+
{
|
|
7249
|
+
"name": "ModifyOrderPolicy",
|
|
7250
|
+
"type": {
|
|
7251
|
+
"kind": "enum",
|
|
7252
|
+
"variants": [
|
|
7253
|
+
{
|
|
7254
|
+
"name": "TryModify"
|
|
7255
|
+
},
|
|
7256
|
+
{
|
|
7257
|
+
"name": "MustModify"
|
|
7258
|
+
}
|
|
7259
|
+
]
|
|
7260
|
+
}
|
|
7261
|
+
},
|
|
7240
7262
|
{
|
|
7241
7263
|
"name": "TwapPeriod",
|
|
7242
7264
|
"type": {
|
|
@@ -10067,4 +10089,4 @@
|
|
|
10067
10089
|
"msg": "InvalidPhoenixMarket"
|
|
10068
10090
|
}
|
|
10069
10091
|
]
|
|
10070
|
-
}
|
|
10092
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -391,8 +391,8 @@ export class LiquidationType {
|
|
|
391
391
|
static readonly PERP_BANKRUPTCY = {
|
|
392
392
|
perpBankruptcy: {},
|
|
393
393
|
};
|
|
394
|
-
static readonly
|
|
395
|
-
|
|
394
|
+
static readonly SPOT_BANKRUPTCY = {
|
|
395
|
+
spotBankruptcy: {},
|
|
396
396
|
};
|
|
397
397
|
static readonly LIQUIDATE_SPOT = {
|
|
398
398
|
liquidateSpot: {},
|
|
@@ -883,7 +883,12 @@ export type OptionalOrderParams = {
|
|
|
883
883
|
|
|
884
884
|
export type ModifyOrderParams = {
|
|
885
885
|
[Property in keyof OrderParams]?: OrderParams[Property] | null;
|
|
886
|
-
};
|
|
886
|
+
} & { policy?: ModifyOrderPolicy };
|
|
887
|
+
|
|
888
|
+
export class ModifyOrderPolicy {
|
|
889
|
+
static readonly MUST_MODIFY = { mustModify: {} };
|
|
890
|
+
static readonly TRY_MODIFY = { tryModify: {} };
|
|
891
|
+
}
|
|
887
892
|
|
|
888
893
|
export const DefaultOrderParams: OrderParams = {
|
|
889
894
|
orderType: OrderType.MARKET,
|
package/src/assert/assert.js
DELETED
package/src/token/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTokenAccount = void 0;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
function parseTokenAccount(data) {
|
|
7
|
-
const accountInfo = spl_token_1.AccountLayout.decode(data);
|
|
8
|
-
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
|
|
9
|
-
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
|
|
10
|
-
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
|
|
11
|
-
if (accountInfo.delegateOption === 0) {
|
|
12
|
-
accountInfo.delegate = null;
|
|
13
|
-
// eslint-disable-next-line new-cap
|
|
14
|
-
accountInfo.delegatedAmount = new spl_token_1.u64(0);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
|
|
18
|
-
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
|
|
19
|
-
}
|
|
20
|
-
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
21
|
-
accountInfo.isFrozen = accountInfo.state === 2;
|
|
22
|
-
if (accountInfo.isNativeOption === 1) {
|
|
23
|
-
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
|
|
24
|
-
accountInfo.isNative = true;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
accountInfo.rentExemptReserve = null;
|
|
28
|
-
accountInfo.isNative = false;
|
|
29
|
-
}
|
|
30
|
-
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
-
accountInfo.closeAuthority = null;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
|
|
35
|
-
}
|
|
36
|
-
return accountInfo;
|
|
37
|
-
}
|
|
38
|
-
exports.parseTokenAccount = parseTokenAccount;
|
package/src/util/computeUnits.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.findComputeUnitConsumption = void 0;
|
|
13
|
-
function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const tx = yield connection.getTransaction(txSignature, { commitment });
|
|
16
|
-
const computeUnits = [];
|
|
17
|
-
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
|
|
18
|
-
tx.meta.logMessages.forEach((logMessage) => {
|
|
19
|
-
const match = logMessage.match(regex);
|
|
20
|
-
if (match && match[1]) {
|
|
21
|
-
computeUnits.push(match[1]);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return computeUnits;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.findComputeUnitConsumption = findComputeUnitConsumption;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTokenAddress = void 0;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
const getTokenAddress = (mintAddress, userPubKey) => {
|
|
7
|
-
return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
|
|
8
|
-
};
|
|
9
|
-
exports.getTokenAddress = getTokenAddress;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promiseTimeout = void 0;
|
|
4
|
-
function promiseTimeout(promise, timeoutMs) {
|
|
5
|
-
let timeoutId;
|
|
6
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
7
|
-
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
8
|
-
});
|
|
9
|
-
return Promise.race([promise, timeoutPromise]).then((result) => {
|
|
10
|
-
clearTimeout(timeoutId);
|
|
11
|
-
return result;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
exports.promiseTimeout = promiseTimeout;
|
package/src/util/tps.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.estimateTps = void 0;
|
|
13
|
-
function estimateTps(programId, connection, failed) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
|
|
16
|
-
if (failed) {
|
|
17
|
-
signatures = signatures.filter((signature) => signature.err);
|
|
18
|
-
}
|
|
19
|
-
const numberOfSignatures = signatures.length;
|
|
20
|
-
if (numberOfSignatures === 0) {
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
return (numberOfSignatures /
|
|
24
|
-
(signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.estimateTps = estimateTps;
|