@drift-labs/sdk 0.1.36-master.5 → 0.2.0-master.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 (197) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +7 -6
  2. package/lib/accounts/bulkAccountLoader.js +83 -93
  3. package/lib/accounts/bulkUserSubscription.js +13 -57
  4. package/lib/accounts/fetch.d.ts +4 -0
  5. package/lib/accounts/fetch.js +18 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
  8. package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
  9. package/lib/accounts/pollingOracleSubscriber.js +37 -49
  10. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
  11. package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
  12. package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
  13. package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
  14. package/lib/accounts/types.d.ts +34 -41
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
  16. package/lib/accounts/webSocketAccountSubscriber.js +39 -35
  17. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
  18. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
  19. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
  20. package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
  21. package/lib/addresses/marketAddresses.d.ts +4 -0
  22. package/lib/addresses/marketAddresses.js +15 -0
  23. package/lib/addresses/pda.d.ts +12 -0
  24. package/lib/addresses/pda.js +83 -0
  25. package/lib/admin.d.ts +8 -12
  26. package/lib/admin.js +366 -490
  27. package/lib/clearingHouse.d.ts +84 -103
  28. package/lib/clearingHouse.js +779 -810
  29. package/lib/clearingHouseConfig.d.ts +34 -0
  30. package/lib/clearingHouseConfig.js +2 -0
  31. package/lib/clearingHouseUser.d.ts +19 -18
  32. package/lib/clearingHouseUser.js +157 -115
  33. package/lib/clearingHouseUserConfig.d.ts +14 -0
  34. package/lib/clearingHouseUserConfig.js +2 -0
  35. package/lib/config.d.ts +12 -0
  36. package/lib/config.js +35 -4
  37. package/lib/constants/banks.d.ts +16 -0
  38. package/lib/constants/banks.js +34 -0
  39. package/lib/constants/markets.d.ts +8 -3
  40. package/lib/constants/markets.js +13 -206
  41. package/lib/constants/numericConstants.d.ts +16 -0
  42. package/lib/constants/numericConstants.js +22 -6
  43. package/lib/events/eventList.d.ts +22 -0
  44. package/lib/events/eventList.js +77 -0
  45. package/lib/events/eventSubscriber.d.ts +34 -0
  46. package/lib/events/eventSubscriber.js +126 -0
  47. package/lib/events/fetchLogs.d.ts +13 -0
  48. package/lib/events/fetchLogs.js +39 -0
  49. package/lib/events/pollingLogProvider.d.ts +15 -0
  50. package/lib/events/pollingLogProvider.js +53 -0
  51. package/lib/events/sort.d.ts +2 -0
  52. package/lib/events/sort.js +44 -0
  53. package/lib/events/txEventCache.d.ts +24 -0
  54. package/lib/events/txEventCache.js +71 -0
  55. package/lib/events/types.d.ts +49 -0
  56. package/lib/events/types.js +20 -0
  57. package/lib/events/webSocketLogProvider.d.ts +12 -0
  58. package/lib/events/webSocketLogProvider.js +30 -0
  59. package/lib/examples/makeTradeExample.js +26 -27
  60. package/lib/factory/bigNum.d.ts +112 -0
  61. package/lib/factory/bigNum.js +356 -0
  62. package/lib/factory/oracleClient.d.ts +1 -2
  63. package/lib/factory/oracleClient.js +6 -2
  64. package/lib/idl/clearing_house.json +1739 -2287
  65. package/lib/index.d.ts +13 -4
  66. package/lib/index.js +13 -4
  67. package/lib/math/amm.d.ts +19 -29
  68. package/lib/math/amm.js +129 -179
  69. package/lib/math/auction.d.ts +5 -0
  70. package/lib/math/auction.js +39 -0
  71. package/lib/math/bankBalance.d.ts +9 -0
  72. package/lib/math/bankBalance.js +75 -0
  73. package/lib/math/conversion.d.ts +0 -1
  74. package/lib/math/conversion.js +1 -5
  75. package/lib/math/funding.d.ts +6 -6
  76. package/lib/math/funding.js +158 -175
  77. package/lib/math/market.d.ts +6 -6
  78. package/lib/math/market.js +10 -9
  79. package/lib/math/oracles.d.ts +3 -0
  80. package/lib/math/oracles.js +26 -0
  81. package/lib/math/orders.d.ts +5 -0
  82. package/lib/math/orders.js +31 -1
  83. package/lib/math/position.d.ts +7 -4
  84. package/lib/math/position.js +27 -9
  85. package/lib/math/repeg.d.ts +22 -0
  86. package/lib/math/repeg.js +128 -0
  87. package/lib/math/trade.d.ts +13 -8
  88. package/lib/math/trade.js +85 -22
  89. package/lib/mockUSDCFaucet.js +87 -116
  90. package/lib/oracles/oracleClientCache.d.ts +8 -0
  91. package/lib/oracles/oracleClientCache.js +19 -0
  92. package/lib/oracles/pythClient.d.ts +3 -5
  93. package/lib/oracles/pythClient.js +12 -30
  94. package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
  95. package/lib/oracles/quoteAssetOracleClient.js +21 -0
  96. package/lib/oracles/switchboardClient.d.ts +3 -5
  97. package/lib/oracles/switchboardClient.js +29 -47
  98. package/lib/oracles/types.d.ts +7 -1
  99. package/lib/orders.d.ts +6 -6
  100. package/lib/orders.js +10 -9
  101. package/lib/slot/SlotSubscriber.d.ts +12 -0
  102. package/lib/slot/SlotSubscriber.js +23 -0
  103. package/lib/tx/retryTxSender.d.ts +2 -2
  104. package/lib/tx/retryTxSender.js +108 -123
  105. package/lib/tx/types.d.ts +5 -1
  106. package/lib/tx/utils.d.ts +1 -1
  107. package/lib/tx/utils.js +11 -2
  108. package/lib/types.d.ts +105 -98
  109. package/lib/types.js +13 -1
  110. package/lib/userName.d.ts +4 -0
  111. package/lib/userName.js +20 -0
  112. package/lib/util/computeUnits.js +10 -21
  113. package/lib/util/tps.js +11 -22
  114. package/lib/wallet.js +7 -20
  115. package/package.json +10 -3
  116. package/src/accounts/bulkAccountLoader.ts +26 -15
  117. package/src/accounts/bulkUserSubscription.ts +1 -45
  118. package/src/accounts/fetch.ts +33 -0
  119. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
  120. package/src/accounts/pollingOracleSubscriber.ts +16 -8
  121. package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
  122. package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
  123. package/src/accounts/types.ts +41 -70
  124. package/src/accounts/webSocketAccountSubscriber.ts +33 -16
  125. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
  126. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
  127. package/src/addresses/marketAddresses.ts +18 -0
  128. package/src/addresses/pda.ts +118 -0
  129. package/src/admin.ts +209 -267
  130. package/src/clearingHouse.ts +921 -829
  131. package/src/clearingHouseConfig.ts +37 -0
  132. package/src/clearingHouseUser.ts +280 -127
  133. package/src/clearingHouseUserConfig.ts +18 -0
  134. package/src/config.ts +54 -1
  135. package/src/constants/banks.ts +43 -0
  136. package/src/constants/markets.ts +16 -207
  137. package/src/constants/numericConstants.ts +33 -5
  138. package/src/events/eventList.ts +94 -0
  139. package/src/events/eventSubscriber.ts +194 -0
  140. package/src/events/fetchLogs.ts +80 -0
  141. package/src/events/pollingLogProvider.ts +79 -0
  142. package/src/events/sort.ts +65 -0
  143. package/src/events/txEventCache.ts +74 -0
  144. package/src/events/types.ts +98 -0
  145. package/src/events/webSocketLogProvider.ts +38 -0
  146. package/src/examples/makeTradeExample.ts +20 -11
  147. package/src/factory/bigNum.ts +507 -0
  148. package/src/factory/oracleClient.ts +7 -4
  149. package/src/idl/clearing_house.json +1739 -2287
  150. package/src/index.ts +13 -4
  151. package/src/math/amm.ts +229 -245
  152. package/src/math/auction.ts +39 -0
  153. package/src/math/bankBalance.ts +112 -0
  154. package/src/math/conversion.ts +1 -11
  155. package/src/math/funding.ts +12 -9
  156. package/src/math/market.ts +37 -30
  157. package/src/math/oracles.ts +36 -0
  158. package/src/math/orders.ts +38 -0
  159. package/src/math/position.ts +48 -13
  160. package/src/math/repeg.ts +175 -0
  161. package/src/math/trade.ts +114 -36
  162. package/src/math/utils.js +27 -0
  163. package/src/math/utils.js.map +1 -0
  164. package/src/oracles/oracleClientCache.ts +20 -0
  165. package/src/oracles/pythClient.ts +5 -11
  166. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  167. package/src/oracles/switchboardClient.ts +16 -24
  168. package/src/oracles/types.ts +8 -1
  169. package/src/orders.ts +35 -20
  170. package/src/slot/SlotSubscriber.ts +32 -0
  171. package/src/tx/retryTxSender.ts +6 -4
  172. package/src/tx/types.ts +6 -1
  173. package/src/tx/utils.ts +22 -3
  174. package/src/types.ts +108 -110
  175. package/src/userName.ts +20 -0
  176. package/src/util/computeUnits.js +17 -0
  177. package/src/util/computeUnits.js.map +1 -0
  178. package/tests/bn/test.ts +255 -0
  179. package/tsconfig.json +12 -12
  180. package/lib/addresses.d.ts +0 -9
  181. package/lib/addresses.js +0 -87
  182. package/lib/constants/accounts.d.ts +0 -15
  183. package/lib/constants/accounts.js +0 -18
  184. package/lib/factory/clearingHouse.d.ts +0 -35
  185. package/lib/factory/clearingHouse.js +0 -81
  186. package/lib/factory/clearingHouseUser.d.ts +0 -19
  187. package/lib/factory/clearingHouseUser.js +0 -34
  188. package/lib/math/insuranceFund.d.ts +0 -15
  189. package/lib/math/insuranceFund.js +0 -33
  190. package/lib/tx/defaultTxSender.d.ts +0 -8
  191. package/lib/tx/defaultTxSender.js +0 -12
  192. package/src/addresses.ts +0 -71
  193. package/src/constants/accounts.ts +0 -26
  194. package/src/factory/clearingHouse.ts +0 -173
  195. package/src/factory/clearingHouseUser.ts +0 -73
  196. package/src/math/insuranceFund.ts +0 -29
  197. package/src/tx/defaultTxSender.ts +0 -24
