@drift-labs/sdk 0.2.0-master.24 → 0.2.0-master.26

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 (193) hide show
  1. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +13 -13
  2. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
  3. package/lib/accounts/types.d.ts +8 -9
  4. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
  5. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
  6. package/lib/addresses/pda.d.ts +8 -6
  7. package/lib/addresses/pda.js +35 -27
  8. package/lib/admin.d.ts +9 -6
  9. package/lib/admin.js +90 -54
  10. package/lib/clearingHouse.d.ts +71 -42
  11. package/lib/clearingHouse.js +765 -282
  12. package/lib/clearingHouseConfig.d.ts +2 -2
  13. package/lib/clearingHouseUser.d.ts +19 -17
  14. package/lib/clearingHouseUser.js +145 -123
  15. package/lib/config.d.ts +7 -7
  16. package/lib/config.js +21 -21
  17. package/lib/constants/numericConstants.d.ts +12 -12
  18. package/lib/constants/numericConstants.js +13 -13
  19. package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
  20. package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
  21. package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
  22. package/lib/constants/{banks.js → spotMarkets.js} +16 -16
  23. package/lib/events/eventSubscriber.d.ts +4 -2
  24. package/lib/events/eventSubscriber.js +16 -9
  25. package/lib/events/fetchLogs.d.ts +10 -1
  26. package/lib/events/fetchLogs.js +27 -7
  27. package/lib/events/pollingLogProvider.d.ts +2 -1
  28. package/lib/events/pollingLogProvider.js +6 -2
  29. package/lib/events/types.d.ts +4 -2
  30. package/lib/events/types.js +2 -0
  31. package/lib/examples/makeTradeExample.js +18 -6
  32. package/lib/idl/clearing_house.json +1128 -347
  33. package/lib/index.d.ts +6 -3
  34. package/lib/index.js +6 -3
  35. package/lib/math/amm.d.ts +5 -3
  36. package/lib/math/amm.js +42 -4
  37. package/lib/math/funding.d.ts +6 -6
  38. package/lib/math/funding.js +2 -1
  39. package/lib/math/margin.d.ts +4 -4
  40. package/lib/math/margin.js +18 -11
  41. package/lib/math/market.d.ts +10 -9
  42. package/lib/math/market.js +29 -6
  43. package/lib/math/oracles.d.ts +2 -1
  44. package/lib/math/oracles.js +11 -1
  45. package/lib/math/orders.d.ts +5 -5
  46. package/lib/math/position.d.ts +13 -13
  47. package/lib/math/position.js +19 -19
  48. package/lib/math/spotBalance.d.ts +19 -0
  49. package/lib/math/spotBalance.js +176 -0
  50. package/lib/math/spotMarket.d.ts +4 -0
  51. package/lib/math/spotMarket.js +8 -0
  52. package/lib/math/spotPosition.d.ts +2 -0
  53. package/lib/math/spotPosition.js +8 -0
  54. package/lib/math/state.js +2 -2
  55. package/lib/math/trade.d.ts +4 -4
  56. package/lib/orderParams.d.ts +4 -4
  57. package/lib/orderParams.js +12 -4
  58. package/lib/serum/serumSubscriber.d.ts +23 -0
  59. package/lib/serum/serumSubscriber.js +41 -0
  60. package/lib/serum/types.d.ts +11 -0
  61. package/lib/serum/types.js +2 -0
  62. package/lib/tx/retryTxSender.d.ts +1 -1
  63. package/lib/tx/retryTxSender.js +4 -2
  64. package/lib/tx/types.d.ts +1 -1
  65. package/lib/types.d.ts +148 -39
  66. package/lib/types.js +37 -9
  67. package/my-script/.env +7 -0
  68. package/my-script/getUserStats.ts +106 -0
  69. package/my-script/multiConnections.ts +119 -0
  70. package/my-script/test-regex.ts +11 -0
  71. package/my-script/utils.ts +52 -0
  72. package/package.json +1 -1
  73. package/src/accounts/bulkAccountLoader.js +249 -0
  74. package/src/accounts/bulkUserStatsSubscription.js +75 -0
  75. package/src/accounts/bulkUserSubscription.js +75 -0
  76. package/src/accounts/fetch.js +92 -0
  77. package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
  78. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
  79. package/src/accounts/pollingOracleSubscriber.js +156 -0
  80. package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
  81. package/src/accounts/pollingUserAccountSubscriber.js +208 -0
  82. package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
  83. package/src/accounts/types.js +28 -0
  84. package/src/accounts/types.ts +11 -9
  85. package/src/accounts/utils.js +7 -0
  86. package/src/accounts/webSocketAccountSubscriber.js +138 -0
  87. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
  88. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
  89. package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
  90. package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
  91. package/src/addresses/pda.js +186 -0
  92. package/src/addresses/pda.ts +56 -42
  93. package/src/admin.js +1284 -0
  94. package/src/admin.ts +149 -75
  95. package/src/assert/assert.js +1 -1
  96. package/src/clearingHouse.js +3433 -0
  97. package/src/clearingHouse.ts +1097 -380
  98. package/src/clearingHouseConfig.js +2 -0
  99. package/src/clearingHouseConfig.ts +2 -2
  100. package/src/clearingHouseUser.js +874 -0
  101. package/src/clearingHouseUser.ts +237 -172
  102. package/src/clearingHouseUserConfig.js +2 -0
  103. package/src/clearingHouseUserStats.js +115 -0
  104. package/src/clearingHouseUserStatsConfig.js +2 -0
  105. package/src/config.js +80 -0
  106. package/src/config.ts +30 -30
  107. package/src/constants/numericConstants.js +18 -11
  108. package/src/constants/numericConstants.ts +17 -15
  109. package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
  110. package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
  111. package/src/constants/spotMarkets.js +51 -0
  112. package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
  113. package/src/events/eventList.js +66 -23
  114. package/src/events/eventSubscriber.js +202 -0
  115. package/src/events/eventSubscriber.ts +20 -12
  116. package/src/events/fetchLogs.js +117 -0
  117. package/src/events/fetchLogs.ts +35 -8
  118. package/src/events/pollingLogProvider.js +113 -0
  119. package/src/events/pollingLogProvider.ts +10 -2
  120. package/src/events/sort.js +41 -0
  121. package/src/events/txEventCache.js +22 -19
  122. package/src/events/types.js +25 -0
  123. package/src/events/types.ts +7 -1
  124. package/src/events/webSocketLogProvider.js +76 -0
  125. package/src/examples/makeTradeExample.ts +27 -6
  126. package/src/factory/bigNum.js +183 -180
  127. package/src/factory/oracleClient.js +9 -9
  128. package/src/idl/clearing_house.json +1128 -347
  129. package/src/index.js +75 -0
  130. package/src/index.ts +6 -3
  131. package/src/math/amm.js +422 -0
  132. package/src/math/amm.ts +73 -5
  133. package/src/math/auction.js +10 -10
  134. package/src/math/conversion.js +4 -3
  135. package/src/math/funding.js +223 -175
  136. package/src/math/funding.ts +7 -7
  137. package/src/math/insurance.js +27 -0
  138. package/src/math/margin.js +77 -0
  139. package/src/math/margin.ts +34 -23
  140. package/src/math/market.js +105 -0
  141. package/src/math/market.ts +71 -19
  142. package/src/math/oracles.js +40 -10
  143. package/src/math/oracles.ts +18 -1
  144. package/src/math/orders.js +153 -0
  145. package/src/math/orders.ts +5 -5
  146. package/src/math/position.js +172 -0
  147. package/src/math/position.ts +31 -31
  148. package/src/math/repeg.js +40 -40
  149. package/src/math/spotBalance.js +176 -0
  150. package/src/math/spotBalance.ts +290 -0
  151. package/src/math/spotMarket.js +8 -0
  152. package/src/math/spotMarket.ts +9 -0
  153. package/src/math/spotPosition.js +8 -0
  154. package/src/math/spotPosition.ts +6 -0
  155. package/src/math/state.ts +2 -2
  156. package/src/math/trade.js +81 -74
  157. package/src/math/trade.ts +4 -4
  158. package/src/math/utils.js +8 -7
  159. package/src/oracles/oracleClientCache.js +10 -9
  160. package/src/oracles/pythClient.js +52 -17
  161. package/src/oracles/quoteAssetOracleClient.js +44 -13
  162. package/src/oracles/switchboardClient.js +69 -37
  163. package/src/oracles/types.js +1 -1
  164. package/src/orderParams.js +14 -6
  165. package/src/orderParams.ts +16 -8
  166. package/src/serum/serumSubscriber.js +102 -0
  167. package/src/serum/serumSubscriber.ts +80 -0
  168. package/src/serum/types.js +2 -0
  169. package/src/serum/types.ts +13 -0
  170. package/src/slot/SlotSubscriber.js +67 -20
  171. package/src/token/index.js +4 -4
  172. package/src/tokenFaucet.js +288 -154
  173. package/src/tx/retryTxSender.js +280 -0
  174. package/src/tx/retryTxSender.ts +5 -2
  175. package/src/tx/types.js +1 -1
  176. package/src/tx/types.ts +2 -1
  177. package/src/tx/utils.js +7 -6
  178. package/src/types.js +216 -0
  179. package/src/types.ts +131 -39
  180. package/src/userName.js +5 -5
  181. package/src/util/computeUnits.js +46 -11
  182. package/src/util/promiseTimeout.js +5 -5
  183. package/src/util/tps.js +46 -12
  184. package/src/wallet.js +55 -18
  185. package/lib/math/bankBalance.d.ts +0 -15
  186. package/lib/math/bankBalance.js +0 -150
  187. package/src/addresses/marketAddresses.js +0 -26
  188. package/src/constants/banks.js +0 -42
  189. package/src/examples/makeTradeExample.js +0 -80
  190. package/src/math/bankBalance.ts +0 -258
  191. package/src/math/state.js +0 -15
  192. package/src/math/utils.js.map +0 -1
  193. package/src/util/getTokenAddress.js +0 -9
