@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/lib/admin.js CHANGED
@@ -29,6 +29,7 @@ const types_1 = require("./types");
29
29
  const anchor_1 = require("@project-serum/anchor");
30
30
  const anchor = __importStar(require("@project-serum/anchor"));
31
31
  const pda_1 = require("./addresses/pda");
32
+ const utils_1 = require("./math/utils");
32
33
  const spl_token_1 = require("@solana/spl-token");
33
34
  const clearingHouse_1 = require("./clearingHouse");
34
35
  const numericConstants_1 = require("./constants/numericConstants");
@@ -40,17 +41,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
40
41
  if (stateAccountRPCResponse.value !== null) {
41
42
  throw new Error('Clearing house already initialized');
42
43
  }
43
- const [insuranceVaultPublicKey] = await web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
44
- const [insuranceVaultAuthority] = await web3_js_1.PublicKey.findProgramAddress([insuranceVaultPublicKey.toBuffer()], this.program.programId);
45
44
  const [clearingHouseStatePublicKey] = await (0, pda_1.getClearingHouseStateAccountPublicKeyAndNonce)(this.program.programId);
45
+ const [insuranceVaultPublicKey] = await web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
46
46
  const initializeTx = await this.program.transaction.initialize(adminControlsPrices, {
47
47
  accounts: {
48
48
  admin: this.wallet.publicKey,
49
49
  state: clearingHouseStatePublicKey,
50
50
  quoteAssetMint: usdcMint,
51
- insuranceVault: insuranceVaultPublicKey,
52
- insuranceVaultAuthority: insuranceVaultAuthority,
53
51
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
52
+ insuranceVault: insuranceVaultPublicKey,
53
+ clearingHouseSigner: this.getSignerPublicKey(),
54
54
  systemProgram: anchor.web3.SystemProgram.programId,
55
55
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
56
56
  },
@@ -58,23 +58,20 @@ class Admin extends clearingHouse_1.ClearingHouse {
58
58
  const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
59
59
  return [initializeTxSig];
60
60
  }
61
- async initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
62
- const bankIndex = this.getStateAccount().numberOfBanks;
63
- const bank = await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex);
64
- const bankVault = await (0, pda_1.getBankVaultPublicKey)(this.program.programId, bankIndex);
65
- const bankVaultAuthority = await (0, pda_1.getBankVaultAuthorityPublicKey)(this.program.programId, bankIndex);
66
- const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, bankIndex);
67
- const insuranceFundVaultAuthority = await (0, pda_1.getInsuranceFundVaultAuthorityPublicKey)(this.program.programId, bankIndex);
68
- const initializeTx = await this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
61
+ async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
62
+ const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
63
+ const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
64
+ const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
65
+ const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
66
+ const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
69
67
  accounts: {
70
68
  admin: this.wallet.publicKey,
71
69
  state: await this.getStatePublicKey(),
72
- bank,
73
- bankVault,
74
- bankVaultAuthority,
70
+ spotMarket,
71
+ spotMarketVault,
75
72
  insuranceFundVault,
76
- insuranceFundVaultAuthority,
77
- bankMint: mint,
73
+ clearingHouseSigner: this.getSignerPublicKey(),
74
+ spotMarketMint: mint,
78
75
  oracle,
79
76
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
80
77
  systemProgram: anchor.web3.SystemProgram.programId,
@@ -82,13 +79,32 @@ class Admin extends clearingHouse_1.ClearingHouse {
82
79
  },
83
80
  });
84
81
  const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
85
- await this.accountSubscriber.addBank(bankIndex);
82
+ await this.accountSubscriber.addSpotMarket(spotMarketIndex);
86
83
  await this.accountSubscriber.addOracle({
87
84
  source: oracleSource,
88
85
  publicKey: oracle,
89
86
  });
90
87
  return txSig;
91
88
  }
