@drift-labs/sdk 0.1.36-master.5 → 0.2.0-master.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +7 -6
  2. package/lib/accounts/bulkAccountLoader.js +83 -93
  3. package/lib/accounts/bulkUserSubscription.js +13 -57
  4. package/lib/accounts/fetch.d.ts +4 -0
  5. package/lib/accounts/fetch.js +18 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
  8. package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
  9. package/lib/accounts/pollingOracleSubscriber.js +37 -49
  10. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
  11. package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
  12. package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
  13. package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
  14. package/lib/accounts/types.d.ts +34 -41
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
  16. package/lib/accounts/webSocketAccountSubscriber.js +39 -35
  17. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
  18. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
  19. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
  20. package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
  21. package/lib/addresses/marketAddresses.d.ts +4 -0
  22. package/lib/addresses/marketAddresses.js +15 -0
  23. package/lib/addresses/pda.d.ts +12 -0
  24. package/lib/addresses/pda.js +83 -0
  25. package/lib/admin.d.ts +8 -12
  26. package/lib/admin.js +366 -490
  27. package/lib/clearingHouse.d.ts +84 -103
  28. package/lib/clearingHouse.js +779 -810
  29. package/lib/clearingHouseConfig.d.ts +34 -0
  30. package/lib/clearingHouseConfig.js +2 -0
  31. package/lib/clearingHouseUser.d.ts +19 -18
  32. package/lib/clearingHouseUser.js +157 -115
  33. package/lib/clearingHouseUserConfig.d.ts +14 -0
  34. package/lib/clearingHouseUserConfig.js +2 -0
  35. package/lib/config.d.ts +12 -0
  36. package/lib/config.js +35 -4
  37. package/lib/constants/banks.d.ts +16 -0
  38. package/lib/constants/banks.js +34 -0
  39. package/lib/constants/markets.d.ts +8 -3
  40. package/lib/constants/markets.js +13 -206
  41. package/lib/constants/numericConstants.d.ts +16 -0
  42. package/lib/constants/numericConstants.js +22 -6
  43. package/lib/events/eventList.d.ts +22 -0
  44. package/lib/events/eventList.js +77 -0
  45. package/lib/events/eventSubscriber.d.ts +34 -0
  46. package/lib/events/eventSubscriber.js +126 -0
  47. package/lib/events/fetchLogs.d.ts +13 -0
  48. package/lib/events/fetchLogs.js +39 -0
  49. package/lib/events/pollingLogProvider.d.ts +15 -0
  50. package/lib/events/pollingLogProvider.js +53 -0
  51. package/lib/events/sort.d.ts +2 -0
  52. package/lib/events/sort.js +44 -0
  53. package/lib/events/txEventCache.d.ts +24 -0
  54. package/lib/events/txEventCache.js +71 -0
  55. package/lib/events/types.d.ts +49 -0
  56. package/lib/events/types.js +20 -0
  57. package/lib/events/webSocketLogProvider.d.ts +12 -0
  58. package/lib/events/webSocketLogProvider.js +30 -0
  59. package/lib/examples/makeTradeExample.js +26 -27
  60. package/lib/factory/bigNum.d.ts +112 -0
  61. package/lib/factory/bigNum.js +356 -0
  62. package/lib/factory/oracleClient.d.ts +1 -2
  63. package/lib/factory/oracleClient.js +6 -2
  64. package/lib/idl/clearing_house.json +1739 -2287
  65. package/lib/index.d.ts +13 -4
  66. package/lib/index.js +13 -4
  67. package/lib/math/amm.d.ts +19 -29
  68. package/lib/math/amm.js +129 -179
  69. package/lib/math/auction.d.ts +5 -0
  70. package/lib/math/auction.js +39 -0
  71. package/lib/math/bankBalance.d.ts +9 -0
  72. package/lib/math/bankBalance.js +75 -0
  73. package/lib/math/conversion.d.ts +0 -1
  74. package/lib/math/conversion.js +1 -5
  75. package/lib/math/funding.d.ts +6 -6
  76. package/lib/math/funding.js +158 -175
  77. package/lib/math/market.d.ts +6 -6
  78. package/lib/math/market.js +10 -9
  79. package/lib/math/oracles.d.ts +3 -0
  80. package/lib/math/oracles.js +26 -0
  81. package/lib/math/orders.d.ts +5 -0
  82. package/lib/math/orders.js +31 -1
  83. package/lib/math/position.d.ts +7 -4
  84. package/lib/math/position.js +27 -9
  85. package/lib/math/repeg.d.ts +22 -0
  86. package/lib/math/repeg.js +128 -0
  87. package/lib/math/trade.d.ts +13 -8
  88. package/lib/math/trade.js +85 -22
  89. package/lib/mockUSDCFaucet.js +87 -116
  90. package/lib/oracles/oracleClientCache.d.ts +8 -0
  91. package/lib/oracles/oracleClientCache.js +19 -0
  92. package/lib/oracles/pythClient.d.ts +3 -5
  93. package/lib/oracles/pythClient.js +12 -30
  94. package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
  95. package/lib/oracles/quoteAssetOracleClient.js +21 -0
  96. package/lib/oracles/switchboardClient.d.ts +3 -5
  97. package/lib/oracles/switchboardClient.js +29 -47
  98. package/lib/oracles/types.d.ts +7 -1
  99. package/lib/orders.d.ts +6 -6
  100. package/lib/orders.js +10 -9
  101. package/lib/slot/SlotSubscriber.d.ts +12 -0
  102. package/lib/slot/SlotSubscriber.js +23 -0
  103. package/lib/tx/retryTxSender.d.ts +2 -2
  104. package/lib/tx/retryTxSender.js +108 -123
  105. package/lib/tx/types.d.ts +5 -1
  106. package/lib/tx/utils.d.ts +1 -1
  107. package/lib/tx/utils.js +11 -2
  108. package/lib/types.d.ts +105 -98
  109. package/lib/types.js +13 -1
  110. package/lib/userName.d.ts +4 -0
  111. package/lib/userName.js +20 -0
  112. package/lib/util/computeUnits.js +10 -21
  113. package/lib/util/tps.js +11 -22
  114. package/lib/wallet.js +7 -20
  115. package/package.json +10 -3
  116. package/src/accounts/bulkAccountLoader.ts +26 -15
  117. package/src/accounts/bulkUserSubscription.ts +1 -45
  118. package/src/accounts/fetch.ts +33 -0
  119. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
  120. package/src/accounts/pollingOracleSubscriber.ts +16 -8
  121. package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
  122. package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
  123. package/src/accounts/types.ts +41 -70
  124. package/src/accounts/webSocketAccountSubscriber.ts +33 -16
  125. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
  126. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
  127. package/src/addresses/marketAddresses.ts +18 -0
  128. package/src/addresses/pda.ts +118 -0
  129. package/src/admin.ts +209 -267
  130. package/src/clearingHouse.ts +921 -829
  131. package/src/clearingHouseConfig.ts +37 -0
  132. package/src/clearingHouseUser.ts +280 -127
  133. package/src/clearingHouseUserConfig.ts +18 -0
  134. package/src/config.ts +54 -1
  135. package/src/constants/banks.ts +43 -0
  136. package/src/constants/markets.ts +16 -207
  137. package/src/constants/numericConstants.ts +33 -5
  138. package/src/events/eventList.ts +94 -0
  139. package/src/events/eventSubscriber.ts +194 -0
  140. package/src/events/fetchLogs.ts +80 -0
  141. package/src/events/pollingLogProvider.ts +79 -0
  142. package/src/events/sort.ts +65 -0
  143. package/src/events/txEventCache.ts +74 -0
  144. package/src/events/types.ts +98 -0
  145. package/src/events/webSocketLogProvider.ts +38 -0
  146. package/src/examples/makeTradeExample.ts +20 -11
  147. package/src/factory/bigNum.ts +507 -0
  148. package/src/factory/oracleClient.ts +7 -4
  149. package/src/idl/clearing_house.json +1739 -2287
  150. package/src/index.ts +13 -4
  151. package/src/math/amm.ts +229 -245
  152. package/src/math/auction.ts +39 -0
  153. package/src/math/bankBalance.ts +112 -0
  154. package/src/math/conversion.ts +1 -11
  155. package/src/math/funding.ts +12 -9
  156. package/src/math/market.ts +37 -30
  157. package/src/math/oracles.ts +36 -0
  158. package/src/math/orders.ts +38 -0
  159. package/src/math/position.ts +48 -13
  160. package/src/math/repeg.ts +175 -0
  161. package/src/math/trade.ts +114 -36
  162. package/src/math/utils.js +27 -0
  163. package/src/math/utils.js.map +1 -0
  164. package/src/oracles/oracleClientCache.ts +20 -0
  165. package/src/oracles/pythClient.ts +5 -11
  166. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  167. package/src/oracles/switchboardClient.ts +16 -24
  168. package/src/oracles/types.ts +8 -1
  169. package/src/orders.ts +35 -20
  170. package/src/slot/SlotSubscriber.ts +32 -0
  171. package/src/tx/retryTxSender.ts +6 -4
  172. package/src/tx/types.ts +6 -1
  173. package/src/tx/utils.ts +22 -3
  174. package/src/types.ts +108 -110
  175. package/src/userName.ts +20 -0
  176. package/src/util/computeUnits.js +17 -0
  177. package/src/util/computeUnits.js.map +1 -0
  178. package/tests/bn/test.ts +255 -0
  179. package/tsconfig.json +12 -12
  180. package/lib/addresses.d.ts +0 -9
  181. package/lib/addresses.js +0 -87
  182. package/lib/constants/accounts.d.ts +0 -15
  183. package/lib/constants/accounts.js +0 -18
  184. package/lib/factory/clearingHouse.d.ts +0 -35
  185. package/lib/factory/clearingHouse.js +0 -81
  186. package/lib/factory/clearingHouseUser.d.ts +0 -19
  187. package/lib/factory/clearingHouseUser.js +0 -34
  188. package/lib/math/insuranceFund.d.ts +0 -15
  189. package/lib/math/insuranceFund.js +0 -33
  190. package/lib/tx/defaultTxSender.d.ts +0 -8
  191. package/lib/tx/defaultTxSender.js +0 -12
  192. package/src/addresses.ts +0 -71
  193. package/src/constants/accounts.ts +0 -26
  194. package/src/factory/clearingHouse.ts +0 -173
  195. package/src/factory/clearingHouseUser.ts +0 -73
  196. package/src/math/insuranceFund.ts +0 -29
  197. package/src/tx/defaultTxSender.ts +0 -24
