@drift-labs/sdk 0.2.0-master.25 → 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 (184) 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 +7 -6
  7. package/lib/addresses/pda.js +31 -27
  8. package/lib/admin.d.ts +9 -6
  9. package/lib/admin.js +83 -42
  10. package/lib/clearingHouse.d.ts +69 -42
  11. package/lib/clearingHouse.js +753 -277
  12. package/lib/clearingHouseConfig.d.ts +2 -2
  13. package/lib/clearingHouseUser.d.ts +16 -16
  14. package/lib/clearingHouseUser.js +139 -119
  15. package/lib/config.d.ts +7 -7
  16. package/lib/config.js +20 -20
  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/types.d.ts +2 -1
  24. package/lib/events/types.js +1 -0
  25. package/lib/examples/makeTradeExample.js +7 -7
  26. package/lib/idl/clearing_house.json +1008 -279
  27. package/lib/index.d.ts +5 -3
  28. package/lib/index.js +5 -3
  29. package/lib/math/amm.d.ts +2 -2
  30. package/lib/math/amm.js +1 -1
  31. package/lib/math/funding.d.ts +6 -6
  32. package/lib/math/funding.js +2 -1
  33. package/lib/math/margin.d.ts +4 -4
  34. package/lib/math/margin.js +18 -11
  35. package/lib/math/market.d.ts +10 -9
  36. package/lib/math/market.js +29 -6
  37. package/lib/math/oracles.d.ts +2 -1
  38. package/lib/math/oracles.js +11 -1
  39. package/lib/math/orders.d.ts +5 -5
  40. package/lib/math/position.d.ts +13 -13
  41. package/lib/math/position.js +19 -19
  42. package/lib/math/spotBalance.d.ts +19 -0
  43. package/lib/math/spotBalance.js +176 -0
  44. package/lib/math/spotMarket.d.ts +4 -0
  45. package/lib/math/spotMarket.js +8 -0
  46. package/lib/math/spotPosition.d.ts +2 -0
  47. package/lib/math/spotPosition.js +8 -0
  48. package/lib/math/state.js +2 -2
  49. package/lib/math/trade.d.ts +4 -4
  50. package/lib/orderParams.d.ts +4 -4
  51. package/lib/orderParams.js +12 -4
  52. package/lib/serum/serumSubscriber.d.ts +23 -0
  53. package/lib/serum/serumSubscriber.js +41 -0
  54. package/lib/serum/types.d.ts +11 -0
  55. package/lib/serum/types.js +2 -0
  56. package/lib/tx/retryTxSender.d.ts +1 -1
  57. package/lib/tx/retryTxSender.js +4 -2
  58. package/lib/tx/types.d.ts +1 -1
  59. package/lib/types.d.ts +123 -33
  60. package/lib/types.js +31 -9
  61. package/my-script/.env +7 -0
  62. package/my-script/getUserStats.ts +106 -0
  63. package/my-script/multiConnections.ts +119 -0
  64. package/my-script/test-regex.ts +11 -0
  65. package/my-script/utils.ts +52 -0
  66. package/package.json +1 -1
  67. package/src/accounts/bulkAccountLoader.js +249 -0
  68. package/src/accounts/bulkUserStatsSubscription.js +75 -0
  69. package/src/accounts/bulkUserSubscription.js +75 -0
  70. package/src/accounts/fetch.js +92 -0
  71. package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
  72. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
  73. package/src/accounts/pollingOracleSubscriber.js +156 -0
  74. package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
  75. package/src/accounts/pollingUserAccountSubscriber.js +208 -0
  76. package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
  77. package/src/accounts/types.js +28 -0
  78. package/src/accounts/types.ts +11 -9
  79. package/src/accounts/utils.js +7 -0
  80. package/src/accounts/webSocketAccountSubscriber.js +138 -0
  81. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
  82. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
  83. package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
  84. package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
  85. package/src/addresses/pda.js +186 -0
  86. package/src/addresses/pda.ts +49 -44
  87. package/src/admin.js +1284 -0
  88. package/src/admin.ts +140 -47
  89. package/src/assert/assert.js +1 -1
  90. package/src/clearingHouse.js +3433 -0
  91. package/src/clearingHouse.ts +1083 -378
  92. package/src/clearingHouseConfig.js +2 -0
  93. package/src/clearingHouseConfig.ts +2 -2
  94. package/src/clearingHouseUser.js +874 -0
  95. package/src/clearingHouseUser.ts +232 -168
  96. package/src/clearingHouseUserConfig.js +2 -0
  97. package/src/clearingHouseUserStats.js +115 -0
  98. package/src/clearingHouseUserStatsConfig.js +2 -0
  99. package/src/config.js +80 -0
  100. package/src/config.ts +29 -29
  101. package/src/constants/numericConstants.js +18 -11
  102. package/src/constants/numericConstants.ts +17 -15
  103. package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
  104. package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
  105. package/src/constants/spotMarkets.js +51 -0
  106. package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
  107. package/src/events/eventList.js +66 -23
  108. package/src/events/eventSubscriber.js +202 -0
  109. package/src/events/fetchLogs.js +117 -0
  110. package/src/events/pollingLogProvider.js +113 -0
  111. package/src/events/sort.js +41 -0
  112. package/src/events/txEventCache.js +22 -19
  113. package/src/events/types.js +25 -0
  114. package/src/events/types.ts +3 -0
  115. package/src/events/webSocketLogProvider.js +76 -0
  116. package/src/examples/makeTradeExample.ts +10 -8
  117. package/src/factory/bigNum.js +183 -180
  118. package/src/factory/oracleClient.js +9 -9
  119. package/src/idl/clearing_house.json +1008 -279
  120. package/src/index.js +75 -0
  121. package/src/index.ts +5 -3
  122. package/src/math/amm.js +422 -0
  123. package/src/math/amm.ts +6 -3
  124. package/src/math/auction.js +10 -10
  125. package/src/math/conversion.js +4 -3
  126. package/src/math/funding.js +223 -175
  127. package/src/math/funding.ts +7 -7
  128. package/src/math/insurance.js +27 -0
  129. package/src/math/margin.js +77 -0
  130. package/src/math/margin.ts +34 -23
  131. package/src/math/market.js +105 -0
  132. package/src/math/market.ts +71 -19
  133. package/src/math/oracles.js +40 -10
  134. package/src/math/oracles.ts +18 -1
  135. package/src/math/orders.js +153 -0
  136. package/src/math/orders.ts +5 -5
  137. package/src/math/position.js +172 -0
  138. package/src/math/position.ts +31 -31
  139. package/src/math/repeg.js +40 -40
  140. package/src/math/spotBalance.js +176 -0
  141. package/src/math/spotBalance.ts +290 -0
  142. package/src/math/spotMarket.js +8 -0
  143. package/src/math/spotMarket.ts +9 -0
  144. package/src/math/spotPosition.js +8 -0
  145. package/src/math/spotPosition.ts +6 -0
  146. package/src/math/state.ts +2 -2
  147. package/src/math/trade.js +81 -74
  148. package/src/math/trade.ts +4 -4
  149. package/src/math/utils.js +8 -7
  150. package/src/oracles/oracleClientCache.js +10 -9
  151. package/src/oracles/pythClient.js +52 -17
  152. package/src/oracles/quoteAssetOracleClient.js +44 -13
  153. package/src/oracles/switchboardClient.js +69 -37
  154. package/src/oracles/types.js +1 -1
  155. package/src/orderParams.js +14 -6
  156. package/src/orderParams.ts +16 -8
  157. package/src/serum/serumSubscriber.js +102 -0
  158. package/src/serum/serumSubscriber.ts +80 -0
  159. package/src/serum/types.js +2 -0
  160. package/src/serum/types.ts +13 -0
  161. package/src/slot/SlotSubscriber.js +67 -20
  162. package/src/token/index.js +4 -4
  163. package/src/tokenFaucet.js +288 -154
  164. package/src/tx/retryTxSender.js +280 -0
  165. package/src/tx/retryTxSender.ts +5 -2
  166. package/src/tx/types.js +1 -1
  167. package/src/tx/types.ts +2 -1
  168. package/src/tx/utils.js +7 -6
  169. package/src/types.js +216 -0
  170. package/src/types.ts +110 -33
  171. package/src/userName.js +5 -5
  172. package/src/util/computeUnits.js +46 -11
  173. package/src/util/promiseTimeout.js +5 -5
  174. package/src/util/tps.js +46 -12
  175. package/src/wallet.js +55 -18
  176. package/lib/math/bankBalance.d.ts +0 -15
  177. package/lib/math/bankBalance.js +0 -150
  178. package/src/addresses/marketAddresses.js +0 -26
  179. package/src/constants/banks.js +0 -42
  180. package/src/examples/makeTradeExample.js +0 -80
  181. package/src/math/bankBalance.ts +0 -258
  182. package/src/math/state.js +0 -15
  183. package/src/math/utils.js.map +0 -1
  184. package/src/util/getTokenAddress.js +0 -9
