@drift-labs/sdk 2.10.0-beta.0 → 2.10.0-beta.2
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/pollingDriftClientAccountSubscriber.js +12 -3
- package/lib/accounts/types.d.ts +0 -1
- package/lib/adminClient.js +96 -34
- package/lib/driftClient.d.ts +3 -2
- package/lib/driftClient.js +99 -58
- package/lib/idl/drift.json +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/math/amm.js +15 -6
- package/lib/math/oracles.js +2 -2
- package/lib/math/repeg.d.ts +1 -1
- package/lib/math/repeg.js +46 -19
- package/lib/math/spotBalance.js +1 -1
- package/lib/testClient.d.ts +8 -0
- package/lib/testClient.js +22 -0
- package/lib/user.d.ts +1 -0
- package/lib/user.js +4 -0
- package/package.json +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +26 -3
- package/src/adminClient.ts +301 -169
- package/src/driftClient.ts +199 -118
- package/src/idl/drift.json +1 -1
- package/src/index.ts +1 -0
- package/src/math/amm.ts +27 -12
- package/src/math/oracles.ts +6 -4
- package/src/math/repeg.ts +54 -26
- package/src/math/spotBalance.ts +1 -5
- package/src/testClient.ts +40 -0
- package/src/user.ts +5 -0
package/lib/driftClient.js
CHANGED
|
@@ -54,7 +54,7 @@ const spotPosition_1 = require("./math/spotPosition");
|
|
|
54
54
|
*/
|
|
55
55
|
class DriftClient {
|
|
56
56
|
constructor(config) {
|
|
57
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
57
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
58
58
|
this.users = new Map();
|
|
59
59
|
this._isSubscribed = false;
|
|
60
60
|
this.perpMarketLastSlotCache = new Map();
|
|
@@ -88,23 +88,23 @@ class DriftClient {
|
|
|
88
88
|
let spotMarketIndexes = config.spotMarketIndexes;
|
|
89
89
|
let oracleInfos = config.oracleInfos;
|
|
90
90
|
if (config.env) {
|
|
91
|
-
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos:
|
|
91
|
+
const { perpMarketIndexes: envPerpMarketIndexes, spotMarketIndexes: envSpotMarketIndexes, oracleInfos: envOracleInfos, } = (0, config_1.getMarketsAndOraclesForSubscription)(config.env);
|
|
92
92
|
perpMarketIndexes = perpMarketIndexes
|
|
93
93
|
? perpMarketIndexes
|
|
94
94
|
: envPerpMarketIndexes;
|
|
95
95
|
spotMarketIndexes = spotMarketIndexes
|
|
96
96
|
? spotMarketIndexes
|
|
97
97
|
: envSpotMarketIndexes;
|
|
98
|
-
oracleInfos = oracleInfos ? oracleInfos :
|
|
98
|
+
oracleInfos = oracleInfos ? oracleInfos : envOracleInfos;
|
|
99
99
|
}
|
|
100
100
|
if (((_e = config.accountSubscription) === null || _e === void 0 ? void 0 : _e.type) === 'polling') {
|
|
101
101
|
this.accountSubscriber = new pollingDriftClientAccountSubscriber_1.PollingDriftClientAccountSubscriber(this.program, config.accountSubscription.accountLoader, perpMarketIndexes !== null && perpMarketIndexes !== void 0 ? perpMarketIndexes : [], spotMarketIndexes !== null && spotMarketIndexes !== void 0 ? spotMarketIndexes : [], oracleInfos !== null && oracleInfos !== void 0 ? oracleInfos : []);
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program,
|
|
104
|
+
this.accountSubscriber = new webSocketDriftClientAccountSubscriber_1.WebSocketDriftClientAccountSubscriber(this.program, perpMarketIndexes !== null && perpMarketIndexes !== void 0 ? perpMarketIndexes : [], spotMarketIndexes !== null && spotMarketIndexes !== void 0 ? spotMarketIndexes : [], oracleInfos !== null && oracleInfos !== void 0 ? oracleInfos : []);
|
|
105
105
|
}
|
|
106
106
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
107
|
-
this.txSender = new retryTxSender_1.RetryTxSender(this.provider, (
|
|
107
|
+
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
108
|
}
|
|
109
109
|
get isSubscribed() {
|
|
110
110
|
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
@@ -193,9 +193,16 @@ class DriftClient {
|
|
|
193
193
|
* @param marketIndex
|
|
194
194
|
*/
|
|
195
195
|
async forceGetPerpMarketAccount(marketIndex) {
|
|
196
|
-
var _a;
|
|
196
|
+
var _a, _b;
|
|
197
197
|
await this.accountSubscriber.fetch();
|
|
198
|
-
|
|
198
|
+
let data = (_a = this.accountSubscriber.getMarketAccountAndSlot(marketIndex)) === null || _a === void 0 ? void 0 : _a.data;
|
|
199
|
+
let i = 0;
|
|
200
|
+
while (data === undefined && i < 10) {
|
|
201
|
+
await this.accountSubscriber.fetch();
|
|
202
|
+
data = (_b = this.accountSubscriber.getMarketAccountAndSlot(marketIndex)) === null || _b === void 0 ? void 0 : _b.data;
|
|
203
|
+
i++;
|
|
204
|
+
}
|
|
205
|
+
return data;
|
|
199
206
|
}
|
|
200
207
|
getPerpMarketAccounts() {
|
|
201
208
|
return this.accountSubscriber
|
|
@@ -285,7 +292,7 @@ class DriftClient {
|
|
|
285
292
|
}
|
|
286
293
|
}
|
|
287
294
|
tx.add(initializeUserAccountIx);
|
|
288
|
-
const { txSig } = await this.
|
|
295
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
289
296
|
return [txSig, userAccountPublicKey];
|
|
290
297
|
}
|
|
291
298
|
async getInitializeUserInstructions(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, referrerInfo) {
|
|
@@ -342,37 +349,45 @@ class DriftClient {
|
|
|
342
349
|
async updateUserName(name, subAccountId = 0) {
|
|
343
350
|
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
344
351
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
345
|
-
|
|
352
|
+
const tx = await this.program.transaction.updateUserName(subAccountId, nameBuffer, {
|
|
346
353
|
accounts: {
|
|
347
354
|
user: userAccountPublicKey,
|
|
348
355
|
authority: this.wallet.publicKey,
|
|
349
356
|
},
|
|
350
357
|
});
|
|
358
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
359
|
+
return txSig;
|
|
351
360
|
}
|
|
352
361
|
async updateUserCustomMarginRatio(marginRatio, subAccountId = 0) {
|
|
353
|
-
|
|
362
|
+
const tx = await this.program.transaction.updateUserCustomMarginRatio(subAccountId, marginRatio, {
|
|
354
363
|
accounts: {
|
|
355
364
|
user: await this.getUserAccountPublicKey(),
|
|
356
365
|
authority: this.wallet.publicKey,
|
|
357
366
|
},
|
|
358
367
|
});
|
|
368
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
369
|
+
return txSig;
|
|
359
370
|
}
|
|
360
371
|
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
|
|
361
372
|
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
362
|
-
|
|
373
|
+
const tx = await this.program.transaction.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled, {
|
|
363
374
|
accounts: {
|
|
364
375
|
user: userAccountPublicKey,
|
|
365
376
|
authority: this.wallet.publicKey,
|
|
366
377
|
},
|
|
367
378
|
});
|
|
379
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
380
|
+
return txSig;
|
|
368
381
|
}
|
|
369
382
|
async updateUserDelegate(delegate, subAccountId = 0) {
|
|
370
|
-
|
|
383
|
+
const tx = await this.program.transaction.updateUserDelegate(subAccountId, delegate, {
|
|
371
384
|
accounts: {
|
|
372
385
|
user: await this.getUserAccountPublicKey(),
|
|
373
386
|
authority: this.wallet.publicKey,
|
|
374
387
|
},
|
|
375
388
|
});
|
|
389
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
390
|
+
return txSig;
|
|
376
391
|
}
|
|
377
392
|
async getUserAccountsForDelegate(delegate) {
|
|
378
393
|
const programAccounts = await this.program.account.user.all([
|
|
@@ -401,7 +416,7 @@ class DriftClient {
|
|
|
401
416
|
async deleteUser(subAccountId = 0) {
|
|
402
417
|
var _a;
|
|
403
418
|
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
404
|
-
const
|
|
419
|
+
const ix = await this.program.instruction.deleteUser({
|
|
405
420
|
accounts: {
|
|
406
421
|
user: userAccountPublicKey,
|
|
407
422
|
userStats: this.getUserStatsAccountPublicKey(),
|
|
@@ -409,6 +424,7 @@ class DriftClient {
|
|
|
409
424
|
state: await this.getStatePublicKey(),
|
|
410
425
|
},
|
|
411
426
|
});
|
|
427
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix), [], this.opts);
|
|
412
428
|
await ((_a = this.users.get(subAccountId)) === null || _a === void 0 ? void 0 : _a.unsubscribe());
|
|
413
429
|
this.users.delete(subAccountId);
|
|
414
430
|
return txSig;
|
|
@@ -667,7 +683,7 @@ class DriftClient {
|
|
|
667
683
|
if (createWSOLTokenAccount) {
|
|
668
684
|
tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, collateralAccountPublicKey, authority, authority, []));
|
|
669
685
|
}
|
|
670
|
-
const { txSig, slot } = await this.
|
|
686
|
+
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
671
687
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
672
688
|
return txSig;
|
|
673
689
|
}
|
|
@@ -678,7 +694,7 @@ class DriftClient {
|
|
|
678
694
|
let remainingAccounts = [];
|
|
679
695
|
if (userInitialized) {
|
|
680
696
|
remainingAccounts = this.getRemainingAccounts({
|
|
681
|
-
userAccounts: [this.
|
|
697
|
+
userAccounts: [await this.forceGetUserAccount()],
|
|
682
698
|
useMarketLastSlotCache: true,
|
|
683
699
|
writableSpotMarketIndexes: [marketIndex],
|
|
684
700
|
});
|
|
@@ -780,7 +796,7 @@ class DriftClient {
|
|
|
780
796
|
if (createWSOLTokenAccount) {
|
|
781
797
|
tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, userTokenAccount, authority, authority, []));
|
|
782
798
|
}
|
|
783
|
-
const { txSig, slot } = await this.
|
|
799
|
+
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
784
800
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
785
801
|
return [txSig, userAccountPublicKey];
|
|
786
802
|
}
|
|
@@ -830,7 +846,7 @@ class DriftClient {
|
|
|
830
846
|
if (createWSOLTokenAccount) {
|
|
831
847
|
tx.add(spl_token_1.Token.createCloseAccountInstruction(spl_token_1.TOKEN_PROGRAM_ID, userTokenAccount, authority, authority, []));
|
|
832
848
|
}
|
|
833
|
-
const { txSig, slot } = await this.
|
|
849
|
+
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
834
850
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
835
851
|
return txSig;
|
|
836
852
|
}
|
|
@@ -859,7 +875,7 @@ class DriftClient {
|
|
|
859
875
|
});
|
|
860
876
|
}
|
|
861
877
|
async transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId) {
|
|
862
|
-
const { txSig, slot } = await this.
|
|
878
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getTransferDepositIx(amount, marketIndex, fromSubAccountId, toSubAccountId)), [], this.opts);
|
|
863
879
|
if (fromSubAccountId === this.activeSubAccountId ||
|
|
864
880
|
toSubAccountId === this.activeSubAccountId) {
|
|
865
881
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
@@ -899,7 +915,7 @@ class DriftClient {
|
|
|
899
915
|
});
|
|
900
916
|
}
|
|
901
917
|
async updateSpotMarketCumulativeInterest(marketIndex) {
|
|
902
|
-
const { txSig } = await this.
|
|
918
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.updateSpotMarketCumulativeInterestIx(marketIndex)), [], this.opts);
|
|
903
919
|
return txSig;
|
|
904
920
|
}
|
|
905
921
|
async updateSpotMarketCumulativeInterestIx(marketIndex) {
|
|
@@ -913,7 +929,7 @@ class DriftClient {
|
|
|
913
929
|
});
|
|
914
930
|
}
|
|
915
931
|
async settleLP(settleeUserAccountPublicKey, marketIndex) {
|
|
916
|
-
const { txSig } = await this.
|
|
932
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.settleLPIx(settleeUserAccountPublicKey, marketIndex)), [], this.opts);
|
|
917
933
|
return txSig;
|
|
918
934
|
}
|
|
919
935
|
async settleLPIx(settleeUserAccountPublicKey, marketIndex) {
|
|
@@ -931,11 +947,11 @@ class DriftClient {
|
|
|
931
947
|
});
|
|
932
948
|
}
|
|
933
949
|
async removePerpLpShares(marketIndex, sharesToBurn) {
|
|
934
|
-
const { txSig } = await this.
|
|
950
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getRemovePerpLpSharesIx(marketIndex, sharesToBurn)), [], this.opts);
|
|
935
951
|
return txSig;
|
|
936
952
|
}
|
|
937
953
|
async removePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
938
|
-
const { txSig } = await this.
|
|
954
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn)), [], this.opts);
|
|
939
955
|
return txSig;
|
|
940
956
|
}
|
|
941
957
|
async getRemovePerpLpSharesInExpiringMarket(marketIndex, userAccountPublicKey, sharesToBurn) {
|
|
@@ -981,7 +997,7 @@ class DriftClient {
|
|
|
981
997
|
});
|
|
982
998
|
}
|
|
983
999
|
async addPerpLpShares(amount, marketIndex) {
|
|
984
|
-
const { txSig, slot } = await this.
|
|
1000
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getAddPerpLpSharesIx(amount, marketIndex)), [], this.opts);
|
|
985
1001
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
986
1002
|
return txSig;
|
|
987
1003
|
}
|
|
@@ -1011,7 +1027,7 @@ class DriftClient {
|
|
|
1011
1027
|
});
|
|
1012
1028
|
}
|
|
1013
1029
|
async sendSignedTx(tx) {
|
|
1014
|
-
const { txSig } = await this.
|
|
1030
|
+
const { txSig } = await this.sendTransaction(tx, undefined, this.opts, true);
|
|
1015
1031
|
return txSig;
|
|
1016
1032
|
}
|
|
1017
1033
|
/**
|
|
@@ -1037,12 +1053,12 @@ class DriftClient {
|
|
|
1037
1053
|
marketOrderTx.feePayer = userAccount.authority;
|
|
1038
1054
|
fillTx.feePayer = userAccount.authority;
|
|
1039
1055
|
const [signedMarketOrderTx, signedFillTx] = await this.provider.wallet.signAllTransactions([marketOrderTx, fillTx]);
|
|
1040
|
-
const { txSig, slot } = await this.
|
|
1056
|
+
const { txSig, slot } = await this.sendTransaction(signedMarketOrderTx, [], this.opts, true);
|
|
1041
1057
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1042
1058
|
return { txSig, signedFillTx };
|
|
1043
1059
|
}
|
|
1044
1060
|
async placePerpOrder(orderParams) {
|
|
1045
|
-
const { txSig, slot } = await this.
|
|
1061
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlacePerpOrderIx(orderParams)), [], this.opts);
|
|
1046
1062
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1047
1063
|
return txSig;
|
|
1048
1064
|
}
|
|
@@ -1070,7 +1086,7 @@ class DriftClient {
|
|
|
1070
1086
|
});
|
|
1071
1087
|
}
|
|
1072
1088
|
async updateAMMs(marketIndexes) {
|
|
1073
|
-
const { txSig } = await this.
|
|
1089
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getUpdateAMMsIx(marketIndexes)), [], this.opts);
|
|
1074
1090
|
return txSig;
|
|
1075
1091
|
}
|
|
1076
1092
|
async getUpdateAMMsIx(marketIndexes) {
|
|
@@ -1104,7 +1120,7 @@ class DriftClient {
|
|
|
1104
1120
|
});
|
|
1105
1121
|
}
|
|
1106
1122
|
async settleExpiredMarket(marketIndex) {
|
|
1107
|
-
const { txSig } = await this.
|
|
1123
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getSettleExpiredMarketIx(marketIndex)), [], this.opts);
|
|
1108
1124
|
return txSig;
|
|
1109
1125
|
}
|
|
1110
1126
|
async getSettleExpiredMarketIx(marketIndex) {
|
|
@@ -1149,11 +1165,11 @@ class DriftClient {
|
|
|
1149
1165
|
perpMarket: perpMarketPublicKey,
|
|
1150
1166
|
},
|
|
1151
1167
|
});
|
|
1152
|
-
const { txSig } = await this.
|
|
1168
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(ix), [], this.opts);
|
|
1153
1169
|
return txSig;
|
|
1154
1170
|
}
|
|
1155
1171
|
async cancelOrder(orderId) {
|
|
1156
|
-
const { txSig } = await this.
|
|
1172
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrderIx(orderId)), [], this.opts);
|
|
1157
1173
|
return txSig;
|
|
1158
1174
|
}
|
|
1159
1175
|
async getCancelOrderIx(orderId) {
|
|
@@ -1172,7 +1188,7 @@ class DriftClient {
|
|
|
1172
1188
|
});
|
|
1173
1189
|
}
|
|
1174
1190
|
async cancelOrderByUserId(userOrderId) {
|
|
1175
|
-
const { txSig } = await this.
|
|
1191
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
|
|
1176
1192
|
return txSig;
|
|
1177
1193
|
}
|
|
1178
1194
|
async getCancelOrderByUserIdIx(userOrderId) {
|
|
@@ -1194,13 +1210,25 @@ class DriftClient {
|
|
|
1194
1210
|
});
|
|
1195
1211
|
}
|
|
1196
1212
|
async cancelOrders(marketType, marketIndex, direction) {
|
|
1197
|
-
const { txSig } = await this.
|
|
1213
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getCancelOrdersIx(marketType, marketIndex, direction)), [], this.opts);
|
|
1198
1214
|
return txSig;
|
|
1199
1215
|
}
|
|
1200
1216
|
async getCancelOrdersIx(marketType, marketIndex, direction) {
|
|
1201
1217
|
const userAccountPublicKey = await this.getUserAccountPublicKey();
|
|
1218
|
+
let readablePerpMarketIndex = undefined;
|
|
1219
|
+
let readableSpotMarketIndexes = undefined;
|
|
1220
|
+
if (marketIndex) {
|
|
1221
|
+
if (marketType && (0, types_1.isVariant)(marketType, 'perp')) {
|
|
1222
|
+
readablePerpMarketIndex = marketIndex;
|
|
1223
|
+
}
|
|
1224
|
+
else if (marketType && (0, types_1.isVariant)(marketType, 'spot')) {
|
|
1225
|
+
readableSpotMarketIndexes = [marketIndex];
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1202
1228
|
const remainingAccounts = this.getRemainingAccounts({
|
|
1203
1229
|
userAccounts: [this.getUserAccount()],
|
|
1230
|
+
readablePerpMarketIndex,
|
|
1231
|
+
readableSpotMarketIndexes,
|
|
1204
1232
|
useMarketLastSlotCache: true,
|
|
1205
1233
|
});
|
|
1206
1234
|
return await this.program.instruction.cancelOrders(marketType !== null && marketType !== void 0 ? marketType : null, marketIndex !== null && marketIndex !== void 0 ? marketIndex : null, direction !== null && direction !== void 0 ? direction : null, {
|
|
@@ -1213,7 +1241,7 @@ class DriftClient {
|
|
|
1213
1241
|
});
|
|
1214
1242
|
}
|
|
1215
1243
|
async fillPerpOrder(userAccountPublicKey, user, order, makerInfo, referrerInfo) {
|
|
1216
|
-
const { txSig } = await this.
|
|
1244
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getFillPerpOrderIx(userAccountPublicKey, user, order, makerInfo, referrerInfo)), [], this.opts);
|
|
1217
1245
|
return txSig;
|
|
1218
1246
|
}
|
|
1219
1247
|
async getFillPerpOrderIx(userAccountPublicKey, userAccount, order, makerInfo, referrerInfo) {
|
|
@@ -1270,7 +1298,7 @@ class DriftClient {
|
|
|
1270
1298
|
});
|
|
1271
1299
|
}
|
|
1272
1300
|
async placeSpotOrder(orderParams) {
|
|
1273
|
-
const { txSig, slot } = await this.
|
|
1301
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceSpotOrderIx(orderParams)), [], this.opts);
|
|
1274
1302
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1275
1303
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1276
1304
|
return txSig;
|
|
@@ -1297,7 +1325,7 @@ class DriftClient {
|
|
|
1297
1325
|
});
|
|
1298
1326
|
}
|
|
1299
1327
|
async fillSpotOrder(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1300
|
-
const { txSig } = await this.
|
|
1328
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getFillSpotOrderIx(userAccountPublicKey, user, order, fulfillmentConfig, makerInfo, referrerInfo)), [], this.opts);
|
|
1301
1329
|
return txSig;
|
|
1302
1330
|
}
|
|
1303
1331
|
async getFillSpotOrderIx(userAccountPublicKey, userAccount, order, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
@@ -1454,7 +1482,7 @@ class DriftClient {
|
|
|
1454
1482
|
});
|
|
1455
1483
|
}
|
|
1456
1484
|
async triggerOrder(userAccountPublicKey, user, order) {
|
|
1457
|
-
const { txSig } = await this.
|
|
1485
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getTriggerOrderIx(userAccountPublicKey, user, order)), [], this.opts);
|
|
1458
1486
|
return txSig;
|
|
1459
1487
|
}
|
|
1460
1488
|
async getTriggerOrderIx(userAccountPublicKey, userAccount, order) {
|
|
@@ -1505,7 +1533,7 @@ class DriftClient {
|
|
|
1505
1533
|
});
|
|
1506
1534
|
}
|
|
1507
1535
|
async placeAndTakePerpOrder(orderParams, makerInfo, referrerInfo) {
|
|
1508
|
-
const { txSig, slot } = await this.
|
|
1536
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndTakePerpOrderIx(orderParams, makerInfo, referrerInfo)), [], this.opts);
|
|
1509
1537
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1510
1538
|
return txSig;
|
|
1511
1539
|
}
|
|
@@ -1559,7 +1587,7 @@ class DriftClient {
|
|
|
1559
1587
|
});
|
|
1560
1588
|
}
|
|
1561
1589
|
async placeAndMakePerpOrder(orderParams, takerInfo, referrerInfo) {
|
|
1562
|
-
const { txSig, slot } = await this.
|
|
1590
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndMakePerpOrderIx(orderParams, takerInfo, referrerInfo)), [], this.opts);
|
|
1563
1591
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1564
1592
|
return txSig;
|
|
1565
1593
|
}
|
|
@@ -1598,7 +1626,7 @@ class DriftClient {
|
|
|
1598
1626
|
});
|
|
1599
1627
|
}
|
|
1600
1628
|
async placeAndTakeSpotOrder(orderParams, fulfillmentConfig, makerInfo, referrerInfo) {
|
|
1601
|
-
const { txSig, slot } = await this.
|
|
1629
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndTakeSpotOrderIx(orderParams, fulfillmentConfig, makerInfo, referrerInfo)), [], this.opts);
|
|
1602
1630
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1603
1631
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1604
1632
|
return txSig;
|
|
@@ -1657,7 +1685,7 @@ class DriftClient {
|
|
|
1657
1685
|
});
|
|
1658
1686
|
}
|
|
1659
1687
|
async placeAndMakeSpotOrder(orderParams, takerInfo, fulfillmentConfig, referrerInfo) {
|
|
1660
|
-
const { txSig, slot } = await this.
|
|
1688
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getPlaceAndMakeSpotOrderIx(orderParams, takerInfo, fulfillmentConfig, referrerInfo)), [], this.opts);
|
|
1661
1689
|
this.spotMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1662
1690
|
this.spotMarketLastSlotCache.set(numericConstants_1.QUOTE_SPOT_MARKET_INDEX, slot);
|
|
1663
1691
|
return txSig;
|
|
@@ -1762,7 +1790,7 @@ class DriftClient {
|
|
|
1762
1790
|
}));
|
|
1763
1791
|
tx.add(cancelOrderIx);
|
|
1764
1792
|
tx.add(placeOrderIx);
|
|
1765
|
-
const { txSig, slot } = await this.
|
|
1793
|
+
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);
|
|
1766
1794
|
this.perpMarketLastSlotCache.set(newOrderParams.marketIndex, slot);
|
|
1767
1795
|
return txSig;
|
|
1768
1796
|
}
|
|
@@ -1777,11 +1805,11 @@ class DriftClient {
|
|
|
1777
1805
|
additionalFee: 0,
|
|
1778
1806
|
}))
|
|
1779
1807
|
.add(...ixs);
|
|
1780
|
-
const { txSig } = await this.
|
|
1808
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1781
1809
|
return txSig;
|
|
1782
1810
|
}
|
|
1783
1811
|
async settlePNL(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
1784
|
-
const { txSig } = await this.
|
|
1812
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex)), [], this.opts);
|
|
1785
1813
|
return txSig;
|
|
1786
1814
|
}
|
|
1787
1815
|
async settlePNLIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndex) {
|
|
@@ -1801,7 +1829,7 @@ class DriftClient {
|
|
|
1801
1829
|
});
|
|
1802
1830
|
}
|
|
1803
1831
|
async liquidatePerp(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice) {
|
|
1804
|
-
const { txSig, slot } = await this.
|
|
1832
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidatePerpIx(userAccountPublicKey, userAccount, marketIndex, maxBaseAssetAmount, limitPrice)), [], this.opts);
|
|
1805
1833
|
this.perpMarketLastSlotCache.set(marketIndex, slot);
|
|
1806
1834
|
return txSig;
|
|
1807
1835
|
}
|
|
@@ -1827,7 +1855,7 @@ class DriftClient {
|
|
|
1827
1855
|
});
|
|
1828
1856
|
}
|
|
1829
1857
|
async liquidateSpot(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1830
|
-
const { txSig, slot } = await this.
|
|
1858
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidateSpotIx(userAccountPublicKey, userAccount, assetMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1831
1859
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1832
1860
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1833
1861
|
return txSig;
|
|
@@ -1854,7 +1882,7 @@ class DriftClient {
|
|
|
1854
1882
|
});
|
|
1855
1883
|
}
|
|
1856
1884
|
async liquidateBorrowForPerpPnl(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice) {
|
|
1857
|
-
const { txSig, slot } = await this.
|
|
1885
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidateBorrowForPerpPnlIx(userAccountPublicKey, userAccount, perpMarketIndex, liabilityMarketIndex, maxLiabilityTransfer, limitPrice)), [], this.opts);
|
|
1858
1886
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1859
1887
|
this.spotMarketLastSlotCache.set(liabilityMarketIndex, slot);
|
|
1860
1888
|
return txSig;
|
|
@@ -1881,7 +1909,7 @@ class DriftClient {
|
|
|
1881
1909
|
});
|
|
1882
1910
|
}
|
|
1883
1911
|
async liquidatePerpPnlForDeposit(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice) {
|
|
1884
|
-
const { txSig, slot } = await this.
|
|
1912
|
+
const { txSig, slot } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getLiquidatePerpPnlForDepositIx(userAccountPublicKey, userAccount, perpMarketIndex, assetMarketIndex, maxPnlTransfer, limitPrice)), [], this.opts);
|
|
1885
1913
|
this.perpMarketLastSlotCache.set(perpMarketIndex, slot);
|
|
1886
1914
|
this.spotMarketLastSlotCache.set(assetMarketIndex, slot);
|
|
1887
1915
|
return txSig;
|
|
@@ -1908,7 +1936,7 @@ class DriftClient {
|
|
|
1908
1936
|
});
|
|
1909
1937
|
}
|
|
1910
1938
|
async resolvePerpBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
1911
|
-
const { txSig } = await this.
|
|
1939
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
1912
1940
|
return txSig;
|
|
1913
1941
|
}
|
|
1914
1942
|
async getResolvePerpBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
@@ -1938,7 +1966,7 @@ class DriftClient {
|
|
|
1938
1966
|
});
|
|
1939
1967
|
}
|
|
1940
1968
|
async resolveSpotBankruptcy(userAccountPublicKey, userAccount, marketIndex) {
|
|
1941
|
-
const { txSig } = await this.
|
|
1969
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex)), [], this.opts);
|
|
1942
1970
|
return txSig;
|
|
1943
1971
|
}
|
|
1944
1972
|
async getResolveSpotBankruptcyIx(userAccountPublicKey, userAccount, marketIndex) {
|
|
@@ -1967,7 +1995,7 @@ class DriftClient {
|
|
|
1967
1995
|
});
|
|
1968
1996
|
}
|
|
1969
1997
|
async updateFundingRate(perpMarketIndex, oracle) {
|
|
1970
|
-
const { txSig } = await this.
|
|
1998
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getUpdateFundingRateIx(perpMarketIndex, oracle)), [], this.opts);
|
|
1971
1999
|
return txSig;
|
|
1972
2000
|
}
|
|
1973
2001
|
async getUpdateFundingRateIx(perpMarketIndex, oracle) {
|
|
@@ -1981,7 +2009,7 @@ class DriftClient {
|
|
|
1981
2009
|
});
|
|
1982
2010
|
}
|
|
1983
2011
|
async settleFundingPayment(userAccountPublicKey) {
|
|
1984
|
-
const { txSig } = await this.
|
|
2012
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getSettleFundingPaymentIx(userAccountPublicKey)), [], this.opts);
|
|
1985
2013
|
return txSig;
|
|
1986
2014
|
}
|
|
1987
2015
|
async getSettleFundingPaymentIx(userAccountPublicKey) {
|
|
@@ -2018,7 +2046,7 @@ class DriftClient {
|
|
|
2018
2046
|
return oracleData;
|
|
2019
2047
|
}
|
|
2020
2048
|
async initializeInsuranceFundStake(marketIndex) {
|
|
2021
|
-
const { txSig } = await this.
|
|
2049
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getInitializeInsuranceFundStakeIx(marketIndex)), [], this.opts);
|
|
2022
2050
|
return txSig;
|
|
2023
2051
|
}
|
|
2024
2052
|
async getInitializeInsuranceFundStakeIx(marketIndex) {
|
|
@@ -2044,7 +2072,7 @@ class DriftClient {
|
|
|
2044
2072
|
useMarketLastSlotCache: true,
|
|
2045
2073
|
writableSpotMarketIndexes: [marketIndex],
|
|
2046
2074
|
});
|
|
2047
|
-
|
|
2075
|
+
const tx = await this.program.transaction.addInsuranceFundStake(marketIndex, amount, {
|
|
2048
2076
|
accounts: {
|
|
2049
2077
|
state: await this.getStatePublicKey(),
|
|
2050
2078
|
spotMarket: spotMarket.pubkey,
|
|
@@ -2059,6 +2087,8 @@ class DriftClient {
|
|
|
2059
2087
|
},
|
|
2060
2088
|
remainingAccounts,
|
|
2061
2089
|
});
|
|
2090
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2091
|
+
return txSig;
|
|
2062
2092
|
}
|
|
2063
2093
|
async requestRemoveInsuranceFundStake(marketIndex, amount) {
|
|
2064
2094
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2068,7 +2098,7 @@ class DriftClient {
|
|
|
2068
2098
|
useMarketLastSlotCache: true,
|
|
2069
2099
|
writableSpotMarketIndexes: [marketIndex],
|
|
2070
2100
|
});
|
|
2071
|
-
|
|
2101
|
+
const tx = await this.program.transaction.requestRemoveInsuranceFundStake(marketIndex, amount, {
|
|
2072
2102
|
accounts: {
|
|
2073
2103
|
state: await this.getStatePublicKey(),
|
|
2074
2104
|
spotMarket: spotMarketAccount.pubkey,
|
|
@@ -2079,6 +2109,8 @@ class DriftClient {
|
|
|
2079
2109
|
},
|
|
2080
2110
|
remainingAccounts,
|
|
2081
2111
|
});
|
|
2112
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2113
|
+
return txSig;
|
|
2082
2114
|
}
|
|
2083
2115
|
async cancelRequestRemoveInsuranceFundStake(marketIndex) {
|
|
2084
2116
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2088,7 +2120,7 @@ class DriftClient {
|
|
|
2088
2120
|
useMarketLastSlotCache: true,
|
|
2089
2121
|
writableSpotMarketIndexes: [marketIndex],
|
|
2090
2122
|
});
|
|
2091
|
-
|
|
2123
|
+
const tx = await this.program.transaction.cancelRequestRemoveInsuranceFundStake(marketIndex, {
|
|
2092
2124
|
accounts: {
|
|
2093
2125
|
state: await this.getStatePublicKey(),
|
|
2094
2126
|
spotMarket: spotMarketAccount.pubkey,
|
|
@@ -2099,6 +2131,8 @@ class DriftClient {
|
|
|
2099
2131
|
},
|
|
2100
2132
|
remainingAccounts,
|
|
2101
2133
|
});
|
|
2134
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2135
|
+
return txSig;
|
|
2102
2136
|
}
|
|
2103
2137
|
async removeInsuranceFundStake(marketIndex, collateralAccountPublicKey) {
|
|
2104
2138
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2108,7 +2142,7 @@ class DriftClient {
|
|
|
2108
2142
|
useMarketLastSlotCache: true,
|
|
2109
2143
|
writableSpotMarketIndexes: [marketIndex],
|
|
2110
2144
|
});
|
|
2111
|
-
|
|
2145
|
+
const tx = await this.program.transaction.removeInsuranceFundStake(marketIndex, {
|
|
2112
2146
|
accounts: {
|
|
2113
2147
|
state: await this.getStatePublicKey(),
|
|
2114
2148
|
spotMarket: spotMarketAccount.pubkey,
|
|
@@ -2122,6 +2156,8 @@ class DriftClient {
|
|
|
2122
2156
|
},
|
|
2123
2157
|
remainingAccounts,
|
|
2124
2158
|
});
|
|
2159
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2160
|
+
return txSig;
|
|
2125
2161
|
}
|
|
2126
2162
|
async settleRevenueToInsuranceFund(marketIndex) {
|
|
2127
2163
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -2130,7 +2166,7 @@ class DriftClient {
|
|
|
2130
2166
|
useMarketLastSlotCache: true,
|
|
2131
2167
|
writableSpotMarketIndexes: [marketIndex],
|
|
2132
2168
|
});
|
|
2133
|
-
|
|
2169
|
+
const tx = await this.program.transaction.settleRevenueToInsuranceFund(marketIndex, {
|
|
2134
2170
|
accounts: {
|
|
2135
2171
|
state: await this.getStatePublicKey(),
|
|
2136
2172
|
spotMarket: spotMarketAccount.pubkey,
|
|
@@ -2141,9 +2177,11 @@ class DriftClient {
|
|
|
2141
2177
|
},
|
|
2142
2178
|
remainingAccounts,
|
|
2143
2179
|
});
|
|
2180
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
2181
|
+
return txSig;
|
|
2144
2182
|
}
|
|
2145
2183
|
async resolvePerpPnlDeficit(spotMarketIndex, perpMarketIndex) {
|
|
2146
|
-
const { txSig } = await this.
|
|
2184
|
+
const { txSig } = await this.sendTransaction((0, utils_1.wrapInTx)(await this.getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex)), [], this.opts);
|
|
2147
2185
|
return txSig;
|
|
2148
2186
|
}
|
|
2149
2187
|
async getResolvePerpPnlDeficitIx(spotMarketIndex, perpMarketIndex) {
|
|
@@ -2166,5 +2204,8 @@ class DriftClient {
|
|
|
2166
2204
|
remainingAccounts: remainingAccounts,
|
|
2167
2205
|
});
|
|
2168
2206
|
}
|
|
2207
|
+
sendTransaction(tx, additionalSigners, opts, preSigned) {
|
|
2208
|
+
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
2209
|
+
}
|
|
2169
2210
|
}
|
|
2170
2211
|
exports.DriftClient = DriftClient;
|
package/lib/idl/drift.json
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
|
20
20
|
export * from './accounts/types';
|
|
21
21
|
export * from './addresses/pda';
|
|
22
22
|
export * from './adminClient';
|
|
23
|
+
export * from './testClient';
|
|
23
24
|
export * from './user';
|
|
24
25
|
export * from './userConfig';
|
|
25
26
|
export * from './userStats';
|
package/lib/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __exportStar(require("./accounts/pollingUserStatsAccountSubscriber"), exports);
|
|
|
43
43
|
__exportStar(require("./accounts/types"), exports);
|
|
44
44
|
__exportStar(require("./addresses/pda"), exports);
|
|
45
45
|
__exportStar(require("./adminClient"), exports);
|
|
46
|
+
__exportStar(require("./testClient"), exports);
|
|
46
47
|
__exportStar(require("./user"), exports);
|
|
47
48
|
__exportStar(require("./userConfig"), exports);
|
|
48
49
|
__exportStar(require("./userStats"), exports);
|