@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.2

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 +6 -6
  2. package/lib/accounts/bulkAccountLoader.js +81 -95
  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 +9 -17
  26. package/lib/admin.js +375 -558
  27. package/lib/clearingHouse.d.ts +86 -109
  28. package/lib/clearingHouse.js +828 -895
  29. package/lib/clearingHouseConfig.d.ts +34 -0
  30. package/lib/clearingHouseConfig.js +2 -0
  31. package/lib/clearingHouseUser.d.ts +19 -22
  32. package/lib/clearingHouseUser.js +155 -141
  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 +17 -0
  42. package/lib/constants/numericConstants.js +23 -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 +118 -0
  61. package/lib/factory/bigNum.js +364 -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 +2287 -2938
  65. package/lib/index.d.ts +12 -4
  66. package/lib/index.js +12 -4
  67. package/lib/math/amm.d.ts +24 -29
  68. package/lib/math/amm.js +239 -178
  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/orders.d.ts +5 -0
  80. package/lib/math/orders.js +31 -1
  81. package/lib/math/position.d.ts +7 -5
  82. package/lib/math/position.js +27 -27
  83. package/lib/math/repeg.d.ts +22 -0
  84. package/lib/math/repeg.js +128 -0
  85. package/lib/math/trade.d.ts +5 -4
  86. package/lib/math/trade.js +29 -21
  87. package/lib/mockUSDCFaucet.js +87 -116
  88. package/lib/oracles/oracleClientCache.d.ts +8 -0
  89. package/lib/oracles/oracleClientCache.js +19 -0
  90. package/lib/oracles/pythClient.d.ts +3 -5
  91. package/lib/oracles/pythClient.js +12 -31
  92. package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
  93. package/lib/oracles/quoteAssetOracleClient.js +21 -0
  94. package/lib/oracles/switchboardClient.d.ts +3 -5
  95. package/lib/oracles/switchboardClient.js +29 -50
  96. package/lib/oracles/types.d.ts +6 -1
  97. package/lib/orders.d.ts +6 -7
  98. package/lib/orders.js +10 -80
  99. package/lib/slot/SlotSubscriber.d.ts +12 -0
  100. package/lib/slot/SlotSubscriber.js +23 -0
  101. package/lib/tx/retryTxSender.d.ts +2 -2
  102. package/lib/tx/retryTxSender.js +108 -123
  103. package/lib/tx/types.d.ts +5 -1
  104. package/lib/tx/utils.d.ts +1 -1
  105. package/lib/tx/utils.js +11 -2
  106. package/lib/types.d.ts +110 -109
  107. package/lib/types.js +14 -1
  108. package/lib/userName.d.ts +4 -0
  109. package/lib/userName.js +20 -0
  110. package/lib/util/computeUnits.js +10 -21
  111. package/lib/util/tps.js +11 -22
  112. package/lib/wallet.js +7 -20
  113. package/package.json +11 -4
  114. package/src/accounts/bulkAccountLoader.ts +21 -15
  115. package/src/accounts/bulkUserSubscription.ts +1 -45
  116. package/src/accounts/fetch.ts +33 -0
  117. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
  118. package/src/accounts/pollingOracleSubscriber.ts +16 -8
  119. package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
  120. package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
  121. package/src/accounts/types.ts +41 -70
  122. package/src/accounts/webSocketAccountSubscriber.ts +33 -16
  123. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
  124. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
  125. package/src/addresses/marketAddresses.ts +18 -0
  126. package/src/addresses/pda.ts +118 -0
  127. package/src/admin.ts +218 -346
  128. package/src/clearingHouse.ts +983 -952
  129. package/src/clearingHouseConfig.ts +37 -0
  130. package/src/clearingHouseUser.ts +275 -185
  131. package/src/clearingHouseUserConfig.ts +18 -0
  132. package/src/config.ts +54 -1
  133. package/src/constants/banks.ts +43 -0
  134. package/src/constants/markets.ts +16 -207
  135. package/src/constants/numericConstants.ts +34 -5
  136. package/src/events/eventList.ts +94 -0
  137. package/src/events/eventSubscriber.ts +194 -0
  138. package/src/events/fetchLogs.ts +80 -0
  139. package/src/events/pollingLogProvider.ts +79 -0
  140. package/src/events/sort.ts +65 -0
  141. package/src/events/txEventCache.ts +74 -0
  142. package/src/events/types.ts +98 -0
  143. package/src/events/webSocketLogProvider.ts +38 -0
  144. package/src/examples/makeTradeExample.ts +20 -11
  145. package/src/factory/bigNum.ts +524 -0
  146. package/src/factory/oracleClient.ts +7 -4
  147. package/src/idl/clearing_house.json +2287 -2938
  148. package/src/index.ts +12 -4
  149. package/src/math/amm.ts +414 -245
  150. package/src/math/auction.ts +39 -0
  151. package/src/math/bankBalance.ts +112 -0
  152. package/src/math/conversion.ts +1 -11
  153. package/src/math/funding.ts +12 -9
  154. package/src/math/market.ts +37 -30
  155. package/src/math/orders.ts +38 -0
  156. package/src/math/position.ts +48 -35
  157. package/src/math/repeg.ts +176 -0
  158. package/src/math/trade.ts +45 -35
  159. package/src/math/utils.js +27 -0
  160. package/src/math/utils.js.map +1 -0
  161. package/src/oracles/oracleClientCache.ts +20 -0
  162. package/src/oracles/pythClient.ts +4 -11
  163. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  164. package/src/oracles/switchboardClient.ts +11 -24
  165. package/src/oracles/types.ts +7 -1
  166. package/src/orders.ts +24 -126
  167. package/src/slot/SlotSubscriber.ts +32 -0
  168. package/src/tx/retryTxSender.ts +6 -4
  169. package/src/tx/types.ts +6 -1
  170. package/src/tx/utils.ts +22 -3
  171. package/src/types.ts +111 -122
  172. package/src/userName.ts +20 -0
  173. package/src/util/computeUnits.js +17 -0
  174. package/src/util/computeUnits.js.map +1 -0
  175. package/tests/bn/test.ts +255 -0
  176. package/tsconfig.json +12 -12
  177. package/lib/addresses.d.ts +0 -10
  178. package/lib/addresses.js +0 -93
  179. package/lib/constants/accounts.d.ts +0 -15
  180. package/lib/constants/accounts.js +0 -18
  181. package/lib/factory/clearingHouse.d.ts +0 -35
  182. package/lib/factory/clearingHouse.js +0 -81
  183. package/lib/factory/clearingHouseUser.d.ts +0 -19
  184. package/lib/factory/clearingHouseUser.js +0 -34
  185. package/lib/math/insuranceFund.d.ts +0 -15
  186. package/lib/math/insuranceFund.js +0 -33
  187. package/lib/settlement.d.ts +0 -4
  188. package/lib/settlement.js +0 -10
  189. package/lib/tx/defaultTxSender.d.ts +0 -8
  190. package/lib/tx/defaultTxSender.js +0 -12
  191. package/src/addresses.ts +0 -82
  192. package/src/constants/accounts.ts +0 -26
  193. package/src/factory/clearingHouse.ts +0 -173
  194. package/src/factory/clearingHouseUser.ts +0 -73
  195. package/src/math/insuranceFund.ts +0 -29
  196. package/src/settlement.ts +0 -9
  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, SettlementStateAccount } 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,141 +22,117 @@ 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
