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

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 (234) 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/pollingUserStatsAccountSubscriber.d.ts +27 -0
  15. package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
  16. package/lib/accounts/types.d.ts +26 -15
  17. package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
  18. package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
  19. package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
  20. package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
  21. package/lib/addresses/marketAddresses.d.ts +1 -3
  22. package/lib/addresses/marketAddresses.js +1 -1
  23. package/lib/addresses/pda.d.ts +15 -9
  24. package/lib/addresses/pda.js +73 -35
  25. package/lib/adminClient.d.ts +65 -0
  26. package/lib/adminClient.js +637 -0
  27. package/lib/config.d.ts +9 -9
  28. package/lib/config.js +25 -21
  29. package/lib/constants/numericConstants.d.ts +30 -12
  30. package/lib/constants/numericConstants.js +41 -21
  31. package/lib/constants/perpMarkets.d.ts +18 -0
  32. package/lib/constants/{markets.js → perpMarkets.js} +7 -7
  33. package/lib/constants/spotMarkets.d.ts +19 -0
  34. package/lib/constants/spotMarkets.js +53 -0
  35. package/lib/dlob/DLOB.d.ts +82 -0
  36. package/lib/dlob/DLOB.js +696 -0
  37. package/lib/dlob/DLOBNode.d.ts +54 -0
  38. package/lib/dlob/DLOBNode.js +77 -0
  39. package/lib/dlob/NodeList.d.ts +27 -0
  40. package/lib/dlob/NodeList.js +144 -0
  41. package/lib/driftClient.d.ts +233 -0
  42. package/lib/driftClient.js +2096 -0
  43. package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
  44. package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
  45. package/lib/events/eventList.js +3 -0
  46. package/lib/events/eventSubscriber.d.ts +5 -2
  47. package/lib/events/eventSubscriber.js +25 -11
  48. package/lib/events/fetchLogs.d.ts +13 -2
  49. package/lib/events/fetchLogs.js +40 -12
  50. package/lib/events/pollingLogProvider.d.ts +2 -1
  51. package/lib/events/pollingLogProvider.js +7 -3
  52. package/lib/events/sort.js +8 -11
  53. package/lib/events/types.d.ts +9 -3
  54. package/lib/events/types.js +6 -0
  55. package/lib/events/webSocketLogProvider.js +1 -1
  56. package/lib/examples/makeTradeExample.js +30 -18
  57. package/lib/factory/bigNum.d.ts +8 -4
  58. package/lib/factory/bigNum.js +109 -19
  59. package/lib/idl/drift.json +8250 -0
  60. package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  61. package/lib/index.d.ts +30 -13
  62. package/lib/index.js +30 -13
  63. package/lib/math/amm.d.ts +9 -6
  64. package/lib/math/amm.js +91 -38
  65. package/lib/math/conversion.js +1 -1
  66. package/lib/math/exchangeStatus.d.ts +4 -0
  67. package/lib/math/exchangeStatus.js +18 -0
  68. package/lib/math/funding.d.ts +6 -6
  69. package/lib/math/funding.js +23 -21
  70. package/lib/math/insurance.d.ts +4 -0
  71. package/lib/math/insurance.js +27 -0
  72. package/lib/math/margin.d.ts +11 -0
  73. package/lib/math/margin.js +82 -0
  74. package/lib/math/market.d.ts +14 -9
  75. package/lib/math/market.js +70 -10
  76. package/lib/math/oracles.d.ts +4 -0
  77. package/lib/math/oracles.js +36 -8
  78. package/lib/math/orders.d.ts +14 -6
  79. package/lib/math/orders.js +90 -17
  80. package/lib/math/position.d.ts +27 -13
  81. package/lib/math/position.js +92 -36
  82. package/lib/math/repeg.js +17 -8
  83. package/lib/math/spotBalance.d.ts +22 -0
  84. package/lib/math/spotBalance.js +192 -0
  85. package/lib/math/spotMarket.d.ts +4 -0
  86. package/lib/math/spotMarket.js +8 -0
  87. package/lib/math/spotPosition.d.ts +6 -0
  88. package/lib/math/spotPosition.js +23 -0
  89. package/lib/math/trade.d.ts +10 -10
  90. package/lib/math/trade.js +27 -31
  91. package/lib/oracles/pythClient.js +1 -1
  92. package/lib/oracles/quoteAssetOracleClient.js +1 -1
  93. package/lib/oracles/switchboardClient.js +1 -1
  94. package/lib/orderParams.d.ts +4 -4
  95. package/lib/orderParams.js +12 -4
  96. package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
  97. package/lib/serum/serumFulfillmentConfigMap.js +17 -0
  98. package/lib/serum/serumSubscriber.d.ts +27 -0
  99. package/lib/serum/serumSubscriber.js +56 -0
  100. package/lib/serum/types.d.ts +11 -0
  101. package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
  102. package/lib/slot/SlotSubscriber.d.ts +7 -0
  103. package/lib/slot/SlotSubscriber.js +3 -0
  104. package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
  105. package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
  106. package/lib/tx/retryTxSender.d.ts +1 -1
  107. package/lib/tx/retryTxSender.js +13 -4
  108. package/lib/tx/types.d.ts +1 -1
  109. package/lib/tx/utils.js +1 -1
  110. package/lib/types.d.ts +589 -196
  111. package/lib/types.js +108 -17
  112. package/lib/user.d.ts +226 -0
  113. package/lib/user.js +949 -0
  114. package/lib/userConfig.d.ts +14 -0
  115. package/lib/userConfig.js +2 -0
  116. package/lib/userMap/userMap.d.ts +41 -0
  117. package/lib/userMap/userMap.js +85 -0
  118. package/lib/userMap/userStatsMap.d.ts +19 -0
  119. package/lib/userMap/userStatsMap.js +68 -0
  120. package/lib/userName.d.ts +1 -0
  121. package/lib/userName.js +3 -2
  122. package/lib/userStats.d.ts +18 -0
  123. package/lib/userStats.js +49 -0
  124. package/lib/userStatsConfig.d.ts +14 -0
  125. package/lib/userStatsConfig.js +2 -0
  126. package/lib/util/computeUnits.js +1 -1
  127. package/lib/util/getTokenAddress.d.ts +2 -0
  128. package/lib/util/getTokenAddress.js +9 -0
  129. package/package.json +10 -3
  130. package/src/accounts/bulkAccountLoader.ts +44 -34
  131. package/src/accounts/bulkUserStatsSubscription.ts +33 -0
  132. package/src/accounts/bulkUserSubscription.ts +2 -3
  133. package/src/accounts/fetch.ts +27 -2
  134. package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
  135. package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
  136. package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
  137. package/src/accounts/types.ts +35 -15
  138. package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
  139. package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
  140. package/src/addresses/marketAddresses.ts +3 -4
  141. package/src/addresses/pda.ts +105 -33
  142. package/src/adminClient.ts +1207 -0
  143. package/src/config.ts +37 -31
  144. package/src/constants/numericConstants.ts +58 -24
  145. package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
  146. package/src/constants/spotMarkets.ts +73 -0
  147. package/src/dlob/DLOB.ts +1123 -0
  148. package/src/dlob/DLOBNode.ts +155 -0
  149. package/src/dlob/NodeList.ts +195 -0
  150. package/src/driftClient.ts +3564 -0
  151. package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
  152. package/src/events/eventList.ts +3 -0
  153. package/src/events/eventSubscriber.ts +36 -14
  154. package/src/events/fetchLogs.ts +55 -13
  155. package/src/events/pollingLogProvider.ts +11 -3
  156. package/src/events/sort.ts +11 -15
  157. package/src/events/types.ts +21 -2
  158. package/src/events/webSocketLogProvider.ts +1 -1
  159. package/src/examples/makeTradeExample.ts +44 -28
  160. package/src/factory/bigNum.ts +150 -22
  161. package/src/idl/drift.json +8250 -0
  162. package/src/idl/pyth.json +98 -2
  163. package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
  164. package/src/index.ts +30 -13
  165. package/src/math/amm.ts +161 -48
  166. package/src/math/conversion.ts +2 -2
  167. package/src/math/exchangeStatus.ts +31 -0
  168. package/src/math/funding.ts +41 -31
  169. package/src/math/insurance.ts +35 -0
  170. package/src/math/margin.ts +133 -0
  171. package/src/math/market.ts +143 -14
  172. package/src/math/oracles.ts +63 -9
  173. package/src/math/orders.ts +163 -26
  174. package/src/math/position.ts +136 -58
  175. package/src/math/repeg.ts +19 -9
  176. package/src/math/spotBalance.ts +319 -0
  177. package/src/math/spotMarket.ts +9 -0
  178. package/src/math/spotPosition.ts +47 -0
  179. package/src/math/trade.ts +33 -37
  180. package/src/oracles/pythClient.ts +2 -2
  181. package/src/oracles/quoteAssetOracleClient.ts +2 -2
  182. package/src/oracles/switchboardClient.ts +2 -2
  183. package/src/orderParams.ts +16 -8
  184. package/src/serum/serumFulfillmentConfigMap.ts +26 -0
  185. package/src/serum/serumSubscriber.ts +99 -0
  186. package/src/serum/types.ts +13 -0
  187. package/src/slot/SlotSubscriber.ts +11 -1
  188. package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
  189. package/src/tx/retryTxSender.ts +16 -5
  190. package/src/tx/types.ts +2 -1
  191. package/src/tx/utils.ts +1 -1
  192. package/src/types.ts +572 -178
  193. package/src/user.ts +1582 -0
  194. package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
  195. package/src/userMap/userMap.ts +124 -0
  196. package/src/userMap/userStatsMap.ts +108 -0
  197. package/src/userName.ts +2 -1
  198. package/src/userStats.ts +75 -0
  199. package/src/userStatsConfig.ts +18 -0
  200. package/src/util/computeUnits.ts +1 -1
  201. package/src/util/getTokenAddress.ts +18 -0
  202. package/tests/bn/test.ts +46 -11
  203. package/tests/dlob/helpers.ts +611 -0
  204. package/tests/dlob/test.ts +4588 -0
  205. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
  206. package/lib/admin.d.ts +0 -44
  207. package/lib/admin.js +0 -433
  208. package/lib/clearingHouse.d.ts +0 -133
  209. package/lib/clearingHouse.js +0 -931
  210. package/lib/clearingHouseUser.d.ts +0 -187
  211. package/lib/clearingHouseUser.js +0 -643
  212. package/lib/clearingHouseUserConfig.d.ts +0 -14
  213. package/lib/constants/banks.d.ts +0 -16
  214. package/lib/constants/banks.js +0 -34
  215. package/lib/constants/markets.d.ts +0 -19
  216. package/lib/idl/clearing_house.json +0 -3998
  217. package/lib/math/bankBalance.d.ts +0 -9
  218. package/lib/math/bankBalance.js +0 -75
  219. package/lib/math/state.d.ts +0 -8
  220. package/lib/math/state.js +0 -15
  221. package/lib/orders.d.ts +0 -8
  222. package/lib/orders.js +0 -134
  223. package/src/admin.ts +0 -722
  224. package/src/clearingHouse.ts +0 -1451
  225. package/src/clearingHouseUser.ts +0 -989
  226. package/src/constants/banks.ts +0 -43
  227. package/src/idl/clearing_house.json +0 -3998
  228. package/src/math/bankBalance.ts +0 -112
  229. package/src/math/state.ts +0 -14
  230. package/src/math/utils.js +0 -27
  231. package/src/math/utils.js.map +0 -1
  232. package/src/orders.ts +0 -244
  233. package/src/util/computeUnits.js +0 -17
  234. package/src/util/computeUnits.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, SpotMarketAccount, PerpMarketAccount, OraclePriceData, Order } from '..';
