@drift-labs/sdk 0.2.0-master.4 → 0.2.0-master.41

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 (247) hide show
  1. package/README.md +27 -27
  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 +9 -9
  30. package/lib/config.js +25 -21
  31. package/lib/constants/numericConstants.d.ts +30 -12
  32. package/lib/constants/numericConstants.js +41 -21
  33. package/lib/constants/perpMarkets.d.ts +18 -0
  34. package/lib/constants/{markets.js → perpMarkets.js} +7 -7
  35. package/lib/constants/spotMarkets.d.ts +19 -0
  36. package/lib/constants/spotMarkets.js +53 -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 +40 -12
  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 +8386 -0
  62. package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  63. package/lib/index.d.ts +30 -13
  64. package/lib/index.js +30 -13
  65. package/lib/math/amm.d.ts +9 -6
  66. package/lib/math/amm.js +91 -38
  67. package/lib/math/conversion.js +1 -1
  68. package/lib/math/exchangeStatus.d.ts +4 -0
  69. package/lib/math/exchangeStatus.js +18 -0
  70. package/lib/math/funding.d.ts +6 -6
  71. package/lib/math/funding.js +23 -21
  72. package/lib/math/insurance.d.ts +4 -0
  73. package/lib/math/insurance.js +27 -0
  74. package/lib/math/margin.d.ts +11 -0
  75. package/lib/math/margin.js +82 -0
  76. package/lib/math/market.d.ts +14 -9
  77. package/lib/math/market.js +70 -10
  78. package/lib/math/oracles.d.ts +4 -0
  79. package/lib/math/oracles.js +36 -8
  80. package/lib/math/orders.d.ts +16 -6
  81. package/lib/math/orders.js +97 -17
  82. package/lib/math/position.d.ts +27 -13
  83. package/lib/math/position.js +92 -36
  84. package/lib/math/repeg.js +17 -8
  85. package/lib/math/spotBalance.d.ts +22 -0
  86. package/lib/math/spotBalance.js +192 -0
  87. package/lib/math/spotMarket.d.ts +4 -0
  88. package/lib/math/spotMarket.js +8 -0
  89. package/lib/math/spotPosition.d.ts +6 -0
  90. package/lib/math/spotPosition.js +23 -0
  91. package/lib/math/trade.d.ts +10 -10
  92. package/lib/math/trade.js +27 -31
  93. package/lib/oracles/pythClient.js +1 -1
  94. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  95. package/lib/oracles/switchboardClient.js +1 -1
  96. package/lib/orderParams.d.ts +4 -4
  97. package/lib/orderParams.js +12 -4
  98. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  99. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  100. package/lib/serum/serumSubscriber.d.ts +27 -0
  101. package/lib/serum/serumSubscriber.js +56 -0
  102. package/lib/serum/types.d.ts +11 -0
  103. package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
  104. package/lib/slot/SlotSubscriber.d.ts +7 -0
  105. package/lib/slot/SlotSubscriber.js +3 -0
  106. package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
  107. package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
  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/tx/utils.js +1 -1
  112. package/lib/types.d.ts +688 -216
  113. package/lib/types.js +153 -24
  114. package/lib/user.d.ts +228 -0
  115. package/lib/user.js +959 -0
  116. package/lib/userConfig.d.ts +14 -0
  117. package/lib/userConfig.js +2 -0
  118. package/lib/userMap/userMap.d.ts +41 -0
  119. package/lib/userMap/userMap.js +85 -0
  120. package/lib/userMap/userStatsMap.d.ts +19 -0
  121. package/lib/userMap/userStatsMap.js +68 -0
  122. package/lib/userName.d.ts +1 -0
  123. package/lib/userName.js +3 -2
  124. package/lib/userStats.d.ts +18 -0
  125. package/lib/userStats.js +49 -0
  126. package/lib/userStatsConfig.d.ts +14 -0
  127. package/lib/userStatsConfig.js +2 -0
  128. package/lib/util/computeUnits.js +1 -1
  129. package/lib/util/getTokenAddress.d.ts +2 -0
  130. package/lib/util/getTokenAddress.js +9 -0
  131. package/package.json +11 -4
  132. package/src/accounts/bulkAccountLoader.ts +44 -34
  133. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  134. package/src/accounts/bulkUserSubscription.ts +2 -3
  135. package/src/accounts/fetch.ts +27 -2
  136. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  137. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  138. package/src/accounts/pollingUserAccountSubscriber.ts +5 -12
  139. package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -0
  140. package/src/accounts/types.ts +35 -15
  141. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  142. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  143. package/src/addresses/marketAddresses.ts +3 -4
  144. package/src/addresses/pda.ts +105 -33
  145. package/src/adminClient.ts +1207 -0
  146. package/src/assert/assert.js +9 -0
  147. package/src/config.ts +37 -31
  148. package/src/constants/numericConstants.ts +58 -24
  149. package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
  150. package/src/constants/spotMarkets.ts +73 -0
  151. package/src/dlob/DLOB.ts +1120 -0
  152. package/src/dlob/DLOBNode.ts +155 -0
  153. package/src/dlob/NodeList.ts +195 -0
  154. package/src/driftClient.ts +3594 -0
  155. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  156. package/src/events/eventList.js +77 -0
  157. package/src/events/eventList.ts +3 -0
  158. package/src/events/eventSubscriber.ts +36 -14
  159. package/src/events/fetchLogs.ts +55 -13
  160. package/src/events/pollingLogProvider.ts +11 -3
  161. package/src/events/sort.ts +11 -15
  162. package/src/events/types.ts +27 -2
  163. package/src/events/webSocketLogProvider.ts +1 -1
  164. package/src/examples/makeTradeExample.js +157 -0
  165. package/src/examples/makeTradeExample.ts +44 -28
  166. package/src/factory/bigNum.ts +150 -22
  167. package/src/idl/drift.json +8386 -0
  168. package/src/idl/pyth.json +98 -2
  169. package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  170. package/src/index.ts +30 -13
  171. package/src/math/amm.ts +161 -48
  172. package/src/math/conversion.ts +2 -2
  173. package/src/math/exchangeStatus.ts +31 -0
  174. package/src/math/funding.ts +41 -31
  175. package/src/math/insurance.ts +35 -0
  176. package/src/math/margin.ts +133 -0
  177. package/src/math/market.ts +143 -14
  178. package/src/math/oracles.ts +63 -9
  179. package/src/math/orders.ts +168 -26
  180. package/src/math/position.ts +136 -58
  181. package/src/math/repeg.ts +19 -9
  182. package/src/math/spotBalance.ts +319 -0
  183. package/src/math/spotMarket.ts +9 -0
  184. package/src/math/spotPosition.ts +47 -0
  185. package/src/math/trade.ts +33 -37
  186. package/src/oracles/pythClient.ts +2 -2
  187. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  188. package/src/oracles/switchboardClient.ts +2 -2
  189. package/src/orderParams.ts +16 -8
  190. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  191. package/src/serum/serumSubscriber.ts +99 -0
  192. package/src/serum/types.ts +13 -0
  193. package/src/slot/SlotSubscriber.ts +11 -1
  194. package/src/token/index.js +38 -0
  195. package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
  196. package/src/tx/retryTxSender.ts +16 -5
  197. package/src/tx/types.js +2 -0
  198. package/src/tx/types.ts +2 -1
  199. package/src/tx/utils.js +17 -0
  200. package/src/tx/utils.ts +1 -1
  201. package/src/types.ts +650 -189
  202. package/src/user.ts +1599 -0
  203. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  204. package/src/userMap/userMap.ts +124 -0
  205. package/src/userMap/userStatsMap.ts +108 -0
  206. package/src/userName.ts +2 -1
  207. package/src/userStats.ts +75 -0
  208. package/src/userStatsConfig.ts +18 -0
  209. package/src/util/computeUnits.js +21 -11
  210. package/src/util/computeUnits.ts +1 -1
  211. package/src/util/getTokenAddress.js +9 -0
  212. package/src/util/getTokenAddress.ts +18 -0
  213. package/src/util/promiseTimeout.js +14 -0
  214. package/src/util/tps.js +27 -0
  215. package/tests/bn/test.ts +46 -11
  216. package/tests/dlob/helpers.ts +620 -0
  217. package/tests/dlob/test.ts +4586 -0
  218. package/yarn-error.log +3160 -0
  219. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  220. package/lib/admin.d.ts +0 -44
  221. package/lib/admin.js +0 -433
  222. package/lib/clearingHouse.d.ts +0 -133
  223. package/lib/clearingHouse.js +0 -931
  224. package/lib/clearingHouseUser.d.ts +0 -187
  225. package/lib/clearingHouseUser.js +0 -643
  226. package/lib/clearingHouseUserConfig.d.ts +0 -14
  227. package/lib/constants/banks.d.ts +0 -16
  228. package/lib/constants/banks.js +0 -34
  229. package/lib/constants/markets.d.ts +0 -19
  230. package/lib/idl/clearing_house.json +0 -3998
  231. package/lib/math/bankBalance.d.ts +0 -9
  232. package/lib/math/bankBalance.js +0 -75
  233. package/lib/math/state.d.ts +0 -8
  234. package/lib/math/state.js +0 -15
  235. package/lib/orders.d.ts +0 -8
  236. package/lib/orders.js +0 -134
  237. package/src/admin.ts +0 -722
  238. package/src/clearingHouse.ts +0 -1451
  239. package/src/clearingHouseUser.ts +0 -989
  240. package/src/constants/banks.ts +0 -43
  241. package/src/idl/clearing_house.json +0 -3998
  242. package/src/math/bankBalance.ts +0 -112
  243. package/src/math/state.ts +0 -14
  244. package/src/math/utils.js +0 -27
  245. package/src/math/utils.js.map +0 -1
  246. package/src/orders.ts +0 -244
  247. package/src/util/computeUnits.js.map +0 -1
