@drift-labs/sdk 2.12.0-beta.2 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/bulkAccountLoader.js +3 -3
- package/lib/accounts/fetch.js +2 -2
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.js +1 -5
- package/lib/adminClient.js +57 -61
- package/lib/dlob/DLOB.d.ts +8 -8
- package/lib/dlob/DLOB.js +91 -84
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.d.ts +3 -3
- package/lib/driftClient.js +83 -87
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +9 -9
- package/lib/factory/oracleClient.js +2 -2
- package/lib/idl/drift.json +1 -1
- package/lib/index.js +1 -5
- package/lib/math/amm.js +23 -23
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +5 -5
- package/lib/math/market.js +12 -12
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +23 -23
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +7 -7
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +35 -3
- package/lib/math/trade.js +225 -47
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/tokenFaucet.js +1 -5
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +7 -4
- package/lib/types.d.ts +4 -0
- package/lib/user.js +47 -47
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +34 -26
- package/src/driftClient.ts +11 -4
- package/src/idl/drift.json +1 -1
- package/src/math/trade.ts +322 -16
- package/src/tx/utils.ts +11 -3
- package/src/types.ts +5 -0
- package/tests/dlob/test.ts +307 -38
package/lib/driftClient.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
5
|
}) : (function(o, m, k, k2) {
|
|
10
6
|
if (k2 === undefined) k2 = k;
|
|
11
7
|
o[k2] = m[k];
|
|
@@ -80,7 +76,7 @@ class DriftClient {
|
|
|
80
76
|
if (config.userStats) {
|
|
81
77
|
this.userStats = new userStats_1.UserStats({
|
|
82
78
|
driftClient: this,
|
|
83
|
-
userStatsAccountPublicKey:
|
|
79
|
+
userStatsAccountPublicKey: pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority),
|
|
84
80
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
85
81
|
});
|
|
86
82
|
}
|
|
@@ -88,7 +84,7 @@ class DriftClient {
|
|
|
88
84
|
let spotMarketIndexes = config.spotMarketIndexes;
|
|
89
85
|
let oracleInfos = config.oracleInfos;
|
|
90
86
|
if (config.env) {
|
|
91
|
-
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos: envOracleInfos, } =
|
|
87
|
+
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos: envOracleInfos, } = config_1.getMarketsAndOraclesForSubscription(config.env);
|
|
92
88
|
perpMarketIndexes = perpMarketIndexes
|
|
93
89
|
? perpMarketIndexes
|
|
94
90
|
: envPerpMarketIndexes;
|
|
@@ -119,7 +115,7 @@ class DriftClient {
|
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
createUser(subAccountId, accountSubscriptionConfig) {
|
|
122
|
-
const userAccountPublicKey =
|
|
118
|
+
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.authority, subAccountId);
|
|
123
119
|
return new user_1.User({
|
|
124
120
|
driftClient: this,
|
|
125
121
|
userAccountPublicKey,
|
|
@@ -164,14 +160,14 @@ class DriftClient {
|
|
|
164
160
|
if (this.statePublicKey) {
|
|
165
161
|
return this.statePublicKey;
|
|
166
162
|
}
|
|
167
|
-
this.statePublicKey = await
|
|
163
|
+
this.statePublicKey = await pda_1.getDriftStateAccountPublicKey(this.program.programId);
|
|
168
164
|
return this.statePublicKey;
|
|
169
165
|
}
|
|
170
166
|
getSignerPublicKey() {
|
|
171
167
|
if (this.signerPublicKey) {
|
|
172
168
|
return this.signerPublicKey;
|
|
173
169
|
}
|
|
174
|
-
this.signerPublicKey =
|
|
170
|
+
this.signerPublicKey = pda_1.getDriftSignerPublicKey(this.program.programId);
|
|
175
171
|
return this.signerPublicKey;
|
|
176
172
|
}
|
|
177
173
|
getStateAccount() {
|
|
@@ -232,7 +228,7 @@ class DriftClient {
|
|
|
232
228
|
return this.accountSubscriber.getOraclePriceDataAndSlot(oraclePublicKey);
|
|
233
229
|
}
|
|
234
230
|
async getSerumV3FulfillmentConfig(serumMarket) {
|
|
235
|
-
const address = await
|
|
231
|
+
const address = await pda_1.getSerumFulfillmentConfigPublicKey(this.program.programId, serumMarket);
|
|
236
232
|
return (await this.program.account.serumV3FulfillmentConfig.fetch(address));
|
|
237
233
|
}
|
|
238
234
|
/**
|
|
@@ -256,7 +252,7 @@ class DriftClient {
|
|
|
256
252
|
await this.userStats.unsubscribe();
|
|
257
253
|
this.userStats = new userStats_1.UserStats({
|
|
258
254
|
driftClient: this,
|
|
259
|
-
userStatsAccountPublicKey:
|
|
255
|
+
userStatsAccountPublicKey: pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority),
|
|
260
256
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
261
257
|
});
|
|
262
258
|
}
|
|
@@ -296,7 +292,7 @@ class DriftClient {
|
|
|
296
292
|
return [txSig, userAccountPublicKey];
|
|
297
293
|
}
|
|
298
294
|
async getInitializeUserInstructions(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, referrerInfo) {
|
|
299
|
-
const userAccountPublicKey = await
|
|
295
|
+
const userAccountPublicKey = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
300
296
|
const remainingAccounts = new Array();
|
|
301
297
|
if (referrerInfo !== undefined) {
|
|
302
298
|
remainingAccounts.push({
|
|
@@ -319,7 +315,7 @@ class DriftClient {
|
|
|
319
315
|
isSigner: false,
|
|
320
316
|
});
|
|
321
317
|
}
|
|
322
|
-
const nameBuffer =
|
|
318
|
+
const nameBuffer = userName_1.encodeName(name);
|
|
323
319
|
const initializeUserAccountIx = await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
324
320
|
accounts: {
|
|
325
321
|
user: userAccountPublicKey,
|
|
@@ -347,8 +343,8 @@ class DriftClient {
|
|
|
347
343
|
});
|
|
348
344
|
}
|
|
349
345
|
async updateUserName(name, subAccountId = 0) {
|
|
350
|
-
const userAccountPublicKey =
|
|
351
|
-
const nameBuffer =
|
|
346
|
+
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
347
|
+
const nameBuffer = userName_1.encodeName(name);
|
|
352
348
|
const tx = await this.program.transaction.updateUserName(subAccountId, nameBuffer, {
|
|
353
349
|
accounts: {
|
|
354
350
|
user: userAccountPublicKey,
|
|
@@ -369,7 +365,7 @@ class DriftClient {
|
|
|
369
365
|
return txSig;
|
|
370
366
|
}
|
|
371
367
|
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
|
|
372
|
-
const userAccountPublicKey =
|
|
368
|
+
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
373
369
|
const tx = await this.program.transaction.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled, {
|
|
374
370
|
accounts: {
|
|
375
371
|
user: userAccountPublicKey,
|
|
@@ -415,7 +411,7 @@ class DriftClient {
|
|
|
415
411
|
}
|
|
416
412
|
async deleteUser(subAccountId = 0) {
|
|
417
413
|
var _a;
|
|
418
|
-
const userAccountPublicKey =
|
|
414
|
+
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
419
415
|
const ix = await this.program.instruction.deleteUser({
|
|
420
416
|
accounts: {
|
|
421
417
|
user: userAccountPublicKey,
|
|
@@ -424,7 +420,7 @@ class DriftClient {
|
|
|
424
420
|
state: await this.getStatePublicKey(),
|
|
425
421
|
},
|
|
426
422
|
});
|
|
427
|
-
const { txSig } = await this.sendTransaction(
|
|
423
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix), [], this.opts);
|
|
428
424
|
await ((_a = this.users.get(subAccountId)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
|
|
429
425
|
this.users.delete(subAccountId);
|
|
430
426
|
return txSig;
|
|
@@ -446,7 +442,7 @@ class DriftClient {
|
|
|
446
442
|
if (this.userStatsAccountPublicKey) {
|
|
447
443
|
return this.userStatsAccountPublicKey;
|
|
448
444
|
}
|
|
449
|
-
this.userStatsAccountPublicKey =
|
|
445
|
+
this.userStatsAccountPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority);
|
|
450
446
|
return this.userStatsAccountPublicKey;
|
|
451
447
|
}
|
|
452
448
|
async getUserAccountPublicKey() {
|
|
@@ -472,7 +468,7 @@ class DriftClient {
|
|
|
472
468
|
getQuoteAssetTokenAmount() {
|
|
473
469
|
const spotMarket = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
474
470
|
const spotPosition = this.getSpotPosition(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
475
|
-
return
|
|
471
|
+
return spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
476
472
|
}
|
|
477
473
|
getTokenAmount(marketIndex) {
|
|
478
474
|
const spotPosition = this.getSpotPosition(marketIndex);
|
|
@@ -480,7 +476,7 @@ class DriftClient {
|
|
|
480
476
|
return numericConstants_1.ZERO;
|
|
481
477
|
}
|
|
482
478
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
483
|
-
return
|
|
479
|
+
return spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
484
480
|
}
|
|
485
481
|
getRemainingAccounts(params) {
|
|
486
482
|
var _a;
|
|
@@ -604,7 +600,7 @@ class DriftClient {
|
|
|
604
600
|
const perpMarketAccountMap = new Map();
|
|
605
601
|
for (const userAccount of userAccounts) {
|
|
606
602
|
for (const spotPosition of userAccount.spotPositions) {
|
|
607
|
-
if (!
|
|
603
|
+
if (!spotPosition_1.isSpotPositionAvailable(spotPosition)) {
|
|
608
604
|
const spotMarket = this.getSpotMarketAccount(spotPosition.marketIndex);
|
|
609
605
|
spotMarketAccountMap.set(spotPosition.marketIndex, {
|
|
610
606
|
pubkey: spotMarket.pubkey,
|
|
@@ -629,7 +625,7 @@ class DriftClient {
|
|
|
629
625
|
}
|
|
630
626
|
}
|
|
631
627
|
for (const position of userAccount.perpPositions) {
|
|
632
|
-
if (!
|
|
628
|
+
if (!position_1.positionIsAvailable(position)) {
|
|
633
629
|
const market = this.getPerpMarketAccount(position.marketIndex);
|
|
634
630
|
perpMarketAccountMap.set(position.marketIndex, {
|
|
635
631
|
pubkey: market.pubkey,
|
|
@@ -689,7 +685,7 @@ class DriftClient {
|
|
|
689
685
|
}
|
|
690
686
|
async getDepositInstruction(amount, marketIndex, userTokenAccount, subAccountId, reduceOnly = false, userInitialized = true) {
|
|
691
687
|
const userAccountPublicKey = subAccountId
|
|
692
|
-
? await
|
|
688
|
+
? await pda_1.getUserAccountPublicKey(this.program.programId, this.authority, subAccountId)
|
|
693
689
|
: await this.getUserAccountPublicKey();
|
|
694
690
|
let remainingAccounts = [];
|
|
695
691
|
if (userInitialized) {
|
|
@@ -875,7 +871,7 @@ class DriftClient {
|
|
|
875
871
|
});
|
|
876
872
|
}
|
|
877
873
|
async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId) {
|
|
878
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
874
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId)), [], this.opts);
|
|
879
875
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
880
876
|
toSubAccountId === this.activeSubAccountId) {
|
|
881
877
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
@@ -883,8 +879,8 @@ class DriftClient {
|
|
|
883
879
|
return txSig;
|
|
884
880
|
}
|
|
885
881
|
async getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId) {
|
|
886
|
-
const fromUser = await
|
|
887
|
-
const toUser = await
|
|
882
|
+
const fromUser = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, fromSubAccountId);
|
|
883
|
+
const toUser = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
888
884
|
let remainingAccounts;
|
|
889
885
|
if (this.users.has(fromSubAccountId)) {
|
|
890
886
|
remainingAccounts = this.getRemainingAccounts({
|
|
@@ -894,7 +890,7 @@ class DriftClient {
|
|
|
894
890
|
});
|
|
895
891
|
}
|
|
896
892
|
else {
|
|
897
|
-
const userAccountPublicKey =
|
|
893
|
+
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.authority, fromSubAccountId);
|
|
898
894
|
const fromUserAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
899
895
|
remainingAccounts = this.getRemainingAccounts({
|
|
900
896
|
userAccounts: [fromUserAccount],
|
|
@@ -915,7 +911,7 @@ class DriftClient {
|
|
|
915
911
|
});
|
|
916
912
|
}
|
|
917
913
|
async updateSpotMarketCumulativeInterest(marketIndex) {
|
|
918
|
-
const { txSig } = await this.sendTransaction(
|
|
914
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.updateSpotMarketCumulativeInterestIx(marketIndex)), [], this.opts);
|
|
919
915
|
return txSig;
|
|
920
916
|
}
|
|
921
917
|
async updateSpotMarketCumulativeInterestIx(marketIndex) {
|
|
@@ -929,7 +925,7 @@ class DriftClient {
|
|
|
929
925
|
});
|
|
930
926
|
}
|
|
931
927
|
async settleLP(settleeUserAccountPublicKey, marketIndex) {
|
|
932
|
-
const { txSig } = await this.sendTransaction(
|
|
928
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex)), [], this.opts);
|
|
933
929
|
return txSig;
|
|
934
930
|
}
|
|
935
931
|
async settleLPIx(settleeUserAccountPublicKey, marketIndex) {
|
|
@@ -947,11 +943,11 @@ class DriftClient {
|
|
|
947
943
|
});
|
|
948
944
|
}
|
|
949
945
|
async removePerpLpShares(marketIndex, sharesToBurn) {
|
|
950
|
-
const { txSig } = await this.sendTransaction(
|
|
946
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn)), [], this.opts);
|
|
951
947
|
return txSig;
|
|
952
948
|
}
|
|
953
949
|
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
954
|
-
const { txSig } = await this.sendTransaction(
|
|
950
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn)), [], this.opts);
|
|
955
951
|
return txSig;
|
|
956
952
|
}
|
|
957
953
|
async getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
@@ -997,7 +993,7 @@ class DriftClient {
|
|
|
997
993
|
});
|
|
998
994
|
}
|
|
999
995
|
async addPerpLpShares(amount, marketIndex) {
|
|
1000
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
996
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getAddPerpLpSharesIx(amount, marketIndex)), [], this.opts);
|
|
1001
997
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1002
998
|
return txSig;
|
|
1003
999
|
}
|
|
@@ -1041,8 +1037,8 @@ class DriftClient {
|
|
|
1041
1037
|
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo) {
|
|
1042
1038
|
const marketIndex = orderParams.marketIndex;
|
|
1043
1039
|
const orderId = userAccount.nextOrderId;
|
|
1044
|
-
const marketOrderTx =
|
|
1045
|
-
const fillTx =
|
|
1040
|
+
const marketOrderTx = utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams));
|
|
1041
|
+
const fillTx = utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1046
1042
|
orderId,
|
|
1047
1043
|
marketIndex,
|
|
1048
1044
|
}, makerInfo));
|
|
@@ -1058,7 +1054,7 @@ class DriftClient {
|
|
|
1058
1054
|
return { txSig, signedFillTx };
|
|
1059
1055
|
}
|
|
1060
1056
|
async placePerpOrder(orderParams) {
|
|
1061
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1057
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams)), [], this.opts);
|
|
1062
1058
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1063
1059
|
return txSig;
|
|
1064
1060
|
}
|
|
@@ -1086,7 +1082,7 @@ class DriftClient {
|
|
|
1086
1082
|
});
|
|
1087
1083
|
}
|
|
1088
1084
|
async updateAMMs(marketIndexes) {
|
|
1089
|
-
const { txSig } = await this.sendTransaction(
|
|
1085
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
|
|
1090
1086
|
return txSig;
|
|
1091
1087
|
}
|
|
1092
1088
|
async getUpdateAMMsIx(marketIndexes) {
|
|
@@ -1120,7 +1116,7 @@ class DriftClient {
|
|
|
1120
1116
|
});
|
|
1121
1117
|
}
|
|
1122
1118
|
async settleExpiredMarket(marketIndex) {
|
|
1123
|
-
const { txSig } = await this.sendTransaction(
|
|
1119
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleExpiredMarketIx(marketIndex)), [], this.opts);
|
|
1124
1120
|
return txSig;
|
|
1125
1121
|
}
|
|
1126
1122
|
async getSettleExpiredMarketIx(marketIndex) {
|
|
@@ -1155,8 +1151,8 @@ class DriftClient {
|
|
|
1155
1151
|
});
|
|
1156
1152
|
}
|
|
1157
1153
|
async settleExpiredMarketPoolsToRevenuePool(perpMarketIndex) {
|
|
1158
|
-
const perpMarketPublicKey = await
|
|
1159
|
-
const spotMarketPublicKey = await
|
|
1154
|
+
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
1155
|
+
const spotMarketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
1160
1156
|
const ix = await this.program.instruction.settleExpiredMarketPoolsToRevenuePool({
|
|
1161
1157
|
accounts: {
|
|
1162
1158
|
state: await this.getStatePublicKey(),
|
|
@@ -1165,11 +1161,11 @@ class DriftClient {
|
|
|
1165
1161
|
perpMarket: perpMarketPublicKey,
|
|
1166
1162
|
},
|
|
1167
1163
|
});
|
|
1168
|
-
const { txSig } = await this.sendTransaction(
|
|
1164
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(ix), [], this.opts);
|
|
1169
1165
|
return txSig;
|
|
1170
1166
|
}
|
|
1171
1167
|
async cancelOrder(orderId) {
|
|
1172
|
-
const { txSig } = await this.sendTransaction(
|
|
1168
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderIx(orderId)), [], this.opts);
|
|
1173
1169
|
return txSig;
|
|
1174
1170
|
}
|
|
1175
1171
|
async getCancelOrderIx(orderId) {
|
|
@@ -1188,7 +1184,7 @@ class DriftClient {
|
|
|
1188
1184
|
});
|
|
1189
1185
|
}
|
|
1190
1186
|
async cancelOrderByUserId(userOrderId) {
|
|
1191
|
-
const { txSig } = await this.sendTransaction(
|
|
1187
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
|
|
1192
1188
|
return txSig;
|
|
1193
1189
|
}
|
|
1194
1190
|
async getCancelOrderByUserIdIx(userOrderId) {
|
|
@@ -1210,7 +1206,7 @@ class DriftClient {
|
|
|
1210
1206
|
});
|
|
1211
1207
|
}
|
|
1212
1208
|
async cancelOrders(marketType, marketIndex, direction) {
|
|
1213
|
-
const { txSig } = await this.sendTransaction(
|
|
1209
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrdersIx(marketType, marketIndex, direction)), [], this.opts);
|
|
1214
1210
|
return txSig;
|
|
1215
1211
|
}
|
|
1216
1212
|
async getCancelOrdersIx(marketType, marketIndex, direction) {
|
|
@@ -1218,10 +1214,10 @@ class DriftClient {
|
|
|
1218
1214
|
let readablePerpMarketIndex = undefined;
|
|
1219
1215
|
let readableSpotMarketIndexes = undefined;
|
|
1220
1216
|
if (marketIndex) {
|
|
1221
|
-
if (marketType &&
|
|
1217
|
+
if (marketType && types_1.isVariant(marketType, 'perp')) {
|
|
1222
1218
|
readablePerpMarketIndex = marketIndex;
|
|
1223
1219
|
}
|
|
1224
|
-
else if (marketType &&
|
|
1220
|
+
else if (marketType && types_1.isVariant(marketType, 'spot')) {
|
|
1225
1221
|
readableSpotMarketIndexes = [marketIndex];
|
|
1226
1222
|
}
|
|
1227
1223
|
}
|
|
@@ -1241,11 +1237,11 @@ class DriftClient {
|
|
|
1241
1237
|
});
|
|
1242
1238
|
}
|
|
1243
1239
|
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo) {
|
|
1244
|
-
const { txSig } = await this.sendTransaction(
|
|
1240
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo)), [], this.opts);
|
|
1245
1241
|
return txSig;
|
|
1246
1242
|
}
|
|
1247
1243
|
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
|
|
1248
|
-
const userStatsPublicKey =
|
|
1244
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1249
1245
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1250
1246
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1251
1247
|
const marketIndex = order
|
|
@@ -1298,7 +1294,7 @@ class DriftClient {
|
|
|
1298
1294
|
});
|
|
1299
1295
|
}
|
|
1300
1296
|
async placeSpotOrder(orderParams) {
|
|
1301
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1297
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceSpotOrderIx(orderParams)), [], this.opts);
|
|
1302
1298
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1303
1299
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1304
1300
|
return txSig;
|
|
@@ -1324,12 +1320,12 @@ class DriftClient {
|
|
|
1324
1320
|
remainingAccounts,
|
|
1325
1321
|
});
|
|
1326
1322
|
}
|
|
1327
|
-
async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1328
|
-
const { txSig } = await this.sendTransaction(
|
|
1323
|
+
async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1324
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getFillSpotOrderIx(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1329
1325
|
return txSig;
|
|
1330
1326
|
}
|
|
1331
1327
|
async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1332
|
-
const userStatsPublicKey =
|
|
1328
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1333
1329
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1334
1330
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1335
1331
|
const marketIndex = order
|
|
@@ -1451,7 +1447,7 @@ class DriftClient {
|
|
|
1451
1447
|
isSigner: false,
|
|
1452
1448
|
});
|
|
1453
1449
|
remainingAccounts.push({
|
|
1454
|
-
pubkey:
|
|
1450
|
+
pubkey: pda_1.getSerumSignerPublicKey(fulfillmentConfig.serumProgramId, fulfillmentConfig.serumMarket, fulfillmentConfig.serumSignerNonce),
|
|
1455
1451
|
isWritable: false,
|
|
1456
1452
|
isSigner: false,
|
|
1457
1453
|
});
|
|
@@ -1482,13 +1478,13 @@ class DriftClient {
|
|
|
1482
1478
|
});
|
|
1483
1479
|
}
|
|
1484
1480
|
async triggerOrder(userAccountPublicKey, user, order) {
|
|
1485
|
-
const { txSig } = await this.sendTransaction(
|
|
1481
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getTriggerOrderIx(userAccountPublicKey, user, order)), [], this.opts);
|
|
1486
1482
|
return txSig;
|
|
1487
1483
|
}
|
|
1488
1484
|
async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
|
|
1489
1485
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1490
1486
|
let remainingAccountsParams;
|
|
1491
|
-
if (
|
|
1487
|
+
if (types_1.isVariant(order.marketType, 'perp')) {
|
|
1492
1488
|
remainingAccountsParams = {
|
|
1493
1489
|
userAccounts: [userAccount],
|
|
1494
1490
|
writablePerpMarketIndexes: [order.marketIndex],
|
|
@@ -1513,7 +1509,7 @@ class DriftClient {
|
|
|
1513
1509
|
});
|
|
1514
1510
|
}
|
|
1515
1511
|
async forceCancelOrders(userAccountPublicKey, user) {
|
|
1516
|
-
const { txSig } = await this.txSender.send(
|
|
1512
|
+
const { txSig } = await this.txSender.send(utils_1.wrapInTx(await this.getForceCancelOrdersIx(userAccountPublicKey, user)), [], this.opts);
|
|
1517
1513
|
return txSig;
|
|
1518
1514
|
}
|
|
1519
1515
|
async getForceCancelOrdersIx(userAccountPublicKey, userAccount) {
|
|
@@ -1533,7 +1529,7 @@ class DriftClient {
|
|
|
1533
1529
|
});
|
|
1534
1530
|
}
|
|
1535
1531
|
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo) {
|
|
1536
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1532
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo)), [], this.opts);
|
|
1537
1533
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1538
1534
|
return txSig;
|
|
1539
1535
|
}
|
|
@@ -1587,7 +1583,7 @@ class DriftClient {
|
|
|
1587
1583
|
});
|
|
1588
1584
|
}
|
|
1589
1585
|
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo) {
|
|
1590
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1586
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo)), [], this.opts);
|
|
1591
1587
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1592
1588
|
return txSig;
|
|
1593
1589
|
}
|
|
@@ -1625,8 +1621,8 @@ class DriftClient {
|
|
|
1625
1621
|
remainingAccounts,
|
|
1626
1622
|
});
|
|
1627
1623
|
}
|
|
1628
|
-
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1629
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1624
|
+
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1625
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1630
1626
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1631
1627
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1632
1628
|
return txSig;
|
|
@@ -1685,7 +1681,7 @@ class DriftClient {
|
|
|
1685
1681
|
});
|
|
1686
1682
|
}
|
|
1687
1683
|
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
|
|
1688
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1684
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo)), [], this.opts);
|
|
1689
1685
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1690
1686
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1691
1687
|
return txSig;
|
|
@@ -1741,7 +1737,7 @@ class DriftClient {
|
|
|
1741
1737
|
return await this.placeAndTakePerpOrder({
|
|
1742
1738
|
orderType: types_1.OrderType.MARKET,
|
|
1743
1739
|
marketIndex,
|
|
1744
|
-
direction:
|
|
1740
|
+
direction: position_1.findDirectionToClose(userPosition),
|
|
1745
1741
|
baseAssetAmount: userPosition.baseAssetAmount.abs(),
|
|
1746
1742
|
reduceOnly: true,
|
|
1747
1743
|
price: limitPrice,
|
|
@@ -1809,7 +1805,7 @@ class DriftClient {
|
|
|
1809
1805
|
return txSig;
|
|
1810
1806
|
}
|
|
1811
1807
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
1812
|
-
const { txSig } = await this.sendTransaction(
|
|
1808
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex)), [], this.opts);
|
|
1813
1809
|
return txSig;
|
|
1814
1810
|
}
|
|
1815
1811
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -1829,12 +1825,12 @@ class DriftClient {
|
|
|
1829
1825
|
});
|
|
1830
1826
|
}
|
|
1831
1827
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1832
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1828
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice)), [], this.opts);
|
|
1833
1829
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1834
1830
|
return txSig;
|
|
1835
1831
|
}
|
|
1836
1832
|
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1837
|
-
const userStatsPublicKey =
|
|
1833
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1838
1834
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1839
1835
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1840
1836
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1855,13 +1851,13 @@ class DriftClient {
|
|
|
1855
1851
|
});
|
|
1856
1852
|
}
|
|
1857
1853
|
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1858
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1854
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1859
1855
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1860
1856
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1861
1857
|
return txSig;
|
|
1862
1858
|
}
|
|
1863
1859
|
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1864
|
-
const userStatsPublicKey =
|
|
1860
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1865
1861
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1866
1862
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1867
1863
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1882,13 +1878,13 @@ class DriftClient {
|
|
|
1882
1878
|
});
|
|
1883
1879
|
}
|
|
1884
1880
|
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1885
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1881
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1886
1882
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1887
1883
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1888
1884
|
return txSig;
|
|
1889
1885
|
}
|
|
1890
1886
|
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1891
|
-
const userStatsPublicKey =
|
|
1887
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1892
1888
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1893
1889
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1894
1890
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1909,13 +1905,13 @@ class DriftClient {
|
|
|
1909
1905
|
});
|
|
1910
1906
|
}
|
|
1911
1907
|
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
1912
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1908
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice)), [], this.opts);
|
|
1913
1909
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1914
1910
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1915
1911
|
return txSig;
|
|
1916
1912
|
}
|
|
1917
1913
|
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
1918
|
-
const userStatsPublicKey =
|
|
1914
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1919
1915
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1920
1916
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1921
1917
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1936,11 +1932,11 @@ class DriftClient {
|
|
|
1936
1932
|
});
|
|
1937
1933
|
}
|
|
1938
1934
|
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
1939
|
-
const { txSig } = await this.sendTransaction(
|
|
1935
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
1940
1936
|
return txSig;
|
|
1941
1937
|
}
|
|
1942
1938
|
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
1943
|
-
const userStatsPublicKey =
|
|
1939
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1944
1940
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1945
1941
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1946
1942
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1966,11 +1962,11 @@ class DriftClient {
|
|
|
1966
1962
|
});
|
|
1967
1963
|
}
|
|
1968
1964
|
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
1969
|
-
const { txSig } = await this.sendTransaction(
|
|
1965
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
1970
1966
|
return txSig;
|
|
1971
1967
|
}
|
|
1972
1968
|
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
1973
|
-
const userStatsPublicKey =
|
|
1969
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1974
1970
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1975
1971
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1976
1972
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1995,11 +1991,11 @@ class DriftClient {
|
|
|
1995
1991
|
});
|
|
1996
1992
|
}
|
|
1997
1993
|
async updateFundingRate(perpMarketIndex, oracle) {
|
|
1998
|
-
const { txSig } = await this.sendTransaction(
|
|
1994
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateFundingRateIx(perpMarketIndex, oracle)), [], this.opts);
|
|
1999
1995
|
return txSig;
|
|
2000
1996
|
}
|
|
2001
1997
|
async getUpdateFundingRateIx(perpMarketIndex, oracle) {
|
|
2002
|
-
const perpMarketPublicKey = await
|
|
1998
|
+
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
2003
1999
|
return await this.program.instruction.updateFundingRate(perpMarketIndex, {
|
|
2004
2000
|
accounts: {
|
|
2005
2001
|
state: await this.getStatePublicKey(),
|
|
@@ -2009,14 +2005,14 @@ class DriftClient {
|
|
|
2009
2005
|
});
|
|
2010
2006
|
}
|
|
2011
2007
|
async settleFundingPayment(userAccountPublicKey) {
|
|
2012
|
-
const { txSig } = await this.sendTransaction(
|
|
2008
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleFundingPaymentIx(userAccountPublicKey)), [], this.opts);
|
|
2013
2009
|
return txSig;
|
|
2014
2010
|
}
|
|
2015
2011
|
async getSettleFundingPaymentIx(userAccountPublicKey) {
|
|
2016
2012
|
const userAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
2017
2013
|
const writablePerpMarketIndexes = [];
|
|
2018
2014
|
for (const position of userAccount.perpPositions) {
|
|
2019
|
-
if (!
|
|
2015
|
+
if (!position_1.positionIsAvailable(position)) {
|
|
2020
2016
|
writablePerpMarketIndexes.push(position.marketIndex);
|
|
2021
2017
|
}
|
|
2022
2018
|
}
|
|
@@ -2046,11 +2042,11 @@ class DriftClient {
|
|
|
2046
2042
|
return oracleData;
|
|
2047
2043
|
}
|
|
2048
2044
|
async initializeInsuranceFundStake(marketIndex) {
|
|
2049
|
-
const { txSig } = await this.sendTransaction(
|
|
2045
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getInitializeInsuranceFundStakeIx(marketIndex)), [], this.opts);
|
|
2050
2046
|
return txSig;
|
|
2051
2047
|
}
|
|
2052
2048
|
async getInitializeInsuranceFundStakeIx(marketIndex) {
|
|
2053
|
-
const ifStakeAccountPublicKey =
|
|
2049
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2054
2050
|
return await this.program.instruction.initializeInsuranceFundStake(marketIndex, {
|
|
2055
2051
|
accounts: {
|
|
2056
2052
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
@@ -2066,7 +2062,7 @@ class DriftClient {
|
|
|
2066
2062
|
}
|
|
2067
2063
|
async addInsuranceFundStake(marketIndex, amount, collateralAccountPublicKey) {
|
|
2068
2064
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
2069
|
-
const ifStakeAccountPublicKey =
|
|
2065
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2070
2066
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2071
2067
|
userAccounts: [this.getUserAccount()],
|
|
2072
2068
|
useMarketLastSlotCache: true,
|
|
@@ -2092,7 +2088,7 @@ class DriftClient {
|
|
|
2092
2088
|
}
|
|
2093
2089
|
async requestRemoveInsuranceFundStake(marketIndex, amount) {
|
|
2094
2090
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2095
|
-
const ifStakeAccountPublicKey =
|
|
2091
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2096
2092
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2097
2093
|
userAccounts: [this.getUserAccount()],
|
|
2098
2094
|
useMarketLastSlotCache: true,
|
|
@@ -2114,7 +2110,7 @@ class DriftClient {
|
|
|
2114
2110
|
}
|
|
2115
2111
|
async cancelRequestRemoveInsuranceFundStake(marketIndex) {
|
|
2116
2112
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2117
|
-
const ifStakeAccountPublicKey =
|
|
2113
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2118
2114
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2119
2115
|
userAccounts: [this.getUserAccount()],
|
|
2120
2116
|
useMarketLastSlotCache: true,
|
|
@@ -2136,7 +2132,7 @@ class DriftClient {
|
|
|
2136
2132
|
}
|
|
2137
2133
|
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
2138
2134
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2139
|
-
const ifStakeAccountPublicKey =
|
|
2135
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2140
2136
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2141
2137
|
userAccounts: [this.getUserAccount()],
|
|
2142
2138
|
useMarketLastSlotCache: true,
|
|
@@ -2181,7 +2177,7 @@ class DriftClient {
|
|
|
2181
2177
|
return txSig;
|
|
2182
2178
|
}
|
|
2183
2179
|
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex) {
|
|
2184
|
-
const { txSig } = await this.sendTransaction(
|
|
2180
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex)), [], this.opts);
|
|
2185
2181
|
return txSig;
|
|
2186
2182
|
}
|
|
2187
2183
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|