3
+ import { PublicKey } from '@solana/web3.js';
4
+ export interface DLOBNode {
5
+ getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
6
+ isVammNode(): boolean;
7
+ order: Order | undefined;
8
+ isBaseFilled(): boolean;
9
+ haveFilled: boolean;
10
+ userAccount: PublicKey | undefined;
11
+ market: SpotMarketAccount | PerpMarketAccount;
12
+ }
13
+ export declare abstract class OrderNode implements DLOBNode {
14
+ order: Order;
15
+ market: SpotMarketAccount | PerpMarketAccount;
16
+ userAccount: PublicKey;
17
+ sortValue: BN;
18
+ haveFilled: boolean;
19
+ haveTrigger: boolean;
20
+ constructor(order: Order, market: SpotMarketAccount | PerpMarketAccount, userAccount: PublicKey);
21
+ abstract getSortValue(order: Order): BN;
22
+ getLabel(): string;
23
+ getPrice(oraclePriceData: OraclePriceData, slot: number): BN;
24
+ isBaseFilled(): boolean;
25
+ isVammNode(): boolean;
26
+ }
27
+ export declare class LimitOrderNode extends OrderNode {
28
+ next?: LimitOrderNode;
29
+ previous?: LimitOrderNode;
30
+ getSortValue(order: Order): BN;
31
+ }
32
+ export declare class FloatingLimitOrderNode extends OrderNode {
33
+ next?: FloatingLimitOrderNode;
34
+ previous?: FloatingLimitOrderNode;
35
+ getSortValue(order: Order): BN;
36
+ }
37
+ export declare class MarketOrderNode extends OrderNode {
38
+ next?: MarketOrderNode;
39
+ previous?: MarketOrderNode;
40
+ getSortValue(order: Order): BN;
41
+ }
42
+ export declare class TriggerOrderNode extends OrderNode {
43
+ next?: TriggerOrderNode;
44
+ previous?: TriggerOrderNode;
45
+ getSortValue(order: Order): BN;
46
+ }
47
+ export declare type DLOBNodeMap = {
48
+ limit: LimitOrderNode;
49
+ floatingLimit: FloatingLimitOrderNode;
50
+ market: MarketOrderNode;
51
+ trigger: TriggerOrderNode;
52
+ };
53
+ export declare type DLOBNodeType = 'limit' | 'floatingLimit' | 'market' | ('trigger' & keyof DLOBNodeMap);
54
+ export declare function createNode<T extends DLOBNodeType>(nodeType: T, order: Order, market: SpotMarketAccount | PerpMarketAccount, userAccount: PublicKey): DLOBNodeMap[T];
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNode = exports.TriggerOrderNode = exports.MarketOrderNode = exports.FloatingLimitOrderNode = exports.LimitOrderNode = exports.OrderNode = void 0;
4
+ const __1 = require("..");
5
+ const NodeList_1 = require("./NodeList");
6
+ class OrderNode {
7
+ constructor(order, market, userAccount) {
8
+ this.haveFilled = false;
9
+ this.haveTrigger = false;
10
+ this.order = order;
11
+ this.market = market;
12
+ this.userAccount = userAccount;
13
+ this.sortValue = this.getSortValue(order);
14
+ }
15
+ getLabel() {
16
+ let msg = `Order ${(0, NodeList_1.getOrderSignature)(this.order.orderId, this.userAccount)}`;
17
+ msg += ` ${(0, __1.isVariant)(this.order.direction, 'long') ? 'LONG' : 'SHORT'} `;
18
+ msg += `${(0, __1.convertToNumber)(this.order.baseAssetAmount, __1.AMM_RESERVE_PRECISION).toFixed(3)}`;
19
+ if (this.order.price.gt(__1.ZERO)) {
20
+ msg += ` @ ${(0, __1.convertToNumber)(this.order.price, __1.PRICE_PRECISION).toFixed(3)}`;
21
+ }
22
+ if (this.order.triggerPrice.gt(__1.ZERO)) {
23
+ msg += ` ${(0, __1.isVariant)(this.order.triggerCondition, 'below') ? 'BELOW' : 'ABOVE'}`;
24
+ msg += ` ${(0, __1.convertToNumber)(this.order.triggerPrice, __1.PRICE_PRECISION).toFixed(3)}`;
25
+ }
26
+ return msg;
27
+ }
28
+ getPrice(oraclePriceData, slot) {
29
+ return (0, __1.getLimitPrice)(this.order, oraclePriceData, slot);
30
+ }
31
+ isBaseFilled() {
32
+ return this.order.baseAssetAmountFilled.eq(this.order.baseAssetAmount);
33
+ }
34
+ isVammNode() {
35
+ return false;
36
+ }
37
+ }
38
+ exports.OrderNode = OrderNode;
39
+ class LimitOrderNode extends OrderNode {
40
+ getSortValue(order) {
41
+ return order.price;
42
+ }
43
+ }
44
+ exports.LimitOrderNode = LimitOrderNode;
45
+ class FloatingLimitOrderNode extends OrderNode {
46
+ getSortValue(order) {
47
+ return new __1.BN(order.oraclePriceOffset);
48
+ }
49
+ }
50
+ exports.FloatingLimitOrderNode = FloatingLimitOrderNode;
51
+ class MarketOrderNode extends OrderNode {
52
+ getSortValue(order) {
53
+ return order.slot;
54
+ }
55
+ }
56
+ exports.MarketOrderNode = MarketOrderNode;
57
+ class TriggerOrderNode extends OrderNode {
58
+ getSortValue(order) {
59
+ return order.triggerPrice;
60
+ }
61
+ }
62
+ exports.TriggerOrderNode = TriggerOrderNode;
63
+ function createNode(nodeType, order, market, userAccount) {
64
+ switch (nodeType) {
65
+ case 'floatingLimit':
66
+ return new FloatingLimitOrderNode(order, market, userAccount);
67
+ case 'limit':
68
+ return new LimitOrderNode(order, market, userAccount);
69
+ case 'market':
70
+ return new MarketOrderNode(order, market, userAccount);
71
+ case 'trigger':
72
+ return new TriggerOrderNode(order, market, userAccount);
73
+ default:
74
+ throw Error(`Unknown DLOBNode type ${nodeType}`);
75
+ }
76
+ }
77
+ exports.createNode = createNode;
@@ -0,0 +1,27 @@
1
+ /// <reference types="bn.js" />
2
+ import { BN, MarketTypeStr, Order, PerpMarketAccount, SpotMarketAccount } from '..';
3
+ import { PublicKey } from '@solana/web3.js';
4
+ import { DLOBNode, DLOBNodeMap } from './DLOBNode';
5
+ export declare type SortDirection = 'asc' | 'desc';
6
+ export declare function getOrderSignature(orderId: number, userAccount: PublicKey): string;
7
+ export interface DLOBNodeGenerator {
8
+ getGenerator(): Generator<DLOBNode>;
9
+ }
10
+ export declare class NodeList<NodeType extends keyof DLOBNodeMap> implements DLOBNodeGenerator {
11
+ private nodeType;
12
+ private sortDirection;
13
+ head?: DLOBNodeMap[NodeType];
14
+ length: number;
15
+ nodeMap: Map<string, DLOBNodeMap[NodeType]>;
16
+ constructor(nodeType: NodeType, sortDirection: SortDirection);
17
+ clear(): void;
18
+ insert(order: Order, marketType: MarketTypeStr, market: PerpMarketAccount | SpotMarketAccount, userAccount: PublicKey): void;
19
+ prependNode(currentNode: DLOBNodeMap[NodeType], newNode: DLOBNodeMap[NodeType]): boolean;
20
+ update(order: Order, userAccount: PublicKey): void;
21
+ remove(order: Order, userAccount: PublicKey): void;
22
+ getGenerator(): Generator<DLOBNode>;
23
+ has(order: Order, userAccount: PublicKey): boolean;
24
+ print(): void;
25
+ printTop(): void;
26
+ }
27
+ export declare function getVammNodeGenerator(price: BN | undefined): Generator<DLOBNode>;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getVammNodeGenerator = exports.NodeList = exports.getOrderSignature = void 0;
4
+ const __1 = require("..");
5
+ const DLOBNode_1 = require("./DLOBNode");
6
+ function getOrderSignature(orderId, userAccount) {
7
+ return `${userAccount.toString()}-${orderId.toString()}`;
8
+ }
9
+ exports.getOrderSignature = getOrderSignature;
10
+ class NodeList {
11
+ constructor(nodeType, sortDirection) {
12
+ this.nodeType = nodeType;
13
+ this.sortDirection = sortDirection;
14
+ this.length = 0;
15
+ this.nodeMap = new Map();
16
+ }
17
+ clear() {
18
+ this.head = undefined;
19
+ this.length = 0;
20
+ this.nodeMap.clear();
21
+ }
22
+ insert(order, marketType, market, userAccount) {
23
+ if ((0, __1.isVariant)(order.status, 'init')) {
24
+ return;
25
+ }
26
+ if (marketType === 'spot') {
27
+ market = market;
28
+ }
29
+ else if (marketType === 'perp') {
30
+ market = market;
31
+ }
32
+ const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, market, userAccount);
33
+ const orderSignature = getOrderSignature(order.orderId, userAccount);
34
+ if (this.nodeMap.has(orderSignature)) {
35
+ return;
36
+ }
37
+ this.nodeMap.set(orderSignature, newNode);
38
+ this.length += 1;
39
+ if (this.head === undefined) {
40
+ this.head = newNode;
41
+ return;
42
+ }
43
+ if (this.prependNode(this.head, newNode)) {
44
+ this.head.previous = newNode;
45
+ newNode.next = this.head;
46
+ this.head = newNode;
47
+ return;
48
+ }
49
+ let currentNode = this.head;
50
+ while (currentNode.next !== undefined &&
51
+ !this.prependNode(currentNode.next, newNode)) {
52
+ currentNode = currentNode.next;
53
+ }
54
+ newNode.next = currentNode.next;
55
+ if (currentNode.next !== undefined) {
56
+ newNode.next.previous = newNode;
57
+ }
58
+ currentNode.next = newNode;
59
+ newNode.previous = currentNode;
60
+ }
61
+ prependNode(currentNode, newNode) {
62
+ const currentOrder = currentNode.order;
63
+ const newOrder = newNode.order;
64
+ const currentOrderSortPrice = currentNode.sortValue;
65
+ const newOrderSortPrice = newNode.sortValue;
66
+ if (newOrderSortPrice.eq(currentOrderSortPrice)) {
67
+ return newOrder.slot.lt(currentOrder.slot);
68
+ }
69
+ if (this.sortDirection === 'asc') {
70
+ return newOrderSortPrice.lt(currentOrderSortPrice);
71
+ }
72
+ else {
73
+ return newOrderSortPrice.gt(currentOrderSortPrice);
74
+ }
75
+ }
76
+ update(order, userAccount) {
77
+ const orderId = getOrderSignature(order.orderId, userAccount);
78
+ if (this.nodeMap.has(orderId)) {
79
+ const node = this.nodeMap.get(orderId);
80
+ Object.assign(node.order, order);
81
+ node.haveFilled = false;
82
+ }
83
+ }
84
+ remove(order, userAccount) {
85
+ const orderId = getOrderSignature(order.orderId, userAccount);
86
+ if (this.nodeMap.has(orderId)) {
87
+ const node = this.nodeMap.get(orderId);
88
+ if (node.next) {
89
+ node.next.previous = node.previous;
90
+ }
91
+ if (node.previous) {
92
+ node.previous.next = node.next;
93
+ }
94
+ if (this.head && node.order.orderId === this.head.order.orderId) {
95
+ this.head = node.next;
96
+ }
97
+ node.previous = undefined;
98
+ node.next = undefined;
99
+ this.nodeMap.delete(orderId);
100
+ this.length--;
101
+ }
102
+ }
103
+ *getGenerator() {
104
+ let node = this.head;
105
+ while (node !== undefined) {
106
+ yield node;
107
+ node = node.next;
108
+ }
109
+ }
110
+ has(order, userAccount) {
111
+ return this.nodeMap.has(getOrderSignature(order.orderId, userAccount));
112
+ }
113
+ print() {
114
+ let currentNode = this.head;
115
+ while (currentNode !== undefined) {
116
+ console.log(currentNode.getLabel());
117
+ currentNode = currentNode.next;
118
+ }
119
+ }
120
+ printTop() {
121
+ if (this.head) {
122
+ console.log(this.sortDirection.toUpperCase(), this.head.getLabel());
123
+ }
124
+ else {
125
+ console.log('---');
126
+ }
127
+ }
128
+ }
129
+ exports.NodeList = NodeList;
130
+ function* getVammNodeGenerator(price) {
131
+ if (!price) {
132
+ return;
133
+ }
134
+ yield {
135
+ getPrice: () => price,
136
+ isVammNode: () => true,
137
+ order: undefined,
138
+ market: undefined,
139
+ userAccount: undefined,
140
+ isBaseFilled: () => false,
141
+ haveFilled: false,
142
+ };
143
+ }
144
+ exports.getVammNodeGenerator = getVammNodeGenerator;
@@ -0,0 +1,233 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="bn.js" />
3
+ import { AnchorProvider, BN, Program } from '@project-serum/anchor';
4
+ import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, SerumV3FulfillmentConfigAccount } from './types';
5
+ import * as anchor from '@project-serum/anchor';
6
+ import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta } from '@solana/web3.js';
7
+ import { TokenFaucet } from './tokenFaucet';
8
+ import { EventEmitter } from 'events';
9
+ import StrictEventEmitter from 'strict-event-emitter-types';
10
+ import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './accounts/types';
11
+ import { TxSender } from './tx/types';
12
+ import { OraclePriceData } from './oracles/types';
13
+ import { DriftClientConfig } from './driftClientConfig';
14
+ import { User } from './user';
15
+ import { UserSubscriptionConfig } from './userConfig';
16
+ import { UserStats } from './userStats';
17
+ declare type RemainingAccountParams = {
18
+ userAccounts: UserAccount[];
19
+ writablePerpMarketIndexes?: number[];
20
+ writableSpotMarketIndexes?: number[];
21
+ readablePerpMarketIndex?: number;
22
+ readableSpotMarketIndexes?: number[];
23
+ useMarketLastSlotCache?: boolean;
24
+ };
25
+ /**
26
+ * # DriftClient
27
+ * 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.
28
+ */
29
+ export declare class DriftClient {
30
+ connection: Connection;
31
+ wallet: IWallet;
32
+ program: Program;
33
+ provider: AnchorProvider;
34
+ opts?: ConfirmOptions;
35
+ users: Map<number, User>;
36
+ userStats?: UserStats;
37
+ activeSubAccountId: number;
38
+ userAccountSubscriptionConfig: UserSubscriptionConfig;
39
+ accountSubscriber: DriftClientAccountSubscriber;
40
+ eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
41
+ _isSubscribed: boolean;
42
+ txSender: TxSender;
43
+ perpMarketLastSlotCache: Map<number, number>;
44
+ spotMarketLastSlotCache: Map<number, number>;
45
+ authority: PublicKey;
46
+ get isSubscribed(): boolean;
47
+ set isSubscribed(val: boolean);
48
+ constructor(config: DriftClientConfig);
49
+ createUsers(subAccountIds: number[], accountSubscriptionConfig: UserSubscriptionConfig): void;
50
+ createUser(subAccountId: number, accountSubscriptionConfig: UserSubscriptionConfig): User;
51
+ subscribe(): Promise<boolean>;
52
+ subscribeUsers(): Promise<boolean>[];
53
+ /**
54
+ * Forces the accountSubscriber to fetch account updates from rpc
55
+ */
56
+ fetchAccounts(): Promise<void>;
57
+ unsubscribe(): Promise<void>;
58
+ unsubscribeUsers(): Promise<void>[];
59
+ statePublicKey?: PublicKey;
60
+ getStatePublicKey(): Promise<PublicKey>;
61
+ signerPublicKey?: PublicKey;
62
+ getSignerPublicKey(): PublicKey;
63
+ getStateAccount(): StateAccount;
64
+ getPerpMarketAccount(marketIndex: number): PerpMarketAccount | undefined;
65
+ getPerpMarketAccounts(): PerpMarketAccount[];
66
+ getSpotMarketAccount(marketIndex: number): SpotMarketAccount | undefined;
67
+ getSpotMarketAccounts(): SpotMarketAccount[];
68
+ getQuoteSpotMarketAccount(): SpotMarketAccount;
69
+ getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
70
+ getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
71
+ /**
72
+ * Update the wallet to use for drift transactions and linked user account
73
+ * @param newWallet
74
+ * @param subAccountIds
75
+ * @param activeSubAccountId
76
+ */
77
+ updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number): Promise<void>;
78
+ switchActiveUser(subAccountId: number): Promise<void>;
79
+ addUser(subAccountId: number): Promise<void>;
80
+ initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
81
+ getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
82
+ getInitializeUserStatsIx(): Promise<TransactionInstruction>;
83
+ updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
84
+ updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
85
+ updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
86
+ getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
87
+ deleteUser(subAccountId?: number): Promise<TransactionSignature>;
88
+ getUser(subAccountId?: number): User;
89
+ getUsers(): User[];
90
+ getUserStats(): UserStats;
91
+ userStatsAccountPublicKey: PublicKey;
92
+ getUserStatsAccountPublicKey(): PublicKey;
93
+ getUserAccountPublicKey(): Promise<PublicKey>;
94
+ getUserAccount(subAccountId?: number): UserAccount | undefined;
95
+ getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
96
+ getSpotPosition(marketIndex: number): SpotPosition | undefined;
97
+ getQuoteAssetTokenAmount(): BN;
98
+ getTokenAmount(marketIndex: number): BN;
99
+ getRemainingAccounts(params: RemainingAccountParams): AccountMeta[];
100
+ getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
101
+ oracleAccountMap: Map<string, AccountMeta>;
102
+ spotMarketAccountMap: Map<number, AccountMeta>;
103
+ perpMarketAccountMap: Map<number, AccountMeta>;
104
+ };
105
+ getOrder(orderId: number): Order | undefined;
106
+ getOrderByUserId(userOrderId: number): Order | undefined;
107
+ deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
108
+ getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
109
+ private checkIfAccountExists;
110
+ private getWrappedSolAccountCreationIxs;
111
+ getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
112
+ /**
113
+ * Creates the Clearing House User account for a user, and deposits some initial collateral
114
+ * @param amount
115
+ * @param userTokenAccount
116
+ * @param marketIndex
117
+ * @param subAccountId
118
+ * @param name
119
+ * @param fromSubAccountId
120
+ * @returns
121
+ */
122
+ initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
123
+ initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
124
+ withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
125
+ getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
126
+ transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionSignature>;
127
+ getTransferDepositIx(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionInstruction>;
128
+ updateSpotMarketCumulativeInterest(marketIndex: number): Promise<TransactionSignature>;
129
+ updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
130
+ settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionSignature>;
131
+ settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
132
+ removePerpLpShares(marketIndex: number, sharesToBurn?: BN): Promise<TransactionSignature>;
133
+ removePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionSignature>;
134
+ getRemovePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionInstruction>;
135
+ getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
136
+ addPerpLpShares(amount: BN, marketIndex: number): Promise<TransactionSignature>;
137
+ getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
138
+ openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
139
+ sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
140
+ /**
141
+ * Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
142
+ * @param orderParams
143
+ * @param userAccountPublicKey
144
+ * @param userAccount
145
+ * @returns
146
+ */
147
+ sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<{
148
+ txSig: TransactionSignature;
149
+ signedFillTx: Transaction;
150
+ }>;
151
+ placePerpOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
152
+ getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
153
+ getPlacePerpOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
154
+ updateAMMs(marketIndexes: number[]): Promise<TransactionSignature>;
155
+ getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
156
+ settleExpiredMarket(marketIndex: number): Promise<TransactionSignature>;
157
+ getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
158
+ settleExpiredMarketPoolsToRevenuePool(perpMarketIndex: number): Promise<TransactionSignature>;
159
+ cancelOrder(orderId?: number): Promise<TransactionSignature>;
160
+ getCancelOrderIx(orderId?: number): Promise<TransactionInstruction>;
161
+ cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
162
+ getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
163
+ cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection): Promise<TransactionSignature>;
164
+ getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null): Promise<TransactionInstruction>;
165
+ fillPerpOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
166
+ getFillPerpOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
167
+ placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
168
+ getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
169
+ fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
170
+ getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
171
+ addSpotFulfillmentAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount): void;
172
+ addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
173
+ triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
174
+ getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
175
+ placeAndTakePerpOrder(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
176
+ getPlaceAndTakePerpOrderIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
177
+ placeAndMakePerpOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
178
+ getPlaceAndMakePerpOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
179
+ placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
180
+ getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
181
+ placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
182
+ getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
183
+ /**
184
+ * Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
185
+ * @param marketIndex
186
+ * @returns
187
+ */
188
+ closePosition(marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
189
+ /**
190
+ * Modifies an open order by closing it and replacing it with a new order.
191
+ * @param orderId: The open order to modify
192
+ * @param newBaseAmount: The new base amount for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
193
+ * @param newLimitPice: The new limit price for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
194
+ * @param newOraclePriceOffset: The new oracle price offset for the order. One of [newBaseAmount|newLimitPrice|newOraclePriceOffset] must be provided.
195
+ * @returns
196
+ */
197
+ modifyPerpOrder(orderId: number, newBaseAmount?: BN, newLimitPrice?: BN, newOraclePriceOffset?: number): Promise<TransactionSignature>;
198
+ settlePNLs(users: {
199
+ settleeUserAccountPublicKey: PublicKey;
200
+ settleeUserAccount: UserAccount;
201
+ }[], marketIndex: number): Promise<TransactionSignature>;
202
+ settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
203
+ settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
204
+ liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionSignature>;
205
+ getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: BN): Promise<TransactionInstruction>;
206
+ liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
207
+ getLiquidateSpotIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
208
+ liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
209
+ getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
210
+ liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN): Promise<TransactionSignature>;
211
+ getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN): Promise<TransactionInstruction>;
212
+ resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
213
+ getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
214
+ resolveSpotBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
215
+ getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
216
+ updateFundingRate(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionSignature>;
217
+ getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
218
+ settleFundingPayment(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
219
+ getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
220
+ triggerEvent(eventName: keyof DriftClientAccountEvents, data?: any): void;
221
+ getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
222
+ getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
223
+ initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
224
+ getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
225
+ addInsuranceFundStake(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
226
+ requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
227
+ cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
228
+ removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
229
+ settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
230
+ resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionSignature>;
231
+ getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
232
+ }
233
+ export {};