@drift-labs/sdk 0.2.0-master.4 → 0.2.0-master.41

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 (247) hide show
  1. package/README.md +27 -27
  2. package/lib/accounts/bulkAccountLoader.d.ts +2 -0
  3. package/lib/accounts/bulkAccountLoader.js +36 -29
  4. package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
  5. package/lib/accounts/bulkUserStatsSubscription.js +21 -0
  6. package/lib/accounts/bulkUserSubscription.d.ts +2 -2
  7. package/lib/accounts/bulkUserSubscription.js +0 -1
  8. package/lib/accounts/fetch.d.ts +2 -1
  9. package/lib/accounts/fetch.js +9 -1
  10. package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
  11. package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
  12. package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
  13. package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
  14. package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
  15. package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
  16. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  17. package/lib/accounts/pollingUserStatsAccountSubscriber.js +107 -0
  18. package/lib/accounts/types.d.ts +26 -15
  19. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
  20. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
  21. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
  22. package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
  23. package/lib/addresses/marketAddresses.d.ts +1 -3
  24. package/lib/addresses/marketAddresses.js +1 -1
  25. package/lib/addresses/pda.d.ts +15 -9
  26. package/lib/addresses/pda.js +73 -35
  27. package/lib/adminClient.d.ts +65 -0
  28. package/lib/adminClient.js +637 -0
  29. package/lib/config.d.ts +9 -9
  30. package/lib/config.js +25 -21
  31. package/lib/constants/numericConstants.d.ts +30 -12
  32. package/lib/constants/numericConstants.js +41 -21
  33. package/lib/constants/perpMarkets.d.ts +18 -0
  34. package/lib/constants/{markets.js → perpMarkets.js} +7 -7
  35. package/lib/constants/spotMarkets.d.ts +19 -0
  36. package/lib/constants/spotMarkets.js +53 -0
  37. package/lib/dlob/DLOB.d.ts +82 -0
  38. package/lib/dlob/DLOB.js +694 -0
  39. package/lib/dlob/DLOBNode.d.ts +54 -0
  40. package/lib/dlob/DLOBNode.js +77 -0
  41. package/lib/dlob/NodeList.d.ts +27 -0
  42. package/lib/dlob/NodeList.js +144 -0
  43. package/lib/driftClient.d.ts +234 -0
  44. package/lib/driftClient.js +2108 -0
  45. package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
  46. package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
  47. package/lib/events/eventList.js +3 -0
  48. package/lib/events/eventSubscriber.d.ts +5 -2
  49. package/lib/events/eventSubscriber.js +25 -11
  50. package/lib/events/fetchLogs.d.ts +13 -2
  51. package/lib/events/fetchLogs.js +40 -12
  52. package/lib/events/pollingLogProvider.d.ts +2 -1
  53. package/lib/events/pollingLogProvider.js +7 -3
  54. package/lib/events/sort.js +8 -11
  55. package/lib/events/types.d.ts +11 -3
  56. package/lib/events/types.js +8 -0
  57. package/lib/events/webSocketLogProvider.js +1 -1
  58. package/lib/examples/makeTradeExample.js +30 -18
  59. package/lib/factory/bigNum.d.ts +8 -4
  60. package/lib/factory/bigNum.js +109 -19
  61. package/lib/idl/drift.json +8386 -0
  62. package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  63. package/lib/index.d.ts +30 -13
  64. package/lib/index.js +30 -13
  65. package/lib/math/amm.d.ts +9 -6
  66. package/lib/math/amm.js +91 -38
  67. package/lib/math/conversion.js +1 -1
  68. package/lib/math/exchangeStatus.d.ts +4 -0
  69. package/lib/math/exchangeStatus.js +18 -0
  70. package/lib/math/funding.d.ts +6 -6
  71. package/lib/math/funding.js +23 -21
  72. package/lib/math/insurance.d.ts +4 -0
  73. package/lib/math/insurance.js +27 -0
  74. package/lib/math/margin.d.ts +11 -0
  75. package/lib/math/margin.js +82 -0
  76. package/lib/math/market.d.ts +14 -9
  77. package/lib/math/market.js +70 -10
  78. package/lib/math/oracles.d.ts +4 -0
  79. package/lib/math/oracles.js +36 -8
  80. package/lib/math/orders.d.ts +16 -6
  81. package/lib/math/orders.js +97 -17
  82. package/lib/math/position.d.ts +27 -13
  83. package/lib/math/position.js +92 -36
  84. package/lib/math/repeg.js +17 -8
  85. package/lib/math/spotBalance.d.ts +22 -0
  86. package/lib/math/spotBalance.js +192 -0
  87. package/lib/math/spotMarket.d.ts +4 -0
  88. package/lib/math/spotMarket.js +8 -0
  89. package/lib/math/spotPosition.d.ts +6 -0
  90. package/lib/math/spotPosition.js +23 -0
  91. package/lib/math/trade.d.ts +10 -10
  92. package/lib/math/trade.js +27 -31
  93. package/lib/oracles/pythClient.js +1 -1
  94. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  95. package/lib/oracles/switchboardClient.js +1 -1
  96. package/lib/orderParams.d.ts +4 -4
  97. package/lib/orderParams.js +12 -4
  98. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  99. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  100. package/lib/serum/serumSubscriber.d.ts +27 -0
  101. package/lib/serum/serumSubscriber.js +56 -0
  102. package/lib/serum/types.d.ts +11 -0
  103. package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
  104. package/lib/slot/SlotSubscriber.d.ts +7 -0
  105. package/lib/slot/SlotSubscriber.js +3 -0
  106. package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
  107. package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
  108. package/lib/tx/retryTxSender.d.ts +1 -1
  109. package/lib/tx/retryTxSender.js +13 -4
  110. package/lib/tx/types.d.ts +1 -1
  111. package/lib/tx/utils.js +1 -1
  112. package/lib/types.d.ts +688 -216
  113. package/lib/types.js +153 -24
  114. package/lib/user.d.ts +228 -0
  115. package/lib/user.js +959 -0
  116. package/lib/userConfig.d.ts +14 -0
  117. package/lib/userConfig.js +2 -0
  118. package/lib/userMap/userMap.d.ts +41 -0
  119. package/lib/userMap/userMap.js +85 -0
  120. package/lib/userMap/userStatsMap.d.ts +19 -0
  121. package/lib/userMap/userStatsMap.js +68 -0
  122. package/lib/userName.d.ts +1 -0
  123. package/lib/userName.js +3 -2
  124. package/lib/userStats.d.ts +18 -0
  125. package/lib/userStats.js +49 -0
  126. package/lib/userStatsConfig.d.ts +14 -0
  127. package/lib/userStatsConfig.js +2 -0
  128. package/lib/util/computeUnits.js +1 -1
  129. package/lib/util/getTokenAddress.d.ts +2 -0
  130. package/lib/util/getTokenAddress.js +9 -0
  131. package/package.json +11 -4
  132. package/src/accounts/bulkAccountLoader.ts +44 -34
  133. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  134. package/src/accounts/bulkUserSubscription.ts +2 -3
  135. package/src/accounts/fetch.ts +27 -2
  136. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  137. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  138. package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
  139. package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
  140. package/src/accounts/types.ts +35 -15
  141. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  142. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  143. package/src/addresses/marketAddresses.ts +3 -4
  144. package/src/addresses/pda.ts +105 -33
  145. package/src/adminClient.ts +1207 -0
  146. package/src/assert/assert.js +9 -0
  147. package/src/config.ts +37 -31
  148. package/src/constants/numericConstants.ts +58 -24
  149. package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
  150. package/src/constants/spotMarkets.ts +73 -0
  151. package/src/dlob/DLOB.ts +1120 -0
  152. package/src/dlob/DLOBNode.ts +155 -0
  153. package/src/dlob/NodeList.ts +195 -0
  154. package/src/driftClient.ts +3594 -0
  155. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  156. package/src/events/eventList.js +77 -0
  157. package/src/events/eventList.ts +3 -0
  158. package/src/events/eventSubscriber.ts +36 -14
  159. package/src/events/fetchLogs.ts +55 -13
  160. package/src/events/pollingLogProvider.ts +11 -3
  161. package/src/events/sort.ts +11 -15
  162. package/src/events/types.ts +27 -2
  163. package/src/events/webSocketLogProvider.ts +1 -1
  164. package/src/examples/makeTradeExample.js +157 -0
  165. package/src/examples/makeTradeExample.ts +44 -28
  166. package/src/factory/bigNum.ts +150 -22
  167. package/src/idl/drift.json +8386 -0
  168. package/src/idl/pyth.json +98 -2
  169. package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  170. package/src/index.ts +30 -13
  171. package/src/math/amm.ts +161 -48
  172. package/src/math/conversion.ts +2 -2
  173. package/src/math/exchangeStatus.ts +31 -0
  174. package/src/math/funding.ts +41 -31
  175. package/src/math/insurance.ts +35 -0
  176. package/src/math/margin.ts +133 -0
  177. package/src/math/market.ts +143 -14
  178. package/src/math/oracles.ts +63 -9
  179. package/src/math/orders.ts +168 -26
  180. package/src/math/position.ts +136 -58
  181. package/src/math/repeg.ts +19 -9
  182. package/src/math/spotBalance.ts +319 -0
  183. package/src/math/spotMarket.ts +9 -0
  184. package/src/math/spotPosition.ts +47 -0
  185. package/src/math/trade.ts +33 -37
  186. package/src/oracles/pythClient.ts +2 -2
  187. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  188. package/src/oracles/switchboardClient.ts +2 -2
  189. package/src/orderParams.ts +16 -8
  190. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  191. package/src/serum/serumSubscriber.ts +99 -0
  192. package/src/serum/types.ts +13 -0
  193. package/src/slot/SlotSubscriber.ts +11 -1
  194. package/src/token/index.js +38 -0
  195. package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
  196. package/src/tx/retryTxSender.ts +16 -5
  197. package/src/tx/types.js +2 -0
  198. package/src/tx/types.ts +2 -1
  199. package/src/tx/utils.js +17 -0
  200. package/src/tx/utils.ts +1 -1
  201. package/src/types.ts +650 -189
  202. package/src/user.ts +1599 -0
  203. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  204. package/src/userMap/userMap.ts +124 -0
  205. package/src/userMap/userStatsMap.ts +108 -0
  206. package/src/userName.ts +2 -1
  207. package/src/userStats.ts +75 -0
  208. package/src/userStatsConfig.ts +18 -0
  209. package/src/util/computeUnits.js +21 -11
  210. package/src/util/computeUnits.ts +1 -1
  211. package/src/util/getTokenAddress.js +9 -0
  212. package/src/util/getTokenAddress.ts +18 -0
  213. package/src/util/promiseTimeout.js +14 -0
  214. package/src/util/tps.js +27 -0
  215. package/tests/bn/test.ts +46 -11
  216. package/tests/dlob/helpers.ts +620 -0
  217. package/tests/dlob/test.ts +4586 -0
  218. package/yarn-error.log +3160 -0
  219. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  220. package/lib/admin.d.ts +0 -44
  221. package/lib/admin.js +0 -433
  222. package/lib/clearingHouse.d.ts +0 -133
  223. package/lib/clearingHouse.js +0 -931
  224. package/lib/clearingHouseUser.d.ts +0 -187
  225. package/lib/clearingHouseUser.js +0 -643
  226. package/lib/clearingHouseUserConfig.d.ts +0 -14
  227. package/lib/constants/banks.d.ts +0 -16
  228. package/lib/constants/banks.js +0 -34
  229. package/lib/constants/markets.d.ts +0 -19
  230. package/lib/idl/clearing_house.json +0 -3998
  231. package/lib/math/bankBalance.d.ts +0 -9
  232. package/lib/math/bankBalance.js +0 -75
  233. package/lib/math/state.d.ts +0 -8
  234. package/lib/math/state.js +0 -15
  235. package/lib/orders.d.ts +0 -8
  236. package/lib/orders.js +0 -134
  237. package/src/admin.ts +0 -722
  238. package/src/clearingHouse.ts +0 -1451
  239. package/src/clearingHouseUser.ts +0 -989
  240. package/src/constants/banks.ts +0 -43
  241. package/src/idl/clearing_house.json +0 -3998
  242. package/src/math/bankBalance.ts +0 -112
  243. package/src/math/state.ts +0 -14
  244. package/src/math/utils.js +0 -27
  245. package/src/math/utils.js.map +0 -1
  246. package/src/orders.ts +0 -244
  247. package/src/util/computeUnits.js.map +0 -1
