@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.
Files changed (99) hide show
  1. package/lib/accounts/bulkAccountLoader.js +2 -1
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +2 -2
  3. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +8 -8
  4. package/lib/accounts/types.d.ts +1 -0
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +2 -2
  6. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +7 -7
  7. package/lib/addresses/marketAddresses.js +1 -1
  8. package/lib/addresses/pda.d.ts +4 -4
  9. package/lib/addresses/pda.js +23 -22
  10. package/lib/admin.d.ts +30 -32
  11. package/lib/admin.js +111 -119
  12. package/lib/clearingHouse.d.ts +43 -34
  13. package/lib/clearingHouse.js +353 -193
  14. package/lib/clearingHouseConfig.d.ts +2 -2
  15. package/lib/clearingHouseUser.d.ts +26 -5
  16. package/lib/clearingHouseUser.js +151 -51
  17. package/lib/config.d.ts +2 -0
  18. package/lib/config.js +5 -1
  19. package/lib/constants/numericConstants.d.ts +1 -0
  20. package/lib/constants/numericConstants.js +3 -2
  21. package/lib/dlob/DLOB.d.ts +19 -11
  22. package/lib/dlob/DLOB.js +208 -107
  23. package/lib/dlob/DLOBNode.js +2 -10
  24. package/lib/dlob/NodeList.d.ts +1 -0
  25. package/lib/dlob/NodeList.js +6 -1
  26. package/lib/events/eventSubscriber.d.ts +1 -0
  27. package/lib/events/eventSubscriber.js +11 -4
  28. package/lib/events/fetchLogs.d.ts +3 -1
  29. package/lib/events/fetchLogs.js +13 -5
  30. package/lib/events/pollingLogProvider.js +1 -1
  31. package/lib/events/types.d.ts +1 -1
  32. package/lib/events/webSocketLogProvider.js +1 -1
  33. package/lib/factory/bigNum.d.ts +5 -4
  34. package/lib/factory/bigNum.js +36 -6
  35. package/lib/idl/clearing_house.json +1527 -1242
  36. package/lib/index.d.ts +3 -0
  37. package/lib/index.js +3 -0
  38. package/lib/math/amm.js +9 -9
  39. package/lib/math/exchangeStatus.d.ts +4 -0
  40. package/lib/math/exchangeStatus.js +18 -0
  41. package/lib/math/funding.js +10 -10
  42. package/lib/math/margin.js +6 -1
  43. package/lib/math/market.js +9 -9
  44. package/lib/math/orders.d.ts +7 -3
  45. package/lib/math/orders.js +39 -31
  46. package/lib/math/repeg.js +3 -3
  47. package/lib/math/spotBalance.js +3 -3
  48. package/lib/math/spotPosition.js +2 -2
  49. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  50. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  51. package/lib/serum/serumSubscriber.d.ts +4 -0
  52. package/lib/serum/serumSubscriber.js +16 -1
  53. package/lib/types.d.ts +70 -85
  54. package/lib/types.js +12 -11
  55. package/lib/userMap/userMap.d.ts +17 -1
  56. package/lib/userMap/userMap.js +12 -0
  57. package/lib/userName.d.ts +1 -0
  58. package/lib/userName.js +3 -2
  59. package/package.json +1 -1
  60. package/src/accounts/bulkAccountLoader.ts +5 -1
  61. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +9 -9
  62. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +8 -8
  63. package/src/addresses/marketAddresses.ts +2 -2
  64. package/src/addresses/pda.ts +20 -20
  65. package/src/admin.ts +246 -221
  66. package/src/clearingHouse.ts +556 -236
  67. package/src/clearingHouseConfig.ts +2 -2
  68. package/src/clearingHouseUser.ts +237 -87
  69. package/src/config.ts +8 -1
  70. package/src/constants/numericConstants.ts +5 -1
  71. package/src/dlob/DLOB.ts +290 -120
  72. package/src/dlob/DLOBNode.ts +2 -14
  73. package/src/dlob/NodeList.ts +7 -1
  74. package/src/events/eventSubscriber.ts +18 -4
  75. package/src/events/fetchLogs.ts +20 -5
  76. package/src/events/pollingLogProvider.ts +1 -1
  77. package/src/events/types.ts +2 -1
  78. package/src/events/webSocketLogProvider.ts +1 -1
  79. package/src/factory/bigNum.ts +59 -6
  80. package/src/idl/clearing_house.json +1527 -1242
  81. package/src/idl/pyth.json +98 -2
  82. package/src/index.ts +3 -0
  83. package/src/math/amm.ts +9 -9
  84. package/src/math/exchangeStatus.ts +31 -0
  85. package/src/math/funding.ts +20 -10
  86. package/src/math/margin.ts +7 -1
  87. package/src/math/market.ts +9 -9
  88. package/src/math/orders.ts +44 -29
  89. package/src/math/repeg.ts +3 -3
  90. package/src/math/spotBalance.ts +4 -4
  91. package/src/math/spotPosition.ts +2 -2
  92. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  93. package/src/serum/serumSubscriber.ts +20 -1
  94. package/src/types.ts +75 -61
  95. package/src/userMap/userMap.ts +25 -1
  96. package/src/userName.ts +2 -1
  97. package/tests/bn/test.ts +22 -1
  98. package/tests/dlob/helpers.ts +252 -81
  99. package/tests/dlob/test.ts +1115 -215
@@ -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 anchor.web3.PublicKey.findProgramAddress(
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
- userId = 0
23
+ subAccountId = 0
24
24
  ): Promise<[PublicKey, number]> {
25
- return anchor.web3.PublicKey.findProgramAddress(
25
+ return PublicKey.findProgramAddress(
26
26
  [
27
27
  Buffer.from(anchor.utils.bytes.utf8.encode('user')),
28
28
  authority.toBuffer(),
29
- Uint8Array.from([userId]),
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
- userId = 0
38
+ subAccountId = 0
39
39
  ): Promise<PublicKey> {
40
40
  return (
41
- await getUserAccountPublicKeyAndNonce(programId, authority, userId)
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
- userId = 0
48
+ subAccountId = 0
49
49
  ): PublicKey {
50
- return anchor.web3.PublicKey.findProgramAddressSync(
50
+ return PublicKey.findProgramAddressSync(
51
51
  [
52
52
  Buffer.from(anchor.utils.bytes.utf8.encode('user')),
53
53
  authority.toBuffer(),
54
- Uint8Array.from([userId]),
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 anchor.web3.PublicKey.findProgramAddressSync(
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 getMarketPublicKey(
73
+ export async function getPerpMarketPublicKey(
74
74
  programId: PublicKey,
75
75
  marketIndex: number
76
76
  ): Promise<PublicKey> {
77
77
  return (
78
- await anchor.web3.PublicKey.findProgramAddress(
78
+ await PublicKey.findProgramAddress(
79
79
  [
80
- Buffer.from(anchor.utils.bytes.utf8.encode('market')),
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 anchor.web3.PublicKey.findProgramAddress(
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 anchor.web3.PublicKey.findProgramAddress(
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 anchor.web3.PublicKey.findProgramAddress(
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 anchor.web3.PublicKey.findProgramAddressSync(
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 anchor.web3.PublicKey.findProgramAddressSync(
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 anchor.web3.PublicKey.findProgramAddressSync(
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 anchor.web3.PublicKey.findProgramAddressSync(
185
+ return PublicKey.findProgramAddressSync(
186
186
  [
187
187
  Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
188
188
  market.toBuffer(),