@drift-labs/sdk 0.2.0-temp.2 → 2.0.1

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 (278) hide show
  1. package/README.md +27 -29
  2. package/lib/accounts/bulkAccountLoader.d.ts +2 -0
  3. package/lib/accounts/bulkAccountLoader.js +36 -29
  4. package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
  5. package/lib/accounts/bulkUserStatsSubscription.js +21 -0
  6. package/lib/accounts/bulkUserSubscription.d.ts +2 -2
  7. package/lib/accounts/bulkUserSubscription.js +0 -1
  8. package/lib/accounts/fetch.d.ts +2 -1
  9. package/lib/accounts/fetch.js +9 -1
  10. package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
  11. package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
  12. package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
  13. package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
  14. package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
  15. package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
  16. package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
  17. package/lib/accounts/pollingUserStatsAccountSubscriber.js +107 -0
  18. package/lib/accounts/types.d.ts +26 -15
  19. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
  20. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
  21. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
  22. package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
  23. package/lib/addresses/marketAddresses.d.ts +1 -3
  24. package/lib/addresses/marketAddresses.js +1 -1
  25. package/lib/addresses/pda.d.ts +15 -9
  26. package/lib/addresses/pda.js +73 -35
  27. package/lib/adminClient.d.ts +65 -0
  28. package/lib/adminClient.js +637 -0
  29. package/lib/config.d.ts +10 -10
  30. package/lib/config.js +26 -22
  31. package/lib/constants/numericConstants.d.ts +29 -12
  32. package/lib/constants/numericConstants.js +40 -21
  33. package/lib/constants/perpMarkets.d.ts +18 -0
  34. package/lib/constants/{markets.js → perpMarkets.js} +20 -9
  35. package/lib/constants/spotMarkets.d.ts +19 -0
  36. package/lib/constants/spotMarkets.js +63 -0
  37. package/lib/dlob/DLOB.d.ts +82 -0
  38. package/lib/dlob/DLOB.js +694 -0
  39. package/lib/dlob/DLOBNode.d.ts +54 -0
  40. package/lib/dlob/DLOBNode.js +77 -0
  41. package/lib/dlob/NodeList.d.ts +27 -0
  42. package/lib/dlob/NodeList.js +144 -0
  43. package/lib/driftClient.d.ts +234 -0
  44. package/lib/driftClient.js +2108 -0
  45. package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
  46. package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
  47. package/lib/events/eventList.d.ts +0 -1
  48. package/lib/events/eventList.js +0 -7
  49. package/lib/events/eventSubscriber.d.ts +5 -2
  50. package/lib/events/eventSubscriber.js +25 -11
  51. package/lib/events/fetchLogs.d.ts +13 -2
  52. package/lib/events/fetchLogs.js +45 -14
  53. package/lib/events/pollingLogProvider.d.ts +2 -1
  54. package/lib/events/pollingLogProvider.js +7 -3
  55. package/lib/events/sort.js +8 -11
  56. package/lib/events/txEventCache.d.ts +0 -2
  57. package/lib/events/txEventCache.js +0 -14
  58. package/lib/events/types.d.ts +11 -3
  59. package/lib/events/types.js +8 -0
  60. package/lib/events/webSocketLogProvider.js +1 -1
  61. package/lib/examples/makeTradeExample.js +30 -18
  62. package/lib/factory/bigNum.d.ts +8 -4
  63. package/lib/factory/bigNum.js +109 -19
  64. package/lib/idl/drift.json +8392 -0
  65. package/lib/index.d.ts +29 -12
  66. package/lib/index.js +29 -12
  67. package/lib/math/amm.d.ts +9 -6
  68. package/lib/math/amm.js +91 -38
  69. package/lib/math/conversion.js +1 -1
  70. package/lib/math/exchangeStatus.d.ts +4 -0
  71. package/lib/math/exchangeStatus.js +18 -0
  72. package/lib/math/funding.d.ts +6 -6
  73. package/lib/math/funding.js +23 -21
  74. package/lib/math/insurance.d.ts +4 -0
  75. package/lib/math/insurance.js +27 -0
  76. package/lib/math/margin.d.ts +11 -0
  77. package/lib/math/margin.js +82 -0
  78. package/lib/math/market.d.ts +14 -9
  79. package/lib/math/market.js +70 -10
  80. package/lib/math/oracles.d.ts +4 -0
  81. package/lib/math/oracles.js +36 -8
  82. package/lib/math/orders.d.ts +16 -6
  83. package/lib/math/orders.js +97 -17
  84. package/lib/math/position.d.ts +27 -13
  85. package/lib/math/position.js +91 -37
  86. package/lib/math/repeg.js +17 -8
  87. package/lib/math/spotBalance.d.ts +22 -0
  88. package/lib/math/spotBalance.js +192 -0
  89. package/lib/math/spotMarket.d.ts +4 -0
  90. package/lib/math/spotMarket.js +8 -0
  91. package/lib/math/spotPosition.d.ts +6 -0
  92. package/lib/math/spotPosition.js +23 -0
  93. package/lib/math/trade.d.ts +10 -10
  94. package/lib/math/trade.js +27 -31
  95. package/lib/oracles/pythClient.js +1 -1
  96. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  97. package/lib/oracles/switchboardClient.js +1 -1
  98. package/lib/orderParams.d.ts +4 -4
  99. package/lib/orderParams.js +12 -4
  100. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  101. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  102. package/lib/serum/serumSubscriber.d.ts +27 -0
  103. package/lib/serum/serumSubscriber.js +56 -0
  104. package/lib/serum/types.d.ts +11 -0
  105. package/{src/oracles → lib/serum}/types.js +0 -0
  106. package/lib/tokenFaucet.d.ts +1 -0
  107. package/lib/tokenFaucet.js +23 -12
  108. package/lib/tx/retryTxSender.d.ts +1 -1
  109. package/lib/tx/retryTxSender.js +13 -4
  110. package/lib/tx/types.d.ts +1 -1
  111. package/lib/types.d.ts +631 -222
  112. package/lib/types.js +137 -24
  113. package/lib/user.d.ts +228 -0
  114. package/lib/user.js +959 -0
  115. package/lib/userConfig.d.ts +14 -0
  116. package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
  117. package/lib/userMap/userMap.d.ts +41 -0
  118. package/lib/userMap/userMap.js +85 -0
  119. package/lib/userMap/userStatsMap.d.ts +19 -0
  120. package/lib/userMap/userStatsMap.js +68 -0
  121. package/lib/userName.d.ts +1 -0
  122. package/lib/userName.js +3 -2
  123. package/lib/userStats.d.ts +18 -0
  124. package/lib/userStats.js +49 -0
  125. package/lib/userStatsConfig.d.ts +14 -0
  126. package/{src/clearingHouseConfig.js → lib/userStatsConfig.js} +0 -0
  127. package/lib/util/getTokenAddress.d.ts +2 -0
  128. package/lib/util/getTokenAddress.js +9 -0
  129. package/package.json +12 -5
  130. package/src/accounts/bulkAccountLoader.ts +44 -34
  131. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  132. package/src/accounts/bulkUserSubscription.ts +2 -3
  133. package/src/accounts/fetch.ts +27 -2
  134. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  135. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  136. package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
  137. package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
  138. package/src/accounts/types.ts +35 -15
  139. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  140. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  141. package/src/addresses/marketAddresses.ts +3 -4
  142. package/src/addresses/pda.ts +105 -33
  143. package/src/adminClient.ts +1207 -0
  144. package/src/config.ts +41 -34
  145. package/src/constants/numericConstants.ts +59 -26
  146. package/src/constants/{markets.ts → perpMarkets.ts} +22 -11
  147. package/src/constants/spotMarkets.ts +83 -0
  148. package/src/dlob/DLOB.ts +1120 -0
  149. package/src/dlob/DLOBNode.ts +155 -0
  150. package/src/dlob/NodeList.ts +195 -0
  151. package/src/driftClient.ts +3594 -0
  152. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  153. package/src/events/eventList.ts +1 -8
  154. package/src/events/eventSubscriber.ts +36 -14
  155. package/src/events/fetchLogs.ts +60 -15
  156. package/src/events/pollingLogProvider.ts +11 -3
  157. package/src/events/sort.ts +11 -15
  158. package/src/events/txEventCache.ts +0 -16
  159. package/src/events/types.ts +27 -2
  160. package/src/events/webSocketLogProvider.ts +1 -1
  161. package/src/examples/makeTradeExample.js +152 -75
  162. package/src/examples/makeTradeExample.ts +44 -28
  163. package/src/factory/bigNum.ts +150 -22
  164. package/src/idl/drift.json +8392 -0
  165. package/src/idl/pyth.json +98 -2
  166. package/src/index.ts +29 -12
  167. package/src/math/amm.ts +161 -48
  168. package/src/math/conversion.ts +2 -2
  169. package/src/math/exchangeStatus.ts +31 -0
  170. package/src/math/funding.ts +41 -31
  171. package/src/math/insurance.ts +35 -0
  172. package/src/math/margin.ts +133 -0
  173. package/src/math/market.ts +143 -14
  174. package/src/math/oracles.ts +63 -9
  175. package/src/math/orders.ts +168 -26
  176. package/src/math/position.ts +133 -59
  177. package/src/math/repeg.ts +19 -9
  178. package/src/math/spotBalance.ts +319 -0
  179. package/src/math/spotMarket.ts +9 -0
  180. package/src/math/spotPosition.ts +47 -0
  181. package/src/math/trade.ts +33 -37
  182. package/src/oracles/pythClient.ts +2 -2
  183. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  184. package/src/oracles/switchboardClient.ts +2 -2
  185. package/src/orderParams.ts +16 -8
  186. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  187. package/src/serum/serumSubscriber.ts +99 -0
  188. package/src/serum/types.ts +13 -0
  189. package/src/tokenFaucet.ts +38 -15
  190. package/src/tx/retryTxSender.ts +16 -5
  191. package/src/tx/types.ts +2 -1
  192. package/src/types.ts +594 -195
  193. package/src/user.ts +1599 -0
  194. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  195. package/src/userMap/userMap.ts +124 -0
  196. package/src/userMap/userStatsMap.ts +108 -0
  197. package/src/userName.ts +2 -1
  198. package/src/userStats.ts +75 -0
  199. package/src/userStatsConfig.ts +18 -0
  200. package/src/util/getTokenAddress.ts +18 -0
  201. package/tests/bn/test.ts +46 -11
  202. package/tests/dlob/helpers.ts +619 -0
  203. package/tests/dlob/test.ts +4586 -0
  204. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  205. package/lib/admin.d.ts +0 -44
  206. package/lib/admin.js +0 -438
  207. package/lib/clearingHouse.d.ts +0 -146
  208. package/lib/clearingHouse.js +0 -1154
  209. package/lib/clearingHouseUser.d.ts +0 -187
  210. package/lib/clearingHouseUser.js +0 -634
  211. package/lib/clearingHouseUserConfig.d.ts +0 -14
  212. package/lib/constants/banks.d.ts +0 -16
  213. package/lib/constants/banks.js +0 -41
  214. package/lib/constants/markets.d.ts +0 -19
  215. package/lib/idl/clearing_house.json +0 -4464
  216. package/lib/math/bankBalance.d.ts +0 -9
  217. package/lib/math/bankBalance.js +0 -75
  218. package/lib/math/state.d.ts +0 -8
  219. package/lib/math/state.js +0 -15
  220. package/lib/orders.d.ts +0 -8
  221. package/lib/orders.js +0 -134
  222. package/src/accounts/bulkAccountLoader.js +0 -197
  223. package/src/accounts/bulkUserSubscription.js +0 -33
  224. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
  225. package/src/accounts/pollingOracleSubscriber.js +0 -93
  226. package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
  227. package/src/accounts/pollingUserAccountSubscriber.js +0 -132
  228. package/src/accounts/types.js +0 -10
  229. package/src/accounts/utils.js +0 -7
  230. package/src/accounts/webSocketAccountSubscriber.js +0 -93
  231. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
  232. package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
  233. package/src/addresses/marketAddresses.js +0 -26
  234. package/src/admin.js +0 -517
  235. package/src/admin.ts +0 -730
  236. package/src/clearingHouse.ts +0 -1828
  237. package/src/clearingHouseUser.ts +0 -978
  238. package/src/clearingHouseUserConfig.js +0 -2
  239. package/src/config.js +0 -67
  240. package/src/constants/banks.js +0 -42
  241. package/src/constants/banks.ts +0 -50
  242. package/src/constants/markets.js +0 -42
  243. package/src/constants/numericConstants.js +0 -41
  244. package/src/events/eventSubscriber.js +0 -139
  245. package/src/events/fetchLogs.js +0 -50
  246. package/src/events/pollingLogProvider.js +0 -64
  247. package/src/events/sort.js +0 -44
  248. package/src/events/txEventCache.js +0 -71
  249. package/src/events/types.js +0 -20
  250. package/src/events/webSocketLogProvider.js +0 -41
  251. package/src/factory/bigNum.js +0 -390
  252. package/src/factory/oracleClient.js +0 -20
  253. package/src/idl/clearing_house.json +0 -4464
  254. package/src/index.js +0 -69
  255. package/src/math/amm.js +0 -369
  256. package/src/math/auction.js +0 -42
  257. package/src/math/bankBalance.ts +0 -112
  258. package/src/math/conversion.js +0 -11
  259. package/src/math/funding.js +0 -248
  260. package/src/math/oracles.js +0 -26
  261. package/src/math/repeg.js +0 -128
  262. package/src/math/state.js +0 -15
  263. package/src/math/state.ts +0 -14
  264. package/src/math/trade.js +0 -253
  265. package/src/math/utils.js +0 -26
  266. package/src/math/utils.js.map +0 -1
  267. package/src/mockUSDCFaucet.js +0 -280
  268. package/src/oracles/oracleClientCache.js +0 -19
  269. package/src/oracles/pythClient.js +0 -46
  270. package/src/oracles/quoteAssetOracleClient.js +0 -32
  271. package/src/oracles/switchboardClient.js +0 -69
  272. package/src/orderParams.js +0 -20
  273. package/src/orders.ts +0 -245
  274. package/src/slot/SlotSubscriber.js +0 -39
  275. package/src/tokenFaucet.js +0 -189
  276. package/src/types.js +0 -125
  277. package/src/userName.js +0 -20
  278. package/src/wallet.js +0 -35
