@drift-labs/sdk 0.1.36-master.7 → 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 +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 +8 -17
  26. package/lib/admin.js +366 -558
  27. package/lib/clearingHouse.d.ts +84 -109
  28. package/lib/clearingHouse.js +778 -899
  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 +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 +2213 -2951
  65. package/lib/index.d.ts +12 -4
  66. package/lib/index.js +12 -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/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 -6
  98. package/lib/orders.js +10 -9
  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 +105 -109
  107. package/lib/types.js +13 -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 +10 -3
  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 +205 -346
  128. package/src/clearingHouse.ts +918 -961
  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 +33 -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 +507 -0
  146. package/src/factory/oracleClient.ts +7 -4
  147. package/src/idl/clearing_house.json +2213 -2951
  148. package/src/index.ts +12 -4
  149. package/src/math/amm.ts +229 -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 +175 -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 +35 -20
  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 +108 -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,10 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- export declare function getClearingHouseStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
3
- export declare function getOrderStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
4
- export declare function getOrderStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
5
- export declare function getClearingHouseStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
6
- export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>;
7
- export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey): Promise<PublicKey>;
8
- export declare function getUserOrdersAccountPublicKeyAndNonce(programId: PublicKey, userAccount: PublicKey): Promise<[PublicKey, number]>;
9
- export declare function getUserOrdersAccountPublicKey(programId: PublicKey, userAccount: PublicKey): Promise<PublicKey>;
10
- export declare function getSettlementStatePublicKey(programId: PublicKey): Promise<PublicKey>;
package/lib/addresses.js DELETED
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.getSettlementStatePublicKey = exports.getUserOrdersAccountPublicKey = exports.getUserOrdersAccountPublicKeyAndNonce = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getOrderStateAccountPublicKeyAndNonce = exports.getOrderStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
36
- const anchor = __importStar(require("@project-serum/anchor"));
37
- function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId);
40
- });
41
- }
42
- exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
43
- function getOrderStateAccountPublicKey(programId) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return (yield getOrderStateAccountPublicKeyAndNonce(programId))[0];
46
- });
47
- }
48
- exports.getOrderStateAccountPublicKey = getOrderStateAccountPublicKey;
49
- function getOrderStateAccountPublicKeyAndNonce(programId) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))], programId);
52
- });
53
- }
54
- exports.getOrderStateAccountPublicKeyAndNonce = getOrderStateAccountPublicKeyAndNonce;
55
- function getClearingHouseStateAccountPublicKey(programId) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- return (yield getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
58
- });
59
- }
60
- exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
61
- function getUserAccountPublicKeyAndNonce(programId, authority) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('user')), authority.toBuffer()], programId);
64
- });
65
- }
66
- exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
67
- function getUserAccountPublicKey(programId, authority) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- return (yield getUserAccountPublicKeyAndNonce(programId, authority))[0];
70
- });
71
- }
72
- exports.getUserAccountPublicKey = getUserAccountPublicKey;
73
- function getUserOrdersAccountPublicKeyAndNonce(programId, userAccount) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- return anchor.web3.PublicKey.findProgramAddress([
76
- Buffer.from(anchor.utils.bytes.utf8.encode('user_orders')),
77
- userAccount.toBuffer(),
78
- ], programId);
79
- });
80
- }
81
- exports.getUserOrdersAccountPublicKeyAndNonce = getUserOrdersAccountPublicKeyAndNonce;
82
- function getUserOrdersAccountPublicKey(programId, userAccount) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- return (yield getUserOrdersAccountPublicKeyAndNonce(programId, userAccount))[0];
85
- });
86
- }
87
- exports.getUserOrdersAccountPublicKey = getUserOrdersAccountPublicKey;
88
- function getSettlementStatePublicKey(programId) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- return (yield anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('settlement_state'))], programId))[0];
91
- });
92
- }
93
- exports.getSettlementStatePublicKey = getSettlementStatePublicKey;
@@ -1,15 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- export declare const CLEARING_HOUSE_STATE_ACCOUNTS: {
3
- dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
4
- state: PublicKey;
5
- markets: PublicKey;
6
- orderState: PublicKey;
7
- tradeHistory: PublicKey;
8
- depositHistory: PublicKey;
9
- fundingPaymentHistory: PublicKey;
10
- fundingRateHistory: PublicKey;
11
- extendedCurveHistory: PublicKey;
12
- liquidationHistory: PublicKey;
13
- orderHistory: PublicKey;
14
- };
15
- };
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLEARING_HOUSE_STATE_ACCOUNTS = void 0;
4
- const web3_js_1 = require("@solana/web3.js");
5
- exports.CLEARING_HOUSE_STATE_ACCOUNTS = {
6
- dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
7
- state: new web3_js_1.PublicKey('FExhvPycCCwYnZGeDsVtLhpEQ3yEkVY2k1HuPyfLj91L'),
8
- markets: new web3_js_1.PublicKey('773hq3SbGPKVj93TXi5qV5CREuhxobywfALjS3XVHhLH'),
9
- orderState: new web3_js_1.PublicKey('4cC34bWwTPGncBaX2S6v5mH3Lj4Nb3byPMrxQSDcY985'),
10
- tradeHistory: new web3_js_1.PublicKey('FCuCXEoQppoaCYdttA7rK3HNQfYkTNEGpwuBESzYcENp'),
11
- depositHistory: new web3_js_1.PublicKey('C7rF2Qy2rnDGQLRijBRRArJyaeuQcFi81BXDrUCQ45ya'),
12
- fundingPaymentHistory: new web3_js_1.PublicKey('895iPhzwT2tBufLnRpYtBG3gif1HDDUfpH2AqbS5joo4'),
13
- fundingRateHistory: new web3_js_1.PublicKey('BWiJLMbmrwfqHVpcPJa8715XamNyNYamDDKQVQMnduEC'),
14
- extendedCurveHistory: new web3_js_1.PublicKey('7vBbqvMdtZLQdTVdzt5y63pZdAFE5W42kP3avngSJKCk'),
15
- liquidationHistory: new web3_js_1.PublicKey('CSFaaf8yVoTx6NcXUKtNPYAewv76CH2jATqSVRBvUWKM'),
16
- orderHistory: new web3_js_1.PublicKey('DZ7XfUqyHoRKnJLRApxmJ943xHJ7NDBUTqpbooviEtbU'),
17
- },
18
- };
@@ -1,35 +0,0 @@
1
- import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
2
- import { IWallet } from '../types';
3
- import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
- import { ClearingHouse } from '../clearingHouse';
5
- import { Admin } from '../admin';
6
- export declare type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
7
- declare type BaseClearingHouseConfig = {
8
- type: ClearingHouseConfigType;
9
- connection: Connection;
10
- wallet: IWallet;
11
- programID: PublicKey;
12
- opts?: ConfirmOptions;
13
- txSenderConfig?: TxSenderConfig;
14
- };
15
- declare type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
16
- declare type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
17
- accountLoader: BulkAccountLoader;
18
- };
19
- declare type ClearingHouseConfig = PollingClearingHouseConfiguration | WebSocketClearingHouseConfiguration;
20
- export declare type TxSenderType = 'default' | 'retry';
21
- declare type BaseTxSenderConfig = {
22
- type: TxSenderType;
23
- };
24
- declare type DefaultTxSenderConfig = BaseTxSenderConfig;
25
- declare type RetryTxSenderConfig = BaseTxSenderConfig & {
26
- timeout?: number;
27
- retrySleep?: number;
28
- additionalConnections?: Connection[];
29
- };
30
- declare type TxSenderConfig = DefaultTxSenderConfig | RetryTxSenderConfig;
31
- export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): WebSocketClearingHouseConfiguration;
32
- export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): PollingClearingHouseConfiguration;
33
- export declare function getClearingHouse(config: ClearingHouseConfig): ClearingHouse;
34
- export declare function getAdmin(config: ClearingHouseConfig): Admin;
35
- export {};
@@ -1,81 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getAdmin = exports.getClearingHouse = exports.getPollingClearingHouseConfig = exports.getWebSocketClearingHouseConfig = void 0;
7
- const anchor_1 = require("@project-serum/anchor");
8
- const clearingHouse_1 = require("../clearingHouse");
9
- const clearing_house_json_1 = __importDefault(require("../idl/clearing_house.json"));
10
- const webSocketClearingHouseAccountSubscriber_1 = require("../accounts/webSocketClearingHouseAccountSubscriber");
11
- const defaultTxSender_1 = require("../tx/defaultTxSender");
12
- const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
13
- const admin_1 = require("../admin");
14
- const retryTxSender_1 = require("../tx/retryTxSender");
15
- function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
16
- return {
17
- type: 'websocket',
18
- connection,
19
- wallet,
20
- programID,
21
- opts,
22
- txSenderConfig,
23
- };
24
- }
25
- exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
26
- function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
27
- return {
28
- type: 'polling',
29
- connection,
30
- wallet,
31
- programID,
32
- accountLoader,
33
- opts,
34
- txSenderConfig,
35
- };
36
- }
37
- exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
38
- function getClearingHouse(config) {
39
- var _a;
40
- const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
41
- const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
42
- let accountSubscriber;
43
- if (config.type === 'websocket') {
44
- accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
45
- }
46
- else if (config.type === 'polling') {
47
- accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
48
- }
49
- let txSender;
50
- if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
51
- const txSenderConfig = config.txSenderConfig;
52
- txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
53
- }
54
- else {
55
- txSender = new defaultTxSender_1.DefaultTxSender(provider);
56
- }
57
- return new clearingHouse_1.ClearingHouse(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
58
- }
59
- exports.getClearingHouse = getClearingHouse;
60
- function getAdmin(config) {
61
- var _a;
62
- const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
63
- const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
64
- let accountSubscriber;
65
- if (config.type === 'websocket') {
66
- accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
67
- }
68
- else if (config.type === 'polling') {
69
- accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
70
- }
71
- let txSender;
72
- if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
73
- const txSenderConfig = config.txSenderConfig;
74
- txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
75
- }
76
- else {
77
- txSender = new defaultTxSender_1.DefaultTxSender(provider);
78
- }
79
- return new admin_1.Admin(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
80
- }
81
- exports.getAdmin = getAdmin;
@@ -1,19 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- import { ClearingHouse } from '../clearingHouse';
3
- import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
- import { ClearingHouseUser } from '../clearingHouseUser';
5
- export declare type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
6
- declare type BaseClearingHouseUserConfig = {
7
- type: ClearingHouseUserConfigType;
8
- clearingHouse: ClearingHouse;
9
- authority: PublicKey;
10
- };
11
- declare type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
12
- declare type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
13
- accountLoader: BulkAccountLoader;
14
- };
15
- declare type ClearingHouseUserConfig = PollingClearingHouseUserConfig | WebSocketClearingHouseUserConfig;
16
- export declare function getWebSocketClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey): WebSocketClearingHouseUserConfig;
17
- export declare function getPollingClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey, accountLoader: BulkAccountLoader): PollingClearingHouseUserConfig;
18
- export declare function getClearingHouseUser(config: ClearingHouseUserConfig): ClearingHouseUser;
19
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClearingHouseUser = exports.getPollingClearingHouseUserConfig = exports.getWebSocketClearingHouseUserConfig = void 0;
4
- const clearingHouseUser_1 = require("../clearingHouseUser");
5
- const webSocketUserAccountSubscriber_1 = require("../accounts/webSocketUserAccountSubscriber");
6
- const pollingUserAccountSubscriber_1 = require("../accounts/pollingUserAccountSubscriber");
7
- function getWebSocketClearingHouseUserConfig(clearingHouse, authority) {
8
- return {
9
- type: 'websocket',
10
- clearingHouse,
11
- authority,
12
- };
13
- }
14
- exports.getWebSocketClearingHouseUserConfig = getWebSocketClearingHouseUserConfig;
15
- function getPollingClearingHouseUserConfig(clearingHouse, authority, accountLoader) {
16
- return {
17
- type: 'polling',
18
- clearingHouse,
19
- authority,
20
- accountLoader,
21
- };
22
- }
23
- exports.getPollingClearingHouseUserConfig = getPollingClearingHouseUserConfig;
24
- function getClearingHouseUser(config) {
25
- let accountSubscriber;
26
- if (config.type === 'websocket') {
27
- accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.clearingHouse.program, config.authority);
28
- }
29
- else if (config.type === 'polling') {
30
- accountSubscriber = new pollingUserAccountSubscriber_1.PollingUserAccountSubscriber(config.clearingHouse.program, config.authority, config.accountLoader);
31
- }
32
- return new clearingHouseUser_1.ClearingHouseUser(config.clearingHouse, config.authority, accountSubscriber);
33
- }
34
- exports.getClearingHouseUser = getClearingHouseUser;
@@ -1,15 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { MarketsAccount, StateAccount } from '../types';
3
- import { BN } from '../';
4
- import { Connection } from '@solana/web3.js';
5
- /**
6
- * In the case of a levered loss, the exchange first pays out undistributed fees and then the insurance fund.
7
- * Thus the de facto size of the insurance fund is the amount in the insurance vault plus the sum of each markets
8
- * undistributed fees.
9
- *
10
- * @param connection
11
- * @param state
12
- * @param marketsAccount
13
- * @returns Precision : QUOTE_ASSET_PRECISION
14
- */
15
- export declare function calculateInsuranceFundSize(connection: Connection, state: StateAccount, marketsAccount: MarketsAccount): Promise<BN>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.calculateInsuranceFundSize = void 0;
13
- const __1 = require("../");
14
- /**
15
- * In the case of a levered loss, the exchange first pays out undistributed fees and then the insurance fund.
16
- * Thus the de facto size of the insurance fund is the amount in the insurance vault plus the sum of each markets
17
- * undistributed fees.
18
- *
19
- * @param connection
20
- * @param state
21
- * @param marketsAccount
22
- * @returns Precision : QUOTE_ASSET_PRECISION
23
- */
24
- function calculateInsuranceFundSize(connection, state, marketsAccount) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- const insuranceVaultPublicKey = state.insuranceVault;
27
- const insuranceVaultAmount = new __1.BN((yield connection.getTokenAccountBalance(insuranceVaultPublicKey)).value.amount);
28
- return marketsAccount.markets.reduce((insuranceVaultAmount, market) => {
29
- return insuranceVaultAmount.add(market.amm.totalFee.div(new __1.BN(2)));
30
- }, insuranceVaultAmount);
31
- });
32
- }
33
- exports.calculateInsuranceFundSize = calculateInsuranceFundSize;
@@ -1,4 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { BN } from '@project-serum/anchor';
3
- export declare const SETTLEMENT_RATIO_PRECISION: BN;
4
- export declare const SETTLEMENT_RATIOS: number[];
package/lib/settlement.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SETTLEMENT_RATIOS = exports.SETTLEMENT_RATIO_PRECISION = void 0;
4
- const anchor_1 = require("@project-serum/anchor");
5
- exports.SETTLEMENT_RATIO_PRECISION = new anchor_1.BN(1000000);
6
- exports.SETTLEMENT_RATIOS = [
7
- 291786, 243613, 712271, 293771, 555181, 604938, 241133, 218489, 251741,
8
- 883058, 51614, 531737, 956092, 106424, 727107, 477277, 217325, 127477, 248561,
9
- 565938, 59349,
10
- ];
@@ -1,8 +0,0 @@
1
- import { TxSender } from './types';
2
- import { ConfirmOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
3
- import { AnchorProvider } from '@project-serum/anchor';
4
- export declare class DefaultTxSender implements TxSender {
5
- provider: AnchorProvider;
6
- constructor(provider: AnchorProvider);
7
- send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TransactionSignature>;
8
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultTxSender = void 0;
4
- class DefaultTxSender {
5
- constructor(provider) {
6
- this.provider = provider;
7
- }
8
- send(tx, additionalSigners, opts) {
9
- return this.provider.sendAndConfirm(tx, additionalSigners, opts);
10
- }
11
- }
12
- exports.DefaultTxSender = DefaultTxSender;
package/src/addresses.ts DELETED
@@ -1,82 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
- import * as anchor from '@project-serum/anchor';
3
-
4
- export async function getClearingHouseStateAccountPublicKeyAndNonce(
5
- programId: PublicKey
6
- ): Promise<[PublicKey, number]> {
7
- return anchor.web3.PublicKey.findProgramAddress(
8
- [Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))],
9
- programId
10
- );
11
- }
12
-
13
- export async function getOrderStateAccountPublicKey(
14
- programId: PublicKey
15
- ): Promise<PublicKey> {
16
- return (await getOrderStateAccountPublicKeyAndNonce(programId))[0];
17
- }
18
-
19
- export async function getOrderStateAccountPublicKeyAndNonce(
20
- programId: PublicKey
21
- ): Promise<[PublicKey, number]> {
22
- return anchor.web3.PublicKey.findProgramAddress(
23
- [Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))],
24
- programId
25
- );
26
- }
27
-
28
- export async function getClearingHouseStateAccountPublicKey(
29
- programId: PublicKey
30
- ): Promise<PublicKey> {
31
- return (await getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
32
- }
33
-
34
- export async function getUserAccountPublicKeyAndNonce(
35
- programId: PublicKey,
36
- authority: PublicKey
37
- ): Promise<[PublicKey, number]> {
38
- return anchor.web3.PublicKey.findProgramAddress(
39
- [Buffer.from(anchor.utils.bytes.utf8.encode('user')), authority.toBuffer()],
40
- programId
41
- );
42
- }
43
-
44
- export async function getUserAccountPublicKey(
45
- programId: PublicKey,
46
- authority: PublicKey
47
- ): Promise<PublicKey> {
48
- return (await getUserAccountPublicKeyAndNonce(programId, authority))[0];
49
- }
50
-
51
- export async function getUserOrdersAccountPublicKeyAndNonce(
52
- programId: PublicKey,
53
- userAccount: PublicKey
54
- ): Promise<[PublicKey, number]> {
55
- return anchor.web3.PublicKey.findProgramAddress(
56
- [
57
- Buffer.from(anchor.utils.bytes.utf8.encode('user_orders')),
58
- userAccount.toBuffer(),
59
- ],
60
- programId
61
- );
62
- }
63
-
64
- export async function getUserOrdersAccountPublicKey(
65
- programId: PublicKey,
66
- userAccount: PublicKey
67
- ): Promise<PublicKey> {
68
- return (
69
- await getUserOrdersAccountPublicKeyAndNonce(programId, userAccount)
70
- )[0];
71
- }
72
-
73
- export async function getSettlementStatePublicKey(
74
- programId: PublicKey
75
- ): Promise<PublicKey> {
76
- return (
77
- await anchor.web3.PublicKey.findProgramAddress(
78
- [Buffer.from(anchor.utils.bytes.utf8.encode('settlement_state'))],
79
- programId
80
- )
81
- )[0];
82
- }
@@ -1,26 +0,0 @@
1
- import { PublicKey } from '@solana/web3.js';
2
-
3
- export const CLEARING_HOUSE_STATE_ACCOUNTS = {
4
- dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
5
- state: new PublicKey('FExhvPycCCwYnZGeDsVtLhpEQ3yEkVY2k1HuPyfLj91L'),
6
- markets: new PublicKey('773hq3SbGPKVj93TXi5qV5CREuhxobywfALjS3XVHhLH'),
7
- orderState: new PublicKey('4cC34bWwTPGncBaX2S6v5mH3Lj4Nb3byPMrxQSDcY985'),
8
- tradeHistory: new PublicKey('FCuCXEoQppoaCYdttA7rK3HNQfYkTNEGpwuBESzYcENp'),
9
- depositHistory: new PublicKey(
10
- 'C7rF2Qy2rnDGQLRijBRRArJyaeuQcFi81BXDrUCQ45ya'
11
- ),
12
- fundingPaymentHistory: new PublicKey(
13
- '895iPhzwT2tBufLnRpYtBG3gif1HDDUfpH2AqbS5joo4'
14
- ),
15
- fundingRateHistory: new PublicKey(
16
- 'BWiJLMbmrwfqHVpcPJa8715XamNyNYamDDKQVQMnduEC'
17
- ),
18
- extendedCurveHistory: new PublicKey(
19
- '7vBbqvMdtZLQdTVdzt5y63pZdAFE5W42kP3avngSJKCk'
20
- ),
21
- liquidationHistory: new PublicKey(
22
- 'CSFaaf8yVoTx6NcXUKtNPYAewv76CH2jATqSVRBvUWKM'
23
- ),
24
- orderHistory: new PublicKey('DZ7XfUqyHoRKnJLRApxmJ943xHJ7NDBUTqpbooviEtbU'),
25
- },
26
- };