@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
package/src/admin.ts DELETED
@@ -1,722 +0,0 @@
1
- import {
2
- PublicKey,
3
- SYSVAR_RENT_PUBKEY,
4
- TransactionSignature,
5
- } from '@solana/web3.js';
6
- import {
7
- FeeStructure,
8
- OracleGuardRails,
9
- OracleSource,
10
- OrderFillerRewardStructure,
11
- } from './types';
12
- import { BN } from '@project-serum/anchor';
13
- import * as anchor from '@project-serum/anchor';
14
- import {
15
- getClearingHouseStateAccountPublicKeyAndNonce,
16
- getBankVaultAuthorityPublicKey,
17
- getBankPublicKey,
18
- getBankVaultPublicKey,
19
- getMarketPublicKey,
20
- } from './addresses/pda';
21
- import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
22
- import { ClearingHouse } from './clearingHouse';
23
- import { PEG_PRECISION } from './constants/numericConstants';
24
- import { calculateTargetPriceTrade } from './math/trade';
25
- import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
26
-
27
- export class Admin extends ClearingHouse {
28
- public async initialize(
29
- usdcMint: PublicKey,
30
- adminControlsPrices: boolean
31
- ): Promise<[TransactionSignature]> {
32
- const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(
33
- await this.getStatePublicKey()
34
- );
35
- if (stateAccountRPCResponse.value !== null) {
36
- throw new Error('Clearing house already initialized');
37
- }
38
-
39
- const [insuranceVaultPublicKey] = await PublicKey.findProgramAddress(
40
- [Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))],
41
- this.program.programId
42
- );
43
-
44
- const [insuranceVaultAuthority] = await PublicKey.findProgramAddress(
45
- [insuranceVaultPublicKey.toBuffer()],
46
- this.program.programId
47
- );
48
-
49
- const [clearingHouseStatePublicKey] =
50
- await getClearingHouseStateAccountPublicKeyAndNonce(
51
- this.program.programId
52
- );
53
- const initializeTx = await this.program.transaction.initialize(
54
- adminControlsPrices,
55
- {
56
- accounts: {
57
- admin: this.wallet.publicKey,
58
- state: clearingHouseStatePublicKey,
59
- quoteAssetMint: usdcMint,
60
- insuranceVault: insuranceVaultPublicKey,
61
- insuranceVaultAuthority: insuranceVaultAuthority,
62
- rent: SYSVAR_RENT_PUBKEY,
63
- systemProgram: anchor.web3.SystemProgram.programId,
64
- tokenProgram: TOKEN_PROGRAM_ID,
65
- },
66
- }
67
- );
68
-
69
- const { txSig: initializeTxSig } = await this.txSender.send(
70
- initializeTx,
71
- [],
72
- this.opts
73
- );
74
-
75
- return [initializeTxSig];
76
- }
77
-
78
- public async initializeBank(
79
- mint: PublicKey,
80
- optimalUtilization: BN,
81
- optimalRate: BN,
82
- maxRate: BN,
83
- oracle: PublicKey,
84
- oracleSource: OracleSource,
85
- initialAssetWeight: BN,
86
- maintenanceAssetWeight: BN,
87
- initialLiabilityWeight: BN,
88
- maintenanceLiabilityWeight: BN
89
- ): Promise<TransactionSignature> {
90
- const bankIndex = this.getStateAccount().numberOfBanks;
91
- const bank = await getBankPublicKey(this.program.programId, bankIndex);
92
-
93
- const bankVault = await getBankVaultPublicKey(
94
- this.program.programId,
95
- bankIndex
96
- );
97
-
98
- const bankVaultAuthority = await getBankVaultAuthorityPublicKey(
99
- this.program.programId,
100
- bankIndex
101
- );
102
-
103
- const initializeTx = await this.program.transaction.initializeBank(
104
- optimalUtilization,
105
- optimalRate,
106
- maxRate,
107
- oracleSource,
108
- initialAssetWeight,
109
- maintenanceAssetWeight,
110
- initialLiabilityWeight,
111
- maintenanceLiabilityWeight,
112
- {
113
- accounts: {
114
- admin: this.wallet.publicKey,
115
- state: await this.getStatePublicKey(),
116
- bank,
117
- bankVault,
118
- bankVaultAuthority,
119
- bankMint: mint,
120
- oracle,
121
- rent: SYSVAR_RENT_PUBKEY,
122
- systemProgram: anchor.web3.SystemProgram.programId,
123
- tokenProgram: TOKEN_PROGRAM_ID,
124
- },
125
- }
126
- );
127
-
128
- const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
129
-
130
- await this.accountSubscriber.addBank(bankIndex);
131
- await this.accountSubscriber.addOracle({
132
- source: oracleSource,
133
- publicKey: oracle,
134
- });
135
-
136
- return txSig;
137
- }
138
-
139
- public async initializeMarket(
140
- priceOracle: PublicKey,
141
- baseAssetReserve: BN,
142
- quoteAssetReserve: BN,
143
- periodicity: BN,
144
- pegMultiplier: BN = PEG_PRECISION,
145
- oracleSource: OracleSource = OracleSource.PYTH,
146
- marginRatioInitial = 2000,
147
- marginRatioPartial = 625,
148
- marginRatioMaintenance = 500
149
- ): Promise<TransactionSignature> {
150
- const marketPublicKey = await getMarketPublicKey(
151
- this.program.programId,
152
- this.getStateAccount().numberOfMarkets
153
- );
154
-
155
- const initializeMarketTx = await this.program.transaction.initializeMarket(
156
- baseAssetReserve,
157
- quoteAssetReserve,
158
- periodicity,
159
- pegMultiplier,
160
- oracleSource,
161
- marginRatioInitial,
162
- marginRatioPartial,
163
- marginRatioMaintenance,
164
- {
165
- accounts: {
166
- state: await this.getStatePublicKey(),
167
- admin: this.wallet.publicKey,
168
- oracle: priceOracle,
169
- market: marketPublicKey,
170
- rent: SYSVAR_RENT_PUBKEY,
171
- systemProgram: anchor.web3.SystemProgram.programId,
172
- },
173
- }
174
- );
175
- const { txSig } = await this.txSender.send(
176
- initializeMarketTx,
177
- [],
178
- this.opts
179
- );
180
-
181
- await this.accountSubscriber.addMarket(
182
- this.getStateAccount().numberOfMarkets
183
- );
184
- await this.accountSubscriber.addOracle({
185
- source: oracleSource,
186
- publicKey: priceOracle,
187
- });
188
-
189
- return txSig;
190
- }
191
-
192
- public async moveAmmPrice(
193
- baseAssetReserve: BN,
194
- quoteAssetReserve: BN,
195
- marketIndex: BN
196
- ): Promise<TransactionSignature> {
197
- const marketPublicKey = await getMarketPublicKey(
198
- this.program.programId,
199
- marketIndex
200
- );
201
-
202
- return await this.program.rpc.moveAmmPrice(
203
- baseAssetReserve,
204
- quoteAssetReserve,
205
- {
206
- accounts: {
207
- state: await this.getStatePublicKey(),
208
- admin: this.wallet.publicKey,
209
- market: marketPublicKey,
210
- },
211
- }
212
- );
213
- }
214
-
215
- public async updateK(
216
- sqrtK: BN,
217
- marketIndex: BN
218
- ): Promise<TransactionSignature> {
219
- return await this.program.rpc.updateK(sqrtK, {
220
- accounts: {
221
- state: await this.getStatePublicKey(),
222
- admin: this.wallet.publicKey,
223
- market: await getMarketPublicKey(this.program.programId, marketIndex),
224
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
225
- },
226
- });
227
- }
228
-
229
- public async moveAmmToPrice(
230
- marketIndex: BN,
231
- targetPrice: BN
232
- ): Promise<TransactionSignature> {
233
- const market = this.getMarketAccount(marketIndex);
234
-
235
- const [direction, tradeSize, _] = calculateTargetPriceTrade(
236
- market,
237
- targetPrice,
238
- new BN(1000),
239
- 'quote',
240
- undefined //todo
241
- );
242
-
243
- const [newQuoteAssetAmount, newBaseAssetAmount] =
244
- calculateAmmReservesAfterSwap(
245
- market.amm,
246
- 'quote',
247
- tradeSize,
248
- getSwapDirection('quote', direction)
249
- );
250
-
251
- const marketPublicKey = await getMarketPublicKey(
252
- this.program.programId,
253
- marketIndex
254
- );
255
-
256
- return await this.program.rpc.moveAmmPrice(
257
- newBaseAssetAmount,
258
- newQuoteAssetAmount,
259
- {
260
- accounts: {
261
- state: await this.getStatePublicKey(),
262
- admin: this.wallet.publicKey,
263
- market: marketPublicKey,
264
- },
265
- }
266
- );
267
- }
268
-
269
- public async repegAmmCurve(
270
- newPeg: BN,
271
- marketIndex: BN
272
- ): Promise<TransactionSignature> {
273
- const marketPublicKey = await getMarketPublicKey(
274
- this.program.programId,
275
- marketIndex
276
- );
277
- const ammData = this.getMarketAccount(marketIndex).amm;
278
-
279
- return await this.program.rpc.repegAmmCurve(newPeg, {
280
- accounts: {
281
- state: await this.getStatePublicKey(),
282
- admin: this.wallet.publicKey,
283
- oracle: ammData.oracle,
284
- market: marketPublicKey,
285
- },
286
- });
287
- }
288
-
289
- public async updateAmmOracleTwap(
290
- marketIndex: BN
291
- ): Promise<TransactionSignature> {
292
- const ammData = this.getMarketAccount(marketIndex).amm;
293
- const marketPublicKey = await getMarketPublicKey(
294
- this.program.programId,
295
- marketIndex
296
- );
297
-
298
- return await this.program.rpc.updateAmmOracleTwap({
299
- accounts: {
300
- state: await this.getStatePublicKey(),
301
- admin: this.wallet.publicKey,
302
- oracle: ammData.oracle,
303
- market: marketPublicKey,
304
- },
305
- });
306
- }
307
-
308
- public async resetAmmOracleTwap(
309
- marketIndex: BN
310
- ): Promise<TransactionSignature> {
311
- const ammData = this.getMarketAccount(marketIndex).amm;
312
- const marketPublicKey = await getMarketPublicKey(
313
- this.program.programId,
314
- marketIndex
315
- );
316
-
317
- return await this.program.rpc.resetAmmOracleTwap({
318
- accounts: {
319
- state: await this.getStatePublicKey(),
320
- admin: this.wallet.publicKey,
321
- oracle: ammData.oracle,
322
- market: marketPublicKey,
323
- },
324
- });
325
- }
326
-
327
- public async withdrawFromInsuranceVault(
328
- amount: BN,
329
- recipient: PublicKey
330
- ): Promise<TransactionSignature> {
331
- const state = await this.getStateAccount();
332
- return await this.program.rpc.withdrawFromInsuranceVault(amount, {
333
- accounts: {
334
- admin: this.wallet.publicKey,
335
- state: await this.getStatePublicKey(),
336
- insuranceVault: state.insuranceVault,
337
- insuranceVaultAuthority: state.insuranceVaultAuthority,
338
- recipient: recipient,
339
- tokenProgram: TOKEN_PROGRAM_ID,
340
- },
341
- });
342
- }
343
-
344
- public async withdrawFees(
345
- marketIndex: BN,
346
- amount: BN,
347
- recipient: PublicKey
348
- ): Promise<TransactionSignature> {
349
- const marketPublicKey = await getMarketPublicKey(
350
- this.program.programId,
351
- marketIndex
352
- );
353
- const bank = this.getQuoteAssetBankAccount();
354
- return await this.program.rpc.withdrawFees(amount, {
355
- accounts: {
356
- admin: this.wallet.publicKey,
357
- state: await this.getStatePublicKey(),
358
- market: marketPublicKey,
359
- bank: bank.pubkey,
360
- bankVault: bank.vault,
361
- bankVaultAuthority: bank.vaultAuthority,
362
- recipient: recipient,
363
- tokenProgram: TOKEN_PROGRAM_ID,
364
- },
365
- });
366
- }
367
-
368
- public async withdrawFromInsuranceVaultToMarket(
369
- marketIndex: BN,
370
- amount: BN
371
- ): Promise<TransactionSignature> {
372
- const state = await this.getStateAccount();
373
- return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
374
- accounts: {
375
- admin: this.wallet.publicKey,
376
- state: await this.getStatePublicKey(),
377
- market: await getMarketPublicKey(this.program.programId, marketIndex),
378
- insuranceVault: state.insuranceVault,
379
- insuranceVaultAuthority: state.insuranceVaultAuthority,
380
- bankVault: this.getQuoteAssetBankAccount().vault,
381
- tokenProgram: TOKEN_PROGRAM_ID,
382
- },
383
- });
384
- }
385
-
386
- public async updateAdmin(admin: PublicKey): Promise<TransactionSignature> {
387
- return await this.program.rpc.updateAdmin(admin, {
388
- accounts: {
389
- admin: this.wallet.publicKey,
390
- state: await this.getStatePublicKey(),
391
- },
392
- });
393
- }
394
-
395
- public async updateCurveUpdateIntensity(
396
- marketIndex: BN,
397
- curveUpdateIntensity: number
398
- ): Promise<TransactionSignature> {
399
- // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
400
- // assert(Number.isInteger(curveUpdateIntensity));
401
-
402
- return await this.program.rpc.updateCurveUpdateIntensity(
403
- curveUpdateIntensity,
404
- {
405
- accounts: {
406
- admin: this.wallet.publicKey,
407
- state: await this.getStatePublicKey(),
408
- market: await getMarketPublicKey(this.program.programId, marketIndex),
409
- },
410
- }
411
- );
412
- }
413
-
414
- public async updateMarginRatio(
415
- marketIndex: BN,
416
- marginRatioInitial: number,
417
- marginRatioPartial: number,
418
- marginRatioMaintenance: number
419
- ): Promise<TransactionSignature> {
420
- return await this.program.rpc.updateMarginRatio(
421
- marginRatioInitial,
422
- marginRatioPartial,
423
- marginRatioMaintenance,
424
- {
425
- accounts: {
426
- admin: this.wallet.publicKey,
427
- state: await this.getStatePublicKey(),
428
- market: await getMarketPublicKey(this.program.programId, marketIndex),
429
- },
430
- }
431
- );
432
- }
433
-
434
- public async updateMarketBaseSpread(
435
- marketIndex: BN,
436
- baseSpread: number
437
- ): Promise<TransactionSignature> {
438
- return await this.program.rpc.updateMarketBaseSpread(baseSpread, {
439
- accounts: {
440
- admin: this.wallet.publicKey,
441
- state: await this.getStatePublicKey(),
442
- market: await getMarketPublicKey(this.program.programId, marketIndex),
443
- },
444
- });
445
- }
446
-
447
- public async updateMarketMaxSpread(
448
- marketIndex: BN,
449
- maxSpread: number
450
- ): Promise<TransactionSignature> {
451
- return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
452
- accounts: {
453
- admin: this.wallet.publicKey,
454
- state: await this.getStatePublicKey(),
455
- market: await getMarketPublicKey(this.program.programId, marketIndex),
456
- },
457
- });
458
- }
459
-
460
- public async updatePartialLiquidationClosePercentage(
461
- numerator: BN,
462
- denominator: BN
463
- ): Promise<TransactionSignature> {
464
- return await this.program.rpc.updatePartialLiquidationClosePercentage(
465
- numerator,
466
- denominator,
467
- {
468
- accounts: {
469
- admin: this.wallet.publicKey,
470
- state: await this.getStatePublicKey(),
471
- },
472
- }
473
- );
474
- }
475
-
476
- public async updatePartialLiquidationPenaltyPercentage(
477
- numerator: BN,
478
- denominator: BN
479
- ): Promise<TransactionSignature> {
480
- return await this.program.rpc.updatePartialLiquidationPenaltyPercentage(
481
- numerator,
482
- denominator,
483
- {
484
- accounts: {
485
- admin: this.wallet.publicKey,
486
- state: await this.getStatePublicKey(),
487
- },
488
- }
489
- );
490
- }
491
-
492
- public async updateFullLiquidationPenaltyPercentage(
493
- numerator: BN,
494
- denominator: BN
495
- ): Promise<TransactionSignature> {
496
- return await this.program.rpc.updateFullLiquidationPenaltyPercentage(
497
- numerator,
498
- denominator,
499
- {
500
- accounts: {
501
- admin: this.wallet.publicKey,
502
- state: await this.getStatePublicKey(),
503
- },
504
- }
505
- );
506
- }
507
-
508
- public async updatePartialLiquidationShareDenominator(
509
- denominator: BN
510
- ): Promise<TransactionSignature> {
511
- return await this.program.rpc.updatePartialLiquidationLiquidatorShareDenominator(
512
- denominator,
513
- {
514
- accounts: {
515
- admin: this.wallet.publicKey,
516
- state: await this.getStatePublicKey(),
517
- },
518
- }
519
- );
520
- }
521
-
522
- public async updateFullLiquidationShareDenominator(
523
- denominator: BN
524
- ): Promise<TransactionSignature> {
525
- return await this.program.rpc.updateFullLiquidationLiquidatorShareDenominator(
526
- denominator,
527
- {
528
- accounts: {
529
- admin: this.wallet.publicKey,
530
- state: await this.getStatePublicKey(),
531
- },
532
- }
533
- );
534
- }
535
-
536
- public async updateOrderFillerRewardStructure(
537
- orderFillerRewardStructure: OrderFillerRewardStructure
538
- ): Promise<TransactionSignature> {
539
- return await this.program.rpc.updateOrderFillerRewardStructure(
540
- orderFillerRewardStructure,
541
- {
542
- accounts: {
543
- admin: this.wallet.publicKey,
544
- state: await this.getStatePublicKey(),
545
- },
546
- }
547
- );
548
- }
549
-
550
- public async updateFee(fees: FeeStructure): Promise<TransactionSignature> {
551
- return await this.program.rpc.updateFee(fees, {
552
- accounts: {
553
- admin: this.wallet.publicKey,
554
- state: await this.getStatePublicKey(),
555
- },
556
- });
557
- }
558
-
559
- public async updateOracleGuardRails(
560
- oracleGuardRails: OracleGuardRails
561
- ): Promise<TransactionSignature> {
562
- return await this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
563
- accounts: {
564
- admin: this.wallet.publicKey,
565
- state: await this.getStatePublicKey(),
566
- },
567
- });
568
- }
569
-
570
- public async updateMarketOracle(
571
- marketIndex: BN,
572
- oracle: PublicKey,
573
- oracleSource: OracleSource
574
- ): Promise<TransactionSignature> {
575
- return await this.program.rpc.updateMarketOracle(oracle, oracleSource, {
576
- accounts: {
577
- admin: this.wallet.publicKey,
578
- state: await this.getStatePublicKey(),
579
- market: await getMarketPublicKey(this.program.programId, marketIndex),
580
- },
581
- });
582
- }
583
-
584
- public async updateMarketMinimumQuoteAssetTradeSize(
585
- marketIndex: BN,
586
- minimumTradeSize: BN
587
- ): Promise<TransactionSignature> {
588
- return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(
589
- minimumTradeSize,
590
- {
591
- accounts: {
592
- admin: this.wallet.publicKey,
593
- state: await this.getStatePublicKey(),
594
- market: await getMarketPublicKey(this.program.programId, marketIndex),
595
- },
596
- }
597
- );
598
- }
599
-
600
- public async updateMarketBaseAssetAmountStepSize(
601
- marketIndex: BN,
602
- stepSize: BN
603
- ): Promise<TransactionSignature> {
604
- return await this.program.rpc.updateMarketBaseAssetAmountStepSize(
605
- stepSize,
606
- {
607
- accounts: {
608
- admin: this.wallet.publicKey,
609
- state: await this.getStatePublicKey(),
610
- market: await getMarketPublicKey(this.program.programId, marketIndex),
611
- },
612
- }
613
- );
614
- }
615
-
616
- public async updateWhitelistMint(
617
- whitelistMint?: PublicKey
618
- ): Promise<TransactionSignature> {
619
- return await this.program.rpc.updateWhitelistMint(whitelistMint, {
620
- accounts: {
621
- admin: this.wallet.publicKey,
622
- state: await this.getStatePublicKey(),
623
- },
624
- });
625
- }
626
-
627
- public async updateDiscountMint(
628
- discountMint: PublicKey
629
- ): Promise<TransactionSignature> {
630
- return await this.program.rpc.updateDiscountMint(discountMint, {
631
- accounts: {
632
- admin: this.wallet.publicKey,
633
- state: await this.getStatePublicKey(),
634
- },
635
- });
636
- }
637
-
638
- public async updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature> {
639
- return await this.program.rpc.updateMaxDeposit(maxDeposit, {
640
- accounts: {
641
- admin: this.wallet.publicKey,
642
- state: await this.getStatePublicKey(),
643
- },
644
- });
645
- }
646
-
647
- public async updateFundingPaused(
648
- fundingPaused: boolean
649
- ): Promise<TransactionSignature> {
650
- return await this.program.rpc.updateFundingPaused(fundingPaused, {
651
- accounts: {
652
- admin: this.wallet.publicKey,
653
- state: await this.getStatePublicKey(),
654
- },
655
- });
656
- }
657
-
658
- public async updateExchangePaused(
659
- exchangePaused: boolean
660
- ): Promise<TransactionSignature> {
661
- return await this.program.rpc.updateExchangePaused(exchangePaused, {
662
- accounts: {
663
- admin: this.wallet.publicKey,
664
- state: await this.getStatePublicKey(),
665
- },
666
- });
667
- }
668
-
669
- public async disableAdminControlsPrices(): Promise<TransactionSignature> {
670
- return await this.program.rpc.disableAdminControlsPrices({
671
- accounts: {
672
- admin: this.wallet.publicKey,
673
- state: await this.getStatePublicKey(),
674
- },
675
- });
676
- }
677
-
678
- public async updateAuctionDuration(
679
- minDuration: BN | number,
680
- maxDuration: BN | number
681
- ): Promise<TransactionSignature> {
682
- return await this.program.rpc.updateAuctionDuration(
683
- typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
684
- typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
685
- {
686
- accounts: {
687
- admin: this.wallet.publicKey,
688
- state: await this.getStatePublicKey(),
689
- },
690
- }
691
- );
692
- }
693
-
694
- public async updateMaxBaseAssetAmountRatio(
695
- marketIndex: BN,
696
- maxBaseAssetAmountRatio: number
697
- ): Promise<TransactionSignature> {
698
- return await this.program.rpc.updateMaxBaseAssetAmountRatio(
699
- maxBaseAssetAmountRatio,
700
- {
701
- accounts: {
702
- admin: this.wallet.publicKey,
703
- state: await this.getStatePublicKey(),
704
- market: this.getMarketAccount(marketIndex).pubkey,
705
- },
706
- }
707
- );
708
- }
709
-
710
- public async updateMaxSlippageRatio(
711
- marketIndex: BN,
712
- maxSlippageRatio: number
713
- ): Promise<TransactionSignature> {
714
- return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
715
- accounts: {
716
- admin: this.wallet.publicKey,
717
- state: await this.getStatePublicKey(),
718
- market: this.getMarketAccount(marketIndex).pubkey,
719
- },
720
- });
721
- }
722
- }