package/src/admin.ts CHANGED
@@ -13,13 +13,14 @@ import { BN } from '@project-serum/anchor';
13
13
  import * as anchor from '@project-serum/anchor';
14
14
  import {
15
15
  getClearingHouseStateAccountPublicKeyAndNonce,
16
- getBankVaultAuthorityPublicKey,
17
- getBankPublicKey,
18
- getBankVaultPublicKey,
16
+ getSpotMarketPublicKey,
17
+ getSpotMarketVaultPublicKey,
19
18
  getMarketPublicKey,
20
19
  getInsuranceFundVaultPublicKey,
21
- getInsuranceFundVaultAuthorityPublicKey,
20
+ getSerumOpenOrdersPublicKey,
21
+ getSerumFulfillmentConfigPublicKey,
22
22
  } from './addresses/pda';
23
+ import { squareRootBN } from './math/utils';
23
24
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
24
25
  import { ClearingHouse } from './clearingHouse';
25
26
  import { PEG_PRECISION, ZERO } from './constants/numericConstants';
@@ -38,20 +39,16 @@ export class Admin extends ClearingHouse {
38
39
  throw new Error('Clearing house already initialized');
39
40
  }
40
41
 
42
+ const [clearingHouseStatePublicKey] =
43
+ await getClearingHouseStateAccountPublicKeyAndNonce(
44
+ this.program.programId
45
+ );
46
+
41
47
  const [insuranceVaultPublicKey] = await PublicKey.findProgramAddress(
42
48
  [Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))],
