@drift-labs/sdk 0.2.0-master.31 → 0.2.0-master.33
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.js +2 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +8 -8
- package/lib/accounts/types.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +7 -7
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +4 -4
- package/lib/addresses/pda.js +23 -22
- package/lib/admin.d.ts +30 -32
- package/lib/admin.js +111 -119
- package/lib/clearingHouse.d.ts +43 -34
- package/lib/clearingHouse.js +353 -193
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +26 -5
- package/lib/clearingHouseUser.js +151 -51
- package/lib/config.d.ts +2 -0
- package/lib/config.js +5 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/dlob/DLOB.d.ts +19 -11
- package/lib/dlob/DLOB.js +208 -107
- package/lib/dlob/DLOBNode.js +2 -10
- package/lib/dlob/NodeList.d.ts +1 -0
- package/lib/dlob/NodeList.js +6 -1
- package/lib/events/eventSubscriber.d.ts +1 -0
- package/lib/events/eventSubscriber.js +11 -4
- package/lib/events/fetchLogs.d.ts +3 -1
- package/lib/events/fetchLogs.js +13 -5
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +1 -1
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/factory/bigNum.d.ts +5 -4
- package/lib/factory/bigNum.js +36 -6
- package/lib/idl/clearing_house.json +1527 -1242
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/math/amm.js +9 -9
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.js +10 -10
- package/lib/math/margin.js +6 -1
- package/lib/math/market.js +9 -9
- package/lib/math/orders.d.ts +7 -3
- package/lib/math/orders.js +39 -31
- package/lib/math/repeg.js +3 -3
- package/lib/math/spotBalance.js +3 -3
- package/lib/math/spotPosition.js +2 -2
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +4 -0
- package/lib/serum/serumSubscriber.js +16 -1
- package/lib/types.d.ts +70 -85
- package/lib/types.js +12 -11
- package/lib/userMap/userMap.d.ts +17 -1
- package/lib/userMap/userMap.js +12 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +9 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +8 -8
- package/src/addresses/marketAddresses.ts +2 -2
- package/src/addresses/pda.ts +20 -20
- package/src/admin.ts +246 -221
- package/src/clearingHouse.ts +556 -236
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +237 -87
- package/src/config.ts +8 -1
- package/src/constants/numericConstants.ts +5 -1
- package/src/dlob/DLOB.ts +290 -120
- package/src/dlob/DLOBNode.ts +2 -14
- package/src/dlob/NodeList.ts +7 -1
- package/src/events/eventSubscriber.ts +18 -4
- package/src/events/fetchLogs.ts +20 -5
- package/src/events/pollingLogProvider.ts +1 -1
- package/src/events/types.ts +2 -1
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/factory/bigNum.ts +59 -6
- package/src/idl/clearing_house.json +1527 -1242
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +3 -0
- package/src/math/amm.ts +9 -9
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +20 -10
- package/src/math/margin.ts +7 -1
- package/src/math/market.ts +9 -9
- package/src/math/orders.ts +44 -29
- package/src/math/repeg.ts +3 -3
- package/src/math/spotBalance.ts +4 -4
- package/src/math/spotPosition.ts +2 -2
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +20 -1
- package/src/types.ts +75 -61
- package/src/userMap/userMap.ts +25 -1
- package/src/userName.ts +2 -1
- package/tests/bn/test.ts +22 -1
- package/tests/dlob/helpers.ts +252 -81
- package/tests/dlob/test.ts +1115 -215
package/src/addresses/pda.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { BN } from '@project-serum/anchor';
|
|
|
5
5
|
export async function getClearingHouseStateAccountPublicKeyAndNonce(
|
|
6
6
|
programId: PublicKey
|
|
7
7
|
): Promise<[PublicKey, number]> {
|
|
8
|
-
return
|
|
8
|
+
return PublicKey.findProgramAddress(
|
|
9
9
|
[Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))],
|
|
10
10
|
programId
|
|
11
11
|
);
|
|
@@ -20,13 +20,13 @@ export async function getClearingHouseStateAccountPublicKey(
|
|
|
20
20
|
export async function getUserAccountPublicKeyAndNonce(
|
|
21
21
|
programId: PublicKey,
|
|
22
22
|
authority: PublicKey,
|
|
23
|
-
|
|
23
|
+
subAccountId = 0
|
|
24
24
|
): Promise<[PublicKey, number]> {
|
|
25
|
-
return
|
|
25
|
+
return PublicKey.findProgramAddress(
|
|
26
26
|
[
|
|
27
27
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
28
28
|
authority.toBuffer(),
|
|
29
|
-
Uint8Array.from([
|
|
29
|
+
Uint8Array.from([subAccountId]),
|
|
30
30
|
],
|
|
31
31
|
programId
|
|
32
32
|
);
|
|
@@ -35,23 +35,23 @@ export async function getUserAccountPublicKeyAndNonce(
|
|
|
35
35
|
export async function getUserAccountPublicKey(
|
|
36
36
|
programId: PublicKey,
|
|
37
37
|
authority: PublicKey,
|
|
38
|
-
|
|
38
|
+
subAccountId = 0
|
|
39
39
|
): Promise<PublicKey> {
|
|
40
40
|
return (
|
|
41
|
-
await getUserAccountPublicKeyAndNonce(programId, authority,
|
|
41
|
+
await getUserAccountPublicKeyAndNonce(programId, authority, subAccountId)
|
|
42
42
|
)[0];
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export function getUserAccountPublicKeySync(
|
|
46
46
|
programId: PublicKey,
|
|
47
47
|
authority: PublicKey,
|
|
48
|
-
|
|
48
|
+
subAccountId = 0
|
|
49
49
|
): PublicKey {
|
|
50
|
-
return
|
|
50
|
+
return PublicKey.findProgramAddressSync(
|
|
51
51
|
[
|
|
52
52
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
53
53
|
authority.toBuffer(),
|
|
54
|
-
Uint8Array.from([
|
|
54
|
+
Uint8Array.from([subAccountId]),
|
|
55
55
|
],
|
|
56
56
|
programId
|
|
57
57
|
)[0];
|
|
@@ -61,7 +61,7 @@ export function getUserStatsAccountPublicKey(
|
|
|
61
61
|
programId: PublicKey,
|
|
62
62
|
authority: PublicKey
|
|
63
63
|
): PublicKey {
|
|
64
|
-
return
|
|
64
|
+
return PublicKey.findProgramAddressSync(
|
|
65
65
|
[
|
|
66
66
|
Buffer.from(anchor.utils.bytes.utf8.encode('user_stats')),
|
|
67
67
|
authority.toBuffer(),
|
|
@@ -70,14 +70,14 @@ export function getUserStatsAccountPublicKey(
|
|
|
70
70
|
)[0];
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export async function
|
|
73
|
+
export async function getPerpMarketPublicKey(
|
|
74
74
|
programId: PublicKey,
|
|
75
75
|
marketIndex: number
|
|
76
76
|
): Promise<PublicKey> {
|
|
77
77
|
return (
|
|
78
|
-
await
|
|
78
|
+
await PublicKey.findProgramAddress(
|
|
79
79
|
[
|
|
80
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
80
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
|
|
81
81
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
82
82
|
],
|
|
83
83
|
programId
|
|
@@ -90,7 +90,7 @@ export async function getSpotMarketPublicKey(
|
|
|
90
90
|
marketIndex: number
|
|
91
91
|
): Promise<PublicKey> {
|
|
92
92
|
return (
|
|
93
|
-
await
|
|
93
|
+
await PublicKey.findProgramAddress(
|
|
94
94
|
[
|
|
95
95
|
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
96
96
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
@@ -105,7 +105,7 @@ export async function getSpotMarketVaultPublicKey(
|
|
|
105
105
|
marketIndex: number
|
|
106
106
|
): Promise<PublicKey> {
|
|
107
107
|
return (
|
|
108
|
-
await
|
|
108
|
+
await PublicKey.findProgramAddress(
|
|
109
109
|
[
|
|
110
110
|
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
111
111
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
@@ -120,7 +120,7 @@ export async function getInsuranceFundVaultPublicKey(
|
|
|
120
120
|
marketIndex: number
|
|
121
121
|
): Promise<PublicKey> {
|
|
122
122
|
return (
|
|
123
|
-
await
|
|
123
|
+
await PublicKey.findProgramAddress(
|
|
124
124
|
[
|
|
125
125
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
126
126
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
@@ -135,7 +135,7 @@ export function getInsuranceFundStakeAccountPublicKey(
|
|
|
135
135
|
authority: PublicKey,
|
|
136
136
|
marketIndex: number
|
|
137
137
|
): PublicKey {
|
|
138
|
-
return
|
|
138
|
+
return PublicKey.findProgramAddressSync(
|
|
139
139
|
[
|
|
140
140
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
141
141
|
authority.toBuffer(),
|
|
@@ -148,7 +148,7 @@ export function getInsuranceFundStakeAccountPublicKey(
|
|
|
148
148
|
export function getClearingHouseSignerPublicKey(
|
|
149
149
|
programId: PublicKey
|
|
150
150
|
): PublicKey {
|
|
151
|
-
return
|
|
151
|
+
return PublicKey.findProgramAddressSync(
|
|
152
152
|
[Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house_signer'))],
|
|
153
153
|
programId
|
|
154
154
|
)[0];
|
|
@@ -158,7 +158,7 @@ export function getSerumOpenOrdersPublicKey(
|
|
|
158
158
|
programId: PublicKey,
|
|
159
159
|
market: PublicKey
|
|
160
160
|
): PublicKey {
|
|
161
|
-
return
|
|
161
|
+
return PublicKey.findProgramAddressSync(
|
|
162
162
|
[
|
|
163
163
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
164
164
|
market.toBuffer(),
|
|
@@ -182,7 +182,7 @@ export function getSerumFulfillmentConfigPublicKey(
|
|
|
182
182
|
programId: PublicKey,
|
|
183
183
|
market: PublicKey
|
|
184
184
|
): PublicKey {
|
|
185
|
-
return
|
|
185
|
+
return PublicKey.findProgramAddressSync(
|
|
186
186
|
[
|
|
187
187
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
188
188
|
market.toBuffer(),
|