89
+ async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
90
+ const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
91
+ const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
92
+ return await this.program.rpc.initializeSerumFulfillmentConfig(marketIndex, {
93
+ accounts: {
94
+ admin: this.wallet.publicKey,
95
+ state: await this.getStatePublicKey(),
96
+ baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
97
+ quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
98
+ clearingHouseSigner: this.getSignerPublicKey(),
99
+ serumProgram,
100
+ serumMarket,
101
+ serumOpenOrders,
102
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
103
+ systemProgram: anchor.web3.SystemProgram.programId,
104
+ serumFulfillmentConfig,
105
+ },
106
+ });
107
+ }
92
108
  async initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO) {
93
109
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
94
110
  const initializeMarketTx = await this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, {
@@ -102,20 +118,23 @@ class Admin extends clearingHouse_1.ClearingHouse {
102
118
  },
103
119
  });
104
120
  const { txSig } = await this.txSender.send(initializeMarketTx, [], this.opts);
105
- await this.accountSubscriber.addMarket(this.getStateAccount().numberOfMarkets);
121
+ await this.accountSubscriber.addPerpMarket(this.getStateAccount().numberOfMarkets);
106
122
  await this.accountSubscriber.addOracle({
107
123
  source: oracleSource,
108
124
  publicKey: priceOracle,
109
125
  });
110
126
  return txSig;
111
127
  }
112
- async moveAmmPrice(baseAssetReserve, quoteAssetReserve, marketIndex) {
128
+ async moveAmmPrice(marketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
113
129
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
114
- return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, {
130
+ if (sqrtK == undefined) {
131
+ sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
132
+ }
133
+ return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
115
134
  accounts: {
116
135
  state: await this.getStatePublicKey(),
117
136
  admin: this.wallet.publicKey,
118
- market: marketPublicKey,
137
+ perpMarket: marketPublicKey,
119
138
  },
120
139
  });
121
140
  }
@@ -125,27 +144,27 @@ class Admin extends clearingHouse_1.ClearingHouse {
125
144
  state: await this.getStatePublicKey(),
126
145
  admin: this.wallet.publicKey,
127
146
  market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
128
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
147
+ oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
129
148
  },
130
149
  });
131
150
  }
132
- async moveAmmToPrice(marketIndex, targetPrice) {
133
- const market = this.getMarketAccount(marketIndex);
151
+ async moveAmmToPrice(perpMarketIndex, targetPrice) {
152
+ const market = this.getPerpMarketAccount(perpMarketIndex);
134
153
  const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
135
154
  );
136
155
  const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
137
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
138
- return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
156
+ const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex);
157
+ return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, market.amm.sqrtK, {
139
158
  accounts: {
140
159
  state: await this.getStatePublicKey(),
141
160
  admin: this.wallet.publicKey,
142
- market: marketPublicKey,
161
+ perpMarket: marketPublicKey,
143
162
  },
144
163
  });
145
164
  }
