@drift-labs/sdk 2.14.0-beta.0 → 2.15.0-beta.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.d.ts +0 -1
- 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/types.d.ts +0 -1
- 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/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/constants/perpMarkets.js +10 -0
- package/lib/dlob/DLOB.js +68 -68
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.js +81 -85
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/examples/loadDlob.js +2 -2
- 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 +13 -13
- 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 +8 -8
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.js +42 -42
- 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/user.js +52 -52
- 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/assert/assert.js +9 -0
- package/src/constants/numericConstants.ts +1 -0
- package/src/constants/perpMarkets.ts +10 -0
- package/src/dlob/DLOB.ts +1 -1
- package/src/idl/drift.json +1 -1
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/user.ts +2 -1
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
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, txParams) {
|
|
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, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
878
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
874
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
918
|
-
const { txSig } = await this.sendTransaction(
|
|
914
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.updateSpotMarketCumulativeInterestIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
932
|
-
const { txSig } = await this.sendTransaction(
|
|
928
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
950
|
-
const { txSig } = await this.sendTransaction(
|
|
946
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
951
947
|
return txSig;
|
|
952
948
|
}
|
|
953
949
|
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn, txParams) {
|
|
954
|
-
const { txSig } = await this.sendTransaction(
|
|
950
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1000
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
996
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getAddPerpLpSharesIx(amount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
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), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
1041
|
+
const fillTx = utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1046
1042
|
orderId,
|
|
1047
1043
|
marketIndex,
|
|
1048
1044
|
}, makerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
@@ -1058,7 +1054,7 @@ class DriftClient {
|
|
|
1058
1054
|
return { txSig, signedFillTx };
|
|
1059
1055
|
}
|
|
1060
1056
|
async placePerpOrder(orderParams, txParams) {
|
|
1061
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1057
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlacePerpOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1089
|
-
const { txSig } = await this.sendTransaction(
|
|
1085
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateAMMsIx(marketIndexes), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1123
|
-
const { txSig } = await this.sendTransaction(
|
|
1119
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleExpiredMarketIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
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, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1169
1165
|
return txSig;
|
|
1170
1166
|
}
|
|
1171
1167
|
async cancelOrder(orderId, txParams) {
|
|
1172
|
-
const { txSig } = await this.sendTransaction(
|
|
1168
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderIx(orderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1191
|
-
const { txSig } = await this.sendTransaction(
|
|
1187
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrderByUserIdIx(userOrderId), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1213
|
-
const { txSig } = await this.sendTransaction(
|
|
1209
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getCancelOrdersIx(marketType, marketIndex, direction), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1244
|
-
const { txSig } = await this.sendTransaction(
|
|
1240
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1301
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1297
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceSpotOrderIx(orderParams), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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;
|
|
@@ -1325,11 +1321,11 @@ class DriftClient {
|
|
|
1325
1321
|
});
|
|
1326
1322
|
}
|
|
1327
1323
|
async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1328
|
-
const { txSig } = await this.sendTransaction(
|
|
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, txParams) {
|
|
1485
|
-
const { txSig } = await this.sendTransaction(
|
|
1481
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getTriggerOrderIx(userAccountPublicKey, user, order), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1516
|
-
const { txSig } = await this.txSender.send(
|
|
1512
|
+
const { txSig } = await this.txSender.send(utils_1.wrapInTx(await this.getForceCancelOrdersIx(userAccountPublicKey, user), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1536
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1532
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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, txParams) {
|
|
1590
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1586
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1591
1587
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1592
1588
|
return txSig;
|
|
1593
1589
|
}
|
|
@@ -1626,7 +1622,7 @@ class DriftClient {
|
|
|
1626
1622
|
});
|
|
1627
1623
|
}
|
|
1628
1624
|
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1629
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
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, txParams) {
|
|
1688
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1684
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], 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,
|
|
@@ -1858,7 +1854,7 @@ class DriftClient {
|
|
|
1858
1854
|
return txSig;
|
|
1859
1855
|
}
|
|
1860
1856
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams) {
|
|
1861
|
-
const { txSig } = await this.sendTransaction(
|
|
1857
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1862
1858
|
return txSig;
|
|
1863
1859
|
}
|
|
1864
1860
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -1878,12 +1874,12 @@ class DriftClient {
|
|
|
1878
1874
|
});
|
|
1879
1875
|
}
|
|
1880
1876
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams) {
|
|
1881
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1877
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1882
1878
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1883
1879
|
return txSig;
|
|
1884
1880
|
}
|
|
1885
1881
|
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1886
|
-
const userStatsPublicKey =
|
|
1882
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1887
1883
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1888
1884
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1889
1885
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1904,13 +1900,13 @@ class DriftClient {
|
|
|
1904
1900
|
});
|
|
1905
1901
|
}
|
|
1906
1902
|
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
1907
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1903
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1908
1904
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1909
1905
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1910
1906
|
return txSig;
|
|
1911
1907
|
}
|
|
1912
1908
|
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1913
|
-
const userStatsPublicKey =
|
|
1909
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1914
1910
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1915
1911
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1916
1912
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1931,13 +1927,13 @@ class DriftClient {
|
|
|
1931
1927
|
});
|
|
1932
1928
|
}
|
|
1933
1929
|
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
1934
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1930
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1935
1931
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1936
1932
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1937
1933
|
return txSig;
|
|
1938
1934
|
}
|
|
1939
1935
|
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1940
|
-
const userStatsPublicKey =
|
|
1936
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1941
1937
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1942
1938
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1943
1939
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1958,13 +1954,13 @@ class DriftClient {
|
|
|
1958
1954
|
});
|
|
1959
1955
|
}
|
|
1960
1956
|
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams) {
|
|
1961
|
-
const { txSig, slot } = await this.sendTransaction(
|
|
1957
|
+
const { txSig, slot } = await this.sendTransaction(utils_1.wrapInTx(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1962
1958
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1963
1959
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1964
1960
|
return txSig;
|
|
1965
1961
|
}
|
|
1966
1962
|
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
1967
|
-
const userStatsPublicKey =
|
|
1963
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1968
1964
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1969
1965
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1970
1966
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -1985,11 +1981,11 @@ class DriftClient {
|
|
|
1985
1981
|
});
|
|
1986
1982
|
}
|
|
1987
1983
|
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
1988
|
-
const { txSig } = await this.sendTransaction(
|
|
1984
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1989
1985
|
return txSig;
|
|
1990
1986
|
}
|
|
1991
1987
|
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
1992
|
-
const userStatsPublicKey =
|
|
1988
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1993
1989
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1994
1990
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
1995
1991
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2015,11 +2011,11 @@ class DriftClient {
|
|
|
2015
2011
|
});
|
|
2016
2012
|
}
|
|
2017
2013
|
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2018
|
-
const { txSig } = await this.sendTransaction(
|
|
2014
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2019
2015
|
return txSig;
|
|
2020
2016
|
}
|
|
2021
2017
|
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
2022
|
-
const userStatsPublicKey =
|
|
2018
|
+
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2023
2019
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2024
2020
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2025
2021
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2044,11 +2040,11 @@ class DriftClient {
|
|
|
2044
2040
|
});
|
|
2045
2041
|
}
|
|
2046
2042
|
async updateFundingRate(perpMarketIndex, oracle, txParams) {
|
|
2047
|
-
const { txSig } = await this.sendTransaction(
|
|
2043
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getUpdateFundingRateIx(perpMarketIndex, oracle), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2048
2044
|
return txSig;
|
|
2049
2045
|
}
|
|
2050
2046
|
async getUpdateFundingRateIx(perpMarketIndex, oracle) {
|
|
2051
|
-
const perpMarketPublicKey = await
|
|
2047
|
+
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
2052
2048
|
return await this.program.instruction.updateFundingRate(perpMarketIndex, {
|
|
2053
2049
|
accounts: {
|
|
2054
2050
|
state: await this.getStatePublicKey(),
|
|
@@ -2058,14 +2054,14 @@ class DriftClient {
|
|
|
2058
2054
|
});
|
|
2059
2055
|
}
|
|
2060
2056
|
async settleFundingPayment(userAccountPublicKey, txParams) {
|
|
2061
|
-
const { txSig } = await this.sendTransaction(
|
|
2057
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getSettleFundingPaymentIx(userAccountPublicKey), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2062
2058
|
return txSig;
|
|
2063
2059
|
}
|
|
2064
2060
|
async getSettleFundingPaymentIx(userAccountPublicKey) {
|
|
2065
2061
|
const userAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
2066
2062
|
const writablePerpMarketIndexes = [];
|
|
2067
2063
|
for (const position of userAccount.perpPositions) {
|
|
2068
|
-
if (!
|
|
2064
|
+
if (!position_1.positionIsAvailable(position)) {
|
|
2069
2065
|
writablePerpMarketIndexes.push(position.marketIndex);
|
|
2070
2066
|
}
|
|
2071
2067
|
}
|
|
@@ -2095,11 +2091,11 @@ class DriftClient {
|
|
|
2095
2091
|
return oracleData;
|
|
2096
2092
|
}
|
|
2097
2093
|
async initializeInsuranceFundStake(marketIndex, txParams) {
|
|
2098
|
-
const { txSig } = await this.sendTransaction(
|
|
2094
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getInitializeInsuranceFundStakeIx(marketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2099
2095
|
return txSig;
|
|
2100
2096
|
}
|
|
2101
2097
|
async getInitializeInsuranceFundStakeIx(marketIndex) {
|
|
2102
|
-
const ifStakeAccountPublicKey =
|
|
2098
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2103
2099
|
return await this.program.instruction.initializeInsuranceFundStake(marketIndex, {
|
|
2104
2100
|
accounts: {
|
|
2105
2101
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
@@ -2115,7 +2111,7 @@ class DriftClient {
|
|
|
2115
2111
|
}
|
|
2116
2112
|
async addInsuranceFundStake(marketIndex, amount, collateralAccountPublicKey) {
|
|
2117
2113
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
2118
|
-
const ifStakeAccountPublicKey =
|
|
2114
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2119
2115
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2120
2116
|
userAccounts: [this.getUserAccount()],
|
|
2121
2117
|
useMarketLastSlotCache: true,
|
|
@@ -2141,7 +2137,7 @@ class DriftClient {
|
|
|
2141
2137
|
}
|
|
2142
2138
|
async requestRemoveInsuranceFundStake(marketIndex, amount) {
|
|
2143
2139
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2144
|
-
const ifStakeAccountPublicKey =
|
|
2140
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2145
2141
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2146
2142
|
userAccounts: [this.getUserAccount()],
|
|
2147
2143
|
useMarketLastSlotCache: true,
|
|
@@ -2163,7 +2159,7 @@ class DriftClient {
|
|
|
2163
2159
|
}
|
|
2164
2160
|
async cancelRequestRemoveInsuranceFundStake(marketIndex) {
|
|
2165
2161
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2166
|
-
const ifStakeAccountPublicKey =
|
|
2162
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2167
2163
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2168
2164
|
userAccounts: [this.getUserAccount()],
|
|
2169
2165
|
useMarketLastSlotCache: true,
|
|
@@ -2185,7 +2181,7 @@ class DriftClient {
|
|
|
2185
2181
|
}
|
|
2186
2182
|
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
2187
2183
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2188
|
-
const ifStakeAccountPublicKey =
|
|
2184
|
+
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2189
2185
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2190
2186
|
userAccounts: [this.getUserAccount()],
|
|
2191
2187
|
useMarketLastSlotCache: true,
|
|
@@ -2230,7 +2226,7 @@ class DriftClient {
|
|
|
2230
2226
|
return txSig;
|
|
2231
2227
|
}
|
|
2232
2228
|
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, txParams) {
|
|
2233
|
-
const { txSig } = await this.sendTransaction(
|
|
2229
|
+
const { txSig } = await this.sendTransaction(utils_1.wrapInTx(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
2234
2230
|
return txSig;
|
|
2235
2231
|
}
|
|
2236
2232
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|