package/src/types.ts CHANGED
@@ -2,12 +2,62 @@ import { PublicKey, Transaction } from '@solana/web3.js';
2
2
  import { BN, ZERO } from '.';
3
3
 
4
4
  // # Utility Types / Enums / Constants
5
+
6
+ export class ExchangeStatus {
7
+ static readonly ACTIVE = { active: {} };
8
+ static readonly FUNDING_PAUSED = { fundingPaused: {} };
9
+ static readonly AMM_PAUSED = { ammPaused: {} };
10
+ static readonly FILL_PAUSED = { fillPaused: {} };
11
+ static readonly LIQ_PAUSED = { liqPaused: {} };
12
+ static readonly WITHDRAW_PAUSED = { withdrawPaused: {} };
13
+ static readonly PAUSED = { paused: {} };
14
+ }
15
+
16
+ export class MarketStatus {
17
+ static readonly INITIALIZED = { initialized: {} };
18
+ static readonly ACTIVE = { active: {} };
19
+ static readonly FUNDING_PAUSED = { fundingPaused: {} };
20
+ static readonly AMM_PAUSED = { ammPaused: {} };
21
+ static readonly FILL_PAUSED = { fillPaused: {} };
22
+ static readonly WITHDRAW_PAUSED = { withdrawPaused: {} };
23
+ static readonly REDUCE_ONLY = { reduceOnly: {} };
24
+ static readonly SETTLEMENT = { settlement: {} };
25
+ static readonly DELISTED = { delisted: {} };
26
+ }
27
+
28
+ export class UserStatus {
29
+ static readonly ACTIVE = { active: {} };
30
+ static readonly BEING_LIQUIDATED = { beingLiquidated: {} };
31
+ static readonly BANKRUPT = { bankrupt: {} };
32
+ }
33
+
34
+ export class ContractType {
35
+ static readonly PERPETUAL = { perpetual: {} };
36
+ static readonly FUTURE = { future: {} };
37
+ }
38
+
39
+ export class ContractTier {
40
+ static readonly A = { a: {} };
41
+ static readonly B = { b: {} };
42
+ static readonly C = { c: {} };
43
+ static readonly SPECULATIVE = { speculative: {} };
44
+ static readonly ISOLATED = { isolated: {} };
45
+ }
46
+
47
+ export class AssetTier {
48
+ static readonly COLLATERAL = { collateral: {} };
49
+ static readonly PROTECTED = { protected: {} };
50
+ static readonly CROSS = { cross: {} };
51
+ static readonly ISOLATED = { isolated: {} };
52
+ static readonly UNLISTED = { unlisted: {} };
53
+ }
54
+
5
55
  export class SwapDirection {
6
56
  static readonly ADD = { add: {} };
7
57
  static readonly REMOVE = { remove: {} };
8
58
  }