146
165
  async repegAmmCurve(newPeg, marketIndex) {
147
166
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
148
- const ammData = this.getMarketAccount(marketIndex).amm;
167
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
149
168
  return await this.program.rpc.repegAmmCurve(newPeg, {
150
169
  accounts: {
151
170
  state: await this.getStatePublicKey(),
@@ -156,7 +175,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
156
175
  });
157
176
  }
158
177
  async updateAmmOracleTwap(marketIndex) {
159
- const ammData = this.getMarketAccount(marketIndex).amm;
178
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
160
179
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
161
180
  return await this.program.rpc.updateAmmOracleTwap({
162
181
  accounts: {
@@ -168,7 +187,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
168
187
  });
169
188
  }
170
189
  async resetAmmOracleTwap(marketIndex) {
171
- const ammData = this.getMarketAccount(marketIndex).amm;
190
+ const ammData = this.getPerpMarketAccount(marketIndex).amm;
172
191
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
173
192
  return await this.program.rpc.resetAmmOracleTwap({
174
193
  accounts: {
@@ -181,14 +200,14 @@ class Admin extends clearingHouse_1.ClearingHouse {
181
200
  }
182
201
  async withdrawFromInsuranceVault(amount, recipient) {
183
202
  const state = await this.getStateAccount();
184
- const bank = this.getQuoteAssetBankAccount();
203
+ const spotMarket = this.getQuoteSpotMarketAccount();
185
204
  return await this.program.rpc.withdrawFromInsuranceVault(amount, {
186
205
  accounts: {
187
206
  admin: this.wallet.publicKey,
188
207
  state: await this.getStatePublicKey(),
189
- bank: bank.pubkey,
208
+ spotMarket: spotMarket.pubkey,
190
209
  insuranceVault: state.insuranceVault,
191
- insuranceVaultAuthority: state.insuranceVaultAuthority,
210
+ clearingHouseSigner: this.getSignerPublicKey(),
192
211
  recipient: recipient,
193
212
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
194
213
  },
@@ -196,15 +215,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
196
215
  }
197
216
  async withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
198
217
  const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
199
- const bank = this.getQuoteAssetBankAccount();
218
+ const spotMarket = this.getQuoteSpotMarketAccount();
200
219
  return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
201
220
  accounts: {
202
221
  admin: this.wallet.publicKey,
203
222
  state: await this.getStatePublicKey(),
204
223
  market: marketPublicKey,
205
- bank: bank.pubkey,
206
- bankVault: bank.vault,
207
- bankVaultAuthority: bank.vaultAuthority,
224
+ spotMarket: spotMarket.pubkey,
225
+ spotMarketVault: spotMarket.vault,
226
+ clearingHouseSigner: this.getSignerPublicKey(),
208
227
  recipient: recipient,
209
228
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
210
229
  },
@@ -212,17 +231,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
212
231
  }
213
232
  async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
214
233
  const state = await this.getStateAccount();
215
- const bank = this.getQuoteAssetBankAccount();
234
+ const spotMarket = this.getQuoteSpotMarketAccount();
216
235
  return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
217
236
  accounts: {
218
237
  admin: this.wallet.publicKey,
219
238
  state: await this.getStatePublicKey(),
220
239
  market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
221
240
  insuranceVault: state.insuranceVault,
222
- insuranceVaultAuthority: state.insuranceVaultAuthority,
223
- bank: bank.pubkey,
224
- bankVault: bank.vault,
225
- bankVaultAuthority: bank.vaultAuthority,
241
+ clearingHouseSigner: this.getSignerPublicKey(),
242
+ quoteSpotMarket: spotMarket.pubkey,
243
+ spotMarketVault: spotMarket.vault,
226
244
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
227
245
  },
228
246
  });
@@ -346,30 +364,30 @@ class Admin extends clearingHouse_1.ClearingHouse {
346
364
  },
347
365
  });
348
366
  }
349
- async updateBankWithdrawGuardThreshold(bankIndex, withdrawGuardThreshold) {
350
- return await this.program.rpc.updateBankWithdrawGuardThreshold(withdrawGuardThreshold, {
367
+ async updateWithdrawGuardThreshold(marketIndex, withdrawGuardThreshold) {
368
+ return await this.program.rpc.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
351
369
  accounts: {
352
370
  admin: this.wallet.publicKey,
353
371
  state: await this.getStatePublicKey(),
354
- bank: await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex),
372
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
355
373
  },
356
374
  });
357
375
  }
358
- async updateBankIfFactor(bankIndex, userIfFactor, totalIfFactor, liquidationIfFactor) {
359
- return await this.program.rpc.updateBankIfFactor(bankIndex, userIfFactor, totalIfFactor, liquidationIfFactor, {
376
+ async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor) {
377
+ return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor, {
360
378
  accounts: {
361
379
  admin: this.wallet.publicKey,
362
380
  state: await this.getStatePublicKey(),
363
- bank: await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex),
381
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
364
382
  },
365
383
  });
366
384
  }
367
- async updateBankInsuranceWithdrawEscrowPeriod(bankIndex, insuranceWithdrawEscrowPeriod) {
368
- return await this.program.rpc.updateBankInsuranceWithdrawEscrowPeriod(insuranceWithdrawEscrowPeriod, {
385
+ async updateInsuranceWithdrawEscrowPeriod(marketIndex, insuranceWithdrawEscrowPeriod) {
386
+ return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(insuranceWithdrawEscrowPeriod, {
369
387
  accounts: {
370
388
  admin: this.wallet.publicKey,
371
389
  state: await this.getStatePublicKey(),
372
- bank: await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex),
390
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
373
391
  },
374
392
  });
375
393
  }
@@ -409,6 +427,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
409
427
  },
410
428
  });
411
429
  }