43
49
  this.program.programId
44
50
  );
45
51
 
46
- const [insuranceVaultAuthority] = await PublicKey.findProgramAddress(
47
- [insuranceVaultPublicKey.toBuffer()],
48
- this.program.programId
49
- );
50
-
51
- const [clearingHouseStatePublicKey] =
52
- await getClearingHouseStateAccountPublicKeyAndNonce(
53
- this.program.programId
54
- );
55
52
  const initializeTx = await this.program.transaction.initialize(
56
53
  adminControlsPrices,
57
54
  {
@@ -59,9 +56,9 @@ export class Admin extends ClearingHouse {
59
56
  admin: this.wallet.publicKey,
60
57
  state: clearingHouseStatePublicKey,
61
58
  quoteAssetMint: usdcMint,
62
- insuranceVault: insuranceVaultPublicKey,
63
- insuranceVaultAuthority: insuranceVaultAuthority,
64
59
  rent: SYSVAR_RENT_PUBKEY,
60
+ insuranceVault: insuranceVaultPublicKey,
61
+ clearingHouseSigner: this.getSignerPublicKey(),
65
62
  systemProgram: anchor.web3.SystemProgram.programId,
66
63
  tokenProgram: TOKEN_PROGRAM_ID,
67
64
  },
@@ -77,7 +74,7 @@ export class Admin extends ClearingHouse {
77
74
  return [initializeTxSig];
78
75
  }
79
76
 
80
- public async initializeBank(
77
+ public async initializeSpotMarket(
81
78
  mint: PublicKey,
82
79
  optimalUtilization: BN,
83
80
  optimalRate: BN,
@@ -91,31 +88,23 @@ export class Admin extends ClearingHouse {
91
88
  imfFactor = new BN(0),
92
89
  liquidationFee = ZERO
93
90
  ): Promise<TransactionSignature> {
94
- const bankIndex = this.getStateAccount().numberOfBanks;
95
- const bank = await getBankPublicKey(this.program.programId, bankIndex);
96
-
97
- const bankVault = await getBankVaultPublicKey(
91
+ const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
92
+ const spotMarket = await getSpotMarketPublicKey(
98
93
  this.program.programId,
99
- bankIndex
94
+ spotMarketIndex
100
95
  );
101
96
 
102
- const bankVaultAuthority = await getBankVaultAuthorityPublicKey(
97
+ const spotMarketVault = await getSpotMarketVaultPublicKey(
103
98
  this.program.programId,
104
- bankIndex
99
+ spotMarketIndex
105
100
  );
106
101
 
107
102
  const insuranceFundVault = await getInsuranceFundVaultPublicKey(
108
103
  this.program.programId,
109
- bankIndex
104
+ spotMarketIndex
110
105
  );
111
106
 
112
- const insuranceFundVaultAuthority =
113
- await getInsuranceFundVaultAuthorityPublicKey(
114
- this.program.programId,
115
- bankIndex
116
- );
117
-
118
- const initializeTx = await this.program.transaction.initializeBank(
107
+ const initializeTx = await this.program.transaction.initializeSpotMarket(
119
108
  optimalUtilization,
120
109
  optimalRate,
121
110
  maxRate,
@@ -130,12 +119,11 @@ export class Admin extends ClearingHouse {
130
119
  accounts: {
131
120
  admin: this.wallet.publicKey,
132
121
  state: await this.getStatePublicKey(),
133
- bank,
134
- bankVault,
135
- bankVaultAuthority,
122
+ spotMarket,
123
+ spotMarketVault,
136
124
  insuranceFundVault,
137
- insuranceFundVaultAuthority,
138
- bankMint: mint,
125
+ clearingHouseSigner: this.getSignerPublicKey(),
126
+ spotMarketMint: mint,
139
127
  oracle,
140
128
  rent: SYSVAR_RENT_PUBKEY,
141
129
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -146,7 +134,7 @@ export class Admin extends ClearingHouse {
146
134
 
147
135
  const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
148
136
 
149
- await this.accountSubscriber.addBank(bankIndex);
137
+ await this.accountSubscriber.addSpotMarket(spotMarketIndex);
150
138
  await this.accountSubscriber.addOracle({
151
139
  source: oracleSource,
152
140
  publicKey: oracle,
@@ -155,6 +143,41 @@ export class Admin extends ClearingHouse {
155
143
  return txSig;
156
144
  }
157
145
 
146
+ public async initializeSerumFulfillmentConfig(
147
+ marketIndex: BN,
148
+ serumMarket: PublicKey,
149
+ serumProgram: PublicKey
150
+ ): Promise<TransactionSignature> {
151
+ const serumOpenOrders = getSerumOpenOrdersPublicKey(
152
+ this.program.programId,
153
+ serumMarket
154
+ );
155
+
156
+ const serumFulfillmentConfig = getSerumFulfillmentConfigPublicKey(
157
+ this.program.programId,
158
+ serumMarket
159
+ );
160
+
161
+ return await this.program.rpc.initializeSerumFulfillmentConfig(
162
+ marketIndex,
163
+ {
164
+ accounts: {
165
+ admin: this.wallet.publicKey,
166
+ state: await this.getStatePublicKey(),
167
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
168
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
169
+ clearingHouseSigner: this.getSignerPublicKey(),
170
+ serumProgram,
171
+ serumMarket,
172
+ serumOpenOrders,
173
+ rent: SYSVAR_RENT_PUBKEY,
174
+ systemProgram: anchor.web3.SystemProgram.programId,
175
+ serumFulfillmentConfig,
176
+ },
177
+ }
178
+ );
179
+ }
180
+
158
181
  public async initializeMarket(
159
182
  priceOracle: PublicKey,
160
183
  baseAssetReserve: BN,
@@ -197,7 +220,7 @@ export class Admin extends ClearingHouse {
197
220
  this.opts
198
221
  );
199
222
 
200
- await this.accountSubscriber.addMarket(
223
+ await this.accountSubscriber.addPerpMarket(
201
224
  this.getStateAccount().numberOfMarkets
202
225
  );
203
226
  await this.accountSubscriber.addOracle({
@@ -209,23 +232,29 @@ export class Admin extends ClearingHouse {
209
232
  }
210
233
 
211
234
  public async moveAmmPrice(
235
+ marketIndex: BN,
212
236
  baseAssetReserve: BN,
213
237
  quoteAssetReserve: BN,
214
- marketIndex: BN
238
+ sqrtK?: BN
215
239
  ): Promise<TransactionSignature> {
216
240
  const marketPublicKey = await getMarketPublicKey(
217
241
  this.program.programId,
218
242
  marketIndex
219
243
  );
220
244
 
245
+ if (sqrtK == undefined) {
246
+ sqrtK = squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
247
+ }
248
+
221
249
  return await this.program.rpc.moveAmmPrice(
222
250
  baseAssetReserve,
223
251
  quoteAssetReserve,
252
+ sqrtK,
224
253
  {
225
254
  accounts: {
226
255
  state: await this.getStatePublicKey(),
227
256
  admin: this.wallet.publicKey,
228
- market: marketPublicKey,
257
+ perpMarket: marketPublicKey,
229
258
  },
230
259
  }
231
260
  );
@@ -240,16 +269,16 @@ export class Admin extends ClearingHouse {
240
269
  state: await this.getStatePublicKey(),
241
270
  admin: this.wallet.publicKey,
242
271
  market: await getMarketPublicKey(this.program.programId, marketIndex),
243
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
272
+ oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
244
273
  },
245
274
  });
246
275
  }
247
276
 
248
277
  public async moveAmmToPrice(
249
- marketIndex: BN,
278
+ perpMarketIndex: BN,
250
279
  targetPrice: BN
251
280
  ): Promise<TransactionSignature> {
252
- const market = this.getMarketAccount(marketIndex);
281
+ const market = this.getPerpMarketAccount(perpMarketIndex);
253
282
 
254
283
  const [direction, tradeSize, _] = calculateTargetPriceTrade(
255
284
  market,
@@ -269,17 +298,18 @@ export class Admin extends ClearingHouse {
269
298
 
270
299
  const marketPublicKey = await getMarketPublicKey(
271
300
  this.program.programId,
272
- marketIndex
301
+ perpMarketIndex
273
302
  );
274
303
 
275
304
  return await this.program.rpc.moveAmmPrice(
276
305
  newBaseAssetAmount,
277
306
  newQuoteAssetAmount,
307
+ market.amm.sqrtK,
278
308
  {
279
309
  accounts: {
280
310
  state: await this.getStatePublicKey(),
281
311
  admin: this.wallet.publicKey,
282
- market: marketPublicKey,
312
+ perpMarket: marketPublicKey,
283
313
  },
284
314
  }
285
315
  );
@@ -293,7 +323,7 @@ export class Admin extends ClearingHouse {
293
323
  this.program.programId,
294
324
  marketIndex
295
325
  );
296
- const ammData = this.getMarketAccount(marketIndex).amm;
326
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
297
327
 
298
328
  return await this.program.rpc.repegAmmCurve(newPeg, {
299
329
  accounts: {
@@ -308,7 +338,7 @@ export class Admin extends ClearingHouse {
308
338
  public async updateAmmOracleTwap(
309
339
  marketIndex: BN
310
340
  ): Promise<TransactionSignature> {
311
- const ammData = this.getMarketAccount(marketIndex).amm;
341
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
312
342
  const marketPublicKey = await getMarketPublicKey(
313
343
  this.program.programId,
314
344
  marketIndex
@@ -327,7 +357,7 @@ export class Admin extends ClearingHouse {
327
357
  public async resetAmmOracleTwap(
328
358
  marketIndex: BN
329
359
  ): Promise<TransactionSignature> {
330
- const ammData = this.getMarketAccount(marketIndex).amm;
360
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
331
361
  const marketPublicKey = await getMarketPublicKey(
332
362
  this.program.programId,
333
363
  marketIndex
@@ -348,14 +378,14 @@ export class Admin extends ClearingHouse {
348
378
  recipient: PublicKey
349
379
  ): Promise<TransactionSignature> {
350
380
  const state = await this.getStateAccount();
351
- const bank = this.getQuoteAssetBankAccount();
381
+ const spotMarket = this.getQuoteSpotMarketAccount();
352
382
  return await this.program.rpc.withdrawFromInsuranceVault(amount, {
353
383
  accounts: {
354
384
  admin: this.wallet.publicKey,
355
385
  state: await this.getStatePublicKey(),
356
- bank: bank.pubkey,
386
+ spotMarket: spotMarket.pubkey,
357
387
  insuranceVault: state.insuranceVault,
358
- insuranceVaultAuthority: state.insuranceVaultAuthority,
388
+ clearingHouseSigner: this.getSignerPublicKey(),
359
389
  recipient: recipient,
360
390
  tokenProgram: TOKEN_PROGRAM_ID,
361
391
  },
@@ -371,15 +401,15 @@ export class Admin extends ClearingHouse {
371
401
  this.program.programId,
372
402
  marketIndex
373
403
  );
374
- const bank = this.getQuoteAssetBankAccount();
404
+ const spotMarket = this.getQuoteSpotMarketAccount();
375
405
  return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
376
406
  accounts: {
377
407
  admin: this.wallet.publicKey,
378
408
  state: await this.getStatePublicKey(),
379
409
  market: marketPublicKey,
380
- bank: bank.pubkey,
381
- bankVault: bank.vault,
382
- bankVaultAuthority: bank.vaultAuthority,
410
+ spotMarket: spotMarket.pubkey,
411
+ spotMarketVault: spotMarket.vault,
412
+ clearingHouseSigner: this.getSignerPublicKey(),
383
413
  recipient: recipient,
384
414
  tokenProgram: TOKEN_PROGRAM_ID,
385
415
  },
@@ -391,7 +421,7 @@ export class Admin extends ClearingHouse {
391
421
  amount: BN
392
422
  ): Promise<TransactionSignature> {
393
423
  const state = await this.getStateAccount();
394
- const bank = this.getQuoteAssetBankAccount();
424
+ const spotMarket = this.getQuoteSpotMarketAccount();
395
425
 
396
426
  return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
397
427
  accounts: {
@@ -399,10 +429,9 @@ export class Admin extends ClearingHouse {
399
429
  state: await this.getStatePublicKey(),
400
430
  market: await getMarketPublicKey(this.program.programId, marketIndex),
401
431
  insuranceVault: state.insuranceVault,
402
- insuranceVaultAuthority: state.insuranceVaultAuthority,
403
- bank: bank.pubkey,
404
- bankVault: bank.vault,
405
- bankVaultAuthority: bank.vaultAuthority,
432
+ clearingHouseSigner: this.getSignerPublicKey(),
433
+ quoteSpotMarket: spotMarket.pubkey,
434
+ spotMarketVault: spotMarket.vault,
406
435
  tokenProgram: TOKEN_PROGRAM_ID,
407
436
  },
408
437
  });
@@ -603,30 +632,33 @@ export class Admin extends ClearingHouse {
603
632
  });
604
633
  }
605
634
 
606
- public async updateBankWithdrawGuardThreshold(
607
- bankIndex: BN,
635
+ public async updateWithdrawGuardThreshold(
636
+ marketIndex: BN,
608
637
  withdrawGuardThreshold: BN
609
638
  ): Promise<TransactionSignature> {
610
- return await this.program.rpc.updateBankWithdrawGuardThreshold(
639
+ return await this.program.rpc.updateWithdrawGuardThreshold(
611
640
  withdrawGuardThreshold,
612
641
  {
613
642
  accounts: {
614
643
  admin: this.wallet.publicKey,
615
644
  state: await this.getStatePublicKey(),
616
- bank: await getBankPublicKey(this.program.programId, bankIndex),
645
+ spotMarket: await getSpotMarketPublicKey(
646
+ this.program.programId,
647
+ marketIndex
648
+ ),
617
649
  },
618
650
  }
619
651
  );
620
652
  }
621
653
 
622
- public async updateBankIfFactor(
623
- bankIndex: BN,
654
+ public async updateSpotMarketIfFactor(
655
+ marketIndex: BN,
624
656
  userIfFactor: BN,
625
657
  totalIfFactor: BN,
626
658
  liquidationIfFactor: BN
627
659
  ): Promise<TransactionSignature> {
628
- return await this.program.rpc.updateBankIfFactor(
629
- bankIndex,
660
+ return await this.program.rpc.updateSpotMarketIfFactor(
661
+ marketIndex,
630
662
  userIfFactor,
631
663
  totalIfFactor,
632
664
  liquidationIfFactor,
@@ -634,23 +666,29 @@ export class Admin extends ClearingHouse {
634
666
  accounts: {
635
667
  admin: this.wallet.publicKey,
636
668
  state: await this.getStatePublicKey(),
637
- bank: await getBankPublicKey(this.program.programId, bankIndex),
669
+ spotMarket: await getSpotMarketPublicKey(
670
+ this.program.programId,
671
+ marketIndex
672
+ ),
638
673
  },
639
674
  }
640
675
  );
641
676
  }
642
677
 
643
- public async updateBankInsuranceWithdrawEscrowPeriod(
644
- bankIndex: BN,
678
+ public async updateInsuranceWithdrawEscrowPeriod(
679
+ marketIndex: BN,
645
680
  insuranceWithdrawEscrowPeriod: BN
646
681
  ): Promise<TransactionSignature> {
647
- return await this.program.rpc.updateBankInsuranceWithdrawEscrowPeriod(
682
+ return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(
648
683
  insuranceWithdrawEscrowPeriod,
649
684
  {
650
685
  accounts: {
651
686
  admin: this.wallet.publicKey,
652
687
  state: await this.getStatePublicKey(),
653
- bank: await getBankPublicKey(this.program.programId, bankIndex),
688
+ spotMarket: await getSpotMarketPublicKey(
689
+ this.program.programId,
690
+ marketIndex
691
+ ),
654
692
  },
655
693
  }
656
694
  );
@@ -715,6 +753,22 @@ export class Admin extends ClearingHouse {
715
753
  );
716
754
  }
717
755
 
756
+ public async updateMarketExpiry(
757
+ perpMarketIndex: BN,
758
+ expiryTs: BN
759
+ ): Promise<TransactionSignature> {
760
+ return await this.program.rpc.updateMarketExpiry(expiryTs, {
761
+ accounts: {
762
+ admin: this.wallet.publicKey,
763
+ state: await this.getStatePublicKey(),
764
+ perpMarket: await getMarketPublicKey(
765
+ this.program.programId,
766
+ perpMarketIndex
767
+ ),
768
+ },
769
+ });
770
+ }
771
+
718
772
  public async updateWhitelistMint(
719
773
  whitelistMint?: PublicKey
720
774
  ): Promise<TransactionSignature> {
@@ -802,7 +856,7 @@ export class Admin extends ClearingHouse {
802
856
  accounts: {
803
857
  admin: this.wallet.publicKey,
804
858
  state: await this.getStatePublicKey(),
805
- market: this.getMarketAccount(marketIndex).pubkey,
859
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
806
860
  },
807
861
  }
808
862
  );
@@ -816,8 +870,28 @@ export class Admin extends ClearingHouse {
816
870
  accounts: {
817
871
  admin: this.wallet.publicKey,
818
872
  state: await this.getStatePublicKey(),
819
- market: this.getMarketAccount(marketIndex).pubkey,
873
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
820
874
  },
821
875
  });
822
876
  }
877
+
878
+ public async updateMarketMaxImbalances(
879
+ marketIndex: BN,
880
+ unrealizedMaxImbalance: BN,
881
+ maxRevenueWithdrawPerPeriod: BN,
882
+ quoteMaxInsurance: BN
883
+ ): Promise<TransactionSignature> {
884
+ return await this.program.rpc.updateMarketMaxImbalances(
885
+ unrealizedMaxImbalance,
886
+ maxRevenueWithdrawPerPeriod,
887
+ quoteMaxInsurance,
888
+ {
889
+ accounts: {
890
+ admin: this.wallet.publicKey,
891
+ state: await this.getStatePublicKey(),
892
+ market: await getMarketPublicKey(this.program.programId, marketIndex),
893
+ },
894
+ }
895
+ );
896
+ }
823
897
  }
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ exports.__esModule = true;
3
3
  exports.assert = void 0;
4
4
  function assert(condition, error) {
5
5
  if (!condition) {