- getSettlementAccount(): Promise<SettlementStateAccount>;
63
- getMarketsAccount(): MarketsAccount;
64
- getMarket(marketIndex: BN | number): Market;
65
- getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
66
- getFundingRateHistoryAccount(): FundingRateHistoryAccount;
67
- getTradeHistoryAccount(): TradeHistoryAccount;
68
- getLiquidationHistoryAccount(): LiquidationHistoryAccount;
69
- getDepositHistoryAccount(): DepositHistoryAccount;
70
- getCurveHistoryAccount(): ExtendedCurveHistoryAccount;
71
- getOrderHistoryAccount(): OrderHistoryAccount;
72
- orderStatePublicKey?: PublicKey;
73
- getOrderStatePublicKey(): Promise<PublicKey>;
74
- 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;
75
54
  /**
76
55
  * Update the wallet to use for clearing house transactions and linked user account
77
56
  * @param newWallet
57
+ * @param userIds
58
+ * @param activeUserId
78
59
  */
79
- updateWallet(newWallet: IWallet): void;
80
- initializeUserAccount(): Promise<[
81
- TransactionSignature,
82
- PublicKey
83
- ]>;
84
- getInitializeUserInstructions(): Promise<[
85
- Keypair,
86
- PublicKey,
87
- TransactionInstruction,
88
- TransactionInstruction
89
- ]>;
90
- getInitializeUserOrdersInstruction(userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
91
- userAccountPublicKey?: PublicKey;
92
- /**
93
- * Get the address for the Clearing House User's account. NOT the user's wallet address.
94
- * @returns
95
- */
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[];
96
67
  getUserAccountPublicKey(): Promise<PublicKey>;
97
- userAccount?: UserAccount;
98
- getUserAccount(): Promise<UserAccount>;
99
- userOrdersAccountPublicKey?: PublicKey;
100
- /**
101
- * Get the address for the Clearing House User Order's account. NOT the user's wallet address.
102
- * @returns
103
- */
104
- getUserOrdersAccountPublicKey(): Promise<PublicKey>;
105
- userOrdersExist?: boolean;
106
- userOrdersAccountExists(): Promise<boolean>;
107
- depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionSignature>;
108
- 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>;
109
80
  /**
110
81
  * Creates the Clearing House User account for a user, and deposits some initial collateral
82
+ * @param userId
83
+ * @param name
111
84
  * @param amount
112
- * @param collateralAccountPublicKey
85
+ * @param userTokenAccount
86
+ * @param fromUserId
113
87
  * @returns
114
88
  */
115
- initializeUserAccountAndDepositCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<[TransactionSignature, PublicKey]>;
116
- initializeUserAccountForDevnet(mockUSDCFaucet: MockUSDCFaucet, amount: BN): Promise<[TransactionSignature, PublicKey]>;
117
- withdrawCollateral(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
118
- getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
119
- openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
120
- getOpenPositionIx(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
121
- initializeUserOrdersThenPlaceOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
122
- placeOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
123
- getPlaceOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
124
- expireOrders(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey): Promise<TransactionSignature>;
125
- getExpireOrdersIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
126
- cancelOrder(orderId: BN, oracle?: PublicKey): Promise<TransactionSignature>;
127
- getCancelOrderIx(orderId: BN, oracle?: PublicKey): Promise<TransactionInstruction>;
128
- cancelOrderByUserId(userOrderId: number, oracle?: PublicKey): Promise<TransactionSignature>;
129
- getCancelOrderByUserIdIx(userOrderId: number, oracle?: PublicKey): Promise<TransactionInstruction>;
130
- cancelAllOrders(oracles?: PublicKey[], bestEffort?: boolean): Promise<TransactionSignature>;
131
- getCancelAllOrdersIx(oracles: PublicKey[], bestEffort?: boolean): Promise<TransactionInstruction>;
132
- cancelOrdersByMarketAndSide(oracles?: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
133
- getCancelOrdersByMarketAndSideIx(oracles: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
134
- fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
135
- getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
136
- initializeUserOrdersThenPlaceAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
137
- placeAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
138
- 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
+ triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
115
+ getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
116
+ placeAndTake(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionSignature>;
117
+ getPlaceAndTakeIx(orderParams: OrderParams, makerInfo?: MakerInfo): Promise<TransactionInstruction>;
139
118
  /**
140
119
  * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
141
120
  * @param marketIndex
142
- * @param discountToken
143
- * @param referrer
144
121
  * @returns
145
122
  */
146
- closePosition(marketIndex: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
147
- getClosePositionIx(marketIndex: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
148
- closeAllPositions(userPositionsAccount: UserPositionsAccount, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
123
+ closePosition(marketIndex: BN): Promise<TransactionSignature>;
124
+ settlePNLs(users: {
125
+ settleeUserAccountPublicKey: PublicKey;
126
+ settleeUserAccount: UserAccount;
127
+ }[], marketIndex: BN): Promise<TransactionSignature>;
128
+ settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
129
+ settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
149
130
  liquidate(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionSignature>;
150
131
  getLiquidateIx(liquidateeUserAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
151
132
  updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
152
133
  getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
153
- settleFundingPayment(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionSignature>;
154
- getSettleFundingPaymentIx(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionInstruction>;
134
+ settleFundingPayment(userAccount: PublicKey): Promise<TransactionSignature>;
135
+ getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
155
136
  triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
156
- settlePositionAndClaimCollateral(collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
157
- getSettlePositionIx(): Promise<TransactionInstruction>;
158
- getClaimCollateralIx(collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
159
- getTotalSettlementSize(): Promise<BN>;
160
- updateUserForgoSettlement(): Promise<TransactionSignature>;
137
+ getOracleDataForMarket(marketIndex: BN): OraclePriceData;
161
138
  }