@drift-labs/sdk 0.2.0-master.37 → 0.2.0-master.39
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 +14 -14
- package/lib/accounts/bulkUserStatsSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +3 -8
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +6 -13
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/types.d.ts +4 -4
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.d.ts → webSocketDriftClientAccountSubscriber.d.ts} +3 -3
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +4 -4
- package/lib/addresses/pda.d.ts +3 -3
- package/lib/addresses/pda.js +10 -10
- package/lib/{admin.d.ts → adminClient.d.ts} +12 -4
- package/lib/{admin.js → adminClient.js} +89 -15
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +3 -0
- package/lib/constants/numericConstants.js +5 -2
- package/lib/dlob/DLOB.d.ts +2 -2
- package/lib/dlob/DLOB.js +4 -4
- package/lib/{clearingHouse.d.ts → driftClient.d.ts} +21 -20
- package/lib/{clearingHouse.js → driftClient.js} +48 -37
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +3 -3
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/examples/makeTradeExample.js +13 -13
- package/lib/idl/{clearing_house.json → drift.json} +717 -143
- package/lib/index.d.ts +10 -10
- package/lib/index.js +10 -10
- package/lib/math/orders.d.ts +4 -4
- package/lib/math/orders.js +3 -3
- package/lib/serum/serumFulfillmentConfigMap.d.ts +3 -3
- package/lib/serum/serumFulfillmentConfigMap.js +3 -3
- package/lib/types.d.ts +38 -2
- package/lib/types.js +2 -1
- package/lib/{clearingHouseUser.d.ts → user.d.ts} +16 -10
- package/lib/{clearingHouseUser.js → user.js} +54 -46
- package/lib/userConfig.d.ts +14 -0
- package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
- package/lib/userMap/userMap.d.ts +17 -17
- package/lib/userMap/userMap.js +15 -15
- package/lib/userMap/userStatsMap.d.ts +7 -7
- package/lib/userMap/userStatsMap.js +10 -10
- package/lib/{clearingHouseUserStats.d.ts → userStats.d.ts} +5 -5
- package/lib/{clearingHouseUserStats.js → userStats.js} +8 -8
- package/lib/userStatsConfig.d.ts +14 -0
- package/lib/{clearingHouseUserStatsConfig.js → userStatsConfig.js} +0 -0
- package/package.json +1 -1
- package/src/accounts/bulkUserStatsSubscription.ts +2 -2
- package/src/accounts/bulkUserSubscription.ts +2 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +11 -25
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/types.ts +4 -4
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +7 -7
- package/src/addresses/pda.ts +6 -8
- package/src/{admin.ts → adminClient.ts} +185 -18
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +4 -0
- package/src/dlob/DLOB.ts +5 -5
- package/src/{clearingHouse.ts → driftClient.ts} +85 -68
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +3 -3
- package/src/examples/makeTradeExample.ts +15 -17
- package/src/idl/{clearing_house.json → drift.json} +717 -143
- package/src/index.ts +10 -10
- package/src/math/orders.ts +7 -13
- package/src/serum/serumFulfillmentConfigMap.ts +5 -5
- package/src/types.ts +41 -2
- package/src/{clearingHouseUser.ts → user.ts} +60 -54
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +29 -29
- package/src/userMap/userStatsMap.ts +21 -23
- package/src/{clearingHouseUserStats.ts → userStats.ts} +10 -10
- package/src/userStatsConfig.ts +18 -0
- package/tests/dlob/helpers.ts +55 -13
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/clearingHouseUserStatsConfig.d.ts +0 -14
- package/src/clearingHouseUserStatsConfig.ts +0 -18
package/README.md
CHANGED
|
@@ -89,8 +89,8 @@ import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
|
89
89
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
90
90
|
import {
|
|
91
91
|
calculateReservePrice,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
DriftClient,
|
|
93
|
+
User,
|
|
94
94
|
initialize,
|
|
95
95
|
Markets,
|
|
96
96
|
PositionDirection,
|
|
@@ -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(),
|
|
@@ -178,7 +178,7 @@ const main = async () => {
|
|
|
178
178
|
);
|
|
179
179
|
|
|
180
180
|
const currentMarketPrice = calculateReservePrice(
|
|
181
|
-
|
|
181
|
+
driftClient.getMarket(solMarketInfo.marketIndex)
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
const formattedPrice = convertToNumber(currentMarketPrice, PRICE_PRECISION);
|
|
@@ -186,7 +186,7 @@ const main = async () => {
|
|
|
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(
|
|
@@ -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,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserStats } from '../userStats';
|
|
2
2
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
3
|
/**
|
|
4
4
|
* @param userStats
|
|
5
5
|
* @param accountLoader
|
|
6
6
|
*/
|
|
7
|
-
export declare function bulkPollingUserStatsSubscribe(userStats:
|
|
7
|
+
export declare function bulkPollingUserStatsSubscribe(userStats: UserStats[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -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>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataAndSlot, AccountToPoll,
|
|
2
|
+
import { DataAndSlot, AccountToPoll, DriftClientAccountEvents, DriftClientAccountSubscriber, OraclesToPoll } 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';
|
|
@@ -8,14 +8,14 @@ import { BulkAccountLoader } from './bulkAccountLoader';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class PollingDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
12
|
isSubscribed: boolean;
|
|
13
13
|
program: Program;
|
|
14
14
|
perpMarketIndexes: number[];
|
|
15
15
|
spotMarketIndexes: number[];
|
|
16
16
|
oracleInfos: OracleInfo[];
|
|
17
17
|
oracleClientCache: OracleClientCache;
|
|
18
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
19
19
|
accountLoader: BulkAccountLoader;
|
|
20
20
|
accountsToPoll: Map<string, AccountToPoll>;
|
|
21
21
|
oraclesToPoll: Map<string, OraclesToPoll>;
|
|
@@ -37,7 +37,6 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
37
37
|
addSpotMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
38
38
|
updateOraclesToPoll(): boolean;
|
|
39
39
|
addOracleToPoll(oracleInfo: OracleInfo): boolean;
|
|
40
|
-
getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
|
|
41
40
|
addToAccountLoader(): Promise<void>;
|
|
42
41
|
addAccountToAccountLoader(accountToPoll: AccountToPoll): void;
|
|
43
42
|
addOracleToAccountLoader(oracleToPoll: OraclesToPoll): void;
|
|
@@ -55,7 +54,3 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
55
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,7 +8,7 @@ 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
|
|
11
|
+
class PollingDriftClientAccountSubscriber {
|
|
12
12
|
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.accountsToPoll = new Map();
|
|
@@ -58,10 +58,10 @@ 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
67
|
await this.updatePerpMarketAccountsToPoll();
|
|
@@ -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);
|
|
@@ -276,4 +269,4 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
276
269
|
return this.oracles.get(oraclePublicKey.toString());
|
|
277
270
|
}
|
|
278
271
|
}
|
|
279
|
-
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;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface AccountSubscriber<T> {
|
|
|
15
15
|
export declare class NotSubscribedError extends Error {
|
|
16
16
|
name: string;
|
|
17
17
|
}
|
|
18
|
-
export interface
|
|
18
|
+
export interface DriftClientAccountEvents {
|
|
19
19
|
stateAccountUpdate: (payload: StateAccount) => void;
|
|
20
20
|
perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
|
|
21
21
|
spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
|
|
@@ -24,8 +24,8 @@ export interface ClearingHouseAccountEvents {
|
|
|
24
24
|
update: void;
|
|
25
25
|
error: (e: Error) => void;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
28
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
27
|
+
export interface DriftClientAccountSubscriber {
|
|
28
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
29
29
|
isSubscribed: boolean;
|
|
30
30
|
subscribe(): Promise<boolean>;
|
|
31
31
|
fetch(): Promise<void>;
|
|
@@ -71,7 +71,7 @@ export interface OracleEvents {
|
|
|
71
71
|
update: void;
|
|
72
72
|
error: (e: Error) => void;
|
|
73
73
|
}
|
|
74
|
-
export interface
|
|
74
|
+
export interface OracleAccountSubscriber {
|
|
75
75
|
eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
|
|
76
76
|
isSubscribed: boolean;
|
|
77
77
|
subscribe(): Promise<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './types';
|
|
3
3
|
import { AccountSubscriber } from './types';
|
|
4
4
|
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
5
5
|
import { Program } from '@project-serum/anchor';
|
|
@@ -8,14 +8,14 @@ import { EventEmitter } from 'events';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class WebSocketDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
12
|
isSubscribed: boolean;
|
|
13
13
|
program: Program;
|
|
14
14
|
perpMarketIndexes: number[];
|
|
15
15
|
spotMarketIndexes: number[];
|
|
16
16
|
oracleInfos: OracleInfo[];
|
|
17
17
|
oracleClientCache: OracleClientCache;
|
|
18
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
19
19
|
stateAccountSubscriber?: AccountSubscriber<StateAccount>;
|
|
20
20
|
perpMarketAccountSubscribers: Map<number, AccountSubscriber<PerpMarketAccount>>;
|
|
21
21
|
spotMarketAccountSubscribers: Map<number, AccountSubscriber<SpotMarketAccount>>;
|
|
@@ -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,7 +8,7 @@ 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
|
|
11
|
+
class WebSocketDriftClientAccountSubscriber {
|
|
12
12
|
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.perpMarketAccountSubscribers = new Map();
|
|
@@ -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) => {
|
|
@@ -193,4 +193,4 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
193
193
|
return this.oracleSubscribers.get(oraclePublicKey.toString()).dataAndSlot;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
exports.
|
|
196
|
+
exports.WebSocketDriftClientAccountSubscriber = WebSocketDriftClientAccountSubscriber;
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
|
4
|
+
export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
|
+
export declare function getDriftStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
6
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
|
7
7
|
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<PublicKey>;
|
|
8
8
|
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
|
|
@@ -12,7 +12,7 @@ export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex
|
|
|
12
12
|
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
13
13
|
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
14
|
export declare function getInsuranceFundStakeAccountPublicKey(programId: PublicKey, authority: PublicKey, marketIndex: number): PublicKey;
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function getDriftSignerPublicKey(programId: PublicKey): PublicKey;
|
|
16
16
|
export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
|
17
17
|
export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
|
|
18
18
|
export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,17 +23,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.
|
|
26
|
+
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
29
|
-
async function
|
|
30
|
-
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
29
|
+
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
30
|
+
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))], programId);
|
|
31
31
|
}
|
|
32
|
-
exports.
|
|
33
|
-
async function
|
|
34
|
-
return (await
|
|
32
|
+
exports.getDriftStateAccountPublicKeyAndNonce = getDriftStateAccountPublicKeyAndNonce;
|
|
33
|
+
async function getDriftStateAccountPublicKey(programId) {
|
|
34
|
+
return (await getDriftStateAccountPublicKeyAndNonce(programId))[0];
|
|
35
35
|
}
|
|
36
|
-
exports.
|
|
36
|
+
exports.getDriftStateAccountPublicKey = getDriftStateAccountPublicKey;
|
|
37
37
|
async function getUserAccountPublicKeyAndNonce(programId, authority, subAccountId = 0) {
|
|
38
38
|
return web3_js_1.PublicKey.findProgramAddress([
|
|
39
39
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
@@ -97,10 +97,10 @@ function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex
|
|
|
97
97
|
], programId)[0];
|
|
98
98
|
}
|
|
99
99
|
exports.getInsuranceFundStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey;
|
|
100
|
-
function
|
|
101
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
100
|
+
function getDriftSignerPublicKey(programId) {
|
|
101
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('drift_signer'))], programId)[0];
|
|
102
102
|
}
|
|
103
|
-
exports.
|
|
103
|
+
exports.getDriftSignerPublicKey = getDriftSignerPublicKey;
|
|
104
104
|
function getSerumOpenOrdersPublicKey(programId, market) {
|
|
105
105
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
106
106
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
3
|
import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier } from './types';
|
|
4
4
|
import { BN } from '@project-serum/anchor';
|
|
5
|
-
import {
|
|
6
|
-
export declare class
|
|
5
|
+
import { DriftClient } from './driftClient';
|
|
6
|
+
export declare class AdminClient extends DriftClient {
|
|
7
7
|
initialize(usdcMint: PublicKey, _adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
|
-
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number,
|
|
8
|
+
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
9
9
|
initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
10
|
-
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number,
|
|
10
|
+
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
11
11
|
moveAmmPrice(perpMarketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
12
|
updateK(perpMarketIndex: number, sqrtK: BN): Promise<TransactionSignature>;
|
|
13
13
|
updatePerpMarketConcentrationScale(perpMarketIndex: number, concentrationScale: BN): Promise<TransactionSignature>;
|
|
@@ -19,9 +19,11 @@ export declare class Admin extends ClearingHouse {
|
|
|
19
19
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
20
20
|
updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
21
21
|
updatePerpMarketMarginRatio(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
22
|
+
updatePerpMarketImfFactor(perpMarketIndex: number, imfFactor: number, unrealizedPnlImfFactor: number): Promise<TransactionSignature>;
|
|
22
23
|
updatePerpMarketBaseSpread(perpMarketIndex: number, baseSpread: number): Promise<TransactionSignature>;
|
|
23
24
|
updateAmmJitIntensity(perpMarketIndex: number, ammJitIntensity: number): Promise<TransactionSignature>;
|
|
24
25
|
updatePerpMarketName(perpMarketIndex: number, name: string): Promise<TransactionSignature>;
|
|
26
|
+
updateSpotMarketName(spotMarketIndex: number, name: string): Promise<TransactionSignature>;
|
|
25
27
|
updatePerpMarketMaxSpread(perpMarketIndex: number, maxSpread: number): Promise<TransactionSignature>;
|
|
26
28
|
updatePerpFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
27
29
|
updateSpotFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
@@ -36,12 +38,15 @@ export declare class Admin extends ClearingHouse {
|
|
|
36
38
|
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
37
39
|
updatePerpMarketStepSizeAndTickSize(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionSignature>;
|
|
38
40
|
updatePerpMarketMinOrderSize(perpMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
41
|
+
updateSpotMarketStepSizeAndTickSize(spotMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionSignature>;
|
|
42
|
+
updateSpotMarketMinOrderSize(spotMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
39
43
|
updatePerpMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
40
44
|
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
41
45
|
updateSpotMarketExpiry(spotMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
42
46
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
43
47
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
44
48
|
updateSpotMarketMarginWeights(spotMarketIndex: number, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number): Promise<TransactionSignature>;
|
|
49
|
+
updateSpotMarketBorrowRate(spotMarketIndex: number, optimalUtilization: number, optimalBorrowRate: number, optimalMaxRate: number): Promise<TransactionSignature>;
|
|
45
50
|
updateSpotMarketAssetTier(spotMarketIndex: number, assetTier: AssetTier): Promise<TransactionSignature>;
|
|
46
51
|
updateSpotMarketStatus(spotMarketIndex: number, marketStatus: MarketStatus): Promise<TransactionSignature>;
|
|
47
52
|
updatePerpMarketStatus(perpMarketIndex: number, marketStatus: MarketStatus): Promise<TransactionSignature>;
|
|
@@ -51,7 +56,10 @@ export declare class Admin extends ClearingHouse {
|
|
|
51
56
|
updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
|
|
52
57
|
updatePerpMarketMaxFillReserveFraction(perpMarketIndex: number, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
53
58
|
updateMaxSlippageRatio(perpMarketIndex: number, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
59
|
+
updatePerpMarketUnrealizedAssetWeight(perpMarketIndex: number, unrealizedInitialAssetWeight: number, unrealizedMaintenanceAssetWeight: number): Promise<TransactionSignature>;
|
|
54
60
|
updatePerpMarketMaxImbalances(perpMarketIndex: number, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
|
55
61
|
updatePerpMarketMaxOpenInterest(perpMarketIndex: number, maxOpenInterest: BN): Promise<TransactionSignature>;
|
|
56
62
|
updateSerumVault(srmVault: PublicKey): Promise<TransactionSignature>;
|
|
63
|
+
updatePerpMarketLiquidationFee(perpMarketIndex: number, liquidatorFee: number, ifLiquidationFee: number): Promise<TransactionSignature>;
|
|
64
|
+
updateSpotMarketLiquidationFee(spotMarketIndex: number, liquidatorFee: number, ifLiquidationFee: number): Promise<TransactionSignature>;
|
|
57
65
|
}
|