@@ -0,0 +1,637 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AdminClient = void 0;
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const types_1 = require("./types");
29
+ const userName_1 = require("./userName");
30
+ const anchor_1 = require("@project-serum/anchor");
31
+ const anchor = __importStar(require("@project-serum/anchor"));
32
+ const pda_1 = require("./addresses/pda");
33
+ const utils_1 = require("./math/utils");
34
+ const spl_token_1 = require("@solana/spl-token");
35
+ const driftClient_1 = require("./driftClient");
36
+ const numericConstants_1 = require("./constants/numericConstants");
37
+ const trade_1 = require("./math/trade");
38
+ const amm_1 = require("./math/amm");
39
+ class AdminClient extends driftClient_1.DriftClient {
40
+ async initialize(usdcMint, _adminControlsPrices) {
41
+ const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
42
+ if (stateAccountRPCResponse.value !== null) {
43
+ throw new Error('Clearing house already initialized');
44
+ }
45
+ const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
46
+ const initializeTx = await this.program.transaction.initialize({
47
+ accounts: {
48
+ admin: this.wallet.publicKey,
49
+ state: driftStatePublicKey,
50
+ quoteAssetMint: usdcMint,
51
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
52
+ driftSigner: this.getSignerPublicKey(),
53
+ systemProgram: anchor.web3.SystemProgram.programId,
54
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
55
+ },
56
+ });
57
+ const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
58
+ return [initializeTxSig];
59
+ }
60
+ async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
61
+ const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
62
+ const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
63
+ const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
64
+ const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
65
+ const nameBuffer = (0, userName_1.encodeName)(name);
66
+ const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
67
+ accounts: {
68
+ admin: this.wallet.publicKey,
69
+ state: await this.getStatePublicKey(),
70
+ spotMarket,
71
+ spotMarketVault,
72
+ insuranceFundVault,
73
+ driftSigner: this.getSignerPublicKey(),
74
+ spotMarketMint: mint,
75
+ oracle,
76
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
77
+ systemProgram: anchor.web3.SystemProgram.programId,
78
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
79
+ },
80
+ });
81
+ const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
82
+ await this.accountSubscriber.addSpotMarket(spotMarketIndex);
83
+ await this.accountSubscriber.addOracle({
84
+ source: oracleSource,
85
+ publicKey: oracle,
86
+ });
87
+ return txSig;
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
+ driftSigner: 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
+ }
108
+ async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
109
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
110
+ const nameBuffer = (0, userName_1.encodeName)(name);
111
+ const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
112
+ accounts: {
113
+ state: await this.getStatePublicKey(),
114
+ admin: this.wallet.publicKey,
115
+ oracle: priceOracle,
116
+ perpMarket: perpMarketPublicKey,
117
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
118
+ systemProgram: anchor.web3.SystemProgram.programId,
119
+ },
120
+ });
121
+ const { txSig } = await this.txSender.send(initializeMarketTx, [], this.opts);
122
+ await this.accountSubscriber.addPerpMarket(this.getStateAccount().numberOfMarkets);
123
+ await this.accountSubscriber.addOracle({
124
+ source: oracleSource,
125
+ publicKey: priceOracle,
126
+ });
127
+ return txSig;
128
+ }
129
+ async moveAmmPrice(perpMarketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
130
+ const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
131
+ if (sqrtK == undefined) {
132
+ sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
133
+ }
134
+ return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
135
+ accounts: {
136
+ state: await this.getStatePublicKey(),
137
+ admin: this.wallet.publicKey,
138
+ perpMarket: marketPublicKey,
139
+ },
140
+ });
141
+ }
142
+ async updateK(perpMarketIndex, sqrtK) {
143
+ return await this.program.rpc.updateK(sqrtK, {
144
+ accounts: {
145
+ state: await this.getStatePublicKey(),
146
+ admin: this.wallet.publicKey,
147
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
148
+ oracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
149
+ },
150
+ });
151
+ }
152
+ async updatePerpMarketConcentrationScale(perpMarketIndex, concentrationScale) {
153
+ return await this.program.rpc.updatePerpMarketConcentrationCoef(concentrationScale, {
154
+ accounts: {
155
+ state: await this.getStatePublicKey(),
156
+ admin: this.wallet.publicKey,
157
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
158
+ },
159
+ });
160
+ }
161
+ async moveAmmToPrice(perpMarketIndex, targetPrice) {
162
+ const perpMarket = this.getPerpMarketAccount(perpMarketIndex);
163
+ const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(perpMarket, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
164
+ );
165
+ const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(perpMarket.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
166
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
167
+ return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, perpMarket.amm.sqrtK, {
168
+ accounts: {
169
+ state: await this.getStatePublicKey(),
170
+ admin: this.wallet.publicKey,
171
+ perpMarket: perpMarketPublicKey,
172
+ },
173
+ });
174
+ }
175
+ async repegAmmCurve(newPeg, perpMarketIndex) {
176
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
177
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
178
+ return await this.program.rpc.repegAmmCurve(newPeg, {
179
+ accounts: {
180
+ state: await this.getStatePublicKey(),
181
+ admin: this.wallet.publicKey,
182
+ oracle: ammData.oracle,
183
+ perpMarket: perpMarketPublicKey,
184
+ },
185
+ });
186
+ }
187
+ async updatePerpMarketAmmOracleTwap(perpMarketIndex) {
188
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
189
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
190
+ return await this.program.rpc.updatePerpMarketAmmOracleTwap({
191
+ accounts: {
192
+ state: await this.getStatePublicKey(),
193
+ admin: this.wallet.publicKey,
194
+ oracle: ammData.oracle,
195
+ perpMarket: perpMarketPublicKey,
196
+ },
197
+ });
198
+ }
199
+ async resetPerpMarketAmmOracleTwap(perpMarketIndex) {
200
+ const ammData = this.getPerpMarketAccount(perpMarketIndex).amm;
201
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
202
+ return await this.program.rpc.resetPerpMarketAmmOracleTwap({
203
+ accounts: {
204
+ state: await this.getStatePublicKey(),
205
+ admin: this.wallet.publicKey,
206
+ oracle: ammData.oracle,
207
+ perpMarket: perpMarketPublicKey,
208
+ },
209
+ });
210
+ }
211
+ async depositIntoPerpMarketFeePool(perpMarketIndex, amount, sourceVault) {
212
+ const spotMarket = this.getQuoteSpotMarketAccount();
213
+ return await this.program.rpc.depositIntoPerpMarketFeePool(amount, {
214
+ accounts: {
215
+ admin: this.wallet.publicKey,
216
+ state: await this.getStatePublicKey(),
217
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
218
+ sourceVault,
219
+ driftSigner: this.getSignerPublicKey(),
220
+ quoteSpotMarket: spotMarket.pubkey,
221
+ spotMarketVault: spotMarket.vault,
222
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
223
+ },
224
+ });
225
+ }
226
+ async updateAdmin(admin) {
227
+ return await this.program.rpc.updateAdmin(admin, {
228
+ accounts: {
229
+ admin: this.wallet.publicKey,
230
+ state: await this.getStatePublicKey(),
231
+ },
232
+ });
233
+ }
234
+ async updatePerpMarketCurveUpdateIntensity(perpMarketIndex, curveUpdateIntensity) {
235
+ // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
236
+ // assert(Number.isInteger(curveUpdateIntensity));
237
+ return await this.program.rpc.updatePerpMarketCurveUpdateIntensity(curveUpdateIntensity, {
238
+ accounts: {
239
+ admin: this.wallet.publicKey,
240
+ state: await this.getStatePublicKey(),
241
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
242
+ },
243
+ });
244
+ }
245
+ async updatePerpMarketMarginRatio(perpMarketIndex, marginRatioInitial, marginRatioMaintenance) {
246
+ return await this.program.rpc.updatePerpMarketMarginRatio(marginRatioInitial, marginRatioMaintenance, {
247
+ accounts: {
248
+ admin: this.wallet.publicKey,
249
+ state: await this.getStatePublicKey(),
250
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
251
+ },
252
+ });
253
+ }
254
+ async updatePerpMarketImfFactor(perpMarketIndex, imfFactor, unrealizedPnlImfFactor) {
255
+ return await this.program.rpc.updatePerpMarketImfFactor(imfFactor, unrealizedPnlImfFactor, {
256
+ accounts: {
257
+ admin: this.wallet.publicKey,
258
+ state: await this.getStatePublicKey(),
259
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
260
+ },
261
+ });
262
+ }
263
+ async updatePerpMarketBaseSpread(perpMarketIndex, baseSpread) {
264
+ return await this.program.rpc.updatePerpMarketBaseSpread(baseSpread, {
265
+ accounts: {
266
+ admin: this.wallet.publicKey,
267
+ state: await this.getStatePublicKey(),
268
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
269
+ },
270
+ });
271
+ }
272
+ async updateAmmJitIntensity(perpMarketIndex, ammJitIntensity) {
273
+ return await this.program.rpc.updateAmmJitIntensity(ammJitIntensity, {
274
+ accounts: {
275
+ admin: this.wallet.publicKey,
276
+ state: await this.getStatePublicKey(),
277
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
278
+ },
279
+ });
280
+ }
281
+ async updatePerpMarketName(perpMarketIndex, name) {
282
+ const nameBuffer = (0, userName_1.encodeName)(name);
283
+ return await this.program.rpc.updatePerpMarketName(nameBuffer, {
284
+ accounts: {
285
+ admin: this.wallet.publicKey,
286
+ state: await this.getStatePublicKey(),
287
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
288
+ },
289
+ });
290
+ }
291
+ async updateSpotMarketName(spotMarketIndex, name) {
292
+ const nameBuffer = (0, userName_1.encodeName)(name);
293
+ return await this.program.rpc.updateSpotMarketName(nameBuffer, {
294
+ accounts: {
295
+ admin: this.wallet.publicKey,
296
+ state: await this.getStatePublicKey(),
297
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
298
+ },
299
+ });
300
+ }
301
+ async updatePerpMarketMaxSpread(perpMarketIndex, maxSpread) {
302
+ const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
303
+ return await this.program.rpc.updatePerpMarketMaxSpread(maxSpread, {
304
+ accounts: {
305
+ admin: this.wallet.publicKey,
306
+ state: await this.getStatePublicKey(),
307
+ perpMarket: perpMarketPublicKey,
308
+ },
309
+ });
310
+ }
311
+ async updatePerpFeeStructure(feeStructure) {
312
+ return await this.program.rpc.updatePerpFeeStructure(feeStructure, {
313
+ accounts: {
314
+ admin: this.wallet.publicKey,
315
+ state: await this.getStatePublicKey(),
316
+ },
317
+ });
318
+ }
319
+ async updateSpotFeeStructure(feeStructure) {
320
+ return await this.program.rpc.updateSpotFeeStructure(feeStructure, {
321
+ accounts: {
322
+ admin: this.wallet.publicKey,
323
+ state: await this.getStatePublicKey(),
324
+ },
325
+ });
326
+ }
327
+ async updateOracleGuardRails(oracleGuardRails) {
328
+ return await this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
329
+ accounts: {
330
+ admin: this.wallet.publicKey,
331
+ state: await this.getStatePublicKey(),
332
+ },
333
+ });
334
+ }
335
+ async updateStateSettlementDuration(settlementDuration) {
336
+ return await this.program.rpc.updateStateSettlementDuration(settlementDuration, {
337
+ accounts: {
338
+ admin: this.wallet.publicKey,
339
+ state: await this.getStatePublicKey(),
340
+ },
341
+ });
342
+ }
343
+ async updateWithdrawGuardThreshold(spotMarketIndex, withdrawGuardThreshold) {
344
+ return await this.program.rpc.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
345
+ accounts: {
346
+ admin: this.wallet.publicKey,
347
+ state: await this.getStatePublicKey(),
348
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
349
+ },
350
+ });
351
+ }
352
+ async updateSpotMarketIfFactor(spotMarketIndex, userIfFactor, totalIfFactor) {
353
+ return await this.program.rpc.updateSpotMarketIfFactor(spotMarketIndex, userIfFactor, totalIfFactor, {
354
+ accounts: {
355
+ admin: this.wallet.publicKey,
356
+ state: await this.getStatePublicKey(),
357
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
358
+ },
359
+ });
360
+ }
361
+ async updateSpotMarketRevenueSettlePeriod(spotMarketIndex, revenueSettlePeriod) {
362
+ return await this.program.rpc.updateSpotMarketRevenueSettlePeriod(revenueSettlePeriod, {
363
+ accounts: {
364
+ admin: this.wallet.publicKey,
365
+ state: await this.getStatePublicKey(),
366
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
367
+ },
368
+ });
369
+ }
370
+ async updateSpotMarketMaxTokenDeposits(spotMarketIndex, maxTokenDeposits) {
371
+ return await this.program.rpc.updateSpotMarketMaxTokenDeposits(maxTokenDeposits, {
372
+ accounts: {
373
+ admin: this.wallet.publicKey,
374
+ state: await this.getStatePublicKey(),
375
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
376
+ },
377
+ });
378
+ }
379
+ async updateInsuranceFundUnstakingPeriod(spotMarketIndex, insuranceWithdrawEscrowPeriod) {
380
+ return await this.program.rpc.updateInsuranceFundUnstakingPeriod(insuranceWithdrawEscrowPeriod, {
381
+ accounts: {
382
+ admin: this.wallet.publicKey,
383
+ state: await this.getStatePublicKey(),
384
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
385
+ },
386
+ });
387
+ }
388
+ async updateLpCooldownTime(cooldownTime) {
389
+ return await this.program.rpc.updateLpCooldownTime(cooldownTime, {
390
+ accounts: {
391
+ admin: this.wallet.publicKey,
392
+ state: await this.getStatePublicKey(),
393
+ },
394
+ });
395
+ }
396
+ async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource) {
397
+ return await this.program.rpc.updatePerpMarketOracle(oracle, oracleSource, {
398
+ accounts: {
399
+ admin: this.wallet.publicKey,
400
+ state: await this.getStatePublicKey(),
401
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
402
+ oracle: oracle,
403
+ },
404
+ });
405
+ }
406
+ async updatePerpMarketStepSizeAndTickSize(perpMarketIndex, stepSize, tickSize) {
407
+ return await this.program.rpc.updatePerpMarketStepSizeAndTickSize(stepSize, tickSize, {
408
+ accounts: {
409
+ admin: this.wallet.publicKey,
410
+ state: await this.getStatePublicKey(),
411
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
412
+ },
413
+ });
414
+ }
415
+ async updatePerpMarketMinOrderSize(perpMarketIndex, orderSize) {
416
+ return await this.program.rpc.updatePerpMarketMinOrderSize(orderSize, {
417
+ accounts: {
418
+ admin: this.wallet.publicKey,
419
+ state: await this.getStatePublicKey(),
420
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
421
+ },
422
+ });
423
+ }
424
+ async updateSpotMarketStepSizeAndTickSize(spotMarketIndex, stepSize, tickSize) {
425
+ return await this.program.rpc.updateSpotMarketStepSizeAndTickSize(stepSize, tickSize, {
426
+ accounts: {
427
+ admin: this.wallet.publicKey,
428
+ state: await this.getStatePublicKey(),
429
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
430
+ },
431
+ });
432
+ }
433
+ async updateSpotMarketMinOrderSize(spotMarketIndex, orderSize) {
434
+ return await this.program.rpc.updateSpotMarketMinOrderSize(orderSize, {
435
+ accounts: {
436
+ admin: this.wallet.publicKey,
437
+ state: await this.getStatePublicKey(),
438
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
439
+ },
440
+ });
441
+ }
442
+ async updatePerpMarketExpiry(perpMarketIndex, expiryTs) {
443
+ return await this.program.rpc.updatePerpMarketExpiry(expiryTs, {
444
+ accounts: {
445
+ admin: this.wallet.publicKey,
446
+ state: await this.getStatePublicKey(),
447
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
448
+ },
449
+ });
450
+ }
451
+ async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource) {
452
+ return await this.program.rpc.updatePerpMarketOracle(oracle, oracleSource, {
453
+ accounts: {
454
+ admin: this.wallet.publicKey,
455
+ state: await this.getStatePublicKey(),
456
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
457
+ oracle: oracle,
458
+ },
459
+ });
460
+ }
461
+ async updateSpotMarketExpiry(spotMarketIndex, expiryTs) {
462
+ return await this.program.rpc.updateSpotMarketExpiry(expiryTs, {
463
+ accounts: {
464
+ admin: this.wallet.publicKey,
465
+ state: await this.getStatePublicKey(),
466
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
467
+ },
468
+ });
469
+ }
470
+ async updateWhitelistMint(whitelistMint) {
471
+ return await this.program.rpc.updateWhitelistMint(whitelistMint, {
472
+ accounts: {
473
+ admin: this.wallet.publicKey,
474
+ state: await this.getStatePublicKey(),
475
+ },
476
+ });
477
+ }
478
+ async updateDiscountMint(discountMint) {
479
+ return await this.program.rpc.updateDiscountMint(discountMint, {
480
+ accounts: {
481
+ admin: this.wallet.publicKey,
482
+ state: await this.getStatePublicKey(),
483
+ },
484
+ });
485
+ }
486
+ async updateSpotMarketMarginWeights(spotMarketIndex, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0) {
487
+ return await this.program.rpc.updateSpotMarketMarginWeights(initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, {
488
+ accounts: {
489
+ admin: this.wallet.publicKey,
490
+ state: await this.getStatePublicKey(),
491
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
492
+ },
493
+ });
494
+ }
495
+ async updateSpotMarketBorrowRate(spotMarketIndex, optimalUtilization, optimalBorrowRate, optimalMaxRate) {
496
+ return await this.program.rpc.updateSpotMarketBorrowRate(optimalUtilization, optimalBorrowRate, optimalMaxRate, {
497
+ accounts: {
498
+ admin: this.wallet.publicKey,
499
+ state: await this.getStatePublicKey(),
500
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
501
+ },
502
+ });
503
+ }
504
+ async updateSpotMarketAssetTier(spotMarketIndex, assetTier) {
505
+ return await this.program.rpc.updateSpotMarketAssetTier(assetTier, {
506
+ accounts: {
507
+ admin: this.wallet.publicKey,
508
+ state: await this.getStatePublicKey(),
509
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
510
+ },
511
+ });
512
+ }
513
+ async updateSpotMarketStatus(spotMarketIndex, marketStatus) {
514
+ return await this.program.rpc.updateSpotMarketStatus(marketStatus, {
515
+ accounts: {
516
+ admin: this.wallet.publicKey,
517
+ state: await this.getStatePublicKey(),
518
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
519
+ },
520
+ });
521
+ }
522
+ async updatePerpMarketStatus(perpMarketIndex, marketStatus) {
523
+ return await this.program.rpc.updatePerpMarketStatus(marketStatus, {
524
+ accounts: {
525
+ admin: this.wallet.publicKey,
526
+ state: await this.getStatePublicKey(),
527
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
528
+ },
529
+ });
530
+ }
531
+ async updatePerpMarketContractTier(perpMarketIndex, contractTier) {
532
+ return await this.program.rpc.updatePerpMarketContractTier(contractTier, {
533
+ accounts: {
534
+ admin: this.wallet.publicKey,
535
+ state: await this.getStatePublicKey(),
536
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
537
+ },
538
+ });
539
+ }
540
+ async updateExchangeStatus(exchangeStatus) {
541
+ return await this.program.rpc.updateExchangeStatus(exchangeStatus, {
542
+ accounts: {
543
+ admin: this.wallet.publicKey,
544
+ state: await this.getStatePublicKey(),
545
+ },
546
+ });
547
+ }
548
+ async updatePerpAuctionDuration(minDuration) {
549
+ return await this.program.rpc.updatePerpAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), {
550
+ accounts: {
551
+ admin: this.wallet.publicKey,
552
+ state: await this.getStatePublicKey(),
553
+ },
554
+ });
555
+ }
556
+ async updateSpotAuctionDuration(defaultAuctionDuration) {
557
+ return await this.program.rpc.updateSpotAuctionDuration(defaultAuctionDuration, {
558
+ accounts: {
559
+ admin: this.wallet.publicKey,
560
+ state: await this.getStatePublicKey(),
561
+ },
562
+ });
563
+ }
564
+ async updatePerpMarketMaxFillReserveFraction(perpMarketIndex, maxBaseAssetAmountRatio) {
565
+ return await this.program.rpc.updatePerpMarketMaxFillReserveFraction(maxBaseAssetAmountRatio, {
566
+ accounts: {
567
+ admin: this.wallet.publicKey,
568
+ state: await this.getStatePublicKey(),
569
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
570
+ },
571
+ });
572
+ }
573
+ async updateMaxSlippageRatio(perpMarketIndex, maxSlippageRatio) {
574
+ return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
575
+ accounts: {
576
+ admin: this.wallet.publicKey,
577
+ state: await this.getStatePublicKey(),
578
+ perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey,
579
+ },
580
+ });
581
+ }
582
+ async updatePerpMarketUnrealizedAssetWeight(perpMarketIndex, unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight) {
583
+ return await this.program.rpc.updatePerpMarketUnrealizedAssetWeight(unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight, {
584
+ accounts: {
585
+ admin: this.wallet.publicKey,
586
+ state: await this.getStatePublicKey(),
587
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
588
+ },
589
+ });
590
+ }
591
+ async updatePerpMarketMaxImbalances(perpMarketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
592
+ return await this.program.rpc.updatePerpMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
593
+ accounts: {
594
+ admin: this.wallet.publicKey,
595
+ state: await this.getStatePublicKey(),
596
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
597
+ },
598
+ });
599
+ }
600
+ async updatePerpMarketMaxOpenInterest(perpMarketIndex, maxOpenInterest) {
601
+ return await this.program.rpc.updatePerpMarketMaxOpenInterest(maxOpenInterest, {
602
+ accounts: {
603
+ admin: this.wallet.publicKey,
604
+ state: await this.getStatePublicKey(),
605
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
606
+ },
607
+ });
608
+ }
609
+ async updateSerumVault(srmVault) {
610
+ return await this.program.rpc.updateSerumVault({
611
+ accounts: {
612
+ admin: this.wallet.publicKey,
613
+ state: await this.getStatePublicKey(),
614
+ srmVault: srmVault,
615
+ },
616
+ });
617
+ }
618
+ async updatePerpMarketLiquidationFee(perpMarketIndex, liquidatorFee, ifLiquidationFee) {
619
+ return await this.program.rpc.updatePerpMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
620
+ accounts: {
621
+ admin: this.wallet.publicKey,
622
+ state: await this.getStatePublicKey(),
623
+ perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
624
+ },
625
+ });
626
+ }
627
+ async updateSpotMarketLiquidationFee(spotMarketIndex, liquidatorFee, ifLiquidationFee) {
628
+ return await this.program.rpc.updateSpotMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
629
+ accounts: {
630
+ admin: this.wallet.publicKey,
631
+ state: await this.getStatePublicKey(),
632
+ spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
633
+ },
634
+ });
635
+ }
636
+ }
637
+ exports.AdminClient = AdminClient;
package/lib/config.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- /// <reference types="bn.js" />
2
- import { MarketConfig } from './constants/markets';
3
- import { BankConfig } from './constants/banks';
4
- import { BN } from '@project-serum/anchor';
1
+ import { PerpMarketConfig } from './constants/perpMarkets';
2
+ import { SpotMarketConfig } from './constants/spotMarkets';
5
3
  import { OracleInfo } from './oracles/types';
