@drift-labs/sdk 0.2.0-master.13 → 0.2.0-master.14
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/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
- package/lib/accounts/types.d.ts +14 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/admin.d.ts +2 -0
- package/lib/admin.js +18 -0
- package/lib/clearingHouse.d.ts +17 -1
- package/lib/clearingHouse.js +195 -14
- package/lib/clearingHouseConfig.d.ts +1 -0
- package/lib/clearingHouseUser.d.ts +5 -0
- package/lib/clearingHouseUser.js +97 -3
- package/lib/clearingHouseUserStats.d.ts +17 -0
- package/lib/clearingHouseUserStats.js +36 -0
- package/lib/clearingHouseUserStatsConfig.d.ts +14 -0
- package/{src/clearingHouseConfig.js → lib/clearingHouseUserStatsConfig.js} +0 -0
- package/lib/config.js +1 -1
- package/lib/idl/clearing_house.json +614 -64
- package/lib/math/bankBalance.d.ts +4 -0
- package/lib/math/bankBalance.js +23 -1
- package/lib/math/oracles.d.ts +3 -0
- package/lib/math/oracles.js +25 -5
- package/lib/math/position.js +2 -1
- package/lib/math/trade.js +2 -2
- package/lib/types.d.ts +55 -8
- package/lib/types.js +6 -0
- package/package.json +1 -1
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
- package/src/accounts/types.ts +18 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/pda.ts +13 -0
- package/src/admin.ts +29 -1
- package/src/clearingHouse.ts +318 -15
- package/src/clearingHouseConfig.ts +1 -0
- package/src/clearingHouseUser.ts +113 -10
- package/src/clearingHouseUserStats.ts +53 -0
- package/src/clearingHouseUserStatsConfig.ts +18 -0
- package/src/config.ts +1 -1
- package/src/idl/clearing_house.json +614 -64
- package/src/math/bankBalance.ts +49 -0
- package/src/math/oracles.ts +42 -5
- package/src/math/position.ts +2 -1
- package/src/math/trade.ts +2 -2
- package/src/types.ts +59 -8
- package/src/accounts/bulkAccountLoader.js +0 -197
- package/src/accounts/bulkUserSubscription.js +0 -33
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +0 -311
- package/src/accounts/pollingOracleSubscriber.js +0 -93
- package/src/accounts/pollingTokenAccountSubscriber.js +0 -90
- package/src/accounts/pollingUserAccountSubscriber.js +0 -132
- package/src/accounts/types.js +0 -10
- package/src/accounts/utils.js +0 -7
- package/src/accounts/webSocketAccountSubscriber.js +0 -93
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +0 -233
- package/src/accounts/webSocketUserAccountSubscriber.js +0 -62
- package/src/clearingHouseUserConfig.js +0 -2
- package/src/index.js +0 -69
- package/src/mockUSDCFaucet.js +0 -280
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ClearingHouse } from './clearingHouse';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { DataAndSlot, UserStatsAccountSubscriber } from './accounts/types';
|
|
4
|
+
import { ClearingHouseUserStatsConfig } from './clearingHouseUserStatsConfig';
|
|
5
|
+
import { PollingUserStatsAccountSubscriber } from './accounts/pollingUserStatsAccountSubscriber';
|
|
6
|
+
import { WebSocketUserStatsAccountSubscriber } from './accounts/webSocketUserStatsAccountSubsriber';
|
|
7
|
+
import { UserStatsAccount } from './types';
|
|
8
|
+
|
|
9
|
+
export class ClearingHouseUserStats {
|
|
10
|
+
clearingHouse: ClearingHouse;
|
|
11
|
+
userStatsAccountPublicKey: PublicKey;
|
|
12
|
+
accountSubscriber: UserStatsAccountSubscriber;
|
|
13
|
+
isSubscribed: boolean;
|
|
14
|
+
|
|
15
|
+
public constructor(config: ClearingHouseUserStatsConfig) {
|
|
16
|
+
this.clearingHouse = config.clearingHouse;
|
|
17
|
+
this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
|
|
18
|
+
if (config.accountSubscription?.type === 'polling') {
|
|
19
|
+
this.accountSubscriber = new PollingUserStatsAccountSubscriber(
|
|
20
|
+
config.clearingHouse.program,
|
|
21
|
+
config.userStatsAccountPublicKey,
|
|
22
|
+
config.accountSubscription.accountLoader
|
|
23
|
+
);
|
|
24
|
+
} else {
|
|
25
|
+
this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
|
|
26
|
+
config.clearingHouse.program,
|
|
27
|
+
config.userStatsAccountPublicKey
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async subscribe(): Promise<boolean> {
|
|
33
|
+
this.isSubscribed = await this.accountSubscriber.subscribe();
|
|
34
|
+
return this.isSubscribed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async fetchAccounts(): Promise<void> {
|
|
38
|
+
await this.accountSubscriber.fetch();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public async unsubscribe(): Promise<void> {
|
|
42
|
+
await this.accountSubscriber.unsubscribe();
|
|
43
|
+
this.isSubscribed = false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public getAccountAndSlot(): DataAndSlot<UserStatsAccount> {
|
|
47
|
+
return this.accountSubscriber.getUserStatsAccountAndSlot();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getAccount(): UserStatsAccount {
|
|
51
|
+
return this.accountSubscriber.getUserStatsAccountAndSlot().data;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ClearingHouse } from './clearingHouse';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
|
+
|
|
5
|
+
export type ClearingHouseUserStatsConfig = {
|
|
6
|
+
accountSubscription?: ClearingHouseUserStatsAccountSubscriptionConfig;
|
|
7
|
+
clearingHouse: ClearingHouse;
|
|
8
|
+
userStatsAccountPublicKey: PublicKey;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ClearingHouseUserStatsAccountSubscriptionConfig =
|
|
12
|
+
| {
|
|
13
|
+
type: 'websocket';
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
type: 'polling';
|
|
17
|
+
accountLoader: BulkAccountLoader;
|
|
18
|
+
};
|
package/src/config.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const configs: { [key in DriftEnv]: DriftConfig } = {
|
|
|
28
28
|
devnet: {
|
|
29
29
|
ENV: 'devnet',
|
|
30
30
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
31
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
31
|
+
CLEARING_HOUSE_PROGRAM_ID: 'D9bW92Maa1yDigJqvabRgr5S5VybPNDB5xxSpQD6mkkV',
|
|
32
32
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
33
33
|
MARKETS: DevnetMarkets,
|
|
34
34
|
BANKS: DevnetBanks,
|