@drift-labs/sdk-browser 2.137.0-beta.0 → 2.137.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/VERSION +1 -1
- package/lib/browser/accounts/webSocketAccountSubscriberV2.d.ts +1 -1
- package/lib/browser/accounts/webSocketProgramAccountsSubscriberV2.d.ts +1 -1
- package/lib/browser/decode/user.js +3 -2
- package/lib/browser/driftClient.d.ts +2 -0
- package/lib/browser/driftClient.js +17 -0
- package/lib/browser/idl/drift.json +28 -175
- package/lib/browser/math/bankruptcy.js +1 -2
- package/lib/browser/types.d.ts +2 -0
- package/lib/browser/user.d.ts +2 -15
- package/lib/browser/user.js +29 -225
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/webSocketAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts +1 -1
- package/lib/node/accounts/webSocketProgramAccountsSubscriberV2.d.ts.map +1 -1
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +3 -2
- package/lib/node/driftClient.d.ts +2 -0
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +17 -0
- package/lib/node/idl/drift.json +28 -175
- package/lib/node/math/bankruptcy.d.ts.map +1 -1
- package/lib/node/math/bankruptcy.js +1 -2
- package/lib/node/types.d.ts +2 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +2 -15
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +29 -225
- package/package.json +1 -1
- package/src/accounts/webSocketAccountSubscriberV2.ts +2 -2
- package/src/accounts/webSocketProgramAccountsSubscriberV2.ts +2 -2
- package/src/decode/user.ts +3 -2
- package/src/driftClient.ts +44 -0
- package/src/idl/drift.json +29 -176
- package/src/math/bankruptcy.ts +1 -2
- package/src/types.ts +2 -0
- package/src/user.ts +47 -343
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.137.0-beta.
|
|
1
|
+
2.137.0-beta.2
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { DataAndSlot, AccountSubscriber, ResubOpts, BufferAndSlot } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
|
-
import { AccountInfoBase, AccountInfoWithBase64EncodedData, AccountInfoWithBase58EncodedData, Rpc, RpcSubscriptions, SolanaRpcSubscriptionsApi,
|
|
5
|
+
import { AccountInfoBase, AccountInfoWithBase64EncodedData, AccountInfoWithBase58EncodedData, Rpc, RpcSubscriptions, SolanaRpcSubscriptionsApi, Commitment } from 'gill';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
7
7
|
/**
|
|
8
8
|
* WebSocketAccountSubscriberV2
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { BufferAndSlot, ProgramAccountSubscriber, ResubOpts } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
5
|
import { Commitment, Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
6
|
-
import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData,
|
|
6
|
+
import { AccountInfoBase, AccountInfoWithBase58EncodedData, AccountInfoWithBase64EncodedData, Address } from 'gill';
|
|
7
7
|
/**
|
|
8
8
|
* WebSocketProgramAccountsSubscriberV2
|
|
9
9
|
*
|
|
@@ -94,7 +94,7 @@ function decodeUser(buffer) {
|
|
|
94
94
|
offset += 8;
|
|
95
95
|
const lastQuoteAssetAmountPerLp = readSignedBigInt64LE(buffer, offset);
|
|
96
96
|
offset += 8;
|
|
97
|
-
const
|
|
97
|
+
const maxMarginRatio = buffer.readUInt16LE(offset);
|
|
98
98
|
offset += 4;
|
|
99
99
|
const marketIndex = buffer.readUInt16LE(offset);
|
|
100
100
|
offset += 3;
|
|
@@ -110,12 +110,13 @@ function decodeUser(buffer) {
|
|
|
110
110
|
openAsks,
|
|
111
111
|
settledPnl,
|
|
112
112
|
lpShares,
|
|
113
|
+
remainderBaseAssetAmount: 0,
|
|
113
114
|
lastBaseAssetAmountPerLp,
|
|
114
115
|
lastQuoteAssetAmountPerLp,
|
|
115
|
-
remainderBaseAssetAmount,
|
|
116
116
|
marketIndex,
|
|
117
117
|
openOrders,
|
|
118
118
|
perLpBase,
|
|
119
|
+
maxMarginRatio,
|
|
119
120
|
});
|
|
120
121
|
}
|
|
121
122
|
const orders = [];
|
|
@@ -188,6 +188,8 @@ export declare class DriftClient {
|
|
|
188
188
|
subAccountId: number;
|
|
189
189
|
}[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
190
190
|
getUpdateUserCustomMarginRatioIx(marginRatio: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
191
|
+
getUpdateUserPerpPositionCustomMarginRatioIx(perpMarketIndex: number, marginRatio: number, subAccountId?: number): Promise<TransactionInstruction>;
|
|
192
|
+
updateUserPerpPositionCustomMarginRatio(perpMarketIndex: number, marginRatio: number, subAccountId?: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
191
193
|
getUpdateUserMarginTradingEnabledIx(marginTradingEnabled: boolean, subAccountId?: number, userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
192
194
|
updateUserMarginTradingEnabled(updates: {
|
|
193
195
|
marginTradingEnabled: boolean;
|
|
@@ -868,6 +868,23 @@ class DriftClient {
|
|
|
868
868
|
});
|
|
869
869
|
return ix;
|
|
870
870
|
}
|
|
871
|
+
async getUpdateUserPerpPositionCustomMarginRatioIx(perpMarketIndex, marginRatio, subAccountId = 0) {
|
|
872
|
+
const userAccountPublicKey = (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
873
|
+
await this.addUser(subAccountId, this.wallet.publicKey);
|
|
874
|
+
const ix = this.program.instruction.updateUserPerpPositionCustomMarginRatio(subAccountId, perpMarketIndex, marginRatio, {
|
|
875
|
+
accounts: {
|
|
876
|
+
user: userAccountPublicKey,
|
|
877
|
+
authority: this.wallet.publicKey,
|
|
878
|
+
},
|
|
879
|
+
});
|
|
880
|
+
return ix;
|
|
881
|
+
}
|
|
882
|
+
async updateUserPerpPositionCustomMarginRatio(perpMarketIndex, marginRatio, subAccountId = 0, txParams) {
|
|
883
|
+
const ix = await this.getUpdateUserPerpPositionCustomMarginRatioIx(perpMarketIndex, marginRatio, subAccountId);
|
|
884
|
+
const tx = await this.buildTransaction(ix, txParams !== null && txParams !== void 0 ? txParams : this.txParams);
|
|
885
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
886
|
+
return txSig;
|
|
887
|
+
}
|
|
871
888
|
async getUpdateUserMarginTradingEnabledIx(marginTradingEnabled, subAccountId = 0, userAccountPublicKey) {
|
|
872
889
|
const userAccountPublicKeyToUse = userAccountPublicKey ||
|
|
873
890
|
(0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId);
|
|
@@ -1390,13 +1390,8 @@
|
|
|
1390
1390
|
]
|
|
1391
1391
|
},
|
|
1392
1392
|
{
|
|
1393
|
-
"name": "
|
|
1393
|
+
"name": "updateUserName",
|
|
1394
1394
|
"accounts": [
|
|
1395
|
-
{
|
|
1396
|
-
"name": "state",
|
|
1397
|
-
"isMut": false,
|
|
1398
|
-
"isSigner": false
|
|
1399
|
-
},
|
|
1400
1395
|
{
|
|
1401
1396
|
"name": "user",
|
|
1402
1397
|
"isMut": true,
|
|
@@ -1410,23 +1405,23 @@
|
|
|
1410
1405
|
],
|
|
1411
1406
|
"args": [
|
|
1412
1407
|
{
|
|
1413
|
-
"name": "
|
|
1414
|
-
"type": "
|
|
1408
|
+
"name": "subAccountId",
|
|
1409
|
+
"type": "u16"
|
|
1415
1410
|
},
|
|
1416
1411
|
{
|
|
1417
|
-
"name": "
|
|
1418
|
-
"type":
|
|
1412
|
+
"name": "name",
|
|
1413
|
+
"type": {
|
|
1414
|
+
"array": [
|
|
1415
|
+
"u8",
|
|
1416
|
+
32
|
|
1417
|
+
]
|
|
1418
|
+
}
|
|
1419
1419
|
}
|
|
1420
1420
|
]
|
|
1421
1421
|
},
|
|
1422
1422
|
{
|
|
1423
|
-
"name": "
|
|
1423
|
+
"name": "updateUserCustomMarginRatio",
|
|
1424
1424
|
"accounts": [
|
|
1425
|
-
{
|
|
1426
|
-
"name": "state",
|
|
1427
|
-
"isMut": false,
|
|
1428
|
-
"isSigner": false
|
|
1429
|
-
},
|
|
1430
1425
|
{
|
|
1431
1426
|
"name": "user",
|
|
1432
1427
|
"isMut": true,
|
|
@@ -1440,47 +1435,17 @@
|
|
|
1440
1435
|
],
|
|
1441
1436
|
"args": [
|
|
1442
1437
|
{
|
|
1443
|
-
"name": "
|
|
1444
|
-
"type": "u64"
|
|
1445
|
-
},
|
|
1446
|
-
{
|
|
1447
|
-
"name": "marketIndex",
|
|
1438
|
+
"name": "subAccountId",
|
|
1448
1439
|
"type": "u16"
|
|
1449
|
-
}
|
|
1450
|
-
]
|
|
1451
|
-
},
|
|
1452
|
-
{
|
|
1453
|
-
"name": "removePerpLpSharesInExpiringMarket",
|
|
1454
|
-
"accounts": [
|
|
1455
|
-
{
|
|
1456
|
-
"name": "state",
|
|
1457
|
-
"isMut": false,
|
|
1458
|
-
"isSigner": false
|
|
1459
|
-
},
|
|
1460
|
-
{
|
|
1461
|
-
"name": "user",
|
|
1462
|
-
"isMut": true,
|
|
1463
|
-
"isSigner": false
|
|
1464
|
-
},
|
|
1465
|
-
{
|
|
1466
|
-
"name": "signer",
|
|
1467
|
-
"isMut": false,
|
|
1468
|
-
"isSigner": true
|
|
1469
|
-
}
|
|
1470
|
-
],
|
|
1471
|
-
"args": [
|
|
1472
|
-
{
|
|
1473
|
-
"name": "sharesToBurn",
|
|
1474
|
-
"type": "u64"
|
|
1475
1440
|
},
|
|
1476
1441
|
{
|
|
1477
|
-
"name": "
|
|
1478
|
-
"type": "
|
|
1442
|
+
"name": "marginRatio",
|
|
1443
|
+
"type": "u32"
|
|
1479
1444
|
}
|
|
1480
1445
|
]
|
|
1481
1446
|
},
|
|
1482
1447
|
{
|
|
1483
|
-
"name": "
|
|
1448
|
+
"name": "updateUserPerpPositionCustomMarginRatio",
|
|
1484
1449
|
"accounts": [
|
|
1485
1450
|
{
|
|
1486
1451
|
"name": "user",
|
|
@@ -1499,38 +1464,12 @@
|
|
|
1499
1464
|
"type": "u16"
|
|
1500
1465
|
},
|
|
1501
1466
|
{
|
|
1502
|
-
"name": "
|
|
1503
|
-
"type": {
|
|
1504
|
-
"array": [
|
|
1505
|
-
"u8",
|
|
1506
|
-
32
|
|
1507
|
-
]
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
]
|
|
1511
|
-
},
|
|
1512
|
-
{
|
|
1513
|
-
"name": "updateUserCustomMarginRatio",
|
|
1514
|
-
"accounts": [
|
|
1515
|
-
{
|
|
1516
|
-
"name": "user",
|
|
1517
|
-
"isMut": true,
|
|
1518
|
-
"isSigner": false
|
|
1519
|
-
},
|
|
1520
|
-
{
|
|
1521
|
-
"name": "authority",
|
|
1522
|
-
"isMut": false,
|
|
1523
|
-
"isSigner": true
|
|
1524
|
-
}
|
|
1525
|
-
],
|
|
1526
|
-
"args": [
|
|
1527
|
-
{
|
|
1528
|
-
"name": "subAccountId",
|
|
1467
|
+
"name": "perpMarketIndex",
|
|
1529
1468
|
"type": "u16"
|
|
1530
1469
|
},
|
|
1531
1470
|
{
|
|
1532
1471
|
"name": "marginRatio",
|
|
1533
|
-
"type": "
|
|
1472
|
+
"type": "u16"
|
|
1534
1473
|
}
|
|
1535
1474
|
]
|
|
1536
1475
|
},
|
|
@@ -2291,27 +2230,6 @@
|
|
|
2291
2230
|
],
|
|
2292
2231
|
"args": []
|
|
2293
2232
|
},
|
|
2294
|
-
{
|
|
2295
|
-
"name": "settleLp",
|
|
2296
|
-
"accounts": [
|
|
2297
|
-
{
|
|
2298
|
-
"name": "state",
|
|
2299
|
-
"isMut": false,
|
|
2300
|
-
"isSigner": false
|
|
2301
|
-
},
|
|
2302
|
-
{
|
|
2303
|
-
"name": "user",
|
|
2304
|
-
"isMut": true,
|
|
2305
|
-
"isSigner": false
|
|
2306
|
-
}
|
|
2307
|
-
],
|
|
2308
|
-
"args": [
|
|
2309
|
-
{
|
|
2310
|
-
"name": "marketIndex",
|
|
2311
|
-
"type": "u16"
|
|
2312
|
-
}
|
|
2313
|
-
]
|
|
2314
|
-
},
|
|
2315
2233
|
{
|
|
2316
2234
|
"name": "settleExpiredMarket",
|
|
2317
2235
|
"accounts": [
|
|
@@ -6003,58 +5921,6 @@
|
|
|
6003
5921
|
}
|
|
6004
5922
|
]
|
|
6005
5923
|
},
|
|
6006
|
-
{
|
|
6007
|
-
"name": "updatePerpMarketTargetBaseAssetAmountPerLp",
|
|
6008
|
-
"accounts": [
|
|
6009
|
-
{
|
|
6010
|
-
"name": "admin",
|
|
6011
|
-
"isMut": false,
|
|
6012
|
-
"isSigner": true
|
|
6013
|
-
},
|
|
6014
|
-
{
|
|
6015
|
-
"name": "state",
|
|
6016
|
-
"isMut": false,
|
|
6017
|
-
"isSigner": false
|
|
6018
|
-
},
|
|
6019
|
-
{
|
|
6020
|
-
"name": "perpMarket",
|
|
6021
|
-
"isMut": true,
|
|
6022
|
-
"isSigner": false
|
|
6023
|
-
}
|
|
6024
|
-
],
|
|
6025
|
-
"args": [
|
|
6026
|
-
{
|
|
6027
|
-
"name": "targetBaseAssetAmountPerLp",
|
|
6028
|
-
"type": "i32"
|
|
6029
|
-
}
|
|
6030
|
-
]
|
|
6031
|
-
},
|
|
6032
|
-
{
|
|
6033
|
-
"name": "updatePerpMarketPerLpBase",
|
|
6034
|
-
"accounts": [
|
|
6035
|
-
{
|
|
6036
|
-
"name": "admin",
|
|
6037
|
-
"isMut": false,
|
|
6038
|
-
"isSigner": true
|
|
6039
|
-
},
|
|
6040
|
-
{
|
|
6041
|
-
"name": "state",
|
|
6042
|
-
"isMut": false,
|
|
6043
|
-
"isSigner": false
|
|
6044
|
-
},
|
|
6045
|
-
{
|
|
6046
|
-
"name": "perpMarket",
|
|
6047
|
-
"isMut": true,
|
|
6048
|
-
"isSigner": false
|
|
6049
|
-
}
|
|
6050
|
-
],
|
|
6051
|
-
"args": [
|
|
6052
|
-
{
|
|
6053
|
-
"name": "perLpBase",
|
|
6054
|
-
"type": "i8"
|
|
6055
|
-
}
|
|
6056
|
-
]
|
|
6057
|
-
},
|
|
6058
5924
|
{
|
|
6059
5925
|
"name": "updateLpCooldownTime",
|
|
6060
5926
|
"accounts": [
|
|
@@ -11647,13 +11513,17 @@
|
|
|
11647
11513
|
"type": "i64"
|
|
11648
11514
|
},
|
|
11649
11515
|
{
|
|
11650
|
-
"name": "
|
|
11651
|
-
"
|
|
11652
|
-
"
|
|
11653
|
-
|
|
11654
|
-
|
|
11655
|
-
|
|
11656
|
-
|
|
11516
|
+
"name": "padding",
|
|
11517
|
+
"type": {
|
|
11518
|
+
"array": [
|
|
11519
|
+
"u8",
|
|
11520
|
+
2
|
|
11521
|
+
]
|
|
11522
|
+
}
|
|
11523
|
+
},
|
|
11524
|
+
{
|
|
11525
|
+
"name": "maxMarginRatio",
|
|
11526
|
+
"type": "u16"
|
|
11657
11527
|
},
|
|
11658
11528
|
{
|
|
11659
11529
|
"name": "marketIndex",
|
|
@@ -12713,23 +12583,6 @@
|
|
|
12713
12583
|
]
|
|
12714
12584
|
}
|
|
12715
12585
|
},
|
|
12716
|
-
{
|
|
12717
|
-
"name": "AMMLiquiditySplit",
|
|
12718
|
-
"type": {
|
|
12719
|
-
"kind": "enum",
|
|
12720
|
-
"variants": [
|
|
12721
|
-
{
|
|
12722
|
-
"name": "ProtocolOwned"
|
|
12723
|
-
},
|
|
12724
|
-
{
|
|
12725
|
-
"name": "LPOwned"
|
|
12726
|
-
},
|
|
12727
|
-
{
|
|
12728
|
-
"name": "Shared"
|
|
12729
|
-
}
|
|
12730
|
-
]
|
|
12731
|
-
}
|
|
12732
|
-
},
|
|
12733
12586
|
{
|
|
12734
12587
|
"name": "AMMAvailability",
|
|
12735
12588
|
"type": {
|
|
@@ -20,8 +20,7 @@ function isUserBankrupt(user) {
|
|
|
20
20
|
for (const position of userAccount.perpPositions) {
|
|
21
21
|
if (!position.baseAssetAmount.eq(numericConstants_1.ZERO) ||
|
|
22
22
|
position.quoteAssetAmount.gt(numericConstants_1.ZERO) ||
|
|
23
|
-
(0, position_1.hasOpenOrders)(position)
|
|
24
|
-
position.lpShares.gt(numericConstants_1.ZERO)) {
|
|
23
|
+
(0, position_1.hasOpenOrders)(position)) {
|
|
25
24
|
return false;
|
|
26
25
|
}
|
|
27
26
|
if (position.quoteAssetAmount.lt(numericConstants_1.ZERO)) {
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1102,7 +1102,9 @@ export type PerpPosition = {
|
|
|
1102
1102
|
openAsks: BN;
|
|
1103
1103
|
settledPnl: BN;
|
|
1104
1104
|
lpShares: BN;
|
|
1105
|
+
/** TODO: remove this field - it doesn't exist on chain */
|
|
1105
1106
|
remainderBaseAssetAmount: number;
|
|
1107
|
+
maxMarginRatio: number;
|
|
1106
1108
|
lastBaseAssetAmountPerLp: BN;
|
|
1107
1109
|
lastQuoteAssetAmountPerLp: BN;
|
|
1108
1110
|
perLpBase: number;
|
package/lib/browser/user.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export declare class User {
|
|
|
41
41
|
* @returns userPerpPosition
|
|
42
42
|
*/
|
|
43
43
|
getPerpPosition(marketIndex: number): PerpPosition | undefined;
|
|
44
|
+
getPerpPositionOrEmpty(marketIndex: number): PerpPosition;
|
|
44
45
|
getPerpPositionAndSlot(marketIndex: number): DataAndSlot<PerpPosition | undefined>;
|
|
45
46
|
getSpotPositionForUserAccount(userAccount: UserAccount, marketIndex: number): SpotPosition | undefined;
|
|
46
47
|
/**
|
|
@@ -85,26 +86,12 @@ export declare class User {
|
|
|
85
86
|
* @returns : open asks
|
|
86
87
|
*/
|
|
87
88
|
getPerpBidAsks(marketIndex: number): [BN, BN];
|
|
88
|
-
/**
|
|
89
|
-
* calculates the open bids and asks for an lp
|
|
90
|
-
* optionally pass in lpShares to see what bid/asks a user *would* take on
|
|
91
|
-
* @returns : lp open bids
|
|
92
|
-
* @returns : lp open asks
|
|
93
|
-
*/
|
|
94
|
-
getLPBidAsks(marketIndex: number, lpShares?: BN): [BN, BN];
|
|
95
|
-
/**
|
|
96
|
-
* calculates the market position if the lp position was settled
|
|
97
|
-
* @returns : the settled userPosition
|
|
98
|
-
* @returns : the dust base asset amount (ie, < stepsize)
|
|
99
|
-
* @returns : pnl from settle
|
|
100
|
-
*/
|
|
101
|
-
getPerpPositionWithLPSettle(marketIndex: number, originalPosition?: PerpPosition, burnLpShares?: boolean, includeRemainderInBaseAmount?: boolean): [PerpPosition, BN, BN];
|
|
102
89
|
/**
|
|
103
90
|
* calculates Buying Power = free collateral / initial margin ratio
|
|
104
91
|
* @returns : Precision QUOTE_PRECISION
|
|
105
92
|
*/
|
|
106
93
|
getPerpBuyingPower(marketIndex: number, collateralBuffer?: BN, enterHighLeverageMode?: any): BN;
|
|
107
|
-
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex: number, freeCollateral: BN, baseAssetAmount: BN, enterHighLeverageMode?: any): BN;
|
|
94
|
+
getPerpBuyingPowerFromFreeCollateralAndBaseAssetAmount(marketIndex: number, freeCollateral: BN, baseAssetAmount: BN, enterHighLeverageMode?: any, perpPosition?: PerpPosition): BN;
|
|
108
95
|
/**
|
|
109
96
|
* calculates Free Collateral = Total collateral - margin requirement
|
|
110
97
|
* @returns : Precision QUOTE_PRECISION
|