@@ -1,19 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="bn.js" />
3
3
  import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
- import { MarketsAccount, StateAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, OrderHistoryAccount, OrderStateAccount, OrderParams, Order, ExtendedCurveHistoryAccount, UserPositionsAccount } from './types';
5
- import { Connection, PublicKey, TransactionSignature, Keypair, ConfirmOptions, TransactionInstruction } from '@solana/web3.js';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, MarketAccount, OrderParams, Order, BankAccount, UserBankBalance, MakerInfo } from './types';
5
+ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
6
6
  import { MockUSDCFaucet } from './mockUSDCFaucet';
7
7
  import { EventEmitter } from 'events';
8
8
  import StrictEventEmitter from 'strict-event-emitter-types';
9
- import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, ClearingHouseAccountTypes } from './accounts/types';
9
+ import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, DataAndSlot } from './accounts/types';
10
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';
11
15
  /**
12
16
  * # ClearingHouse
13
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.
14
- *
15
- * The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link WebSocketClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
16
- * Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a {@link ClearingHouseAccountSubscriber} and use it in the {@link ClearingHouse.constructor}
17
18
  */
18
19
  export declare class ClearingHouse {
19
20
  connection: Connection;
@@ -21,135 +22,115 @@ export declare class ClearingHouse {
21
22
  program: Program;
22
23
  provider: AnchorProvider;
23
24
  opts?: ConfirmOptions;
25
+ users: Map<number, ClearingHouseUser>;
26
+ activeUserId: number;
27
+ userAccountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig;
24
28
  accountSubscriber: ClearingHouseAccountSubscriber;
25
29
  eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
26
30
  _isSubscribed: boolean;
27
31
  txSender: TxSender;
32
+ marketLastSlotCache: Map<number, number>;
28
33
  get isSubscribed(): boolean;
29
34
  set isSubscribed(val: boolean);
30
- /**
31
- * @deprecated You should use the getClearingHouse factory method instead
32
- * @param connection
33
- * @param wallet
34
- * @param clearingHouseProgramId
35
- * @param opts
36
- * @returns
37
- */
38
- static from(connection: Connection, wallet: IWallet, clearingHouseProgramId: PublicKey, opts?: ConfirmOptions): ClearingHouse;
39
- constructor(connection: Connection, wallet: IWallet, program: Program, accountSubscriber: ClearingHouseAccountSubscriber, txSender: TxSender, opts: ConfirmOptions);
40
- /**
41
- *
42
- * @param optionalSubscriptions - Optional extra accounts to subcribe to. Always subscribes to base clearing house state and market account state by default. You should only subscribe to optional extra accounts if required, to avoid overloading your RPC.
43
- * @returns Promise<boolean> : SubscriptionSuccess
44
- */
45
- subscribe(optionalSubscriptions?: ClearingHouseAccountTypes[]): Promise<boolean>;
46
- /**
47
- * Shorthand function to subscribe to all available Clearing House State Accounts
48
- * @returns Promise<boolean> : SubscriptionSuccess
49
- */
50
- subscribeToAll(): Promise<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>[];
51
40
  /**
52
41
  * Forces the accountSubscriber to fetch account updates from rpc
53
42
  */
54
43
  fetchAccounts(): Promise<void>;
55
- /**
56
- * Unsubscribe from all currently subscribed state accounts
57
- */
58
44
  unsubscribe(): Promise<void>;
45
+ unsubscribeUsers(): Promise<void>[];
59
46
  statePublicKey?: PublicKey;
60
47
  getStatePublicKey(): Promise<PublicKey>;
61
48
  getStateAccount(): StateAccount;
62
- getMarketsAccount(): MarketsAccount;
63
- getMarket(marketIndex: BN | number): Market;
64
- getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
65
- getFundingRateHistoryAccount(): FundingRateHistoryAccount;
66
- getTradeHistoryAccount(): TradeHistoryAccount;
67
- getLiquidationHistoryAccount(): LiquidationHistoryAccount;
68
- getDepositHistoryAccount(): DepositHistoryAccount;
69
- getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
70
- getOrderHistoryAccount(): OrderHistoryAccount;
71
- orderStatePublicKey?: PublicKey;
72
- getOrderStatePublicKey(): Promise<PublicKey>;
73
- getOrderStateAccount(): OrderStateAccount;
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;
74
54
  /**
75
55
  * Update the wallet to use for clearing house transactions and linked user account
76
56
  * @param newWallet
57
+ * @param userIds
58
+ * @param activeUserId
77
59
  */
78
- updateWallet(newWallet: IWallet): void;
79
- initializeUserAccount(): Promise<[
80
- TransactionSignature,
81
- PublicKey
82
- ]>;
83
- getInitializeUserInstructions(): Promise<[
84
- Keypair,
85
- PublicKey,
86
- TransactionInstruction,
87
- TransactionInstruction
88
- ]>;
89
- getInitializeUserOrdersInstruction(userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
90
- userAccountPublicKey?: PublicKey;
91
- /**
92
- * Get the address for the Clearing House User's account. NOT the user's wallet address.
93
- * @returns
94
- */
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[];
95
67
  getUserAccountPublicKey(): Promise<PublicKey>;
96
- userAccount?: UserAccount;
97
- getUserAccount(): Promise<UserAccount>;
98
- userOrdersAccountPublicKey?: PublicKey;
99
- /**
100
- * Get the address for the Clearing House User Order's account. NOT the user's wallet address.
101
- * @returns
102
- */
103
- getUserOrdersAccountPublicKey(): Promise<PublicKey>;
104
- userOrdersExist?: boolean;
105
- userOrdersAccountExists(): Promise<boolean>;
106
- depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionSignature>;
107
- getDepositCollateralInstruction(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
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>;
108
80
  /**
109
81
  * Creates the Clearing House User account for a user, and deposits some initial collateral
82
+ * @param userId
83
+ * @param name
110
84
  * @param amount
111
- * @param collateralAccountPublicKey
85
+ * @param userTokenAccount
86
+ * @param fromUserId
112
87
  * @returns
113
88
  */
114
- initializeUserAccountAndDepositCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<[TransactionSignature, PublicKey]>;
115
- initializeUserAccountForDevnet(mockUSDCFaucet: MockUSDCFaucet, amount: BN): Promise<[TransactionSignature, PublicKey]>;
116
- withdrawCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
117
- getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
118
- openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
119
- getOpenPositionIx(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
120
- initializeUserOrdersThenPlaceOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
121
- placeOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
122
- getPlaceOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
123
- expireOrders(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey): Promise<TransactionSignature>;
124
- getExpireOrdersIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
125
- cancelOrder(orderId: BN, oracle?: PublicKey): Promise<TransactionSignature>;
126
- getCancelOrderIx(orderId: BN, oracle?: PublicKey): Promise<TransactionInstruction>;
127
- cancelOrderByUserId(userOrderId: number, oracle?: PublicKey): Promise<TransactionSignature>;
128
- getCancelOrderByUserIdIx(userOrderId: number, oracle?: PublicKey): Promise<TransactionInstruction>;
129
- cancelAllOrders(oracles?: PublicKey[], bestEffort?: boolean): Promise<TransactionSignature>;
130
- getCancelAllOrdersIx(oracles: PublicKey[], bestEffort?: boolean): Promise<TransactionInstruction>;
131
- cancelOrdersByMarketAndSide(oracles?: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
132
- getCancelOrdersByMarketAndSideIx(oracles: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
133
- fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
134
- getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
135
- initializeUserOrdersThenPlaceAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
136
- placeAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
137
- getPlaceAndFillOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
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: OrderParams): Promise<TransactionSignature>;
99
+ getPlaceOrderIx(orderParams: OrderParams): Promise<TransactionInstruction>;
100
+ expireOrders(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
101
+ getExpireOrdersIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
102
+ updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
103
+ getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
104
+ cancelOrder(orderId: BN): Promise<TransactionSignature>;
105
+ getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
106
+ cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
107
+ getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
108
+ cancelAllOrders(bestEffort?: boolean): Promise<TransactionSignature>;
109
+ getCancelAllOrdersIx(bestEffort?: boolean): Promise<TransactionInstruction>;
110
+ cancelOrdersByMarketAndSide(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
111
+ getCancelOrdersByMarketAndSideIx(bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
112
+ fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionSignature>;
113
+ getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
114
+ placeAndTake(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
115
+ getPlaceAndTakeIx(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
138
116
  /**
139
117
  * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
140
118
  * @param marketIndex
141
- * @param discountToken
142
- * @param referrer
143
119
  * @returns
144
120
  */
145
- closePosition(marketIndex: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
146
- getClosePositionIx(marketIndex: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
147
- closeAllPositions(userPositionsAccount: UserPositionsAccount, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
121
+ closePosition(marketIndex: BN): Promise<TransactionSignature>;
122
+ settlePNLs(users: {
123
+ settleeUserAccountPublicKey: PublicKey;
124
+ settleeUserAccount: UserAccount;
125
+ }[], marketIndex: BN): Promise<TransactionSignature>;
126
+ settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
127
+ settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
148
128
  liquidate(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionSignature>;
149
129
  getLiquidateIx(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
150
130
  updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
151
131
  getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
152
- settleFundingPayment(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionSignature>;
153
- getSettleFundingPaymentIx(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionInstruction>;
132
+ settleFundingPayment(userAccount: PublicKey): Promise<TransactionSignature>;
133
+ getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
154
134
  triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
135
+ getOracleDataForMarket(marketIndex: BN): OraclePriceData;
155
136
  }