@@ -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): Promise<TransactionSignature>;
9
- initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioPartial?: number, marginRatioMaintenance?: number): 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
- withdrawFees(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, marginRatioPartial: 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,433 +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) {
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, {
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, marginRatioPartial = 625, marginRatioMaintenance = 500) {
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, marginRatioPartial, marginRatioMaintenance, {
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
- return await this.program.rpc.withdrawFromInsuranceVault(amount, {
181
- accounts: {
182
- admin: this.wallet.publicKey,
183
- state: await this.getStatePublicKey(),
184
- insuranceVault: state.insuranceVault,
185
- insuranceVaultAuthority: state.insuranceVaultAuthority,
186
- recipient: recipient,
187
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
188
- },
189
- });
190
- }
191
- async withdrawFees(marketIndex, amount, recipient) {
192
- const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
193
- const bank = this.getQuoteAssetBankAccount();
194
- return await this.program.rpc.withdrawFees(amount, {
195
- accounts: {
196
- admin: this.wallet.publicKey,
197
- state: await this.getStatePublicKey(),
198
- market: marketPublicKey,
199
- bank: bank.pubkey,
200
- bankVault: bank.vault,
201
- bankVaultAuthority: bank.vaultAuthority,
202
- recipient: recipient,
203
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
204
- },
205
- });
206
- }
207
- async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
208
- const state = await this.getStateAccount();
209
- return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
210
- accounts: {
211
- admin: this.wallet.publicKey,
212
- state: await this.getStatePublicKey(),
213
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
214
- insuranceVault: state.insuranceVault,
215
- insuranceVaultAuthority: state.insuranceVaultAuthority,
216
- bankVault: this.getQuoteAssetBankAccount().vault,
217
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
218
- },
219
- });
220
- }
221
- async updateAdmin(admin) {
222
- return await this.program.rpc.updateAdmin(admin, {
223
- accounts: {
224
- admin: this.wallet.publicKey,
225
- state: await this.getStatePublicKey(),
226
- },
227
- });
228
- }
229
- async updateCurveUpdateIntensity(marketIndex, curveUpdateIntensity) {
230
- // assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
231
- // assert(Number.isInteger(curveUpdateIntensity));
232
- return await this.program.rpc.updateCurveUpdateIntensity(curveUpdateIntensity, {
233
- accounts: {
234
- admin: this.wallet.publicKey,
235
- state: await this.getStatePublicKey(),
236
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
237
- },
238
- });
239
- }
240
- async updateMarginRatio(marketIndex, marginRatioInitial, marginRatioPartial, marginRatioMaintenance) {
241
- return await this.program.rpc.updateMarginRatio(marginRatioInitial, marginRatioPartial, marginRatioMaintenance, {
242
- accounts: {
243
- admin: this.wallet.publicKey,
244
- state: await this.getStatePublicKey(),
245
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
246
- },
247
- });
248
- }
249
- async updateMarketBaseSpread(marketIndex, baseSpread) {
250
- return await this.program.rpc.updateMarketBaseSpread(baseSpread, {
251
- accounts: {
252
- admin: this.wallet.publicKey,
253
- state: await this.getStatePublicKey(),
254
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
255
- },
256
- });
257
- }
258
- async updateMarketMaxSpread(marketIndex, maxSpread) {
259
- return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
260
- accounts: {
261
- admin: this.wallet.publicKey,
262
- state: await this.getStatePublicKey(),
263
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
264
- },
265
- });
266
- }
267
- async updatePartialLiquidationClosePercentage(numerator, denominator) {
268
- return await this.program.rpc.updatePartialLiquidationClosePercentage(numerator, denominator, {
269
- accounts: {
270
- admin: this.wallet.publicKey,
271
- state: await this.getStatePublicKey(),
272
- },
273
- });
274
- }
275
- async updatePartialLiquidationPenaltyPercentage(numerator, denominator) {
276
- return await this.program.rpc.updatePartialLiquidationPenaltyPercentage(numerator, denominator, {
277
- accounts: {
278
- admin: this.wallet.publicKey,
279
- state: await this.getStatePublicKey(),
280
- },
281
- });
282
- }
283
- async updateFullLiquidationPenaltyPercentage(numerator, denominator) {
284
- return await this.program.rpc.updateFullLiquidationPenaltyPercentage(numerator, denominator, {
285
- accounts: {
286
- admin: this.wallet.publicKey,
287
- state: await this.getStatePublicKey(),
288
- },
289
- });
290
- }
291
- async updatePartialLiquidationShareDenominator(denominator) {
292
- return await this.program.rpc.updatePartialLiquidationLiquidatorShareDenominator(denominator, {
293
- accounts: {
294
- admin: this.wallet.publicKey,
295
- state: await this.getStatePublicKey(),
296
- },
297
- });
298
- }
299
- async updateFullLiquidationShareDenominator(denominator) {
300
- return await this.program.rpc.updateFullLiquidationLiquidatorShareDenominator(denominator, {
301
- accounts: {
302
- admin: this.wallet.publicKey,
303
- state: await this.getStatePublicKey(),
304
- },
305
- });
306
- }
307
- async updateOrderFillerRewardStructure(orderFillerRewardStructure) {
308
- return await this.program.rpc.updateOrderFillerRewardStructure(orderFillerRewardStructure, {
309
- accounts: {
310
- admin: this.wallet.publicKey,
311
- state: await this.getStatePublicKey(),
312
- },
313
- });
314
- }
315
- async updateFee(fees) {
316
- return await this.program.rpc.updateFee(fees, {
317
- accounts: {
318
- admin: this.wallet.publicKey,
319
- state: await this.getStatePublicKey(),
320
- },
321
- });
322
- }
323
- async updateOracleGuardRails(oracleGuardRails) {
324
- return await this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
325
- accounts: {
326
- admin: this.wallet.publicKey,
327
- state: await this.getStatePublicKey(),
328
- },
329
- });
330
- }
331
- async updateMarketOracle(marketIndex, oracle, oracleSource) {
332
- return await this.program.rpc.updateMarketOracle(oracle, oracleSource, {
333
- accounts: {
334
- admin: this.wallet.publicKey,
335
- state: await this.getStatePublicKey(),
336
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
337
- },
338
- });
339
- }
340
- async updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize) {
341
- return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(minimumTradeSize, {
342
- accounts: {
343
- admin: this.wallet.publicKey,
344
- state: await this.getStatePublicKey(),
345
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
346
- },
347
- });
348
- }
349
- async updateMarketBaseAssetAmountStepSize(marketIndex, stepSize) {
350
- return await this.program.rpc.updateMarketBaseAssetAmountStepSize(stepSize, {
351
- accounts: {
352
- admin: this.wallet.publicKey,
353
- state: await this.getStatePublicKey(),
354
- market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
355
- },
356
- });
357
- }
358
- async updateWhitelistMint(whitelistMint) {
359
- return await this.program.rpc.updateWhitelistMint(whitelistMint, {
360
- accounts: {
361
- admin: this.wallet.publicKey,
362
- state: await this.getStatePublicKey(),
363
- },
364
- });
365
- }
366
- async updateDiscountMint(discountMint) {
367
- return await this.program.rpc.updateDiscountMint(discountMint, {
368
- accounts: {
369
- admin: this.wallet.publicKey,
370
- state: await this.getStatePublicKey(),
371
- },
372
- });
373
- }
374
- async updateMaxDeposit(maxDeposit) {
375
- return await this.program.rpc.updateMaxDeposit(maxDeposit, {
376
- accounts: {
377
- admin: this.wallet.publicKey,
378
- state: await this.getStatePublicKey(),
379
- },
380
- });
381
- }
382
- async updateFundingPaused(fundingPaused) {
383
- return await this.program.rpc.updateFundingPaused(fundingPaused, {
384
- accounts: {
385
- admin: this.wallet.publicKey,
386
- state: await this.getStatePublicKey(),
387
- },
388
- });
389
- }
390
- async updateExchangePaused(exchangePaused) {
391
- return await this.program.rpc.updateExchangePaused(exchangePaused, {
392
- accounts: {
393
- admin: this.wallet.publicKey,
394
- state: await this.getStatePublicKey(),
395
- },
396
- });
397
- }
398
- async disableAdminControlsPrices() {
399
- return await this.program.rpc.disableAdminControlsPrices({
400
- accounts: {
401
- admin: this.wallet.publicKey,
402
- state: await this.getStatePublicKey(),
403
- },
404
- });
405
- }
406
- async updateAuctionDuration(minDuration, maxDuration) {
407
- return await this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
408
- accounts: {
409
- admin: this.wallet.publicKey,
410
- state: await this.getStatePublicKey(),
411
- },
412
- });
413
- }
414
- async updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
415
- return await this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
416
- accounts: {
417
- admin: this.wallet.publicKey,
418
- state: await this.getStatePublicKey(),
419
- market: this.getMarketAccount(marketIndex).pubkey,
420
- },
421
- });
422
- }
423
- async updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
424
- return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
425
- accounts: {
426
- admin: this.wallet.publicKey,
427
- state: await this.getStatePublicKey(),
428
- market: this.getMarketAccount(marketIndex).pubkey,
429
- },
430
- });
431
- }
432
- }
433
- exports.Admin = Admin;
@@ -1,133 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="bn.js" />
3
- import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo, OptionalOrderParams } from './types';
5
- import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
6
- import { MockUSDCFaucet } from './mockUSDCFaucet';
7
- import { EventEmitter } from 'events';
8
- import StrictEventEmitter from 'strict-event-emitter-types';
9
- import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, DataAndSlot } from './accounts/types';
10
- import { TxSender } from './tx/types';
11
- import { OraclePriceData } from './oracles/types';
12
- import { ClearingHouseConfig } from './clearingHouseConfig';
13
- import { ClearingHouseUser } from './clearingHouseUser';
14
- import { ClearingHouseUserAccountSubscriptionConfig } from './clearingHouseUserConfig';
15
- /**
16
- * # ClearingHouse
17
- * This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
18
- */
19
- export declare class ClearingHouse {
20
- connection: Connection;
21
- wallet: IWallet;
22
- program: Program;
23
- provider: AnchorProvider;
24
- opts?: ConfirmOptions;
25
- users: Map<number, ClearingHouseUser>;
26
- activeUserId: number;
27
- userAccountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig;
28
- accountSubscriber: ClearingHouseAccountSubscriber;
29
- eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
30
- _isSubscribed: boolean;
31
- txSender: TxSender;
32
- marketLastSlotCache: Map<number, number>;
33
- get isSubscribed(): boolean;
34
- set isSubscribed(val: boolean);
35
- constructor(config: ClearingHouseConfig);
36
- createUsers(userIds: number[], accountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig): void;
37
- createUser(userId: number, accountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig): ClearingHouseUser;
38
- subscribe(): Promise<boolean>;
39
- subscribeUsers(): Promise<boolean>[];
40
- /**
41
- * Forces the accountSubscriber to fetch account updates from rpc
42
- */
43
- fetchAccounts(): Promise<void>;
44
- unsubscribe(): Promise<void>;
45
- unsubscribeUsers(): Promise<void>[];
46
- statePublicKey?: PublicKey;
47
- getStatePublicKey(): Promise<PublicKey>;
48
- getStateAccount(): StateAccount;
49
- getMarketAccount(marketIndex: BN | number): MarketAccount | undefined;
50
- getMarketAccounts(): MarketAccount[];
51
- getBankAccount(bankIndex: BN | number): BankAccount | undefined;
52
- getQuoteAssetBankAccount(): BankAccount;
53
- getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
54
- /**
55
- * Update the wallet to use for clearing house transactions and linked user account
56
- * @param newWallet
57
- * @param userIds
58
- * @param activeUserId
59
- */
60
- updateWallet(newWallet: IWallet, userIds?: number[], activeUserId?: number): Promise<void>;
61
- switchActiveUser(userId: number): Promise<void>;
62
- addUser(userId: number): Promise<void>;
63
- initializeUserAccount(userId?: number, name?: string): Promise<[TransactionSignature, PublicKey]>;
64
- getInitializeUserInstructions(userId?: number, name?: string): Promise<[PublicKey, TransactionInstruction]>;
65
- getUser(userId?: number): ClearingHouseUser;
66
- getUsers(): ClearingHouseUser[];
67
- getUserAccountPublicKey(): Promise<PublicKey>;
68
- getUserAccount(userId?: number): UserAccount | undefined;
69
- getUserAccountAndSlot(userId?: number): DataAndSlot<UserAccount> | undefined;
70
- getUserBankBalance(bankIndex: number | BN): UserBankBalance | undefined;
71
- getQuoteAssetTokenAmount(): BN;
72
- getRemainingAccounts(params: {
73
- writableMarketIndex?: BN;
74
- writableBankIndex?: BN;
75
- }): AccountMeta[];
76
- getOrder(orderId: BN | number): Order | undefined;
77
- getOrderByUserId(userOrderId: number): Order | undefined;
78
- deposit(amount: BN, bankIndex: BN, collateralAccountPublicKey: PublicKey, userId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
79
- getDepositInstruction(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, userId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
80
- /**
81
- * Creates the Clearing House User account for a user, and deposits some initial collateral
82
- * @param userId
83
- * @param name
84
- * @param amount
85
- * @param userTokenAccount
86
- * @param fromUserId
87
- * @returns
88
- */
89
- initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, bankIndex?: BN, userId?: number, name?: string, fromUserId?: number): Promise<[TransactionSignature, PublicKey]>;
90
- initializeUserAccountForDevnet(userId: number, name: string, mockUSDCFaucet: MockUSDCFaucet, amount: BN): Promise<[TransactionSignature, PublicKey]>;
91
- withdraw(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
92
- getWithdrawIx(amount: BN, bankIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
93
- transferDeposit(amount: BN, bankIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionSignature>;
94
- getTransferDepositIx(amount: BN, bankIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionInstruction>;
95
- updateBankCumulativeInterest(bankIndex: BN): Promise<TransactionSignature>;
96
- updateBankCumulativeInterestIx(bankIndex: BN): Promise<TransactionInstruction>;
97
- openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
98
- placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
99
- getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams;
100
- getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
101
- updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
102
- getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
103
- cancelOrder(orderId?: BN): Promise<TransactionSignature>;
104
- getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
105
- cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
106
- getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
107
- fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
108
- getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
109
- triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
110
- getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
111
- placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
112
- getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
113
- /**
114
- * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
115
- * @param marketIndex
116
- * @returns
117
- */
118
- closePosition(marketIndex: BN): Promise<TransactionSignature>;
119
- settlePNLs(users: {
120
- settleeUserAccountPublicKey: PublicKey;
121
- settleeUserAccount: UserAccount;
122
- }[], marketIndex: BN): Promise<TransactionSignature>;
123
- settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
124
- settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
125
- liquidate(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionSignature>;
126
- getLiquidateIx(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
127
- updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
128
- getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
129
- settleFundingPayment(userAccount: PublicKey): Promise<TransactionSignature>;
130
- getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
131
- triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
132
- getOracleDataForMarket(marketIndex: BN): OraclePriceData;
133
- }