@drift-labs/sdk 2.23.0-beta.1 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/driftClient.d.ts +1 -0
- package/lib/driftClient.js +13 -22
- package/lib/idl/drift.json +17 -1
- package/lib/tx/utils.js +2 -6
- package/lib/user.js +2 -1
- package/package.json +1 -1
- package/src/driftClient.ts +7 -8
- package/src/idl/drift.json +17 -1
- package/src/tx/utils.ts +0 -2
- package/src/user.ts +4 -1
package/lib/driftClient.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ export declare class DriftClient {
|
|
|
93
93
|
updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number): Promise<void>;
|
|
94
94
|
switchActiveUser(subAccountId: number): void;
|
|
95
95
|
addUser(subAccountId: number): Promise<void>;
|
|
96
|
+
addAllUsers(): Promise<void>;
|
|
96
97
|
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
97
98
|
getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
98
99
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -246,7 +246,6 @@ class DriftClient {
|
|
|
246
246
|
if (!this.marketLookupTable) {
|
|
247
247
|
throw Error('Market lookup table address not set');
|
|
248
248
|
}
|
|
249
|
-
// @ts-ignore
|
|
250
249
|
return (await this.connection.getAddressLookupTable(this.marketLookupTable))
|
|
251
250
|
.value;
|
|
252
251
|
}
|
|
@@ -298,6 +297,12 @@ class DriftClient {
|
|
|
298
297
|
await user.subscribe();
|
|
299
298
|
this.users.set(subAccountId, user);
|
|
300
299
|
}
|
|
300
|
+
async addAllUsers() {
|
|
301
|
+
const userAccounts = await this.getUserAccountsForAuthority(this.authority);
|
|
302
|
+
for (const userAccount of userAccounts) {
|
|
303
|
+
await this.addUser(userAccount.subAccountId);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
301
306
|
async initializeUserAccount(subAccountId = 0, name = userName_1.DEFAULT_USER_NAME, referrerInfo) {
|
|
302
307
|
const [userAccountPublicKey, initializeUserAccountIx] = await this.getInitializeUserInstructions(subAccountId, name, referrerInfo);
|
|
303
308
|
const tx = new web3_js_1.Transaction();
|
|
@@ -801,9 +806,7 @@ class DriftClient {
|
|
|
801
806
|
}
|
|
802
807
|
async deposit(amount, marketIndex, collateralAccountPublicKey, subAccountId, reduceOnly = false) {
|
|
803
808
|
const tx = new web3_js_1.Transaction();
|
|
804
|
-
tx.add(
|
|
805
|
-
// @ts-ignore
|
|
806
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
809
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
807
810
|
units: 600000,
|
|
808
811
|
}));
|
|
809
812
|
const additionalSigners = [];
|
|
@@ -916,15 +919,11 @@ class DriftClient {
|
|
|
916
919
|
const spotMarket = this.getSpotMarketAccount(marketIndex);
|
|
917
920
|
const isSolMarket = spotMarket.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
918
921
|
const tx = new web3_js_1.Transaction();
|
|
919
|
-
tx.add(
|
|
920
|
-
// @ts-ignore
|
|
921
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
922
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
922
923
|
units: (_a = txParams === null || txParams === void 0 ? void 0 : txParams.computeUnits) !== null && _a !== void 0 ? _a : 600000,
|
|
923
924
|
}));
|
|
924
925
|
if (txParams === null || txParams === void 0 ? void 0 : txParams.computeUnitsPrice) {
|
|
925
|
-
tx.add(
|
|
926
|
-
// @ts-ignore
|
|
927
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
926
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
928
927
|
microLamports: txParams.computeUnitsPrice,
|
|
929
928
|
}));
|
|
930
929
|
}
|
|
@@ -971,9 +970,7 @@ class DriftClient {
|
|
|
971
970
|
}
|
|
972
971
|
async withdraw(amount, marketIndex, userTokenAccount, reduceOnly = false) {
|
|
973
972
|
const tx = new web3_js_1.Transaction();
|
|
974
|
-
tx.add(
|
|
975
|
-
// @ts-ignore
|
|
976
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
973
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
977
974
|
units: 600000,
|
|
978
975
|
}));
|
|
979
976
|
const additionalSigners = [];
|
|
@@ -2048,9 +2045,7 @@ class DriftClient {
|
|
|
2048
2045
|
? await this.getPlaceSpotOrderIx(newOrderParams)
|
|
2049
2046
|
: await this.getPlacePerpOrderIx(newOrderParams);
|
|
2050
2047
|
const tx = new web3_js_1.Transaction();
|
|
2051
|
-
tx.add(
|
|
2052
|
-
// @ts-ignore
|
|
2053
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2048
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2054
2049
|
units: 1000000,
|
|
2055
2050
|
}));
|
|
2056
2051
|
tx.add(cancelOrderIx);
|
|
@@ -2125,9 +2120,7 @@ class DriftClient {
|
|
|
2125
2120
|
? await this.getPlaceSpotOrderIx(newOrderParams)
|
|
2126
2121
|
: await this.getPlacePerpOrderIx(newOrderParams);
|
|
2127
2122
|
const tx = new web3_js_1.Transaction();
|
|
2128
|
-
tx.add(
|
|
2129
|
-
// @ts-ignore
|
|
2130
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2123
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2131
2124
|
units: 1000000,
|
|
2132
2125
|
}));
|
|
2133
2126
|
tx.add(cancelOrderIx);
|
|
@@ -2150,9 +2143,7 @@ class DriftClient {
|
|
|
2150
2143
|
}
|
|
2151
2144
|
}
|
|
2152
2145
|
const tx = new web3_js_1.Transaction()
|
|
2153
|
-
.add(
|
|
2154
|
-
// @ts-ignore
|
|
2155
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2146
|
+
.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
2156
2147
|
units: 1000000,
|
|
2157
2148
|
}))
|
|
2158
2149
|
.add(...ixs);
|
package/lib/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.23.0
|
|
2
|
+
"version": "2.23.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -5994,6 +5994,22 @@
|
|
|
5994
5994
|
]
|
|
5995
5995
|
}
|
|
5996
5996
|
},
|
|
5997
|
+
{
|
|
5998
|
+
"name": "FulfillmentParams",
|
|
5999
|
+
"type": {
|
|
6000
|
+
"kind": "enum",
|
|
6001
|
+
"variants": [
|
|
6002
|
+
{
|
|
6003
|
+
"name": "SerumFulfillmentParams",
|
|
6004
|
+
"fields": [
|
|
6005
|
+
{
|
|
6006
|
+
"defined": "SerumFulfillmentParams<'a,'b>"
|
|
6007
|
+
}
|
|
6008
|
+
]
|
|
6009
|
+
}
|
|
6010
|
+
]
|
|
6011
|
+
}
|
|
6012
|
+
},
|
|
5997
6013
|
{
|
|
5998
6014
|
"name": "SpotFulfillmentType",
|
|
5999
6015
|
"type": {
|
package/lib/tx/utils.js
CHANGED
|
@@ -6,16 +6,12 @@ const COMPUTE_UNITS_DEFAULT = 200000;
|
|
|
6
6
|
function wrapInTx(instruction, computeUnits = 600000, computeUnitsPrice = 0) {
|
|
7
7
|
const tx = new web3_js_1.Transaction();
|
|
8
8
|
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
9
|
-
tx.add(
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
9
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
12
10
|
units: computeUnits,
|
|
13
11
|
}));
|
|
14
12
|
}
|
|
15
13
|
if (computeUnitsPrice != 0) {
|
|
16
|
-
tx.add(
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
14
|
+
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
19
15
|
microLamports: computeUnitsPrice,
|
|
20
16
|
}));
|
|
21
17
|
}
|
package/lib/user.js
CHANGED
|
@@ -1249,7 +1249,8 @@ class User {
|
|
|
1249
1249
|
}
|
|
1250
1250
|
}
|
|
1251
1251
|
for (const spotPosition of userAccount.spotPositions) {
|
|
1252
|
-
if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow')
|
|
1252
|
+
if ((0, types_1.isVariant)(spotPosition.balanceType, 'borrow') &&
|
|
1253
|
+
spotPosition.scaledBalance.gt(numericConstants_1.ZERO)) {
|
|
1253
1254
|
return false;
|
|
1254
1255
|
}
|
|
1255
1256
|
if (spotPosition.openOrders !== 0) {
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -418,7 +418,6 @@ export class DriftClient {
|
|
|
418
418
|
throw Error('Market lookup table address not set');
|
|
419
419
|
}
|
|
420
420
|
|
|
421
|
-
// @ts-ignore
|
|
422
421
|
return (await this.connection.getAddressLookupTable(this.marketLookupTable))
|
|
423
422
|
.value;
|
|
424
423
|
}
|
|
@@ -500,6 +499,13 @@ export class DriftClient {
|
|
|
500
499
|
this.users.set(subAccountId, user);
|
|
501
500
|
}
|
|
502
501
|
|
|
502
|
+
public async addAllUsers(): Promise<void> {
|
|
503
|
+
const userAccounts = await this.getUserAccountsForAuthority(this.authority);
|
|
504
|
+
for (const userAccount of userAccounts) {
|
|
505
|
+
await this.addUser(userAccount.subAccountId);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
503
509
|
public async initializeUserAccount(
|
|
504
510
|
subAccountId = 0,
|
|
505
511
|
name = DEFAULT_USER_NAME,
|
|
@@ -1233,7 +1239,6 @@ export class DriftClient {
|
|
|
1233
1239
|
): Promise<TransactionSignature> {
|
|
1234
1240
|
const tx = new Transaction();
|
|
1235
1241
|
tx.add(
|
|
1236
|
-
// @ts-ignore
|
|
1237
1242
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1238
1243
|
units: 600_000,
|
|
1239
1244
|
})
|
|
@@ -1459,7 +1464,6 @@ export class DriftClient {
|
|
|
1459
1464
|
const tx = new Transaction();
|
|
1460
1465
|
|
|
1461
1466
|
tx.add(
|
|
1462
|
-
// @ts-ignore
|
|
1463
1467
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1464
1468
|
units: txParams?.computeUnits ?? 600_000,
|
|
1465
1469
|
})
|
|
@@ -1467,7 +1471,6 @@ export class DriftClient {
|
|
|
1467
1471
|
|
|
1468
1472
|
if (txParams?.computeUnitsPrice) {
|
|
1469
1473
|
tx.add(
|
|
1470
|
-
// @ts-ignore
|
|
1471
1474
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
1472
1475
|
microLamports: txParams.computeUnitsPrice,
|
|
1473
1476
|
})
|
|
@@ -1598,7 +1601,6 @@ export class DriftClient {
|
|
|
1598
1601
|
): Promise<TransactionSignature> {
|
|
1599
1602
|
const tx = new Transaction();
|
|
1600
1603
|
tx.add(
|
|
1601
|
-
// @ts-ignore
|
|
1602
1604
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1603
1605
|
units: 600_000,
|
|
1604
1606
|
})
|
|
@@ -3458,7 +3460,6 @@ export class DriftClient {
|
|
|
3458
3460
|
|
|
3459
3461
|
const tx = new Transaction();
|
|
3460
3462
|
tx.add(
|
|
3461
|
-
// @ts-ignore
|
|
3462
3463
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
3463
3464
|
units: 1_000_000,
|
|
3464
3465
|
})
|
|
@@ -3570,7 +3571,6 @@ export class DriftClient {
|
|
|
3570
3571
|
|
|
3571
3572
|
const tx = new Transaction();
|
|
3572
3573
|
tx.add(
|
|
3573
|
-
// @ts-ignore
|
|
3574
3574
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
3575
3575
|
units: 1_000_000,
|
|
3576
3576
|
})
|
|
@@ -3611,7 +3611,6 @@ export class DriftClient {
|
|
|
3611
3611
|
|
|
3612
3612
|
const tx = new Transaction()
|
|
3613
3613
|
.add(
|
|
3614
|
-
// @ts-ignore
|
|
3615
3614
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
3616
3615
|
units: 1_000_000,
|
|
3617
3616
|
})
|
package/src/idl/drift.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.23.0
|
|
2
|
+
"version": "2.23.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -5994,6 +5994,22 @@
|
|
|
5994
5994
|
]
|
|
5995
5995
|
}
|
|
5996
5996
|
},
|
|
5997
|
+
{
|
|
5998
|
+
"name": "FulfillmentParams",
|
|
5999
|
+
"type": {
|
|
6000
|
+
"kind": "enum",
|
|
6001
|
+
"variants": [
|
|
6002
|
+
{
|
|
6003
|
+
"name": "SerumFulfillmentParams",
|
|
6004
|
+
"fields": [
|
|
6005
|
+
{
|
|
6006
|
+
"defined": "SerumFulfillmentParams<'a,'b>"
|
|
6007
|
+
}
|
|
6008
|
+
]
|
|
6009
|
+
}
|
|
6010
|
+
]
|
|
6011
|
+
}
|
|
6012
|
+
},
|
|
5997
6013
|
{
|
|
5998
6014
|
"name": "SpotFulfillmentType",
|
|
5999
6015
|
"type": {
|
package/src/tx/utils.ts
CHANGED
|
@@ -14,7 +14,6 @@ export function wrapInTx(
|
|
|
14
14
|
const tx = new Transaction();
|
|
15
15
|
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
16
16
|
tx.add(
|
|
17
|
-
// @ts-ignore
|
|
18
17
|
ComputeBudgetProgram.setComputeUnitLimit({
|
|
19
18
|
units: computeUnits,
|
|
20
19
|
})
|
|
@@ -23,7 +22,6 @@ export function wrapInTx(
|
|
|
23
22
|
|
|
24
23
|
if (computeUnitsPrice != 0) {
|
|
25
24
|
tx.add(
|
|
26
|
-
// @ts-ignore
|
|
27
25
|
ComputeBudgetProgram.setComputeUnitPrice({
|
|
28
26
|
microLamports: computeUnitsPrice,
|
|
29
27
|
})
|
package/src/user.ts
CHANGED
|
@@ -2253,7 +2253,10 @@ export class User {
|
|
|
2253
2253
|
}
|
|
2254
2254
|
|
|
2255
2255
|
for (const spotPosition of userAccount.spotPositions) {
|
|
2256
|
-
if (
|
|
2256
|
+
if (
|
|
2257
|
+
isVariant(spotPosition.balanceType, 'borrow') &&
|
|
2258
|
+
spotPosition.scaledBalance.gt(ZERO)
|
|
2259
|
+
) {
|
|
2257
2260
|
return false;
|
|
2258
2261
|
}
|
|
2259
2262
|
|