@drift-labs/sdk 0.2.0-temp.1 → 2.0.0

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 (274) 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.js +3 -0
  48. package/lib/events/eventSubscriber.d.ts +5 -2
  49. package/lib/events/eventSubscriber.js +25 -11
  50. package/lib/events/fetchLogs.d.ts +13 -2
  51. package/lib/events/fetchLogs.js +45 -14
  52. package/lib/events/pollingLogProvider.d.ts +2 -1
  53. package/lib/events/pollingLogProvider.js +7 -3
  54. package/lib/events/sort.js +8 -11
  55. package/lib/events/types.d.ts +11 -3
  56. package/lib/events/types.js +8 -0
  57. package/lib/events/webSocketLogProvider.js +1 -1
  58. package/lib/examples/makeTradeExample.js +30 -18
  59. package/lib/factory/bigNum.d.ts +8 -4
  60. package/lib/factory/bigNum.js +109 -19
  61. package/lib/idl/drift.json +8392 -0
  62. package/lib/index.d.ts +29 -12
  63. package/lib/index.js +29 -12
  64. package/lib/math/amm.d.ts +9 -6
  65. package/lib/math/amm.js +91 -38
  66. package/lib/math/conversion.js +1 -1
  67. package/lib/math/exchangeStatus.d.ts +4 -0
  68. package/lib/math/exchangeStatus.js +18 -0
  69. package/lib/math/funding.d.ts +6 -6
  70. package/lib/math/funding.js +23 -21
  71. package/lib/math/insurance.d.ts +4 -0
  72. package/lib/math/insurance.js +27 -0
  73. package/lib/math/margin.d.ts +11 -0
  74. package/lib/math/margin.js +82 -0
  75. package/lib/math/market.d.ts +14 -9
  76. package/lib/math/market.js +70 -10
  77. package/lib/math/oracles.d.ts +4 -0
  78. package/lib/math/oracles.js +36 -8
  79. package/lib/math/orders.d.ts +16 -6
  80. package/lib/math/orders.js +97 -17
  81. package/lib/math/position.d.ts +27 -13
  82. package/lib/math/position.js +91 -37
  83. package/lib/math/repeg.js +17 -8
  84. package/lib/math/spotBalance.d.ts +22 -0
  85. package/lib/math/spotBalance.js +192 -0
  86. package/lib/math/spotMarket.d.ts +4 -0
  87. package/lib/math/spotMarket.js +8 -0
  88. package/lib/math/spotPosition.d.ts +6 -0
  89. package/lib/math/spotPosition.js +23 -0
  90. package/lib/math/trade.d.ts +10 -10
  91. package/lib/math/trade.js +27 -31
  92. package/lib/oracles/pythClient.js +1 -1
  93. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  94. package/lib/oracles/switchboardClient.js +1 -1
  95. package/lib/orderParams.d.ts +4 -4
  96. package/lib/orderParams.js +12 -4
  97. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  98. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  99. package/lib/serum/serumSubscriber.d.ts +27 -0
  100. package/lib/serum/serumSubscriber.js +56 -0
  101. package/lib/serum/types.d.ts +11 -0
  102. package/{src/oracles → lib/serum}/types.js +0 -0
  103. package/lib/tokenFaucet.d.ts +1 -0
  104. package/lib/tokenFaucet.js +23 -12
  105. package/lib/tx/retryTxSender.d.ts +1 -1
  106. package/lib/tx/retryTxSender.js +13 -4
  107. package/lib/tx/types.d.ts +1 -1
  108. package/lib/types.d.ts +631 -222
  109. package/lib/types.js +137 -24
  110. package/lib/user.d.ts +228 -0
  111. package/lib/user.js +959 -0
  112. package/lib/userConfig.d.ts +14 -0
  113. package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
  114. package/lib/userMap/userMap.d.ts +41 -0
  115. package/lib/userMap/userMap.js +85 -0
  116. package/lib/userMap/userStatsMap.d.ts +19 -0
  117. package/lib/userMap/userStatsMap.js +68 -0
  118. package/lib/userName.d.ts +1 -0
  119. package/lib/userName.js +3 -2
  120. package/lib/userStats.d.ts +18 -0
  121. package/lib/userStats.js +49 -0
  122. package/lib/userStatsConfig.d.ts +14 -0
  123. package/{src/clearingHouseConfig.js → lib/userStatsConfig.js} +0 -0
  124. package/lib/util/getTokenAddress.d.ts +2 -0
  125. package/lib/util/getTokenAddress.js +9 -0
  126. package/package.json +12 -5
  127. package/src/accounts/bulkAccountLoader.ts +44 -34
  128. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  129. package/src/accounts/bulkUserSubscription.ts +2 -3
  130. package/src/accounts/fetch.ts +27 -2
  131. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  132. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  133. package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
  134. package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
  135. package/src/accounts/types.ts +35 -15
  136. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  137. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  138. package/src/addresses/marketAddresses.ts +3 -4
  139. package/src/addresses/pda.ts +105 -33
  140. package/src/adminClient.ts +1207 -0
  141. package/src/config.ts +41 -34
  142. package/src/constants/numericConstants.ts +59 -26
  143. package/src/constants/{markets.ts → perpMarkets.ts} +22 -11
  144. package/src/constants/spotMarkets.ts +83 -0
  145. package/src/dlob/DLOB.ts +1120 -0
  146. package/src/dlob/DLOBNode.ts +155 -0
  147. package/src/dlob/NodeList.ts +195 -0
  148. package/src/driftClient.ts +3594 -0
  149. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  150. package/src/events/eventList.ts +3 -0
  151. package/src/events/eventSubscriber.ts +36 -14
  152. package/src/events/fetchLogs.ts +60 -15
  153. package/src/events/pollingLogProvider.ts +11 -3
  154. package/src/events/sort.ts +11 -15
  155. package/src/events/types.ts +27 -2
  156. package/src/events/webSocketLogProvider.ts +1 -1
  157. package/src/examples/makeTradeExample.js +152 -75
  158. package/src/examples/makeTradeExample.ts +44 -28
  159. package/src/factory/bigNum.ts +150 -22
  160. package/src/idl/drift.json +8392 -0
  161. package/src/idl/pyth.json +98 -2
  162. package/src/index.ts +29 -12
  163. package/src/math/amm.ts +161 -48
  164. package/src/math/conversion.ts +2 -2
  165. package/src/math/exchangeStatus.ts +31 -0
  166. package/src/math/funding.ts +41 -31
  167. package/src/math/insurance.ts +35 -0
  168. package/src/math/margin.ts +133 -0
  169. package/src/math/market.ts +143 -14
  170. package/src/math/oracles.ts +63 -9
  171. package/src/math/orders.ts +168 -26
  172. package/src/math/position.ts +133 -59
  173. package/src/math/repeg.ts +19 -9
  174. package/src/math/spotBalance.ts +319 -0
  175. package/src/math/spotMarket.ts +9 -0
  176. package/src/math/spotPosition.ts +47 -0
  177. package/src/math/trade.ts +33 -37
  178. package/src/oracles/pythClient.ts +2 -2
  179. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  180. package/src/oracles/switchboardClient.ts +2 -2
  181. package/src/orderParams.ts +16 -8
  182. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  183. package/src/serum/serumSubscriber.ts +99 -0
  184. package/src/serum/types.ts +13 -0
  185. package/src/tokenFaucet.ts +38 -15
  186. package/src/tx/retryTxSender.ts +16 -5
  187. package/src/tx/types.ts +2 -1
  188. package/src/types.ts +594 -195
  189. package/src/user.ts +1599 -0
  190. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  191. package/src/userMap/userMap.ts +124 -0
  192. package/src/userMap/userStatsMap.ts +108 -0
  193. package/src/userName.ts +2 -1
  194. package/src/userStats.ts +75 -0
  195. package/src/userStatsConfig.ts +18 -0
  196. package/src/util/getTokenAddress.ts +18 -0
  197. package/tests/bn/test.ts +46 -11
  198. package/tests/dlob/helpers.ts +619 -0
  199. package/tests/dlob/test.ts +4586 -0
  200. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  201. package/lib/admin.d.ts +0 -44
  202. package/lib/admin.js +0 -438
  203. package/lib/clearingHouse.d.ts +0 -146
  204. package/lib/clearingHouse.js +0 -1154
  205. package/lib/clearingHouseUser.d.ts +0 -187
  206. package/lib/clearingHouseUser.js +0 -634
  207. package/lib/clearingHouseUserConfig.d.ts +0 -14
  208. package/lib/constants/banks.d.ts +0 -16
  209. package/lib/constants/banks.js +0 -41
  210. package/lib/constants/markets.d.ts +0 -19
  211. package/lib/idl/clearing_house.json +0 -4464
  212. package/lib/math/bankBalance.d.ts +0 -9
  213. package/lib/math/bankBalance.js +0 -75
  214. package/lib/math/state.d.ts +0 -8
  215. package/lib/math/state.js +0 -15
  216. package/lib/orders.d.ts +0 -8
  217. package/lib/orders.js +0 -134
  218. package/src/accounts/bulkAccountLoader.js +0 -197
  219. package/src/accounts/bulkUserSubscription.js +0 -33
  220. package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
  221. package/src/accounts/pollingOracleSubscriber.js +0 -93
  222. package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
  223. package/src/accounts/pollingUserAccountSubscriber.js +0 -132
  224. package/src/accounts/types.js +0 -10
  225. package/src/accounts/utils.js +0 -7
  226. package/src/accounts/webSocketAccountSubscriber.js +0 -93
  227. package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
  228. package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
  229. package/src/addresses/marketAddresses.js +0 -26
  230. package/src/admin.js +0 -517
  231. package/src/admin.ts +0 -730
  232. package/src/clearingHouse.ts +0 -1828
  233. package/src/clearingHouseUser.ts +0 -978
  234. package/src/clearingHouseUserConfig.js +0 -2
  235. package/src/config.js +0 -67
  236. package/src/constants/banks.js +0 -42
  237. package/src/constants/banks.ts +0 -50
  238. package/src/constants/markets.js +0 -42
  239. package/src/constants/numericConstants.js +0 -41
  240. package/src/events/eventSubscriber.js +0 -139
  241. package/src/events/fetchLogs.js +0 -50
  242. package/src/events/pollingLogProvider.js +0 -64
  243. package/src/events/sort.js +0 -44
  244. package/src/events/txEventCache.js +0 -71
  245. package/src/events/types.js +0 -20
  246. package/src/events/webSocketLogProvider.js +0 -41
  247. package/src/factory/bigNum.js +0 -390
  248. package/src/factory/oracleClient.js +0 -20
  249. package/src/idl/clearing_house.json +0 -4464
  250. package/src/index.js +0 -69
  251. package/src/math/amm.js +0 -369
  252. package/src/math/auction.js +0 -42
  253. package/src/math/bankBalance.ts +0 -112
  254. package/src/math/conversion.js +0 -11
  255. package/src/math/funding.js +0 -248
  256. package/src/math/oracles.js +0 -26
  257. package/src/math/repeg.js +0 -128
  258. package/src/math/state.js +0 -15
  259. package/src/math/state.ts +0 -14
  260. package/src/math/trade.js +0 -253
  261. package/src/math/utils.js +0 -26
  262. package/src/math/utils.js.map +0 -1
  263. package/src/mockUSDCFaucet.js +0 -280
  264. package/src/oracles/oracleClientCache.js +0 -19
  265. package/src/oracles/pythClient.js +0 -46
  266. package/src/oracles/quoteAssetOracleClient.js +0 -32
  267. package/src/oracles/switchboardClient.js +0 -69
  268. package/src/orderParams.js +0 -20
  269. package/src/orders.ts +0 -245
  270. package/src/slot/SlotSubscriber.js +0 -39
  271. package/src/tokenFaucet.js +0 -189
  272. package/src/types.js +0 -125
  273. package/src/userName.js +0 -20
  274. package/src/wallet.js +0 -35