package/src/addresses.ts DELETED
@@ -1,71 +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
- }
@@ -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
- };
@@ -1,173 +0,0 @@
1
- import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
2
- import { IWallet } from '../types';
3
- import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
4
- import { TxSender } from '../tx/types';
5
- import { AnchorProvider, Idl, Program } from '@project-serum/anchor';
6
- import { ClearingHouse } from '../clearingHouse';
7
- import clearingHouseIDL from '../idl/clearing_house.json';
8
- import { WebSocketClearingHouseAccountSubscriber } from '../accounts/webSocketClearingHouseAccountSubscriber';
9
- import { DefaultTxSender } from '../tx/defaultTxSender';
10
- import { ClearingHouseAccountSubscriber } from '../accounts/types';
11
- import { PollingClearingHouseAccountSubscriber } from '../accounts/pollingClearingHouseAccountSubscriber';
12
- import { Admin } from '../admin';
13
- import { RetryTxSender } from '../tx/retryTxSender';
14
-
15
- export type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
16
-
17
- type BaseClearingHouseConfig = {
18
- type: ClearingHouseConfigType;
19
- connection: Connection;
20
- wallet: IWallet;
21
- programID: PublicKey;
22
- opts?: ConfirmOptions;
23
- txSenderConfig?: TxSenderConfig;
24
- };
25
-
26
- type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
27
-
28
- type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
29
- accountLoader: BulkAccountLoader;
30
- };
31
-
32
- type ClearingHouseConfig =
33
- | PollingClearingHouseConfiguration
34
- | WebSocketClearingHouseConfiguration;
35
-
36
- export type TxSenderType = 'default' | 'retry';
37
-
38
- type BaseTxSenderConfig = {
39
- type: TxSenderType;
40
- };
41
-
42
- type DefaultTxSenderConfig = BaseTxSenderConfig;
43
-
44
- type RetryTxSenderConfig = BaseTxSenderConfig & {
45
- timeout?: number;
46
- retrySleep?: number;
47
- additionalConnections?: Connection[];
48
- };
49
-
50
- type TxSenderConfig = DefaultTxSenderConfig | RetryTxSenderConfig;
51
-
52
- export function getWebSocketClearingHouseConfig(
53
- connection: Connection,
54
- wallet: IWallet,
55
- programID: PublicKey,
56
- opts: ConfirmOptions = AnchorProvider.defaultOptions(),
57
- txSenderConfig?: TxSenderConfig
58
- ): WebSocketClearingHouseConfiguration {
59
- return {
60
- type: 'websocket',
61
- connection,
62
- wallet,
63
- programID,
64
- opts,
65
- txSenderConfig,
66
- };
67
- }
68
-
69
- export function getPollingClearingHouseConfig(
70
- connection: Connection,
71
- wallet: IWallet,
72
- programID: PublicKey,
73
- accountLoader: BulkAccountLoader,
74
- opts: ConfirmOptions = AnchorProvider.defaultOptions(),
75
- txSenderConfig?: TxSenderConfig
76
- ): PollingClearingHouseConfiguration {
77
- return {
78
- type: 'polling',
79
- connection,
80
- wallet,
81
- programID,
82
- accountLoader,
83
- opts,
84
- txSenderConfig,
85
- };
86
- }
87
-
88
- export function getClearingHouse(config: ClearingHouseConfig): ClearingHouse {
89
- const provider = new AnchorProvider(
90
- config.connection,
91
- config.wallet,
92
- config.opts
93
- );
94
- const program = new Program(
95
- clearingHouseIDL as Idl,
96
- config.programID,
97
- provider
98
- );
99
- let accountSubscriber: ClearingHouseAccountSubscriber;
100
- if (config.type === 'websocket') {
101
- accountSubscriber = new WebSocketClearingHouseAccountSubscriber(program);
102
- } else if (config.type === 'polling') {
103
- accountSubscriber = new PollingClearingHouseAccountSubscriber(
104
- program,
105
- (config as PollingClearingHouseConfiguration).accountLoader
106
- );
107
- }
108
-
109
- let txSender: TxSender;
110
- if (config.txSenderConfig?.type === 'retry') {
111
- const txSenderConfig = config.txSenderConfig as RetryTxSenderConfig;
112
- txSender = new RetryTxSender(
113
- provider,
114
- txSenderConfig.timeout,
115
- txSenderConfig.retrySleep,
116
- txSenderConfig.additionalConnections
117
- );
118
- } else {
119
- txSender = new DefaultTxSender(provider);
120
- }
121
-
122
- return new ClearingHouse(
123
- config.connection,
124
- config.wallet,
125
- program,
126
- accountSubscriber,
127
- txSender,
128
- config.opts
129
- );
130
- }
131
-
132
- export function getAdmin(config: ClearingHouseConfig): Admin {
133
- const provider = new AnchorProvider(
134
- config.connection,
135
- config.wallet,
136
- config.opts
137
- );
138
- const program = new Program(
139
- clearingHouseIDL as Idl,
140
- config.programID,
141
- provider
142
- );
143
- let accountSubscriber: ClearingHouseAccountSubscriber;
144
- if (config.type === 'websocket') {
145
- accountSubscriber = new WebSocketClearingHouseAccountSubscriber(program);
146
- } else if (config.type === 'polling') {
147
- accountSubscriber = new PollingClearingHouseAccountSubscriber(
148
- program,
149
- (config as PollingClearingHouseConfiguration).accountLoader
150
- );
151
- }
152
-
153
- let txSender: TxSender;
154
- if (config.txSenderConfig?.type === 'retry') {
155
- const txSenderConfig = config.txSenderConfig as RetryTxSenderConfig;
156
- txSender = new RetryTxSender(
157
- provider,
158
- txSenderConfig.timeout,
159
- txSenderConfig.retrySleep,
160
- txSenderConfig.additionalConnections
161
- );
162
- } else {
163
- txSender = new DefaultTxSender(provider);
164
- }
165
- return new Admin(
166
- config.connection,
167
- config.wallet,
168
- program,
169
- accountSubscriber,
170
- txSender,
171
- config.opts
172
- );
173
- }
@@ -1,73 +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
- import { UserAccountSubscriber } from '../accounts/types';
6
- import { WebSocketUserAccountSubscriber } from '../accounts/webSocketUserAccountSubscriber';
7
- import { PollingUserAccountSubscriber } from '../accounts/pollingUserAccountSubscriber';
8
-
9
- export type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
10
-
11
- type BaseClearingHouseUserConfig = {
12
- type: ClearingHouseUserConfigType;
13
- clearingHouse: ClearingHouse;
14
- authority: PublicKey;
15
- };
16
-
17
- type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
18
-
19
- type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
20
- accountLoader: BulkAccountLoader;
21
- };
22
-
23
- type ClearingHouseUserConfig =
24
- | PollingClearingHouseUserConfig
25
- | WebSocketClearingHouseUserConfig;
26
-
27
- export function getWebSocketClearingHouseUserConfig(
28
- clearingHouse: ClearingHouse,
29
- authority: PublicKey
30
- ): WebSocketClearingHouseUserConfig {
31
- return {
32
- type: 'websocket',
33
- clearingHouse,
34
- authority,
35
- };
36
- }
37
-
38
- export function getPollingClearingHouseUserConfig(
39
- clearingHouse: ClearingHouse,
40
- authority: PublicKey,
41
- accountLoader: BulkAccountLoader
42
- ): PollingClearingHouseUserConfig {
43
- return {
44
- type: 'polling',
45
- clearingHouse,
46
- authority,
47
- accountLoader,
48
- };
49
- }
50
-
51
- export function getClearingHouseUser(
52
- config: ClearingHouseUserConfig
53
- ): ClearingHouseUser {
54
- let accountSubscriber: UserAccountSubscriber;
55
- if (config.type === 'websocket') {
56
- accountSubscriber = new WebSocketUserAccountSubscriber(
57
- config.clearingHouse.program,
58
- config.authority
59
- );
60
- } else if (config.type === 'polling') {
61
- accountSubscriber = new PollingUserAccountSubscriber(
62
- config.clearingHouse.program,
63
- config.authority,
64
- (config as PollingClearingHouseUserConfig).accountLoader
65
- );
66
- }
67
-
68
- return new ClearingHouseUser(
69
- config.clearingHouse,
70
- config.authority,
71
- accountSubscriber
72
- );
73
- }
@@ -1,29 +0,0 @@
1
- import { MarketsAccount, StateAccount } from '../types';
2
- import { BN } from '../';
3
- import { Connection } from '@solana/web3.js';
4
-
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 async function calculateInsuranceFundSize(
16
- connection: Connection,
17
- state: StateAccount,
18
- marketsAccount: MarketsAccount
19
- ): Promise<BN> {
20
- const insuranceVaultPublicKey = state.insuranceVault;
21
- const insuranceVaultAmount = new BN(
22
- (
23
- await connection.getTokenAccountBalance(insuranceVaultPublicKey)
24
- ).value.amount
25
- );
26
- return marketsAccount.markets.reduce((insuranceVaultAmount, market) => {
27
- return insuranceVaultAmount.add(market.amm.totalFee.div(new BN(2)));
28
- }, insuranceVaultAmount);
29
- }
@@ -1,24 +0,0 @@
1
- import { TxSender } from './types';
2
- import {
3
- ConfirmOptions,
4
- Signer,
5
- Transaction,
6
- TransactionSignature,
7
- } from '@solana/web3.js';
8
- import { AnchorProvider } from '@project-serum/anchor';
9
-
10
- export class DefaultTxSender implements TxSender {
11
- provider: AnchorProvider;
12
-
13
- public constructor(provider: AnchorProvider) {
14
- this.provider = provider;
15
- }
16
-
17
- send(
18
- tx: Transaction,
19
- additionalSigners?: Array<Signer>,
20
- opts?: ConfirmOptions
21
- ): Promise<TransactionSignature> {
22
- return this.provider.sendAndConfirm(tx, additionalSigners, opts);
23
- }
24
- }