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

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 (234) 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/pollingUserStatsAccountSubscriber.d.ts +27 -0
  15. package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
  16. package/lib/accounts/types.d.ts +26 -15
  17. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
  18. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
  19. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
  20. package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
  21. package/lib/addresses/marketAddresses.d.ts +1 -3
  22. package/lib/addresses/marketAddresses.js +1 -1
  23. package/lib/addresses/pda.d.ts +15 -9
  24. package/lib/addresses/pda.js +73 -35
  25. package/lib/adminClient.d.ts +65 -0
  26. package/lib/adminClient.js +637 -0
  27. package/lib/config.d.ts +9 -9
  28. package/lib/config.js +25 -21
  29. package/lib/constants/numericConstants.d.ts +30 -12
  30. package/lib/constants/numericConstants.js +41 -21
  31. package/lib/constants/perpMarkets.d.ts +18 -0
  32. package/lib/constants/{markets.js → perpMarkets.js} +7 -7
  33. package/lib/constants/spotMarkets.d.ts +19 -0
  34. package/lib/constants/spotMarkets.js +53 -0
  35. package/lib/dlob/DLOB.d.ts +82 -0
  36. package/lib/dlob/DLOB.js +696 -0
  37. package/lib/dlob/DLOBNode.d.ts +54 -0
  38. package/lib/dlob/DLOBNode.js +77 -0
  39. package/lib/dlob/NodeList.d.ts +27 -0
  40. package/lib/dlob/NodeList.js +144 -0
  41. package/lib/driftClient.d.ts +233 -0
  42. package/lib/driftClient.js +2096 -0
  43. package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
  44. package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
  45. package/lib/events/eventList.js +3 -0
  46. package/lib/events/eventSubscriber.d.ts +5 -2
  47. package/lib/events/eventSubscriber.js +25 -11
  48. package/lib/events/fetchLogs.d.ts +13 -2
  49. package/lib/events/fetchLogs.js +40 -12
  50. package/lib/events/pollingLogProvider.d.ts +2 -1
  51. package/lib/events/pollingLogProvider.js +7 -3
  52. package/lib/events/sort.js +8 -11
  53. package/lib/events/types.d.ts +9 -3
  54. package/lib/events/types.js +6 -0
  55. package/lib/events/webSocketLogProvider.js +1 -1
  56. package/lib/examples/makeTradeExample.js +30 -18
  57. package/lib/factory/bigNum.d.ts +8 -4
  58. package/lib/factory/bigNum.js +109 -19
  59. package/lib/idl/drift.json +8250 -0
  60. package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  61. package/lib/index.d.ts +30 -13
  62. package/lib/index.js +30 -13
  63. package/lib/math/amm.d.ts +9 -6
  64. package/lib/math/amm.js +91 -38
  65. package/lib/math/conversion.js +1 -1
  66. package/lib/math/exchangeStatus.d.ts +4 -0
  67. package/lib/math/exchangeStatus.js +18 -0
  68. package/lib/math/funding.d.ts +6 -6
  69. package/lib/math/funding.js +23 -21
  70. package/lib/math/insurance.d.ts +4 -0
  71. package/lib/math/insurance.js +27 -0
  72. package/lib/math/margin.d.ts +11 -0
  73. package/lib/math/margin.js +82 -0
  74. package/lib/math/market.d.ts +14 -9
  75. package/lib/math/market.js +70 -10
  76. package/lib/math/oracles.d.ts +4 -0
  77. package/lib/math/oracles.js +36 -8
  78. package/lib/math/orders.d.ts +14 -6
  79. package/lib/math/orders.js +90 -17
  80. package/lib/math/position.d.ts +27 -13
  81. package/lib/math/position.js +92 -36
  82. package/lib/math/repeg.js +17 -8
  83. package/lib/math/spotBalance.d.ts +22 -0
  84. package/lib/math/spotBalance.js +192 -0
  85. package/lib/math/spotMarket.d.ts +4 -0
  86. package/lib/math/spotMarket.js +8 -0
  87. package/lib/math/spotPosition.d.ts +6 -0
  88. package/lib/math/spotPosition.js +23 -0
  89. package/lib/math/trade.d.ts +10 -10
  90. package/lib/math/trade.js +27 -31
  91. package/lib/oracles/pythClient.js +1 -1
  92. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  93. package/lib/oracles/switchboardClient.js +1 -1
  94. package/lib/orderParams.d.ts +4 -4
  95. package/lib/orderParams.js +12 -4
  96. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  97. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  98. package/lib/serum/serumSubscriber.d.ts +27 -0
  99. package/lib/serum/serumSubscriber.js +56 -0
  100. package/lib/serum/types.d.ts +11 -0
  101. package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
  102. package/lib/slot/SlotSubscriber.d.ts +7 -0
  103. package/lib/slot/SlotSubscriber.js +3 -0
  104. package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
  105. package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
  106. package/lib/tx/retryTxSender.d.ts +1 -1
  107. package/lib/tx/retryTxSender.js +13 -4
  108. package/lib/tx/types.d.ts +1 -1
  109. package/lib/tx/utils.js +1 -1
  110. package/lib/types.d.ts +589 -196
  111. package/lib/types.js +108 -17
  112. package/lib/user.d.ts +226 -0
  113. package/lib/user.js +949 -0
  114. package/lib/userConfig.d.ts +14 -0
  115. package/lib/userConfig.js +2 -0
  116. package/lib/userMap/userMap.d.ts +41 -0
  117. package/lib/userMap/userMap.js +85 -0
  118. package/lib/userMap/userStatsMap.d.ts +19 -0
  119. package/lib/userMap/userStatsMap.js +68 -0
  120. package/lib/userName.d.ts +1 -0
  121. package/lib/userName.js +3 -2
  122. package/lib/userStats.d.ts +18 -0
  123. package/lib/userStats.js +49 -0
  124. package/lib/userStatsConfig.d.ts +14 -0
  125. package/lib/userStatsConfig.js +2 -0
  126. package/lib/util/computeUnits.js +1 -1
  127. package/lib/util/getTokenAddress.d.ts +2 -0
  128. package/lib/util/getTokenAddress.js +9 -0
  129. package/package.json +10 -3
  130. package/src/accounts/bulkAccountLoader.ts +44 -34
  131. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  132. package/src/accounts/bulkUserSubscription.ts +2 -3
  133. package/src/accounts/fetch.ts +27 -2
  134. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  135. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  136. package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
  137. package/src/accounts/types.ts +35 -15
  138. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  139. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  140. package/src/addresses/marketAddresses.ts +3 -4
  141. package/src/addresses/pda.ts +105 -33
  142. package/src/adminClient.ts +1207 -0
  143. package/src/config.ts +37 -31
  144. package/src/constants/numericConstants.ts +58 -24
  145. package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
  146. package/src/constants/spotMarkets.ts +73 -0
  147. package/src/dlob/DLOB.ts +1123 -0
  148. package/src/dlob/DLOBNode.ts +155 -0
  149. package/src/dlob/NodeList.ts +195 -0
  150. package/src/driftClient.ts +3564 -0
  151. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  152. package/src/events/eventList.ts +3 -0
  153. package/src/events/eventSubscriber.ts +36 -14
  154. package/src/events/fetchLogs.ts +55 -13
  155. package/src/events/pollingLogProvider.ts +11 -3
  156. package/src/events/sort.ts +11 -15
  157. package/src/events/types.ts +21 -2
  158. package/src/events/webSocketLogProvider.ts +1 -1
  159. package/src/examples/makeTradeExample.ts +44 -28
  160. package/src/factory/bigNum.ts +150 -22
  161. package/src/idl/drift.json +8250 -0
  162. package/src/idl/pyth.json +98 -2
  163. package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  164. package/src/index.ts +30 -13
  165. package/src/math/amm.ts +161 -48
  166. package/src/math/conversion.ts +2 -2
  167. package/src/math/exchangeStatus.ts +31 -0
  168. package/src/math/funding.ts +41 -31
  169. package/src/math/insurance.ts +35 -0
  170. package/src/math/margin.ts +133 -0
  171. package/src/math/market.ts +143 -14
  172. package/src/math/oracles.ts +63 -9
  173. package/src/math/orders.ts +163 -26
  174. package/src/math/position.ts +136 -58
  175. package/src/math/repeg.ts +19 -9
  176. package/src/math/spotBalance.ts +319 -0
  177. package/src/math/spotMarket.ts +9 -0
  178. package/src/math/spotPosition.ts +47 -0
  179. package/src/math/trade.ts +33 -37
  180. package/src/oracles/pythClient.ts +2 -2
  181. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  182. package/src/oracles/switchboardClient.ts +2 -2
  183. package/src/orderParams.ts +16 -8
  184. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  185. package/src/serum/serumSubscriber.ts +99 -0
  186. package/src/serum/types.ts +13 -0
  187. package/src/slot/SlotSubscriber.ts +11 -1
  188. package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
  189. package/src/tx/retryTxSender.ts +16 -5
  190. package/src/tx/types.ts +2 -1
  191. package/src/tx/utils.ts +1 -1
  192. package/src/types.ts +572 -178
  193. package/src/user.ts +1582 -0
  194. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  195. package/src/userMap/userMap.ts +124 -0
  196. package/src/userMap/userStatsMap.ts +108 -0
  197. package/src/userName.ts +2 -1
  198. package/src/userStats.ts +75 -0
  199. package/src/userStatsConfig.ts +18 -0
  200. package/src/util/computeUnits.ts +1 -1
  201. package/src/util/getTokenAddress.ts +18 -0
  202. package/tests/bn/test.ts +46 -11
  203. package/tests/dlob/helpers.ts +611 -0
  204. package/tests/dlob/test.ts +4588 -0
  205. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  206. package/lib/admin.d.ts +0 -44
  207. package/lib/admin.js +0 -433
  208. package/lib/clearingHouse.d.ts +0 -133
  209. package/lib/clearingHouse.js +0 -931
  210. package/lib/clearingHouseUser.d.ts +0 -187
  211. package/lib/clearingHouseUser.js +0 -643
  212. package/lib/clearingHouseUserConfig.d.ts +0 -14
  213. package/lib/constants/banks.d.ts +0 -16
  214. package/lib/constants/banks.js +0 -34
  215. package/lib/constants/markets.d.ts +0 -19
  216. package/lib/idl/clearing_house.json +0 -3998
  217. package/lib/math/bankBalance.d.ts +0 -9
  218. package/lib/math/bankBalance.js +0 -75
  219. package/lib/math/state.d.ts +0 -8
  220. package/lib/math/state.js +0 -15
  221. package/lib/orders.d.ts +0 -8
  222. package/lib/orders.js +0 -134
  223. package/src/admin.ts +0 -722
  224. package/src/clearingHouse.ts +0 -1451
  225. package/src/clearingHouseUser.ts +0 -989
  226. package/src/constants/banks.ts +0 -43
  227. package/src/idl/clearing_house.json +0 -3998
  228. package/src/math/bankBalance.ts +0 -112
  229. package/src/math/state.ts +0 -14
  230. package/src/math/utils.js +0 -27
  231. package/src/math/utils.js.map +0 -1
  232. package/src/orders.ts +0 -244
  233. package/src/util/computeUnits.js +0 -17
  234. package/src/util/computeUnits.js.map +0 -1
