@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
@@ -1,49 +0,0 @@
1
- /// <reference types="bn.js" />
2
- /// <reference types="node" />
3
- import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, DataAndSlot } from './types';
4
- import { AccountSubscriber } from './types';
5
- import { BankAccount, MarketAccount, StateAccount } from '../types';
6
- import { BN, Program } from '@project-serum/anchor';
7
- import StrictEventEmitter from 'strict-event-emitter-types';
8
- import { EventEmitter } from 'events';
9
- import { PublicKey } from '@solana/web3.js';
10
- import { OracleInfo, OraclePriceData } from '../oracles/types';
11
- import { OracleClientCache } from '../oracles/oracleClientCache';
12
- export declare class WebSocketClearingHouseAccountSubscriber implements ClearingHouseAccountSubscriber {
13
- isSubscribed: boolean;
14
- program: Program;
15
- marketIndexes: BN[];
16
- bankIndexes: BN[];
17
- oracleInfos: OracleInfo[];
18
- oracleClientCache: OracleClientCache;
19
- eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
20
- stateAccountSubscriber?: AccountSubscriber<StateAccount>;
21
- marketAccountSubscribers: Map<number, AccountSubscriber<MarketAccount>>;
22
- bankAccountSubscribers: Map<number, AccountSubscriber<BankAccount>>;
23
- oracleSubscribers: Map<string, AccountSubscriber<OraclePriceData>>;
24
- private isSubscribing;
25
- private subscriptionPromise;
26
- private subscriptionPromiseResolver;
27
- constructor(program: Program, marketIndexes: BN[], bankIndexes: BN[], oracleInfos: OracleInfo[]);
28
- subscribe(): Promise<boolean>;
29
- subscribeToMarketAccounts(): Promise<boolean>;
30
- subscribeToMarketAccount(marketIndex: BN): Promise<boolean>;
31
- subscribeToBankAccounts(): Promise<boolean>;
32
- subscribeToBankAccount(bankIndex: BN): Promise<boolean>;
33
- subscribeToOracles(): Promise<boolean>;
34
- subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean>;
35
- unsubscribeFromMarketAccounts(): Promise<void>;
36
- unsubscribeFromBankAccounts(): Promise<void>;
37
- unsubscribeFromOracles(): Promise<void>;
38
- fetch(): Promise<void>;
39
- unsubscribe(): Promise<void>;
40
- addBank(bankIndex: BN): Promise<boolean>;
41
- addMarket(marketIndex: BN): Promise<boolean>;
42
- addOracle(oracleInfo: OracleInfo): Promise<boolean>;
43
- assertIsSubscribed(): void;
44
- getStateAccountAndSlot(): DataAndSlot<StateAccount>;
45
- getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<MarketAccount> | undefined;
46
- getMarketAccountsAndSlots(): DataAndSlot<MarketAccount>[];
47
- getBankAccountAndSlot(bankIndex: BN): DataAndSlot<BankAccount> | undefined;
48
- getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
49
- }
package/lib/admin.d.ts DELETED
@@ -1,44 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { FeeStructure, OracleGuardRails, OracleSource, OrderFillerRewardStructure } from './types';
4
- import { BN } from '@project-serum/anchor';
5
- import { ClearingHouse } from './clearingHouse';
6
- export declare class Admin extends ClearingHouse {
7
- initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[TransactionSignature]>;
8
- initializeBank(mint: PublicKey, optimalUtilization: BN, optimalRate: BN, maxRate: BN, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN, liquidationFee?: BN): Promise<TransactionSignature>;
9
- initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN): Promise<TransactionSignature>;
10
- moveAmmPrice(baseAssetReserve: BN, quoteAssetReserve: BN, marketIndex: BN): Promise<TransactionSignature>;
11
- updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
12
- moveAmmToPrice(marketIndex: BN, targetPrice: BN): Promise<TransactionSignature>;
13
- repegAmmCurve(newPeg: BN, marketIndex: BN): Promise<TransactionSignature>;
14
- updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
15
- resetAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
16
- withdrawFromInsuranceVault(amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
17
- withdrawFromMarketToInsuranceVault(marketIndex: BN, amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
18
- withdrawFromInsuranceVaultToMarket(marketIndex: BN, amount: BN): Promise<TransactionSignature>;
19
- updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
20
- updateCurveUpdateIntensity(marketIndex: BN, curveUpdateIntensity: number): Promise<TransactionSignature>;
21
- updateMarginRatio(marketIndex: BN, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
22
- updateMarketBaseSpread(marketIndex: BN, baseSpread: number): Promise<TransactionSignature>;
23
- updateMarketMaxSpread(marketIndex: BN, maxSpread: number): Promise<TransactionSignature>;
24
- updatePartialLiquidationClosePercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
25
- updatePartialLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
26
- updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
27
- updatePartialLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
28
- updateFullLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
29
- updateOrderFillerRewardStructure(orderFillerRewardStructure: OrderFillerRewardStructure): Promise<TransactionSignature>;
30
- updateFee(fees: FeeStructure): Promise<TransactionSignature>;
31
- updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
32
- updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
33
- updateMarketMinimumQuoteAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
34
- updateMarketBaseAssetAmountStepSize(marketIndex: BN, stepSize: BN): Promise<TransactionSignature>;
35
- updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
36
- updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
37
- updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
38
- updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
39
- updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
40
- disableAdminControlsPrices(): Promise<TransactionSignature>;
41
- updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
42
- updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
43
- updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
44
- }
package/lib/admin.js DELETED
@@ -1,438 +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
- 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.Admin = void 0;
27
- const web3_js_1 = require("@solana/web3.js");
28
- const types_1 = require("./types");
29
- const anchor_1 = require("@project-serum/anchor");
30
- const anchor = __importStar(require("@project-serum/anchor"));
31
- const pda_1 = require("./addresses/pda");
32
- const spl_token_1 = require("@solana/spl-token");
33
- const clearingHouse_1 = require("./clearingHouse");
34
- const numericConstants_1 = require("./constants/numericConstants");
35
- const trade_1 = require("./math/trade");
36
- const amm_1 = require("./math/amm");
37
- class Admin extends clearingHouse_1.ClearingHouse {
38
- async initialize(usdcMint, adminControlsPrices) {
39
- const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
40
- if (stateAccountRPCResponse.value !== null) {
41
- throw new Error('Clearing house already initialized');
42
- }
43
- const [insuranceVaultPublicKey] = await web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
44
- const [insuranceVaultAuthority] = await web3_js_1.PublicKey.findProgramAddress([insuranceVaultPublicKey.toBuffer()], this.program.programId);
45
- const [clearingHouseStatePublicKey] = await (0, pda_1.getClearingHouseStateAccountPublicKeyAndNonce)(this.program.programId);
46
- const initializeTx = await this.program.transaction.initialize(adminControlsPrices, {
47
- accounts: {
48
- admin: this.wallet.publicKey,
49
- state: clearingHouseStatePublicKey,
50
- quoteAssetMint: usdcMint,
51
- insuranceVault: insuranceVaultPublicKey,
52
- insuranceVaultAuthority: insuranceVaultAuthority,
53
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
54
- systemProgram: anchor.web3.SystemProgram.programId,
55
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
56
- },
57
- });
58
- const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
59
- return [initializeTxSig];
60
- }
61
- async initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
62
- const bankIndex = this.getStateAccount().numberOfBanks;
63
- const bank = await (0, pda_1.getBankPublicKey)(this.program.programId, bankIndex);
64
- const bankVault = await (0, pda_1.getBankVaultPublicKey)(this.program.programId, bankIndex);
65
- const bankVaultAuthority = await (0, pda_1.getBankVaultAuthorityPublicKey)(this.program.programId, bankIndex);
66
- const initializeTx = await this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
67
- accounts: {
68
- admin: this.wallet.publicKey,
69
- state: await this.getStatePublicKey(),
70
- bank,
71
- bankVault,
72
- bankVaultAuthority,
73
- bankMint: mint,
74
- oracle,
75
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
76
- systemProgram: anchor.web3.SystemProgram.programId,
77
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
78
- },
79
- });
80
- const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
81
- await this.accountSubscriber.addBank(bankIndex);
82
- await this.accountSubscriber.addOracle({
83
- source: oracleSource,
84
- publicKey: oracle,
85
- });
86
- return txSig;
87
- }
88
- async initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO) {
89
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
90
- const initializeMarketTx = await this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, {
91
- accounts: {
92
- state: await this.getStatePublicKey(),
93
- admin: this.wallet.publicKey,
94
- oracle: priceOracle,
95
- market: marketPublicKey,
96
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
97
- systemProgram: anchor.web3.SystemProgram.programId,
98
- },
99
- });
100
- const { txSig } = await this.txSender.send(initializeMarketTx, [], this.opts);
101
- await this.accountSubscriber.addMarket(this.getStateAccount().numberOfMarkets);
102
- await this.accountSubscriber.addOracle({
103
- source: oracleSource,
104
- publicKey: priceOracle,
105
- });
106
- return txSig;
107
- }
108
- async moveAmmPrice(baseAssetReserve, quoteAssetReserve, marketIndex) {
109
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
110
- return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, {
111
- accounts: {
112
- state: await this.getStatePublicKey(),
113
- admin: this.wallet.publicKey,
114
- market: marketPublicKey,
115
- },
116
- });
117
- }
118
- async updateK(sqrtK, marketIndex) {
119
- return await this.program.rpc.updateK(sqrtK, {
120
- accounts: {
121
- state: await this.getStatePublicKey(),
122
- admin: this.wallet.publicKey,
123
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
124
- oracle: this.getMarketAccount(marketIndex).amm.oracle,
125
- },
126
- });
127
- }
128
- async moveAmmToPrice(marketIndex, targetPrice) {
129
- const market = this.getMarketAccount(marketIndex);
130
- const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
131
- );
132
- const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
133
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
134
- return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
135
- accounts: {
136
- state: await this.getStatePublicKey(),
137
- admin: this.wallet.publicKey,
138
- market: marketPublicKey,
139
- },
140
- });
141
- }
142
- async repegAmmCurve(newPeg, marketIndex) {
143
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
144
- const ammData = this.getMarketAccount(marketIndex).amm;
145
- return await this.program.rpc.repegAmmCurve(newPeg, {
146
- accounts: {
147
- state: await this.getStatePublicKey(),
148
- admin: this.wallet.publicKey,
149
- oracle: ammData.oracle,
150
- market: marketPublicKey,
151
- },
152
- });
153
- }
154
- async updateAmmOracleTwap(marketIndex) {
155
- const ammData = this.getMarketAccount(marketIndex).amm;
156
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
157
- return await this.program.rpc.updateAmmOracleTwap({
158
- accounts: {
159
- state: await this.getStatePublicKey(),
160
- admin: this.wallet.publicKey,
161
- oracle: ammData.oracle,
162
- market: marketPublicKey,
163
- },
164
- });
165
- }
166
- async resetAmmOracleTwap(marketIndex) {
167
- const ammData = this.getMarketAccount(marketIndex).amm;
168
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
169
- return await this.program.rpc.resetAmmOracleTwap({
170
- accounts: {
171
- state: await this.getStatePublicKey(),
172
- admin: this.wallet.publicKey,
173
- oracle: ammData.oracle,
174
- market: marketPublicKey,
175
- },
176
- });
177
- }
178
- async withdrawFromInsuranceVault(amount, recipient) {
179
- const state = await this.getStateAccount();
180
- const bank = this.getQuoteAssetBankAccount();
181
- return await this.program.rpc.withdrawFromInsuranceVault(amount, {
182
- accounts: {
183
- admin: this.wallet.publicKey,
184
- state: await this.getStatePublicKey(),
185
- bank: bank.pubkey,
186
- insuranceVault: state.insuranceVault,
187
- insuranceVaultAuthority: state.insuranceVaultAuthority,
188
- recipient: recipient,
189
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
190
- },
191
- });
192
- }
193
- async withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
194
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
195
- const bank = this.getQuoteAssetBankAccount();
196
- return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
197
- accounts: {
198
- admin: this.wallet.publicKey,
199
- state: await this.getStatePublicKey(),
200
- market: marketPublicKey,
201
- bank: bank.pubkey,
202
- bankVault: bank.vault,
203
- bankVaultAuthority: bank.vaultAuthority,
204
- recipient: recipient,
205
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
206
- },
207
- });
208
- }
209
- async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
210
- const state = await this.getStateAccount();
211
- const bank = this.getQuoteAssetBankAccount();
212
- return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
213
- accounts: {
214
- admin: this.wallet.publicKey,
215
- state: await this.getStatePublicKey(),
216
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
217
- insuranceVault: state.insuranceVault,
218
- insuranceVaultAuthority: state.insuranceVaultAuthority,
219
- bank: bank.pubkey,
220
- bankVault: bank.vault,
221
- bankVaultAuthority: bank.vaultAuthority,
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 updateCurveUpdateIntensity(marketIndex, curveUpdateIntensity) {
235
- // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
236
- // assert(Number.isInteger(curveUpdateIntensity));
237
- return await this.program.rpc.updateCurveUpdateIntensity(curveUpdateIntensity, {
238
- accounts: {
239
- admin: this.wallet.publicKey,
240
- state: await this.getStatePublicKey(),
241
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
242
- },
243
- });
244
- }
245
- async updateMarginRatio(marketIndex, marginRatioInitial, marginRatioMaintenance) {
246
- return await this.program.rpc.updateMarginRatio(marginRatioInitial, marginRatioMaintenance, {
247
- accounts: {
248
- admin: this.wallet.publicKey,
249
- state: await this.getStatePublicKey(),
250
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
251
- },
252
- });
253
- }
254
- async updateMarketBaseSpread(marketIndex, baseSpread) {
255
- return await this.program.rpc.updateMarketBaseSpread(baseSpread, {
256
- accounts: {
257
- admin: this.wallet.publicKey,
258
- state: await this.getStatePublicKey(),
259
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
260
- },
261
- });
262
- }
263
- async updateMarketMaxSpread(marketIndex, maxSpread) {
264
- return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
265
- accounts: {
266
- admin: this.wallet.publicKey,
267
- state: await this.getStatePublicKey(),
268
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
269
- },
270
- });
271
- }
272
- async updatePartialLiquidationClosePercentage(numerator, denominator) {
273
- return await this.program.rpc.updatePartialLiquidationClosePercentage(numerator, denominator, {
274
- accounts: {
275
- admin: this.wallet.publicKey,
276
- state: await this.getStatePublicKey(),
277
- },
278
- });
279
- }
280
- async updatePartialLiquidationPenaltyPercentage(numerator, denominator) {
281
- return await this.program.rpc.updatePartialLiquidationPenaltyPercentage(numerator, denominator, {
282
- accounts: {
283
- admin: this.wallet.publicKey,
284
- state: await this.getStatePublicKey(),
285
- },
286
- });
287
- }
288
- async updateFullLiquidationPenaltyPercentage(numerator, denominator) {
289
- return await this.program.rpc.updateFullLiquidationPenaltyPercentage(numerator, denominator, {
290
- accounts: {
291
- admin: this.wallet.publicKey,
292
- state: await this.getStatePublicKey(),
293
- },
294
- });
295
- }
296
- async updatePartialLiquidationShareDenominator(denominator) {
297
- return await this.program.rpc.updatePartialLiquidationLiquidatorShareDenominator(denominator, {
298
- accounts: {
299
- admin: this.wallet.publicKey,
300
- state: await this.getStatePublicKey(),
301
- },
302
- });
303
- }
304
- async updateFullLiquidationShareDenominator(denominator) {
305
- return await this.program.rpc.updateFullLiquidationLiquidatorShareDenominator(denominator, {
306
- accounts: {
307
- admin: this.wallet.publicKey,
308
- state: await this.getStatePublicKey(),
309
- },
310
- });
311
- }
312
- async updateOrderFillerRewardStructure(orderFillerRewardStructure) {
313
- return await this.program.rpc.updateOrderFillerRewardStructure(orderFillerRewardStructure, {
314
- accounts: {
315
- admin: this.wallet.publicKey,
316
- state: await this.getStatePublicKey(),
317
- },
318
- });
319
- }
320
- async updateFee(fees) {
321
- return await this.program.rpc.updateFee(fees, {
322
- accounts: {
323
- admin: this.wallet.publicKey,
324
- state: await this.getStatePublicKey(),
325
- },
326
- });
327
- }
328
- async updateOracleGuardRails(oracleGuardRails) {
329
- return await this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
330
- accounts: {
331
- admin: this.wallet.publicKey,
332
- state: await this.getStatePublicKey(),
333
- },
334
- });
335
- }
336
- async updateMarketOracle(marketIndex, oracle, oracleSource) {
337
- return await this.program.rpc.updateMarketOracle(oracle, oracleSource, {
338
- accounts: {
339
- admin: this.wallet.publicKey,
340
- state: await this.getStatePublicKey(),
341
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
342
- },
343
- });
344
- }
345
- async updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize) {
346
- return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(minimumTradeSize, {
347
- accounts: {
348
- admin: this.wallet.publicKey,
349
- state: await this.getStatePublicKey(),
350
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
351
- },
352
- });
353
- }
354
- async updateMarketBaseAssetAmountStepSize(marketIndex, stepSize) {
355
- return await this.program.rpc.updateMarketBaseAssetAmountStepSize(stepSize, {
356
- accounts: {
357
- admin: this.wallet.publicKey,
358
- state: await this.getStatePublicKey(),
359
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
360
- },
361
- });
362
- }
363
- async updateWhitelistMint(whitelistMint) {
364
- return await this.program.rpc.updateWhitelistMint(whitelistMint, {
365
- accounts: {
366
- admin: this.wallet.publicKey,
367
- state: await this.getStatePublicKey(),
368
- },
369
- });
370
- }
371
- async updateDiscountMint(discountMint) {
372
- return await this.program.rpc.updateDiscountMint(discountMint, {
373
- accounts: {
374
- admin: this.wallet.publicKey,
375
- state: await this.getStatePublicKey(),
376
- },
377
- });
378
- }
379
- async updateMaxDeposit(maxDeposit) {
380
- return await this.program.rpc.updateMaxDeposit(maxDeposit, {
381
- accounts: {
382
- admin: this.wallet.publicKey,
383
- state: await this.getStatePublicKey(),
384
- },
385
- });
386
- }
387
- async updateFundingPaused(fundingPaused) {
388
- return await this.program.rpc.updateFundingPaused(fundingPaused, {
389
- accounts: {
390
- admin: this.wallet.publicKey,
391
- state: await this.getStatePublicKey(),
392
- },
393
- });
394
- }
395
- async updateExchangePaused(exchangePaused) {
396
- return await this.program.rpc.updateExchangePaused(exchangePaused, {
397
- accounts: {
398
- admin: this.wallet.publicKey,
399
- state: await this.getStatePublicKey(),
400
- },
401
- });
402
- }
403
- async disableAdminControlsPrices() {
404
- return await this.program.rpc.disableAdminControlsPrices({
405
- accounts: {
406
- admin: this.wallet.publicKey,
407
- state: await this.getStatePublicKey(),
408
- },
409
- });
410
- }
411
- async updateAuctionDuration(minDuration, maxDuration) {
412
- return await this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
413
- accounts: {
414
- admin: this.wallet.publicKey,
415
- state: await this.getStatePublicKey(),
416
- },
417
- });
418
- }
419
- async updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
420
- return await this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
421
- accounts: {
422
- admin: this.wallet.publicKey,
423
- state: await this.getStatePublicKey(),
424
- market: this.getMarketAccount(marketIndex).pubkey,
425
- },
426
- });
427
- }
428
- async updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
429
- return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
430
- accounts: {
431
- admin: this.wallet.publicKey,
432
- state: await this.getStatePublicKey(),
433
- market: this.getMarketAccount(marketIndex).pubkey,
434
- },
435
- });
436
- }
437
- }
438
- exports.Admin = Admin;