@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.
- package/README.md +27 -27
- package/lib/accounts/bulkAccountLoader.d.ts +2 -0
- package/lib/accounts/bulkAccountLoader.js +36 -29
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +20 -25
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +45 -49
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
- package/lib/accounts/types.d.ts +26 -15
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +49 -0
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +47 -45
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +15 -9
- package/lib/addresses/pda.js +73 -35
- package/lib/adminClient.d.ts +65 -0
- package/lib/adminClient.js +637 -0
- package/lib/config.d.ts +9 -9
- package/lib/config.js +25 -21
- package/lib/constants/numericConstants.d.ts +30 -12
- package/lib/constants/numericConstants.js +41 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +7 -7
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +53 -0
- package/lib/dlob/DLOB.d.ts +82 -0
- package/lib/dlob/DLOB.js +696 -0
- package/lib/dlob/DLOBNode.d.ts +54 -0
- package/lib/dlob/DLOBNode.js +77 -0
- package/lib/dlob/NodeList.d.ts +27 -0
- package/lib/dlob/NodeList.js +144 -0
- package/lib/driftClient.d.ts +233 -0
- package/lib/driftClient.js +2096 -0
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +9 -9
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/events/eventList.js +3 -0
- package/lib/events/eventSubscriber.d.ts +5 -2
- package/lib/events/eventSubscriber.js +25 -11
- package/lib/events/fetchLogs.d.ts +13 -2
- package/lib/events/fetchLogs.js +40 -12
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +7 -3
- package/lib/events/sort.js +8 -11
- package/lib/events/types.d.ts +9 -3
- package/lib/events/types.js +6 -0
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/examples/makeTradeExample.js +30 -18
- package/lib/factory/bigNum.d.ts +8 -4
- package/lib/factory/bigNum.js +109 -19
- package/lib/idl/drift.json +8250 -0
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +30 -13
- package/lib/index.js +30 -13
- package/lib/math/amm.d.ts +9 -6
- package/lib/math/amm.js +91 -38
- package/lib/math/conversion.js +1 -1
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +23 -21
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +82 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +70 -10
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +14 -6
- package/lib/math/orders.js +90 -17
- package/lib/math/position.d.ts +27 -13
- package/lib/math/position.js +92 -36
- package/lib/math/repeg.js +17 -8
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +192 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/trade.d.ts +10 -10
- package/lib/math/trade.js +27 -31
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +27 -0
- package/lib/serum/serumSubscriber.js +56 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/{clearingHouseUserConfig.js → serum/types.js} +0 -0
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +589 -196
- package/lib/types.js +108 -17
- package/lib/user.d.ts +226 -0
- package/lib/user.js +949 -0
- package/lib/userConfig.d.ts +14 -0
- package/lib/userConfig.js +2 -0
- package/lib/userMap/userMap.d.ts +41 -0
- package/lib/userMap/userMap.js +85 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/lib/userStats.d.ts +18 -0
- package/lib/userStats.js +49 -0
- package/lib/userStatsConfig.d.ts +14 -0
- package/lib/userStatsConfig.js +2 -0
- package/lib/util/computeUnits.js +1 -1
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +10 -3
- package/src/accounts/bulkAccountLoader.ts +44 -34
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +2 -3
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +65 -75
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
- package/src/accounts/types.ts +35 -15
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +78 -73
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +3 -4
- package/src/addresses/pda.ts +105 -33
- package/src/adminClient.ts +1207 -0
- package/src/config.ts +37 -31
- package/src/constants/numericConstants.ts +58 -24
- package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
- package/src/constants/spotMarkets.ts +73 -0
- package/src/dlob/DLOB.ts +1123 -0
- package/src/dlob/DLOBNode.ts +155 -0
- package/src/dlob/NodeList.ts +195 -0
- package/src/driftClient.ts +3564 -0
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.ts +36 -14
- package/src/events/fetchLogs.ts +55 -13
- package/src/events/pollingLogProvider.ts +11 -3
- package/src/events/sort.ts +11 -15
- package/src/events/types.ts +21 -2
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.ts +44 -28
- package/src/factory/bigNum.ts +150 -22
- package/src/idl/drift.json +8250 -0
- package/src/idl/pyth.json +98 -2
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.ts +30 -13
- package/src/math/amm.ts +161 -48
- package/src/math/conversion.ts +2 -2
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +41 -31
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +133 -0
- package/src/math/market.ts +143 -14
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +163 -26
- package/src/math/position.ts +136 -58
- package/src/math/repeg.ts +19 -9
- package/src/math/spotBalance.ts +319 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +33 -37
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +16 -8
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +99 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +572 -178
- package/src/user.ts +1582 -0
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +124 -0
- package/src/userMap/userStatsMap.ts +108 -0
- package/src/userName.ts +2 -1
- package/src/userStats.ts +75 -0
- package/src/userStatsConfig.ts +18 -0
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.ts +18 -0
- package/tests/bn/test.ts +46 -11
- package/tests/dlob/helpers.ts +611 -0
- package/tests/dlob/test.ts +4588 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +0 -49
- package/lib/admin.d.ts +0 -44
- package/lib/admin.js +0 -433
- package/lib/clearingHouse.d.ts +0 -133
- package/lib/clearingHouse.js +0 -931
- package/lib/clearingHouseUser.d.ts +0 -187
- package/lib/clearingHouseUser.js +0 -643
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -34
- package/lib/constants/markets.d.ts +0 -19
- package/lib/idl/clearing_house.json +0 -3998
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/admin.ts +0 -722
- package/src/clearingHouse.ts +0 -1451
- package/src/clearingHouseUser.ts +0 -989
- package/src/constants/banks.ts +0 -43
- package/src/idl/clearing_house.json +0 -3998
- package/src/math/bankBalance.ts +0 -112
- package/src/math/state.ts +0 -14
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/orders.ts +0 -244
- package/src/util/computeUnits.js +0 -17
- package/src/util/computeUnits.js.map +0 -1
package/README.md
CHANGED
|
@@ -54,13 +54,13 @@ a BigNum: 10,500,000, with precision 10^6, is equal to 10.5 because 10,500,000 /
|
|
|
54
54
|
|
|
55
55
|
The Drift SDK uses some common precisions, which are available as constants to import from the SDK.
|
|
56
56
|
|
|
57
|
-
| Precision Name
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
57
|
+
| Precision Name | Value |
|
|
58
|
+
| --------------------- | ----- |
|
|
59
|
+
| FUNDING_RATE_BUFFER | 10^3 |
|
|
60
|
+
| QUOTE_PRECISION | 10^6 |
|
|
61
|
+
| PEG_PRECISION | 10^6 |
|
|
62
|
+
| PRICE_PRECISION | 10^6 |
|
|
63
|
+
| AMM_RESERVE_PRECISION | 10^9 |
|
|
64
64
|
|
|
65
65
|
**Important Note for BigNum division**
|
|
66
66
|
|
|
@@ -88,17 +88,17 @@ import { BN, Provider } from '@project-serum/anchor';
|
|
|
88
88
|
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
89
89
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
90
90
|
import {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
calculateReservePrice,
|
|
92
|
+
DriftClient,
|
|
93
|
+
User,
|
|
94
94
|
initialize,
|
|
95
95
|
Markets,
|
|
96
96
|
PositionDirection,
|
|
97
97
|
convertToNumber,
|
|
98
98
|
calculateTradeSlippage,
|
|
99
|
-
|
|
99
|
+
PRICE_PRECISION,
|
|
100
100
|
QUOTE_PRECISION,
|
|
101
|
-
Wallet
|
|
101
|
+
Wallet,
|
|
102
102
|
} from '@drift-labs/sdk';
|
|
103
103
|
|
|
104
104
|
export const getTokenAddress = (
|
|
@@ -141,19 +141,19 @@ const main = async () => {
|
|
|
141
141
|
wallet.publicKey.toString()
|
|
142
142
|
);
|
|
143
143
|
|
|
144
|
-
// Set up the Drift
|
|
145
|
-
const
|
|
144
|
+
// Set up the Drift Client
|
|
145
|
+
const driftClientPublicKey = new PublicKey(
|
|
146
146
|
sdkConfig.CLEARING_HOUSE_PROGRAM_ID
|
|
147
147
|
);
|
|
148
|
-
const
|
|
148
|
+
const driftClient = DriftClient.from(
|
|
149
149
|
connection,
|
|
150
150
|
provider.wallet,
|
|
151
|
-
|
|
151
|
+
driftClientPublicKey
|
|
152
152
|
);
|
|
153
|
-
await
|
|
153
|
+
await driftClient.subscribe();
|
|
154
154
|
|
|
155
155
|
// Set up Clearing House user client
|
|
156
|
-
const user =
|
|
156
|
+
const user = User.from(driftClient, wallet.publicKey);
|
|
157
157
|
|
|
158
158
|
//// Check if clearing house account exists for the current wallet
|
|
159
159
|
const userAccountExists = await user.exists();
|
|
@@ -161,7 +161,7 @@ const main = async () => {
|
|
|
161
161
|
if (!userAccountExists) {
|
|
162
162
|
//// Create a Clearing House account by Depositing some USDC ($10,000 in this case)
|
|
163
163
|
const depositAmount = new BN(10000).mul(QUOTE_PRECISION);
|
|
164
|
-
await
|
|
164
|
+
await driftClient.initializeUserAccountAndDepositCollateral(
|
|
165
165
|
depositAmount,
|
|
166
166
|
await getTokenAddress(
|
|
167
167
|
usdcTokenAddress.toString(),
|
|
@@ -177,16 +177,16 @@ const main = async () => {
|
|
|
177
177
|
(market) => market.baseAssetSymbol === 'SOL'
|
|
178
178
|
);
|
|
179
179
|
|
|
180
|
-
const currentMarketPrice =
|
|
181
|
-
|
|
180
|
+
const currentMarketPrice = calculateReservePrice(
|
|
181
|
+
driftClient.getMarket(solMarketInfo.marketIndex)
|
|
182
182
|
);
|
|
183
183
|
|
|
184
|
-
const formattedPrice = convertToNumber(currentMarketPrice,
|
|
184
|
+
const formattedPrice = convertToNumber(currentMarketPrice, PRICE_PRECISION);
|
|
185
185
|
|
|
186
186
|
console.log(`Current Market Price is $${formattedPrice}`);
|
|
187
187
|
|
|
188
188
|
// Estimate the slippage for a $5000 LONG trade
|
|
189
|
-
const solMarketAccount =
|
|
189
|
+
const solMarketAccount = driftClient.getMarket(solMarketInfo.marketIndex);
|
|
190
190
|
|
|
191
191
|
const slippage = convertToNumber(
|
|
192
192
|
calculateTradeSlippage(
|
|
@@ -194,7 +194,7 @@ const main = async () => {
|
|
|
194
194
|
new BN(5000).mul(QUOTE_PRECISION),
|
|
195
195
|
solMarketAccount
|
|
196
196
|
)[0],
|
|
197
|
-
|
|
197
|
+
PRICE_PRECISION
|
|
198
198
|
);
|
|
199
199
|
|
|
200
200
|
console.log(
|
|
@@ -202,7 +202,7 @@ const main = async () => {
|
|
|
202
202
|
);
|
|
203
203
|
|
|
204
204
|
// Make a $5000 LONG trade
|
|
205
|
-
await
|
|
205
|
+
await driftClient.openPosition(
|
|
206
206
|
PositionDirection.LONG,
|
|
207
207
|
new BN(5000).mul(QUOTE_PRECISION),
|
|
208
208
|
solMarketInfo.marketIndex
|
|
@@ -210,14 +210,14 @@ const main = async () => {
|
|
|
210
210
|
console.log(`LONGED $5000 worth of SOL`);
|
|
211
211
|
|
|
212
212
|
// Reduce the position by $2000
|
|
213
|
-
await
|
|
213
|
+
await driftClient.openPosition(
|
|
214
214
|
PositionDirection.SHORT,
|
|
215
215
|
new BN(2000).mul(QUOTE_PRECISION),
|
|
216
216
|
solMarketInfo.marketIndex
|
|
217
217
|
);
|
|
218
218
|
|
|
219
219
|
// Close the rest of the position
|
|
220
|
-
await
|
|
220
|
+
await driftClient.closePosition(solMarketInfo.marketIndex);
|
|
221
221
|
};
|
|
222
222
|
|
|
223
223
|
main();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BufferAndSlot } from './types';
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
4
5
|
declare type AccountToLoad = {
|
|
5
6
|
publicKey: PublicKey;
|
|
6
7
|
callbacks: Map<string, (buffer: Buffer, slot: number) => void>;
|
|
@@ -14,6 +15,7 @@ export declare class BulkAccountLoader {
|
|
|
14
15
|
errorCallbacks: Map<string, (e: any) => void>;
|
|
15
16
|
intervalId?: NodeJS.Timer;
|
|
16
17
|
loadPromise?: Promise<void>;
|
|
18
|
+
loadPromiseLock: Mutex;
|
|
17
19
|
loadPromiseResolver: () => void;
|
|
18
20
|
lastTimeLoadingPromiseCleared: number;
|
|
19
21
|
mostRecentSlot: number;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BulkAccountLoader = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const promiseTimeout_1 = require("../util/promiseTimeout");
|
|
6
|
+
const async_mutex_1 = require("async-mutex");
|
|
6
7
|
const GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE = 99;
|
|
7
8
|
const oneMinute = 60 * 1000;
|
|
8
9
|
class BulkAccountLoader {
|
|
@@ -10,6 +11,7 @@ class BulkAccountLoader {
|
|
|
10
11
|
this.accountsToLoad = new Map();
|
|
11
12
|
this.bufferAndSlotMap = new Map();
|
|
12
13
|
this.errorCallbacks = new Map();
|
|
14
|
+
this.loadPromiseLock = new async_mutex_1.Mutex();
|
|
13
15
|
this.lastTimeLoadingPromiseCleared = Date.now();
|
|
14
16
|
this.mostRecentSlot = 0;
|
|
15
17
|
this.connection = connection;
|
|
@@ -36,7 +38,9 @@ class BulkAccountLoader {
|
|
|
36
38
|
this.startPolling();
|
|
37
39
|
}
|
|
38
40
|
// if a new account needs to be polled, remove the cached loadPromise in case client calls load immediately after
|
|
39
|
-
this.
|
|
41
|
+
this.loadPromiseLock.runExclusive(() => {
|
|
42
|
+
this.loadPromise = undefined;
|
|
43
|
+
});
|
|
40
44
|
return callbackId;
|
|
41
45
|
}
|
|
42
46
|
removeAccount(publicKey, callbackId) {
|
|
@@ -66,36 +70,38 @@ class BulkAccountLoader {
|
|
|
66
70
|
.map((begin) => array.slice(begin, begin + size));
|
|
67
71
|
}
|
|
68
72
|
async load() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
+
await this.loadPromiseLock.runExclusive(async () => {
|
|
74
|
+
if (this.loadPromise) {
|
|
75
|
+
const now = Date.now();
|
|
76
|
+
if (now - this.lastTimeLoadingPromiseCleared > oneMinute) {
|
|
77
|
+
this.loadPromise = undefined;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return this.loadPromise;
|
|
81
|
+
}
|
|
73
82
|
}
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
this.loadPromise = new Promise((resolver) => {
|
|
84
|
+
this.loadPromiseResolver = resolver;
|
|
85
|
+
});
|
|
86
|
+
this.lastTimeLoadingPromiseCleared = Date.now();
|
|
87
|
+
try {
|
|
88
|
+
const chunks = this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE);
|
|
89
|
+
await Promise.all(chunks.map((chunk) => {
|
|
90
|
+
return this.loadChunk(chunk);
|
|
91
|
+
}));
|
|
76
92
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const chunks = this.chunks(Array.from(this.accountsToLoad.values()), GET_MULTIPLE_ACCOUNTS_CHUNK_SIZE);
|
|
84
|
-
await Promise.all(chunks.map((chunk) => {
|
|
85
|
-
return this.loadChunk(chunk);
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
catch (e) {
|
|
89
|
-
console.error(`Error in bulkAccountLoader.load()`);
|
|
90
|
-
console.error(e);
|
|
91
|
-
for (const [_, callback] of this.errorCallbacks) {
|
|
92
|
-
callback(e);
|
|
93
|
+
catch (e) {
|
|
94
|
+
console.error(`Error in bulkAccountLoader.load()`);
|
|
95
|
+
console.error(e);
|
|
96
|
+
for (const [_, callback] of this.errorCallbacks) {
|
|
97
|
+
callback(e);
|
|
98
|
+
}
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
100
|
+
finally {
|
|
101
|
+
this.loadPromiseResolver();
|
|
102
|
+
this.loadPromise = undefined;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
99
105
|
}
|
|
100
106
|
async loadChunk(accountsToLoad) {
|
|
101
107
|
if (accountsToLoad.length === 0) {
|
|
@@ -162,7 +168,8 @@ class BulkAccountLoader {
|
|
|
162
168
|
if (this.intervalId) {
|
|
163
169
|
return;
|
|
164
170
|
}
|
|
165
|
-
|
|
171
|
+
if (this.pollingFrequency !== 0)
|
|
172
|
+
this.intervalId = setInterval(this.load.bind(this), this.pollingFrequency);
|
|
166
173
|
}
|
|
167
174
|
stopPolling() {
|
|
168
175
|
if (this.intervalId) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { UserStats } from '../userStats';
|
|
2
|
+
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
|
+
/**
|
|
4
|
+
* @param userStats
|
|
5
|
+
* @param accountLoader
|
|
6
|
+
*/
|
|
7
|
+
export declare function bulkPollingUserStatsSubscribe(userStats: UserStats[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bulkPollingUserStatsSubscribe = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param userStats
|
|
6
|
+
* @param accountLoader
|
|
7
|
+
*/
|
|
8
|
+
async function bulkPollingUserStatsSubscribe(userStats, accountLoader) {
|
|
9
|
+
if (userStats.length === 0) {
|
|
10
|
+
await accountLoader.load();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
await Promise.all(userStats.map((userStat) => {
|
|
14
|
+
return userStat.accountSubscriber.addToAccountLoader();
|
|
15
|
+
}));
|
|
16
|
+
await accountLoader.load();
|
|
17
|
+
await Promise.all(userStats.map(async (userStat) => {
|
|
18
|
+
return userStat.subscribe();
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
exports.bulkPollingUserStatsSubscribe = bulkPollingUserStatsSubscribe;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { User } from '../user';
|
|
2
2
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
3
|
/**
|
|
4
4
|
* @param users
|
|
5
5
|
* @param accountLoader
|
|
6
6
|
*/
|
|
7
|
-
export declare function bulkPollingUserSubscribe(users:
|
|
7
|
+
export declare function bulkPollingUserSubscribe(users: User[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -11,7 +11,6 @@ async function bulkPollingUserSubscribe(users, accountLoader) {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
await Promise.all(users.map((user) => {
|
|
14
|
-
// Pull the keys from the authority map so we can skip fetching them in addToAccountLoader
|
|
15
14
|
return user.accountSubscriber.addToAccountLoader();
|
|
16
15
|
}));
|
|
17
16
|
await accountLoader.load();
|
package/lib/accounts/fetch.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { UserAccount } from '../types';
|
|
2
|
+
import { UserAccount, UserStatsAccount } from '../types';
|
|
3
3
|
import { Program } from '@project-serum/anchor';
|
|
4
4
|
export declare function fetchUserAccounts(connection: Connection, program: Program, authority: PublicKey, limit?: number): Promise<(UserAccount | undefined)[]>;
|
|
5
|
+
export declare function fetchUserStatsAccount(connection: Connection, program: Program, authority: PublicKey): Promise<UserStatsAccount | undefined>;
|
package/lib/accounts/fetch.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchUserAccounts = void 0;
|
|
3
|
+
exports.fetchUserStatsAccount = exports.fetchUserAccounts = void 0;
|
|
4
4
|
const pda_1 = require("../addresses/pda");
|
|
5
5
|
async function fetchUserAccounts(connection, program, authority, limit = 8) {
|
|
6
6
|
const userAccountPublicKeys = new Array();
|
|
@@ -16,3 +16,11 @@ async function fetchUserAccounts(connection, program, authority, limit = 8) {
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
exports.fetchUserAccounts = fetchUserAccounts;
|
|
19
|
+
async function fetchUserStatsAccount(connection, program, authority) {
|
|
20
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(program.programId, authority);
|
|
21
|
+
const accountInfo = await connection.getAccountInfo(userStatsPublicKey, 'confirmed');
|
|
22
|
+
return accountInfo
|
|
23
|
+
? program.account.user.coder.accounts.decode('UserStats', accountInfo.data)
|
|
24
|
+
: undefined;
|
|
25
|
+
}
|
|
26
|
+
exports.fetchUserStatsAccount = fetchUserStatsAccount;
|
|
@@ -1,61 +1,56 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
/// <reference types="node" />
|
|
3
|
-
import { DataAndSlot, AccountToPoll,
|
|
4
|
-
import {
|
|
2
|
+
import { DataAndSlot, AccountToPoll, DriftClientAccountEvents, DriftClientAccountSubscriber, OraclesToPoll } from './types';
|
|
3
|
+
import { Program } from '@project-serum/anchor';
|
|
5
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
5
|
import { EventEmitter } from 'events';
|
|
7
|
-
import {
|
|
6
|
+
import { SpotMarketAccount, PerpMarketAccount, StateAccount, UserAccount } from '../types';
|
|
8
7
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
9
8
|
import { PublicKey } from '@solana/web3.js';
|
|
10
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
11
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
12
|
-
export declare class
|
|
11
|
+
export declare class PollingDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
13
12
|
isSubscribed: boolean;
|
|
14
13
|
program: Program;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
perpMarketIndexes: number[];
|
|
15
|
+
spotMarketIndexes: number[];
|
|
17
16
|
oracleInfos: OracleInfo[];
|
|
18
17
|
oracleClientCache: OracleClientCache;
|
|
19
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
20
19
|
accountLoader: BulkAccountLoader;
|
|
21
20
|
accountsToPoll: Map<string, AccountToPoll>;
|
|
22
21
|
oraclesToPoll: Map<string, OraclesToPoll>;
|
|
23
22
|
errorCallbackId?: string;
|
|
24
23
|
state?: DataAndSlot<StateAccount>;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
perpMarket: Map<number, DataAndSlot<PerpMarketAccount>>;
|
|
25
|
+
spotMarket: Map<number, DataAndSlot<SpotMarketAccount>>;
|
|
27
26
|
oracles: Map<string, DataAndSlot<OraclePriceData>>;
|
|
28
27
|
user?: DataAndSlot<UserAccount>;
|
|
29
28
|
private isSubscribing;
|
|
30
29
|
private subscriptionPromise;
|
|
31
30
|
private subscriptionPromiseResolver;
|
|
32
|
-
constructor(program: Program, accountLoader: BulkAccountLoader,
|
|
31
|
+
constructor(program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[]);
|
|
33
32
|
subscribe(): Promise<boolean>;
|
|
34
33
|
updateAccountsToPoll(): Promise<void>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
updatePerpMarketAccountsToPoll(): Promise<boolean>;
|
|
35
|
+
addPerpMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
36
|
+
updateSpotMarketAccountsToPoll(): Promise<boolean>;
|
|
37
|
+
addSpotMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
39
38
|
updateOraclesToPoll(): boolean;
|
|
40
39
|
addOracleToPoll(oracleInfo: OracleInfo): boolean;
|
|
41
|
-
getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
|
|
42
40
|
addToAccountLoader(): Promise<void>;
|
|
43
41
|
addAccountToAccountLoader(accountToPoll: AccountToPoll): void;
|
|
44
42
|
addOracleToAccountLoader(oracleToPoll: OraclesToPoll): void;
|
|
45
43
|
fetch(): Promise<void>;
|
|
46
44
|
didSubscriptionSucceed(): boolean;
|
|
47
45
|
unsubscribe(): Promise<void>;
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
addSpotMarket(marketIndex: number): Promise<boolean>;
|
|
47
|
+
addPerpMarket(marketIndex: number): Promise<boolean>;
|
|
50
48
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
51
49
|
assertIsSubscribed(): void;
|
|
52
50
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
53
|
-
getMarketAccountAndSlot(marketIndex:
|
|
54
|
-
getMarketAccountsAndSlots(): DataAndSlot<
|
|
55
|
-
|
|
51
|
+
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
52
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
53
|
+
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
54
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
56
55
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
57
56
|
}
|
|
58
|
-
declare type ClearingHouseAccounts = {
|
|
59
|
-
state: PublicKey;
|
|
60
|
-
};
|
|
61
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PollingDriftClientAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
@@ -8,21 +8,21 @@ const utils_1 = require("./utils");
|
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
|
-
class
|
|
12
|
-
constructor(program, accountLoader,
|
|
11
|
+
class PollingDriftClientAccountSubscriber {
|
|
12
|
+
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.accountsToPoll = new Map();
|
|
15
15
|
this.oraclesToPoll = new Map();
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
16
|
+
this.perpMarket = new Map();
|
|
17
|
+
this.spotMarket = new Map();
|
|
18
18
|
this.oracles = new Map();
|
|
19
19
|
this.isSubscribing = false;
|
|
20
20
|
this.isSubscribed = false;
|
|
21
21
|
this.program = program;
|
|
22
22
|
this.eventEmitter = new events_1.EventEmitter();
|
|
23
23
|
this.accountLoader = accountLoader;
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
24
|
+
this.perpMarketIndexes = perpMarketIndexes;
|
|
25
|
+
this.spotMarketIndexes = spotMarketIndexes;
|
|
26
26
|
this.oracleInfos = oracleInfos;
|
|
27
27
|
}
|
|
28
28
|
async subscribe() {
|
|
@@ -58,44 +58,44 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
58
58
|
if (this.accountsToPoll.size > 0) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
this.accountsToPoll.set(
|
|
61
|
+
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
62
|
+
this.accountsToPoll.set(statePublicKey.toString(), {
|
|
63
63
|
key: 'state',
|
|
64
|
-
publicKey:
|
|
64
|
+
publicKey: statePublicKey,
|
|
65
65
|
eventType: 'stateAccountUpdate',
|
|
66
66
|
});
|
|
67
|
-
await this.
|
|
68
|
-
await this.
|
|
67
|
+
await this.updatePerpMarketAccountsToPoll();
|
|
68
|
+
await this.updateSpotMarketAccountsToPoll();
|
|
69
69
|
}
|
|
70
|
-
async
|
|
71
|
-
for (const marketIndex of this.
|
|
72
|
-
await this.
|
|
70
|
+
async updatePerpMarketAccountsToPoll() {
|
|
71
|
+
for (const marketIndex of this.perpMarketIndexes) {
|
|
72
|
+
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
73
73
|
}
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
|
-
async
|
|
77
|
-
const
|
|
78
|
-
this.accountsToPoll.set(
|
|
79
|
-
key: '
|
|
80
|
-
publicKey:
|
|
81
|
-
eventType: '
|
|
82
|
-
mapKey: marketIndex
|
|
76
|
+
async addPerpMarketAccountToPoll(marketIndex) {
|
|
77
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
78
|
+
this.accountsToPoll.set(perpMarketPublicKey.toString(), {
|
|
79
|
+
key: 'perpMarket',
|
|
80
|
+
publicKey: perpMarketPublicKey,
|
|
81
|
+
eventType: 'perpMarketAccountUpdate',
|
|
82
|
+
mapKey: marketIndex,
|
|
83
83
|
});
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
86
|
-
async
|
|
87
|
-
for (const
|
|
88
|
-
await this.
|
|
86
|
+
async updateSpotMarketAccountsToPoll() {
|
|
87
|
+
for (const marketIndex of this.spotMarketIndexes) {
|
|
88
|
+
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
89
89
|
}
|
|
90
90
|
return true;
|
|
91
91
|
}
|
|
92
|
-
async
|
|
93
|
-
const
|
|
94
|
-
this.accountsToPoll.set(
|
|
95
|
-
key: '
|
|
96
|
-
publicKey:
|
|
97
|
-
eventType: '
|
|
98
|
-
mapKey:
|
|
92
|
+
async addSpotMarketAccountToPoll(marketIndex) {
|
|
93
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
94
|
+
this.accountsToPoll.set(marketPublicKey.toString(), {
|
|
95
|
+
key: 'spotMarket',
|
|
96
|
+
publicKey: marketPublicKey,
|
|
97
|
+
eventType: 'spotMarketAccountUpdate',
|
|
98
|
+
mapKey: marketIndex,
|
|
99
99
|
});
|
|
100
100
|
return true;
|
|
101
101
|
}
|
|
@@ -114,13 +114,6 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
114
114
|
});
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
|
-
async getClearingHouseAccounts() {
|
|
118
|
-
const statePublicKey = await (0, pda_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
|
|
119
|
-
const accounts = {
|
|
120
|
-
state: statePublicKey,
|
|
121
|
-
};
|
|
122
|
-
return accounts;
|
|
123
|
-
}
|
|
124
117
|
async addToAccountLoader() {
|
|
125
118
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
126
119
|
this.addAccountToAccountLoader(accountToPoll);
|
|
@@ -223,14 +216,14 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
223
216
|
this.oraclesToPoll.clear();
|
|
224
217
|
this.isSubscribed = false;
|
|
225
218
|
}
|
|
226
|
-
async
|
|
227
|
-
await this.
|
|
228
|
-
const accountToPoll = this.accountsToPoll.get(
|
|
219
|
+
async addSpotMarket(marketIndex) {
|
|
220
|
+
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
221
|
+
const accountToPoll = this.accountsToPoll.get(marketIndex.toString());
|
|
229
222
|
this.addAccountToAccountLoader(accountToPoll);
|
|
230
223
|
return true;
|
|
231
224
|
}
|
|
232
|
-
async
|
|
233
|
-
await this.
|
|
225
|
+
async addPerpMarket(marketIndex) {
|
|
226
|
+
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
234
227
|
const accountToPoll = this.accountsToPoll.get(marketIndex.toString());
|
|
235
228
|
this.addAccountToAccountLoader(accountToPoll);
|
|
236
229
|
return true;
|
|
@@ -254,13 +247,16 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
254
247
|
return this.state;
|
|
255
248
|
}
|
|
256
249
|
getMarketAccountAndSlot(marketIndex) {
|
|
257
|
-
return this.
|
|
250
|
+
return this.perpMarket.get(marketIndex);
|
|
258
251
|
}
|
|
259
252
|
getMarketAccountsAndSlots() {
|
|
260
|
-
return Array.from(this.
|
|
253
|
+
return Array.from(this.perpMarket.values());
|
|
254
|
+
}
|
|
255
|
+
getSpotMarketAccountAndSlot(marketIndex) {
|
|
256
|
+
return this.spotMarket.get(marketIndex);
|
|
261
257
|
}
|
|
262
|
-
|
|
263
|
-
return this.
|
|
258
|
+
getSpotMarketAccountsAndSlots() {
|
|
259
|
+
return Array.from(this.spotMarket.values());
|
|
264
260
|
}
|
|
265
261
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
266
262
|
this.assertIsSubscribed();
|
|
@@ -273,4 +269,4 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
273
269
|
return this.oracles.get(oraclePublicKey.toString());
|
|
274
270
|
}
|
|
275
271
|
}
|
|
276
|
-
exports.
|
|
272
|
+
exports.PollingDriftClientAccountSubscriber = PollingDriftClientAccountSubscriber;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataAndSlot, OracleEvents,
|
|
2
|
+
import { DataAndSlot, OracleEvents, OracleAccountSubscriber } from './types';
|
|
3
3
|
import { Program } from '@project-serum/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
7
7
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
8
8
|
import { OracleClient, OraclePriceData } from '../oracles/types';
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class PollingOracleAccountSubscriber implements OracleAccountSubscriber {
|
|
10
10
|
isSubscribed: boolean;
|
|
11
11
|
program: Program;
|
|
12
12
|
eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PollingOracleAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
|
-
class
|
|
6
|
+
class PollingOracleAccountSubscriber {
|
|
7
7
|
constructor(publicKey, oracleClient, accountLoader) {
|
|
8
8
|
this.isSubscribed = false;
|
|
9
9
|
this.publicKey = publicKey;
|
|
@@ -75,4 +75,4 @@ class PollingOracleSubscriber {
|
|
|
75
75
|
return !!this.oraclePriceData;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
exports.
|
|
78
|
+
exports.PollingOracleAccountSubscriber = PollingOracleAccountSubscriber;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataAndSlot, AccountToPoll, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
|
|
3
|
+
import { Program } from '@project-serum/anchor';
|
|
4
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { PublicKey } from '@solana/web3.js';
|
|
7
|
+
import { UserStatsAccount } from '../types';
|
|
8
|
+
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
9
|
+
export declare class PollingUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
|
|
10
|
+
isSubscribed: boolean;
|
|
11
|
+
program: Program;
|
|
12
|
+
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
13
|
+
userStatsAccountPublicKey: PublicKey;
|
|
14
|
+
accountLoader: BulkAccountLoader;
|
|
15
|
+
accountsToPoll: Map<string, AccountToPoll>;
|
|
16
|
+
errorCallbackId?: string;
|
|
17
|
+
userStats?: DataAndSlot<UserStatsAccount>;
|
|
18
|
+
constructor(program: Program, userStatsAccountPublicKey: PublicKey, accountLoader: BulkAccountLoader);
|
|
19
|
+
subscribe(): Promise<boolean>;
|
|
20
|
+
addToAccountLoader(): Promise<void>;
|
|
21
|
+
fetchIfUnloaded(): Promise<void>;
|
|
22
|
+
fetch(): Promise<void>;
|
|
23
|
+
didSubscriptionSucceed(): boolean;
|
|
24
|
+
unsubscribe(): Promise<void>;
|
|
25
|
+
assertIsSubscribed(): void;
|
|
26
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
27
|
+
}
|