6
4
  declare type DriftConfig = {
7
5
  ENV: DriftEnv;
8
6
  PYTH_ORACLE_MAPPING_ADDRESS: string;
9
- CLEARING_HOUSE_PROGRAM_ID: string;
7
+ DRIFT_PROGRAM_ID: string;
10
8
  USDC_MINT_ADDRESS: string;
11
- MARKETS: MarketConfig[];
12
- BANKS: BankConfig[];
9
+ SERUM_V3: string;
10
+ V2_ALPHA_TICKET_MINT_ADDRESS: string;
11
+ PERP_MARKETS: PerpMarketConfig[];
12
+ SPOT_MARKETS: SpotMarketConfig[];
13
13
  };
14
14
  export declare type DriftEnv = 'devnet' | 'mainnet-beta';
15
15
  export declare const configs: {
@@ -27,9 +27,9 @@ export declare const initialize: (props: {
27
27
  env: DriftEnv;
28
28
  overrideEnv?: Partial<DriftConfig>;
29
29
  }) => DriftConfig;
30
- export declare function getMarketsBanksAndOraclesForSubscription(env: DriftEnv): {
31
- marketIndexes: BN[];
32
- bankIndexes: BN[];
30
+ export declare function getMarketsAndOraclesForSubscription(env: DriftEnv): {
31
+ perpMarketIndexes: number[];
32
+ spotMarketIndexes: number[];
33
33
  oracleInfos: OracleInfo[];
34
34
  };
35
35
  export {};