@drift-labs/sdk 2.49.0-beta.1 → 2.49.0-beta.10
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/accounts/{mockUserAccountSubscriber.d.ts → basicUserAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{mockUserAccountSubscriber.js → basicUserAccountSubscriber.js} +9 -6
- package/lib/accounts/pollingInsuranceFundStakeAccountSubscriber.d.ts +29 -0
- package/lib/accounts/pollingInsuranceFundStakeAccountSubscriber.js +110 -0
- package/lib/accounts/types.d.ts +14 -1
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +23 -0
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +65 -0
- package/lib/dlob/DLOB.d.ts +6 -2
- package/lib/dlob/DLOB.js +37 -12
- package/lib/driftClient.d.ts +66 -66
- package/lib/driftClient.js +208 -194
- package/lib/events/eventSubscriber.js +2 -1
- package/lib/events/sort.d.ts +2 -2
- package/lib/events/sort.js +6 -23
- package/lib/examples/loadDlob.js +10 -5
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/orderSubscriber/OrderSubscriber.js +4 -0
- package/lib/orderSubscriber/WebsocketSubscription.d.ts +1 -1
- package/lib/orderSubscriber/WebsocketSubscription.js +8 -6
- package/lib/types.d.ts +0 -2
- package/lib/userMap/PollingSubscription.d.ts +15 -0
- package/lib/userMap/PollingSubscription.js +26 -0
- package/lib/userMap/WebsocketSubscription.d.ts +19 -0
- package/lib/userMap/WebsocketSubscription.js +40 -0
- package/lib/userMap/userMap.d.ts +15 -18
- package/lib/userMap/userMap.js +62 -31
- package/lib/userMap/userMapConfig.d.ts +20 -0
- package/lib/userMap/userMapConfig.js +2 -0
- package/package.json +1 -1
- package/src/accounts/{mockUserAccountSubscriber.ts → basicUserAccountSubscriber.ts} +8 -6
- package/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +185 -0
- package/src/accounts/types.ts +21 -0
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +127 -0
- package/src/dlob/DLOB.ts +55 -15
- package/src/driftClient.ts +429 -272
- package/src/events/eventSubscriber.ts +2 -1
- package/src/events/sort.ts +7 -29
- package/src/examples/loadDlob.ts +11 -6
- package/src/index.ts +3 -1
- package/src/orderSubscriber/OrderSubscriber.ts +4 -0
- package/src/orderSubscriber/WebsocketSubscription.ts +19 -16
- package/src/types.ts +0 -2
- package/src/userMap/PollingSubscription.ts +46 -0
- package/src/userMap/WebsocketSubscription.ts +74 -0
- package/src/userMap/userMap.ts +88 -60
- package/src/userMap/userMapConfig.ts +31 -0
- package/tests/amm/test.ts +6 -3
- package/tests/dlob/helpers.ts +2 -6
- package/tests/dlob/test.ts +194 -0
package/src/driftClient.ts
CHANGED
|
@@ -710,7 +710,7 @@ export class DriftClient {
|
|
|
710
710
|
|
|
711
711
|
public async initializeUserAccount(
|
|
712
712
|
subAccountId = 0,
|
|
713
|
-
name
|
|
713
|
+
name?: string,
|
|
714
714
|
referrerInfo?: ReferrerInfo
|
|
715
715
|
): Promise<[TransactionSignature, PublicKey]> {
|
|
716
716
|
const initializeIxs = [];
|
|
@@ -729,6 +729,7 @@ export class DriftClient {
|
|
|
729
729
|
initializeIxs.push(await this.getInitializeUserStatsIx());
|
|
730
730
|
}
|
|
731
731
|
}
|
|
732
|
+
|
|
732
733
|
initializeIxs.push(initializeUserAccountIx);
|
|
733
734
|
const tx = await this.buildTransaction(initializeIxs);
|
|
734
735
|
|
|
@@ -741,7 +742,7 @@ export class DriftClient {
|
|
|
741
742
|
|
|
742
743
|
async getInitializeUserInstructions(
|
|
743
744
|
subAccountId = 0,
|
|
744
|
-
name
|
|
745
|
+
name?: string,
|
|
745
746
|
referrerInfo?: ReferrerInfo
|
|
746
747
|
): Promise<[PublicKey, TransactionInstruction]> {
|
|
747
748
|
const userAccountPublicKey = await getUserAccountPublicKey(
|
|
@@ -777,6 +778,14 @@ export class DriftClient {
|
|
|
777
778
|
});
|
|
778
779
|
}
|
|
779
780
|
|
|
781
|
+
if (name === undefined) {
|
|
782
|
+
if (subAccountId === 0) {
|
|
783
|
+
name = DEFAULT_USER_NAME;
|
|
784
|
+
} else {
|
|
785
|
+
name = `Subaccount ${subAccountId + 1}`;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
780
789
|
const nameBuffer = encodeName(name);
|
|
781
790
|
const initializeUserAccountIx =
|
|
782
791
|
await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
@@ -1229,8 +1238,11 @@ export class DriftClient {
|
|
|
1229
1238
|
return this.getUser(subAccountId).getUserAccountAndSlot();
|
|
1230
1239
|
}
|
|
1231
1240
|
|
|
1232
|
-
public getSpotPosition(
|
|
1233
|
-
|
|
1241
|
+
public getSpotPosition(
|
|
1242
|
+
marketIndex: number,
|
|
1243
|
+
subAccountId?: number
|
|
1244
|
+
): SpotPosition | undefined {
|
|
1245
|
+
return this.getUserAccount(subAccountId).spotPositions.find(
|
|
1234
1246
|
(spotPosition) => spotPosition.marketIndex === marketIndex
|
|
1235
1247
|
);
|
|
1236
1248
|
}
|
|
@@ -1531,14 +1543,17 @@ export class DriftClient {
|
|
|
1531
1543
|
};
|
|
1532
1544
|
}
|
|
1533
1545
|
|
|
1534
|
-
public getOrder(orderId: number): Order | undefined {
|
|
1535
|
-
return this.getUserAccount()?.orders.find(
|
|
1546
|
+
public getOrder(orderId: number, subAccountId?: number): Order | undefined {
|
|
1547
|
+
return this.getUserAccount(subAccountId)?.orders.find(
|
|
1536
1548
|
(order) => order.orderId === orderId
|
|
1537
1549
|
);
|
|
1538
1550
|
}
|
|
1539
1551
|
|
|
1540
|
-
public getOrderByUserId(
|
|
1541
|
-
|
|
1552
|
+
public getOrderByUserId(
|
|
1553
|
+
userOrderId: number,
|
|
1554
|
+
subAccountId?: number
|
|
1555
|
+
): Order | undefined {
|
|
1556
|
+
return this.getUserAccount(subAccountId)?.orders.find(
|
|
1542
1557
|
(order) => order.userOrderId === userOrderId
|
|
1543
1558
|
);
|
|
1544
1559
|
}
|
|
@@ -1587,11 +1602,11 @@ export class DriftClient {
|
|
|
1587
1602
|
/**
|
|
1588
1603
|
* Deposit funds into the given spot market
|
|
1589
1604
|
*
|
|
1590
|
-
* @param amount
|
|
1591
|
-
* @param marketIndex
|
|
1605
|
+
* @param amount to deposit
|
|
1606
|
+
* @param marketIndex spot market index to deposit into
|
|
1592
1607
|
* @param associatedTokenAccount can be the wallet public key if using native sol
|
|
1593
|
-
* @param subAccountId
|
|
1594
|
-
* @param reduceOnly
|
|
1608
|
+
* @param subAccountId subaccountId to deposit
|
|
1609
|
+
* @param reduceOnly if true, deposit must not increase account risk
|
|
1595
1610
|
*/
|
|
1596
1611
|
public async deposit(
|
|
1597
1612
|
amount: BN,
|
|
@@ -1803,7 +1818,7 @@ export class DriftClient {
|
|
|
1803
1818
|
userTokenAccount: PublicKey,
|
|
1804
1819
|
marketIndex = 0,
|
|
1805
1820
|
subAccountId = 0,
|
|
1806
|
-
name
|
|
1821
|
+
name?: string,
|
|
1807
1822
|
fromSubAccountId?: number,
|
|
1808
1823
|
referrerInfo?: ReferrerInfo,
|
|
1809
1824
|
txParams?: TxParams
|
|
@@ -1967,7 +1982,8 @@ export class DriftClient {
|
|
|
1967
1982
|
amount: BN,
|
|
1968
1983
|
marketIndex: number,
|
|
1969
1984
|
associatedTokenAddress: PublicKey,
|
|
1970
|
-
reduceOnly = false
|
|
1985
|
+
reduceOnly = false,
|
|
1986
|
+
subAccountId?: number
|
|
1971
1987
|
): Promise<TransactionSignature> {
|
|
1972
1988
|
const withdrawIxs = [];
|
|
1973
1989
|
|
|
@@ -2011,7 +2027,8 @@ export class DriftClient {
|
|
|
2011
2027
|
amount,
|
|
2012
2028
|
spotMarketAccount.marketIndex,
|
|
2013
2029
|
associatedTokenAddress,
|
|
2014
|
-
reduceOnly
|
|
2030
|
+
reduceOnly,
|
|
2031
|
+
subAccountId
|
|
2015
2032
|
);
|
|
2016
2033
|
|
|
2017
2034
|
withdrawIxs.push(withdrawCollateralIx);
|
|
@@ -2044,12 +2061,13 @@ export class DriftClient {
|
|
|
2044
2061
|
amount: BN,
|
|
2045
2062
|
marketIndex: number,
|
|
2046
2063
|
userTokenAccount: PublicKey,
|
|
2047
|
-
reduceOnly = false
|
|
2064
|
+
reduceOnly = false,
|
|
2065
|
+
subAccountId?: number
|
|
2048
2066
|
): Promise<TransactionInstruction> {
|
|
2049
|
-
const
|
|
2067
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2050
2068
|
|
|
2051
2069
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2052
|
-
userAccounts: [this.getUserAccount()],
|
|
2070
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2053
2071
|
useMarketLastSlotCache: true,
|
|
2054
2072
|
writableSpotMarketIndexes: [marketIndex],
|
|
2055
2073
|
readableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
@@ -2067,7 +2085,7 @@ export class DriftClient {
|
|
|
2067
2085
|
spotMarket: spotMarketAccount.pubkey,
|
|
2068
2086
|
spotMarketVault: spotMarketAccount.vault,
|
|
2069
2087
|
driftSigner: this.getSignerPublicKey(),
|
|
2070
|
-
user
|
|
2088
|
+
user,
|
|
2071
2089
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2072
2090
|
userTokenAccount: userTokenAccount,
|
|
2073
2091
|
authority: this.wallet.publicKey,
|
|
@@ -2244,11 +2262,16 @@ export class DriftClient {
|
|
|
2244
2262
|
public async removePerpLpShares(
|
|
2245
2263
|
marketIndex: number,
|
|
2246
2264
|
sharesToBurn?: BN,
|
|
2247
|
-
txParams?: TxParams
|
|
2265
|
+
txParams?: TxParams,
|
|
2266
|
+
subAccountId?: number
|
|
2248
2267
|
): Promise<TransactionSignature> {
|
|
2249
2268
|
const { txSig } = await this.sendTransaction(
|
|
2250
2269
|
await this.buildTransaction(
|
|
2251
|
-
await this.getRemovePerpLpSharesIx(
|
|
2270
|
+
await this.getRemovePerpLpSharesIx(
|
|
2271
|
+
marketIndex,
|
|
2272
|
+
sharesToBurn,
|
|
2273
|
+
subAccountId
|
|
2274
|
+
),
|
|
2252
2275
|
txParams
|
|
2253
2276
|
),
|
|
2254
2277
|
[],
|
|
@@ -2316,18 +2339,19 @@ export class DriftClient {
|
|
|
2316
2339
|
|
|
2317
2340
|
public async getRemovePerpLpSharesIx(
|
|
2318
2341
|
marketIndex: number,
|
|
2319
|
-
sharesToBurn?: BN
|
|
2342
|
+
sharesToBurn?: BN,
|
|
2343
|
+
subAccountId?: number
|
|
2320
2344
|
): Promise<TransactionInstruction> {
|
|
2321
|
-
const
|
|
2345
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2322
2346
|
|
|
2323
2347
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2324
|
-
userAccounts: [this.getUserAccount()],
|
|
2348
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2325
2349
|
useMarketLastSlotCache: true,
|
|
2326
2350
|
writablePerpMarketIndexes: [marketIndex],
|
|
2327
2351
|
});
|
|
2328
2352
|
|
|
2329
2353
|
if (sharesToBurn == undefined) {
|
|
2330
|
-
const userAccount = this.getUserAccount();
|
|
2354
|
+
const userAccount = this.getUserAccount(subAccountId);
|
|
2331
2355
|
const perpPosition = userAccount.perpPositions.filter(
|
|
2332
2356
|
(position) => position.marketIndex === marketIndex
|
|
2333
2357
|
)[0];
|
|
@@ -2341,7 +2365,7 @@ export class DriftClient {
|
|
|
2341
2365
|
{
|
|
2342
2366
|
accounts: {
|
|
2343
2367
|
state: await this.getStatePublicKey(),
|
|
2344
|
-
user
|
|
2368
|
+
user,
|
|
2345
2369
|
authority: this.wallet.publicKey,
|
|
2346
2370
|
},
|
|
2347
2371
|
remainingAccounts: remainingAccounts,
|
|
@@ -2352,11 +2376,12 @@ export class DriftClient {
|
|
|
2352
2376
|
public async addPerpLpShares(
|
|
2353
2377
|
amount: BN,
|
|
2354
2378
|
marketIndex: number,
|
|
2355
|
-
txParams?: TxParams
|
|
2379
|
+
txParams?: TxParams,
|
|
2380
|
+
subAccountId?: number
|
|
2356
2381
|
): Promise<TransactionSignature> {
|
|
2357
2382
|
const { txSig, slot } = await this.sendTransaction(
|
|
2358
2383
|
await this.buildTransaction(
|
|
2359
|
-
await this.getAddPerpLpSharesIx(amount, marketIndex),
|
|
2384
|
+
await this.getAddPerpLpSharesIx(amount, marketIndex, subAccountId),
|
|
2360
2385
|
txParams
|
|
2361
2386
|
),
|
|
2362
2387
|
[],
|
|
@@ -2368,11 +2393,12 @@ export class DriftClient {
|
|
|
2368
2393
|
|
|
2369
2394
|
public async getAddPerpLpSharesIx(
|
|
2370
2395
|
amount: BN,
|
|
2371
|
-
marketIndex: number
|
|
2396
|
+
marketIndex: number,
|
|
2397
|
+
subAccountId?: number
|
|
2372
2398
|
): Promise<TransactionInstruction> {
|
|
2373
|
-
const
|
|
2399
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2374
2400
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2375
|
-
userAccounts: [this.getUserAccount()],
|
|
2401
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2376
2402
|
useMarketLastSlotCache: true,
|
|
2377
2403
|
writablePerpMarketIndexes: [marketIndex],
|
|
2378
2404
|
});
|
|
@@ -2380,7 +2406,7 @@ export class DriftClient {
|
|
|
2380
2406
|
return this.program.instruction.addPerpLpShares(amount, marketIndex, {
|
|
2381
2407
|
accounts: {
|
|
2382
2408
|
state: await this.getStatePublicKey(),
|
|
2383
|
-
user
|
|
2409
|
+
user,
|
|
2384
2410
|
authority: this.wallet.publicKey,
|
|
2385
2411
|
},
|
|
2386
2412
|
remainingAccounts: remainingAccounts,
|
|
@@ -2423,15 +2449,22 @@ export class DriftClient {
|
|
|
2423
2449
|
direction: PositionDirection,
|
|
2424
2450
|
amount: BN,
|
|
2425
2451
|
marketIndex: number,
|
|
2426
|
-
limitPrice?: BN
|
|
2452
|
+
limitPrice?: BN,
|
|
2453
|
+
subAccountId?: number
|
|
2427
2454
|
): Promise<TransactionSignature> {
|
|
2428
|
-
return await this.placeAndTakePerpOrder(
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2455
|
+
return await this.placeAndTakePerpOrder(
|
|
2456
|
+
{
|
|
2457
|
+
orderType: OrderType.MARKET,
|
|
2458
|
+
marketIndex,
|
|
2459
|
+
direction,
|
|
2460
|
+
baseAssetAmount: amount,
|
|
2461
|
+
price: limitPrice,
|
|
2462
|
+
},
|
|
2463
|
+
undefined,
|
|
2464
|
+
undefined,
|
|
2465
|
+
undefined,
|
|
2466
|
+
subAccountId
|
|
2467
|
+
);
|
|
2435
2468
|
}
|
|
2436
2469
|
|
|
2437
2470
|
public async sendSignedTx(tx: Transaction): Promise<TransactionSignature> {
|
|
@@ -2474,11 +2507,15 @@ export class DriftClient {
|
|
|
2474
2507
|
const orderId = userAccount.nextOrderId;
|
|
2475
2508
|
const bracketOrderIxs = [];
|
|
2476
2509
|
|
|
2477
|
-
const placePerpOrderIx = await this.getPlacePerpOrderIx(
|
|
2510
|
+
const placePerpOrderIx = await this.getPlacePerpOrderIx(
|
|
2511
|
+
orderParams,
|
|
2512
|
+
userAccount.subAccountId
|
|
2513
|
+
);
|
|
2478
2514
|
|
|
2479
2515
|
for (const bracketOrderParams of bracketOrdersParams) {
|
|
2480
2516
|
const placeBracketOrderIx = await this.getPlacePerpOrderIx(
|
|
2481
|
-
bracketOrderParams
|
|
2517
|
+
bracketOrderParams,
|
|
2518
|
+
userAccount.subAccountId
|
|
2482
2519
|
);
|
|
2483
2520
|
bracketOrderIxs.push(placeBracketOrderIx);
|
|
2484
2521
|
}
|
|
@@ -2489,7 +2526,8 @@ export class DriftClient {
|
|
|
2489
2526
|
cancelOrdersIx = await this.getCancelOrdersIx(
|
|
2490
2527
|
orderParams.marketType,
|
|
2491
2528
|
orderParams.marketIndex,
|
|
2492
|
-
null
|
|
2529
|
+
null,
|
|
2530
|
+
userAccount.subAccountId
|
|
2493
2531
|
);
|
|
2494
2532
|
|
|
2495
2533
|
//@ts-ignore
|
|
@@ -2516,7 +2554,8 @@ export class DriftClient {
|
|
|
2516
2554
|
marketIndex,
|
|
2517
2555
|
},
|
|
2518
2556
|
makerInfo,
|
|
2519
|
-
referrerInfo
|
|
2557
|
+
referrerInfo,
|
|
2558
|
+
userAccount.subAccountId
|
|
2520
2559
|
);
|
|
2521
2560
|
|
|
2522
2561
|
const versionedFillTx = await this.buildTransaction(
|
|
@@ -2593,11 +2632,12 @@ export class DriftClient {
|
|
|
2593
2632
|
|
|
2594
2633
|
public async placePerpOrder(
|
|
2595
2634
|
orderParams: OptionalOrderParams,
|
|
2596
|
-
txParams?: TxParams
|
|
2635
|
+
txParams?: TxParams,
|
|
2636
|
+
subAccountId?: number
|
|
2597
2637
|
): Promise<TransactionSignature> {
|
|
2598
2638
|
const { txSig, slot } = await this.sendTransaction(
|
|
2599
2639
|
await this.buildTransaction(
|
|
2600
|
-
await this.getPlacePerpOrderIx(orderParams),
|
|
2640
|
+
await this.getPlacePerpOrderIx(orderParams, subAccountId),
|
|
2601
2641
|
txParams
|
|
2602
2642
|
),
|
|
2603
2643
|
[],
|
|
@@ -2608,13 +2648,14 @@ export class DriftClient {
|
|
|
2608
2648
|
}
|
|
2609
2649
|
|
|
2610
2650
|
public async getPlacePerpOrderIx(
|
|
2611
|
-
orderParams: OptionalOrderParams
|
|
2651
|
+
orderParams: OptionalOrderParams,
|
|
2652
|
+
subAccountId?: number
|
|
2612
2653
|
): Promise<TransactionInstruction> {
|
|
2613
2654
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
2614
|
-
const
|
|
2655
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2615
2656
|
|
|
2616
2657
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2617
|
-
userAccounts: [this.getUserAccount()],
|
|
2658
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2618
2659
|
useMarketLastSlotCache: true,
|
|
2619
2660
|
readablePerpMarketIndex: orderParams.marketIndex,
|
|
2620
2661
|
});
|
|
@@ -2622,7 +2663,7 @@ export class DriftClient {
|
|
|
2622
2663
|
return await this.program.instruction.placePerpOrder(orderParams, {
|
|
2623
2664
|
accounts: {
|
|
2624
2665
|
state: await this.getStatePublicKey(),
|
|
2625
|
-
user
|
|
2666
|
+
user,
|
|
2626
2667
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2627
2668
|
authority: this.wallet.publicKey,
|
|
2628
2669
|
},
|
|
@@ -2766,11 +2807,12 @@ export class DriftClient {
|
|
|
2766
2807
|
|
|
2767
2808
|
public async cancelOrder(
|
|
2768
2809
|
orderId?: number,
|
|
2769
|
-
txParams?: TxParams
|
|
2810
|
+
txParams?: TxParams,
|
|
2811
|
+
subAccountId?: number
|
|
2770
2812
|
): Promise<TransactionSignature> {
|
|
2771
2813
|
const { txSig } = await this.sendTransaction(
|
|
2772
2814
|
await this.buildTransaction(
|
|
2773
|
-
await this.getCancelOrderIx(orderId),
|
|
2815
|
+
await this.getCancelOrderIx(orderId, subAccountId),
|
|
2774
2816
|
txParams
|
|
2775
2817
|
),
|
|
2776
2818
|
[],
|
|
@@ -2780,19 +2822,20 @@ export class DriftClient {
|
|
|
2780
2822
|
}
|
|
2781
2823
|
|
|
2782
2824
|
public async getCancelOrderIx(
|
|
2783
|
-
orderId?: number
|
|
2825
|
+
orderId?: number,
|
|
2826
|
+
subAccountId?: number
|
|
2784
2827
|
): Promise<TransactionInstruction> {
|
|
2785
|
-
const
|
|
2828
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2786
2829
|
|
|
2787
2830
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2788
|
-
userAccounts: [this.getUserAccount()],
|
|
2831
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2789
2832
|
useMarketLastSlotCache: true,
|
|
2790
2833
|
});
|
|
2791
2834
|
|
|
2792
2835
|
return await this.program.instruction.cancelOrder(orderId ?? null, {
|
|
2793
2836
|
accounts: {
|
|
2794
2837
|
state: await this.getStatePublicKey(),
|
|
2795
|
-
user
|
|
2838
|
+
user,
|
|
2796
2839
|
authority: this.wallet.publicKey,
|
|
2797
2840
|
},
|
|
2798
2841
|
remainingAccounts,
|
|
@@ -2801,11 +2844,12 @@ export class DriftClient {
|
|
|
2801
2844
|
|
|
2802
2845
|
public async cancelOrderByUserId(
|
|
2803
2846
|
userOrderId: number,
|
|
2804
|
-
txParams?: TxParams
|
|
2847
|
+
txParams?: TxParams,
|
|
2848
|
+
subAccountId?: number
|
|
2805
2849
|
): Promise<TransactionSignature> {
|
|
2806
2850
|
const { txSig } = await this.sendTransaction(
|
|
2807
2851
|
await this.buildTransaction(
|
|
2808
|
-
await this.getCancelOrderByUserIdIx(userOrderId),
|
|
2852
|
+
await this.getCancelOrderByUserIdIx(userOrderId, subAccountId),
|
|
2809
2853
|
txParams
|
|
2810
2854
|
),
|
|
2811
2855
|
[],
|
|
@@ -2815,22 +2859,23 @@ export class DriftClient {
|
|
|
2815
2859
|
}
|
|
2816
2860
|
|
|
2817
2861
|
public async getCancelOrderByUserIdIx(
|
|
2818
|
-
userOrderId: number
|
|
2862
|
+
userOrderId: number,
|
|
2863
|
+
subAccountId?: number
|
|
2819
2864
|
): Promise<TransactionInstruction> {
|
|
2820
|
-
const
|
|
2865
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2821
2866
|
|
|
2822
2867
|
const order = this.getOrderByUserId(userOrderId);
|
|
2823
2868
|
const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle;
|
|
2824
2869
|
|
|
2825
2870
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2826
|
-
userAccounts: [this.getUserAccount()],
|
|
2871
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2827
2872
|
useMarketLastSlotCache: true,
|
|
2828
2873
|
});
|
|
2829
2874
|
|
|
2830
2875
|
return await this.program.instruction.cancelOrderByUserId(userOrderId, {
|
|
2831
2876
|
accounts: {
|
|
2832
2877
|
state: await this.getStatePublicKey(),
|
|
2833
|
-
user
|
|
2878
|
+
user,
|
|
2834
2879
|
authority: this.wallet.publicKey,
|
|
2835
2880
|
oracle,
|
|
2836
2881
|
},
|
|
@@ -2840,11 +2885,12 @@ export class DriftClient {
|
|
|
2840
2885
|
|
|
2841
2886
|
public async cancelOrdersByIds(
|
|
2842
2887
|
orderIds?: number[],
|
|
2843
|
-
txParams?: TxParams
|
|
2888
|
+
txParams?: TxParams,
|
|
2889
|
+
subAccountId?: number
|
|
2844
2890
|
): Promise<TransactionSignature> {
|
|
2845
2891
|
const { txSig } = await this.sendTransaction(
|
|
2846
2892
|
await this.buildTransaction(
|
|
2847
|
-
await this.getCancelOrdersByIdsIx(orderIds),
|
|
2893
|
+
await this.getCancelOrdersByIdsIx(orderIds, subAccountId),
|
|
2848
2894
|
txParams
|
|
2849
2895
|
),
|
|
2850
2896
|
[],
|
|
@@ -2854,19 +2900,20 @@ export class DriftClient {
|
|
|
2854
2900
|
}
|
|
2855
2901
|
|
|
2856
2902
|
public async getCancelOrdersByIdsIx(
|
|
2857
|
-
orderIds?: number[]
|
|
2903
|
+
orderIds?: number[],
|
|
2904
|
+
subAccountId?: number
|
|
2858
2905
|
): Promise<TransactionInstruction> {
|
|
2859
|
-
const
|
|
2906
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2860
2907
|
|
|
2861
2908
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2862
|
-
userAccounts: [this.getUserAccount()],
|
|
2909
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2863
2910
|
useMarketLastSlotCache: true,
|
|
2864
2911
|
});
|
|
2865
2912
|
|
|
2866
2913
|
return await this.program.instruction.cancelOrdersByIds(orderIds, {
|
|
2867
2914
|
accounts: {
|
|
2868
2915
|
state: await this.getStatePublicKey(),
|
|
2869
|
-
user
|
|
2916
|
+
user,
|
|
2870
2917
|
authority: this.wallet.publicKey,
|
|
2871
2918
|
},
|
|
2872
2919
|
remainingAccounts,
|
|
@@ -2877,11 +2924,17 @@ export class DriftClient {
|
|
|
2877
2924
|
marketType?: MarketType,
|
|
2878
2925
|
marketIndex?: number,
|
|
2879
2926
|
direction?: PositionDirection,
|
|
2880
|
-
txParams?: TxParams
|
|
2927
|
+
txParams?: TxParams,
|
|
2928
|
+
subAccountId?: number
|
|
2881
2929
|
): Promise<TransactionSignature> {
|
|
2882
2930
|
const { txSig } = await this.sendTransaction(
|
|
2883
2931
|
await this.buildTransaction(
|
|
2884
|
-
await this.getCancelOrdersIx(
|
|
2932
|
+
await this.getCancelOrdersIx(
|
|
2933
|
+
marketType,
|
|
2934
|
+
marketIndex,
|
|
2935
|
+
direction,
|
|
2936
|
+
subAccountId
|
|
2937
|
+
),
|
|
2885
2938
|
txParams
|
|
2886
2939
|
),
|
|
2887
2940
|
[],
|
|
@@ -2893,9 +2946,10 @@ export class DriftClient {
|
|
|
2893
2946
|
public async getCancelOrdersIx(
|
|
2894
2947
|
marketType: MarketType | null,
|
|
2895
2948
|
marketIndex: number | null,
|
|
2896
|
-
direction: PositionDirection | null
|
|
2949
|
+
direction: PositionDirection | null,
|
|
2950
|
+
subAccountId?: number
|
|
2897
2951
|
): Promise<TransactionInstruction> {
|
|
2898
|
-
const
|
|
2952
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2899
2953
|
|
|
2900
2954
|
let readablePerpMarketIndex = undefined;
|
|
2901
2955
|
let readableSpotMarketIndexes = undefined;
|
|
@@ -2909,7 +2963,7 @@ export class DriftClient {
|
|
|
2909
2963
|
}
|
|
2910
2964
|
|
|
2911
2965
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2912
|
-
userAccounts: [this.getUserAccount()],
|
|
2966
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2913
2967
|
readablePerpMarketIndex,
|
|
2914
2968
|
readableSpotMarketIndexes,
|
|
2915
2969
|
useMarketLastSlotCache: true,
|
|
@@ -2922,7 +2976,7 @@ export class DriftClient {
|
|
|
2922
2976
|
{
|
|
2923
2977
|
accounts: {
|
|
2924
2978
|
state: await this.getStatePublicKey(),
|
|
2925
|
-
user
|
|
2979
|
+
user,
|
|
2926
2980
|
authority: this.wallet.publicKey,
|
|
2927
2981
|
},
|
|
2928
2982
|
remainingAccounts,
|
|
@@ -2937,15 +2991,17 @@ export class DriftClient {
|
|
|
2937
2991
|
direction?: PositionDirection;
|
|
2938
2992
|
},
|
|
2939
2993
|
placeOrderParams: OrderParams[],
|
|
2940
|
-
txParams?: TxParams
|
|
2994
|
+
txParams?: TxParams,
|
|
2995
|
+
subAccountId?: number
|
|
2941
2996
|
): Promise<TransactionSignature> {
|
|
2942
2997
|
const ixs = [
|
|
2943
2998
|
await this.getCancelOrdersIx(
|
|
2944
2999
|
cancelOrderParams.marketType,
|
|
2945
3000
|
cancelOrderParams.marketIndex,
|
|
2946
|
-
cancelOrderParams.direction
|
|
3001
|
+
cancelOrderParams.direction,
|
|
3002
|
+
subAccountId
|
|
2947
3003
|
),
|
|
2948
|
-
await this.getPlaceOrdersIx(placeOrderParams),
|
|
3004
|
+
await this.getPlaceOrdersIx(placeOrderParams, subAccountId),
|
|
2949
3005
|
];
|
|
2950
3006
|
const tx = await this.buildTransaction(ixs, txParams);
|
|
2951
3007
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
@@ -2954,11 +3010,12 @@ export class DriftClient {
|
|
|
2954
3010
|
|
|
2955
3011
|
public async placeOrders(
|
|
2956
3012
|
params: OrderParams[],
|
|
2957
|
-
txParams?: TxParams
|
|
3013
|
+
txParams?: TxParams,
|
|
3014
|
+
subAccountId?: number
|
|
2958
3015
|
): Promise<TransactionSignature> {
|
|
2959
3016
|
const { txSig } = await this.sendTransaction(
|
|
2960
3017
|
await this.buildTransaction(
|
|
2961
|
-
await this.getPlaceOrdersIx(params),
|
|
3018
|
+
await this.getPlaceOrdersIx(params, subAccountId),
|
|
2962
3019
|
txParams
|
|
2963
3020
|
),
|
|
2964
3021
|
[],
|
|
@@ -2968,9 +3025,10 @@ export class DriftClient {
|
|
|
2968
3025
|
}
|
|
2969
3026
|
|
|
2970
3027
|
public async getPlaceOrdersIx(
|
|
2971
|
-
params: OrderParams[]
|
|
3028
|
+
params: OrderParams[],
|
|
3029
|
+
subAccountId?: number
|
|
2972
3030
|
): Promise<TransactionInstruction> {
|
|
2973
|
-
const
|
|
3031
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2974
3032
|
|
|
2975
3033
|
const readablePerpMarketIndex: number[] = [];
|
|
2976
3034
|
const readableSpotMarketIndexes: number[] = [];
|
|
@@ -2986,7 +3044,7 @@ export class DriftClient {
|
|
|
2986
3044
|
}
|
|
2987
3045
|
|
|
2988
3046
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2989
|
-
userAccounts: [this.getUserAccount()],
|
|
3047
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2990
3048
|
readablePerpMarketIndex,
|
|
2991
3049
|
readableSpotMarketIndexes,
|
|
2992
3050
|
useMarketLastSlotCache: true,
|
|
@@ -2995,7 +3053,7 @@ export class DriftClient {
|
|
|
2995
3053
|
return await this.program.instruction.placeOrders(params, {
|
|
2996
3054
|
accounts: {
|
|
2997
3055
|
state: await this.getStatePublicKey(),
|
|
2998
|
-
user
|
|
3056
|
+
user,
|
|
2999
3057
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
3000
3058
|
authority: this.wallet.publicKey,
|
|
3001
3059
|
},
|
|
@@ -3009,7 +3067,8 @@ export class DriftClient {
|
|
|
3009
3067
|
order?: Pick<Order, 'marketIndex' | 'orderId'>,
|
|
3010
3068
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
3011
3069
|
referrerInfo?: ReferrerInfo,
|
|
3012
|
-
txParams?: TxParams
|
|
3070
|
+
txParams?: TxParams,
|
|
3071
|
+
fillerPublicKey?: number
|
|
3013
3072
|
): Promise<TransactionSignature> {
|
|
3014
3073
|
const { txSig } = await this.sendTransaction(
|
|
3015
3074
|
await this.buildTransaction(
|
|
@@ -3018,7 +3077,8 @@ export class DriftClient {
|
|
|
3018
3077
|
user,
|
|
3019
3078
|
order,
|
|
3020
3079
|
makerInfo,
|
|
3021
|
-
referrerInfo
|
|
3080
|
+
referrerInfo,
|
|
3081
|
+
fillerPublicKey
|
|
3022
3082
|
),
|
|
3023
3083
|
txParams
|
|
3024
3084
|
),
|
|
@@ -3033,14 +3093,15 @@ export class DriftClient {
|
|
|
3033
3093
|
userAccount: UserAccount,
|
|
3034
3094
|
order: Pick<Order, 'marketIndex' | 'orderId'>,
|
|
3035
3095
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
3036
|
-
referrerInfo?: ReferrerInfo
|
|
3096
|
+
referrerInfo?: ReferrerInfo,
|
|
3097
|
+
fillerSubAccountId?: number
|
|
3037
3098
|
): Promise<TransactionInstruction> {
|
|
3038
3099
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
3039
3100
|
this.program.programId,
|
|
3040
3101
|
userAccount.authority
|
|
3041
3102
|
);
|
|
3042
3103
|
|
|
3043
|
-
const
|
|
3104
|
+
const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
|
|
3044
3105
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3045
3106
|
|
|
3046
3107
|
const marketIndex = order
|
|
@@ -3099,7 +3160,7 @@ export class DriftClient {
|
|
|
3099
3160
|
return await this.program.instruction.fillPerpOrder(orderId, null, {
|
|
3100
3161
|
accounts: {
|
|
3101
3162
|
state: await this.getStatePublicKey(),
|
|
3102
|
-
filler
|
|
3163
|
+
filler,
|
|
3103
3164
|
fillerStats: fillerStatsPublicKey,
|
|
3104
3165
|
user: userAccountPublicKey,
|
|
3105
3166
|
userStats: userStatsPublicKey,
|
|
@@ -3109,14 +3170,16 @@ export class DriftClient {
|
|
|
3109
3170
|
});
|
|
3110
3171
|
}
|
|
3111
3172
|
|
|
3112
|
-
public async getRevertFillIx(
|
|
3113
|
-
|
|
3173
|
+
public async getRevertFillIx(
|
|
3174
|
+
fillerPublicKey?: PublicKey
|
|
3175
|
+
): Promise<TransactionInstruction> {
|
|
3176
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
3114
3177
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3115
3178
|
|
|
3116
3179
|
return this.program.instruction.revertFill({
|
|
3117
3180
|
accounts: {
|
|
3118
3181
|
state: await this.getStatePublicKey(),
|
|
3119
|
-
filler
|
|
3182
|
+
filler,
|
|
3120
3183
|
fillerStats: fillerStatsPublicKey,
|
|
3121
3184
|
authority: this.wallet.publicKey,
|
|
3122
3185
|
},
|
|
@@ -3125,11 +3188,12 @@ export class DriftClient {
|
|
|
3125
3188
|
|
|
3126
3189
|
public async placeSpotOrder(
|
|
3127
3190
|
orderParams: OptionalOrderParams,
|
|
3128
|
-
txParams?: TxParams
|
|
3191
|
+
txParams?: TxParams,
|
|
3192
|
+
subAccountId?: number
|
|
3129
3193
|
): Promise<TransactionSignature> {
|
|
3130
3194
|
const { txSig, slot } = await this.sendTransaction(
|
|
3131
3195
|
await this.buildTransaction(
|
|
3132
|
-
await this.getPlaceSpotOrderIx(orderParams),
|
|
3196
|
+
await this.getPlaceSpotOrderIx(orderParams, subAccountId),
|
|
3133
3197
|
txParams
|
|
3134
3198
|
),
|
|
3135
3199
|
[],
|
|
@@ -3141,13 +3205,16 @@ export class DriftClient {
|
|
|
3141
3205
|
}
|
|
3142
3206
|
|
|
3143
3207
|
public async getPlaceSpotOrderIx(
|
|
3144
|
-
orderParams: OptionalOrderParams
|
|
3208
|
+
orderParams: OptionalOrderParams,
|
|
3209
|
+
subAccountId?: number
|
|
3145
3210
|
): Promise<TransactionInstruction> {
|
|
3146
3211
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
3147
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey(
|
|
3212
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey(
|
|
3213
|
+
subAccountId
|
|
3214
|
+
);
|
|
3148
3215
|
|
|
3149
3216
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3150
|
-
userAccounts: [this.getUserAccount()],
|
|
3217
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
3151
3218
|
useMarketLastSlotCache: true,
|
|
3152
3219
|
readableSpotMarketIndexes: [
|
|
3153
3220
|
orderParams.marketIndex,
|
|
@@ -3203,14 +3270,15 @@ export class DriftClient {
|
|
|
3203
3270
|
| SerumV3FulfillmentConfigAccount
|
|
3204
3271
|
| PhoenixV1FulfillmentConfigAccount,
|
|
3205
3272
|
makerInfo?: MakerInfo,
|
|
3206
|
-
referrerInfo?: ReferrerInfo
|
|
3273
|
+
referrerInfo?: ReferrerInfo,
|
|
3274
|
+
fillerPublicKey?: PublicKey
|
|
3207
3275
|
): Promise<TransactionInstruction> {
|
|
3208
3276
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
3209
3277
|
this.program.programId,
|
|
3210
3278
|
userAccount.authority
|
|
3211
3279
|
);
|
|
3212
3280
|
|
|
3213
|
-
const
|
|
3281
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
3214
3282
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
3215
3283
|
|
|
3216
3284
|
const marketIndex = order
|
|
@@ -3270,7 +3338,7 @@ export class DriftClient {
|
|
|
3270
3338
|
{
|
|
3271
3339
|
accounts: {
|
|
3272
3340
|
state: await this.getStatePublicKey(),
|
|
3273
|
-
filler
|
|
3341
|
+
filler,
|
|
3274
3342
|
fillerStats: fillerStatsPublicKey,
|
|
3275
3343
|
user: userAccountPublicKey,
|
|
3276
3344
|
userStats: userStatsPublicKey,
|
|
@@ -3983,11 +4051,17 @@ export class DriftClient {
|
|
|
3983
4051
|
userAccountPublicKey: PublicKey,
|
|
3984
4052
|
user: UserAccount,
|
|
3985
4053
|
order: Order,
|
|
3986
|
-
txParams?: TxParams
|
|
4054
|
+
txParams?: TxParams,
|
|
4055
|
+
fillerPublicKey?: PublicKey
|
|
3987
4056
|
): Promise<TransactionSignature> {
|
|
3988
4057
|
const { txSig } = await this.sendTransaction(
|
|
3989
4058
|
await this.buildTransaction(
|
|
3990
|
-
await this.getTriggerOrderIx(
|
|
4059
|
+
await this.getTriggerOrderIx(
|
|
4060
|
+
userAccountPublicKey,
|
|
4061
|
+
user,
|
|
4062
|
+
order,
|
|
4063
|
+
fillerPublicKey
|
|
4064
|
+
),
|
|
3991
4065
|
txParams
|
|
3992
4066
|
),
|
|
3993
4067
|
[],
|
|
@@ -3999,9 +4073,10 @@ export class DriftClient {
|
|
|
3999
4073
|
public async getTriggerOrderIx(
|
|
4000
4074
|
userAccountPublicKey: PublicKey,
|
|
4001
4075
|
userAccount: UserAccount,
|
|
4002
|
-
order: Order
|
|
4076
|
+
order: Order,
|
|
4077
|
+
fillerPublicKey?: PublicKey
|
|
4003
4078
|
): Promise<TransactionInstruction> {
|
|
4004
|
-
const
|
|
4079
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
4005
4080
|
|
|
4006
4081
|
let remainingAccountsParams;
|
|
4007
4082
|
if (isVariant(order.marketType, 'perp')) {
|
|
@@ -4024,7 +4099,7 @@ export class DriftClient {
|
|
|
4024
4099
|
return await this.program.instruction.triggerOrder(orderId, {
|
|
4025
4100
|
accounts: {
|
|
4026
4101
|
state: await this.getStatePublicKey(),
|
|
4027
|
-
filler
|
|
4102
|
+
filler,
|
|
4028
4103
|
user: userAccountPublicKey,
|
|
4029
4104
|
authority: this.wallet.publicKey,
|
|
4030
4105
|
},
|
|
@@ -4035,11 +4110,16 @@ export class DriftClient {
|
|
|
4035
4110
|
public async forceCancelOrders(
|
|
4036
4111
|
userAccountPublicKey: PublicKey,
|
|
4037
4112
|
user: UserAccount,
|
|
4038
|
-
txParams?: TxParams
|
|
4113
|
+
txParams?: TxParams,
|
|
4114
|
+
fillerPublicKey?: PublicKey
|
|
4039
4115
|
): Promise<TransactionSignature> {
|
|
4040
4116
|
const { txSig } = await this.sendTransaction(
|
|
4041
4117
|
await this.buildTransaction(
|
|
4042
|
-
await this.getForceCancelOrdersIx(
|
|
4118
|
+
await this.getForceCancelOrdersIx(
|
|
4119
|
+
userAccountPublicKey,
|
|
4120
|
+
user,
|
|
4121
|
+
fillerPublicKey
|
|
4122
|
+
),
|
|
4043
4123
|
txParams
|
|
4044
4124
|
),
|
|
4045
4125
|
[],
|
|
@@ -4050,9 +4130,10 @@ export class DriftClient {
|
|
|
4050
4130
|
|
|
4051
4131
|
public async getForceCancelOrdersIx(
|
|
4052
4132
|
userAccountPublicKey: PublicKey,
|
|
4053
|
-
userAccount: UserAccount
|
|
4133
|
+
userAccount: UserAccount,
|
|
4134
|
+
fillerPublicKey?: PublicKey
|
|
4054
4135
|
): Promise<TransactionInstruction> {
|
|
4055
|
-
const
|
|
4136
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
4056
4137
|
|
|
4057
4138
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4058
4139
|
userAccounts: [userAccount],
|
|
@@ -4062,7 +4143,7 @@ export class DriftClient {
|
|
|
4062
4143
|
return await this.program.instruction.forceCancelOrders({
|
|
4063
4144
|
accounts: {
|
|
4064
4145
|
state: await this.getStatePublicKey(),
|
|
4065
|
-
filler
|
|
4146
|
+
filler,
|
|
4066
4147
|
user: userAccountPublicKey,
|
|
4067
4148
|
authority: this.wallet.publicKey,
|
|
4068
4149
|
},
|
|
@@ -4073,11 +4154,16 @@ export class DriftClient {
|
|
|
4073
4154
|
public async updateUserIdle(
|
|
4074
4155
|
userAccountPublicKey: PublicKey,
|
|
4075
4156
|
user: UserAccount,
|
|
4076
|
-
txParams?: TxParams
|
|
4157
|
+
txParams?: TxParams,
|
|
4158
|
+
fillerPublicKey?: PublicKey
|
|
4077
4159
|
): Promise<TransactionSignature> {
|
|
4078
4160
|
const { txSig } = await this.sendTransaction(
|
|
4079
4161
|
await this.buildTransaction(
|
|
4080
|
-
await this.getUpdateUserIdleIx(
|
|
4162
|
+
await this.getUpdateUserIdleIx(
|
|
4163
|
+
userAccountPublicKey,
|
|
4164
|
+
user,
|
|
4165
|
+
fillerPublicKey
|
|
4166
|
+
),
|
|
4081
4167
|
txParams
|
|
4082
4168
|
),
|
|
4083
4169
|
[],
|
|
@@ -4088,9 +4174,10 @@ export class DriftClient {
|
|
|
4088
4174
|
|
|
4089
4175
|
public async getUpdateUserIdleIx(
|
|
4090
4176
|
userAccountPublicKey: PublicKey,
|
|
4091
|
-
userAccount: UserAccount
|
|
4177
|
+
userAccount: UserAccount,
|
|
4178
|
+
fillerPublicKey?: PublicKey
|
|
4092
4179
|
): Promise<TransactionInstruction> {
|
|
4093
|
-
const
|
|
4180
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
4094
4181
|
|
|
4095
4182
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4096
4183
|
userAccounts: [userAccount],
|
|
@@ -4099,7 +4186,7 @@ export class DriftClient {
|
|
|
4099
4186
|
return await this.program.instruction.updateUserIdle({
|
|
4100
4187
|
accounts: {
|
|
4101
4188
|
state: await this.getStatePublicKey(),
|
|
4102
|
-
filler
|
|
4189
|
+
filler,
|
|
4103
4190
|
user: userAccountPublicKey,
|
|
4104
4191
|
authority: this.wallet.publicKey,
|
|
4105
4192
|
},
|
|
@@ -4110,11 +4197,16 @@ export class DriftClient {
|
|
|
4110
4197
|
public async updateUserOpenOrdersCount(
|
|
4111
4198
|
userAccountPublicKey: PublicKey,
|
|
4112
4199
|
user: UserAccount,
|
|
4113
|
-
txParams?: TxParams
|
|
4200
|
+
txParams?: TxParams,
|
|
4201
|
+
fillerPublicKey?: PublicKey
|
|
4114
4202
|
): Promise<TransactionSignature> {
|
|
4115
4203
|
const { txSig } = await this.sendTransaction(
|
|
4116
4204
|
await this.buildTransaction(
|
|
4117
|
-
await this.getUpdateUserOpenOrdersCountIx(
|
|
4205
|
+
await this.getUpdateUserOpenOrdersCountIx(
|
|
4206
|
+
userAccountPublicKey,
|
|
4207
|
+
user,
|
|
4208
|
+
fillerPublicKey
|
|
4209
|
+
),
|
|
4118
4210
|
txParams
|
|
4119
4211
|
),
|
|
4120
4212
|
[],
|
|
@@ -4125,9 +4217,10 @@ export class DriftClient {
|
|
|
4125
4217
|
|
|
4126
4218
|
public async getUpdateUserOpenOrdersCountIx(
|
|
4127
4219
|
userAccountPublicKey: PublicKey,
|
|
4128
|
-
userAccount: UserAccount
|
|
4220
|
+
userAccount: UserAccount,
|
|
4221
|
+
fillerPublicKey?: PublicKey
|
|
4129
4222
|
): Promise<TransactionInstruction> {
|
|
4130
|
-
const
|
|
4223
|
+
const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey());
|
|
4131
4224
|
|
|
4132
4225
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4133
4226
|
userAccounts: [userAccount],
|
|
@@ -4136,7 +4229,7 @@ export class DriftClient {
|
|
|
4136
4229
|
return await this.program.instruction.updateUserOpenOrdersCount({
|
|
4137
4230
|
accounts: {
|
|
4138
4231
|
state: await this.getStatePublicKey(),
|
|
4139
|
-
filler
|
|
4232
|
+
filler,
|
|
4140
4233
|
user: userAccountPublicKey,
|
|
4141
4234
|
authority: this.wallet.publicKey,
|
|
4142
4235
|
},
|
|
@@ -4148,14 +4241,16 @@ export class DriftClient {
|
|
|
4148
4241
|
orderParams: OptionalOrderParams,
|
|
4149
4242
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
4150
4243
|
referrerInfo?: ReferrerInfo,
|
|
4151
|
-
txParams?: TxParams
|
|
4244
|
+
txParams?: TxParams,
|
|
4245
|
+
subAccountId?: number
|
|
4152
4246
|
): Promise<TransactionSignature> {
|
|
4153
4247
|
const { txSig, slot } = await this.sendTransaction(
|
|
4154
4248
|
await this.buildTransaction(
|
|
4155
4249
|
await this.getPlaceAndTakePerpOrderIx(
|
|
4156
4250
|
orderParams,
|
|
4157
4251
|
makerInfo,
|
|
4158
|
-
referrerInfo
|
|
4252
|
+
referrerInfo,
|
|
4253
|
+
subAccountId
|
|
4159
4254
|
),
|
|
4160
4255
|
txParams
|
|
4161
4256
|
),
|
|
@@ -4169,11 +4264,12 @@ export class DriftClient {
|
|
|
4169
4264
|
public async getPlaceAndTakePerpOrderIx(
|
|
4170
4265
|
orderParams: OptionalOrderParams,
|
|
4171
4266
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
4172
|
-
referrerInfo?: ReferrerInfo
|
|
4267
|
+
referrerInfo?: ReferrerInfo,
|
|
4268
|
+
subAccountId?: number
|
|
4173
4269
|
): Promise<TransactionInstruction> {
|
|
4174
4270
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
4175
4271
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
4176
|
-
const
|
|
4272
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4177
4273
|
|
|
4178
4274
|
makerInfo = Array.isArray(makerInfo)
|
|
4179
4275
|
? makerInfo
|
|
@@ -4181,7 +4277,7 @@ export class DriftClient {
|
|
|
4181
4277
|
? [makerInfo]
|
|
4182
4278
|
: [];
|
|
4183
4279
|
|
|
4184
|
-
const userAccounts = [this.getUserAccount()];
|
|
4280
|
+
const userAccounts = [this.getUserAccount(subAccountId)];
|
|
4185
4281
|
for (const maker of makerInfo) {
|
|
4186
4282
|
userAccounts.push(maker.makerUserAccount);
|
|
4187
4283
|
}
|
|
@@ -4229,7 +4325,7 @@ export class DriftClient {
|
|
|
4229
4325
|
{
|
|
4230
4326
|
accounts: {
|
|
4231
4327
|
state: await this.getStatePublicKey(),
|
|
4232
|
-
user
|
|
4328
|
+
user,
|
|
4233
4329
|
userStats: userStatsPublicKey,
|
|
4234
4330
|
authority: this.wallet.publicKey,
|
|
4235
4331
|
},
|
|
@@ -4242,14 +4338,16 @@ export class DriftClient {
|
|
|
4242
4338
|
orderParams: OptionalOrderParams,
|
|
4243
4339
|
takerInfo: TakerInfo,
|
|
4244
4340
|
referrerInfo?: ReferrerInfo,
|
|
4245
|
-
txParams?: TxParams
|
|
4341
|
+
txParams?: TxParams,
|
|
4342
|
+
subAccountId?: number
|
|
4246
4343
|
): Promise<TransactionSignature> {
|
|
4247
4344
|
const { txSig, slot } = await this.sendTransaction(
|
|
4248
4345
|
await this.buildTransaction(
|
|
4249
4346
|
await this.getPlaceAndMakePerpOrderIx(
|
|
4250
4347
|
orderParams,
|
|
4251
4348
|
takerInfo,
|
|
4252
|
-
referrerInfo
|
|
4349
|
+
referrerInfo,
|
|
4350
|
+
subAccountId
|
|
4253
4351
|
),
|
|
4254
4352
|
txParams
|
|
4255
4353
|
),
|
|
@@ -4265,14 +4363,18 @@ export class DriftClient {
|
|
|
4265
4363
|
public async getPlaceAndMakePerpOrderIx(
|
|
4266
4364
|
orderParams: OptionalOrderParams,
|
|
4267
4365
|
takerInfo: TakerInfo,
|
|
4268
|
-
referrerInfo?: ReferrerInfo
|
|
4366
|
+
referrerInfo?: ReferrerInfo,
|
|
4367
|
+
subAccountId?: number
|
|
4269
4368
|
): Promise<TransactionInstruction> {
|
|
4270
4369
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.PERP });
|
|
4271
4370
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4272
|
-
const
|
|
4371
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4273
4372
|
|
|
4274
4373
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4275
|
-
userAccounts: [
|
|
4374
|
+
userAccounts: [
|
|
4375
|
+
this.getUserAccount(subAccountId),
|
|
4376
|
+
takerInfo.takerUserAccount,
|
|
4377
|
+
],
|
|
4276
4378
|
useMarketLastSlotCache: true,
|
|
4277
4379
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
4278
4380
|
});
|
|
@@ -4297,7 +4399,7 @@ export class DriftClient {
|
|
|
4297
4399
|
{
|
|
4298
4400
|
accounts: {
|
|
4299
4401
|
state: await this.getStatePublicKey(),
|
|
4300
|
-
user
|
|
4402
|
+
user,
|
|
4301
4403
|
userStats: userStatsPublicKey,
|
|
4302
4404
|
taker: takerInfo.taker,
|
|
4303
4405
|
takerStats: takerInfo.takerStats,
|
|
@@ -4313,7 +4415,8 @@ export class DriftClient {
|
|
|
4313
4415
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
4314
4416
|
makerInfo?: MakerInfo,
|
|
4315
4417
|
referrerInfo?: ReferrerInfo,
|
|
4316
|
-
txParams?: TxParams
|
|
4418
|
+
txParams?: TxParams,
|
|
4419
|
+
subAccountId?: number
|
|
4317
4420
|
): Promise<TransactionSignature> {
|
|
4318
4421
|
const { txSig, slot } = await this.sendTransaction(
|
|
4319
4422
|
await this.buildTransaction(
|
|
@@ -4321,7 +4424,8 @@ export class DriftClient {
|
|
|
4321
4424
|
orderParams,
|
|
4322
4425
|
fulfillmentConfig,
|
|
4323
4426
|
makerInfo,
|
|
4324
|
-
referrerInfo
|
|
4427
|
+
referrerInfo,
|
|
4428
|
+
subAccountId
|
|
4325
4429
|
),
|
|
4326
4430
|
txParams
|
|
4327
4431
|
),
|
|
@@ -4337,13 +4441,14 @@ export class DriftClient {
|
|
|
4337
4441
|
orderParams: OptionalOrderParams,
|
|
4338
4442
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
4339
4443
|
makerInfo?: MakerInfo,
|
|
4340
|
-
referrerInfo?: ReferrerInfo
|
|
4444
|
+
referrerInfo?: ReferrerInfo,
|
|
4445
|
+
subAccountId?: number
|
|
4341
4446
|
): Promise<TransactionInstruction> {
|
|
4342
4447
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
4343
|
-
const userStatsPublicKey =
|
|
4344
|
-
const
|
|
4448
|
+
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4449
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4345
4450
|
|
|
4346
|
-
const userAccounts = [this.getUserAccount()];
|
|
4451
|
+
const userAccounts = [this.getUserAccount(subAccountId)];
|
|
4347
4452
|
if (makerInfo !== undefined) {
|
|
4348
4453
|
userAccounts.push(makerInfo.makerUserAccount);
|
|
4349
4454
|
}
|
|
@@ -4397,7 +4502,7 @@ export class DriftClient {
|
|
|
4397
4502
|
{
|
|
4398
4503
|
accounts: {
|
|
4399
4504
|
state: await this.getStatePublicKey(),
|
|
4400
|
-
user
|
|
4505
|
+
user,
|
|
4401
4506
|
userStats: userStatsPublicKey,
|
|
4402
4507
|
authority: this.wallet.publicKey,
|
|
4403
4508
|
},
|
|
@@ -4411,7 +4516,8 @@ export class DriftClient {
|
|
|
4411
4516
|
takerInfo: TakerInfo,
|
|
4412
4517
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
4413
4518
|
referrerInfo?: ReferrerInfo,
|
|
4414
|
-
txParams?: TxParams
|
|
4519
|
+
txParams?: TxParams,
|
|
4520
|
+
subAccountId?: number
|
|
4415
4521
|
): Promise<TransactionSignature> {
|
|
4416
4522
|
const { txSig, slot } = await this.sendTransaction(
|
|
4417
4523
|
await this.buildTransaction(
|
|
@@ -4419,7 +4525,8 @@ export class DriftClient {
|
|
|
4419
4525
|
orderParams,
|
|
4420
4526
|
takerInfo,
|
|
4421
4527
|
fulfillmentConfig,
|
|
4422
|
-
referrerInfo
|
|
4528
|
+
referrerInfo,
|
|
4529
|
+
subAccountId
|
|
4423
4530
|
),
|
|
4424
4531
|
txParams
|
|
4425
4532
|
),
|
|
@@ -4435,14 +4542,18 @@ export class DriftClient {
|
|
|
4435
4542
|
orderParams: OptionalOrderParams,
|
|
4436
4543
|
takerInfo: TakerInfo,
|
|
4437
4544
|
fulfillmentConfig?: SerumV3FulfillmentConfigAccount,
|
|
4438
|
-
referrerInfo?: ReferrerInfo
|
|
4545
|
+
referrerInfo?: ReferrerInfo,
|
|
4546
|
+
subAccountId?: number
|
|
4439
4547
|
): Promise<TransactionInstruction> {
|
|
4440
4548
|
orderParams = getOrderParams(orderParams, { marketType: MarketType.SPOT });
|
|
4441
4549
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4442
|
-
const
|
|
4550
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4443
4551
|
|
|
4444
4552
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4445
|
-
userAccounts: [
|
|
4553
|
+
userAccounts: [
|
|
4554
|
+
this.getUserAccount(subAccountId),
|
|
4555
|
+
takerInfo.takerUserAccount,
|
|
4556
|
+
],
|
|
4446
4557
|
useMarketLastSlotCache: true,
|
|
4447
4558
|
writableSpotMarketIndexes: [
|
|
4448
4559
|
orderParams.marketIndex,
|
|
@@ -4477,7 +4588,7 @@ export class DriftClient {
|
|
|
4477
4588
|
{
|
|
4478
4589
|
accounts: {
|
|
4479
4590
|
state: await this.getStatePublicKey(),
|
|
4480
|
-
user
|
|
4591
|
+
user,
|
|
4481
4592
|
userStats: userStatsPublicKey,
|
|
4482
4593
|
taker: takerInfo.taker,
|
|
4483
4594
|
takerStats: takerInfo.takerStats,
|
|
@@ -4493,21 +4604,29 @@ export class DriftClient {
|
|
|
4493
4604
|
*/
|
|
4494
4605
|
public async closePosition(
|
|
4495
4606
|
marketIndex: number,
|
|
4496
|
-
limitPrice?: BN
|
|
4607
|
+
limitPrice?: BN,
|
|
4608
|
+
subAccountId?: number
|
|
4497
4609
|
): Promise<TransactionSignature> {
|
|
4498
|
-
const userPosition =
|
|
4610
|
+
const userPosition =
|
|
4611
|
+
this.getUser(subAccountId).getPerpPosition(marketIndex);
|
|
4499
4612
|
if (!userPosition) {
|
|
4500
4613
|
throw Error(`No position in market ${marketIndex.toString()}`);
|
|
4501
4614
|
}
|
|
4502
4615
|
|
|
4503
|
-
return await this.placeAndTakePerpOrder(
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4616
|
+
return await this.placeAndTakePerpOrder(
|
|
4617
|
+
{
|
|
4618
|
+
orderType: OrderType.MARKET,
|
|
4619
|
+
marketIndex,
|
|
4620
|
+
direction: findDirectionToClose(userPosition),
|
|
4621
|
+
baseAssetAmount: userPosition.baseAssetAmount.abs(),
|
|
4622
|
+
reduceOnly: true,
|
|
4623
|
+
price: limitPrice,
|
|
4624
|
+
},
|
|
4625
|
+
undefined,
|
|
4626
|
+
undefined,
|
|
4627
|
+
undefined,
|
|
4628
|
+
subAccountId
|
|
4629
|
+
);
|
|
4511
4630
|
}
|
|
4512
4631
|
|
|
4513
4632
|
/**
|
|
@@ -4592,11 +4711,12 @@ export class DriftClient {
|
|
|
4592
4711
|
maxTs?: BN;
|
|
4593
4712
|
policy?: ModifyOrderPolicy;
|
|
4594
4713
|
},
|
|
4595
|
-
txParams?: TxParams
|
|
4714
|
+
txParams?: TxParams,
|
|
4715
|
+
subAccountId?: number
|
|
4596
4716
|
): Promise<TransactionSignature> {
|
|
4597
4717
|
const { txSig } = await this.sendTransaction(
|
|
4598
4718
|
await this.buildTransaction(
|
|
4599
|
-
await this.getModifyOrderIx(orderParams),
|
|
4719
|
+
await this.getModifyOrderIx(orderParams, subAccountId),
|
|
4600
4720
|
txParams
|
|
4601
4721
|
),
|
|
4602
4722
|
[],
|
|
@@ -4605,43 +4725,46 @@ export class DriftClient {
|
|
|
4605
4725
|
return txSig;
|
|
4606
4726
|
}
|
|
4607
4727
|
|
|
4608
|
-
public async getModifyOrderIx(
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4728
|
+
public async getModifyOrderIx(
|
|
4729
|
+
{
|
|
4730
|
+
orderId,
|
|
4731
|
+
newDirection,
|
|
4732
|
+
newBaseAmount,
|
|
4733
|
+
newLimitPrice,
|
|
4734
|
+
newOraclePriceOffset,
|
|
4735
|
+
newTriggerPrice,
|
|
4736
|
+
newTriggerCondition,
|
|
4737
|
+
auctionDuration,
|
|
4738
|
+
auctionStartPrice,
|
|
4739
|
+
auctionEndPrice,
|
|
4740
|
+
reduceOnly,
|
|
4741
|
+
postOnly,
|
|
4742
|
+
immediateOrCancel,
|
|
4743
|
+
maxTs,
|
|
4744
|
+
policy,
|
|
4745
|
+
}: {
|
|
4746
|
+
orderId: number;
|
|
4747
|
+
newDirection?: PositionDirection;
|
|
4748
|
+
newBaseAmount?: BN;
|
|
4749
|
+
newLimitPrice?: BN;
|
|
4750
|
+
newOraclePriceOffset?: number;
|
|
4751
|
+
newTriggerPrice?: BN;
|
|
4752
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
4753
|
+
auctionDuration?: number;
|
|
4754
|
+
auctionStartPrice?: BN;
|
|
4755
|
+
auctionEndPrice?: BN;
|
|
4756
|
+
reduceOnly?: boolean;
|
|
4757
|
+
postOnly?: boolean;
|
|
4758
|
+
immediateOrCancel?: boolean;
|
|
4759
|
+
maxTs?: BN;
|
|
4760
|
+
policy?: ModifyOrderPolicy;
|
|
4761
|
+
},
|
|
4762
|
+
subAccountId?: number
|
|
4763
|
+
): Promise<TransactionInstruction> {
|
|
4764
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4642
4765
|
|
|
4643
4766
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4644
|
-
userAccounts: [this.getUserAccount()],
|
|
4767
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
4645
4768
|
useMarketLastSlotCache: true,
|
|
4646
4769
|
});
|
|
4647
4770
|
|
|
@@ -4666,7 +4789,7 @@ export class DriftClient {
|
|
|
4666
4789
|
return await this.program.instruction.modifyOrder(orderId, orderParams, {
|
|
4667
4790
|
accounts: {
|
|
4668
4791
|
state: await this.getStatePublicKey(),
|
|
4669
|
-
user
|
|
4792
|
+
user,
|
|
4670
4793
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
4671
4794
|
authority: this.wallet.publicKey,
|
|
4672
4795
|
},
|
|
@@ -4710,11 +4833,12 @@ export class DriftClient {
|
|
|
4710
4833
|
policy?: ModifyOrderPolicy;
|
|
4711
4834
|
maxTs?: BN;
|
|
4712
4835
|
},
|
|
4713
|
-
txParams?: TxParams
|
|
4836
|
+
txParams?: TxParams,
|
|
4837
|
+
subAccountId?: number
|
|
4714
4838
|
): Promise<TransactionSignature> {
|
|
4715
4839
|
const { txSig } = await this.sendTransaction(
|
|
4716
4840
|
await this.buildTransaction(
|
|
4717
|
-
await this.getModifyOrderByUserIdIx(orderParams),
|
|
4841
|
+
await this.getModifyOrderByUserIdIx(orderParams, subAccountId),
|
|
4718
4842
|
txParams
|
|
4719
4843
|
),
|
|
4720
4844
|
[],
|
|
@@ -4723,44 +4847,47 @@ export class DriftClient {
|
|
|
4723
4847
|
return txSig;
|
|
4724
4848
|
}
|
|
4725
4849
|
|
|
4726
|
-
public async getModifyOrderByUserIdIx(
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4850
|
+
public async getModifyOrderByUserIdIx(
|
|
4851
|
+
{
|
|
4852
|
+
userOrderId,
|
|
4853
|
+
newDirection,
|
|
4854
|
+
newBaseAmount,
|
|
4855
|
+
newLimitPrice,
|
|
4856
|
+
newOraclePriceOffset,
|
|
4857
|
+
newTriggerPrice,
|
|
4858
|
+
newTriggerCondition,
|
|
4859
|
+
auctionDuration,
|
|
4860
|
+
auctionStartPrice,
|
|
4861
|
+
auctionEndPrice,
|
|
4862
|
+
reduceOnly,
|
|
4863
|
+
postOnly,
|
|
4864
|
+
immediateOrCancel,
|
|
4865
|
+
maxTs,
|
|
4866
|
+
policy,
|
|
4867
|
+
}: {
|
|
4868
|
+
userOrderId: number;
|
|
4869
|
+
newDirection?: PositionDirection;
|
|
4870
|
+
newBaseAmount?: BN;
|
|
4871
|
+
newLimitPrice?: BN;
|
|
4872
|
+
newOraclePriceOffset?: number;
|
|
4873
|
+
newTriggerPrice?: BN;
|
|
4874
|
+
newTriggerCondition?: OrderTriggerCondition;
|
|
4875
|
+
auctionDuration?: number;
|
|
4876
|
+
auctionStartPrice?: BN;
|
|
4877
|
+
auctionEndPrice?: BN;
|
|
4878
|
+
reduceOnly?: boolean;
|
|
4879
|
+
postOnly?: boolean;
|
|
4880
|
+
immediateOrCancel?: boolean;
|
|
4881
|
+
policy?: ModifyOrderPolicy;
|
|
4882
|
+
maxTs?: BN;
|
|
4883
|
+
txParams?: TxParams;
|
|
4884
|
+
},
|
|
4885
|
+
subAccountId?: number
|
|
4886
|
+
): Promise<TransactionInstruction> {
|
|
4887
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
4761
4888
|
|
|
4762
4889
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4763
|
-
userAccounts: [this.getUserAccount()],
|
|
4890
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
4764
4891
|
useMarketLastSlotCache: true,
|
|
4765
4892
|
});
|
|
4766
4893
|
|
|
@@ -4787,7 +4914,7 @@ export class DriftClient {
|
|
|
4787
4914
|
{
|
|
4788
4915
|
accounts: {
|
|
4789
4916
|
state: await this.getStatePublicKey(),
|
|
4790
|
-
user
|
|
4917
|
+
user,
|
|
4791
4918
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
4792
4919
|
authority: this.wallet.publicKey,
|
|
4793
4920
|
},
|
|
@@ -4883,7 +5010,8 @@ export class DriftClient {
|
|
|
4883
5010
|
marketIndex: number,
|
|
4884
5011
|
maxBaseAssetAmount: BN,
|
|
4885
5012
|
limitPrice?: BN,
|
|
4886
|
-
txParams?: TxParams
|
|
5013
|
+
txParams?: TxParams,
|
|
5014
|
+
liquidatorSubAccountId?: number
|
|
4887
5015
|
): Promise<TransactionSignature> {
|
|
4888
5016
|
const { txSig, slot } = await this.sendTransaction(
|
|
4889
5017
|
await this.buildTransaction(
|
|
@@ -4892,7 +5020,8 @@ export class DriftClient {
|
|
|
4892
5020
|
userAccount,
|
|
4893
5021
|
marketIndex,
|
|
4894
5022
|
maxBaseAssetAmount,
|
|
4895
|
-
limitPrice
|
|
5023
|
+
limitPrice,
|
|
5024
|
+
liquidatorSubAccountId
|
|
4896
5025
|
),
|
|
4897
5026
|
txParams
|
|
4898
5027
|
),
|
|
@@ -4908,18 +5037,21 @@ export class DriftClient {
|
|
|
4908
5037
|
userAccount: UserAccount,
|
|
4909
5038
|
marketIndex: number,
|
|
4910
5039
|
maxBaseAssetAmount: BN,
|
|
4911
|
-
limitPrice?: BN
|
|
5040
|
+
limitPrice?: BN,
|
|
5041
|
+
liquidatorSubAccountId?: number
|
|
4912
5042
|
): Promise<TransactionInstruction> {
|
|
4913
5043
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
4914
5044
|
this.program.programId,
|
|
4915
5045
|
userAccount.authority
|
|
4916
5046
|
);
|
|
4917
5047
|
|
|
4918
|
-
const
|
|
5048
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5049
|
+
liquidatorSubAccountId
|
|
5050
|
+
);
|
|
4919
5051
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4920
5052
|
|
|
4921
5053
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4922
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5054
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
4923
5055
|
useMarketLastSlotCache: true,
|
|
4924
5056
|
writablePerpMarketIndexes: [marketIndex],
|
|
4925
5057
|
});
|
|
@@ -4934,7 +5066,7 @@ export class DriftClient {
|
|
|
4934
5066
|
authority: this.wallet.publicKey,
|
|
4935
5067
|
user: userAccountPublicKey,
|
|
4936
5068
|
userStats: userStatsPublicKey,
|
|
4937
|
-
liquidator
|
|
5069
|
+
liquidator,
|
|
4938
5070
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
4939
5071
|
},
|
|
4940
5072
|
remainingAccounts: remainingAccounts,
|
|
@@ -4949,7 +5081,8 @@ export class DriftClient {
|
|
|
4949
5081
|
liabilityMarketIndex: number,
|
|
4950
5082
|
maxLiabilityTransfer: BN,
|
|
4951
5083
|
limitPrice?: BN,
|
|
4952
|
-
txParams?: TxParams
|
|
5084
|
+
txParams?: TxParams,
|
|
5085
|
+
liquidatorSubAccountId?: number
|
|
4953
5086
|
): Promise<TransactionSignature> {
|
|
4954
5087
|
const { txSig, slot } = await this.sendTransaction(
|
|
4955
5088
|
await this.buildTransaction(
|
|
@@ -4959,7 +5092,8 @@ export class DriftClient {
|
|
|
4959
5092
|
assetMarketIndex,
|
|
4960
5093
|
liabilityMarketIndex,
|
|
4961
5094
|
maxLiabilityTransfer,
|
|
4962
|
-
limitPrice
|
|
5095
|
+
limitPrice,
|
|
5096
|
+
liquidatorSubAccountId
|
|
4963
5097
|
),
|
|
4964
5098
|
txParams
|
|
4965
5099
|
),
|
|
@@ -4977,18 +5111,21 @@ export class DriftClient {
|
|
|
4977
5111
|
assetMarketIndex: number,
|
|
4978
5112
|
liabilityMarketIndex: number,
|
|
4979
5113
|
maxLiabilityTransfer: BN,
|
|
4980
|
-
limitPrice?: BN
|
|
5114
|
+
limitPrice?: BN,
|
|
5115
|
+
liquidatorSubAccountId?: number
|
|
4981
5116
|
): Promise<TransactionInstruction> {
|
|
4982
5117
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
4983
5118
|
this.program.programId,
|
|
4984
5119
|
userAccount.authority
|
|
4985
5120
|
);
|
|
4986
5121
|
|
|
4987
|
-
const
|
|
4988
|
-
|
|
5122
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5123
|
+
liquidatorSubAccountId
|
|
5124
|
+
);
|
|
5125
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
4989
5126
|
|
|
4990
5127
|
const remainingAccounts = this.getRemainingAccounts({
|
|
4991
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5128
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
4992
5129
|
useMarketLastSlotCache: true,
|
|
4993
5130
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
4994
5131
|
});
|
|
@@ -5004,7 +5141,7 @@ export class DriftClient {
|
|
|
5004
5141
|
authority: this.wallet.publicKey,
|
|
5005
5142
|
user: userAccountPublicKey,
|
|
5006
5143
|
userStats: userStatsPublicKey,
|
|
5007
|
-
liquidator
|
|
5144
|
+
liquidator,
|
|
5008
5145
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
5009
5146
|
},
|
|
5010
5147
|
remainingAccounts: remainingAccounts,
|
|
@@ -5019,7 +5156,8 @@ export class DriftClient {
|
|
|
5019
5156
|
liabilityMarketIndex: number,
|
|
5020
5157
|
maxLiabilityTransfer: BN,
|
|
5021
5158
|
limitPrice?: BN,
|
|
5022
|
-
txParams?: TxParams
|
|
5159
|
+
txParams?: TxParams,
|
|
5160
|
+
liquidatorSubAccountId?: number
|
|
5023
5161
|
): Promise<TransactionSignature> {
|
|
5024
5162
|
const { txSig, slot } = await this.sendTransaction(
|
|
5025
5163
|
await this.buildTransaction(
|
|
@@ -5029,7 +5167,8 @@ export class DriftClient {
|
|
|
5029
5167
|
perpMarketIndex,
|
|
5030
5168
|
liabilityMarketIndex,
|
|
5031
5169
|
maxLiabilityTransfer,
|
|
5032
|
-
limitPrice
|
|
5170
|
+
limitPrice,
|
|
5171
|
+
liquidatorSubAccountId
|
|
5033
5172
|
),
|
|
5034
5173
|
txParams
|
|
5035
5174
|
),
|
|
@@ -5047,18 +5186,21 @@ export class DriftClient {
|
|
|
5047
5186
|
perpMarketIndex: number,
|
|
5048
5187
|
liabilityMarketIndex: number,
|
|
5049
5188
|
maxLiabilityTransfer: BN,
|
|
5050
|
-
limitPrice?: BN
|
|
5189
|
+
limitPrice?: BN,
|
|
5190
|
+
liquidatorSubAccountId?: number
|
|
5051
5191
|
): Promise<TransactionInstruction> {
|
|
5052
5192
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
5053
5193
|
this.program.programId,
|
|
5054
5194
|
userAccount.authority
|
|
5055
5195
|
);
|
|
5056
5196
|
|
|
5057
|
-
const
|
|
5058
|
-
|
|
5197
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5198
|
+
liquidatorSubAccountId
|
|
5199
|
+
);
|
|
5200
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
5059
5201
|
|
|
5060
5202
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5061
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5203
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
5062
5204
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
5063
5205
|
writableSpotMarketIndexes: [liabilityMarketIndex],
|
|
5064
5206
|
});
|
|
@@ -5074,7 +5216,7 @@ export class DriftClient {
|
|
|
5074
5216
|
authority: this.wallet.publicKey,
|
|
5075
5217
|
user: userAccountPublicKey,
|
|
5076
5218
|
userStats: userStatsPublicKey,
|
|
5077
|
-
liquidator
|
|
5219
|
+
liquidator,
|
|
5078
5220
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
5079
5221
|
},
|
|
5080
5222
|
remainingAccounts: remainingAccounts,
|
|
@@ -5089,7 +5231,8 @@ export class DriftClient {
|
|
|
5089
5231
|
assetMarketIndex: number,
|
|
5090
5232
|
maxPnlTransfer: BN,
|
|
5091
5233
|
limitPrice?: BN,
|
|
5092
|
-
txParams?: TxParams
|
|
5234
|
+
txParams?: TxParams,
|
|
5235
|
+
liquidatorSubAccountId?: number
|
|
5093
5236
|
): Promise<TransactionSignature> {
|
|
5094
5237
|
const { txSig, slot } = await this.sendTransaction(
|
|
5095
5238
|
await this.buildTransaction(
|
|
@@ -5099,7 +5242,8 @@ export class DriftClient {
|
|
|
5099
5242
|
perpMarketIndex,
|
|
5100
5243
|
assetMarketIndex,
|
|
5101
5244
|
maxPnlTransfer,
|
|
5102
|
-
limitPrice
|
|
5245
|
+
limitPrice,
|
|
5246
|
+
liquidatorSubAccountId
|
|
5103
5247
|
),
|
|
5104
5248
|
txParams
|
|
5105
5249
|
),
|
|
@@ -5117,18 +5261,21 @@ export class DriftClient {
|
|
|
5117
5261
|
perpMarketIndex: number,
|
|
5118
5262
|
assetMarketIndex: number,
|
|
5119
5263
|
maxPnlTransfer: BN,
|
|
5120
|
-
limitPrice?: BN
|
|
5264
|
+
limitPrice?: BN,
|
|
5265
|
+
liquidatorSubAccountId?: number
|
|
5121
5266
|
): Promise<TransactionInstruction> {
|
|
5122
5267
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
5123
5268
|
this.program.programId,
|
|
5124
5269
|
userAccount.authority
|
|
5125
5270
|
);
|
|
5126
5271
|
|
|
5127
|
-
const
|
|
5128
|
-
|
|
5272
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5273
|
+
liquidatorSubAccountId
|
|
5274
|
+
);
|
|
5275
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
5129
5276
|
|
|
5130
5277
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5131
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5278
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
5132
5279
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
5133
5280
|
writableSpotMarketIndexes: [assetMarketIndex],
|
|
5134
5281
|
});
|
|
@@ -5144,7 +5291,7 @@ export class DriftClient {
|
|
|
5144
5291
|
authority: this.wallet.publicKey,
|
|
5145
5292
|
user: userAccountPublicKey,
|
|
5146
5293
|
userStats: userStatsPublicKey,
|
|
5147
|
-
liquidator
|
|
5294
|
+
liquidator,
|
|
5148
5295
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
5149
5296
|
},
|
|
5150
5297
|
remainingAccounts: remainingAccounts,
|
|
@@ -5156,14 +5303,16 @@ export class DriftClient {
|
|
|
5156
5303
|
userAccountPublicKey: PublicKey,
|
|
5157
5304
|
userAccount: UserAccount,
|
|
5158
5305
|
marketIndex: number,
|
|
5159
|
-
txParams?: TxParams
|
|
5306
|
+
txParams?: TxParams,
|
|
5307
|
+
liquidatorSubAccountId?: number
|
|
5160
5308
|
): Promise<TransactionSignature> {
|
|
5161
5309
|
const { txSig } = await this.sendTransaction(
|
|
5162
5310
|
await this.buildTransaction(
|
|
5163
5311
|
await this.getResolvePerpBankruptcyIx(
|
|
5164
5312
|
userAccountPublicKey,
|
|
5165
5313
|
userAccount,
|
|
5166
|
-
marketIndex
|
|
5314
|
+
marketIndex,
|
|
5315
|
+
liquidatorSubAccountId
|
|
5167
5316
|
),
|
|
5168
5317
|
txParams
|
|
5169
5318
|
),
|
|
@@ -5176,18 +5325,21 @@ export class DriftClient {
|
|
|
5176
5325
|
public async getResolvePerpBankruptcyIx(
|
|
5177
5326
|
userAccountPublicKey: PublicKey,
|
|
5178
5327
|
userAccount: UserAccount,
|
|
5179
|
-
marketIndex: number
|
|
5328
|
+
marketIndex: number,
|
|
5329
|
+
liquidatorSubAccountId?: number
|
|
5180
5330
|
): Promise<TransactionInstruction> {
|
|
5181
5331
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
5182
5332
|
this.program.programId,
|
|
5183
5333
|
userAccount.authority
|
|
5184
5334
|
);
|
|
5185
5335
|
|
|
5186
|
-
const
|
|
5187
|
-
|
|
5336
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5337
|
+
liquidatorSubAccountId
|
|
5338
|
+
);
|
|
5339
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
5188
5340
|
|
|
5189
5341
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5190
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5342
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
5191
5343
|
writablePerpMarketIndexes: [marketIndex],
|
|
5192
5344
|
writableSpotMarketIndexes: [QUOTE_SPOT_MARKET_INDEX],
|
|
5193
5345
|
});
|
|
@@ -5203,7 +5355,7 @@ export class DriftClient {
|
|
|
5203
5355
|
authority: this.wallet.publicKey,
|
|
5204
5356
|
user: userAccountPublicKey,
|
|
5205
5357
|
userStats: userStatsPublicKey,
|
|
5206
|
-
liquidator
|
|
5358
|
+
liquidator,
|
|
5207
5359
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
5208
5360
|
spotMarketVault: spotMarket.vault,
|
|
5209
5361
|
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
@@ -5219,14 +5371,16 @@ export class DriftClient {
|
|
|
5219
5371
|
userAccountPublicKey: PublicKey,
|
|
5220
5372
|
userAccount: UserAccount,
|
|
5221
5373
|
marketIndex: number,
|
|
5222
|
-
txParams?: TxParams
|
|
5374
|
+
txParams?: TxParams,
|
|
5375
|
+
liquidatorSubAccountId?: number
|
|
5223
5376
|
): Promise<TransactionSignature> {
|
|
5224
5377
|
const { txSig } = await this.sendTransaction(
|
|
5225
5378
|
await this.buildTransaction(
|
|
5226
5379
|
await this.getResolveSpotBankruptcyIx(
|
|
5227
5380
|
userAccountPublicKey,
|
|
5228
5381
|
userAccount,
|
|
5229
|
-
marketIndex
|
|
5382
|
+
marketIndex,
|
|
5383
|
+
liquidatorSubAccountId
|
|
5230
5384
|
),
|
|
5231
5385
|
txParams
|
|
5232
5386
|
),
|
|
@@ -5239,18 +5393,21 @@ export class DriftClient {
|
|
|
5239
5393
|
public async getResolveSpotBankruptcyIx(
|
|
5240
5394
|
userAccountPublicKey: PublicKey,
|
|
5241
5395
|
userAccount: UserAccount,
|
|
5242
|
-
marketIndex: number
|
|
5396
|
+
marketIndex: number,
|
|
5397
|
+
liquidatorSubAccountId?: number
|
|
5243
5398
|
): Promise<TransactionInstruction> {
|
|
5244
5399
|
const userStatsPublicKey = getUserStatsAccountPublicKey(
|
|
5245
5400
|
this.program.programId,
|
|
5246
5401
|
userAccount.authority
|
|
5247
5402
|
);
|
|
5248
5403
|
|
|
5249
|
-
const
|
|
5250
|
-
|
|
5404
|
+
const liquidator = await this.getUserAccountPublicKey(
|
|
5405
|
+
liquidatorSubAccountId
|
|
5406
|
+
);
|
|
5407
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
5251
5408
|
|
|
5252
5409
|
const remainingAccounts = this.getRemainingAccounts({
|
|
5253
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
5410
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
5254
5411
|
writableSpotMarketIndexes: [marketIndex],
|
|
5255
5412
|
});
|
|
5256
5413
|
|
|
@@ -5263,7 +5420,7 @@ export class DriftClient {
|
|
|
5263
5420
|
user: userAccountPublicKey,
|
|
5264
5421
|
userStats: userStatsPublicKey,
|
|
5265
5422
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
5266
|
-
liquidator
|
|
5423
|
+
liquidator,
|
|
5267
5424
|
spotMarketVault: spotMarket.vault,
|
|
5268
5425
|
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
5269
5426
|
driftSigner: this.getSignerPublicKey(),
|