@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/bulkAccountLoader.d.ts +6 -6
- package/lib/accounts/bulkAccountLoader.js +81 -95
- package/lib/accounts/bulkUserSubscription.js +13 -57
- package/lib/accounts/fetch.d.ts +4 -0
- package/lib/accounts/fetch.js +18 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
- package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
- package/lib/accounts/pollingOracleSubscriber.js +37 -49
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
- package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
- package/lib/accounts/types.d.ts +34 -41
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
- package/lib/accounts/webSocketAccountSubscriber.js +39 -35
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
- package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
- package/lib/addresses/marketAddresses.d.ts +4 -0
- package/lib/addresses/marketAddresses.js +15 -0
- package/lib/addresses/pda.d.ts +12 -0
- package/lib/addresses/pda.js +83 -0
- package/lib/admin.d.ts +9 -17
- package/lib/admin.js +375 -558
- package/lib/clearingHouse.d.ts +86 -109
- package/lib/clearingHouse.js +828 -895
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -22
- package/lib/clearingHouseUser.js +155 -141
- package/lib/clearingHouseUserConfig.d.ts +14 -0
- package/lib/clearingHouseUserConfig.js +2 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +35 -4
- package/lib/constants/banks.d.ts +16 -0
- package/lib/constants/banks.js +34 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +17 -0
- package/lib/constants/numericConstants.js +23 -6
- package/lib/events/eventList.d.ts +22 -0
- package/lib/events/eventList.js +77 -0
- package/lib/events/eventSubscriber.d.ts +34 -0
- package/lib/events/eventSubscriber.js +126 -0
- package/lib/events/fetchLogs.d.ts +13 -0
- package/lib/events/fetchLogs.js +39 -0
- package/lib/events/pollingLogProvider.d.ts +15 -0
- package/lib/events/pollingLogProvider.js +53 -0
- package/lib/events/sort.d.ts +2 -0
- package/lib/events/sort.js +44 -0
- package/lib/events/txEventCache.d.ts +24 -0
- package/lib/events/txEventCache.js +71 -0
- package/lib/events/types.d.ts +49 -0
- package/lib/events/types.js +20 -0
- package/lib/events/webSocketLogProvider.d.ts +12 -0
- package/lib/events/webSocketLogProvider.js +30 -0
- package/lib/examples/makeTradeExample.js +26 -27
- package/lib/factory/bigNum.d.ts +118 -0
- package/lib/factory/bigNum.js +364 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +2287 -2938
- package/lib/index.d.ts +12 -4
- package/lib/index.js +12 -4
- package/lib/math/amm.d.ts +24 -29
- package/lib/math/amm.js +239 -178
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +39 -0
- package/lib/math/bankBalance.d.ts +9 -0
- package/lib/math/bankBalance.js +75 -0
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/conversion.js +1 -5
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +158 -175
- package/lib/math/market.d.ts +6 -6
- package/lib/math/market.js +10 -9
- package/lib/math/orders.d.ts +5 -0
- package/lib/math/orders.js +31 -1
- package/lib/math/position.d.ts +7 -5
- package/lib/math/position.js +27 -27
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +5 -4
- package/lib/math/trade.js +29 -21
- package/lib/mockUSDCFaucet.js +87 -116
- package/lib/oracles/oracleClientCache.d.ts +8 -0
- package/lib/oracles/oracleClientCache.js +19 -0
- package/lib/oracles/pythClient.d.ts +3 -5
- package/lib/oracles/pythClient.js +12 -31
- package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
- package/lib/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/oracles/switchboardClient.d.ts +3 -5
- package/lib/oracles/switchboardClient.js +29 -50
- package/lib/oracles/types.d.ts +6 -1
- package/lib/orders.d.ts +6 -7
- package/lib/orders.js +10 -80
- package/lib/slot/SlotSubscriber.d.ts +12 -0
- package/lib/slot/SlotSubscriber.js +23 -0
- package/lib/tx/retryTxSender.d.ts +2 -2
- package/lib/tx/retryTxSender.js +108 -123
- package/lib/tx/types.d.ts +5 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +11 -2
- package/lib/types.d.ts +110 -109
- package/lib/types.js +14 -1
- package/lib/userName.d.ts +4 -0
- package/lib/userName.js +20 -0
- package/lib/util/computeUnits.js +10 -21
- package/lib/util/tps.js +11 -22
- package/lib/wallet.js +7 -20
- package/package.json +11 -4
- package/src/accounts/bulkAccountLoader.ts +21 -15
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.ts +41 -70
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.ts +18 -0
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +218 -346
- package/src/clearingHouse.ts +983 -952
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +275 -185
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +43 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +34 -5
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.ts +524 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +2287 -2938
- package/src/index.ts +12 -4
- package/src/math/amm.ts +414 -245
- package/src/math/auction.ts +39 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.ts +12 -9
- package/src/math/market.ts +37 -30
- package/src/math/orders.ts +38 -0
- package/src/math/position.ts +48 -35
- package/src/math/repeg.ts +176 -0
- package/src/math/trade.ts +45 -35
- package/src/math/utils.js +27 -0
- package/src/math/utils.js.map +1 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.ts +4 -11
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.ts +11 -24
- package/src/oracles/types.ts +7 -1
- package/src/orders.ts +24 -126
- package/src/slot/SlotSubscriber.ts +32 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.ts +22 -3
- package/src/types.ts +111 -122
- package/src/userName.ts +20 -0
- package/src/util/computeUnits.js +17 -0
- package/src/util/computeUnits.js.map +1 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -10
- package/lib/addresses.js +0 -93
- package/lib/constants/accounts.d.ts +0 -15
- package/lib/constants/accounts.js +0 -18
- package/lib/factory/clearingHouse.d.ts +0 -35
- package/lib/factory/clearingHouse.js +0 -81
- package/lib/factory/clearingHouseUser.d.ts +0 -19
- package/lib/factory/clearingHouseUser.js +0 -34
- package/lib/math/insuranceFund.d.ts +0 -15
- package/lib/math/insuranceFund.js +0 -33
- package/lib/settlement.d.ts +0 -4
- package/lib/settlement.js +0 -10
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -82
- package/src/constants/accounts.ts +0 -26
- package/src/factory/clearingHouse.ts +0 -173
- package/src/factory/clearingHouseUser.ts +0 -73
- package/src/math/insuranceFund.ts +0 -29
- package/src/settlement.ts +0 -9
- package/src/tx/defaultTxSender.ts +0 -24
|
@@ -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
|
-
}
|
package/src/settlement.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BN } from '@project-serum/anchor';
|
|
2
|
-
|
|
3
|
-
export const SETTLEMENT_RATIO_PRECISION = new BN(1000000);
|
|
4
|
-
|
|
5
|
-
export const SETTLEMENT_RATIOS = [
|
|
6
|
-
291786, 243613, 712271, 293771, 555181, 604938, 241133, 218489, 251741,
|
|
7
|
-
883058, 51614, 531737, 956092, 106424, 727107, 477277, 217325, 127477, 248561,
|
|
8
|
-
565938, 59349,
|
|
9
|
-
];
|
|
@@ -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
|
-
}
|