@@ -1,643 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClearingHouseUser = void 0;
4
- const types_1 = require("./types");
5
- const position_1 = require("./math/position");
6
- const numericConstants_1 = require("./constants/numericConstants");
7
- const _1 = require(".");
8
- const bankBalance_1 = require("./math/bankBalance");
9
- const pollingUserAccountSubscriber_1 = require("./accounts/pollingUserAccountSubscriber");
10
- const webSocketUserAccountSubscriber_1 = require("./accounts/webSocketUserAccountSubscriber");
11
- class ClearingHouseUser {
12
- constructor(config) {
13
- var _a;
14
- this._isSubscribed = false;
15
- this.clearingHouse = config.clearingHouse;
16
- this.userAccountPublicKey = config.userAccountPublicKey;
17
- if (((_a = config.accountSubscription) === null || _a === void 0 ? void 0 : _a.type) === 'polling') {
18
- this.accountSubscriber = new pollingUserAccountSubscriber_1.PollingUserAccountSubscriber(config.clearingHouse.program, config.userAccountPublicKey, config.accountSubscription.accountLoader);
19
- }
20
- else {
21
- this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.clearingHouse.program, config.userAccountPublicKey);
22
- }
23
- this.eventEmitter = this.accountSubscriber.eventEmitter;
24
- }
25
- get isSubscribed() {
26
- return this._isSubscribed && this.accountSubscriber.isSubscribed;
27
- }
28
- set isSubscribed(val) {
29
- this._isSubscribed = val;
30
- }
31
- /**
32
- * Subscribe to ClearingHouseUser state accounts
33
- * @returns SusbcriptionSuccess result
34
- */
35
- async subscribe() {
36
- this.isSubscribed = await this.accountSubscriber.subscribe();
37
- return this.isSubscribed;
38
- }
39
- /**
40
- * Forces the accountSubscriber to fetch account updates from rpc
41
- */
42
- async fetchAccounts() {
43
- await this.accountSubscriber.fetch();
44
- }
45
- async unsubscribe() {
46
- await this.accountSubscriber.unsubscribe();
47
- this.isSubscribed = false;
48
- }
49
- getUserAccount() {
50
- return this.accountSubscriber.getUserAccountAndSlot().data;
51
- }
52
- getUserAccountAndSlot() {
53
- return this.accountSubscriber.getUserAccountAndSlot();
54
- }
55
- /**
56
- * Gets the user's current position for a given market. If the user has no position returns undefined
57
- * @param marketIndex
58
- * @returns userPosition
59
- */
60
- getUserPosition(marketIndex) {
61
- return this.getUserAccount().positions.find((position) => position.marketIndex.eq(marketIndex));
62
- }
63
- getEmptyPosition(marketIndex) {
64
- return {
65
- baseAssetAmount: numericConstants_1.ZERO,
66
- lastCumulativeFundingRate: numericConstants_1.ZERO,
67
- marketIndex,
68
- quoteAssetAmount: numericConstants_1.ZERO,
69
- quoteEntryAmount: numericConstants_1.ZERO,
70
- openOrders: numericConstants_1.ZERO,
71
- unsettledPnl: numericConstants_1.ZERO,
72
- openBids: numericConstants_1.ZERO,
73
- openAsks: numericConstants_1.ZERO,
74
- };
75
- }
76
- /**
77
- * @param orderId
78
- * @returns Order
79
- */
80
- getOrder(orderId) {
81
- return this.getUserAccount().orders.find((order) => order.orderId.eq(orderId));
82
- }
83
- /**
84
- * @param userOrderId
85
- * @returns Order
86
- */
87
- getOrderByUserOrderId(userOrderId) {
88
- return this.getUserAccount().orders.find((order) => order.userOrderId === userOrderId);
89
- }
90
- getUserAccountPublicKey() {
91
- return this.userAccountPublicKey;
92
- }
93
- async exists() {
94
- const userAccountRPCResponse = await this.clearingHouse.connection.getParsedAccountInfo(this.userAccountPublicKey);
95
- return userAccountRPCResponse.value !== null;
96
- }
97
- /**
98
- * calculates Buying Power = FC * MAX_LEVERAGE
99
- * @returns : Precision QUOTE_PRECISION
100
- */
101
- getBuyingPower(marketIndex) {
102
- return this.getFreeCollateral()
103
- .mul(this.getMaxLeverage(marketIndex, 'Initial'))
104
- .div(numericConstants_1.TEN_THOUSAND);
105
- }
106
- /**
107
- * calculates Free Collateral = Total collateral - initial margin requirement
108
- * @returns : Precision QUOTE_PRECISION
109
- */
110
- getFreeCollateral() {
111
- const totalCollateral = this.getTotalCollateral();
112
- const initialMarginRequirement = this.getInitialMarginRequirement();
113
- const freeCollateral = totalCollateral.sub(initialMarginRequirement);
114
- return freeCollateral.gte(numericConstants_1.ZERO) ? freeCollateral : numericConstants_1.ZERO;
115
- }
116
- getInitialMarginRequirement() {
117
- return this.getUserAccount()
118
- .positions.reduce((marginRequirement, marketPosition) => {
119
- const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
120
- return marginRequirement.add((0, _1.calculateBaseAssetValue)(market, marketPosition, this.getOracleDataForMarket(market.marketIndex))
121
- .mul(new _1.BN(market.marginRatioInitial))
122
- .div(numericConstants_1.MARGIN_PRECISION));
123
- }, numericConstants_1.ZERO)
124
- .add(this.getTotalLiability());
125
- }
126
- /**
127
- * @returns The partial margin requirement in USDC. : QUOTE_PRECISION
128
- */
129
- getPartialMarginRequirement() {
130
- return this.getUserAccount()
131
- .positions.reduce((marginRequirement, marketPosition) => {
132
- const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
133
- return marginRequirement.add((0, _1.calculateBaseAssetValue)(market, marketPosition, this.getOracleDataForMarket(market.marketIndex))
134
- .mul(new _1.BN(market.marginRatioPartial))
135
- .div(numericConstants_1.MARGIN_PRECISION));
136
- }, numericConstants_1.ZERO)
137
- .add(this.getTotalLiability());
138
- }
139
- /**
140
- * calculates unrealized position price pnl
141
- * @returns : Precision QUOTE_PRECISION
142
- */
143
- getUnrealizedPNL(withFunding, marketIndex) {
144
- return this.getUserAccount()
145
- .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
146
- .reduce((pnl, marketPosition) => {
147
- const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
148
- return pnl.add((0, _1.calculatePositionPNL)(market, marketPosition, withFunding, this.getOracleDataForMarket(market.marketIndex)));
149
- }, numericConstants_1.ZERO);
150
- }
151
- /**
152
- * calculates unrealized position price pnl
153
- * @returns : Precision QUOTE_PRECISION
154
- */
155
- getUnsettledPNL(marketIndex) {
156
- return this.getUserAccount()
157
- .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
158
- .reduce((pnl, marketPosition) => {
159
- return pnl.add(marketPosition.unsettledPnl);
160
- }, numericConstants_1.ZERO);
161
- }
162
- /**
163
- * calculates unrealized funding payment pnl
164
- * @returns : Precision QUOTE_PRECISION
165
- */
166
- getUnrealizedFundingPNL(marketIndex) {
167
- return this.getUserAccount()
168
- .positions.filter((pos) => marketIndex ? pos.marketIndex === marketIndex : true)
169
- .reduce((pnl, marketPosition) => {
170
- const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
171
- return pnl.add((0, _1.calculatePositionFundingPNL)(market, marketPosition));
172
- }, numericConstants_1.ZERO);
173
- }
174
- getTotalLiability() {
175
- return this.getUserAccount().bankBalances.reduce((totalAssetValue, bankBalance) => {
176
- if (bankBalance.balance.eq(numericConstants_1.ZERO) ||
177
- (0, types_1.isVariant)(bankBalance.balanceType, 'deposit')) {
178
- return totalAssetValue;
179
- }
180
- // Todo this needs to account for whether it's based on initial or maintenance requirements
181
- const bankAccount = this.clearingHouse.getBankAccount(bankBalance.bankIndex);
182
- const tokenAmount = (0, bankBalance_1.getTokenAmount)(bankBalance.balance, bankAccount, bankBalance.balanceType);
183
- return totalAssetValue.add(tokenAmount
184
- .mul(this.getOracleDataForBank(bankAccount.bankIndex).price)
185
- .mul(bankAccount.initialLiabilityWeight)
186
- .div(numericConstants_1.BANK_WEIGHT_PRECISION)
187
- .div(numericConstants_1.MARK_PRICE_PRECISION));
188
- }, numericConstants_1.ZERO);
189
- }
190
- getCollateralValue(bankIndex) {
191
- return this.getUserAccount().bankBalances.reduce((totalAssetValue, bankBalance) => {
192
- if (bankBalance.balance.eq(numericConstants_1.ZERO) ||
193
- (bankIndex !== undefined && !bankBalance.bankIndex.eq(bankIndex))) {
194
- return totalAssetValue;
195
- }
196
- // Todo this needs to account for whether it's based on initial or maintenance requirements
197
- const bankAccount = this.clearingHouse.getBankAccount(bankBalance.bankIndex);
198
- let tokenAmount = (0, bankBalance_1.getTokenAmount)(bankBalance.balance, bankAccount, bankBalance.balanceType);
199
- if ((0, types_1.isVariant)(bankBalance.balanceType, 'borrow')) {
200
- tokenAmount = tokenAmount.mul(new _1.BN(-1));
201
- }
202
- return totalAssetValue.add(tokenAmount
203
- .mul(this.getOracleDataForBank(bankAccount.bankIndex).price)
204
- .div(numericConstants_1.MARK_PRICE_PRECISION));
205
- }, numericConstants_1.ZERO);
206
- }
207
- /**
208
- * calculates TotalCollateral: collateral + unrealized pnl
209
- * TODO: rename to total equity (for perpetuals swaps)
210
- * @returns : Precision QUOTE_PRECISION
211
- */
212
- getTotalCollateral() {
213
- return this.getUserAccount()
214
- .bankBalances.reduce((totalAssetValue, bankBalance) => {
215
- if (bankBalance.balance.eq(numericConstants_1.ZERO) ||
216
- (0, types_1.isVariant)(bankBalance.balanceType, 'borrow')) {
217
- return totalAssetValue;
218
- }
219
- // Todo this needs to account for whether it's based on initial or maintenance requirements
220
- const bankAccount = this.clearingHouse.getBankAccount(bankBalance.bankIndex);
221
- const tokenAmount = (0, bankBalance_1.getTokenAmount)(bankBalance.balance, bankAccount, bankBalance.balanceType);
222
- return totalAssetValue.add(tokenAmount
223
- .mul(this.getOracleDataForBank(bankAccount.bankIndex).price)
224
- .mul(bankAccount.initialAssetWeight)
225
- .div(numericConstants_1.BANK_WEIGHT_PRECISION)
226
- .div(numericConstants_1.MARK_PRICE_PRECISION));
227
- }, numericConstants_1.ZERO)
228
- .add(this.getUnrealizedPNL(true))
229
- .add(this.getUnsettledPNL());
230
- }
231
- /**
232
- * calculates sum of position value across all positions
233
- * @returns : Precision QUOTE_PRECISION
234
- */
235
- getTotalPositionValue() {
236
- return this.getUserAccount().positions.reduce((positionValue, marketPosition) => {
237
- const market = this.clearingHouse.getMarketAccount(marketPosition.marketIndex);
238
- return positionValue.add((0, _1.calculateBaseAssetValue)(market, marketPosition, this.getOracleDataForMarket(market.marketIndex)));
239
- }, numericConstants_1.ZERO);
240
- }
241
- /**
242
- * calculates position value from closing 100%
243
- * @returns : Precision QUOTE_PRECISION
244
- */
245
- getPositionValue(marketIndex, oraclePriceData) {
246
- const userPosition = this.getUserPosition(marketIndex) || this.getEmptyPosition(marketIndex);
247
- const market = this.clearingHouse.getMarketAccount(userPosition.marketIndex);
248
- return (0, _1.calculateBaseAssetValue)(market, userPosition, oraclePriceData);
249
- }
250
- getPositionSide(currentPosition) {
251
- if (currentPosition.baseAssetAmount.gt(numericConstants_1.ZERO)) {
252
- return _1.PositionDirection.LONG;
253
- }
254
- else if (currentPosition.baseAssetAmount.lt(numericConstants_1.ZERO)) {
255
- return _1.PositionDirection.SHORT;
256
- }
257
- else {
258
- return undefined;
259
- }
260
- }
261
- /**
262
- * calculates average exit price for closing 100% of position
263
- * @returns : Precision MARK_PRICE_PRECISION
264
- */
265
- getPositionEstimatedExitPriceAndPnl(position, amountToClose) {
266
- const market = this.clearingHouse.getMarketAccount(position.marketIndex);
267
- const entryPrice = (0, position_1.calculateEntryPrice)(position);
268
- const oraclePriceData = this.getOracleDataForMarket(position.marketIndex);
269
- if (amountToClose) {
270
- if (amountToClose.eq(numericConstants_1.ZERO)) {
271
- return [(0, _1.calculateMarkPrice)(market, oraclePriceData), numericConstants_1.ZERO];
272
- }
273
- position = {
274
- baseAssetAmount: amountToClose,
275
- lastCumulativeFundingRate: position.lastCumulativeFundingRate,
276
- marketIndex: position.marketIndex,
277
- quoteAssetAmount: position.quoteAssetAmount,
278
- };
279
- }
280
- const baseAssetValue = (0, _1.calculateBaseAssetValue)(market, position, oraclePriceData);
281
- if (position.baseAssetAmount.eq(numericConstants_1.ZERO)) {
282
- return [numericConstants_1.ZERO, numericConstants_1.ZERO];
283
- }
284
- const exitPrice = baseAssetValue
285
- .mul(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO)
286
- .mul(numericConstants_1.MARK_PRICE_PRECISION)
287
- .div(position.baseAssetAmount.abs());
288
- const pnlPerBase = exitPrice.sub(entryPrice);
289
- const pnl = pnlPerBase
290
- .mul(position.baseAssetAmount)
291
- .div(numericConstants_1.MARK_PRICE_PRECISION)
292
- .div(numericConstants_1.AMM_TO_QUOTE_PRECISION_RATIO);
293
- return [exitPrice, pnl];
294
- }
295
- /**
296
- * calculates current user leverage across all positions
297
- * @returns : Precision TEN_THOUSAND
298
- */
299
- getLeverage() {
300
- const totalCollateral = this.getTotalCollateral();
301
- const totalPositionValue = this.getTotalPositionValue();
302
- if (totalPositionValue.eq(numericConstants_1.ZERO) && totalCollateral.eq(numericConstants_1.ZERO)) {
303
- return numericConstants_1.ZERO;
304
- }
305
- return totalPositionValue.mul(numericConstants_1.TEN_THOUSAND).div(totalCollateral);
306
- }
307
- /**
308
- * calculates max allowable leverage exceeding hitting requirement category
309
- * @params category {Initial, Partial, Maintenance}
310
- * @returns : Precision TEN_THOUSAND
311
- */
312
- getMaxLeverage(marketIndex, category = 'Initial') {
313
- const market = this.clearingHouse.getMarketAccount(marketIndex);
314
- let marginRatioCategory;
315
- switch (category) {
316
- case 'Initial':
317
- marginRatioCategory = market.marginRatioInitial;
318
- break;
319
- case 'Maintenance':
320
- marginRatioCategory = market.marginRatioMaintenance;
321
- break;
322
- case 'Partial':
323
- marginRatioCategory = market.marginRatioPartial;
324
- break;
325
- default:
326
- marginRatioCategory = market.marginRatioInitial;
327
- break;
328
- }
329
- const maxLeverage = numericConstants_1.TEN_THOUSAND.mul(numericConstants_1.TEN_THOUSAND).div(new _1.BN(marginRatioCategory));
330
- return maxLeverage;
331
- }
332
- /**
333
- * calculates margin ratio: total collateral / |total position value|
334
- * @returns : Precision TEN_THOUSAND
335
- */
336
- getMarginRatio() {
337
- const totalPositionValue = this.getTotalPositionValue();
338
- if (totalPositionValue.eq(numericConstants_1.ZERO)) {
339
- return numericConstants_1.BN_MAX;
340
- }
341
- return this.getTotalCollateral().mul(numericConstants_1.TEN_THOUSAND).div(totalPositionValue);
342
- }
343
- canBeLiquidated() {
344
- const totalCollateral = this.getTotalCollateral();
345
- const partialMaintenanceRequirement = this.getPartialMarginRequirement();
346
- const marginRatio = this.getMarginRatio();
347
- const canLiquidate = totalCollateral.lt(partialMaintenanceRequirement);
348
- return [canLiquidate, marginRatio];
349
- }
350
- /**
351
- * Checks if any user position cumulative funding differs from respective market cumulative funding
352
- * @returns
353
- */
354
- needsToSettleFundingPayment() {
355
- for (const userPosition of this.getUserAccount().positions) {
356
- if (userPosition.baseAssetAmount.eq(numericConstants_1.ZERO)) {
357
- continue;
358
- }
359
- const market = this.clearingHouse.getMarketAccount(userPosition.marketIndex);
360
- if (market.amm.cumulativeFundingRateLong.eq(userPosition.lastCumulativeFundingRate) ||
361
- market.amm.cumulativeFundingRateShort.eq(userPosition.lastCumulativeFundingRate)) {
362
- continue;
363
- }
364
- return true;
365
- }
366
- return false;
367
- }
368
- /**
369
- * Calculate the liquidation price of a position, with optional parameter to calculate the liquidation price after a trade
370
- * @param marketPosition
371
- * @param positionBaseSizeChange // change in position size to calculate liquidation price for : Precision 10^13
372
- * @param partial
373
- * @returns Precision : MARK_PRICE_PRECISION
374
- */
375
- liquidationPrice(marketPosition, positionBaseSizeChange = numericConstants_1.ZERO, partial = false) {
376
- // solves formula for example canBeLiquidated below
377
- /* example: assume BTC price is $40k (examine 10% up/down)
378
-
379
- if 10k deposit and levered 10x short BTC => BTC up $400 means:
380
- 1. higher base_asset_value (+$4k)
381
- 2. lower collateral (-$4k)
382
- 3. (10k - 4k)/(100k + 4k) => 6k/104k => .0576
383
-
384
- for 10x long, BTC down $400:
385
- 3. (10k - 4k) / (100k - 4k) = 6k/96k => .0625 */
386
- const totalCollateral = this.getTotalCollateral();
387
- // calculate the total position value ignoring any value from the target market of the trade
388
- const totalPositionValueExcludingTargetMarket = this.getTotalPositionValueExcludingMarket(marketPosition.marketIndex);
389
- const currentMarketPosition = this.getUserPosition(marketPosition.marketIndex) ||
390
- this.getEmptyPosition(marketPosition.marketIndex);
391
- const currentMarketPositionBaseSize = currentMarketPosition.baseAssetAmount;
392
- const proposedBaseAssetAmount = currentMarketPositionBaseSize.add(positionBaseSizeChange);
393
- // calculate position for current market after trade
394
- const proposedMarketPosition = {
395
- marketIndex: marketPosition.marketIndex,
396
- baseAssetAmount: proposedBaseAssetAmount,
397
- lastCumulativeFundingRate: currentMarketPosition.lastCumulativeFundingRate,
398
- quoteAssetAmount: new _1.BN(0),
399
- quoteEntryAmount: new _1.BN(0),
400
- openOrders: new _1.BN(0),
401
- unsettledPnl: new _1.BN(0),
402
- openBids: new _1.BN(0),
403
- openAsks: new _1.BN(0),
404
- };
405
- if (proposedBaseAssetAmount.eq(numericConstants_1.ZERO))
406
- return new _1.BN(-1);
407
- const market = this.clearingHouse.getMarketAccount(proposedMarketPosition.marketIndex);
408
- const proposedMarketPositionValue = (0, _1.calculateBaseAssetValue)(market, proposedMarketPosition, this.getOracleDataForMarket(market.marketIndex));
409
- // total position value after trade
410
- const totalPositionValueAfterTrade = totalPositionValueExcludingTargetMarket.add(proposedMarketPositionValue);
411
- const marginRequirementExcludingTargetMarket = this.getUserAccount().positions.reduce((totalMarginRequirement, position) => {
412
- if (!position.marketIndex.eq(marketPosition.marketIndex)) {
413
- const market = this.clearingHouse.getMarketAccount(position.marketIndex);
414
- const positionValue = (0, _1.calculateBaseAssetValue)(market, position, this.getOracleDataForMarket(market.marketIndex));
415
- const marketMarginRequirement = positionValue
416
- .mul(partial
417
- ? new _1.BN(market.marginRatioPartial)
418
- : new _1.BN(market.marginRatioMaintenance))
419
- .div(numericConstants_1.MARGIN_PRECISION);
420
- totalMarginRequirement = totalMarginRequirement.add(marketMarginRequirement);
421
- }
422
- return totalMarginRequirement;
423
- }, numericConstants_1.ZERO);
424
- const freeCollateralExcludingTargetMarket = totalCollateral.sub(marginRequirementExcludingTargetMarket);
425
- // if the position value after the trade is less than free collateral, there is no liq price
426
- if (totalPositionValueAfterTrade.lte(freeCollateralExcludingTargetMarket) &&
427
- proposedMarketPosition.baseAssetAmount.abs().gt(numericConstants_1.ZERO)) {
428
- return new _1.BN(-1);
429
- }
430
- const marginRequirementAfterTrade = marginRequirementExcludingTargetMarket.add(proposedMarketPositionValue
431
- .mul(partial
432
- ? new _1.BN(market.marginRatioPartial)
433
- : new _1.BN(market.marginRatioMaintenance))
434
- .div(numericConstants_1.MARGIN_PRECISION));
435
- const freeCollateralAfterTrade = totalCollateral.sub(marginRequirementAfterTrade);
436
- const marketMaxLeverage = partial
437
- ? this.getMaxLeverage(proposedMarketPosition.marketIndex, 'Partial')
438
- : this.getMaxLeverage(proposedMarketPosition.marketIndex, 'Maintenance');
439
- let priceDelta;
440
- if (proposedBaseAssetAmount.lt(numericConstants_1.ZERO)) {
441
- priceDelta = freeCollateralAfterTrade
442
- .mul(marketMaxLeverage) // precision is TEN_THOUSAND
443
- .div(marketMaxLeverage.add(numericConstants_1.TEN_THOUSAND))
444
- .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
445
- .mul(numericConstants_1.AMM_RESERVE_PRECISION)
446
- .div(proposedBaseAssetAmount);
447
- }
448
- else {
449
- priceDelta = freeCollateralAfterTrade
450
- .mul(marketMaxLeverage) // precision is TEN_THOUSAND
451
- .div(marketMaxLeverage.sub(numericConstants_1.TEN_THOUSAND))
452
- .mul(numericConstants_1.PRICE_TO_QUOTE_PRECISION)
453
- .mul(numericConstants_1.AMM_RESERVE_PRECISION)
454
- .div(proposedBaseAssetAmount);
455
- }
456
- let markPriceAfterTrade;
457
- if (positionBaseSizeChange.eq(numericConstants_1.ZERO)) {
458
- markPriceAfterTrade = (0, _1.calculateMarkPrice)(this.clearingHouse.getMarketAccount(marketPosition.marketIndex), this.getOracleDataForMarket(marketPosition.marketIndex));
459
- }
460
- else {
461
- const direction = positionBaseSizeChange.gt(numericConstants_1.ZERO)
462
- ? _1.PositionDirection.LONG
463
- : _1.PositionDirection.SHORT;
464
- markPriceAfterTrade = (0, _1.calculateTradeSlippage)(direction, positionBaseSizeChange.abs(), this.clearingHouse.getMarketAccount(marketPosition.marketIndex), 'base', this.getOracleDataForMarket(marketPosition.marketIndex))[3]; // newPrice after swap
465
- }
466
- if (priceDelta.gt(markPriceAfterTrade)) {
467
- return new _1.BN(-1);
468
- }
469
- return markPriceAfterTrade.sub(priceDelta);
470
- }
471
- /**
472
- * Calculates the estimated liquidation price for a position after closing a quote amount of the position.
473
- * @param positionMarketIndex
474
- * @param closeQuoteAmount
475
- * @returns : Precision MARK_PRICE_PRECISION
476
- */
477
- liquidationPriceAfterClose(positionMarketIndex, closeQuoteAmount) {
478
- const currentPosition = this.getUserPosition(positionMarketIndex) ||
479
- this.getEmptyPosition(positionMarketIndex);
480
- const closeBaseAmount = currentPosition.baseAssetAmount
481
- .mul(closeQuoteAmount)
482
- .div(currentPosition.quoteAssetAmount)
483
- .add(currentPosition.baseAssetAmount
484
- .mul(closeQuoteAmount)
485
- .mod(currentPosition.quoteAssetAmount))
486
- .neg();
487
- return this.liquidationPrice({
488
- marketIndex: positionMarketIndex,
489
- }, closeBaseAmount, true);
490
- }
491
- /**
492
- * Get the maximum trade size for a given market, taking into account the user's current leverage, positions, collateral, etc.
493
- *
494
- * To Calculate Max Quote Available:
495
- *
496
- * Case 1: SameSide
497
- * => Remaining quote to get to maxLeverage
498
- *
499
- * Case 2: NOT SameSide && currentLeverage <= maxLeverage
500
- * => Current opposite position x2 + remaining to get to maxLeverage
501
- *
502
- * Case 3: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition > maxLeverage
503
- * => strictly reduce current position size
504
- *
505
- * Case 4: NOT SameSide && currentLeverage > maxLeverage && otherPositions - currentPosition < maxLeverage
506
- * => current position + remaining to get to maxLeverage
507
- *
508
- * @param targetMarketIndex
509
- * @param tradeSide
510
- * @returns tradeSizeAllowed : Precision QUOTE_PRECISION
511
- */
512
- getMaxTradeSizeUSDC(targetMarketIndex, tradeSide) {
513
- const currentPosition = this.getUserPosition(targetMarketIndex) ||
514
- this.getEmptyPosition(targetMarketIndex);
515
- const targetSide = (0, types_1.isVariant)(tradeSide, 'short') ? 'short' : 'long';
516
- const currentPositionSide = (currentPosition === null || currentPosition === void 0 ? void 0 : currentPosition.baseAssetAmount.isNeg())
517
- ? 'short'
518
- : 'long';
519
- const targetingSameSide = !currentPosition
520
- ? true
521
- : targetSide === currentPositionSide;
522
- const oracleData = this.getOracleDataForMarket(targetMarketIndex);
523
- // add any position we have on the opposite side of the current trade, because we can "flip" the size of this position without taking any extra leverage.
524
- const oppositeSizeValueUSDC = targetingSameSide
525
- ? numericConstants_1.ZERO
526
- : this.getPositionValue(targetMarketIndex, oracleData);
527
- let maxPositionSize = this.getBuyingPower(targetMarketIndex);
528
- if (maxPositionSize.gte(numericConstants_1.ZERO)) {
529
- if (oppositeSizeValueUSDC.eq(numericConstants_1.ZERO)) {
530
- // case 1 : Regular trade where current total position less than max, and no opposite position to account for
531
- // do nothing
532
- }
533
- else {
534
- // case 2 : trade where current total position less than max, but need to account for flipping the current position over to the other side
535
- maxPositionSize = maxPositionSize.add(oppositeSizeValueUSDC.mul(new _1.BN(2)));
536
- }
537
- }
538
- else {
539
- // current leverage is greater than max leverage - can only reduce position size
540
- if (!targetingSameSide) {
541
- const market = this.clearingHouse.getMarketAccount(targetMarketIndex);
542
- const marketPositionValue = this.getPositionValue(targetMarketIndex, oracleData);
543
- const totalCollateral = this.getTotalCollateral();
544
- const marginRequirement = this.getInitialMarginRequirement();
545
- const marginFreedByClosing = marketPositionValue
546
- .mul(new _1.BN(market.marginRatioInitial))
547
- .div(numericConstants_1.MARGIN_PRECISION);
548
- const marginRequirementAfterClosing = marginRequirement.sub(marginFreedByClosing);
549
- if (marginRequirementAfterClosing.gt(totalCollateral)) {
550
- maxPositionSize = marketPositionValue;
551
- }
552
- else {
553
- const freeCollateralAfterClose = totalCollateral.sub(marginRequirementAfterClosing);
554
- const buyingPowerAfterClose = freeCollateralAfterClose
555
- .mul(this.getMaxLeverage(targetMarketIndex))
556
- .div(numericConstants_1.TEN_THOUSAND);
557
- maxPositionSize = marketPositionValue.add(buyingPowerAfterClose);
558
- }
559
- }
560
- else {
561
- // do nothing if targetting same side
562
- }
563
- }
564
- // subtract oneMillionth of maxPositionSize
565
- // => to avoid rounding errors when taking max leverage
566
- const oneMilli = maxPositionSize.div(numericConstants_1.QUOTE_PRECISION);
567
- return maxPositionSize.sub(oneMilli);
568
- }
569
- // TODO - should this take the price impact of the trade into account for strict accuracy?
570
- /**
571
- * Returns the leverage ratio for the account after adding (or subtracting) the given quote size to the given position
572
- * @param targetMarketIndex
573
- * @param positionMarketIndex
574
- * @param tradeQuoteAmount
575
- * @returns leverageRatio : Precision TEN_THOUSAND
576
- */
577
- accountLeverageRatioAfterTrade(targetMarketIndex, tradeQuoteAmount, tradeSide) {
578
- const currentPosition = this.getUserPosition(targetMarketIndex) ||
579
- this.getEmptyPosition(targetMarketIndex);
580
- const oracleData = this.getOracleDataForMarket(targetMarketIndex);
581
- let currentPositionQuoteAmount = this.getPositionValue(targetMarketIndex, oracleData);
582
- const currentSide = currentPosition && currentPosition.baseAssetAmount.isNeg()
583
- ? _1.PositionDirection.SHORT
584
- : _1.PositionDirection.LONG;
585
- if (currentSide === _1.PositionDirection.SHORT)
586
- currentPositionQuoteAmount = currentPositionQuoteAmount.neg();
587
- if (tradeSide === _1.PositionDirection.SHORT)
588
- tradeQuoteAmount = tradeQuoteAmount.neg();
589
- const currentMarketPositionAfterTrade = currentPositionQuoteAmount
590
- .add(tradeQuoteAmount)
591
- .abs();
592
- const totalPositionAfterTradeExcludingTargetMarket = this.getTotalPositionValueExcludingMarket(targetMarketIndex);
593
- const totalCollateral = this.getTotalCollateral();
594
- if (totalCollateral.gt(numericConstants_1.ZERO)) {
595
- const newLeverage = currentMarketPositionAfterTrade
596
- .add(totalPositionAfterTradeExcludingTargetMarket)
597
- .abs()
598
- .mul(numericConstants_1.TEN_THOUSAND)
599
- .div(totalCollateral);
600
- return newLeverage;
601
- }
602
- else {
603
- return new _1.BN(0);
604
- }
605
- }
606
- /**
607
- * Calculates how much fee will be taken for a given sized trade
608
- * @param quoteAmount
609
- * @returns feeForQuote : Precision QUOTE_PRECISION
610
- */
611
- calculateFeeForQuoteAmount(quoteAmount) {
612
- const feeStructure = this.clearingHouse.getStateAccount().feeStructure;
613
- return quoteAmount
614
- .mul(feeStructure.feeNumerator)
615
- .div(feeStructure.feeDenominator);
616
- }
617
- /**
618
- * Get the total position value, excluding any position coming from the given target market
619
- * @param marketToIgnore
620
- * @returns positionValue : Precision QUOTE_PRECISION
621
- */
622
- getTotalPositionValueExcludingMarket(marketToIgnore) {
623
- const currentMarketPosition = this.getUserPosition(marketToIgnore) ||
624
- this.getEmptyPosition(marketToIgnore);
625
- const oracleData = this.getOracleDataForMarket(marketToIgnore);
626
- let currentMarketPositionValueUSDC = numericConstants_1.ZERO;
627
- if (currentMarketPosition) {
628
- currentMarketPositionValueUSDC = this.getPositionValue(marketToIgnore, oracleData);
629
- }
630
- return this.getTotalPositionValue().sub(currentMarketPositionValueUSDC);
631
- }
632
- getOracleDataForMarket(marketIndex) {
633
- const oracleKey = this.clearingHouse.getMarketAccount(marketIndex).amm.oracle;
634
- const oracleData = this.clearingHouse.getOraclePriceDataAndSlot(oracleKey).data;
635
- return oracleData;
636
- }
637
- getOracleDataForBank(bankIndex) {
638
- const oracleKey = this.clearingHouse.getBankAccount(bankIndex).oracle;
639
- const oracleData = this.clearingHouse.getOraclePriceDataAndSlot(oracleKey).data;
640
- return oracleData;
641
- }
642
- }
643
- exports.ClearingHouseUser = ClearingHouseUser;
@@ -1,14 +0,0 @@
1
- import { ClearingHouse } from './clearingHouse';
2
- import { PublicKey } from '@solana/web3.js';
3
- import { BulkAccountLoader } from './accounts/bulkAccountLoader';
4
- export declare type ClearingHouseUserConfig = {
5
- accountSubscription?: ClearingHouseUserAccountSubscriptionConfig;
6
- clearingHouse: ClearingHouse;
7
- userAccountPublicKey: PublicKey;
8
- };
9
- export declare type ClearingHouseUserAccountSubscriptionConfig = {
10
- type: 'websocket';
11
- } | {
12
- type: 'polling';
13
- accountLoader: BulkAccountLoader;
14
- };
@@ -1,16 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN, OracleSource } from '../';
3
- import { DriftEnv } from '../';
4
- import { PublicKey } from '@solana/web3.js';
5
- export declare type BankConfig = {
6
- symbol: string;
7
- bankIndex: BN;
8
- oracle: PublicKey;
9
- mint: PublicKey;
10
- oracleSource: OracleSource;
11
- };
12
- export declare const DevnetBanks: BankConfig[];
13
- export declare const MainnetBanks: BankConfig[];
14
- export declare const Banks: {
15
- [key in DriftEnv]: BankConfig[];
16
- };