430
+ async updateMarketExpiry(perpMarketIndex, expiryTs) {
431
+ return await this.program.rpc.updateMarketExpiry(expiryTs, {
432
+ accounts: {
433
+ admin: this.wallet.publicKey,
434
+ state: await this.getStatePublicKey(),
435
+ perpMarket: await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex),
436
+ },
437
+ });
438
+ }
412
439
  async updateWhitelistMint(whitelistMint) {
413
440
  return await this.program.rpc.updateWhitelistMint(whitelistMint, {
414
441
  accounts: {
@@ -470,7 +497,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
470
497
  accounts: {
471
498
  admin: this.wallet.publicKey,
472
499
  state: await this.getStatePublicKey(),
473
- market: this.getMarketAccount(marketIndex).pubkey,
500
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
474
501
  },
475
502
  });
476
503
  }
@@ -479,7 +506,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
479
506
  accounts: {
480
507
  admin: this.wallet.publicKey,
481
508
  state: await this.getStatePublicKey(),
482
- market: this.getMarketAccount(marketIndex).pubkey,
509
+ market: this.getPerpMarketAccount(marketIndex).pubkey,
510
+ },
511
+ });
512
+ }
513
+ async updateMarketMaxImbalances(marketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
514
+ return await this.program.rpc.updateMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
515
+ accounts: {
516
+ admin: this.wallet.publicKey,
517
+ state: await this.getStatePublicKey(),
518
+ market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
483
519
  },
484
520
  });
485
521
  }
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo } from './types';
5
- import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, SerumV3FulfillmentConfigAccount } from './types';
5
+ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta } from '@solana/web3.js';
6
6
  import { TokenFaucet } from './tokenFaucet';
7
7
  import { EventEmitter } from 'events';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