9
59
 
10
- export class BankBalanceType {
60
+ export class SpotBalanceType {
11
61
  static readonly DEPOSIT = { deposit: {} };
12
62
  static readonly BORROW = { borrow: {} };
13
63
  }
@@ -17,6 +67,11 @@ export class PositionDirection {
17
67
  static readonly SHORT = { short: {} };
18
68
  }
19
69
 
70
+ export class DepositDirection {
71
+ static readonly DEPOSIT = { deposit: {} };
72
+ static readonly WITHDRAW = { withdraw: {} };
73
+ }
74
+
20
75
  export class OracleSource {
21
76
  static readonly PYTH = { pyth: {} };
22
77
  static readonly SWITCHBOARD = { switchboard: {} };
@@ -30,19 +85,17 @@ export class OrderType {
30
85
  static readonly MARKET = { market: {} };
31
86
  }
32
87
 
88
+ export declare type MarketTypeStr = 'perp' | 'spot';
89
+ export class MarketType {
90
+ static readonly SPOT = { spot: {} };
91
+ static readonly PERP = { perp: {} };
92
+ }
93
+
33
94
  export class OrderStatus {
34
95
  static readonly INIT = { init: {} };
35
96
  static readonly OPEN = { open: {} };
36
97
  }
37
98
 
38
- export class OrderDiscountTier {
39
- static readonly NONE = { none: {} };
40
- static readonly FIRST = { first: {} };
41
- static readonly SECOND = { second: {} };
42
- static readonly THIRD = { third: {} };
43
- static readonly FOURTH = { fourth: {} };
44
- }
45
-
46
99
  export class OrderAction {
47
100
  static readonly PLACE = { place: {} };
48
101
  static readonly CANCEL = { cancel: {} };
@@ -53,8 +106,8 @@ export class OrderAction {
53
106
 
54
107
  export class OrderActionExplanation {
55
108
  static readonly NONE = { none: {} };
56
- static readonly BREACHED_MARGIN_REQUIREMENT = {
57
- breachedMarginRequirement: {},
109
+ static readonly INSUFFICIENT_FREE_COLLATERAL = {
110
+ insufficientFreeCollateral: {},
58
111
  };
59
112
  static readonly ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
60
113
  oraclePriceBreachedLimitPrice: {},
@@ -62,11 +115,63 @@ export class OrderActionExplanation {
62
115
  static readonly MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
63
116
  marketOrderFilledToLimitPrice: {},
64
117
  };
118
+ static readonly ORDER_EXPIRED = {
119
+ orderExpired: {},
120
+ };
121
+ static readonly LIQUIDATION = {
122
+ liquidation: {},
123
+ };
124
+ static readonly ORDER_FILLED_WITH_AMM = {
125
+ orderFilledWithAMM: {},
126
+ };
127
+ static readonly ORDER_FILLED_WITH_AMM_JIT = {
128
+ orderFilledWithAMMJit: {},
129
+ };
130
+ static readonly ORDER_FILLED_WITH_MATCH = {
131
+ orderFilledWithMatch: {},
132
+ };
133
+ static readonly MARKET_EXPIRED = {
134
+ marketExpired: {},
135
+ };
136
+ static readonly RISK_INCREASING_ORDER = {
137
+ riskingIncreasingOrder: {},
138
+ };
139
+ static readonly ORDER_FILLED_WITH_SERUM = {
140
+ orderFillWithSerum: {},
141
+ };
65
142
  }
66
143
 
67
144
  export class OrderTriggerCondition {
68
145
  static readonly ABOVE = { above: {} };
69
146
  static readonly BELOW = { below: {} };
147
+ static readonly TRIGGERED_ABOVE = { triggeredAbove: {} }; // above condition has been triggered
148
+ static readonly TRIGGERED_BELOW = { triggeredBelow: {} }; // below condition has been triggered
149
+ }
150
+
151
+ export class SpotFulfillmentType {
152
+ static readonly SERUM_v3 = { serumV3: {} };
153
+ }
154
+
155
+ export class SpotFulfillmentStatus {
156
+ static readonly ENABLED = { enabled: {} };
157
+ static readonly DISABLED = { disabled: {} };
158
+ }
159
+
160
+ export class DepositExplanation {
161
+ static readonly NONE = { none: {} };
162
+ static readonly TRANSFER = { transfer: {} };
163
+ }
164
+
165
+ export class SettlePnlExplanation {
166
+ static readonly NONE = { none: {} };
167
+ static readonly EXPIRED_POSITION = { expiredPosition: {} };
168
+ }
169
+
170
+ export class StakeAction {
171
+ static readonly STAKE = { stake: {} };
172
+ static readonly UNSTAKE_REQUEST = { unstakeRequest: {} };
173
+ static readonly UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
174
+ static readonly UNSTAKE = { unstake: {} };
70
175
  }
71
176
 
72
177
  export function isVariant(object: unknown, type: string) {
@@ -79,6 +184,10 @@ export function isOneOfVariant(object: unknown, types: string[]) {
79
184
  }, false);
80
185
  }
81
186
 
187
+ export function getVariant(object: unknown): string {
188
+ return Object.keys(object)[0];
189
+ }
190
+
82
191
  export enum TradeSide {
83
192
  None = 0,
84
193
  Buy = 1,
@@ -95,6 +204,15 @@ export type CandleResolution =
95
204
  | 'W'
96
205
  | 'M';
97
206
 
207
+ export type NewUserRecord = {
208
+ ts: BN;
209
+ userAuthority: PublicKey;
210
+ user: PublicKey;
211
+ subAccount: number;
212
+ name: number[];
213
+ referrer: PublicKey;
214
+ };
215
+
98
216
  export type DepositRecord = {
99
217
  ts: BN;
100
218
  userAuthority: PublicKey;
@@ -103,16 +221,36 @@ export type DepositRecord = {
103
221
  deposit?: any;
104
222
  withdraw?: any;
105
223
  };
106
- bankIndex: BN;
224
+ marketIndex: number;
107
225
  amount: BN;
108
- from?: PublicKey;
109
- to?: PublicKey;
226
+ oraclePrice: BN;
227
+ marketDepositBalance: BN;
228
+ marketWithdrawBalance: BN;
229
+ marketCumulativeDepositInterest: BN;
230
+ marketCumulativeBorrowInterest: BN;
231
+ totalDepositsAfter: BN;
232
+ totalWithdrawsAfter: BN;
233
+ depositRecordId: BN;
234
+ explanation: DepositExplanation;
235
+ transferUser?: PublicKey;
236
+ };
237
+
238
+ export type SpotInterestRecord = {
239
+ ts: BN;
240
+ marketIndex: number;
241
+ depositBalance: BN;
242
+ cumulativeDepositInterest: BN;
243
+ borrowBalance: BN;
244
+ cumulativeBorrowInterest: BN;
245
+ optimalUtilization: number;
246
+ optimalBorrowRate: number;
247
+ maxBorrowRate: number;
110
248
  };
111
249
 
112
250
  export type CurveRecord = {
113
251
  ts: BN;
114
252
  recordId: BN;
115
- marketIndex: BN;
253
+ marketIndex: number;
116
254
  pegMultiplierBefore: BN;
117
255
  baseAssetReserveBefore: BN;
118
256
  quoteAssetReserveBefore: BN;
@@ -123,148 +261,373 @@ export type CurveRecord = {
123
261
  sqrtKAfter: BN;
124
262
  baseAssetAmountLong: BN;
125
263
  baseAssetAmountShort: BN;
126
- baseAssetAmount: BN;
127
- openInterest: BN;
264
+ baseAssetAmountWithAmm: BN;
265
+ totalFee: BN;
266
+ totalFeeMinusDistributions: BN;
267
+ adjustmentCost: BN;
268
+ numberOfUsers: BN;
128
269
  oraclePrice: BN;
129
- tradeId: BN;
270
+ fillRecord: BN;
130
271
  };
131
272
 
273
+ export declare type InsuranceFundRecord = {
274
+ ts: BN;
275
+ spotMarketIndex: BN;
276
+ perpMarketIndex: number;
277
+ userIfFactor: number;
278
+ totalIfFactor: number;
279
+ vaultAmountBefore: BN;
280
+ insuranceVaultAmountBefore: BN;
281
+ totalIfSharesBefore: BN;
282
+ totalIfSharesAfter: BN;
283
+ amount: BN;
284
+ };
285
+
286
+ export declare type InsuranceFundStakeRecord = {
287
+ ts: BN;
288
+ userAuthority: PublicKey;
289
+ action: StakeAction;
290
+ amount: BN;
291
+ marketIndex: number;
292
+ insuranceVaultAmountBefore: BN;
293
+ ifSharesBefore: BN;
294
+ userIfSharesBefore: BN;
295
+ totalIfSharesBefore: BN;
296
+ ifSharesAfter: BN;
297
+ userIfSharesAfter: BN;
298
+ totalIfSharesAfter: BN;
299
+ };
300
+
301
+ export type LPRecord = {
302
+ ts: BN;
303
+ user: PublicKey;
304
+ action: LPAction;
305
+ nShares: BN;
306
+ marketIndex: number;
307
+ deltaBaseAssetAmount: BN;
308
+ deltaQuoteAssetAmount: BN;
309
+ pnl: BN;
310
+ };
311
+
312
+ export class LPAction {
313
+ static readonly ADD_LIQUIDITY = { addLiquidity: {} };
314
+ static readonly REMOVE_LIQUIDITY = { removeLiquidity: {} };
315
+ static readonly SETTLE_LIQUIDITY = { settleLiquidity: {} };
316
+ }
317
+
132
318
  export type FundingRateRecord = {
133
319
  ts: BN;
134
320
  recordId: BN;
135
- marketIndex: BN;
321
+ marketIndex: number;
136
322
  fundingRate: BN;
323
+ fundingRateLong: BN;
324
+ fundingRateShort: BN;
137
325
  cumulativeFundingRateLong: BN;
138
326
  cumulativeFundingRateShort: BN;
139
327
  oraclePriceTwap: BN;
140
328
  markPriceTwap: BN;
329
+ periodRevenue: BN;
330
+ baseAssetAmountWithAmm: BN;
331
+ baseAssetAmountWithUnsettledLp: BN;
141
332
  };
142
333
 
143
334
  export type FundingPaymentRecord = {
144
335
  ts: BN;
145
336
  userAuthority: PublicKey;
146
337
  user: PublicKey;
147
- marketIndex: BN;
338
+ marketIndex: number;
148
339
  fundingPayment: BN;
149
340
  baseAssetAmount: BN;
150
341
  userLastCumulativeFunding: BN;
151
- userLastFundingRateTs: BN;
152
342
  ammCumulativeFundingLong: BN;
153
343
  ammCumulativeFundingShort: BN;
154
344
  };
155
345
 
156
346
  export type LiquidationRecord = {
157
347
  ts: BN;
158
- recordId: BN;
159
- userAuthority: PublicKey;
160
348
  user: PublicKey;
161
- partial: boolean;
162
- baseAssetValue: BN;
163
- baseAssetValueClosed: BN;
164
- liquidationFee: BN;
165
- feeToLiquidator: BN;
166
- feeToInsuranceFund: BN;
167
349
  liquidator: PublicKey;
350
+ liquidationType: LiquidationType;
351
+ marginRequirement: BN;
168
352
  totalCollateral: BN;
169
- collateral: BN;
170
- unrealizedPnl: BN;
171
- marginRatio: BN;
353
+ marginFreed: BN;
354
+ liquidationId: number;
355
+ bankrupt: boolean;
356
+ canceledOrderIds: BN[];
357
+ liquidatePerp: LiquidatePerpRecord;
358
+ liquidateSpot: LiquidateSpotRecord;
359
+ liquidateBorrowForPerpPnl: LiquidateBorrowForPerpPnlRecord;
360
+ liquidatePerpPnlForDeposit: LiquidatePerpPnlForDepositRecord;
361
+ perpBankruptcy: PerpBankruptcyRecord;
362
+ spotBankruptcy: SpotBankruptcyRecord;
363
+ };
364
+
365
+ export class LiquidationType {
366
+ static readonly LIQUIDATE_PERP = { liquidatePerp: {} };
367
+ static readonly LIQUIDATE_BORROW = { liquidateBorrow: {} };
368
+ static readonly LIQUIDATE_BORROW_FOR_PERP_PNL = {
369
+ liquidateBorrowForPerpPnl: {},
370
+ };
371
+ static readonly LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
372
+ liquidatePerpPnlForDeposit: {},
373
+ };
374
+ static readonly PERP_BANKRUPTCY = {
375
+ perpBankruptcy: {},
376
+ };
377
+ static readonly BORROW_BANKRUPTCY = {
378
+ borrowBankruptcy: {},
379
+ };
380
+ }
381
+
382
+ export type LiquidatePerpRecord = {
383
+ marketIndex: number;
384
+ oraclePrice: BN;
385
+ baseAssetAmount: BN;
386
+ quoteAssetAmount: BN;
387
+ lpShares: BN;
388
+ userOrderId: BN;
389
+ liquidatorOrderId: BN;
390
+ fillRecordId: BN;
391
+ liquidatorFee: BN;
392
+ ifFee: BN;
393
+ };
394
+
395
+ export type LiquidateSpotRecord = {
396
+ assetMarketIndex: number;
397
+ assetPrice: BN;
398
+ assetTransfer: BN;
399
+ liabilityMarketIndex: number;
400
+ liabilityPrice: BN;
401
+ liabilityTransfer: BN;
402
+ ifFee: BN;
403
+ };
404
+
405
+ export type LiquidateBorrowForPerpPnlRecord = {
406
+ perpMarketIndex: number;
407
+ marketOraclePrice: BN;
408
+ pnlTransfer: BN;
409
+ liabilityMarketIndex: number;
410
+ liabilityPrice: BN;
411
+ liabilityTransfer: BN;
412
+ };
413
+
414
+ export type LiquidatePerpPnlForDepositRecord = {
415
+ perpMarketIndex: number;
416
+ marketOraclePrice: BN;
417
+ pnlTransfer: BN;
418
+ assetMarketIndex: number;
419
+ assetPrice: BN;
420
+ assetTransfer: BN;
421
+ };
422
+
423
+ export type PerpBankruptcyRecord = {
424
+ marketIndex: number;
425
+ pnl: BN;
426
+ ifPayment: BN;
427
+ clawbackUser: PublicKey | null;
428
+ clawbackUserPayment: BN | null;
429
+ cumulativeFundingRateDelta: BN;
430
+ };
431
+
432
+ export type SpotBankruptcyRecord = {
433
+ marketIndex: number;
434
+ borrowAmount: BN;
435
+ cumulativeDepositInterestDelta: BN;
436
+ ifPayment: BN;
437
+ };
438
+
439
+ export type SettlePnlRecord = {
440
+ ts: BN;
441
+ user: PublicKey;
442
+ marketIndex: number;
443
+ pnl: BN;
444
+ baseAssetAmount: BN;
445
+ quoteAssetAmountAfter: BN;
446
+ quoteEntryAmount: BN;
447
+ settlePrice: BN;
448
+ explanation: SettlePnlExplanation;
172
449
  };
173
450
 
174
451
  export type OrderRecord = {
175
452
  ts: BN;
176
- taker: PublicKey;
177
- maker: PublicKey;
178
- takerOrder: Order;
179
- makerOrder: Order;
180
- takerUnsettledPnl: BN;
181
- makerUnsettledPnl: BN;
453
+ user: PublicKey;
454
+ order: Order;
455
+ };
456
+
457
+ export type OrderActionRecord = {
458
+ ts: BN;
182
459
  action: OrderAction;
183
460
  actionExplanation: OrderActionExplanation;
184
- filler: PublicKey;
185
- fillRecordId: BN;
186
- marketIndex: BN;
187
- baseAssetAmountFilled: BN;
188
- quoteAssetAmountFilled: BN;
189
- makerRebate: BN;
190
- takerFee: BN;
191
- fillerReward: BN;
192
- quoteAssetAmountSurplus: BN;
461
+ marketIndex: number;
462
+ marketType: MarketType;
463
+ filler: PublicKey | null;
464
+ fillerReward: BN | null;
465
+ fillRecordId: BN | null;
466
+ baseAssetAmountFilled: BN | null;
467
+ quoteAssetAmountFilled: BN | null;
468
+ takerFee: BN | null;
469
+ makerFee: BN | null;
470
+ referrerReward: number | null;
471
+ quoteAssetAmountSurplus: BN | null;
472
+ spot_fulfillment_method_fee: BN | null;
473
+ taker: PublicKey | null;
474
+ takerOrderId: number | null;
475
+ takerOrderDirection: PositionDirection | null;
476
+ takerOrderBaseAssetAmount: BN | null;
477
+ takerOrderCumulativeBaseAssetAmountFilled: BN | null;
478
+ takerOrderCumulativeQuoteAssetAmountFilled: BN | null;
479
+ maker: PublicKey | null;
480
+ makerOrderId: number | null;
481
+ makerOrderDirection: PositionDirection | null;
482
+ makerOrderBaseAssetAmount: BN | null;
483
+ makerOrderCumulativeBaseAssetAmountFilled: BN | null;
484
+ makerOrderCumulativeQuoteAssetAmountFilled: BN | null;
193
485
  oraclePrice: BN;
194
486
  };
195
487
 
196
488
  export type StateAccount = {
197
489
  admin: PublicKey;
198
- fundingPaused: boolean;
199
- exchangePaused: boolean;
200
- adminControlsPrices: boolean;
201
- insuranceVault: PublicKey;
202
- insuranceVaultAuthority: PublicKey;
203
- insuranceVaultNonce: number;
204
- marginRatioInitial: BN;
205
- marginRatioMaintenance: BN;
206
- marginRatioPartial: BN;
207
- partialLiquidationClosePercentageNumerator: BN;
208
- partialLiquidationClosePercentageDenominator: BN;
209
- partialLiquidationPenaltyPercentageNumerator: BN;
210
- partialLiquidationPenaltyPercentageDenominator: BN;
211
- fullLiquidationPenaltyPercentageNumerator: BN;
212
- fullLiquidationPenaltyPercentageDenominator: BN;
213
- partialLiquidationLiquidatorShareDenominator: BN;
214
- fullLiquidationLiquidatorShareDenominator: BN;
215
- feeStructure: FeeStructure;
216
- totalFee: BN;
217
- totalFeeWithdrawn: BN;
490
+ exchangeStatus: ExchangeStatus;
218
491
  whitelistMint: PublicKey;
219
492
  discountMint: PublicKey;
220
493
  oracleGuardRails: OracleGuardRails;
221
- maxDeposit: BN;
222
- numberOfMarkets: BN;
223
- numberOfBanks: BN;
224
- minOrderQuoteAssetAmount: BN;
494
+ numberOfAuthorities: BN;
495
+ numberOfSubAccounts: BN;
496
+ numberOfMarkets: number;
497
+ numberOfSpotMarkets: number;
498
+ minPerpAuctionDuration: number;
499
+ defaultMarketOrderTimeInForce: number;
500
+ defaultSpotAuctionDuration: number;
501
+ liquidationMarginBufferRatio: number;
502
+ settlementDuration: number;
503
+ signer: PublicKey;
504
+ signerNonce: number;
505
+ srmVault: PublicKey;
506
+ perpFeeStructure: FeeStructure;
507
+ spotFeeStructure: FeeStructure;
508
+ lpCooldownTime: BN;
225
509
  };
226
510
 
227
- export type MarketAccount = {
228
- initialized: boolean;
229
- marketIndex: BN;
511
+ export type PerpMarketAccount = {
512
+ status: MarketStatus;
513
+ contractType: ContractType;
514
+ contractTier: ContractTier;
515
+ expiryTs: BN;
516
+ expiryPrice: BN;
517
+ marketIndex: number;
230
518
  pubkey: PublicKey;
519
+ name: number[];
231
520
  amm: AMM;
232
- baseAssetAmount: BN;
233
- baseAssetAmountLong: BN;
234
- baseAssetAmountShort: BN;
235
- openInterest: BN;
521
+ numberOfUsersWithBase: number;
522
+ numberOfUsers: number;
236
523
  marginRatioInitial: number;
237
524
  marginRatioMaintenance: number;
238
- marginRatioPartial: number;
239
525
  nextFillRecordId: BN;
526
+ nextFundingRateRecordId: BN;
527
+ nextCurveRecordId: BN;
240
528
  pnlPool: PoolBalance;
529
+ liquidatorFee: number;
530
+ ifLiquidationFee: number;
531
+ imfFactor: number;
532
+ unrealizedPnlImfFactor: number;
533
+ unrealizedPnlMaxImbalance: BN;
534
+ unrealizedPnlInitialAssetWeight: number;
535
+ unrealizedPnlMaintenanceAssetWeight: number;
536
+ insuranceClaim: {
537
+ revenueWithdrawSinceLastSettle: BN;
538
+ maxRevenueWithdrawPerPeriod: BN;
539
+ lastRevenueWithdrawTs: BN;
540
+ quoteSettledInsurance: BN;
541
+ quoteMaxInsurance: BN;
542
+ };
543
+ };
544
+
545
+ export type HistoricalOracleData = {
546
+ lastOraclePrice: BN;
547
+ lastOracleDelay: BN;
548
+ lastOracleConf: BN;
549
+ lastOraclePriceTwap: BN;
550
+ lastOraclePriceTwap5Min: BN;
551
+ lastOraclePriceTwapTs: BN;
241
552
  };
242
553
 
243
- export type BankAccount = {
244
- bankIndex: BN;
554
+ export type HistoricalIndexData = {
555
+ lastIndexBidPrice: BN;
556
+ lastIndexAskPrice: BN;
557
+ lastIndexPriceTwap: BN;
558
+ lastIndexPriceTwap5Min: BN;
559
+ lastIndexPriceTwapTs: BN;
560
+ };
561
+
562
+ export type SpotMarketAccount = {
563
+ status: MarketStatus;
564
+ assetTier: AssetTier;
565
+
566
+ marketIndex: number;
245
567
  pubkey: PublicKey;
246
568
  mint: PublicKey;
247
569
  vault: PublicKey;
248
- vaultAuthority: PublicKey;
249
- vaultAuthorityNonce: number;
570
+
571
+ oracle: PublicKey;
572
+ oracleSource: OracleSource;
573
+ historicalOracleData: HistoricalOracleData;
574
+ historicalIndexData: HistoricalIndexData;
575
+
576
+ insuranceFund: {
577
+ vault: PublicKey;
578
+ totalShares: BN;
579
+ userShares: BN;
580
+ sharesBase: BN;
581
+ unstakingPeriod: BN;
582
+ lastRevenueSettleTs: BN;
583
+ revenueSettlePeriod: BN;
584
+ totalFactor: number;
585
+ userFactor: number;
586
+ };
587
+
588
+ revenuePool: PoolBalance;
589
+
590
+ ifLiquidationFee: number;
591
+
250
592
  decimals: number;
251
- optimalUtilization: BN;
252
- optimalBorrowRate: BN;
253
- maxBorrowRate: BN;
593
+ optimalUtilization: number;
594
+ optimalBorrowRate: number;
595
+ maxBorrowRate: number;
254
596
  cumulativeDepositInterest: BN;
255
597
  cumulativeBorrowInterest: BN;
598
+ totalSocialLoss: BN;
599
+ totalQuoteSocialLoss: BN;
256
600
  depositBalance: BN;
257
601
  borrowBalance: BN;
258
- lastUpdated: BN;
259
- oracle: PublicKey;
260
- initialAssetWeight: BN;
261
- maintenanceAssetWeight: BN;
262
- initialLiabilityWeight: BN;
263
- maintenanceLiabilityWeight: BN;
602
+ maxTokenDeposits: BN;
603
+
604
+ lastInterestTs: BN;
605
+ lastTwapTs: BN;
606
+ initialAssetWeight: number;
607
+ maintenanceAssetWeight: number;
608
+ initialLiabilityWeight: number;
609
+ maintenanceLiabilityWeight: number;
610
+ liquidatorFee: number;
611
+ imfFactor: number;
612
+
613
+ withdrawGuardThreshold: BN;
614
+ depositTokenTwap: BN;
615
+ borrowTokenTwap: BN;
616
+ utilizationTwap: BN;
617
+ nextDepositRecordId: BN;
618
+
619
+ orderStepSize: BN;
620
+ orderTickSize: BN;
621
+ nextFillRecordId: BN;
622
+ spotFeePool: PoolBalance;
623
+ totalSpotFee: BN;
624
+
625
+ ordersEnabled: boolean;
264
626
  };
265
627
 
266
628
  export type PoolBalance = {
267
- balance: BN;
629
+ scaledBalance: BN;
630
+ marketIndex: number;
268
631
  };
269
632
 
270
633
  export type AMM = {
@@ -274,138 +637,209 @@ export type AMM = {
274
637
  lastFundingRate: BN;
275
638
  lastFundingRateTs: BN;
276
639
  lastMarkPriceTwap: BN;
640
+ lastMarkPriceTwap5Min: BN;
277
641
  lastMarkPriceTwapTs: BN;
278
- lastOraclePriceTwap: BN;
279
- lastOraclePriceTwapTs: BN;
280
- lastOracleMarkSpreadPct: BN;
281
- lastOracleConfPct: BN;
642
+ lastTradeTs: BN;
643
+
282
644
  oracle: PublicKey;
283
645
  oracleSource: OracleSource;
646
+ historicalOracleData: HistoricalOracleData;
647
+
648
+ lastOracleReservePriceSpreadPct: BN;
649
+ lastOracleConfPct: BN;
650
+
284
651
  fundingPeriod: BN;
285
652
  quoteAssetReserve: BN;
286
653
  pegMultiplier: BN;
287
654
  cumulativeFundingRateLong: BN;
288
655
  cumulativeFundingRateShort: BN;
289
- cumulativeRepegRebateLong: BN;
290
- cumulativeRepegRebateShort: BN;
656
+ last24hAvgFundingRate: BN;
657
+ lastFundingRateShort: BN;
658
+ lastFundingRateLong: BN;
659
+
660
+ totalLiquidationFee: BN;
291
661
  totalFeeMinusDistributions: BN;
292
662
  totalFeeWithdrawn: BN;
293
663
  totalFee: BN;
294
- minimumQuoteAssetTradeSize: BN;
295
- baseAssetAmountStepSize: BN;
296
- maxBaseAssetAmountRatio: number;
664
+ userLpShares: BN;
665
+ baseAssetAmountWithUnsettledLp: BN;
666
+ orderStepSize: BN;
667
+ orderTickSize: BN;
668
+ maxFillReserveFraction: number;
297
669
  maxSlippageRatio: number;
298
- lastOraclePrice: BN;
299
670
  baseSpread: number;
300
671
  curveUpdateIntensity: number;
301
- netBaseAssetAmount: BN;
302
- quoteAssetAmountLong: BN;
303
- quoteAssetAmountShort: BN;
672
+ baseAssetAmountWithAmm: BN;
673
+ baseAssetAmountLong: BN;
674
+ baseAssetAmountShort: BN;
675
+ quoteAssetAmount: BN;
304
676
  terminalQuoteAssetReserve: BN;
677
+ concentrationCoef: BN;
305
678
  feePool: PoolBalance;
306
679
  totalExchangeFee: BN;
307
680
  totalMmFee: BN;
308
681
  netRevenueSinceLastFunding: BN;
309
682
  lastUpdateSlot: BN;
683
+ lastOracleNormalisedPrice: BN;
684
+ lastOracleValid: boolean;
310
685
  lastBidPriceTwap: BN;
311
686
  lastAskPriceTwap: BN;
312
- longSpread: BN;
313
- shortSpread: BN;
687
+ longSpread: number;
688
+ shortSpread: number;
314
689
  maxSpread: number;
690
+
691
+ baseAssetAmountPerLp: BN;
692
+ quoteAssetAmountPerLp: BN;
693
+
694
+ ammJitIntensity: number;
695
+ maxOpenInterest: BN;
696
+ maxBaseAssetReserve: BN;
697
+ minBaseAssetReserve: BN;
698
+ totalSocialLoss: BN;
699
+
700
+ quoteBreakEvenAmountLong: BN;
701
+ quoteBreakEvenAmountShort: BN;
702
+ quoteEntryAmountLong: BN;
703
+ quoteEntryAmountShort: BN;
704
+
705
+ markStd: BN;
706
+ oracleStd: BN;
707
+ longIntensityCount: number;
708
+ longIntensityVolume: BN;
709
+ shortIntensityCount: number;
710
+ shortIntensityVolume: BN;
711
+ volume24H: BN;
712
+ minOrderSize: BN;
713
+ maxPositionSize: BN;
714
+
715
+ bidBaseAssetReserve: BN;
716
+ bidQuoteAssetReserve: BN;
717
+ askBaseAssetReserve: BN;
718
+ askQuoteAssetReserve: BN;
315
719
  };
316
720
 
317
721
  // # User Account Types
318
- export type UserPosition = {
722
+ export type PerpPosition = {
319
723
  baseAssetAmount: BN;
320
724
  lastCumulativeFundingRate: BN;
321
- marketIndex: BN;
725
+ marketIndex: number;
322
726
  quoteAssetAmount: BN;
323
727
  quoteEntryAmount: BN;
324
- openOrders: BN;
325
- unsettledPnl: BN;
728
+ quoteBreakEvenAmount: BN;
729
+ openOrders: number;
326
730
  openBids: BN;
327
731
  openAsks: BN;
732
+ settledPnl: BN;
733
+ lpShares: BN;
734
+ remainderBaseAssetAmount: number;
735
+ lastNetBaseAssetAmountPerLp: BN;
736
+ lastNetQuoteAssetAmountPerLp: BN;
328
737
  };
329
738
 
330
- export type UserAccount = {
331
- authority: PublicKey;
332
- name: number[];
333
- userId: number;
334
- bankBalances: UserBankBalance[];
335
- collateral: BN;
336
- cumulativeDeposits: BN;
739
+ export type UserStatsAccount = {
740
+ numberOfSubAccounts: number;
741
+ numberOfSubAccountsCreated: number;
742
+ makerVolume30D: BN;
743
+ takerVolume30D: BN;
744
+ fillerVolume30D: BN;
745
+ lastMakerVolume30DTs: BN;
746
+ lastTakerVolume30DTs: BN;
747
+ lastFillerVolume30DTs: BN;
337
748
  fees: {
338
749
  totalFeePaid: BN;
339
750
  totalFeeRebate: BN;
340
751
  totalTokenDiscount: BN;
341
- totalReferralReward: BN;
342
752
  totalRefereeDiscount: BN;
753
+ totalReferrerReward: BN;
754
+ current_epoch_referrer_reward: BN;
343
755
  };
344
- positions: UserPosition[];
756
+ referrer: PublicKey;
757
+ isReferrer: boolean;
758
+ authority: PublicKey;
759
+ ifStakedQuoteAssetAmount: BN;
760
+ };
761
+
762
+ export type UserAccount = {
763
+ authority: PublicKey;
764
+ delegate: PublicKey;
765
+ name: number[];
766
+ subAccountId: number;
767
+ spotPositions: SpotPosition[];
768
+ perpPositions: PerpPosition[];
345
769
  orders: Order[];
770
+ status: UserStatus;
771
+ nextLiquidationId: number;
772
+ nextOrderId: number;
773
+ maxMarginRatio: number;
774
+ lastAddPerpLpSharesTs: BN;
775
+ settledPerpPnl: BN;
776
+ totalDeposits: BN;
777
+ totalWithdraws: BN;
778
+ totalSocialLoss: BN;
779
+ cumulativePerpFunding: BN;
346
780
  };
347
781
 
348
- export type UserBankBalance = {
349
- bankIndex: BN;
350
- balanceType: BankBalanceType;
351
- balance: BN;
782
+ export type SpotPosition = {
783
+ marketIndex: number;
784
+ balanceType: SpotBalanceType;
785
+ scaledBalance: BN;
786
+ openOrders: number;
787
+ openBids: BN;
788
+ openAsks: BN;
789
+ cumulativeDeposits: BN;
352
790
  };
353
791
 
354
792
  export type Order = {
355
793
  status: OrderStatus;
356
794
  orderType: OrderType;
357
- ts: BN;
795
+ marketType: MarketType;
358
796
  slot: BN;
359
- orderId: BN;
797
+ orderId: number;
360
798
  userOrderId: number;
361
- marketIndex: BN;
799
+ marketIndex: number;
362
800
  price: BN;
363
801
  baseAssetAmount: BN;
364
802
  baseAssetAmountFilled: BN;
365
803
  quoteAssetAmount: BN;
366
804
  quoteAssetAmountFilled: BN;
367
- fee: BN;
368
805
  direction: PositionDirection;
369
806
  reduceOnly: boolean;
370
807
  triggerPrice: BN;
371
808
  triggerCondition: OrderTriggerCondition;
372
- triggered: boolean;
373
- discountTier: OrderDiscountTier;
374
809
  existingPositionDirection: PositionDirection;
375
- referrer: PublicKey;
376
810
  postOnly: boolean;
377
811
  immediateOrCancel: boolean;
378
- oraclePriceOffset: BN;
812
+ oraclePriceOffset: number;
379
813
  auctionDuration: number;
380
814
  auctionStartPrice: BN;
381
815
  auctionEndPrice: BN;
816
+ maxTs: BN;
382
817
  };
383
818
 
384
819
  export type OrderParams = {
385
820
  orderType: OrderType;
821
+ marketType: MarketType;
386
822
  userOrderId: number;
387
823
  direction: PositionDirection;
388
824
  baseAssetAmount: BN;
389
825
  price: BN;
390
- marketIndex: BN;
826
+ marketIndex: number;
391
827
  reduceOnly: boolean;
392
828
  postOnly: boolean;
393
829
  immediateOrCancel: boolean;
394
- triggerPrice: BN;
830
+ triggerPrice: BN | null;
395
831
  triggerCondition: OrderTriggerCondition;
396
832
  positionLimit: BN;
397
- oraclePriceOffset: BN;
398
- padding0: boolean;
399
- padding1: BN;
400
- optionalAccounts: {
401
- discountToken: boolean;
402
- referrer: boolean;
403
- };
833
+ oraclePriceOffset: number | null;
834
+ auctionDuration: number | null;
835
+ maxTs: BN | null;
836
+ auctionStartPrice: BN | null;
837
+ auctionEndPrice: BN | null;
404
838
  };
405
839
 
406
840
  export type NecessaryOrderParams = {
407
841
  orderType: OrderType;
408
- marketIndex: BN;
842
+ marketIndex: number;
409
843
  baseAssetAmount: BN;
410
844
  direction: PositionDirection;
411
845
  };
@@ -414,33 +848,46 @@ export type OptionalOrderParams = {
414
848
  [Property in keyof OrderParams]?: OrderParams[Property];
415
849
  } & NecessaryOrderParams;
416
850
 
417
- export const DefaultOrderParams = {
851
+ export const DefaultOrderParams: OrderParams = {
418
852
  orderType: OrderType.MARKET,
853
+ marketType: MarketType.PERP,
419
854
  userOrderId: 0,
420
855
  direction: PositionDirection.LONG,
421
856
  baseAssetAmount: ZERO,
422
857
  price: ZERO,
423
- marketIndex: ZERO,
858
+ marketIndex: 0,
424
859
  reduceOnly: false,
425
860
  postOnly: false,
426
861
  immediateOrCancel: false,
427
- triggerPrice: ZERO,
862
+ triggerPrice: null,
428
863
  triggerCondition: OrderTriggerCondition.ABOVE,
429
864
  positionLimit: ZERO,
430
- oraclePriceOffset: ZERO,
431
- padding0: ZERO,
432
- padding1: ZERO,
433
- optionalAccounts: {
434
- discountToken: false,
435
- referrer: false,
436
- },
865
+ oraclePriceOffset: null,
866
+ auctionDuration: null,
867
+ maxTs: null,
868
+ auctionStartPrice: null,
869
+ auctionEndPrice: null,
437
870
  };
438
871
 
439
872
  export type MakerInfo = {
440
873
  maker: PublicKey;
874
+ makerStats: PublicKey;
875
+ makerUserAccount: UserAccount;
441
876
  order: Order;
442
877
  };
443
878
 
879
+ export type TakerInfo = {
880
+ taker: PublicKey;
881
+ takerStats: PublicKey;
882
+ takerUserAccount: UserAccount;
883
+ order: Order;
884
+ };
885
+
886
+ export type ReferrerInfo = {
887
+ referrer: PublicKey;
888
+ referrerStats: PublicKey;
889
+ };
890
+
444
891
  // # Misc Types
445
892
  export interface IWallet {
446
893
  signTransaction(tx: Transaction): Promise<Transaction>;
@@ -449,39 +896,29 @@ export interface IWallet {
449
896
  }
450
897
 
451
898
  export type FeeStructure = {
452
- feeNumerator: BN;
453
- feeDenominator: BN;
454
- discountTokenTiers: {
455
- firstTier: {
456
- minimumBalance: BN;
457
- discountNumerator: BN;
458
- discountDenominator: BN;
459
- };
460
- secondTier: {
461
- minimumBalance: BN;
462
- discountNumerator: BN;
463
- discountDenominator: BN;
464
- };
465
- thirdTier: {
466
- minimumBalance: BN;
467
- discountNumerator: BN;
468
- discountDenominator: BN;
469
- };
470
- fourthTier: {
471
- minimumBalance: BN;
472
- discountNumerator: BN;
473
- discountDenominator: BN;
474
- };
475
- };
476
- referralDiscount: {
477
- referrerRewardNumerator: BN;
478
- referrerRewardDenominator: BN;
479
- refereeDiscountNumerator: BN;
480
- refereeDiscountDenominator: BN;
481
- };
899
+ feeTiers: FeeTier[];
482
900
  makerRebateNumerator: BN;
483
901
  makerRebateDenominator: BN;
484
902
  fillerRewardStructure: OrderFillerRewardStructure;
903
+ flatFillerFee: BN;
904
+ referrerRewardEpochUpperBound: BN;
905
+ };
906
+
907
+ export type FeeTier = {
908
+ feeNumerator: number;
909
+ feeDenominator: number;
910
+ makerRebateNumerator: number;
911
+ makerRebateDenominator: number;
912
+ referrerRewardNumerator: number;
913
+ referrerRewardDenominator: number;
914
+ refereeFeeNumerator: number;
915
+ refereeFeeDenominator: number;
916
+ };
917
+
918
+ export type OrderFillerRewardStructure = {
919
+ rewardNumerator: BN;
920
+ rewardDenominator: BN;
921
+ timeBasedRewardLowerBound: BN;
485
922
  };
486
923
 
487
924
  export type OracleGuardRails = {
@@ -490,17 +927,41 @@ export type OracleGuardRails = {
490
927
  markOracleDivergenceDenominator: BN;
491
928
  };
492
929
  validity: {
493
- slotsBeforeStale: BN;
930
+ slotsBeforeStaleForAmm: BN;
931
+ slotsBeforeStaleForMargin: BN;
494
932
  confidenceIntervalMaxSize: BN;
495
933
  tooVolatileRatio: BN;
496
934
  };
497
935
  useForLiquidations: boolean;
498
936
  };
499
937
 
500
- export type OrderFillerRewardStructure = {
501
- rewardNumerator: BN;
502
- rewardDenominator: BN;
503
- timeBasedRewardLowerBound: BN;
938
+ export type MarginCategory = 'Initial' | 'Maintenance';
939
+
940
+ export type InsuranceFundStake = {
941
+ marketIndex: number;
942
+ authority: PublicKey;
943
+
944
+ ifShares: BN;
945
+ ifBase: BN;
946
+
947
+ lastWithdrawRequestShares: BN;
948
+ lastWithdrawRequestValue: BN;
949
+ lastWithdrawRequestTs: BN;
504
950
  };
505
951
 
506
- export type MarginCategory = 'Initial' | 'Partial' | 'Maintenance';
952
+ export type SerumV3FulfillmentConfigAccount = {
953
+ fulfillmentType: SpotFulfillmentType;
954
+ status: SpotFulfillmentStatus;
955
+ pubkey: PublicKey;
956
+ marketIndex: number;
957
+ serumProgramId: PublicKey;
958
+ serumMarket: PublicKey;
959
+ serumRequestQueue: PublicKey;
960
+ serumEventQueue: PublicKey;
961
+ serumBids: PublicKey;
962
+ serumAsks: PublicKey;
963
+ serumBaseVault: PublicKey;
964
+ serumQuoteVault: PublicKey;
965
+ serumOpenOrders: PublicKey;
966
+ serumSignerNonce: BN;
967
+ };