@drift-labs/sdk 2.49.0-beta.1 → 2.49.0-beta.11
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/math/superStake.d.ts +43 -0
- package/lib/math/superStake.js +64 -22
- 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/math/superStake.ts +108 -20
- 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/lib/driftClient.js
CHANGED
|
@@ -421,7 +421,7 @@ class DriftClient {
|
|
|
421
421
|
}
|
|
422
422
|
return result;
|
|
423
423
|
}
|
|
424
|
-
async initializeUserAccount(subAccountId = 0, name
|
|
424
|
+
async initializeUserAccount(subAccountId = 0, name, referrerInfo) {
|
|
425
425
|
const initializeIxs = [];
|
|
426
426
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
427
427
|
if (subAccountId === 0) {
|
|
@@ -435,7 +435,7 @@ class DriftClient {
|
|
|
435
435
|
await this.addUser(subAccountId);
|
|
436
436
|
return [txSig, userAccountPublicKey];
|
|
437
437
|
}
|
|
438
|
-
async getInitializeUserInstructions(subAccountId = 0, name
|
|
438
|
+
async getInitializeUserInstructions(subAccountId = 0, name, referrerInfo) {
|
|
439
439
|
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
440
440
|
const remainingAccounts = new Array();
|
|
441
441
|
if (referrerInfo !== undefined) {
|
|
@@ -459,6 +459,14 @@ class DriftClient {
|
|
|
459
459
|
isSigner: false,
|
|
460
460
|
});
|
|
461
461
|
}
|
|
462
|
+
if (name === undefined) {
|
|
463
|
+
if (subAccountId === 0) {
|
|
464
|
+
name = userName_1.DEFAULT_USER_NAME;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
name = `Subaccount ${subAccountId + 1}`;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
462
470
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
463
471
|
const initializeUserAccountIx = await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
464
472
|
accounts: {
|
|
@@ -727,8 +735,8 @@ class DriftClient {
|
|
|
727
735
|
getUserAccountAndSlot(subAccountId) {
|
|
728
736
|
return this.getUser(subAccountId).getUserAccountAndSlot();
|
|
729
737
|
}
|
|
730
|
-
getSpotPosition(marketIndex) {
|
|
731
|
-
return this.getUserAccount().spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
|
|
738
|
+
getSpotPosition(marketIndex, subAccountId) {
|
|
739
|
+
return this.getUserAccount(subAccountId).spotPositions.find((spotPosition) => spotPosition.marketIndex === marketIndex);
|
|
732
740
|
}
|
|
733
741
|
getQuoteAssetTokenAmount() {
|
|
734
742
|
return this.getTokenAmount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
@@ -902,13 +910,13 @@ class DriftClient {
|
|
|
902
910
|
perpMarketAccountMap,
|
|
903
911
|
};
|
|
904
912
|
}
|
|
905
|
-
getOrder(orderId) {
|
|
913
|
+
getOrder(orderId, subAccountId) {
|
|
906
914
|
var _a;
|
|
907
|
-
return (_a = this.getUserAccount()) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.orderId === orderId);
|
|
915
|
+
return (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.orderId === orderId);
|
|
908
916
|
}
|
|
909
|
-
getOrderByUserId(userOrderId) {
|
|
917
|
+
getOrderByUserId(userOrderId, subAccountId) {
|
|
910
918
|
var _a;
|
|
911
|
-
return (_a = this.getUserAccount()) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.userOrderId === userOrderId);
|
|
919
|
+
return (_a = this.getUserAccount(subAccountId)) === null || _a === void 0 ? void 0 : _a.orders.find((order) => order.userOrderId === userOrderId);
|
|
912
920
|
}
|
|
913
921
|
/**
|
|
914
922
|
* Get the associated token address for the given spot market
|
|
@@ -944,11 +952,11 @@ class DriftClient {
|
|
|
944
952
|
/**
|
|
945
953
|
* Deposit funds into the given spot market
|
|
946
954
|
*
|
|
947
|
-
* @param amount
|
|
948
|
-
* @param marketIndex
|
|
955
|
+
* @param amount to deposit
|
|
956
|
+
* @param marketIndex spot market index to deposit into
|
|
949
957
|
* @param associatedTokenAccount can be the wallet public key if using native sol
|
|
950
|
-
* @param subAccountId
|
|
951
|
-
* @param reduceOnly
|
|
958
|
+
* @param subAccountId subaccountId to deposit
|
|
959
|
+
* @param reduceOnly if true, deposit must not increase account risk
|
|
952
960
|
*/
|
|
953
961
|
async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false) {
|
|
954
962
|
const additionalSigners = [];
|
|
@@ -1055,7 +1063,7 @@ class DriftClient {
|
|
|
1055
1063
|
* @param fromSubAccountId
|
|
1056
1064
|
* @returns
|
|
1057
1065
|
*/
|
|
1058
|
-
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name
|
|
1066
|
+
async initializeUserAccountAndDepositCollateral(amount, userTokenAccount, marketIndex = 0, subAccountId = 0, name, fromSubAccountId, referrerInfo, txParams) {
|
|
1059
1067
|
var _a;
|
|
1060
1068
|
const ixs = [];
|
|
1061
1069
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
@@ -1124,7 +1132,7 @@ class DriftClient {
|
|
|
1124
1132
|
* @param associatedTokenAddress - the token account to withdraw to. can be the wallet public key if using native sol
|
|
1125
1133
|
* @param reduceOnly
|
|
1126
1134
|
*/
|
|
1127
|
-
async withdraw(amount, marketIndex, associatedTokenAddress, reduceOnly = false) {
|
|
1135
|
+
async withdraw(amount, marketIndex, associatedTokenAddress, reduceOnly = false, subAccountId) {
|
|
1128
1136
|
const withdrawIxs = [];
|
|
1129
1137
|
const additionalSigners = [];
|
|
1130
1138
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -1143,7 +1151,7 @@ class DriftClient {
|
|
|
1143
1151
|
withdrawIxs.push(createAssociatedTokenAccountIx);
|
|
1144
1152
|
}
|
|
1145
1153
|
}
|
|
1146
|
-
const withdrawCollateralIx = await this.getWithdrawIx(amount, spotMarketAccount.marketIndex, associatedTokenAddress, reduceOnly);
|
|
1154
|
+
const withdrawCollateralIx = await this.getWithdrawIx(amount, spotMarketAccount.marketIndex, associatedTokenAddress, reduceOnly, subAccountId);
|
|
1147
1155
|
withdrawIxs.push(withdrawCollateralIx);
|
|
1148
1156
|
// Close the wrapped sol account at the end of the transaction
|
|
1149
1157
|
if (createWSOLTokenAccount) {
|
|
@@ -1156,10 +1164,10 @@ class DriftClient {
|
|
|
1156
1164
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
1157
1165
|
return txSig;
|
|
1158
1166
|
}
|
|
1159
|
-
async getWithdrawIx(amount, marketIndex, userTokenAccount, reduceOnly = false) {
|
|
1160
|
-
const
|
|
1167
|
+
async getWithdrawIx(amount, marketIndex, userTokenAccount, reduceOnly = false, subAccountId) {
|
|
1168
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1161
1169
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1162
|
-
userAccounts: [this.getUserAccount()],
|
|
1170
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1163
1171
|
useMarketLastSlotCache: true,
|
|
1164
1172
|
writableSpotMarketIndexes: [marketIndex],
|
|
1165
1173
|
readableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
@@ -1171,7 +1179,7 @@ class DriftClient {
|
|
|
1171
1179
|
spotMarket: spotMarketAccount.pubkey,
|
|
1172
1180
|
spotMarketVault: spotMarketAccount.vault,
|
|
1173
1181
|
driftSigner: this.getSignerPublicKey(),
|
|
1174
|
-
user
|
|
1182
|
+
user,
|
|
1175
1183
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
1176
1184
|
userTokenAccount: userTokenAccount,
|
|
1177
1185
|
authority: this.wallet.publicKey,
|
|
@@ -1262,8 +1270,8 @@ class DriftClient {
|
|
|
1262
1270
|
remainingAccounts: remainingAccounts,
|
|
1263
1271
|
});
|
|
1264
1272
|
}
|
|
1265
|
-
async removePerpLpShares(marketIndex, sharesToBurn, txParams) {
|
|
1266
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn), txParams), [], this.opts);
|
|
1273
|
+
async removePerpLpShares(marketIndex, sharesToBurn, txParams, subAccountId) {
|
|
1274
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn, subAccountId), txParams), [], this.opts);
|
|
1267
1275
|
return txSig;
|
|
1268
1276
|
}
|
|
1269
1277
|
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn, txParams) {
|
|
@@ -1290,15 +1298,15 @@ class DriftClient {
|
|
|
1290
1298
|
remainingAccounts: remainingAccounts,
|
|
1291
1299
|
});
|
|
1292
1300
|
}
|
|
1293
|
-
async getRemovePerpLpSharesIx(marketIndex, sharesToBurn) {
|
|
1294
|
-
const
|
|
1301
|
+
async getRemovePerpLpSharesIx(marketIndex, sharesToBurn, subAccountId) {
|
|
1302
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1295
1303
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1296
|
-
userAccounts: [this.getUserAccount()],
|
|
1304
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1297
1305
|
useMarketLastSlotCache: true,
|
|
1298
1306
|
writablePerpMarketIndexes: [marketIndex],
|
|
1299
1307
|
});
|
|
1300
1308
|
if (sharesToBurn == undefined) {
|
|
1301
|
-
const userAccount = this.getUserAccount();
|
|
1309
|
+
const userAccount = this.getUserAccount(subAccountId);
|
|
1302
1310
|
const perpPosition = userAccount.perpPositions.filter((position) => position.marketIndex === marketIndex)[0];
|
|
1303
1311
|
sharesToBurn = perpPosition.lpShares;
|
|
1304
1312
|
console.log('burning lp shares:', sharesToBurn.toString());
|
|
@@ -1306,28 +1314,28 @@ class DriftClient {
|
|
|
1306
1314
|
return this.program.instruction.removePerpLpShares(sharesToBurn, marketIndex, {
|
|
1307
1315
|
accounts: {
|
|
1308
1316
|
state: await this.getStatePublicKey(),
|
|
1309
|
-
user
|
|
1317
|
+
user,
|
|
1310
1318
|
authority: this.wallet.publicKey,
|
|
1311
1319
|
},
|
|
1312
1320
|
remainingAccounts: remainingAccounts,
|
|
1313
1321
|
});
|
|
1314
1322
|
}
|
|
1315
|
-
async addPerpLpShares(amount, marketIndex, txParams) {
|
|
1316
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getAddPerpLpSharesIx(amount, marketIndex), txParams), [], this.opts);
|
|
1323
|
+
async addPerpLpShares(amount, marketIndex, txParams, subAccountId) {
|
|
1324
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getAddPerpLpSharesIx(amount, marketIndex, subAccountId), txParams), [], this.opts);
|
|
1317
1325
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1318
1326
|
return txSig;
|
|
1319
1327
|
}
|
|
1320
|
-
async getAddPerpLpSharesIx(amount, marketIndex) {
|
|
1321
|
-
const
|
|
1328
|
+
async getAddPerpLpSharesIx(amount, marketIndex, subAccountId) {
|
|
1329
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1322
1330
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1323
|
-
userAccounts: [this.getUserAccount()],
|
|
1331
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1324
1332
|
useMarketLastSlotCache: true,
|
|
1325
1333
|
writablePerpMarketIndexes: [marketIndex],
|
|
1326
1334
|
});
|
|
1327
1335
|
return this.program.instruction.addPerpLpShares(amount, marketIndex, {
|
|
1328
1336
|
accounts: {
|
|
1329
1337
|
state: await this.getStatePublicKey(),
|
|
1330
|
-
user
|
|
1338
|
+
user,
|
|
1331
1339
|
authority: this.wallet.publicKey,
|
|
1332
1340
|
},
|
|
1333
1341
|
remainingAccounts: remainingAccounts,
|
|
@@ -1349,14 +1357,14 @@ class DriftClient {
|
|
|
1349
1357
|
/**
|
|
1350
1358
|
* @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
|
|
1351
1359
|
*/
|
|
1352
|
-
async openPosition(direction, amount, marketIndex, limitPrice) {
|
|
1360
|
+
async openPosition(direction, amount, marketIndex, limitPrice, subAccountId) {
|
|
1353
1361
|
return await this.placeAndTakePerpOrder({
|
|
1354
1362
|
orderType: types_1.OrderType.MARKET,
|
|
1355
1363
|
marketIndex,
|
|
1356
1364
|
direction,
|
|
1357
1365
|
baseAssetAmount: amount,
|
|
1358
1366
|
price: limitPrice,
|
|
1359
|
-
});
|
|
1367
|
+
}, undefined, undefined, undefined, subAccountId);
|
|
1360
1368
|
}
|
|
1361
1369
|
async sendSignedTx(tx) {
|
|
1362
1370
|
const { txSig } = await this.sendTransaction(tx, undefined, this.opts, true);
|
|
@@ -1377,15 +1385,15 @@ class DriftClient {
|
|
|
1377
1385
|
const marketIndex = orderParams.marketIndex;
|
|
1378
1386
|
const orderId = userAccount.nextOrderId;
|
|
1379
1387
|
const bracketOrderIxs = [];
|
|
1380
|
-
const placePerpOrderIx = await this.getPlacePerpOrderIx(orderParams);
|
|
1388
|
+
const placePerpOrderIx = await this.getPlacePerpOrderIx(orderParams, userAccount.subAccountId);
|
|
1381
1389
|
for (const bracketOrderParams of bracketOrdersParams) {
|
|
1382
|
-
const placeBracketOrderIx = await this.getPlacePerpOrderIx(bracketOrderParams);
|
|
1390
|
+
const placeBracketOrderIx = await this.getPlacePerpOrderIx(bracketOrderParams, userAccount.subAccountId);
|
|
1383
1391
|
bracketOrderIxs.push(placeBracketOrderIx);
|
|
1384
1392
|
}
|
|
1385
1393
|
let cancelOrdersIx;
|
|
1386
1394
|
let cancelExistingOrdersTx;
|
|
1387
1395
|
if (cancelExistingOrders && (0, types_1.isVariant)(orderParams.marketType, 'perp')) {
|
|
1388
|
-
cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null);
|
|
1396
|
+
cancelOrdersIx = await this.getCancelOrdersIx(orderParams.marketType, orderParams.marketIndex, null, userAccount.subAccountId);
|
|
1389
1397
|
//@ts-ignore
|
|
1390
1398
|
cancelExistingOrdersTx = await this.buildTransaction([cancelOrdersIx], txParams, this.txVersion);
|
|
1391
1399
|
}
|
|
@@ -1395,7 +1403,7 @@ class DriftClient {
|
|
|
1395
1403
|
const fillPerpOrderIx = await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1396
1404
|
orderId,
|
|
1397
1405
|
marketIndex,
|
|
1398
|
-
}, makerInfo, referrerInfo);
|
|
1406
|
+
}, makerInfo, referrerInfo, userAccount.subAccountId);
|
|
1399
1407
|
const versionedFillTx = await this.buildTransaction([fillPerpOrderIx], txParams, 0);
|
|
1400
1408
|
const [signedVersionedMarketOrderTx, signedVersionedFillTx, signedCancelExistingOrdersTx,] = await this.provider.wallet.signAllTransactions([
|
|
1401
1409
|
versionedMarketOrderTx,
|
|
@@ -1431,23 +1439,23 @@ class DriftClient {
|
|
|
1431
1439
|
return { txSig, signedFillTx: undefined, signedCancelExistingOrdersTx };
|
|
1432
1440
|
}
|
|
1433
1441
|
}
|
|
1434
|
-
async placePerpOrder(orderParams, txParams) {
|
|
1435
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlacePerpOrderIx(orderParams), txParams), [], this.opts);
|
|
1442
|
+
async placePerpOrder(orderParams, txParams, subAccountId) {
|
|
1443
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlacePerpOrderIx(orderParams, subAccountId), txParams), [], this.opts);
|
|
1436
1444
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1437
1445
|
return txSig;
|
|
1438
1446
|
}
|
|
1439
|
-
async getPlacePerpOrderIx(orderParams) {
|
|
1447
|
+
async getPlacePerpOrderIx(orderParams, subAccountId) {
|
|
1440
1448
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
1441
|
-
const
|
|
1449
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1442
1450
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1443
|
-
userAccounts: [this.getUserAccount()],
|
|
1451
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1444
1452
|
useMarketLastSlotCache: true,
|
|
1445
1453
|
readablePerpMarketIndex: orderParams.marketIndex,
|
|
1446
1454
|
});
|
|
1447
1455
|
return await this.program.instruction.placePerpOrder(orderParams, {
|
|
1448
1456
|
accounts: {
|
|
1449
1457
|
state: await this.getStatePublicKey(),
|
|
1450
|
-
user
|
|
1458
|
+
user,
|
|
1451
1459
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
1452
1460
|
authority: this.wallet.publicKey,
|
|
1453
1461
|
},
|
|
@@ -1537,72 +1545,72 @@ class DriftClient {
|
|
|
1537
1545
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(ix, txParams), [], this.opts);
|
|
1538
1546
|
return txSig;
|
|
1539
1547
|
}
|
|
1540
|
-
async cancelOrder(orderId, txParams) {
|
|
1541
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderIx(orderId), txParams), [], this.opts);
|
|
1548
|
+
async cancelOrder(orderId, txParams, subAccountId) {
|
|
1549
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderIx(orderId, subAccountId), txParams), [], this.opts);
|
|
1542
1550
|
return txSig;
|
|
1543
1551
|
}
|
|
1544
|
-
async getCancelOrderIx(orderId) {
|
|
1545
|
-
const
|
|
1552
|
+
async getCancelOrderIx(orderId, subAccountId) {
|
|
1553
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1546
1554
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1547
|
-
userAccounts: [this.getUserAccount()],
|
|
1555
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1548
1556
|
useMarketLastSlotCache: true,
|
|
1549
1557
|
});
|
|
1550
1558
|
return await this.program.instruction.cancelOrder(orderId !== null && orderId !== void 0 ? orderId : null, {
|
|
1551
1559
|
accounts: {
|
|
1552
1560
|
state: await this.getStatePublicKey(),
|
|
1553
|
-
user
|
|
1561
|
+
user,
|
|
1554
1562
|
authority: this.wallet.publicKey,
|
|
1555
1563
|
},
|
|
1556
1564
|
remainingAccounts,
|
|
1557
1565
|
});
|
|
1558
1566
|
}
|
|
1559
|
-
async cancelOrderByUserId(userOrderId, txParams) {
|
|
1560
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderByUserIdIx(userOrderId), txParams), [], this.opts);
|
|
1567
|
+
async cancelOrderByUserId(userOrderId, txParams, subAccountId) {
|
|
1568
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrderByUserIdIx(userOrderId, subAccountId), txParams), [], this.opts);
|
|
1561
1569
|
return txSig;
|
|
1562
1570
|
}
|
|
1563
|
-
async getCancelOrderByUserIdIx(userOrderId) {
|
|
1564
|
-
const
|
|
1571
|
+
async getCancelOrderByUserIdIx(userOrderId, subAccountId) {
|
|
1572
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1565
1573
|
const order = this.getOrderByUserId(userOrderId);
|
|
1566
1574
|
const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle;
|
|
1567
1575
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1568
|
-
userAccounts: [this.getUserAccount()],
|
|
1576
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1569
1577
|
useMarketLastSlotCache: true,
|
|
1570
1578
|
});
|
|
1571
1579
|
return await this.program.instruction.cancelOrderByUserId(userOrderId, {
|
|
1572
1580
|
accounts: {
|
|
1573
1581
|
state: await this.getStatePublicKey(),
|
|
1574
|
-
user
|
|
1582
|
+
user,
|
|
1575
1583
|
authority: this.wallet.publicKey,
|
|
1576
1584
|
oracle,
|
|
1577
1585
|
},
|
|
1578
1586
|
remainingAccounts,
|
|
1579
1587
|
});
|
|
1580
1588
|
}
|
|
1581
|
-
async cancelOrdersByIds(orderIds, txParams) {
|
|
1582
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersByIdsIx(orderIds), txParams), [], this.opts);
|
|
1589
|
+
async cancelOrdersByIds(orderIds, txParams, subAccountId) {
|
|
1590
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersByIdsIx(orderIds, subAccountId), txParams), [], this.opts);
|
|
1583
1591
|
return txSig;
|
|
1584
1592
|
}
|
|
1585
|
-
async getCancelOrdersByIdsIx(orderIds) {
|
|
1586
|
-
const
|
|
1593
|
+
async getCancelOrdersByIdsIx(orderIds, subAccountId) {
|
|
1594
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1587
1595
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1588
|
-
userAccounts: [this.getUserAccount()],
|
|
1596
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1589
1597
|
useMarketLastSlotCache: true,
|
|
1590
1598
|
});
|
|
1591
1599
|
return await this.program.instruction.cancelOrdersByIds(orderIds, {
|
|
1592
1600
|
accounts: {
|
|
1593
1601
|
state: await this.getStatePublicKey(),
|
|
1594
|
-
user
|
|
1602
|
+
user,
|
|
1595
1603
|
authority: this.wallet.publicKey,
|
|
1596
1604
|
},
|
|
1597
1605
|
remainingAccounts,
|
|
1598
1606
|
});
|
|
1599
1607
|
}
|
|
1600
|
-
async cancelOrders(marketType, marketIndex, direction, txParams) {
|
|
1601
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersIx(marketType, marketIndex, direction), txParams), [], this.opts);
|
|
1608
|
+
async cancelOrders(marketType, marketIndex, direction, txParams, subAccountId) {
|
|
1609
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getCancelOrdersIx(marketType, marketIndex, direction, subAccountId), txParams), [], this.opts);
|
|
1602
1610
|
return txSig;
|
|
1603
1611
|
}
|
|
1604
|
-
async getCancelOrdersIx(marketType, marketIndex, direction) {
|
|
1605
|
-
const
|
|
1612
|
+
async getCancelOrdersIx(marketType, marketIndex, direction, subAccountId) {
|
|
1613
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1606
1614
|
let readablePerpMarketIndex = undefined;
|
|
1607
1615
|
let readableSpotMarketIndexes = undefined;
|
|
1608
1616
|
if (typeof marketIndex === 'number') {
|
|
@@ -1614,7 +1622,7 @@ class DriftClient {
|
|
|
1614
1622
|
}
|
|
1615
1623
|
}
|
|
1616
1624
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1617
|
-
userAccounts: [this.getUserAccount()],
|
|
1625
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1618
1626
|
readablePerpMarketIndex,
|
|
1619
1627
|
readableSpotMarketIndexes,
|
|
1620
1628
|
useMarketLastSlotCache: true,
|
|
@@ -1622,27 +1630,27 @@ class DriftClient {
|
|
|
1622
1630
|
return await this.program.instruction.cancelOrders(marketType !== null && marketType !== void 0 ? marketType : null, marketIndex !== null && marketIndex !== void 0 ? marketIndex : null, direction !== null && direction !== void 0 ? direction : null, {
|
|
1623
1631
|
accounts: {
|
|
1624
1632
|
state: await this.getStatePublicKey(),
|
|
1625
|
-
user
|
|
1633
|
+
user,
|
|
1626
1634
|
authority: this.wallet.publicKey,
|
|
1627
1635
|
},
|
|
1628
1636
|
remainingAccounts,
|
|
1629
1637
|
});
|
|
1630
1638
|
}
|
|
1631
|
-
async cancelAndPlaceOrders(cancelOrderParams, placeOrderParams, txParams) {
|
|
1639
|
+
async cancelAndPlaceOrders(cancelOrderParams, placeOrderParams, txParams, subAccountId) {
|
|
1632
1640
|
const ixs = [
|
|
1633
|
-
await this.getCancelOrdersIx(cancelOrderParams.marketType, cancelOrderParams.marketIndex, cancelOrderParams.direction),
|
|
1634
|
-
await this.getPlaceOrdersIx(placeOrderParams),
|
|
1641
|
+
await this.getCancelOrdersIx(cancelOrderParams.marketType, cancelOrderParams.marketIndex, cancelOrderParams.direction, subAccountId),
|
|
1642
|
+
await this.getPlaceOrdersIx(placeOrderParams, subAccountId),
|
|
1635
1643
|
];
|
|
1636
1644
|
const tx = await this.buildTransaction(ixs, txParams);
|
|
1637
1645
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1638
1646
|
return txSig;
|
|
1639
1647
|
}
|
|
1640
|
-
async placeOrders(params, txParams) {
|
|
1641
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceOrdersIx(params), txParams), [], this.opts);
|
|
1648
|
+
async placeOrders(params, txParams, subAccountId) {
|
|
1649
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceOrdersIx(params, subAccountId), txParams), [], this.opts);
|
|
1642
1650
|
return txSig;
|
|
1643
1651
|
}
|
|
1644
|
-
async getPlaceOrdersIx(params) {
|
|
1645
|
-
const
|
|
1652
|
+
async getPlaceOrdersIx(params, subAccountId) {
|
|
1653
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
1646
1654
|
const readablePerpMarketIndex = [];
|
|
1647
1655
|
const readableSpotMarketIndexes = [];
|
|
1648
1656
|
for (const param of params) {
|
|
@@ -1657,7 +1665,7 @@ class DriftClient {
|
|
|
1657
1665
|
}
|
|
1658
1666
|
}
|
|
1659
1667
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1660
|
-
userAccounts: [this.getUserAccount()],
|
|
1668
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1661
1669
|
readablePerpMarketIndex,
|
|
1662
1670
|
readableSpotMarketIndexes,
|
|
1663
1671
|
useMarketLastSlotCache: true,
|
|
@@ -1665,20 +1673,20 @@ class DriftClient {
|
|
|
1665
1673
|
return await this.program.instruction.placeOrders(params, {
|
|
1666
1674
|
accounts: {
|
|
1667
1675
|
state: await this.getStatePublicKey(),
|
|
1668
|
-
user
|
|
1676
|
+
user,
|
|
1669
1677
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
1670
1678
|
authority: this.wallet.publicKey,
|
|
1671
1679
|
},
|
|
1672
1680
|
remainingAccounts,
|
|
1673
1681
|
});
|
|
1674
1682
|
}
|
|
1675
|
-
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams) {
|
|
1676
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams), [], this.opts);
|
|
1683
|
+
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams, fillerPublicKey) {
|
|
1684
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo, fillerPublicKey), txParams), [], this.opts);
|
|
1677
1685
|
return txSig;
|
|
1678
1686
|
}
|
|
1679
|
-
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
|
|
1687
|
+
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo, fillerSubAccountId) {
|
|
1680
1688
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
1681
|
-
const
|
|
1689
|
+
const filler = await this.getUserAccountPublicKey(fillerSubAccountId);
|
|
1682
1690
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1683
1691
|
const marketIndex = order
|
|
1684
1692
|
? order.marketIndex
|
|
@@ -1728,7 +1736,7 @@ class DriftClient {
|
|
|
1728
1736
|
return await this.program.instruction.fillPerpOrder(orderId, null, {
|
|
1729
1737
|
accounts: {
|
|
1730
1738
|
state: await this.getStatePublicKey(),
|
|
1731
|
-
filler
|
|
1739
|
+
filler,
|
|
1732
1740
|
fillerStats: fillerStatsPublicKey,
|
|
1733
1741
|
user: userAccountPublicKey,
|
|
1734
1742
|
userStats: userStatsPublicKey,
|
|
@@ -1737,29 +1745,29 @@ class DriftClient {
|
|
|
1737
1745
|
remainingAccounts,
|
|
1738
1746
|
});
|
|
1739
1747
|
}
|
|
1740
|
-
async getRevertFillIx() {
|
|
1741
|
-
const
|
|
1748
|
+
async getRevertFillIx(fillerPublicKey) {
|
|
1749
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
1742
1750
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1743
1751
|
return this.program.instruction.revertFill({
|
|
1744
1752
|
accounts: {
|
|
1745
1753
|
state: await this.getStatePublicKey(),
|
|
1746
|
-
filler
|
|
1754
|
+
filler,
|
|
1747
1755
|
fillerStats: fillerStatsPublicKey,
|
|
1748
1756
|
authority: this.wallet.publicKey,
|
|
1749
1757
|
},
|
|
1750
1758
|
});
|
|
1751
1759
|
}
|
|
1752
|
-
async placeSpotOrder(orderParams, txParams) {
|
|
1753
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceSpotOrderIx(orderParams), txParams), [], this.opts);
|
|
1760
|
+
async placeSpotOrder(orderParams, txParams, subAccountId) {
|
|
1761
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceSpotOrderIx(orderParams, subAccountId), txParams), [], this.opts);
|
|
1754
1762
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1755
1763
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1756
1764
|
return txSig;
|
|
1757
1765
|
}
|
|
1758
|
-
async getPlaceSpotOrderIx(orderParams) {
|
|
1766
|
+
async getPlaceSpotOrderIx(orderParams, subAccountId) {
|
|
1759
1767
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
1760
|
-
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1768
|
+
const userAccountPublicKey = await this.getUserAccountPublicKey(subAccountId);
|
|
1761
1769
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1762
|
-
userAccounts: [this.getUserAccount()],
|
|
1770
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
1763
1771
|
useMarketLastSlotCache: true,
|
|
1764
1772
|
readableSpotMarketIndexes: [
|
|
1765
1773
|
orderParams.marketIndex,
|
|
@@ -1780,9 +1788,9 @@ class DriftClient {
|
|
|
1780
1788
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getFillSpotOrderIx(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo), txParams), [], this.opts);
|
|
1781
1789
|
return txSig;
|
|
1782
1790
|
}
|
|
1783
|
-
async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1791
|
+
async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo, fillerPublicKey) {
|
|
1784
1792
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
1785
|
-
const
|
|
1793
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
1786
1794
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1787
1795
|
const marketIndex = order
|
|
1788
1796
|
? order.marketIndex
|
|
@@ -1825,7 +1833,7 @@ class DriftClient {
|
|
|
1825
1833
|
return await this.program.instruction.fillSpotOrder(orderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, makerOrderId, {
|
|
1826
1834
|
accounts: {
|
|
1827
1835
|
state: await this.getStatePublicKey(),
|
|
1828
|
-
filler
|
|
1836
|
+
filler,
|
|
1829
1837
|
fillerStats: fillerStatsPublicKey,
|
|
1830
1838
|
user: userAccountPublicKey,
|
|
1831
1839
|
userStats: userStatsPublicKey,
|
|
@@ -2266,12 +2274,12 @@ class DriftClient {
|
|
|
2266
2274
|
ixs.push(beginSwapIx, closeWSOLIx, depositIx, createWSOLIx, endSwapIx);
|
|
2267
2275
|
return ixs;
|
|
2268
2276
|
}
|
|
2269
|
-
async triggerOrder(userAccountPublicKey, user, order, txParams) {
|
|
2270
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams), [], this.opts);
|
|
2277
|
+
async triggerOrder(userAccountPublicKey, user, order, txParams, fillerPublicKey) {
|
|
2278
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getTriggerOrderIx(userAccountPublicKey, user, order, fillerPublicKey), txParams), [], this.opts);
|
|
2271
2279
|
return txSig;
|
|
2272
2280
|
}
|
|
2273
|
-
async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
|
|
2274
|
-
const
|
|
2281
|
+
async getTriggerOrderIx(userAccountPublicKey, userAccount, order, fillerPublicKey) {
|
|
2282
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
2275
2283
|
let remainingAccountsParams;
|
|
2276
2284
|
if ((0, types_1.isVariant)(order.marketType, 'perp')) {
|
|
2277
2285
|
remainingAccountsParams = {
|
|
@@ -2290,19 +2298,19 @@ class DriftClient {
|
|
|
2290
2298
|
return await this.program.instruction.triggerOrder(orderId, {
|
|
2291
2299
|
accounts: {
|
|
2292
2300
|
state: await this.getStatePublicKey(),
|
|
2293
|
-
filler
|
|
2301
|
+
filler,
|
|
2294
2302
|
user: userAccountPublicKey,
|
|
2295
2303
|
authority: this.wallet.publicKey,
|
|
2296
2304
|
},
|
|
2297
2305
|
remainingAccounts,
|
|
2298
2306
|
});
|
|
2299
2307
|
}
|
|
2300
|
-
async forceCancelOrders(userAccountPublicKey, user, txParams) {
|
|
2301
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getForceCancelOrdersIx(userAccountPublicKey, user), txParams), [], this.opts);
|
|
2308
|
+
async forceCancelOrders(userAccountPublicKey, user, txParams, fillerPublicKey) {
|
|
2309
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getForceCancelOrdersIx(userAccountPublicKey, user, fillerPublicKey), txParams), [], this.opts);
|
|
2302
2310
|
return txSig;
|
|
2303
2311
|
}
|
|
2304
|
-
async getForceCancelOrdersIx(userAccountPublicKey, userAccount) {
|
|
2305
|
-
const
|
|
2312
|
+
async getForceCancelOrdersIx(userAccountPublicKey, userAccount, fillerPublicKey) {
|
|
2313
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
2306
2314
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2307
2315
|
userAccounts: [userAccount],
|
|
2308
2316
|
writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
@@ -2310,66 +2318,66 @@ class DriftClient {
|
|
|
2310
2318
|
return await this.program.instruction.forceCancelOrders({
|
|
2311
2319
|
accounts: {
|
|
2312
2320
|
state: await this.getStatePublicKey(),
|
|
2313
|
-
filler
|
|
2321
|
+
filler,
|
|
2314
2322
|
user: userAccountPublicKey,
|
|
2315
2323
|
authority: this.wallet.publicKey,
|
|
2316
2324
|
},
|
|
2317
2325
|
remainingAccounts,
|
|
2318
2326
|
});
|
|
2319
2327
|
}
|
|
2320
|
-
async updateUserIdle(userAccountPublicKey, user, txParams) {
|
|
2321
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserIdleIx(userAccountPublicKey, user), txParams), [], this.opts);
|
|
2328
|
+
async updateUserIdle(userAccountPublicKey, user, txParams, fillerPublicKey) {
|
|
2329
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserIdleIx(userAccountPublicKey, user, fillerPublicKey), txParams), [], this.opts);
|
|
2322
2330
|
return txSig;
|
|
2323
2331
|
}
|
|
2324
|
-
async getUpdateUserIdleIx(userAccountPublicKey, userAccount) {
|
|
2325
|
-
const
|
|
2332
|
+
async getUpdateUserIdleIx(userAccountPublicKey, userAccount, fillerPublicKey) {
|
|
2333
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
2326
2334
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2327
2335
|
userAccounts: [userAccount],
|
|
2328
2336
|
});
|
|
2329
2337
|
return await this.program.instruction.updateUserIdle({
|
|
2330
2338
|
accounts: {
|
|
2331
2339
|
state: await this.getStatePublicKey(),
|
|
2332
|
-
filler
|
|
2340
|
+
filler,
|
|
2333
2341
|
user: userAccountPublicKey,
|
|
2334
2342
|
authority: this.wallet.publicKey,
|
|
2335
2343
|
},
|
|
2336
2344
|
remainingAccounts,
|
|
2337
2345
|
});
|
|
2338
2346
|
}
|
|
2339
|
-
async updateUserOpenOrdersCount(userAccountPublicKey, user, txParams) {
|
|
2340
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserOpenOrdersCountIx(userAccountPublicKey, user), txParams), [], this.opts);
|
|
2347
|
+
async updateUserOpenOrdersCount(userAccountPublicKey, user, txParams, fillerPublicKey) {
|
|
2348
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getUpdateUserOpenOrdersCountIx(userAccountPublicKey, user, fillerPublicKey), txParams), [], this.opts);
|
|
2341
2349
|
return txSig;
|
|
2342
2350
|
}
|
|
2343
|
-
async getUpdateUserOpenOrdersCountIx(userAccountPublicKey, userAccount) {
|
|
2344
|
-
const
|
|
2351
|
+
async getUpdateUserOpenOrdersCountIx(userAccountPublicKey, userAccount, fillerPublicKey) {
|
|
2352
|
+
const filler = fillerPublicKey !== null && fillerPublicKey !== void 0 ? fillerPublicKey : (await this.getUserAccountPublicKey());
|
|
2345
2353
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2346
2354
|
userAccounts: [userAccount],
|
|
2347
2355
|
});
|
|
2348
2356
|
return await this.program.instruction.updateUserOpenOrdersCount({
|
|
2349
2357
|
accounts: {
|
|
2350
2358
|
state: await this.getStatePublicKey(),
|
|
2351
|
-
filler
|
|
2359
|
+
filler,
|
|
2352
2360
|
user: userAccountPublicKey,
|
|
2353
2361
|
authority: this.wallet.publicKey,
|
|
2354
2362
|
},
|
|
2355
2363
|
remainingAccounts,
|
|
2356
2364
|
});
|
|
2357
2365
|
}
|
|
2358
|
-
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams) {
|
|
2359
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo), txParams), [], this.opts);
|
|
2366
|
+
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
2367
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId), txParams), [], this.opts);
|
|
2360
2368
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2361
2369
|
return txSig;
|
|
2362
2370
|
}
|
|
2363
|
-
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo) {
|
|
2371
|
+
async getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo, subAccountId) {
|
|
2364
2372
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
2365
2373
|
const userStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2366
|
-
const
|
|
2374
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2367
2375
|
makerInfo = Array.isArray(makerInfo)
|
|
2368
2376
|
? makerInfo
|
|
2369
2377
|
: makerInfo
|
|
2370
2378
|
? [makerInfo]
|
|
2371
2379
|
: [];
|
|
2372
|
-
const userAccounts = [this.getUserAccount()];
|
|
2380
|
+
const userAccounts = [this.getUserAccount(subAccountId)];
|
|
2373
2381
|
for (const maker of makerInfo) {
|
|
2374
2382
|
userAccounts.push(maker.makerUserAccount);
|
|
2375
2383
|
}
|
|
@@ -2409,24 +2417,27 @@ class DriftClient {
|
|
|
2409
2417
|
return await this.program.instruction.placeAndTakePerpOrder(orderParams, null, {
|
|
2410
2418
|
accounts: {
|
|
2411
2419
|
state: await this.getStatePublicKey(),
|
|
2412
|
-
user
|
|
2420
|
+
user,
|
|
2413
2421
|
userStats: userStatsPublicKey,
|
|
2414
2422
|
authority: this.wallet.publicKey,
|
|
2415
2423
|
},
|
|
2416
2424
|
remainingAccounts,
|
|
2417
2425
|
});
|
|
2418
2426
|
}
|
|
2419
|
-
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams) {
|
|
2420
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo), txParams), [], this.opts);
|
|
2427
|
+
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams, subAccountId) {
|
|
2428
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo, subAccountId), txParams), [], this.opts);
|
|
2421
2429
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2422
2430
|
return txSig;
|
|
2423
2431
|
}
|
|
2424
|
-
async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo) {
|
|
2432
|
+
async getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo, subAccountId) {
|
|
2425
2433
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.PERP });
|
|
2426
2434
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2427
|
-
const
|
|
2435
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2428
2436
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2429
|
-
userAccounts: [
|
|
2437
|
+
userAccounts: [
|
|
2438
|
+
this.getUserAccount(subAccountId),
|
|
2439
|
+
takerInfo.takerUserAccount,
|
|
2440
|
+
],
|
|
2430
2441
|
useMarketLastSlotCache: true,
|
|
2431
2442
|
writablePerpMarketIndexes: [orderParams.marketIndex],
|
|
2432
2443
|
});
|
|
@@ -2446,7 +2457,7 @@ class DriftClient {
|
|
|
2446
2457
|
return await this.program.instruction.placeAndMakePerpOrder(orderParams, takerOrderId, {
|
|
2447
2458
|
accounts: {
|
|
2448
2459
|
state: await this.getStatePublicKey(),
|
|
2449
|
-
user
|
|
2460
|
+
user,
|
|
2450
2461
|
userStats: userStatsPublicKey,
|
|
2451
2462
|
taker: takerInfo.taker,
|
|
2452
2463
|
takerStats: takerInfo.takerStats,
|
|
@@ -2455,17 +2466,17 @@ class DriftClient {
|
|
|
2455
2466
|
remainingAccounts,
|
|
2456
2467
|
});
|
|
2457
2468
|
}
|
|
2458
|
-
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
2459
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo), txParams), [], this.opts);
|
|
2469
|
+
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams, subAccountId) {
|
|
2470
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo, subAccountId), txParams), [], this.opts);
|
|
2460
2471
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2461
2472
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
2462
2473
|
return txSig;
|
|
2463
2474
|
}
|
|
2464
|
-
async getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
2475
|
+
async getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo, subAccountId) {
|
|
2465
2476
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
2466
|
-
const userStatsPublicKey =
|
|
2467
|
-
const
|
|
2468
|
-
const userAccounts = [this.getUserAccount()];
|
|
2477
|
+
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2478
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2479
|
+
const userAccounts = [this.getUserAccount(subAccountId)];
|
|
2469
2480
|
if (makerInfo !== undefined) {
|
|
2470
2481
|
userAccounts.push(makerInfo.makerUserAccount);
|
|
2471
2482
|
}
|
|
@@ -2507,25 +2518,28 @@ class DriftClient {
|
|
|
2507
2518
|
return await this.program.instruction.placeAndTakeSpotOrder(orderParams, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, makerOrderId, {
|
|
2508
2519
|
accounts: {
|
|
2509
2520
|
state: await this.getStatePublicKey(),
|
|
2510
|
-
user
|
|
2521
|
+
user,
|
|
2511
2522
|
userStats: userStatsPublicKey,
|
|
2512
2523
|
authority: this.wallet.publicKey,
|
|
2513
2524
|
},
|
|
2514
2525
|
remainingAccounts,
|
|
2515
2526
|
});
|
|
2516
2527
|
}
|
|
2517
|
-
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo, txParams) {
|
|
2518
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo), txParams), [], this.opts);
|
|
2528
|
+
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo, txParams, subAccountId) {
|
|
2529
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo, subAccountId), txParams), [], this.opts);
|
|
2519
2530
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2520
2531
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
2521
2532
|
return txSig;
|
|
2522
2533
|
}
|
|
2523
|
-
async getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
|
|
2534
|
+
async getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo, subAccountId) {
|
|
2524
2535
|
orderParams = (0, orderParams_1.getOrderParams)(orderParams, { marketType: types_1.MarketType.SPOT });
|
|
2525
2536
|
const userStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2526
|
-
const
|
|
2537
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2527
2538
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2528
|
-
userAccounts: [
|
|
2539
|
+
userAccounts: [
|
|
2540
|
+
this.getUserAccount(subAccountId),
|
|
2541
|
+
takerInfo.takerUserAccount,
|
|
2542
|
+
],
|
|
2529
2543
|
useMarketLastSlotCache: true,
|
|
2530
2544
|
writableSpotMarketIndexes: [
|
|
2531
2545
|
orderParams.marketIndex,
|
|
@@ -2549,7 +2563,7 @@ class DriftClient {
|
|
|
2549
2563
|
return await this.program.instruction.placeAndMakeSpotOrder(orderParams, takerOrderId, fulfillmentConfig ? fulfillmentConfig.fulfillmentType : null, {
|
|
2550
2564
|
accounts: {
|
|
2551
2565
|
state: await this.getStatePublicKey(),
|
|
2552
|
-
user
|
|
2566
|
+
user,
|
|
2553
2567
|
userStats: userStatsPublicKey,
|
|
2554
2568
|
taker: takerInfo.taker,
|
|
2555
2569
|
takerStats: takerInfo.takerStats,
|
|
@@ -2561,8 +2575,8 @@ class DriftClient {
|
|
|
2561
2575
|
/**
|
|
2562
2576
|
* @deprecated use {@link placePerpOrder} or {@link placeAndTakePerpOrder} instead
|
|
2563
2577
|
*/
|
|
2564
|
-
async closePosition(marketIndex, limitPrice) {
|
|
2565
|
-
const userPosition = this.getUser().getPerpPosition(marketIndex);
|
|
2578
|
+
async closePosition(marketIndex, limitPrice, subAccountId) {
|
|
2579
|
+
const userPosition = this.getUser(subAccountId).getPerpPosition(marketIndex);
|
|
2566
2580
|
if (!userPosition) {
|
|
2567
2581
|
throw Error(`No position in market ${marketIndex.toString()}`);
|
|
2568
2582
|
}
|
|
@@ -2573,7 +2587,7 @@ class DriftClient {
|
|
|
2573
2587
|
baseAssetAmount: userPosition.baseAssetAmount.abs(),
|
|
2574
2588
|
reduceOnly: true,
|
|
2575
2589
|
price: limitPrice,
|
|
2576
|
-
});
|
|
2590
|
+
}, undefined, undefined, undefined, subAccountId);
|
|
2577
2591
|
}
|
|
2578
2592
|
/**
|
|
2579
2593
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
@@ -2627,14 +2641,14 @@ class DriftClient {
|
|
|
2627
2641
|
* @param orderParams.maxTs:
|
|
2628
2642
|
* @returns
|
|
2629
2643
|
*/
|
|
2630
|
-
async modifyOrder(orderParams, txParams) {
|
|
2631
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderIx(orderParams), txParams), [], this.opts);
|
|
2644
|
+
async modifyOrder(orderParams, txParams, subAccountId) {
|
|
2645
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderIx(orderParams, subAccountId), txParams), [], this.opts);
|
|
2632
2646
|
return txSig;
|
|
2633
2647
|
}
|
|
2634
|
-
async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }) {
|
|
2635
|
-
const
|
|
2648
|
+
async getModifyOrderIx({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }, subAccountId) {
|
|
2649
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2636
2650
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2637
|
-
userAccounts: [this.getUserAccount()],
|
|
2651
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2638
2652
|
useMarketLastSlotCache: true,
|
|
2639
2653
|
});
|
|
2640
2654
|
const orderParams = {
|
|
@@ -2656,7 +2670,7 @@ class DriftClient {
|
|
|
2656
2670
|
return await this.program.instruction.modifyOrder(orderId, orderParams, {
|
|
2657
2671
|
accounts: {
|
|
2658
2672
|
state: await this.getStatePublicKey(),
|
|
2659
|
-
user
|
|
2673
|
+
user,
|
|
2660
2674
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2661
2675
|
authority: this.wallet.publicKey,
|
|
2662
2676
|
},
|
|
@@ -2681,14 +2695,14 @@ class DriftClient {
|
|
|
2681
2695
|
* @param orderParams.maxTs:
|
|
2682
2696
|
* @returns
|
|
2683
2697
|
*/
|
|
2684
|
-
async modifyOrderByUserOrderId(orderParams, txParams) {
|
|
2685
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderByUserIdIx(orderParams), txParams), [], this.opts);
|
|
2698
|
+
async modifyOrderByUserOrderId(orderParams, txParams, subAccountId) {
|
|
2699
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getModifyOrderByUserIdIx(orderParams, subAccountId), txParams), [], this.opts);
|
|
2686
2700
|
return txSig;
|
|
2687
2701
|
}
|
|
2688
|
-
async getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }) {
|
|
2689
|
-
const
|
|
2702
|
+
async getModifyOrderByUserIdIx({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, policy, }, subAccountId) {
|
|
2703
|
+
const user = await this.getUserAccountPublicKey(subAccountId);
|
|
2690
2704
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2691
|
-
userAccounts: [this.getUserAccount()],
|
|
2705
|
+
userAccounts: [this.getUserAccount(subAccountId)],
|
|
2692
2706
|
useMarketLastSlotCache: true,
|
|
2693
2707
|
});
|
|
2694
2708
|
const orderParams = {
|
|
@@ -2710,7 +2724,7 @@ class DriftClient {
|
|
|
2710
2724
|
return await this.program.instruction.modifyOrderByUserId(userOrderId, orderParams, {
|
|
2711
2725
|
accounts: {
|
|
2712
2726
|
state: await this.getStatePublicKey(),
|
|
2713
|
-
user
|
|
2727
|
+
user,
|
|
2714
2728
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
2715
2729
|
authority: this.wallet.publicKey,
|
|
2716
2730
|
},
|
|
@@ -2752,17 +2766,17 @@ class DriftClient {
|
|
|
2752
2766
|
remainingAccounts: remainingAccounts,
|
|
2753
2767
|
});
|
|
2754
2768
|
}
|
|
2755
|
-
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams) {
|
|
2756
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice), txParams), [], this.opts);
|
|
2769
|
+
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams, liquidatorSubAccountId) {
|
|
2770
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2757
2771
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
2758
2772
|
return txSig;
|
|
2759
2773
|
}
|
|
2760
|
-
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
2774
|
+
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, liquidatorSubAccountId) {
|
|
2761
2775
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2762
|
-
const
|
|
2776
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2763
2777
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2764
2778
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2765
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2779
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2766
2780
|
useMarketLastSlotCache: true,
|
|
2767
2781
|
writablePerpMarketIndexes: [marketIndex],
|
|
2768
2782
|
});
|
|
@@ -2772,24 +2786,24 @@ class DriftClient {
|
|
|
2772
2786
|
authority: this.wallet.publicKey,
|
|
2773
2787
|
user: userAccountPublicKey,
|
|
2774
2788
|
userStats: userStatsPublicKey,
|
|
2775
|
-
liquidator
|
|
2789
|
+
liquidator,
|
|
2776
2790
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2777
2791
|
},
|
|
2778
2792
|
remainingAccounts: remainingAccounts,
|
|
2779
2793
|
});
|
|
2780
2794
|
}
|
|
2781
|
-
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
2782
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams), [], this.opts);
|
|
2795
|
+
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
2796
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2783
2797
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
2784
2798
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
2785
2799
|
return txSig;
|
|
2786
2800
|
}
|
|
2787
|
-
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
2801
|
+
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId) {
|
|
2788
2802
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2789
|
-
const
|
|
2790
|
-
const liquidatorStatsPublicKey =
|
|
2803
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2804
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2791
2805
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2792
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2806
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2793
2807
|
useMarketLastSlotCache: true,
|
|
2794
2808
|
writableSpotMarketIndexes: [liabilityMarketIndex, assetMarketIndex],
|
|
2795
2809
|
});
|
|
@@ -2799,24 +2813,24 @@ class DriftClient {
|
|
|
2799
2813
|
authority: this.wallet.publicKey,
|
|
2800
2814
|
user: userAccountPublicKey,
|
|
2801
2815
|
userStats: userStatsPublicKey,
|
|
2802
|
-
liquidator
|
|
2816
|
+
liquidator,
|
|
2803
2817
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2804
2818
|
},
|
|
2805
2819
|
remainingAccounts: remainingAccounts,
|
|
2806
2820
|
});
|
|
2807
2821
|
}
|
|
2808
|
-
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
2809
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams), [], this.opts);
|
|
2822
|
+
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
2823
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2810
2824
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
2811
2825
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
2812
2826
|
return txSig;
|
|
2813
2827
|
}
|
|
2814
|
-
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
2828
|
+
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, liquidatorSubAccountId) {
|
|
2815
2829
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2816
|
-
const
|
|
2817
|
-
const liquidatorStatsPublicKey =
|
|
2830
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2831
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2818
2832
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2819
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2833
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2820
2834
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
2821
2835
|
writableSpotMarketIndexes: [liabilityMarketIndex],
|
|
2822
2836
|
});
|
|
@@ -2826,24 +2840,24 @@ class DriftClient {
|
|
|
2826
2840
|
authority: this.wallet.publicKey,
|
|
2827
2841
|
user: userAccountPublicKey,
|
|
2828
2842
|
userStats: userStatsPublicKey,
|
|
2829
|
-
liquidator
|
|
2843
|
+
liquidator,
|
|
2830
2844
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2831
2845
|
},
|
|
2832
2846
|
remainingAccounts: remainingAccounts,
|
|
2833
2847
|
});
|
|
2834
2848
|
}
|
|
2835
|
-
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams) {
|
|
2836
|
-
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice), txParams), [], this.opts);
|
|
2849
|
+
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams, liquidatorSubAccountId) {
|
|
2850
|
+
const { txSig, slot } = await this.sendTransaction(await this.buildTransaction(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2837
2851
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
2838
2852
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
2839
2853
|
return txSig;
|
|
2840
2854
|
}
|
|
2841
|
-
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
2855
|
+
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, liquidatorSubAccountId) {
|
|
2842
2856
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2843
|
-
const
|
|
2844
|
-
const liquidatorStatsPublicKey =
|
|
2857
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2858
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2845
2859
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2846
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2860
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2847
2861
|
writablePerpMarketIndexes: [perpMarketIndex],
|
|
2848
2862
|
writableSpotMarketIndexes: [assetMarketIndex],
|
|
2849
2863
|
});
|
|
@@ -2853,22 +2867,22 @@ class DriftClient {
|
|
|
2853
2867
|
authority: this.wallet.publicKey,
|
|
2854
2868
|
user: userAccountPublicKey,
|
|
2855
2869
|
userStats: userStatsPublicKey,
|
|
2856
|
-
liquidator
|
|
2870
|
+
liquidator,
|
|
2857
2871
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2858
2872
|
},
|
|
2859
2873
|
remainingAccounts: remainingAccounts,
|
|
2860
2874
|
});
|
|
2861
2875
|
}
|
|
2862
|
-
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2863
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams), [], this.opts);
|
|
2876
|
+
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams, liquidatorSubAccountId) {
|
|
2877
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2864
2878
|
return txSig;
|
|
2865
2879
|
}
|
|
2866
|
-
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
2880
|
+
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex, liquidatorSubAccountId) {
|
|
2867
2881
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2868
|
-
const
|
|
2869
|
-
const liquidatorStatsPublicKey =
|
|
2882
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2883
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2870
2884
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2871
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2885
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2872
2886
|
writablePerpMarketIndexes: [marketIndex],
|
|
2873
2887
|
writableSpotMarketIndexes: [numericConstants_1.QUOTE_SPOT_MARKET_INDEX],
|
|
2874
2888
|
});
|
|
@@ -2879,7 +2893,7 @@ class DriftClient {
|
|
|
2879
2893
|
authority: this.wallet.publicKey,
|
|
2880
2894
|
user: userAccountPublicKey,
|
|
2881
2895
|
userStats: userStatsPublicKey,
|
|
2882
|
-
liquidator
|
|
2896
|
+
liquidator,
|
|
2883
2897
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2884
2898
|
spotMarketVault: spotMarket.vault,
|
|
2885
2899
|
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
@@ -2889,16 +2903,16 @@ class DriftClient {
|
|
|
2889
2903
|
remainingAccounts: remainingAccounts,
|
|
2890
2904
|
});
|
|
2891
2905
|
}
|
|
2892
|
-
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2893
|
-
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams), [], this.opts);
|
|
2906
|
+
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams, liquidatorSubAccountId) {
|
|
2907
|
+
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex, liquidatorSubAccountId), txParams), [], this.opts);
|
|
2894
2908
|
return txSig;
|
|
2895
2909
|
}
|
|
2896
|
-
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
2910
|
+
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex, liquidatorSubAccountId) {
|
|
2897
2911
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2898
|
-
const
|
|
2899
|
-
const liquidatorStatsPublicKey =
|
|
2912
|
+
const liquidator = await this.getUserAccountPublicKey(liquidatorSubAccountId);
|
|
2913
|
+
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
2900
2914
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2901
|
-
userAccounts: [this.getUserAccount(), userAccount],
|
|
2915
|
+
userAccounts: [this.getUserAccount(liquidatorSubAccountId), userAccount],
|
|
2902
2916
|
writableSpotMarketIndexes: [marketIndex],
|
|
2903
2917
|
});
|
|
2904
2918
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2909,7 +2923,7 @@ class DriftClient {
|
|
|
2909
2923
|
user: userAccountPublicKey,
|
|
2910
2924
|
userStats: userStatsPublicKey,
|
|
2911
2925
|
liquidatorStats: liquidatorStatsPublicKey,
|
|
2912
|
-
liquidator
|
|
2926
|
+
liquidator,
|
|
2913
2927
|
spotMarketVault: spotMarket.vault,
|
|
2914
2928
|
insuranceFundVault: spotMarket.insuranceFund.vault,
|
|
2915
2929
|
driftSigner: this.getSignerPublicKey(),
|