@@ -47,12 +47,15 @@ export declare class ClearingHouse {
47
47
  unsubscribeUsers(): Promise<void>[];
48
48
  statePublicKey?: PublicKey;
49
49
  getStatePublicKey(): Promise<PublicKey>;
50
+ signerPublicKey?: PublicKey;
51
+ getSignerPublicKey(): PublicKey;
50
52
  getStateAccount(): StateAccount;
51
- getMarketAccount(marketIndex: BN | number): MarketAccount | undefined;
52
- getMarketAccounts(): MarketAccount[];
53
- getBankAccount(bankIndex: BN | number): BankAccount | undefined;
54
- getQuoteAssetBankAccount(): BankAccount;
53
+ getPerpMarketAccount(marketIndex: BN | number): PerpMarketAccount | undefined;
54
+ getPerpMarketAccounts(): PerpMarketAccount[];
55
+ getSpotMarketAccount(marketIndex: BN | number): SpotMarketAccount | undefined;
56
+ getQuoteSpotMarketAccount(): SpotMarketAccount;
55
57
  getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
58
+ getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
56
59
  /**
57
60
  * Update the wallet to use for clearing house transactions and linked user account
58
61
  * @param newWallet
@@ -65,6 +68,7 @@ export declare class ClearingHouse {
65
68
  initializeUserAccount(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
66
69
  getInitializeUserInstructions(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
67
70
  getInitializeUserStatsIx(): Promise<TransactionInstruction>;
71
+ updateUserName(name: string, userId?: number): Promise<TransactionSignature>;
68
72
  getUser(userId?: number): ClearingHouseUser;
69
73
  getUsers(): ClearingHouseUser[];
70
74
  getUserStats(): ClearingHouseUserStats;
@@ -73,17 +77,18 @@ export declare class ClearingHouse {
73
77
  getUserAccountPublicKey(): Promise<PublicKey>;
74
78
  getUserAccount(userId?: number): UserAccount | undefined;
75
79
  getUserAccountAndSlot(userId?: number): DataAndSlot<UserAccount> | undefined;
76
- getUserBankBalance(bankIndex: number | BN): UserBankBalance | undefined;
80
+ getSpotPosition(marketIndex: number | BN): SpotPosition | undefined;
77
81
  getQuoteAssetTokenAmount(): BN;
78
82
  getRemainingAccounts(params: {
79
- writableMarketIndex?: BN;
80
- writableBankIndex?: BN;
81
- readableMarketIndex?: BN;
83
+ writablePerpMarketIndex?: BN;
84
+ writableSpotMarketIndex?: BN;
85
+ readablePerpMarketIndex?: BN;
86
+ readableSpotMarketIndex?: BN;
82
87
  }): AccountMeta[];
83
88
  getOrder(orderId: BN | number): Order | undefined;
84
89
  getOrderByUserId(userOrderId: number): Order | undefined;
85
- deposit(amount: BN, bankIndex: BN, collateralAccountPublicKey: PublicKey, userId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
86
- getDepositInstruction(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, userId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
90
+ deposit(amount: BN, marketIndex: BN, collateralAccountPublicKey: PublicKey, userId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
91
+ getDepositInstruction(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, userId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
87
92
  private checkIfAccountExists;
88
93
  private getSolWithdrawalIxs;
89
94
  private getWrappedSolAccountCreationIxs;
@@ -91,20 +96,20 @@ export declare class ClearingHouse {
91
96
  * Creates the Clearing House User account for a user, and deposits some initial collateral
92
97
  * @param amount
93
98
  * @param userTokenAccount
94
- * @param bankIndex
99
+ * @param marketIndex
95
100
  * @param userId
96
101
  * @param name
97
102
  * @param fromUserId
98
103
  * @returns
99
104
  */
100
- initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, bankIndex?: BN, userId?: number, name?: string, fromUserId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
101
- initializeUserAccountForDevnet(userId: number, name: string, bankIndex: BN, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
102
- withdraw(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
103
- getWithdrawIx(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
104
- transferDeposit(amount: BN, bankIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionSignature>;
105
- getTransferDepositIx(amount: BN, bankIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionInstruction>;
106
- updateBankCumulativeInterest(bankIndex: BN): Promise<TransactionSignature>;
107
- updateBankCumulativeInterestIx(bankIndex: BN): Promise<TransactionInstruction>;
105
+ initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: BN, userId?: number, name?: string, fromUserId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
106
+ initializeUserAccountForDevnet(userId: number, name: string, marketIndex: BN, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
107
+ withdraw(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
108
+ getWithdrawIx(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
109
+ transferDeposit(amount: BN, marketIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionSignature>;
110
+ getTransferDepositIx(amount: BN, marketIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionInstruction>;
111
+ updateSpotMarketCumulativeInterest(marketIndex: BN): Promise<TransactionSignature>;
112
+ updateSpotMarketCumulativeInterestIx(marketIndex: BN): Promise<TransactionInstruction>;
108
113
  settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
109
114
  settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
110
115
  removeLiquidity(marketIndex: BN, sharesToBurn?: BN): Promise<TransactionSignature>;
@@ -112,19 +117,39 @@ export declare class ClearingHouse {
112
117
  addLiquidity(amount: BN, marketIndex: BN): Promise<TransactionSignature>;
113
118
  getAddLiquidityIx(amount: BN, marketIndex: BN): Promise<TransactionInstruction>;
114
119
  openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
120
+ sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
121
+ /**
122
+ * Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
123
+ * @param orderParams
124
+ * @param userAccountPublicKey
125
+ * @param userAccount
126
+ * @returns
127
+ */
128
+ sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<{
129
+ txSig: TransactionSignature;
130
+ signedFillTx: Transaction;
131
+ }>;
115
132
  placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
116
- getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams;
133
+ getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
117
134
  getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
118
135
  updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
119
136
  getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
137
+ settleExpiredMarket(marketIndex: BN): Promise<TransactionSignature>;
138
+ getSettleExpiredMarketIx(marketIndex: BN): Promise<TransactionInstruction>;
120
139
  cancelOrder(orderId?: BN): Promise<TransactionSignature>;
121
140
  getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
122
141
  cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
123
142
  getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
124
143
  fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
125
- getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
144
+ getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
145
+ placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
146
+ getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
147
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
148
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
126
149
  triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
127
150
  getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
151
+ triggerSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
152
+ getTriggerSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
128
153
  placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
129
154
  getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
130
155
  placeAndMake(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
@@ -141,22 +166,24 @@ export declare class ClearingHouse {
141
166
  }[], marketIndex: BN): Promise<TransactionSignature>;
142
167
  settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
143
168
  settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
169
+ settleExpiredPosition(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
170
+ getSettleExpiredPositionIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
144
171
  liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN, maxBaseAssetAmount: BN): Promise<TransactionSignature>;
145
172
  getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN, maxBaseAssetAmount: BN): Promise<TransactionInstruction>;
146
- liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetBankIndex: BN, liabilityBankIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
147
- getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetBankIndex: BN, liabilityBankIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
148
- liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilityBankIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
149
- getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilityBankIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
150
- liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetBankIndex: BN, maxPnlTransfer: BN): Promise<TransactionSignature>;
151
- getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetBankIndex: BN, maxPnlTransfer: BN): Promise<TransactionInstruction>;
152
- resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, bankIndex: BN, marketIndex: BN): Promise<TransactionSignature>;
153
- getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, bankIndex: BN, marketIndex: BN): Promise<TransactionInstruction>;
154
- resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, bankIndex: BN): Promise<TransactionSignature>;
155
- getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, bankIndex: BN): Promise<TransactionInstruction>;
173
+ liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetmarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
174
+ getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetmarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
175
+ liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
176
+ getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
177
+ liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetMarketIndex: BN, maxPnlTransfer: BN): Promise<TransactionSignature>;
178
+ getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetMarketIndex: BN, maxPnlTransfer: BN): Promise<TransactionInstruction>;
179
+ resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
180
+ getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
181
+ resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
182
+ getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
156
183
  getRemainingAccountsWithCounterparty(params: {
157
184
  counterPartyUserAccount: UserAccount;
158
- writableMarketIndex?: BN;
159
- writableBankIndexes?: BN[];
185
+ writablePerpMarketIndex?: BN;
186
+ writableSpotMarketIndexes?: BN[];
160
187
  }): AccountMeta[];
161
188
  updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
162
189
  getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
@@ -164,11 +191,13 @@ export declare class ClearingHouse {
164
191
  getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
165
192
  triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
166
193
  getOracleDataForMarket(marketIndex: BN): OraclePriceData;
167
- initializeInsuranceFundStake(bankIndex: BN): Promise<TransactionSignature>;
168
- getInitializeInsuranceFundStakeIx(bankIndex: BN): Promise<TransactionInstruction>;
169
- addInsuranceFundStake(bankIndex: BN, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
170
- requestRemoveInsuranceFundStake(bankIndex: BN, amount: BN): Promise<TransactionSignature>;
171
- cancelRequestRemoveInsuranceFundStake(bankIndex: BN): Promise<TransactionSignature>;
172
- removeInsuranceFundStake(bankIndex: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
173
- settleRevenueToInsuranceFund(bankIndex: BN): Promise<TransactionSignature>;
194
+ initializeInsuranceFundStake(marketIndex: BN): Promise<TransactionSignature>;
195
+ getInitializeInsuranceFundStakeIx(marketIndex: BN): Promise<TransactionInstruction>;
196
+ addInsuranceFundStake(marketIndex: BN, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
197
+ requestRemoveInsuranceFundStake(marketIndex: BN, amount: BN): Promise<TransactionSignature>;
198
+ cancelRequestRemoveInsuranceFundStake(marketIndex: BN): Promise<TransactionSignature>;
199
+ removeInsuranceFundStake(marketIndex: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
200
+ settleRevenueToInsuranceFund(marketIndex: BN): Promise<TransactionSignature>;
201
+ resolvePerpPnlDeficit(spotMarketIndex: BN, perpMarketIndex: BN): Promise<TransactionSignature>;
202
+ getResolvePerpPnlDeficitIx(spotMarketIndex: BN, perpMarketIndex: BN): Promise<TransactionInstruction>;
174
203
  }