package/src/admin.ts CHANGED
@@ -13,11 +13,14 @@ import { BN } from '@project-serum/anchor';
13
13
  import * as anchor from '@project-serum/anchor';
14
14
  import {
15
15
  getClearingHouseStateAccountPublicKeyAndNonce,
16
- getBankPublicKey,
17
- getBankVaultPublicKey,
16
+ getSpotMarketPublicKey,
17
+ getSpotMarketVaultPublicKey,
18
18
  getMarketPublicKey,
19
19
  getInsuranceFundVaultPublicKey,
20
+ getSerumOpenOrdersPublicKey,
21
+ getSerumFulfillmentConfigPublicKey,
20
22
  } from './addresses/pda';
23
+ import { squareRootBN } from './math/utils';
21
24
  import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
22
25
  import { ClearingHouse } from './clearingHouse';
23
26
  import { PEG_PRECISION, ZERO } from './constants/numericConstants';
@@ -71,7 +74,7 @@ export class Admin extends ClearingHouse {
71
74
  return [initializeTxSig];
72
75
  }
73
76
 
74
- public async initializeBank(
77
+ public async initializeSpotMarket(
75
78
  mint: PublicKey,
76
79
  optimalUtilization: BN,
77
80
  optimalRate: BN,
@@ -85,20 +88,23 @@ export class Admin extends ClearingHouse {
85
88
  imfFactor = new BN(0),
86
89
  liquidationFee = ZERO
87
90
  ): Promise<TransactionSignature> {
88
- const bankIndex = this.getStateAccount().numberOfBanks;
89
- const bank = await getBankPublicKey(this.program.programId, bankIndex);
91
+ const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
92
+ const spotMarket = await getSpotMarketPublicKey(
93
+ this.program.programId,
94
+ spotMarketIndex
95
+ );
90
96
 
91
- const bankVault = await getBankVaultPublicKey(
97
+ const spotMarketVault = await getSpotMarketVaultPublicKey(
92
98
  this.program.programId,
93
- bankIndex
99
+ spotMarketIndex
94
100
  );
95
101
 
96
102
  const insuranceFundVault = await getInsuranceFundVaultPublicKey(
97
103
  this.program.programId,
98
- bankIndex
104
+ spotMarketIndex
99
105
  );
100
106
 
101
- const initializeTx = await this.program.transaction.initializeBank(
107
+ const initializeTx = await this.program.transaction.initializeSpotMarket(
102
108
  optimalUtilization,
103
109
  optimalRate,
104
110
  maxRate,
@@ -113,11 +119,11 @@ export class Admin extends ClearingHouse {
113
119
  accounts: {
114
120
  admin: this.wallet.publicKey,
115
121
  state: await this.getStatePublicKey(),
116
- bank,
117
- bankVault,
122
+ spotMarket,
123
+ spotMarketVault,
118
124
  insuranceFundVault,
119
125
  clearingHouseSigner: this.getSignerPublicKey(),
120
- bankMint: mint,
126
+ spotMarketMint: mint,
121
127
  oracle,
122
128
  rent: SYSVAR_RENT_PUBKEY,
123
129
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -128,7 +134,7 @@ export class Admin extends ClearingHouse {
128
134
 
129
135
  const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
130
136
 
131
- await this.accountSubscriber.addBank(bankIndex);
137
+ await this.accountSubscriber.addSpotMarket(spotMarketIndex);
132
138
  await this.accountSubscriber.addOracle({
133
139
  source: oracleSource,
134
140
  publicKey: oracle,
@@ -137,6 +143,41 @@ export class Admin extends ClearingHouse {
137
143
  return txSig;
138
144
  }
139
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
+
140
181
  public async initializeMarket(
141
182
  priceOracle: PublicKey,
142
183
  baseAssetReserve: BN,
@@ -179,7 +220,7 @@ export class Admin extends ClearingHouse {
179
220
  this.opts
180
221
  );
181
222
 
182
- await this.accountSubscriber.addMarket(
223
+ await this.accountSubscriber.addPerpMarket(
183
224
  this.getStateAccount().numberOfMarkets
184
225
  );
185
226
  await this.accountSubscriber.addOracle({
@@ -191,23 +232,29 @@ export class Admin extends ClearingHouse {
191
232
  }
192
233
 
193
234
  public async moveAmmPrice(
235
+ marketIndex: BN,
194
236
  baseAssetReserve: BN,
195
237
  quoteAssetReserve: BN,
196
- marketIndex: BN
238
+ sqrtK?: BN
197
239
  ): Promise<TransactionSignature> {
198
240
  const marketPublicKey = await getMarketPublicKey(
199
241
  this.program.programId,
200
242
  marketIndex
201
243
  );
202
244
 
245
+ if (sqrtK == undefined) {
246
+ sqrtK = squareRootBN(baseAssetReserve.mul(quoteAssetReserve));
247
+ }
248
+
203
249
  return await this.program.rpc.moveAmmPrice(
204
250
  baseAssetReserve,
205
251
  quoteAssetReserve,
252
+ sqrtK,
206
253
  {
207
254
  accounts: {
208
255
  state: await this.getStatePublicKey(),
209
256
  admin: this.wallet.publicKey,
210
- market: marketPublicKey,
257
+ perpMarket: marketPublicKey,
211
258
  },
212
259
  }
213
260
  );
@@ -222,16 +269,16 @@ export class Admin extends ClearingHouse {
222
269
  state: await this.getStatePublicKey(),
223
270
  admin: this.wallet.publicKey,
224
271
  market: await getMarketPublicKey(this.program.programId, marketIndex),
225
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
272
+ oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
226
273
  },
227
274
  });
228
275
  }
229
276
 
230
277
  public async moveAmmToPrice(
231
- marketIndex: BN,
278
+ perpMarketIndex: BN,
232
279
  targetPrice: BN
233
280
  ): Promise<TransactionSignature> {
234
- const market = this.getMarketAccount(marketIndex);
281
+ const market = this.getPerpMarketAccount(perpMarketIndex);
235
282
 
236
283
  const [direction, tradeSize, _] = calculateTargetPriceTrade(
237
284
  market,
@@ -251,17 +298,18 @@ export class Admin extends ClearingHouse {
251
298
 
252
299
  const marketPublicKey = await getMarketPublicKey(
253
300
  this.program.programId,
254
- marketIndex
301
+ perpMarketIndex
255
302
  );
256
303
 
257
304
  return await this.program.rpc.moveAmmPrice(
258
305
  newBaseAssetAmount,
259
306
  newQuoteAssetAmount,
307
+ market.amm.sqrtK,
260
308
  {
261
309
  accounts: {
262
310
  state: await this.getStatePublicKey(),
263
311
  admin: this.wallet.publicKey,
264
- market: marketPublicKey,
312
+ perpMarket: marketPublicKey,
265
313
  },
266
314
  }
267
315
  );
@@ -275,7 +323,7 @@ export class Admin extends ClearingHouse {
275
323
  this.program.programId,
276
324
  marketIndex
277
325
  );
278
- const ammData = this.getMarketAccount(marketIndex).amm;
326
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
279
327
 
280
328
  return await this.program.rpc.repegAmmCurve(newPeg, {
281
329
  accounts: {
@@ -290,7 +338,7 @@ export class Admin extends ClearingHouse {
290
338
  public async updateAmmOracleTwap(
291
339
  marketIndex: BN
292
340
  ): Promise<TransactionSignature> {
293
- const ammData = this.getMarketAccount(marketIndex).amm;
341
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
294
342
  const marketPublicKey = await getMarketPublicKey(
295
343
  this.program.programId,
296
344
  marketIndex
@@ -309,7 +357,7 @@ export class Admin extends ClearingHouse {
309
357
  public async resetAmmOracleTwap(
310
358
  marketIndex: BN
311
359
  ): Promise<TransactionSignature> {
312
- const ammData = this.getMarketAccount(marketIndex).amm;
360
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
313
361
  const marketPublicKey = await getMarketPublicKey(
314
362
  this.program.programId,
315
363
  marketIndex
@@ -330,12 +378,12 @@ export class Admin extends ClearingHouse {
330
378
  recipient: PublicKey
331
379
  ): Promise<TransactionSignature> {
332
380
  const state = await this.getStateAccount();
333
- const bank = this.getQuoteAssetBankAccount();
381
+ const spotMarket = this.getQuoteSpotMarketAccount();
334
382
  return await this.program.rpc.withdrawFromInsuranceVault(amount, {
335
383
  accounts: {
336
384
  admin: this.wallet.publicKey,
337
385
  state: await this.getStatePublicKey(),
338
- bank: bank.pubkey,
386
+ spotMarket: spotMarket.pubkey,
339
387
  insuranceVault: state.insuranceVault,
340
388
  clearingHouseSigner: this.getSignerPublicKey(),
341
389
  recipient: recipient,
@@ -353,14 +401,14 @@ export class Admin extends ClearingHouse {
353
401
  this.program.programId,
354
402
  marketIndex
355
403
  );
356
- const bank = this.getQuoteAssetBankAccount();
404
+ const spotMarket = this.getQuoteSpotMarketAccount();
357
405
  return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
358
406
  accounts: {
359
407
  admin: this.wallet.publicKey,
360
408
  state: await this.getStatePublicKey(),
361
409
  market: marketPublicKey,
362
- bank: bank.pubkey,
363
- bankVault: bank.vault,
410
+ spotMarket: spotMarket.pubkey,
411
+ spotMarketVault: spotMarket.vault,
364
412
  clearingHouseSigner: this.getSignerPublicKey(),
365
413
  recipient: recipient,
366
414
  tokenProgram: TOKEN_PROGRAM_ID,
@@ -373,7 +421,7 @@ export class Admin extends ClearingHouse {
373
421
  amount: BN
374
422
  ): Promise<TransactionSignature> {
375
423
  const state = await this.getStateAccount();
376
- const bank = this.getQuoteAssetBankAccount();
424
+ const spotMarket = this.getQuoteSpotMarketAccount();
377
425
 
378
426
  return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
379
427
  accounts: {
@@ -382,8 +430,8 @@ export class Admin extends ClearingHouse {
382
430
  market: await getMarketPublicKey(this.program.programId, marketIndex),
383
431
  insuranceVault: state.insuranceVault,
384
432
  clearingHouseSigner: this.getSignerPublicKey(),
385
- bank: bank.pubkey,
386
- bankVault: bank.vault,
433
+ quoteSpotMarket: spotMarket.pubkey,
434
+ spotMarketVault: spotMarket.vault,
387
435
  tokenProgram: TOKEN_PROGRAM_ID,
388
436
  },
389
437
  });
@@ -584,30 +632,33 @@ export class Admin extends ClearingHouse {
584
632
  });
585
633
  }
586
634
 
587
- public async updateBankWithdrawGuardThreshold(
588
- bankIndex: BN,
635
+ public async updateWithdrawGuardThreshold(
636
+ marketIndex: BN,
589
637
  withdrawGuardThreshold: BN
590
638
  ): Promise<TransactionSignature> {
591
- return await this.program.rpc.updateBankWithdrawGuardThreshold(
639
+ return await this.program.rpc.updateWithdrawGuardThreshold(
592
640
  withdrawGuardThreshold,
593
641
  {
594
642
  accounts: {
595
643
  admin: this.wallet.publicKey,
596
644
  state: await this.getStatePublicKey(),
597
- bank: await getBankPublicKey(this.program.programId, bankIndex),
645
+ spotMarket: await getSpotMarketPublicKey(
646
+ this.program.programId,
647
+ marketIndex
648
+ ),
598
649
  },
599
650
  }
600
651
  );
601
652
  }
602
653
 
603
- public async updateBankIfFactor(
604
- bankIndex: BN,
654
+ public async updateSpotMarketIfFactor(
655
+ marketIndex: BN,
605
656
  userIfFactor: BN,
606
657
  totalIfFactor: BN,
607
658
  liquidationIfFactor: BN
608
659
  ): Promise<TransactionSignature> {
609
- return await this.program.rpc.updateBankIfFactor(
610
- bankIndex,
660
+ return await this.program.rpc.updateSpotMarketIfFactor(
661
+ marketIndex,
611
662
  userIfFactor,
612
663
  totalIfFactor,
613
664
  liquidationIfFactor,
@@ -615,23 +666,29 @@ export class Admin extends ClearingHouse {
615
666
  accounts: {
616
667
  admin: this.wallet.publicKey,
617
668
  state: await this.getStatePublicKey(),
618
- bank: await getBankPublicKey(this.program.programId, bankIndex),
669
+ spotMarket: await getSpotMarketPublicKey(
670
+ this.program.programId,
671
+ marketIndex
672
+ ),
619
673
  },
620
674
  }
621
675
  );
622
676
  }
623
677
 
624
- public async updateBankInsuranceWithdrawEscrowPeriod(
625
- bankIndex: BN,
678
+ public async updateInsuranceWithdrawEscrowPeriod(
679
+ marketIndex: BN,
626
680
  insuranceWithdrawEscrowPeriod: BN
627
681
  ): Promise<TransactionSignature> {
628
- return await this.program.rpc.updateBankInsuranceWithdrawEscrowPeriod(
682
+ return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(
629
683
  insuranceWithdrawEscrowPeriod,
630
684
  {
631
685
  accounts: {
632
686
  admin: this.wallet.publicKey,
633
687
  state: await this.getStatePublicKey(),
634
- bank: await getBankPublicKey(this.program.programId, bankIndex),
688
+ spotMarket: await getSpotMarketPublicKey(
689
+ this.program.programId,
690
+ marketIndex
691
+ ),
635
692
  },
636
693
  }
637
694
  );
@@ -696,6 +753,22 @@ export class Admin extends ClearingHouse {
696
753
  );
697
754
  }
698
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
+
699
772
  public async updateWhitelistMint(
700
773
  whitelistMint?: PublicKey
701
774
  ): Promise<TransactionSignature> {
@@ -783,7 +856,7 @@ export class Admin extends ClearingHouse {
783
856
  accounts: {
784
857
  admin: this.wallet.publicKey,
785
858
  state: await this.getStatePublicKey(),
786
- market: this.getMarketAccount(marketIndex).pubkey,
859
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
787
860
  },
788
861
  }
789
862
  );
@@ -797,8 +870,28 @@ export class Admin extends ClearingHouse {
797
870
  accounts: {
798
871
  admin: this.wallet.publicKey,
799
872
  state: await this.getStatePublicKey(),
800
- market: this.getMarketAccount(marketIndex).pubkey,
873
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
801
874
  },
802
875
  });
803
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
+ }
804
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) {