@drift-labs/sdk 2.19.0 → 2.20.0-beta.1
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 +2 -1
- package/lib/accounts/bulkAccountLoader.js +7 -7
- package/lib/accounts/fetch.d.ts +1 -0
- package/lib/accounts/fetch.js +8 -4
- 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 +5 -4
- 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 +5 -1
- package/lib/adminClient.js +61 -57
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +6 -5
- package/lib/dlob/DLOB.js +105 -75
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.d.ts +5 -4
- package/lib/driftClient.js +139 -112
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +14 -14
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +13 -13
- package/lib/factory/oracleClient.js +4 -4
- package/lib/idl/drift.json +52 -1
- package/lib/index.js +5 -1
- package/lib/math/amm.d.ts +1 -1
- 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 +4 -4
- package/lib/math/market.js +15 -15
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +27 -24
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +9 -9
- package/lib/math/spotMarket.js +3 -3
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +42 -42
- package/lib/math/utils.js +1 -1
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tokenFaucet.js +5 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +66 -45
- package/lib/user.js +63 -63
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -5
- package/src/accounts/fetch.ts +8 -0
- package/src/dlob/DLOB.ts +55 -8
- package/src/driftClient.ts +57 -20
- package/src/idl/drift.json +52 -1
- package/src/math/orders.ts +5 -1
- package/src/types.ts +23 -1
- package/src/userMap/userStatsMap.ts +1 -4
- package/tests/amm/test.ts +24 -28
- package/tests/dlob/test.ts +67 -73
package/lib/driftClient.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
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
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -44,11 +48,18 @@ const config_1 = require("./config");
|
|
|
44
48
|
const spotMarkets_1 = require("./constants/spotMarkets");
|
|
45
49
|
const userStats_1 = require("./userStats");
|
|
46
50
|
const spotPosition_1 = require("./math/spotPosition");
|
|
51
|
+
const market_1 = require("./math/market");
|
|
47
52
|
/**
|
|
48
53
|
* # DriftClient
|
|
49
54
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
50
55
|
*/
|
|
51
56
|
class DriftClient {
|
|
57
|
+
get isSubscribed() {
|
|
58
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
59
|
+
}
|
|
60
|
+
set isSubscribed(val) {
|
|
61
|
+
this._isSubscribed = val;
|
|
62
|
+
}
|
|
52
63
|
constructor(config) {
|
|
53
64
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
54
65
|
this.users = new Map();
|
|
@@ -76,7 +87,7 @@ class DriftClient {
|
|
|
76
87
|
if (config.userStats) {
|
|
77
88
|
this.userStats = new userStats_1.UserStats({
|
|
78
89
|
driftClient: this,
|
|
79
|
-
userStatsAccountPublicKey: pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority),
|
|
90
|
+
userStatsAccountPublicKey: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority),
|
|
80
91
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
81
92
|
});
|
|
82
93
|
}
|
|
@@ -84,7 +95,7 @@ class DriftClient {
|
|
|
84
95
|
let spotMarketIndexes = config.spotMarketIndexes;
|
|
85
96
|
let oracleInfos = config.oracleInfos;
|
|
86
97
|
if (config.env) {
|
|
87
|
-
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos: envOracleInfos, } = config_1.getMarketsAndOraclesForSubscription(config.env);
|
|
98
|
+
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos: envOracleInfos, } = (0, config_1.getMarketsAndOraclesForSubscription)(config.env);
|
|
88
99
|
perpMarketIndexes = perpMarketIndexes
|
|
89
100
|
? perpMarketIndexes
|
|
90
101
|
: envPerpMarketIndexes;
|
|
@@ -106,12 +117,6 @@ class DriftClient {
|
|
|
106
117
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
107
118
|
this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (_f = config.txSenderConfig) === null || _f === void 0 ? void 0 : _f.timeout, (_g = config.txSenderConfig) === null || _g === void 0 ? void 0 : _g.retrySleep, (_h = config.txSenderConfig) === null || _h === void 0 ? void 0 : _h.additionalConnections);
|
|
108
119
|
}
|
|
109
|
-
get isSubscribed() {
|
|
110
|
-
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
111
|
-
}
|
|
112
|
-
set isSubscribed(val) {
|
|
113
|
-
this._isSubscribed = val;
|
|
114
|
-
}
|
|
115
120
|
createUsers(subAccountIds, accountSubscriptionConfig) {
|
|
116
121
|
for (const subAccountId of subAccountIds) {
|
|
117
122
|
const user = this.createUser(subAccountId, accountSubscriptionConfig);
|
|
@@ -119,7 +124,7 @@ class DriftClient {
|
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
126
|
createUser(subAccountId, accountSubscriptionConfig) {
|
|
122
|
-
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.authority, subAccountId);
|
|
127
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.authority, subAccountId);
|
|
123
128
|
return new user_1.User({
|
|
124
129
|
driftClient: this,
|
|
125
130
|
userAccountPublicKey,
|
|
@@ -164,14 +169,14 @@ class DriftClient {
|
|
|
164
169
|
if (this.statePublicKey) {
|
|
165
170
|
return this.statePublicKey;
|
|
166
171
|
}
|
|
167
|
-
this.statePublicKey = await pda_1.getDriftStateAccountPublicKey(this.program.programId);
|
|
172
|
+
this.statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
168
173
|
return this.statePublicKey;
|
|
169
174
|
}
|
|
170
175
|
getSignerPublicKey() {
|
|
171
176
|
if (this.signerPublicKey) {
|
|
172
177
|
return this.signerPublicKey;
|
|
173
178
|
}
|
|
174
|
-
this.signerPublicKey = pda_1.getDriftSignerPublicKey(this.program.programId);
|
|
179
|
+
this.signerPublicKey = (0, pda_1.getDriftSignerPublicKey)(this.program.programId);
|
|
175
180
|
return this.signerPublicKey;
|
|
176
181
|
}
|
|
177
182
|
getStateAccount() {
|
|
@@ -232,7 +237,7 @@ class DriftClient {
|
|
|
232
237
|
return this.accountSubscriber.getOraclePriceDataAndSlot(oraclePublicKey);
|
|
233
238
|
}
|
|
234
239
|
async getSerumV3FulfillmentConfig(serumMarket) {
|
|
235
|
-
const address = await pda_1.getSerumFulfillmentConfigPublicKey(this.program.programId, serumMarket);
|
|
240
|
+
const address = await (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
236
241
|
return (await this.program.account.serumV3FulfillmentConfig.fetch(address));
|
|
237
242
|
}
|
|
238
243
|
async fetchMarketLookupTableAccount() {
|
|
@@ -263,7 +268,7 @@ class DriftClient {
|
|
|
263
268
|
await this.userStats.unsubscribe();
|
|
264
269
|
this.userStats = new userStats_1.UserStats({
|
|
265
270
|
driftClient: this,
|
|
266
|
-
userStatsAccountPublicKey: pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority),
|
|
271
|
+
userStatsAccountPublicKey: (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority),
|
|
267
272
|
accountSubscription: this.userAccountSubscriptionConfig,
|
|
268
273
|
});
|
|
269
274
|
}
|
|
@@ -303,7 +308,7 @@ class DriftClient {
|
|
|
303
308
|
return [txSig, userAccountPublicKey];
|
|
304
309
|
}
|
|
305
310
|
async getInitializeUserInstructions(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, referrerInfo) {
|
|
306
|
-
const userAccountPublicKey = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
311
|
+
const userAccountPublicKey = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
307
312
|
const remainingAccounts = new Array();
|
|
308
313
|
if (referrerInfo !== undefined) {
|
|
309
314
|
remainingAccounts.push({
|
|
@@ -326,7 +331,7 @@ class DriftClient {
|
|
|
326
331
|
isSigner: false,
|
|
327
332
|
});
|
|
328
333
|
}
|
|
329
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
334
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
330
335
|
const initializeUserAccountIx = await this.program.instruction.initializeUser(subAccountId, nameBuffer, {
|
|
331
336
|
accounts: {
|
|
332
337
|
user: userAccountPublicKey,
|
|
@@ -354,8 +359,8 @@ class DriftClient {
|
|
|
354
359
|
});
|
|
355
360
|
}
|
|
356
361
|
async updateUserName(name, subAccountId = 0) {
|
|
357
|
-
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
358
|
-
const nameBuffer = userName_1.encodeName(name);
|
|
362
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
363
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
359
364
|
const tx = await this.program.transaction.updateUserName(subAccountId, nameBuffer, {
|
|
360
365
|
accounts: {
|
|
361
366
|
user: userAccountPublicKey,
|
|
@@ -376,7 +381,7 @@ class DriftClient {
|
|
|
376
381
|
return txSig;
|
|
377
382
|
}
|
|
378
383
|
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
|
|
379
|
-
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
384
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
380
385
|
await this.addUser(subAccountId);
|
|
381
386
|
const remainingAccounts = this.getRemainingAccounts({
|
|
382
387
|
userAccounts: [this.getUserAccount(subAccountId)],
|
|
@@ -427,7 +432,7 @@ class DriftClient {
|
|
|
427
432
|
}
|
|
428
433
|
async deleteUser(subAccountId = 0, txParams) {
|
|
429
434
|
var _a;
|
|
430
|
-
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
435
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
431
436
|
const ix = await this.program.instruction.deleteUser({
|
|
432
437
|
accounts: {
|
|
433
438
|
user: userAccountPublicKey,
|
|
@@ -436,7 +441,7 @@ class DriftClient {
|
|
|
436
441
|
state: await this.getStatePublicKey(),
|
|
437
442
|
},
|
|
438
443
|
});
|
|
439
|
-
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);
|
|
444
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
440
445
|
await ((_a = this.users.get(subAccountId)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
|
|
441
446
|
this.users.delete(subAccountId);
|
|
442
447
|
return txSig;
|
|
@@ -458,7 +463,7 @@ class DriftClient {
|
|
|
458
463
|
if (this.userStatsAccountPublicKey) {
|
|
459
464
|
return this.userStatsAccountPublicKey;
|
|
460
465
|
}
|
|
461
|
-
this.userStatsAccountPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, this.authority);
|
|
466
|
+
this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
|
|
462
467
|
return this.userStatsAccountPublicKey;
|
|
463
468
|
}
|
|
464
469
|
async getUserAccountPublicKey() {
|
|
@@ -484,7 +489,7 @@ class DriftClient {
|
|
|
484
489
|
getQuoteAssetTokenAmount() {
|
|
485
490
|
const spotMarket = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
486
491
|
const spotPosition = this.getSpotPosition(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
487
|
-
return spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
492
|
+
return (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
488
493
|
}
|
|
489
494
|
getTokenAmount(marketIndex) {
|
|
490
495
|
const spotPosition = this.getSpotPosition(marketIndex);
|
|
@@ -492,7 +497,7 @@ class DriftClient {
|
|
|
492
497
|
return numericConstants_1.ZERO;
|
|
493
498
|
}
|
|
494
499
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
495
|
-
return spotBalance_1.getTokenAmount(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
500
|
+
return (0, spotBalance_1.getTokenAmount)(spotPosition.scaledBalance, spotMarket, spotPosition.balanceType);
|
|
496
501
|
}
|
|
497
502
|
getRemainingAccounts(params) {
|
|
498
503
|
var _a;
|
|
@@ -616,7 +621,7 @@ class DriftClient {
|
|
|
616
621
|
const perpMarketAccountMap = new Map();
|
|
617
622
|
for (const userAccount of userAccounts) {
|
|
618
623
|
for (const spotPosition of userAccount.spotPositions) {
|
|
619
|
-
if (!spotPosition_1.isSpotPositionAvailable(spotPosition)) {
|
|
624
|
+
if (!(0, spotPosition_1.isSpotPositionAvailable)(spotPosition)) {
|
|
620
625
|
const spotMarket = this.getSpotMarketAccount(spotPosition.marketIndex);
|
|
621
626
|
spotMarketAccountMap.set(spotPosition.marketIndex, {
|
|
622
627
|
pubkey: spotMarket.pubkey,
|
|
@@ -641,7 +646,7 @@ class DriftClient {
|
|
|
641
646
|
}
|
|
642
647
|
}
|
|
643
648
|
for (const position of userAccount.perpPositions) {
|
|
644
|
-
if (!position_1.positionIsAvailable(position)) {
|
|
649
|
+
if (!(0, position_1.positionIsAvailable)(position)) {
|
|
645
650
|
const market = this.getPerpMarketAccount(position.marketIndex);
|
|
646
651
|
perpMarketAccountMap.set(position.marketIndex, {
|
|
647
652
|
pubkey: market.pubkey,
|
|
@@ -700,7 +705,7 @@ class DriftClient {
|
|
|
700
705
|
}
|
|
701
706
|
async getDepositInstruction(amount, marketIndex, userTokenAccount, subAccountId, reduceOnly = false, userInitialized = true) {
|
|
702
707
|
const userAccountPublicKey = subAccountId
|
|
703
|
-
? await pda_1.getUserAccountPublicKey(this.program.programId, this.authority, subAccountId)
|
|
708
|
+
? await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.authority, subAccountId)
|
|
704
709
|
: await this.getUserAccountPublicKey();
|
|
705
710
|
let remainingAccounts = [];
|
|
706
711
|
if (userInitialized) {
|
|
@@ -885,7 +890,7 @@ class DriftClient {
|
|
|
885
890
|
});
|
|
886
891
|
}
|
|
887
892
|
async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId, txParams) {
|
|
888
|
-
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);
|
|
893
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
889
894
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
890
895
|
toSubAccountId === this.activeSubAccountId) {
|
|
891
896
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
@@ -893,8 +898,8 @@ class DriftClient {
|
|
|
893
898
|
return txSig;
|
|
894
899
|
}
|
|
895
900
|
async getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId) {
|
|
896
|
-
const fromUser = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, fromSubAccountId);
|
|
897
|
-
const toUser = await pda_1.getUserAccountPublicKey(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
901
|
+
const fromUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, fromSubAccountId);
|
|
902
|
+
const toUser = await (0, pda_1.getUserAccountPublicKey)(this.program.programId, this.wallet.publicKey, toSubAccountId);
|
|
898
903
|
let remainingAccounts;
|
|
899
904
|
if (this.users.has(fromSubAccountId)) {
|
|
900
905
|
remainingAccounts = this.getRemainingAccounts({
|
|
@@ -904,7 +909,7 @@ class DriftClient {
|
|
|
904
909
|
});
|
|
905
910
|
}
|
|
906
911
|
else {
|
|
907
|
-
const userAccountPublicKey = pda_1.getUserAccountPublicKeySync(this.program.programId, this.authority, fromSubAccountId);
|
|
912
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.authority, fromSubAccountId);
|
|
908
913
|
const fromUserAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
909
914
|
remainingAccounts = this.getRemainingAccounts({
|
|
910
915
|
userAccounts: [fromUserAccount],
|
|
@@ -925,7 +930,7 @@ class DriftClient {
|
|
|
925
930
|
});
|
|
926
931
|
}
|
|
927
932
|
async updateSpotMarketCumulativeInterest(marketIndex, txParams) {
|
|
928
|
-
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);
|
|
933
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
929
934
|
return txSig;
|
|
930
935
|
}
|
|
931
936
|
async updateSpotMarketCumulativeInterestIx(marketIndex) {
|
|
@@ -939,7 +944,7 @@ class DriftClient {
|
|
|
939
944
|
});
|
|
940
945
|
}
|
|
941
946
|
async settleLP(settleeUserAccountPublicKey, marketIndex, txParams) {
|
|
942
|
-
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);
|
|
947
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
943
948
|
return txSig;
|
|
944
949
|
}
|
|
945
950
|
async settleLPIx(settleeUserAccountPublicKey, marketIndex) {
|
|
@@ -957,11 +962,11 @@ class DriftClient {
|
|
|
957
962
|
});
|
|
958
963
|
}
|
|
959
964
|
async removePerpLpShares(marketIndex, sharesToBurn, txParams) {
|
|
960
|
-
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);
|
|
965
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
961
966
|
return txSig;
|
|
962
967
|
}
|
|
963
968
|
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn, txParams) {
|
|
964
|
-
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);
|
|
969
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
965
970
|
return txSig;
|
|
966
971
|
}
|
|
967
972
|
async getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
@@ -1007,7 +1012,7 @@ class DriftClient {
|
|
|
1007
1012
|
});
|
|
1008
1013
|
}
|
|
1009
1014
|
async addPerpLpShares(amount, marketIndex, txParams) {
|
|
1010
|
-
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);
|
|
1015
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1011
1016
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1012
1017
|
return txSig;
|
|
1013
1018
|
}
|
|
@@ -1051,8 +1056,8 @@ class DriftClient {
|
|
|
1051
1056
|
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams) {
|
|
1052
1057
|
const marketIndex = orderParams.marketIndex;
|
|
1053
1058
|
const orderId = userAccount.nextOrderId;
|
|
1054
|
-
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);
|
|
1055
|
-
const fillTx = utils_1.wrapInTx(await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1059
|
+
const marketOrderTx = (0, 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);
|
|
1060
|
+
const fillTx = (0, utils_1.wrapInTx)(await this.getFillPerpOrderIx(userAccountPublicKey, userAccount, {
|
|
1056
1061
|
orderId,
|
|
1057
1062
|
marketIndex,
|
|
1058
1063
|
}, makerInfo), txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice);
|
|
@@ -1068,7 +1073,7 @@ class DriftClient {
|
|
|
1068
1073
|
return { txSig, signedFillTx };
|
|
1069
1074
|
}
|
|
1070
1075
|
async placePerpOrder(orderParams, txParams) {
|
|
1071
|
-
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);
|
|
1076
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1072
1077
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1073
1078
|
return txSig;
|
|
1074
1079
|
}
|
|
@@ -1096,7 +1101,7 @@ class DriftClient {
|
|
|
1096
1101
|
});
|
|
1097
1102
|
}
|
|
1098
1103
|
async updateAMMs(marketIndexes, txParams) {
|
|
1099
|
-
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);
|
|
1104
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1100
1105
|
return txSig;
|
|
1101
1106
|
}
|
|
1102
1107
|
async getUpdateAMMsIx(marketIndexes) {
|
|
@@ -1130,7 +1135,7 @@ class DriftClient {
|
|
|
1130
1135
|
});
|
|
1131
1136
|
}
|
|
1132
1137
|
async settleExpiredMarket(marketIndex, txParams) {
|
|
1133
|
-
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);
|
|
1138
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1134
1139
|
return txSig;
|
|
1135
1140
|
}
|
|
1136
1141
|
async getSettleExpiredMarketIx(marketIndex) {
|
|
@@ -1165,8 +1170,8 @@ class DriftClient {
|
|
|
1165
1170
|
});
|
|
1166
1171
|
}
|
|
1167
1172
|
async settleExpiredMarketPoolsToRevenuePool(perpMarketIndex, txParams) {
|
|
1168
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
1169
|
-
const spotMarketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
1173
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
1174
|
+
const spotMarketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
1170
1175
|
const ix = await this.program.instruction.settleExpiredMarketPoolsToRevenuePool({
|
|
1171
1176
|
accounts: {
|
|
1172
1177
|
state: await this.getStatePublicKey(),
|
|
@@ -1175,11 +1180,11 @@ class DriftClient {
|
|
|
1175
1180
|
perpMarket: perpMarketPublicKey,
|
|
1176
1181
|
},
|
|
1177
1182
|
});
|
|
1178
|
-
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);
|
|
1183
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits, txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice), [], this.opts);
|
|
1179
1184
|
return txSig;
|
|
1180
1185
|
}
|
|
1181
1186
|
async cancelOrder(orderId, txParams) {
|
|
1182
|
-
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);
|
|
1187
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1183
1188
|
return txSig;
|
|
1184
1189
|
}
|
|
1185
1190
|
async getCancelOrderIx(orderId) {
|
|
@@ -1198,7 +1203,7 @@ class DriftClient {
|
|
|
1198
1203
|
});
|
|
1199
1204
|
}
|
|
1200
1205
|
async cancelOrderByUserId(userOrderId, txParams) {
|
|
1201
|
-
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);
|
|
1206
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1202
1207
|
return txSig;
|
|
1203
1208
|
}
|
|
1204
1209
|
async getCancelOrderByUserIdIx(userOrderId) {
|
|
@@ -1220,7 +1225,7 @@ class DriftClient {
|
|
|
1220
1225
|
});
|
|
1221
1226
|
}
|
|
1222
1227
|
async cancelOrders(marketType, marketIndex, direction, txParams) {
|
|
1223
|
-
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);
|
|
1228
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1224
1229
|
return txSig;
|
|
1225
1230
|
}
|
|
1226
1231
|
async getCancelOrdersIx(marketType, marketIndex, direction) {
|
|
@@ -1228,10 +1233,10 @@ class DriftClient {
|
|
|
1228
1233
|
let readablePerpMarketIndex = undefined;
|
|
1229
1234
|
let readableSpotMarketIndexes = undefined;
|
|
1230
1235
|
if (marketIndex) {
|
|
1231
|
-
if (marketType && types_1.isVariant(marketType, 'perp')) {
|
|
1236
|
+
if (marketType && (0, types_1.isVariant)(marketType, 'perp')) {
|
|
1232
1237
|
readablePerpMarketIndex = marketIndex;
|
|
1233
1238
|
}
|
|
1234
|
-
else if (marketType && types_1.isVariant(marketType, 'spot')) {
|
|
1239
|
+
else if (marketType && (0, types_1.isVariant)(marketType, 'spot')) {
|
|
1235
1240
|
readableSpotMarketIndexes = [marketIndex];
|
|
1236
1241
|
}
|
|
1237
1242
|
}
|
|
@@ -1251,51 +1256,59 @@ class DriftClient {
|
|
|
1251
1256
|
});
|
|
1252
1257
|
}
|
|
1253
1258
|
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo, txParams) {
|
|
1254
|
-
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);
|
|
1259
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1255
1260
|
return txSig;
|
|
1256
1261
|
}
|
|
1257
1262
|
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
|
|
1258
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1263
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
1259
1264
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1260
1265
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1261
1266
|
const marketIndex = order
|
|
1262
1267
|
? order.marketIndex
|
|
1263
1268
|
: userAccount.orders.find((order) => order.orderId === userAccount.nextOrderId - 1).marketIndex;
|
|
1269
|
+
makerInfo = Array.isArray(makerInfo)
|
|
1270
|
+
? makerInfo
|
|
1271
|
+
: makerInfo
|
|
1272
|
+
? [makerInfo]
|
|
1273
|
+
: [];
|
|
1264
1274
|
const userAccounts = [userAccount];
|
|
1265
|
-
|
|
1266
|
-
userAccounts.push(
|
|
1275
|
+
for (const maker of makerInfo) {
|
|
1276
|
+
userAccounts.push(maker.makerUserAccount);
|
|
1267
1277
|
}
|
|
1268
1278
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1269
1279
|
userAccounts,
|
|
1270
1280
|
writablePerpMarketIndexes: [marketIndex],
|
|
1271
1281
|
});
|
|
1272
|
-
|
|
1282
|
+
for (const maker of makerInfo) {
|
|
1273
1283
|
remainingAccounts.push({
|
|
1274
|
-
pubkey:
|
|
1284
|
+
pubkey: maker.maker,
|
|
1275
1285
|
isWritable: true,
|
|
1276
1286
|
isSigner: false,
|
|
1277
1287
|
});
|
|
1278
1288
|
remainingAccounts.push({
|
|
1279
|
-
pubkey:
|
|
1289
|
+
pubkey: maker.makerStats,
|
|
1280
1290
|
isWritable: true,
|
|
1281
1291
|
isSigner: false,
|
|
1282
1292
|
});
|
|
1283
1293
|
}
|
|
1284
1294
|
if (referrerInfo) {
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
+
const referrerIsMaker = makerInfo.find((maker) => maker.maker.equals(referrerInfo.referrer)) !==
|
|
1296
|
+
undefined;
|
|
1297
|
+
if (!referrerIsMaker) {
|
|
1298
|
+
remainingAccounts.push({
|
|
1299
|
+
pubkey: referrerInfo.referrer,
|
|
1300
|
+
isWritable: true,
|
|
1301
|
+
isSigner: false,
|
|
1302
|
+
});
|
|
1303
|
+
remainingAccounts.push({
|
|
1304
|
+
pubkey: referrerInfo.referrerStats,
|
|
1305
|
+
isWritable: true,
|
|
1306
|
+
isSigner: false,
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1295
1309
|
}
|
|
1296
1310
|
const orderId = order.orderId;
|
|
1297
|
-
|
|
1298
|
-
return await this.program.instruction.fillPerpOrder(orderId, makerOrderId, {
|
|
1311
|
+
return await this.program.instruction.fillPerpOrder(orderId, null, {
|
|
1299
1312
|
accounts: {
|
|
1300
1313
|
state: await this.getStatePublicKey(),
|
|
1301
1314
|
filler: fillerPublicKey,
|
|
@@ -1308,7 +1321,7 @@ class DriftClient {
|
|
|
1308
1321
|
});
|
|
1309
1322
|
}
|
|
1310
1323
|
async placeSpotOrder(orderParams, txParams) {
|
|
1311
|
-
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);
|
|
1324
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1312
1325
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1313
1326
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1314
1327
|
return txSig;
|
|
@@ -1335,11 +1348,11 @@ class DriftClient {
|
|
|
1335
1348
|
});
|
|
1336
1349
|
}
|
|
1337
1350
|
async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1338
|
-
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);
|
|
1351
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1339
1352
|
return txSig;
|
|
1340
1353
|
}
|
|
1341
1354
|
async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1342
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1355
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
1343
1356
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1344
1357
|
const fillerStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1345
1358
|
const marketIndex = order
|
|
@@ -1461,7 +1474,7 @@ class DriftClient {
|
|
|
1461
1474
|
isSigner: false,
|
|
1462
1475
|
});
|
|
1463
1476
|
remainingAccounts.push({
|
|
1464
|
-
pubkey: pda_1.getSerumSignerPublicKey(fulfillmentConfig.serumProgramId, fulfillmentConfig.serumMarket, fulfillmentConfig.serumSignerNonce),
|
|
1477
|
+
pubkey: (0, pda_1.getSerumSignerPublicKey)(fulfillmentConfig.serumProgramId, fulfillmentConfig.serumMarket, fulfillmentConfig.serumSignerNonce),
|
|
1465
1478
|
isWritable: false,
|
|
1466
1479
|
isSigner: false,
|
|
1467
1480
|
});
|
|
@@ -1492,13 +1505,13 @@ class DriftClient {
|
|
|
1492
1505
|
});
|
|
1493
1506
|
}
|
|
1494
1507
|
async triggerOrder(userAccountPublicKey, user, order, txParams) {
|
|
1495
|
-
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);
|
|
1508
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1496
1509
|
return txSig;
|
|
1497
1510
|
}
|
|
1498
1511
|
async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
|
|
1499
1512
|
const fillerPublicKey = await this.getUserAccountPublicKey();
|
|
1500
1513
|
let remainingAccountsParams;
|
|
1501
|
-
if (types_1.isVariant(order.marketType, 'perp')) {
|
|
1514
|
+
if ((0, types_1.isVariant)(order.marketType, 'perp')) {
|
|
1502
1515
|
remainingAccountsParams = {
|
|
1503
1516
|
userAccounts: [userAccount],
|
|
1504
1517
|
writablePerpMarketIndexes: [order.marketIndex],
|
|
@@ -1523,7 +1536,7 @@ class DriftClient {
|
|
|
1523
1536
|
});
|
|
1524
1537
|
}
|
|
1525
1538
|
async forceCancelOrders(userAccountPublicKey, user, txParams) {
|
|
1526
|
-
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);
|
|
1539
|
+
const { txSig } = await this.txSender.send((0, 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);
|
|
1527
1540
|
return txSig;
|
|
1528
1541
|
}
|
|
1529
1542
|
async getForceCancelOrdersIx(userAccountPublicKey, userAccount) {
|
|
@@ -1543,7 +1556,7 @@ class DriftClient {
|
|
|
1543
1556
|
});
|
|
1544
1557
|
}
|
|
1545
1558
|
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo, txParams) {
|
|
1546
|
-
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);
|
|
1559
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1547
1560
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1548
1561
|
return txSig;
|
|
1549
1562
|
}
|
|
@@ -1597,7 +1610,7 @@ class DriftClient {
|
|
|
1597
1610
|
});
|
|
1598
1611
|
}
|
|
1599
1612
|
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo, txParams) {
|
|
1600
|
-
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);
|
|
1613
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1601
1614
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1602
1615
|
return txSig;
|
|
1603
1616
|
}
|
|
@@ -1636,7 +1649,7 @@ class DriftClient {
|
|
|
1636
1649
|
});
|
|
1637
1650
|
}
|
|
1638
1651
|
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo, txParams) {
|
|
1639
|
-
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);
|
|
1652
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1640
1653
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1641
1654
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1642
1655
|
return txSig;
|
|
@@ -1695,7 +1708,7 @@ class DriftClient {
|
|
|
1695
1708
|
});
|
|
1696
1709
|
}
|
|
1697
1710
|
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo, txParams) {
|
|
1698
|
-
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);
|
|
1711
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1699
1712
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1700
1713
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1701
1714
|
return txSig;
|
|
@@ -1751,7 +1764,7 @@ class DriftClient {
|
|
|
1751
1764
|
return await this.placeAndTakePerpOrder({
|
|
1752
1765
|
orderType: types_1.OrderType.MARKET,
|
|
1753
1766
|
marketIndex,
|
|
1754
|
-
direction: position_1.findDirectionToClose(userPosition),
|
|
1767
|
+
direction: (0, position_1.findDirectionToClose)(userPosition),
|
|
1755
1768
|
baseAssetAmount: userPosition.baseAssetAmount.abs(),
|
|
1756
1769
|
reduceOnly: true,
|
|
1757
1770
|
price: limitPrice,
|
|
@@ -1815,11 +1828,11 @@ class DriftClient {
|
|
|
1815
1828
|
}
|
|
1816
1829
|
const cancelOrderIx = await this.getCancelOrderIx(orderId);
|
|
1817
1830
|
const orderTypeHasTrigger = newOrderType
|
|
1818
|
-
? types_1.isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1819
|
-
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1831
|
+
? (0, types_1.isOneOfVariant)(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1832
|
+
: (0, types_1.isOneOfVariant)(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1820
1833
|
const orderTypeHasLimitPrice = newOrderType
|
|
1821
|
-
? types_1.isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
1822
|
-
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1834
|
+
? (0, types_1.isOneOfVariant)(newOrderType, ['triggerLimit', 'limit'])
|
|
1835
|
+
: (0, types_1.isOneOfVariant)(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1823
1836
|
const newOrderParams = {
|
|
1824
1837
|
orderType: newOrderType || openOrder.orderType,
|
|
1825
1838
|
marketType: openOrder.marketType,
|
|
@@ -1890,11 +1903,11 @@ class DriftClient {
|
|
|
1890
1903
|
}
|
|
1891
1904
|
const cancelOrderIx = await this.getCancelOrderByUserIdIx(userOrderId);
|
|
1892
1905
|
const orderTypeHasTrigger = newOrderType
|
|
1893
|
-
? types_1.isOneOfVariant(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1894
|
-
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1906
|
+
? (0, types_1.isOneOfVariant)(newOrderType, ['triggerlimit', 'triggerMarket'])
|
|
1907
|
+
: (0, types_1.isOneOfVariant)(openOrder.orderType, ['triggerLimit', 'triggerMarket']);
|
|
1895
1908
|
const orderTypeHasLimitPrice = newOrderType
|
|
1896
|
-
? types_1.isOneOfVariant(newOrderType, ['triggerLimit', 'limit'])
|
|
1897
|
-
: types_1.isOneOfVariant(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1909
|
+
? (0, types_1.isOneOfVariant)(newOrderType, ['triggerLimit', 'limit'])
|
|
1910
|
+
: (0, types_1.isOneOfVariant)(openOrder.orderType, ['triggerLimit', 'limit']);
|
|
1898
1911
|
const newOrderParams = {
|
|
1899
1912
|
orderType: newOrderType || openOrder.orderType,
|
|
1900
1913
|
marketType: openOrder.marketType,
|
|
@@ -1955,7 +1968,7 @@ class DriftClient {
|
|
|
1955
1968
|
return txSig;
|
|
1956
1969
|
}
|
|
1957
1970
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex, txParams) {
|
|
1958
|
-
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);
|
|
1971
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
1959
1972
|
return txSig;
|
|
1960
1973
|
}
|
|
1961
1974
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -1975,12 +1988,12 @@ class DriftClient {
|
|
|
1975
1988
|
});
|
|
1976
1989
|
}
|
|
1977
1990
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice, txParams) {
|
|
1978
|
-
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);
|
|
1991
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
1979
1992
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1980
1993
|
return txSig;
|
|
1981
1994
|
}
|
|
1982
1995
|
async getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1983
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
1996
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
1984
1997
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
1985
1998
|
const liquidatorStatsPublicKey = this.getUserStatsAccountPublicKey();
|
|
1986
1999
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2001,13 +2014,13 @@ class DriftClient {
|
|
|
2001
2014
|
});
|
|
2002
2015
|
}
|
|
2003
2016
|
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
2004
|
-
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);
|
|
2017
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
2005
2018
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
2006
2019
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
2007
2020
|
return txSig;
|
|
2008
2021
|
}
|
|
2009
2022
|
async getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
2010
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2023
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2011
2024
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2012
2025
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2013
2026
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2028,13 +2041,13 @@ class DriftClient {
|
|
|
2028
2041
|
});
|
|
2029
2042
|
}
|
|
2030
2043
|
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice, txParams) {
|
|
2031
|
-
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);
|
|
2044
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
2032
2045
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
2033
2046
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
2034
2047
|
return txSig;
|
|
2035
2048
|
}
|
|
2036
2049
|
async getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
2037
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2050
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2038
2051
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2039
2052
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2040
2053
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2055,13 +2068,13 @@ class DriftClient {
|
|
|
2055
2068
|
});
|
|
2056
2069
|
}
|
|
2057
2070
|
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice, txParams) {
|
|
2058
|
-
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);
|
|
2071
|
+
const { txSig, slot } = await this.sendTransaction((0, 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);
|
|
2059
2072
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
2060
2073
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
2061
2074
|
return txSig;
|
|
2062
2075
|
}
|
|
2063
2076
|
async getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
2064
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2077
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2065
2078
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2066
2079
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2067
2080
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2082,11 +2095,11 @@ class DriftClient {
|
|
|
2082
2095
|
});
|
|
2083
2096
|
}
|
|
2084
2097
|
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2085
|
-
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);
|
|
2098
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2086
2099
|
return txSig;
|
|
2087
2100
|
}
|
|
2088
2101
|
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
2089
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2102
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2090
2103
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2091
2104
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2092
2105
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2112,11 +2125,11 @@ class DriftClient {
|
|
|
2112
2125
|
});
|
|
2113
2126
|
}
|
|
2114
2127
|
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex, txParams) {
|
|
2115
|
-
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);
|
|
2128
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2116
2129
|
return txSig;
|
|
2117
2130
|
}
|
|
2118
2131
|
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
2119
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(this.program.programId, userAccount.authority);
|
|
2132
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, userAccount.authority);
|
|
2120
2133
|
const liquidatorPublicKey = await this.getUserAccountPublicKey();
|
|
2121
2134
|
const liquidatorStatsPublicKey = await this.getUserStatsAccountPublicKey();
|
|
2122
2135
|
const remainingAccounts = this.getRemainingAccounts({
|
|
@@ -2141,11 +2154,11 @@ class DriftClient {
|
|
|
2141
2154
|
});
|
|
2142
2155
|
}
|
|
2143
2156
|
async updateFundingRate(perpMarketIndex, oracle, txParams) {
|
|
2144
|
-
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);
|
|
2157
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2145
2158
|
return txSig;
|
|
2146
2159
|
}
|
|
2147
2160
|
async getUpdateFundingRateIx(perpMarketIndex, oracle) {
|
|
2148
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, perpMarketIndex);
|
|
2161
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
2149
2162
|
return await this.program.instruction.updateFundingRate(perpMarketIndex, {
|
|
2150
2163
|
accounts: {
|
|
2151
2164
|
state: await this.getStatePublicKey(),
|
|
@@ -2155,14 +2168,14 @@ class DriftClient {
|
|
|
2155
2168
|
});
|
|
2156
2169
|
}
|
|
2157
2170
|
async settleFundingPayment(userAccountPublicKey, txParams) {
|
|
2158
|
-
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);
|
|
2171
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2159
2172
|
return txSig;
|
|
2160
2173
|
}
|
|
2161
2174
|
async getSettleFundingPaymentIx(userAccountPublicKey) {
|
|
2162
2175
|
const userAccount = (await this.program.account.user.fetch(userAccountPublicKey));
|
|
2163
2176
|
const writablePerpMarketIndexes = [];
|
|
2164
2177
|
for (const position of userAccount.perpPositions) {
|
|
2165
|
-
if (!position_1.positionIsAvailable(position)) {
|
|
2178
|
+
if (!(0, position_1.positionIsAvailable)(position)) {
|
|
2166
2179
|
writablePerpMarketIndexes.push(position.marketIndex);
|
|
2167
2180
|
}
|
|
2168
2181
|
}
|
|
@@ -2192,11 +2205,11 @@ class DriftClient {
|
|
|
2192
2205
|
return oracleData;
|
|
2193
2206
|
}
|
|
2194
2207
|
async initializeInsuranceFundStake(marketIndex, txParams) {
|
|
2195
|
-
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);
|
|
2208
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2196
2209
|
return txSig;
|
|
2197
2210
|
}
|
|
2198
2211
|
async getInitializeInsuranceFundStakeIx(marketIndex) {
|
|
2199
|
-
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2212
|
+
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2200
2213
|
return await this.program.instruction.initializeInsuranceFundStake(marketIndex, {
|
|
2201
2214
|
accounts: {
|
|
2202
2215
|
insuranceFundStake: ifStakeAccountPublicKey,
|
|
@@ -2212,7 +2225,7 @@ class DriftClient {
|
|
|
2212
2225
|
}
|
|
2213
2226
|
async addInsuranceFundStake(marketIndex, amount, collateralAccountPublicKey) {
|
|
2214
2227
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
2215
|
-
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2228
|
+
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2216
2229
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2217
2230
|
userAccounts: [this.getUserAccount()],
|
|
2218
2231
|
useMarketLastSlotCache: true,
|
|
@@ -2238,7 +2251,7 @@ class DriftClient {
|
|
|
2238
2251
|
}
|
|
2239
2252
|
async requestRemoveInsuranceFundStake(marketIndex, amount) {
|
|
2240
2253
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2241
|
-
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2254
|
+
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2242
2255
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2243
2256
|
userAccounts: [this.getUserAccount()],
|
|
2244
2257
|
useMarketLastSlotCache: true,
|
|
@@ -2260,7 +2273,7 @@ class DriftClient {
|
|
|
2260
2273
|
}
|
|
2261
2274
|
async cancelRequestRemoveInsuranceFundStake(marketIndex) {
|
|
2262
2275
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2263
|
-
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2276
|
+
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2264
2277
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2265
2278
|
userAccounts: [this.getUserAccount()],
|
|
2266
2279
|
useMarketLastSlotCache: true,
|
|
@@ -2282,7 +2295,7 @@ class DriftClient {
|
|
|
2282
2295
|
}
|
|
2283
2296
|
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
2284
2297
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
2285
|
-
const ifStakeAccountPublicKey = pda_1.getInsuranceFundStakeAccountPublicKey(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2298
|
+
const ifStakeAccountPublicKey = (0, pda_1.getInsuranceFundStakeAccountPublicKey)(this.program.programId, this.wallet.publicKey, marketIndex);
|
|
2286
2299
|
const remainingAccounts = this.getRemainingAccounts({
|
|
2287
2300
|
userAccounts: [this.getUserAccount()],
|
|
2288
2301
|
useMarketLastSlotCache: true,
|
|
@@ -2327,7 +2340,7 @@ class DriftClient {
|
|
|
2327
2340
|
return txSig;
|
|
2328
2341
|
}
|
|
2329
2342
|
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex, txParams) {
|
|
2330
|
-
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);
|
|
2343
|
+
const { txSig } = await this.sendTransaction((0, 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);
|
|
2331
2344
|
return txSig;
|
|
2332
2345
|
}
|
|
2333
2346
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|
|
@@ -2350,6 +2363,20 @@ class DriftClient {
|
|
|
2350
2363
|
remainingAccounts: remainingAccounts,
|
|
2351
2364
|
});
|
|
2352
2365
|
}
|
|
2366
|
+
getPerpMarketExtendedInfo(marketIndex) {
|
|
2367
|
+
var _a, _b;
|
|
2368
|
+
const marketAccount = this.getPerpMarketAccount(marketIndex);
|
|
2369
|
+
const quoteAccount = this.getSpotMarketAccount(numericConstants_1.QUOTE_SPOT_MARKET_INDEX);
|
|
2370
|
+
const extendedInfo = {
|
|
2371
|
+
marketIndex,
|
|
2372
|
+
minOrderSize: (_a = marketAccount.amm) === null || _a === void 0 ? void 0 : _a.minOrderSize,
|
|
2373
|
+
marginMaintenance: marketAccount.marginRatioMaintenance,
|
|
2374
|
+
pnlPoolValue: (0, spotBalance_1.getTokenAmount)((_b = marketAccount.pnlPool) === null || _b === void 0 ? void 0 : _b.scaledBalance, quoteAccount, types_1.SpotBalanceType.DEPOSIT),
|
|
2375
|
+
contractTier: marketAccount.contractTier,
|
|
2376
|
+
availableInsurance: (0, market_1.calculateMarketMaxAvailableInsurance)(marketAccount, quoteAccount),
|
|
2377
|
+
};
|
|
2378
|
+
return extendedInfo;
|
|
2379
|
+
}
|
|
2353
2380
|
sendTransaction(tx, additionalSigners, opts, preSigned) {
|
|
2354
2381
|
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
2355
2382
|
}
|