@drift-labs/sdk 0.2.0-master.4 → 0.2.0-master.41
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/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.js +5 -11
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +107 -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 +694 -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 +234 -0
- package/lib/driftClient.js +2108 -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 +11 -3
- package/lib/events/types.js +8 -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 +8386 -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 +16 -6
- package/lib/math/orders.js +97 -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 +688 -216
- package/lib/types.js +153 -24
- package/lib/user.d.ts +228 -0
- package/lib/user.js +959 -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 +11 -4
- 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/pollingUserAccountSubscriber.ts +5 -12
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +166 -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/assert/assert.js +9 -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 +1120 -0
- package/src/dlob/DLOBNode.ts +155 -0
- package/src/dlob/NodeList.ts +195 -0
- package/src/driftClient.ts +3594 -0
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +9 -8
- package/src/events/eventList.js +77 -0
- 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 +27 -2
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.js +157 -0
- package/src/examples/makeTradeExample.ts +44 -28
- package/src/factory/bigNum.ts +150 -22
- package/src/idl/drift.json +8386 -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 +168 -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/token/index.js +38 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +650 -189
- package/src/user.ts +1599 -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.js +21 -11
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/getTokenAddress.ts +18 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/bn/test.ts +46 -11
- package/tests/dlob/helpers.ts +620 -0
- package/tests/dlob/test.ts +4586 -0
- package/yarn-error.log +3160 -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.map +0 -1
|
@@ -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
|
+
doAccountsExist(): boolean;
|
|
24
|
+
unsubscribe(): Promise<void>;
|
|
25
|
+
assertIsSubscribed(): void;
|
|
26
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PollingUserStatsAccountSubscriber = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
class PollingUserStatsAccountSubscriber {
|
|
8
|
+
constructor(program, userStatsAccountPublicKey, accountLoader) {
|
|
9
|
+
this.accountsToPoll = new Map();
|
|
10
|
+
this.isSubscribed = false;
|
|
11
|
+
this.program = program;
|
|
12
|
+
this.accountLoader = accountLoader;
|
|
13
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
14
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
15
|
+
}
|
|
16
|
+
async subscribe() {
|
|
17
|
+
if (this.isSubscribed) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
await this.addToAccountLoader();
|
|
21
|
+
await this.fetchIfUnloaded();
|
|
22
|
+
if (this.doAccountsExist()) {
|
|
23
|
+
this.eventEmitter.emit('update');
|
|
24
|
+
}
|
|
25
|
+
this.isSubscribed = true;
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
async addToAccountLoader() {
|
|
29
|
+
if (this.accountsToPoll.size > 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.accountsToPoll.set(this.userStatsAccountPublicKey.toString(), {
|
|
33
|
+
key: 'userStats',
|
|
34
|
+
publicKey: this.userStatsAccountPublicKey,
|
|
35
|
+
eventType: 'userStatsAccountUpdate',
|
|
36
|
+
});
|
|
37
|
+
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
38
|
+
accountToPoll.callbackId = this.accountLoader.addAccount(accountToPoll.publicKey, (buffer, slot) => {
|
|
39
|
+
if (!buffer) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
43
|
+
this[accountToPoll.key] = { data: account, slot };
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
this.eventEmitter.emit(accountToPoll.eventType, account);
|
|
46
|
+
this.eventEmitter.emit('update');
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
this.errorCallbackId = this.accountLoader.addErrorCallbacks((error) => {
|
|
50
|
+
this.eventEmitter.emit('error', error);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async fetchIfUnloaded() {
|
|
54
|
+
let shouldFetch = false;
|
|
55
|
+
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
56
|
+
if (this[accountToPoll.key] === undefined) {
|
|
57
|
+
shouldFetch = true;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (shouldFetch) {
|
|
62
|
+
await this.fetch();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async fetch() {
|
|
66
|
+
await this.accountLoader.load();
|
|
67
|
+
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
68
|
+
const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
|
|
69
|
+
if (buffer) {
|
|
70
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
71
|
+
this[accountToPoll.key] = { data: account, slot };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
doAccountsExist() {
|
|
76
|
+
let success = true;
|
|
77
|
+
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
78
|
+
if (!this[accountToPoll.key]) {
|
|
79
|
+
success = false;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return success;
|
|
84
|
+
}
|
|
85
|
+
async unsubscribe() {
|
|
86
|
+
if (!this.isSubscribed) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
90
|
+
this.accountLoader.removeAccount(accountToPoll.publicKey, accountToPoll.callbackId);
|
|
91
|
+
}
|
|
92
|
+
this.accountLoader.removeErrorCallbacks(this.errorCallbackId);
|
|
93
|
+
this.errorCallbackId = undefined;
|
|
94
|
+
this.accountsToPoll.clear();
|
|
95
|
+
this.isSubscribed = false;
|
|
96
|
+
}
|
|
97
|
+
assertIsSubscribed() {
|
|
98
|
+
if (!this.isSubscribed) {
|
|
99
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
getUserStatsAccountAndSlot() {
|
|
103
|
+
this.assertIsSubscribed();
|
|
104
|
+
return this.userStats;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.PollingUserStatsAccountSubscriber = PollingUserStatsAccountSubscriber;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
/// <reference types="node" />
|
|
4
|
-
import { BankAccount, MarketAccount, OracleSource, StateAccount, UserAccount } from '../types';
|
|
2
|
+
import { SpotMarketAccount, PerpMarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
5
3
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
4
|
import { EventEmitter } from 'events';
|
|
7
5
|
import { PublicKey } from '@solana/web3.js';
|
|
8
6
|
import { AccountInfo } from '@solana/spl-token';
|
|
9
7
|
import { OracleInfo, OraclePriceData } from '..';
|
|
10
|
-
import { BN } from '@project-serum/anchor';
|
|
11
8
|
export interface AccountSubscriber<T> {
|
|
12
9
|
dataAndSlot?: DataAndSlot<T>;
|
|
13
10
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
@@ -17,28 +14,29 @@ export interface AccountSubscriber<T> {
|
|
|
17
14
|
export declare class NotSubscribedError extends Error {
|
|
18
15
|
name: string;
|
|
19
16
|
}
|
|
20
|
-
export interface
|
|
17
|
+
export interface DriftClientAccountEvents {
|
|
21
18
|
stateAccountUpdate: (payload: StateAccount) => void;
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
|
|
20
|
+
spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
|
|
24
21
|
oraclePriceUpdate: (publicKey: PublicKey, data: OraclePriceData) => void;
|
|
25
22
|
userAccountUpdate: (payload: UserAccount) => void;
|
|
26
23
|
update: void;
|
|
27
24
|
error: (e: Error) => void;
|
|
28
25
|
}
|
|
29
|
-
export interface
|
|
30
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
26
|
+
export interface DriftClientAccountSubscriber {
|
|
27
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
31
28
|
isSubscribed: boolean;
|
|
32
29
|
subscribe(): Promise<boolean>;
|
|
33
30
|
fetch(): Promise<void>;
|
|
34
31
|
unsubscribe(): Promise<void>;
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
addPerpMarket(marketIndex: number): Promise<boolean>;
|
|
33
|
+
addSpotMarket(marketIndex: number): Promise<boolean>;
|
|
37
34
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
38
35
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
39
|
-
getMarketAccountAndSlot(marketIndex:
|
|
40
|
-
getMarketAccountsAndSlots(): DataAndSlot<
|
|
41
|
-
|
|
36
|
+
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
37
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
38
|
+
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
39
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
42
40
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
43
41
|
}
|
|
44
42
|
export interface UserAccountEvents {
|
|
@@ -72,7 +70,7 @@ export interface OracleEvents {
|
|
|
72
70
|
update: void;
|
|
73
71
|
error: (e: Error) => void;
|
|
74
72
|
}
|
|
75
|
-
export interface
|
|
73
|
+
export interface OracleAccountSubscriber {
|
|
76
74
|
eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
|
|
77
75
|
isSubscribed: boolean;
|
|
78
76
|
subscribe(): Promise<boolean>;
|
|
@@ -100,3 +98,16 @@ export declare type DataAndSlot<T> = {
|
|
|
100
98
|
data: T;
|
|
101
99
|
slot: number;
|
|
102
100
|
};
|
|
101
|
+
export interface UserStatsAccountEvents {
|
|
102
|
+
userStatsAccountUpdate: (payload: UserStatsAccount) => void;
|
|
103
|
+
update: void;
|
|
104
|
+
error: (e: Error) => void;
|
|
105
|
+
}
|
|
106
|
+
export interface UserStatsAccountSubscriber {
|
|
107
|
+
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
108
|
+
isSubscribed: boolean;
|
|
109
|
+
subscribe(): Promise<boolean>;
|
|
110
|
+
fetch(): Promise<void>;
|
|
111
|
+
unsubscribe(): Promise<void>;
|
|
112
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
113
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './types';
|
|
3
|
+
import { AccountSubscriber } from './types';
|
|
4
|
+
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
5
|
+
import { Program } from '@project-serum/anchor';
|
|
6
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import { PublicKey } from '@solana/web3.js';
|
|
9
|
+
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
|
+
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
|
+
export declare class WebSocketDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
|
+
isSubscribed: boolean;
|
|
13
|
+
program: Program;
|
|
14
|
+
perpMarketIndexes: number[];
|
|
15
|
+
spotMarketIndexes: number[];
|
|
16
|
+
oracleInfos: OracleInfo[];
|
|
17
|
+
oracleClientCache: OracleClientCache;
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
19
|
+
stateAccountSubscriber?: AccountSubscriber<StateAccount>;
|
|
20
|
+
perpMarketAccountSubscribers: Map<number, AccountSubscriber<PerpMarketAccount>>;
|
|
21
|
+
spotMarketAccountSubscribers: Map<number, AccountSubscriber<SpotMarketAccount>>;
|
|
22
|
+
oracleSubscribers: Map<string, AccountSubscriber<OraclePriceData>>;
|
|
23
|
+
private isSubscribing;
|
|
24
|
+
private subscriptionPromise;
|
|
25
|
+
private subscriptionPromiseResolver;
|
|
26
|
+
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[]);
|
|
27
|
+
subscribe(): Promise<boolean>;
|
|
28
|
+
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
29
|
+
subscribeToPerpMarketAccount(marketIndex: number): Promise<boolean>;
|
|
30
|
+
subscribeToSpotMarketAccounts(): Promise<boolean>;
|
|
31
|
+
subscribeToSpotMarketAccount(marketIndex: number): Promise<boolean>;
|
|
32
|
+
subscribeToOracles(): Promise<boolean>;
|
|
33
|
+
subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
34
|
+
unsubscribeFromMarketAccounts(): Promise<void>;
|
|
35
|
+
unsubscribeFromSpotMarketAccounts(): Promise<void>;
|
|
36
|
+
unsubscribeFromOracles(): Promise<void>;
|
|
37
|
+
fetch(): Promise<void>;
|
|
38
|
+
unsubscribe(): Promise<void>;
|
|
39
|
+
addSpotMarket(marketIndex: number): Promise<boolean>;
|
|
40
|
+
addPerpMarket(marketIndex: number): Promise<boolean>;
|
|
41
|
+
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
42
|
+
assertIsSubscribed(): void;
|
|
43
|
+
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
44
|
+
getMarketAccountAndSlot(marketIndex: number): DataAndSlot<PerpMarketAccount> | undefined;
|
|
45
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
46
|
+
getSpotMarketAccountAndSlot(marketIndex: number): DataAndSlot<SpotMarketAccount> | undefined;
|
|
47
|
+
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
48
|
+
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
49
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WebSocketDriftClientAccountSubscriber = 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,18 +8,18 @@ const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
|
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,
|
|
11
|
+
class WebSocketDriftClientAccountSubscriber {
|
|
12
|
+
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.perpMarketAccountSubscribers = new Map();
|
|
15
|
+
this.spotMarketAccountSubscribers = new Map();
|
|
16
16
|
this.oracleSubscribers = new Map();
|
|
17
17
|
this.isSubscribing = false;
|
|
18
18
|
this.isSubscribed = false;
|
|
19
19
|
this.program = program;
|
|
20
20
|
this.eventEmitter = new events_1.EventEmitter();
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
21
|
+
this.perpMarketIndexes = perpMarketIndexes;
|
|
22
|
+
this.spotMarketIndexes = spotMarketIndexes;
|
|
23
23
|
this.oracleInfos = oracleInfos;
|
|
24
24
|
}
|
|
25
25
|
async subscribe() {
|
|
@@ -33,7 +33,7 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
33
33
|
this.subscriptionPromise = new Promise((res) => {
|
|
34
34
|
this.subscriptionPromiseResolver = res;
|
|
35
35
|
});
|
|
36
|
-
const statePublicKey = await (0, pda_1.
|
|
36
|
+
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
37
37
|
// create and activate main state account subscription
|
|
38
38
|
this.stateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('state', this.program, statePublicKey);
|
|
39
39
|
await this.stateAccountSubscriber.subscribe((data) => {
|
|
@@ -41,9 +41,9 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
41
41
|
this.eventEmitter.emit('update');
|
|
42
42
|
});
|
|
43
43
|
// subscribe to market accounts
|
|
44
|
-
await this.
|
|
45
|
-
// subscribe to
|
|
46
|
-
await this.
|
|
44
|
+
await this.subscribeToPerpMarketAccounts();
|
|
45
|
+
// subscribe to spot market accounts
|
|
46
|
+
await this.subscribeToSpotMarketAccounts();
|
|
47
47
|
// subscribe to oracles
|
|
48
48
|
await this.subscribeToOracles();
|
|
49
49
|
this.eventEmitter.emit('update');
|
|
@@ -52,36 +52,36 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
52
52
|
this.subscriptionPromiseResolver(true);
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
|
-
async
|
|
56
|
-
for (const marketIndex of this.
|
|
57
|
-
await this.
|
|
55
|
+
async subscribeToPerpMarketAccounts() {
|
|
56
|
+
for (const marketIndex of this.perpMarketIndexes) {
|
|
57
|
+
await this.subscribeToPerpMarketAccount(marketIndex);
|
|
58
58
|
}
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
|
-
async
|
|
62
|
-
const
|
|
63
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('
|
|
61
|
+
async subscribeToPerpMarketAccount(marketIndex) {
|
|
62
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
63
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey);
|
|
64
64
|
await accountSubscriber.subscribe((data) => {
|
|
65
|
-
this.eventEmitter.emit('
|
|
65
|
+
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
66
66
|
this.eventEmitter.emit('update');
|
|
67
67
|
});
|
|
68
|
-
this.
|
|
68
|
+
this.perpMarketAccountSubscribers.set(marketIndex, accountSubscriber);
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
|
-
async
|
|
72
|
-
for (const
|
|
73
|
-
await this.
|
|
71
|
+
async subscribeToSpotMarketAccounts() {
|
|
72
|
+
for (const marketIndex of this.spotMarketIndexes) {
|
|
73
|
+
await this.subscribeToSpotMarketAccount(marketIndex);
|
|
74
74
|
}
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
|
-
async
|
|
78
|
-
const
|
|
79
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('
|
|
77
|
+
async subscribeToSpotMarketAccount(marketIndex) {
|
|
78
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
79
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey);
|
|
80
80
|
await accountSubscriber.subscribe((data) => {
|
|
81
|
-
this.eventEmitter.emit('
|
|
81
|
+
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
82
82
|
this.eventEmitter.emit('update');
|
|
83
83
|
});
|
|
84
|
-
this.
|
|
84
|
+
this.spotMarketAccountSubscribers.set(marketIndex, accountSubscriber);
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
87
|
async subscribeToOracles() {
|
|
@@ -105,12 +105,12 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
105
105
|
return true;
|
|
106
106
|
}
|
|
107
107
|
async unsubscribeFromMarketAccounts() {
|
|
108
|
-
for (const accountSubscriber of this.
|
|
108
|
+
for (const accountSubscriber of this.perpMarketAccountSubscribers.values()) {
|
|
109
109
|
await accountSubscriber.unsubscribe();
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
async
|
|
113
|
-
for (const accountSubscriber of this.
|
|
112
|
+
async unsubscribeFromSpotMarketAccounts() {
|
|
113
|
+
for (const accountSubscriber of this.spotMarketAccountSubscribers.values()) {
|
|
114
114
|
await accountSubscriber.unsubscribe();
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -124,8 +124,8 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
const promises = [this.stateAccountSubscriber.fetch()]
|
|
127
|
-
.concat(Array.from(this.
|
|
128
|
-
.concat(Array.from(this.
|
|
127
|
+
.concat(Array.from(this.perpMarketAccountSubscribers.values()).map((subscriber) => subscriber.fetch()))
|
|
128
|
+
.concat(Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.fetch()));
|
|
129
129
|
await Promise.all(promises);
|
|
130
130
|
}
|
|
131
131
|
async unsubscribe() {
|
|
@@ -134,21 +134,21 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
134
134
|
}
|
|
135
135
|
await this.stateAccountSubscriber.unsubscribe();
|
|
136
136
|
await this.unsubscribeFromMarketAccounts();
|
|
137
|
-
await this.
|
|
137
|
+
await this.unsubscribeFromSpotMarketAccounts();
|
|
138
138
|
await this.unsubscribeFromOracles();
|
|
139
139
|
this.isSubscribed = false;
|
|
140
140
|
}
|
|
141
|
-
async
|
|
142
|
-
if (this.
|
|
141
|
+
async addSpotMarket(marketIndex) {
|
|
142
|
+
if (this.spotMarketAccountSubscribers.has(marketIndex)) {
|
|
143
143
|
return true;
|
|
144
144
|
}
|
|
145
|
-
return this.
|
|
145
|
+
return this.subscribeToSpotMarketAccount(marketIndex);
|
|
146
146
|
}
|
|
147
|
-
async
|
|
148
|
-
if (this.
|
|
147
|
+
async addPerpMarket(marketIndex) {
|
|
148
|
+
if (this.perpMarketAccountSubscribers.has(marketIndex)) {
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
|
-
return this.
|
|
151
|
+
return this.subscribeToPerpMarketAccount(marketIndex);
|
|
152
152
|
}
|
|
153
153
|
async addOracle(oracleInfo) {
|
|
154
154
|
if (this.oracleSubscribers.has(oracleInfo.publicKey.toString())) {
|
|
@@ -170,15 +170,17 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
170
170
|
}
|
|
171
171
|
getMarketAccountAndSlot(marketIndex) {
|
|
172
172
|
this.assertIsSubscribed();
|
|
173
|
-
return this.
|
|
174
|
-
.dataAndSlot;
|
|
173
|
+
return this.perpMarketAccountSubscribers.get(marketIndex).dataAndSlot;
|
|
175
174
|
}
|
|
176
175
|
getMarketAccountsAndSlots() {
|
|
177
|
-
return Array.from(this.
|
|
176
|
+
return Array.from(this.perpMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
178
177
|
}
|
|
179
|
-
|
|
178
|
+
getSpotMarketAccountAndSlot(marketIndex) {
|
|
180
179
|
this.assertIsSubscribed();
|
|
181
|
-
return this.
|
|
180
|
+
return this.spotMarketAccountSubscribers.get(marketIndex).dataAndSlot;
|
|
181
|
+
}
|
|
182
|
+
getSpotMarketAccountsAndSlots() {
|
|
183
|
+
return Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
182
184
|
}
|
|
183
185
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
184
186
|
this.assertIsSubscribed();
|
|
@@ -191,4 +193,4 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
191
193
|
return this.oracleSubscribers.get(oraclePublicKey.toString()).dataAndSlot;
|
|
192
194
|
}
|
|
193
195
|
}
|
|
194
|
-
exports.
|
|
196
|
+
exports.WebSocketDriftClientAccountSubscriber = WebSocketDriftClientAccountSubscriber;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataAndSlot, AccountSubscriber, 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
|
+
export declare class WebSocketUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
|
|
9
|
+
isSubscribed: boolean;
|
|
10
|
+
program: Program;
|
|
11
|
+
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
12
|
+
userStatsAccountPublicKey: PublicKey;
|
|
13
|
+
userStatsAccountSubscriber: AccountSubscriber<UserStatsAccount>;
|
|
14
|
+
constructor(program: Program, userStatsAccountPublicKey: PublicKey);
|
|
15
|
+
subscribe(): Promise<boolean>;
|
|
16
|
+
fetch(): Promise<void>;
|
|
17
|
+
unsubscribe(): Promise<void>;
|
|
18
|
+
assertIsSubscribed(): void;
|
|
19
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketUserStatsAccountSubscriber = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
7
|
+
class WebSocketUserStatsAccountSubscriber {
|
|
8
|
+
constructor(program, userStatsAccountPublicKey) {
|
|
9
|
+
this.isSubscribed = false;
|
|
10
|
+
this.program = program;
|
|
11
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
12
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
13
|
+
}
|
|
14
|
+
async subscribe() {
|
|
15
|
+
if (this.isSubscribed) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey);
|
|
19
|
+
await this.userStatsAccountSubscriber.subscribe((data) => {
|
|
20
|
+
this.eventEmitter.emit('userStatsAccountUpdate', data);
|
|
21
|
+
this.eventEmitter.emit('update');
|
|
22
|
+
});
|
|
23
|
+
this.eventEmitter.emit('update');
|
|
24
|
+
this.isSubscribed = true;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
async fetch() {
|
|
28
|
+
await Promise.all([this.userStatsAccountSubscriber.fetch()]);
|
|
29
|
+
}
|
|
30
|
+
async unsubscribe() {
|
|
31
|
+
if (!this.isSubscribed) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await Promise.all([this.userStatsAccountSubscriber.unsubscribe()]);
|
|
35
|
+
this.isSubscribed = false;
|
|
36
|
+
}
|
|
37
|
+
assertIsSubscribed() {
|
|
38
|
+
if (!this.isSubscribed) {
|
|
39
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getUserStatsAccountAndSlot() {
|
|
43
|
+
this.assertIsSubscribed();
|
|
44
|
+
return this.userStatsAccountSubscriber.dataAndSlot;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.WebSocketUserStatsAccountSubscriber = WebSocketUserStatsAccountSubscriber;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
export declare function getMarketAddress(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
2
|
+
export declare function getMarketAddress(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
@@ -8,7 +8,7 @@ async function getMarketAddress(programId, marketIndex) {
|
|
|
8
8
|
if (CACHE.has(cacheKey)) {
|
|
9
9
|
return CACHE.get(cacheKey);
|
|
10
10
|
}
|
|
11
|
-
const publicKey = await (0, pda_1.
|
|
11
|
+
const publicKey = await (0, pda_1.getPerpMarketPublicKey)(programId, marketIndex);
|
|
12
12
|
CACHE.set(cacheKey, publicKey);
|
|
13
13
|
return publicKey;
|
|
14
14
|
}
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey,
|
|
7
|
-
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey,
|
|
8
|
-
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey,
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
4
|
+
export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
|
+
export declare function getDriftStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
|
+
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
|
7
|
+
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<PublicKey>;
|
|
8
|
+
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
|
|
9
|
+
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
10
|
+
export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
11
|
+
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
12
|
+
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
13
|
+
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
|
+
export declare function getInsuranceFundStakeAccountPublicKey(programId: PublicKey, authority: PublicKey, marketIndex: number): PublicKey;
|
|
15
|
+
export declare function getDriftSignerPublicKey(programId: PublicKey): PublicKey;
|
|
16
|
+
export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
|
17
|
+
export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
|
|
18
|
+
export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|