package/src/admin.js DELETED
@@ -1,517 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Admin = void 0;
32
- const web3_js_1 = require("@solana/web3.js");
33
- const types_1 = require("./types");
34
- const anchor_1 = require("@project-serum/anchor");
35
- const anchor = __importStar(require("@project-serum/anchor"));
36
- const pda_1 = require("./addresses/pda");
37
- const spl_token_1 = require("@solana/spl-token");
38
- const clearingHouse_1 = require("./clearingHouse");
39
- const numericConstants_1 = require("./constants/numericConstants");
40
- const trade_1 = require("./math/trade");
41
- const amm_1 = require("./math/amm");
42
- class Admin extends clearingHouse_1.ClearingHouse {
43
- initialize(usdcMint, adminControlsPrices) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const stateAccountRPCResponse = yield this.connection.getParsedAccountInfo(yield this.getStatePublicKey());
46
- if (stateAccountRPCResponse.value !== null) {
47
- throw new Error('Clearing house already initialized');
48
- }
49
- const [insuranceVaultPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
50
- const [insuranceVaultAuthority] = yield web3_js_1.PublicKey.findProgramAddress([insuranceVaultPublicKey.toBuffer()], this.program.programId);
51
- const [clearingHouseStatePublicKey] = yield pda_1.getClearingHouseStateAccountPublicKeyAndNonce(this.program.programId);
52
- const initializeTx = yield this.program.transaction.initialize(adminControlsPrices, {
53
- accounts: {
54
- admin: this.wallet.publicKey,
55
- state: clearingHouseStatePublicKey,
56
- quoteAssetMint: usdcMint,
57
- insuranceVault: insuranceVaultPublicKey,
58
- insuranceVaultAuthority: insuranceVaultAuthority,
59
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
60
- systemProgram: anchor.web3.SystemProgram.programId,
61
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
62
- },
63
- });
64
- const { txSig: initializeTxSig } = yield this.txSender.send(initializeTx, [], this.opts);
65
- return [initializeTxSig];
66
- });
67
- }
68
- initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const bankIndex = this.getStateAccount().numberOfBanks;
71
- const bank = yield pda_1.getBankPublicKey(this.program.programId, bankIndex);
72
- const bankVault = yield pda_1.getBankVaultPublicKey(this.program.programId, bankIndex);
73
- const bankVaultAuthority = yield pda_1.getBankVaultAuthorityPublicKey(this.program.programId, bankIndex);
74
- const initializeTx = yield this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
75
- accounts: {
76
- admin: this.wallet.publicKey,
77
- state: yield this.getStatePublicKey(),
78
- bank,
79
- bankVault,
80
- bankVaultAuthority,
81
- bankMint: mint,
82
- oracle,
83
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
84
- systemProgram: anchor.web3.SystemProgram.programId,
85
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
86
- },
87
- });
88
- const { txSig } = yield this.txSender.send(initializeTx, [], this.opts);
89
- yield this.accountSubscriber.addBank(bankIndex);
90
- yield this.accountSubscriber.addOracle({
91
- source: oracleSource,
92
- publicKey: oracle,
93
- });
94
- return txSig;
95
- });
96
- }
97
- initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO) {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, this.getStateAccount().numberOfMarkets);
100
- const initializeMarketTx = yield this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, {
101
- accounts: {
102
- state: yield this.getStatePublicKey(),
103
- admin: this.wallet.publicKey,
104
- oracle: priceOracle,
105
- market: marketPublicKey,
106
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
107
- systemProgram: anchor.web3.SystemProgram.programId,
108
- },
109
- });
110
- const { txSig } = yield this.txSender.send(initializeMarketTx, [], this.opts);
111
- yield this.accountSubscriber.addMarket(this.getStateAccount().numberOfMarkets);
112
- yield this.accountSubscriber.addOracle({
113
- source: oracleSource,
114
- publicKey: priceOracle,
115
- });
116
- return txSig;
117
- });
118
- }
119
- moveAmmPrice(baseAssetReserve, quoteAssetReserve, marketIndex) {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
122
- return yield this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, {
123
- accounts: {
124
- state: yield this.getStatePublicKey(),
125
- admin: this.wallet.publicKey,
126
- market: marketPublicKey,
127
- },
128
- });
129
- });
130
- }
131
- updateK(sqrtK, marketIndex) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- return yield this.program.rpc.updateK(sqrtK, {
134
- accounts: {
135
- state: yield this.getStatePublicKey(),
136
- admin: this.wallet.publicKey,
137
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
138
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
139
- },
140
- });
141
- });
142
- }
143
- moveAmmToPrice(marketIndex, targetPrice) {
144
- return __awaiter(this, void 0, void 0, function* () {
145
- const market = this.getMarketAccount(marketIndex);
146
- const [direction, tradeSize, _] = trade_1.calculateTargetPriceTrade(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
147
- );
148
- const [newQuoteAssetAmount, newBaseAssetAmount] = amm_1.calculateAmmReservesAfterSwap(market.amm, 'quote', tradeSize, amm_1.getSwapDirection('quote', direction));
149
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
150
- return yield this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
151
- accounts: {
152
- state: yield this.getStatePublicKey(),
153
- admin: this.wallet.publicKey,
154
- market: marketPublicKey,
155
- },
156
- });
157
- });
158
- }
159
- repegAmmCurve(newPeg, marketIndex) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
162
- const ammData = this.getMarketAccount(marketIndex).amm;
163
- return yield this.program.rpc.repegAmmCurve(newPeg, {
164
- accounts: {
165
- state: yield this.getStatePublicKey(),
166
- admin: this.wallet.publicKey,
167
- oracle: ammData.oracle,
168
- market: marketPublicKey,
169
- },
170
- });
171
- });
172
- }
173
- updateAmmOracleTwap(marketIndex) {
174
- return __awaiter(this, void 0, void 0, function* () {
175
- const ammData = this.getMarketAccount(marketIndex).amm;
176
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
177
- return yield this.program.rpc.updateAmmOracleTwap({
178
- accounts: {
179
- state: yield this.getStatePublicKey(),
180
- admin: this.wallet.publicKey,
181
- oracle: ammData.oracle,
182
- market: marketPublicKey,
183
- },
184
- });
185
- });
186
- }
187
- resetAmmOracleTwap(marketIndex) {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- const ammData = this.getMarketAccount(marketIndex).amm;
190
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
191
- return yield this.program.rpc.resetAmmOracleTwap({
192
- accounts: {
193
- state: yield this.getStatePublicKey(),
194
- admin: this.wallet.publicKey,
195
- oracle: ammData.oracle,
196
- market: marketPublicKey,
197
- },
198
- });
199
- });
200
- }
201
- withdrawFromInsuranceVault(amount, recipient) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- const state = yield this.getStateAccount();
204
- const bank = this.getQuoteAssetBankAccount();
205
- return yield this.program.rpc.withdrawFromInsuranceVault(amount, {
206
- accounts: {
207
- admin: this.wallet.publicKey,
208
- state: yield this.getStatePublicKey(),
209
- bank: bank.pubkey,
210
- insuranceVault: state.insuranceVault,
211
- insuranceVaultAuthority: state.insuranceVaultAuthority,
212
- recipient: recipient,
213
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
214
- },
215
- });
216
- });
217
- }
218
- withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
219
- return __awaiter(this, void 0, void 0, function* () {
220
- const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
221
- const bank = this.getQuoteAssetBankAccount();
222
- return yield this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
223
- accounts: {
224
- admin: this.wallet.publicKey,
225
- state: yield this.getStatePublicKey(),
226
- market: marketPublicKey,
227
- bank: bank.pubkey,
228
- bankVault: bank.vault,
229
- bankVaultAuthority: bank.vaultAuthority,
230
- recipient: recipient,
231
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
232
- },
233
- });
234
- });
235
- }
236
- withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- const state = yield this.getStateAccount();
239
- const bank = this.getQuoteAssetBankAccount();
240
- return yield this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
241
- accounts: {
242
- admin: this.wallet.publicKey,
243
- state: yield this.getStatePublicKey(),
244
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
245
- insuranceVault: state.insuranceVault,
246
- insuranceVaultAuthority: state.insuranceVaultAuthority,
247
- bank: bank.pubkey,
248
- bankVault: bank.vault,
249
- bankVaultAuthority: bank.vaultAuthority,
250
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
251
- },
252
- });
253
- });
254
- }
255
- updateAdmin(admin) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- return yield this.program.rpc.updateAdmin(admin, {
258
- accounts: {
259
- admin: this.wallet.publicKey,
260
- state: yield this.getStatePublicKey(),
261
- },
262
- });
263
- });
264
- }
265
- updateCurveUpdateIntensity(marketIndex, curveUpdateIntensity) {
266
- return __awaiter(this, void 0, void 0, function* () {
267
- // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
268
- // assert(Number.isInteger(curveUpdateIntensity));
269
- return yield this.program.rpc.updateCurveUpdateIntensity(curveUpdateIntensity, {
270
- accounts: {
271
- admin: this.wallet.publicKey,
272
- state: yield this.getStatePublicKey(),
273
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
274
- },
275
- });
276
- });
277
- }
278
- updateMarginRatio(marketIndex, marginRatioInitial, marginRatioMaintenance) {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- return yield this.program.rpc.updateMarginRatio(marginRatioInitial, marginRatioMaintenance, {
281
- accounts: {
282
- admin: this.wallet.publicKey,
283
- state: yield this.getStatePublicKey(),
284
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
285
- },
286
- });
287
- });
288
- }
289
- updateMarketBaseSpread(marketIndex, baseSpread) {
290
- return __awaiter(this, void 0, void 0, function* () {
291
- return yield this.program.rpc.updateMarketBaseSpread(baseSpread, {
292
- accounts: {
293
- admin: this.wallet.publicKey,
294
- state: yield this.getStatePublicKey(),
295
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
296
- },
297
- });
298
- });
299
- }
300
- updateMarketMaxSpread(marketIndex, maxSpread) {
301
- return __awaiter(this, void 0, void 0, function* () {
302
- return yield this.program.rpc.updateMarketMaxSpread(maxSpread, {
303
- accounts: {
304
- admin: this.wallet.publicKey,
305
- state: yield this.getStatePublicKey(),
306
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
307
- },
308
- });
309
- });
310
- }
311
- updatePartialLiquidationClosePercentage(numerator, denominator) {
312
- return __awaiter(this, void 0, void 0, function* () {
313
- return yield this.program.rpc.updatePartialLiquidationClosePercentage(numerator, denominator, {
314
- accounts: {
315
- admin: this.wallet.publicKey,
316
- state: yield this.getStatePublicKey(),
317
- },
318
- });
319
- });
320
- }
321
- updatePartialLiquidationPenaltyPercentage(numerator, denominator) {
322
- return __awaiter(this, void 0, void 0, function* () {
323
- return yield this.program.rpc.updatePartialLiquidationPenaltyPercentage(numerator, denominator, {
324
- accounts: {
325
- admin: this.wallet.publicKey,
326
- state: yield this.getStatePublicKey(),
327
- },
328
- });
329
- });
330
- }
331
- updateFullLiquidationPenaltyPercentage(numerator, denominator) {
332
- return __awaiter(this, void 0, void 0, function* () {
333
- return yield this.program.rpc.updateFullLiquidationPenaltyPercentage(numerator, denominator, {
334
- accounts: {
335
- admin: this.wallet.publicKey,
336
- state: yield this.getStatePublicKey(),
337
- },
338
- });
339
- });
340
- }
341
- updatePartialLiquidationShareDenominator(denominator) {
342
- return __awaiter(this, void 0, void 0, function* () {
343
- return yield this.program.rpc.updatePartialLiquidationLiquidatorShareDenominator(denominator, {
344
- accounts: {
345
- admin: this.wallet.publicKey,
346
- state: yield this.getStatePublicKey(),
347
- },
348
- });
349
- });
350
- }
351
- updateFullLiquidationShareDenominator(denominator) {
352
- return __awaiter(this, void 0, void 0, function* () {
353
- return yield this.program.rpc.updateFullLiquidationLiquidatorShareDenominator(denominator, {
354
- accounts: {
355
- admin: this.wallet.publicKey,
356
- state: yield this.getStatePublicKey(),
357
- },
358
- });
359
- });
360
- }
361
- updateOrderFillerRewardStructure(orderFillerRewardStructure) {
362
- return __awaiter(this, void 0, void 0, function* () {
363
- return yield this.program.rpc.updateOrderFillerRewardStructure(orderFillerRewardStructure, {
364
- accounts: {
365
- admin: this.wallet.publicKey,
366
- state: yield this.getStatePublicKey(),
367
- },
368
- });
369
- });
370
- }
371
- updateFee(fees) {
372
- return __awaiter(this, void 0, void 0, function* () {
373
- return yield this.program.rpc.updateFee(fees, {
374
- accounts: {
375
- admin: this.wallet.publicKey,
376
- state: yield this.getStatePublicKey(),
377
- },
378
- });
379
- });
380
- }
381
- updateOracleGuardRails(oracleGuardRails) {
382
- return __awaiter(this, void 0, void 0, function* () {
383
- return yield this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
384
- accounts: {
385
- admin: this.wallet.publicKey,
386
- state: yield this.getStatePublicKey(),
387
- },
388
- });
389
- });
390
- }
391
- updateMarketOracle(marketIndex, oracle, oracleSource) {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- return yield this.program.rpc.updateMarketOracle(oracle, oracleSource, {
394
- accounts: {
395
- admin: this.wallet.publicKey,
396
- state: yield this.getStatePublicKey(),
397
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
398
- },
399
- });
400
- });
401
- }
402
- updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize) {
403
- return __awaiter(this, void 0, void 0, function* () {
404
- return yield this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(minimumTradeSize, {
405
- accounts: {
406
- admin: this.wallet.publicKey,
407
- state: yield this.getStatePublicKey(),
408
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
409
- },
410
- });
411
- });
412
- }
413
- updateMarketBaseAssetAmountStepSize(marketIndex, stepSize) {
414
- return __awaiter(this, void 0, void 0, function* () {
415
- return yield this.program.rpc.updateMarketBaseAssetAmountStepSize(stepSize, {
416
- accounts: {
417
- admin: this.wallet.publicKey,
418
- state: yield this.getStatePublicKey(),
419
- market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
420
- },
421
- });
422
- });
423
- }
424
- updateWhitelistMint(whitelistMint) {
425
- return __awaiter(this, void 0, void 0, function* () {
426
- return yield this.program.rpc.updateWhitelistMint(whitelistMint, {
427
- accounts: {
428
- admin: this.wallet.publicKey,
429
- state: yield this.getStatePublicKey(),
430
- },
431
- });
432
- });
433
- }
434
- updateDiscountMint(discountMint) {
435
- return __awaiter(this, void 0, void 0, function* () {
436
- return yield this.program.rpc.updateDiscountMint(discountMint, {
437
- accounts: {
438
- admin: this.wallet.publicKey,
439
- state: yield this.getStatePublicKey(),
440
- },
441
- });
442
- });
443
- }
444
- updateMaxDeposit(maxDeposit) {
445
- return __awaiter(this, void 0, void 0, function* () {
446
- return yield this.program.rpc.updateMaxDeposit(maxDeposit, {
447
- accounts: {
448
- admin: this.wallet.publicKey,
449
- state: yield this.getStatePublicKey(),
450
- },
451
- });
452
- });
453
- }
454
- updateFundingPaused(fundingPaused) {
455
- return __awaiter(this, void 0, void 0, function* () {
456
- return yield this.program.rpc.updateFundingPaused(fundingPaused, {
457
- accounts: {
458
- admin: this.wallet.publicKey,
459
- state: yield this.getStatePublicKey(),
460
- },
461
- });
462
- });
463
- }
464
- updateExchangePaused(exchangePaused) {
465
- return __awaiter(this, void 0, void 0, function* () {
466
- return yield this.program.rpc.updateExchangePaused(exchangePaused, {
467
- accounts: {
468
- admin: this.wallet.publicKey,
469
- state: yield this.getStatePublicKey(),
470
- },
471
- });
472
- });
473
- }
474
- disableAdminControlsPrices() {
475
- return __awaiter(this, void 0, void 0, function* () {
476
- return yield this.program.rpc.disableAdminControlsPrices({
477
- accounts: {
478
- admin: this.wallet.publicKey,
479
- state: yield this.getStatePublicKey(),
480
- },
481
- });
482
- });
483
- }
484
- updateAuctionDuration(minDuration, maxDuration) {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- return yield this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
487
- accounts: {
488
- admin: this.wallet.publicKey,
489
- state: yield this.getStatePublicKey(),
490
- },
491
- });
492
- });
493
- }
494
- updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
495
- return __awaiter(this, void 0, void 0, function* () {
496
- return yield this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
497
- accounts: {
498
- admin: this.wallet.publicKey,
499
- state: yield this.getStatePublicKey(),
500
- market: this.getMarketAccount(marketIndex).pubkey,
501
- },
502
- });
503
- });
504
- }
505
- updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
506
- return __awaiter(this, void 0, void 0, function* () {
507
- return yield this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
508
- accounts: {
509
- admin: this.wallet.publicKey,
510
- state: yield this.getStatePublicKey(),
511
- market: this.getMarketAccount(marketIndex).pubkey,
512
- },
513
- });
514
- });
515
- }
516
- }
517
- exports.Admin = Admin;