@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.js ADDED
@@ -0,0 +1,1284 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ exports.__esModule = true;
54
+ exports.Admin = void 0;
55
+ var web3_js_1 = require("@solana/web3.js");
56
+ var types_1 = require("./types");
57
+ var anchor_1 = require("@project-serum/anchor");
58
+ var anchor = require("@project-serum/anchor");
59
+ var pda_1 = require("./addresses/pda");
60
+ var utils_1 = require("./math/utils");
61
+ var spl_token_1 = require("@solana/spl-token");
62
+ var clearingHouse_1 = require("./clearingHouse");
63
+ var numericConstants_1 = require("./constants/numericConstants");
64
+ var trade_1 = require("./math/trade");
65
+ var amm_1 = require("./math/amm");
66
+ var Admin = /** @class */ (function (_super) {
67
+ __extends(Admin, _super);
68
+ function Admin() {
69
+ return _super !== null && _super.apply(this, arguments) || this;
70
+ }
71
+ Admin.prototype.initialize = function (usdcMint, adminControlsPrices) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var stateAccountRPCResponse, _a, _b, clearingHouseStatePublicKey, insuranceVaultPublicKey, initializeTx, initializeTxSig;
74
+ return __generator(this, function (_c) {
75
+ switch (_c.label) {
76
+ case 0:
77
+ _b = (_a = this.connection).getParsedAccountInfo;
78
+ return [4 /*yield*/, this.getStatePublicKey()];
79
+ case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];
80
+ case 2:
81
+ stateAccountRPCResponse = _c.sent();
82
+ if (stateAccountRPCResponse.value !== null) {
83
+ throw new Error('Clearing house already initialized');
84
+ }
85
+ return [4 /*yield*/, (0, pda_1.getClearingHouseStateAccountPublicKeyAndNonce)(this.program.programId)];
86
+ case 3:
87
+ clearingHouseStatePublicKey = (_c.sent())[0];
88
+ return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId)];
89
+ case 4:
90
+ insuranceVaultPublicKey = (_c.sent())[0];
91
+ return [4 /*yield*/, this.program.transaction.initialize(adminControlsPrices, {
92
+ accounts: {
93
+ admin: this.wallet.publicKey,
94
+ state: clearingHouseStatePublicKey,
95
+ quoteAssetMint: usdcMint,
96
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
97
+ insuranceVault: insuranceVaultPublicKey,
98
+ clearingHouseSigner: this.getSignerPublicKey(),
99
+ systemProgram: anchor.web3.SystemProgram.programId,
100
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
101
+ }
102
+ })];
103
+ case 5:
104
+ initializeTx = _c.sent();
105
+ return [4 /*yield*/, this.txSender.send(initializeTx, [], this.opts)];
106
+ case 6:
107
+ initializeTxSig = (_c.sent()).txSig;
108
+ return [2 /*return*/, [initializeTxSig]];
109
+ }
110
+ });
111
+ });
112
+ };
113
+ Admin.prototype.initializeSpotMarket = function (mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee) {
114
+ if (imfFactor === void 0) { imfFactor = new anchor_1.BN(0); }
115
+ if (liquidationFee === void 0) { liquidationFee = numericConstants_1.ZERO; }
116
+ return __awaiter(this, void 0, void 0, function () {
117
+ var spotMarketIndex, spotMarket, spotMarketVault, insuranceFundVault, initializeTx, _a, _b, _c, txSig;
118
+ var _d, _e;
119
+ return __generator(this, function (_f) {
120
+ switch (_f.label) {
121
+ case 0:
122
+ spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
123
+ return [4 /*yield*/, (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex)];
124
+ case 1:
125
+ spotMarket = _f.sent();
126
+ return [4 /*yield*/, (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex)];
127
+ case 2:
128
+ spotMarketVault = _f.sent();
129
+ return [4 /*yield*/, (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex)];
130
+ case 3:
131
+ insuranceFundVault = _f.sent();
132
+ _b = (_a = this.program.transaction).initializeSpotMarket;
133
+ _c = [optimalUtilization,
134
+ optimalRate,
135
+ maxRate,
136
+ oracleSource,
137
+ initialAssetWeight,
138
+ maintenanceAssetWeight,
139
+ initialLiabilityWeight,
140
+ maintenanceLiabilityWeight,
141
+ imfFactor,
142
+ liquidationFee];
143
+ _d = {};
144
+ _e = {
145
+ admin: this.wallet.publicKey
146
+ };
147
+ return [4 /*yield*/, this.getStatePublicKey()];
148
+ case 4: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
149
+ _e.spotMarket = spotMarket,
150
+ _e.spotMarketVault = spotMarketVault,
151
+ _e.insuranceFundVault = insuranceFundVault,
152
+ _e.clearingHouseSigner = this.getSignerPublicKey(),
153
+ _e.spotMarketMint = mint,
154
+ _e.oracle = oracle,
155
+ _e.rent = web3_js_1.SYSVAR_RENT_PUBKEY,
156
+ _e.systemProgram = anchor.web3.SystemProgram.programId,
157
+ _e.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
158
+ _e),
159
+ _d)]))];
160
+ case 5:
161
+ initializeTx = _f.sent();
162
+ return [4 /*yield*/, this.txSender.send(initializeTx, [], this.opts)];
163
+ case 6:
164
+ txSig = (_f.sent()).txSig;
165
+ return [4 /*yield*/, this.accountSubscriber.addSpotMarket(spotMarketIndex)];
166
+ case 7:
167
+ _f.sent();
168
+ return [4 /*yield*/, this.accountSubscriber.addOracle({
169
+ source: oracleSource,
170
+ publicKey: oracle
171
+ })];
172
+ case 8:
173
+ _f.sent();
174
+ return [2 /*return*/, txSig];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ Admin.prototype.initializeSerumFulfillmentConfig = function (marketIndex, serumMarket, serumProgram) {
180
+ return __awaiter(this, void 0, void 0, function () {
181
+ var serumOpenOrders, serumFulfillmentConfig, _a, _b, _c;
182
+ var _d, _e;
183
+ return __generator(this, function (_f) {
184
+ switch (_f.label) {
185
+ case 0:
186
+ serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
187
+ serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
188
+ _b = (_a = this.program.rpc).initializeSerumFulfillmentConfig;
189
+ _c = [marketIndex];
190
+ _d = {};
191
+ _e = {
192
+ admin: this.wallet.publicKey
193
+ };
194
+ return [4 /*yield*/, this.getStatePublicKey()];
195
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
196
+ _e.baseSpotMarket = this.getSpotMarketAccount(marketIndex).pubkey,
197
+ _e.quoteSpotMarket = this.getQuoteSpotMarketAccount().pubkey,
198
+ _e.clearingHouseSigner = this.getSignerPublicKey(),
199
+ _e.serumProgram = serumProgram,
200
+ _e.serumMarket = serumMarket,
201
+ _e.serumOpenOrders = serumOpenOrders,
202
+ _e.rent = web3_js_1.SYSVAR_RENT_PUBKEY,
203
+ _e.systemProgram = anchor.web3.SystemProgram.programId,
204
+ _e.serumFulfillmentConfig = serumFulfillmentConfig,
205
+ _e),
206
+ _d)]))];
207
+ case 2: return [2 /*return*/, _f.sent()];
208
+ }
209
+ });
210
+ });
211
+ };
212
+ Admin.prototype.initializeMarket = function (priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee) {
213
+ if (pegMultiplier === void 0) { pegMultiplier = numericConstants_1.PEG_PRECISION; }
214
+ if (oracleSource === void 0) { oracleSource = types_1.OracleSource.PYTH; }
215
+ if (marginRatioInitial === void 0) { marginRatioInitial = 2000; }
216
+ if (marginRatioMaintenance === void 0) { marginRatioMaintenance = 500; }
217
+ if (liquidationFee === void 0) { liquidationFee = numericConstants_1.ZERO; }
218
+ return __awaiter(this, void 0, void 0, function () {
219
+ var marketPublicKey, initializeMarketTx, _a, _b, _c, txSig;
220
+ var _d, _e;
221
+ return __generator(this, function (_f) {
222
+ switch (_f.label) {
223
+ case 0: return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets)];
224
+ case 1:
225
+ marketPublicKey = _f.sent();
226
+ _b = (_a = this.program.transaction).initializeMarket;
227
+ _c = [baseAssetReserve,
228
+ quoteAssetReserve,
229
+ periodicity,
230
+ pegMultiplier,
231
+ oracleSource,
232
+ marginRatioInitial,
233
+ marginRatioMaintenance,
234
+ liquidationFee];
235
+ _d = {};
236
+ _e = {};
237
+ return [4 /*yield*/, this.getStatePublicKey()];
238
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
239
+ _e.admin = this.wallet.publicKey,
240
+ _e.oracle = priceOracle,
241
+ _e.market = marketPublicKey,
242
+ _e.rent = web3_js_1.SYSVAR_RENT_PUBKEY,
243
+ _e.systemProgram = anchor.web3.SystemProgram.programId,
244
+ _e),
245
+ _d)]))];
246
+ case 3:
247
+ initializeMarketTx = _f.sent();
248
+ return [4 /*yield*/, this.txSender.send(initializeMarketTx, [], this.opts)];
249
+ case 4:
250
+ txSig = (_f.sent()).txSig;
251
+ return [4 /*yield*/, this.accountSubscriber.addPerpMarket(this.getStateAccount().numberOfMarkets)];
252
+ case 5:
253
+ _f.sent();
254
+ return [4 /*yield*/, this.accountSubscriber.addOracle({
255
+ source: oracleSource,
256
+ publicKey: priceOracle
257
+ })];
258
+ case 6:
259
+ _f.sent();
260
+ return [2 /*return*/, txSig];
261
+ }
262
+ });
263
+ });
264
+ };
265
+ Admin.prototype.moveAmmPrice = function (marketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var marketPublicKey, _a, _b, _c;
268
+ var _d, _e;
269
+ return __generator(this, function (_f) {
270
+ switch (_f.label) {
271
+ case 0: return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
272
+ case 1:
273
+ marketPublicKey = _f.sent();
274
+ if (sqrtK == undefined) {
275
+ sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
276
+ }
277
+ _b = (_a = this.program.rpc).moveAmmPrice;
278
+ _c = [baseAssetReserve,
279
+ quoteAssetReserve,
280
+ sqrtK];
281
+ _d = {};
282
+ _e = {};
283
+ return [4 /*yield*/, this.getStatePublicKey()];
284
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
285
+ _e.admin = this.wallet.publicKey,
286
+ _e.perpMarket = marketPublicKey,
287
+ _e),
288
+ _d)]))];
289
+ case 3: return [2 /*return*/, _f.sent()];
290
+ }
291
+ });
292
+ });
293
+ };
294
+ Admin.prototype.updateK = function (sqrtK, marketIndex) {
295
+ return __awaiter(this, void 0, void 0, function () {
296
+ var _a, _b, _c;
297
+ var _d, _e;
298
+ return __generator(this, function (_f) {
299
+ switch (_f.label) {
300
+ case 0:
301
+ _b = (_a = this.program.rpc).updateK;
302
+ _c = [sqrtK];
303
+ _d = {};
304
+ _e = {};
305
+ return [4 /*yield*/, this.getStatePublicKey()];
306
+ case 1:
307
+ _e.state = _f.sent(),
308
+ _e.admin = this.wallet.publicKey;
309
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
310
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
311
+ _e.oracle = this.getPerpMarketAccount(marketIndex).amm.oracle,
312
+ _e),
313
+ _d)]))];
314
+ case 3: return [2 /*return*/, _f.sent()];
315
+ }
316
+ });
317
+ });
318
+ };
319
+ Admin.prototype.moveAmmToPrice = function (perpMarketIndex, targetPrice) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ var market, _a, direction, tradeSize, _, _b, newQuoteAssetAmount, newBaseAssetAmount, marketPublicKey, _c, _d, _e;
322
+ var _f, _g;
323
+ return __generator(this, function (_h) {
324
+ switch (_h.label) {
325
+ case 0:
326
+ market = this.getPerpMarketAccount(perpMarketIndex);
327
+ _a = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
328
+ ), direction = _a[0], tradeSize = _a[1], _ = _a[2];
329
+ _b = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction)), newQuoteAssetAmount = _b[0], newBaseAssetAmount = _b[1];
330
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex)];
331
+ case 1:
332
+ marketPublicKey = _h.sent();
333
+ _d = (_c = this.program.rpc).moveAmmPrice;
334
+ _e = [newBaseAssetAmount,
335
+ newQuoteAssetAmount,
336
+ market.amm.sqrtK];
337
+ _f = {};
338
+ _g = {};
339
+ return [4 /*yield*/, this.getStatePublicKey()];
340
+ case 2: return [4 /*yield*/, _d.apply(_c, _e.concat([(_f.accounts = (_g.state = _h.sent(),
341
+ _g.admin = this.wallet.publicKey,
342
+ _g.perpMarket = marketPublicKey,
343
+ _g),
344
+ _f)]))];
345
+ case 3: return [2 /*return*/, _h.sent()];
346
+ }
347
+ });
348
+ });
349
+ };
350
+ Admin.prototype.repegAmmCurve = function (newPeg, marketIndex) {
351
+ return __awaiter(this, void 0, void 0, function () {
352
+ var marketPublicKey, ammData, _a, _b, _c;
353
+ var _d, _e;
354
+ return __generator(this, function (_f) {
355
+ switch (_f.label) {
356
+ case 0: return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
357
+ case 1:
358
+ marketPublicKey = _f.sent();
359
+ ammData = this.getPerpMarketAccount(marketIndex).amm;
360
+ _b = (_a = this.program.rpc).repegAmmCurve;
361
+ _c = [newPeg];
362
+ _d = {};
363
+ _e = {};
364
+ return [4 /*yield*/, this.getStatePublicKey()];
365
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
366
+ _e.admin = this.wallet.publicKey,
367
+ _e.oracle = ammData.oracle,
368
+ _e.market = marketPublicKey,
369
+ _e),
370
+ _d)]))];
371
+ case 3: return [2 /*return*/, _f.sent()];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ Admin.prototype.updateAmmOracleTwap = function (marketIndex) {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ var ammData, marketPublicKey, _a, _b;
379
+ var _c, _d;
380
+ return __generator(this, function (_e) {
381
+ switch (_e.label) {
382
+ case 0:
383
+ ammData = this.getPerpMarketAccount(marketIndex).amm;
384
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
385
+ case 1:
386
+ marketPublicKey = _e.sent();
387
+ _b = (_a = this.program.rpc).updateAmmOracleTwap;
388
+ _c = {};
389
+ _d = {};
390
+ return [4 /*yield*/, this.getStatePublicKey()];
391
+ case 2: return [4 /*yield*/, _b.apply(_a, [(_c.accounts = (_d.state = _e.sent(),
392
+ _d.admin = this.wallet.publicKey,
393
+ _d.oracle = ammData.oracle,
394
+ _d.market = marketPublicKey,
395
+ _d),
396
+ _c)])];
397
+ case 3: return [2 /*return*/, _e.sent()];
398
+ }
399
+ });
400
+ });
401
+ };
402
+ Admin.prototype.resetAmmOracleTwap = function (marketIndex) {
403
+ return __awaiter(this, void 0, void 0, function () {
404
+ var ammData, marketPublicKey, _a, _b;
405
+ var _c, _d;
406
+ return __generator(this, function (_e) {
407
+ switch (_e.label) {
408
+ case 0:
409
+ ammData = this.getPerpMarketAccount(marketIndex).amm;
410
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
411
+ case 1:
412
+ marketPublicKey = _e.sent();
413
+ _b = (_a = this.program.rpc).resetAmmOracleTwap;
414
+ _c = {};
415
+ _d = {};
416
+ return [4 /*yield*/, this.getStatePublicKey()];
417
+ case 2: return [4 /*yield*/, _b.apply(_a, [(_c.accounts = (_d.state = _e.sent(),
418
+ _d.admin = this.wallet.publicKey,
419
+ _d.oracle = ammData.oracle,
420
+ _d.market = marketPublicKey,
421
+ _d),
422
+ _c)])];
423
+ case 3: return [2 /*return*/, _e.sent()];
424
+ }
425
+ });
426
+ });
427
+ };
428
+ Admin.prototype.withdrawFromInsuranceVault = function (amount, recipient) {
429
+ return __awaiter(this, void 0, void 0, function () {
430
+ var state, spotMarket, _a, _b, _c;
431
+ var _d, _e;
432
+ return __generator(this, function (_f) {
433
+ switch (_f.label) {
434
+ case 0: return [4 /*yield*/, this.getStateAccount()];
435
+ case 1:
436
+ state = _f.sent();
437
+ spotMarket = this.getQuoteSpotMarketAccount();
438
+ _b = (_a = this.program.rpc).withdrawFromInsuranceVault;
439
+ _c = [amount];
440
+ _d = {};
441
+ _e = {
442
+ admin: this.wallet.publicKey
443
+ };
444
+ return [4 /*yield*/, this.getStatePublicKey()];
445
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
446
+ _e.spotMarket = spotMarket.pubkey,
447
+ _e.insuranceVault = state.insuranceVault,
448
+ _e.clearingHouseSigner = this.getSignerPublicKey(),
449
+ _e.recipient = recipient,
450
+ _e.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
451
+ _e),
452
+ _d)]))];
453
+ case 3: return [2 /*return*/, _f.sent()];
454
+ }
455
+ });
456
+ });
457
+ };
458
+ Admin.prototype.withdrawFromMarketToInsuranceVault = function (marketIndex, amount, recipient) {
459
+ return __awaiter(this, void 0, void 0, function () {
460
+ var marketPublicKey, spotMarket, _a, _b, _c;
461
+ var _d, _e;
462
+ return __generator(this, function (_f) {
463
+ switch (_f.label) {
464
+ case 0: return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
465
+ case 1:
466
+ marketPublicKey = _f.sent();
467
+ spotMarket = this.getQuoteSpotMarketAccount();
468
+ _b = (_a = this.program.rpc).withdrawFromMarketToInsuranceVault;
469
+ _c = [amount];
470
+ _d = {};
471
+ _e = {
472
+ admin: this.wallet.publicKey
473
+ };
474
+ return [4 /*yield*/, this.getStatePublicKey()];
475
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
476
+ _e.market = marketPublicKey,
477
+ _e.spotMarket = spotMarket.pubkey,
478
+ _e.spotMarketVault = spotMarket.vault,
479
+ _e.clearingHouseSigner = this.getSignerPublicKey(),
480
+ _e.recipient = recipient,
481
+ _e.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
482
+ _e),
483
+ _d)]))];
484
+ case 3: return [2 /*return*/, _f.sent()];
485
+ }
486
+ });
487
+ });
488
+ };
489
+ Admin.prototype.withdrawFromInsuranceVaultToMarket = function (marketIndex, amount) {
490
+ return __awaiter(this, void 0, void 0, function () {
491
+ var state, spotMarket, _a, _b, _c;
492
+ var _d, _e;
493
+ return __generator(this, function (_f) {
494
+ switch (_f.label) {
495
+ case 0: return [4 /*yield*/, this.getStateAccount()];
496
+ case 1:
497
+ state = _f.sent();
498
+ spotMarket = this.getQuoteSpotMarketAccount();
499
+ _b = (_a = this.program.rpc).withdrawFromInsuranceVaultToMarket;
500
+ _c = [amount];
501
+ _d = {};
502
+ _e = {
503
+ admin: this.wallet.publicKey
504
+ };
505
+ return [4 /*yield*/, this.getStatePublicKey()];
506
+ case 2:
507
+ _e.state = _f.sent();
508
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
509
+ case 3: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
510
+ _e.insuranceVault = state.insuranceVault,
511
+ _e.clearingHouseSigner = this.getSignerPublicKey(),
512
+ _e.quoteSpotMarket = spotMarket.pubkey,
513
+ _e.spotMarketVault = spotMarket.vault,
514
+ _e.tokenProgram = spl_token_1.TOKEN_PROGRAM_ID,
515
+ _e),
516
+ _d)]))];
517
+ case 4: return [2 /*return*/, _f.sent()];
518
+ }
519
+ });
520
+ });
521
+ };
522
+ Admin.prototype.updateAdmin = function (admin) {
523
+ return __awaiter(this, void 0, void 0, function () {
524
+ var _a, _b, _c;
525
+ var _d, _e;
526
+ return __generator(this, function (_f) {
527
+ switch (_f.label) {
528
+ case 0:
529
+ _b = (_a = this.program.rpc).updateAdmin;
530
+ _c = [admin];
531
+ _d = {};
532
+ _e = {
533
+ admin: this.wallet.publicKey
534
+ };
535
+ return [4 /*yield*/, this.getStatePublicKey()];
536
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
537
+ _e),
538
+ _d)]))];
539
+ case 2: return [2 /*return*/, _f.sent()];
540
+ }
541
+ });
542
+ });
543
+ };
544
+ Admin.prototype.updateCurveUpdateIntensity = function (marketIndex, curveUpdateIntensity) {
545
+ return __awaiter(this, void 0, void 0, function () {
546
+ var _a, _b, _c;
547
+ var _d, _e;
548
+ return __generator(this, function (_f) {
549
+ switch (_f.label) {
550
+ case 0:
551
+ _b = (_a = this.program.rpc).updateCurveUpdateIntensity;
552
+ _c = [curveUpdateIntensity];
553
+ _d = {};
554
+ _e = {
555
+ admin: this.wallet.publicKey
556
+ };
557
+ return [4 /*yield*/, this.getStatePublicKey()];
558
+ case 1:
559
+ _e.state = _f.sent();
560
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
561
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
562
+ _e),
563
+ _d)]))];
564
+ case 3:
565
+ // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
566
+ // assert(Number.isInteger(curveUpdateIntensity));
567
+ return [2 /*return*/, _f.sent()];
568
+ }
569
+ });
570
+ });
571
+ };
572
+ Admin.prototype.updateMarginRatio = function (marketIndex, marginRatioInitial, marginRatioMaintenance) {
573
+ return __awaiter(this, void 0, void 0, function () {
574
+ var _a, _b, _c;
575
+ var _d, _e;
576
+ return __generator(this, function (_f) {
577
+ switch (_f.label) {
578
+ case 0:
579
+ _b = (_a = this.program.rpc).updateMarginRatio;
580
+ _c = [marginRatioInitial,
581
+ marginRatioMaintenance];
582
+ _d = {};
583
+ _e = {
584
+ admin: this.wallet.publicKey
585
+ };
586
+ return [4 /*yield*/, this.getStatePublicKey()];
587
+ case 1:
588
+ _e.state = _f.sent();
589
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
590
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
591
+ _e),
592
+ _d)]))];
593
+ case 3: return [2 /*return*/, _f.sent()];
594
+ }
595
+ });
596
+ });
597
+ };
598
+ Admin.prototype.updateMarketBaseSpread = function (marketIndex, baseSpread) {
599
+ return __awaiter(this, void 0, void 0, function () {
600
+ var _a, _b, _c;
601
+ var _d, _e;
602
+ return __generator(this, function (_f) {
603
+ switch (_f.label) {
604
+ case 0:
605
+ _b = (_a = this.program.rpc).updateMarketBaseSpread;
606
+ _c = [baseSpread];
607
+ _d = {};
608
+ _e = {
609
+ admin: this.wallet.publicKey
610
+ };
611
+ return [4 /*yield*/, this.getStatePublicKey()];
612
+ case 1:
613
+ _e.state = _f.sent();
614
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
615
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
616
+ _e),
617
+ _d)]))];
618
+ case 3: return [2 /*return*/, _f.sent()];
619
+ }
620
+ });
621
+ });
622
+ };
623
+ Admin.prototype.updateAmmJitIntensity = function (marketIndex, ammJitIntensity) {
624
+ return __awaiter(this, void 0, void 0, function () {
625
+ var _a, _b, _c;
626
+ var _d, _e;
627
+ return __generator(this, function (_f) {
628
+ switch (_f.label) {
629
+ case 0:
630
+ _b = (_a = this.program.rpc).updateAmmJitIntensity;
631
+ _c = [ammJitIntensity];
632
+ _d = {};
633
+ _e = {
634
+ admin: this.wallet.publicKey
635
+ };
636
+ return [4 /*yield*/, this.getStatePublicKey()];
637
+ case 1:
638
+ _e.state = _f.sent();
639
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
640
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
641
+ _e),
642
+ _d)]))];
643
+ case 3: return [2 /*return*/, _f.sent()];
644
+ }
645
+ });
646
+ });
647
+ };
648
+ Admin.prototype.updateMarketMaxSpread = function (marketIndex, maxSpread) {
649
+ return __awaiter(this, void 0, void 0, function () {
650
+ var _a, _b, _c;
651
+ var _d, _e;
652
+ return __generator(this, function (_f) {
653
+ switch (_f.label) {
654
+ case 0:
655
+ _b = (_a = this.program.rpc).updateMarketMaxSpread;
656
+ _c = [maxSpread];
657
+ _d = {};
658
+ _e = {
659
+ admin: this.wallet.publicKey
660
+ };
661
+ return [4 /*yield*/, this.getStatePublicKey()];
662
+ case 1:
663
+ _e.state = _f.sent();
664
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
665
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
666
+ _e),
667
+ _d)]))];
668
+ case 3: return [2 /*return*/, _f.sent()];
669
+ }
670
+ });
671
+ });
672
+ };
673
+ Admin.prototype.updatePartialLiquidationClosePercentage = function (numerator, denominator) {
674
+ return __awaiter(this, void 0, void 0, function () {
675
+ var _a, _b, _c;
676
+ var _d, _e;
677
+ return __generator(this, function (_f) {
678
+ switch (_f.label) {
679
+ case 0:
680
+ _b = (_a = this.program.rpc).updatePartialLiquidationClosePercentage;
681
+ _c = [numerator,
682
+ denominator];
683
+ _d = {};
684
+ _e = {
685
+ admin: this.wallet.publicKey
686
+ };
687
+ return [4 /*yield*/, this.getStatePublicKey()];
688
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
689
+ _e),
690
+ _d)]))];
691
+ case 2: return [2 /*return*/, _f.sent()];
692
+ }
693
+ });
694
+ });
695
+ };
696
+ Admin.prototype.updatePartialLiquidationPenaltyPercentage = function (numerator, denominator) {
697
+ return __awaiter(this, void 0, void 0, function () {
698
+ var _a, _b, _c;
699
+ var _d, _e;
700
+ return __generator(this, function (_f) {
701
+ switch (_f.label) {
702
+ case 0:
703
+ _b = (_a = this.program.rpc).updatePartialLiquidationPenaltyPercentage;
704
+ _c = [numerator,
705
+ denominator];
706
+ _d = {};
707
+ _e = {
708
+ admin: this.wallet.publicKey
709
+ };
710
+ return [4 /*yield*/, this.getStatePublicKey()];
711
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
712
+ _e),
713
+ _d)]))];
714
+ case 2: return [2 /*return*/, _f.sent()];
715
+ }
716
+ });
717
+ });
718
+ };
719
+ Admin.prototype.updateFullLiquidationPenaltyPercentage = function (numerator, denominator) {
720
+ return __awaiter(this, void 0, void 0, function () {
721
+ var _a, _b, _c;
722
+ var _d, _e;
723
+ return __generator(this, function (_f) {
724
+ switch (_f.label) {
725
+ case 0:
726
+ _b = (_a = this.program.rpc).updateFullLiquidationPenaltyPercentage;
727
+ _c = [numerator,
728
+ denominator];
729
+ _d = {};
730
+ _e = {
731
+ admin: this.wallet.publicKey
732
+ };
733
+ return [4 /*yield*/, this.getStatePublicKey()];
734
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
735
+ _e),
736
+ _d)]))];
737
+ case 2: return [2 /*return*/, _f.sent()];
738
+ }
739
+ });
740
+ });
741
+ };
742
+ Admin.prototype.updatePartialLiquidationShareDenominator = function (denominator) {
743
+ return __awaiter(this, void 0, void 0, function () {
744
+ var _a, _b, _c;
745
+ var _d, _e;
746
+ return __generator(this, function (_f) {
747
+ switch (_f.label) {
748
+ case 0:
749
+ _b = (_a = this.program.rpc).updatePartialLiquidationLiquidatorShareDenominator;
750
+ _c = [denominator];
751
+ _d = {};
752
+ _e = {
753
+ admin: this.wallet.publicKey
754
+ };
755
+ return [4 /*yield*/, this.getStatePublicKey()];
756
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
757
+ _e),
758
+ _d)]))];
759
+ case 2: return [2 /*return*/, _f.sent()];
760
+ }
761
+ });
762
+ });
763
+ };
764
+ Admin.prototype.updateFullLiquidationShareDenominator = function (denominator) {
765
+ return __awaiter(this, void 0, void 0, function () {
766
+ var _a, _b, _c;
767
+ var _d, _e;
768
+ return __generator(this, function (_f) {
769
+ switch (_f.label) {
770
+ case 0:
771
+ _b = (_a = this.program.rpc).updateFullLiquidationLiquidatorShareDenominator;
772
+ _c = [denominator];
773
+ _d = {};
774
+ _e = {
775
+ admin: this.wallet.publicKey
776
+ };
777
+ return [4 /*yield*/, this.getStatePublicKey()];
778
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
779
+ _e),
780
+ _d)]))];
781
+ case 2: return [2 /*return*/, _f.sent()];
782
+ }
783
+ });
784
+ });
785
+ };
786
+ Admin.prototype.updateOrderFillerRewardStructure = function (orderFillerRewardStructure) {
787
+ return __awaiter(this, void 0, void 0, function () {
788
+ var _a, _b, _c;
789
+ var _d, _e;
790
+ return __generator(this, function (_f) {
791
+ switch (_f.label) {
792
+ case 0:
793
+ _b = (_a = this.program.rpc).updateOrderFillerRewardStructure;
794
+ _c = [orderFillerRewardStructure];
795
+ _d = {};
796
+ _e = {
797
+ admin: this.wallet.publicKey
798
+ };
799
+ return [4 /*yield*/, this.getStatePublicKey()];
800
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
801
+ _e),
802
+ _d)]))];
803
+ case 2: return [2 /*return*/, _f.sent()];
804
+ }
805
+ });
806
+ });
807
+ };
808
+ Admin.prototype.updateFee = function (fees) {
809
+ return __awaiter(this, void 0, void 0, function () {
810
+ var _a, _b, _c;
811
+ var _d, _e;
812
+ return __generator(this, function (_f) {
813
+ switch (_f.label) {
814
+ case 0:
815
+ _b = (_a = this.program.rpc).updateFee;
816
+ _c = [fees];
817
+ _d = {};
818
+ _e = {
819
+ admin: this.wallet.publicKey
820
+ };
821
+ return [4 /*yield*/, this.getStatePublicKey()];
822
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
823
+ _e),
824
+ _d)]))];
825
+ case 2: return [2 /*return*/, _f.sent()];
826
+ }
827
+ });
828
+ });
829
+ };
830
+ Admin.prototype.updateOracleGuardRails = function (oracleGuardRails) {
831
+ return __awaiter(this, void 0, void 0, function () {
832
+ var _a, _b, _c;
833
+ var _d, _e;
834
+ return __generator(this, function (_f) {
835
+ switch (_f.label) {
836
+ case 0:
837
+ _b = (_a = this.program.rpc).updateOracleGuardRails;
838
+ _c = [oracleGuardRails];
839
+ _d = {};
840
+ _e = {
841
+ admin: this.wallet.publicKey
842
+ };
843
+ return [4 /*yield*/, this.getStatePublicKey()];
844
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
845
+ _e),
846
+ _d)]))];
847
+ case 2: return [2 /*return*/, _f.sent()];
848
+ }
849
+ });
850
+ });
851
+ };
852
+ Admin.prototype.updateWithdrawGuardThreshold = function (marketIndex, withdrawGuardThreshold) {
853
+ return __awaiter(this, void 0, void 0, function () {
854
+ var _a, _b, _c;
855
+ var _d, _e;
856
+ return __generator(this, function (_f) {
857
+ switch (_f.label) {
858
+ case 0:
859
+ _b = (_a = this.program.rpc).updateWithdrawGuardThreshold;
860
+ _c = [withdrawGuardThreshold];
861
+ _d = {};
862
+ _e = {
863
+ admin: this.wallet.publicKey
864
+ };
865
+ return [4 /*yield*/, this.getStatePublicKey()];
866
+ case 1:
867
+ _e.state = _f.sent();
868
+ return [4 /*yield*/, (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex)];
869
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.spotMarket = _f.sent(),
870
+ _e),
871
+ _d)]))];
872
+ case 3: return [2 /*return*/, _f.sent()];
873
+ }
874
+ });
875
+ });
876
+ };
877
+ Admin.prototype.updateSpotMarketIfFactor = function (marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor) {
878
+ return __awaiter(this, void 0, void 0, function () {
879
+ var _a, _b, _c;
880
+ var _d, _e;
881
+ return __generator(this, function (_f) {
882
+ switch (_f.label) {
883
+ case 0:
884
+ _b = (_a = this.program.rpc).updateSpotMarketIfFactor;
885
+ _c = [marketIndex,
886
+ userIfFactor,
887
+ totalIfFactor,
888
+ liquidationIfFactor];
889
+ _d = {};
890
+ _e = {
891
+ admin: this.wallet.publicKey
892
+ };
893
+ return [4 /*yield*/, this.getStatePublicKey()];
894
+ case 1:
895
+ _e.state = _f.sent();
896
+ return [4 /*yield*/, (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex)];
897
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.spotMarket = _f.sent(),
898
+ _e),
899
+ _d)]))];
900
+ case 3: return [2 /*return*/, _f.sent()];
901
+ }
902
+ });
903
+ });
904
+ };
905
+ Admin.prototype.updateInsuranceWithdrawEscrowPeriod = function (marketIndex, insuranceWithdrawEscrowPeriod) {
906
+ return __awaiter(this, void 0, void 0, function () {
907
+ var _a, _b, _c;
908
+ var _d, _e;
909
+ return __generator(this, function (_f) {
910
+ switch (_f.label) {
911
+ case 0:
912
+ _b = (_a = this.program.rpc).updateInsuranceWithdrawEscrowPeriod;
913
+ _c = [insuranceWithdrawEscrowPeriod];
914
+ _d = {};
915
+ _e = {
916
+ admin: this.wallet.publicKey
917
+ };
918
+ return [4 /*yield*/, this.getStatePublicKey()];
919
+ case 1:
920
+ _e.state = _f.sent();
921
+ return [4 /*yield*/, (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex)];
922
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.spotMarket = _f.sent(),
923
+ _e),
924
+ _d)]))];
925
+ case 3: return [2 /*return*/, _f.sent()];
926
+ }
927
+ });
928
+ });
929
+ };
930
+ Admin.prototype.updateLpCooldownTime = function (marketIndex, cooldownTime) {
931
+ return __awaiter(this, void 0, void 0, function () {
932
+ var _a, _b, _c;
933
+ var _d, _e;
934
+ return __generator(this, function (_f) {
935
+ switch (_f.label) {
936
+ case 0:
937
+ _b = (_a = this.program.rpc).updateLpCooldownTime;
938
+ _c = [cooldownTime];
939
+ _d = {};
940
+ _e = {
941
+ admin: this.wallet.publicKey
942
+ };
943
+ return [4 /*yield*/, this.getStatePublicKey()];
944
+ case 1:
945
+ _e.state = _f.sent();
946
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
947
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
948
+ _e),
949
+ _d)]))];
950
+ case 3: return [2 /*return*/, _f.sent()];
951
+ }
952
+ });
953
+ });
954
+ };
955
+ Admin.prototype.updateMarketOracle = function (marketIndex, oracle, oracleSource) {
956
+ return __awaiter(this, void 0, void 0, function () {
957
+ var _a, _b, _c;
958
+ var _d, _e;
959
+ return __generator(this, function (_f) {
960
+ switch (_f.label) {
961
+ case 0:
962
+ _b = (_a = this.program.rpc).updateMarketOracle;
963
+ _c = [oracle, oracleSource];
964
+ _d = {};
965
+ _e = {
966
+ admin: this.wallet.publicKey
967
+ };
968
+ return [4 /*yield*/, this.getStatePublicKey()];
969
+ case 1:
970
+ _e.state = _f.sent();
971
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
972
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
973
+ _e),
974
+ _d)]))];
975
+ case 3: return [2 /*return*/, _f.sent()];
976
+ }
977
+ });
978
+ });
979
+ };
980
+ Admin.prototype.updateMarketMinimumQuoteAssetTradeSize = function (marketIndex, minimumTradeSize) {
981
+ return __awaiter(this, void 0, void 0, function () {
982
+ var _a, _b, _c;
983
+ var _d, _e;
984
+ return __generator(this, function (_f) {
985
+ switch (_f.label) {
986
+ case 0:
987
+ _b = (_a = this.program.rpc).updateMarketMinimumQuoteAssetTradeSize;
988
+ _c = [minimumTradeSize];
989
+ _d = {};
990
+ _e = {
991
+ admin: this.wallet.publicKey
992
+ };
993
+ return [4 /*yield*/, this.getStatePublicKey()];
994
+ case 1:
995
+ _e.state = _f.sent();
996
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
997
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
998
+ _e),
999
+ _d)]))];
1000
+ case 3: return [2 /*return*/, _f.sent()];
1001
+ }
1002
+ });
1003
+ });
1004
+ };
1005
+ Admin.prototype.updateMarketBaseAssetAmountStepSize = function (marketIndex, stepSize) {
1006
+ return __awaiter(this, void 0, void 0, function () {
1007
+ var _a, _b, _c;
1008
+ var _d, _e;
1009
+ return __generator(this, function (_f) {
1010
+ switch (_f.label) {
1011
+ case 0:
1012
+ _b = (_a = this.program.rpc).updateMarketBaseAssetAmountStepSize;
1013
+ _c = [stepSize];
1014
+ _d = {};
1015
+ _e = {
1016
+ admin: this.wallet.publicKey
1017
+ };
1018
+ return [4 /*yield*/, this.getStatePublicKey()];
1019
+ case 1:
1020
+ _e.state = _f.sent();
1021
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
1022
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
1023
+ _e),
1024
+ _d)]))];
1025
+ case 3: return [2 /*return*/, _f.sent()];
1026
+ }
1027
+ });
1028
+ });
1029
+ };
1030
+ Admin.prototype.updateMarketExpiry = function (perpMarketIndex, expiryTs) {
1031
+ return __awaiter(this, void 0, void 0, function () {
1032
+ var _a, _b, _c;
1033
+ var _d, _e;
1034
+ return __generator(this, function (_f) {
1035
+ switch (_f.label) {
1036
+ case 0:
1037
+ _b = (_a = this.program.rpc).updateMarketExpiry;
1038
+ _c = [expiryTs];
1039
+ _d = {};
1040
+ _e = {
1041
+ admin: this.wallet.publicKey
1042
+ };
1043
+ return [4 /*yield*/, this.getStatePublicKey()];
1044
+ case 1:
1045
+ _e.state = _f.sent();
1046
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex)];
1047
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.perpMarket = _f.sent(),
1048
+ _e),
1049
+ _d)]))];
1050
+ case 3: return [2 /*return*/, _f.sent()];
1051
+ }
1052
+ });
1053
+ });
1054
+ };
1055
+ Admin.prototype.updateWhitelistMint = function (whitelistMint) {
1056
+ return __awaiter(this, void 0, void 0, function () {
1057
+ var _a, _b, _c;
1058
+ var _d, _e;
1059
+ return __generator(this, function (_f) {
1060
+ switch (_f.label) {
1061
+ case 0:
1062
+ _b = (_a = this.program.rpc).updateWhitelistMint;
1063
+ _c = [whitelistMint];
1064
+ _d = {};
1065
+ _e = {
1066
+ admin: this.wallet.publicKey
1067
+ };
1068
+ return [4 /*yield*/, this.getStatePublicKey()];
1069
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1070
+ _e),
1071
+ _d)]))];
1072
+ case 2: return [2 /*return*/, _f.sent()];
1073
+ }
1074
+ });
1075
+ });
1076
+ };
1077
+ Admin.prototype.updateDiscountMint = function (discountMint) {
1078
+ return __awaiter(this, void 0, void 0, function () {
1079
+ var _a, _b, _c;
1080
+ var _d, _e;
1081
+ return __generator(this, function (_f) {
1082
+ switch (_f.label) {
1083
+ case 0:
1084
+ _b = (_a = this.program.rpc).updateDiscountMint;
1085
+ _c = [discountMint];
1086
+ _d = {};
1087
+ _e = {
1088
+ admin: this.wallet.publicKey
1089
+ };
1090
+ return [4 /*yield*/, this.getStatePublicKey()];
1091
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1092
+ _e),
1093
+ _d)]))];
1094
+ case 2: return [2 /*return*/, _f.sent()];
1095
+ }
1096
+ });
1097
+ });
1098
+ };
1099
+ Admin.prototype.updateMaxDeposit = function (maxDeposit) {
1100
+ return __awaiter(this, void 0, void 0, function () {
1101
+ var _a, _b, _c;
1102
+ var _d, _e;
1103
+ return __generator(this, function (_f) {
1104
+ switch (_f.label) {
1105
+ case 0:
1106
+ _b = (_a = this.program.rpc).updateMaxDeposit;
1107
+ _c = [maxDeposit];
1108
+ _d = {};
1109
+ _e = {
1110
+ admin: this.wallet.publicKey
1111
+ };
1112
+ return [4 /*yield*/, this.getStatePublicKey()];
1113
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1114
+ _e),
1115
+ _d)]))];
1116
+ case 2: return [2 /*return*/, _f.sent()];
1117
+ }
1118
+ });
1119
+ });
1120
+ };
1121
+ Admin.prototype.updateFundingPaused = function (fundingPaused) {
1122
+ return __awaiter(this, void 0, void 0, function () {
1123
+ var _a, _b, _c;
1124
+ var _d, _e;
1125
+ return __generator(this, function (_f) {
1126
+ switch (_f.label) {
1127
+ case 0:
1128
+ _b = (_a = this.program.rpc).updateFundingPaused;
1129
+ _c = [fundingPaused];
1130
+ _d = {};
1131
+ _e = {
1132
+ admin: this.wallet.publicKey
1133
+ };
1134
+ return [4 /*yield*/, this.getStatePublicKey()];
1135
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1136
+ _e),
1137
+ _d)]))];
1138
+ case 2: return [2 /*return*/, _f.sent()];
1139
+ }
1140
+ });
1141
+ });
1142
+ };
1143
+ Admin.prototype.updateExchangePaused = function (exchangePaused) {
1144
+ return __awaiter(this, void 0, void 0, function () {
1145
+ var _a, _b, _c;
1146
+ var _d, _e;
1147
+ return __generator(this, function (_f) {
1148
+ switch (_f.label) {
1149
+ case 0:
1150
+ _b = (_a = this.program.rpc).updateExchangePaused;
1151
+ _c = [exchangePaused];
1152
+ _d = {};
1153
+ _e = {
1154
+ admin: this.wallet.publicKey
1155
+ };
1156
+ return [4 /*yield*/, this.getStatePublicKey()];
1157
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1158
+ _e),
1159
+ _d)]))];
1160
+ case 2: return [2 /*return*/, _f.sent()];
1161
+ }
1162
+ });
1163
+ });
1164
+ };
1165
+ Admin.prototype.disableAdminControlsPrices = function () {
1166
+ return __awaiter(this, void 0, void 0, function () {
1167
+ var _a, _b;
1168
+ var _c, _d;
1169
+ return __generator(this, function (_e) {
1170
+ switch (_e.label) {
1171
+ case 0:
1172
+ _b = (_a = this.program.rpc).disableAdminControlsPrices;
1173
+ _c = {};
1174
+ _d = {
1175
+ admin: this.wallet.publicKey
1176
+ };
1177
+ return [4 /*yield*/, this.getStatePublicKey()];
1178
+ case 1: return [4 /*yield*/, _b.apply(_a, [(_c.accounts = (_d.state = _e.sent(),
1179
+ _d),
1180
+ _c)])];
1181
+ case 2: return [2 /*return*/, _e.sent()];
1182
+ }
1183
+ });
1184
+ });
1185
+ };
1186
+ Admin.prototype.updateAuctionDuration = function (minDuration, maxDuration) {
1187
+ return __awaiter(this, void 0, void 0, function () {
1188
+ var _a, _b, _c;
1189
+ var _d, _e;
1190
+ return __generator(this, function (_f) {
1191
+ switch (_f.label) {
1192
+ case 0:
1193
+ _b = (_a = this.program.rpc).updateAuctionDuration;
1194
+ _c = [typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
1195
+ typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber()];
1196
+ _d = {};
1197
+ _e = {
1198
+ admin: this.wallet.publicKey
1199
+ };
1200
+ return [4 /*yield*/, this.getStatePublicKey()];
1201
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1202
+ _e),
1203
+ _d)]))];
1204
+ case 2: return [2 /*return*/, _f.sent()];
1205
+ }
1206
+ });
1207
+ });
1208
+ };
1209
+ Admin.prototype.updateMaxBaseAssetAmountRatio = function (marketIndex, maxBaseAssetAmountRatio) {
1210
+ return __awaiter(this, void 0, void 0, function () {
1211
+ var _a, _b, _c;
1212
+ var _d, _e;
1213
+ return __generator(this, function (_f) {
1214
+ switch (_f.label) {
1215
+ case 0:
1216
+ _b = (_a = this.program.rpc).updateMaxBaseAssetAmountRatio;
1217
+ _c = [maxBaseAssetAmountRatio];
1218
+ _d = {};
1219
+ _e = {
1220
+ admin: this.wallet.publicKey
1221
+ };
1222
+ return [4 /*yield*/, this.getStatePublicKey()];
1223
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1224
+ _e.market = this.getPerpMarketAccount(marketIndex).pubkey,
1225
+ _e),
1226
+ _d)]))];
1227
+ case 2: return [2 /*return*/, _f.sent()];
1228
+ }
1229
+ });
1230
+ });
1231
+ };
1232
+ Admin.prototype.updateMaxSlippageRatio = function (marketIndex, maxSlippageRatio) {
1233
+ return __awaiter(this, void 0, void 0, function () {
1234
+ var _a, _b, _c;
1235
+ var _d, _e;
1236
+ return __generator(this, function (_f) {
1237
+ switch (_f.label) {
1238
+ case 0:
1239
+ _b = (_a = this.program.rpc).updateMaxSlippageRatio;
1240
+ _c = [maxSlippageRatio];
1241
+ _d = {};
1242
+ _e = {
1243
+ admin: this.wallet.publicKey
1244
+ };
1245
+ return [4 /*yield*/, this.getStatePublicKey()];
1246
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.state = _f.sent(),
1247
+ _e.market = this.getPerpMarketAccount(marketIndex).pubkey,
1248
+ _e),
1249
+ _d)]))];
1250
+ case 2: return [2 /*return*/, _f.sent()];
1251
+ }
1252
+ });
1253
+ });
1254
+ };
1255
+ Admin.prototype.updateMarketMaxImbalances = function (marketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
1256
+ return __awaiter(this, void 0, void 0, function () {
1257
+ var _a, _b, _c;
1258
+ var _d, _e;
1259
+ return __generator(this, function (_f) {
1260
+ switch (_f.label) {
1261
+ case 0:
1262
+ _b = (_a = this.program.rpc).updateMarketMaxImbalances;
1263
+ _c = [unrealizedMaxImbalance,
1264
+ maxRevenueWithdrawPerPeriod,
1265
+ quoteMaxInsurance];
1266
+ _d = {};
1267
+ _e = {
1268
+ admin: this.wallet.publicKey
1269
+ };
1270
+ return [4 /*yield*/, this.getStatePublicKey()];
1271
+ case 1:
1272
+ _e.state = _f.sent();
1273
+ return [4 /*yield*/, (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex)];
1274
+ case 2: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.accounts = (_e.market = _f.sent(),
1275
+ _e),
1276
+ _d)]))];
1277
+ case 3: return [2 /*return*/, _f.sent()];
1278
+ }
1279
+ });
1280
+ });
1281
+ };
1282
+ return Admin;
1283
+ }(clearingHouse_1.ClearingHouse));
1284
+ exports.Admin = Admin;