@drift-labs/sdk 2.146.0-beta.0 → 2.146.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/browser/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/browser/decode/user.js +4 -0
- package/lib/browser/driftClient.js +19 -17
- package/lib/browser/driftClientConfig.d.ts +7 -2
- package/lib/browser/index.d.ts +4 -0
- package/lib/browser/index.js +9 -1
- package/lib/browser/types.d.ts +2 -0
- package/lib/browser/user.js +2 -0
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts +99 -7
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriberV2.js +435 -144
- package/lib/node/decode/user.d.ts.map +1 -1
- package/lib/node/decode/user.js +4 -0
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +19 -17
- package/lib/node/driftClientConfig.d.ts +7 -2
- package/lib/node/driftClientConfig.d.ts.map +1 -1
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +9 -1
- package/lib/node/types.d.ts +2 -0
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +2 -0
- package/package.json +1 -1
- package/src/accounts/webSocketProgramAccountSubscriberV2.ts +566 -167
- package/src/decode/user.ts +7 -0
- package/src/driftClient.ts +7 -4
- package/src/driftClientConfig.ts +15 -8
- package/src/index.ts +4 -0
- package/src/types.ts +2 -0
- package/src/user.ts +2 -0
package/src/decode/user.ts
CHANGED
|
@@ -84,6 +84,11 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
84
84
|
const quoteAssetAmount = readSignedBigInt64LE(buffer, offset + 16);
|
|
85
85
|
const lpShares = readUnsignedBigInt64LE(buffer, offset + 64);
|
|
86
86
|
const openOrders = buffer.readUInt8(offset + 94);
|
|
87
|
+
const positionFlag = buffer.readUInt8(offset + 95);
|
|
88
|
+
const isolatedPositionScaledBalance = readUnsignedBigInt64LE(
|
|
89
|
+
buffer,
|
|
90
|
+
offset + 96
|
|
91
|
+
);
|
|
87
92
|
|
|
88
93
|
if (
|
|
89
94
|
baseAssetAmount.eq(ZERO) &&
|
|
@@ -135,6 +140,8 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
135
140
|
openOrders,
|
|
136
141
|
perLpBase,
|
|
137
142
|
maxMarginRatio,
|
|
143
|
+
isolatedPositionScaledBalance,
|
|
144
|
+
positionFlag,
|
|
138
145
|
});
|
|
139
146
|
}
|
|
140
147
|
|
package/src/driftClient.ts
CHANGED
|
@@ -406,6 +406,8 @@ export class DriftClient {
|
|
|
406
406
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
407
407
|
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
408
408
|
commitment: config.accountSubscription?.commitment,
|
|
409
|
+
programUserAccountSubscriber:
|
|
410
|
+
config.accountSubscription?.programUserAccountSubscriber,
|
|
409
411
|
};
|
|
410
412
|
this.userStatsAccountSubscriptionConfig = {
|
|
411
413
|
type: 'websocket',
|
|
@@ -474,7 +476,10 @@ export class DriftClient {
|
|
|
474
476
|
}
|
|
475
477
|
);
|
|
476
478
|
} else {
|
|
477
|
-
|
|
479
|
+
const accountSubscriberClass =
|
|
480
|
+
config.accountSubscription?.driftClientAccountSubscriber ??
|
|
481
|
+
WebSocketDriftClientAccountSubscriber;
|
|
482
|
+
this.accountSubscriber = new accountSubscriberClass(
|
|
478
483
|
this.program,
|
|
479
484
|
config.perpMarketIndexes ?? [],
|
|
480
485
|
config.spotMarketIndexes ?? [],
|
|
@@ -485,9 +490,7 @@ export class DriftClient {
|
|
|
485
490
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
486
491
|
logResubMessages: config.accountSubscription?.logResubMessages,
|
|
487
492
|
},
|
|
488
|
-
config.accountSubscription?.commitment
|
|
489
|
-
config.accountSubscription?.perpMarketAccountSubscriber,
|
|
490
|
-
config.accountSubscription?.oracleAccountSubscriber
|
|
493
|
+
config.accountSubscription?.commitment
|
|
491
494
|
);
|
|
492
495
|
}
|
|
493
496
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
package/src/driftClientConfig.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
PublicKey,
|
|
6
6
|
TransactionVersion,
|
|
7
7
|
} from '@solana/web3.js';
|
|
8
|
-
import { IWallet, TxParams } from './types';
|
|
8
|
+
import { IWallet, TxParams, UserAccount } from './types';
|
|
9
9
|
import { OracleInfo } from './oracles/types';
|
|
10
10
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
11
11
|
import { DriftEnv } from './config';
|
|
@@ -22,6 +22,9 @@ import { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscri
|
|
|
22
22
|
import { grpcDriftClientAccountSubscriberV2 } from './accounts/grpcDriftClientAccountSubscriberV2';
|
|
23
23
|
import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber';
|
|
24
24
|
import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountSubscriber';
|
|
25
|
+
import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
26
|
+
import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber';
|
|
27
|
+
import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
25
28
|
|
|
26
29
|
export type DriftClientConfig = {
|
|
27
30
|
connection: Connection;
|
|
@@ -78,6 +81,7 @@ export type DriftClientSubscriptionConfig =
|
|
|
78
81
|
resubTimeoutMs?: number;
|
|
79
82
|
logResubMessages?: boolean;
|
|
80
83
|
commitment?: Commitment;
|
|
84
|
+
programUserAccountSubscriber?: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
81
85
|
perpMarketAccountSubscriber?: new (
|
|
82
86
|
accountName: string,
|
|
83
87
|
program: Program,
|
|
@@ -86,14 +90,17 @@ export type DriftClientSubscriptionConfig =
|
|
|
86
90
|
resubOpts?: ResubOpts,
|
|
87
91
|
commitment?: Commitment
|
|
88
92
|
) => WebSocketAccountSubscriberV2<any> | WebSocketAccountSubscriber<any>;
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
/** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */
|
|
94
|
+
driftClientAccountSubscriber?: new (
|
|
91
95
|
program: Program,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
perpMarketIndexes: number[],
|
|
97
|
+
spotMarketIndexes: number[],
|
|
98
|
+
oracleInfos: OracleInfo[],
|
|
99
|
+
shouldFindAllMarketsAndOracles: boolean,
|
|
100
|
+
delistedMarketSetting: DelistedMarketSetting
|
|
101
|
+
) =>
|
|
102
|
+
| WebSocketDriftClientAccountSubscriber
|
|
103
|
+
| WebSocketDriftClientAccountSubscriberV2;
|
|
97
104
|
}
|
|
98
105
|
| {
|
|
99
106
|
type: 'polling';
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,10 @@ export * from './accounts/webSocketDriftClientAccountSubscriber';
|
|
|
12
12
|
export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
|
|
13
13
|
export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
|
|
14
14
|
export { WebSocketAccountSubscriberV2 } from './accounts/webSocketAccountSubscriberV2';
|
|
15
|
+
export { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber';
|
|
16
|
+
export { WebSocketProgramUserAccountSubscriber } from './accounts/websocketProgramUserAccountSubscriber';
|
|
17
|
+
export { WebSocketProgramAccountsSubscriberV2 } from './accounts/webSocketProgramAccountsSubscriberV2';
|
|
18
|
+
export { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2';
|
|
15
19
|
export * from './accounts/bulkAccountLoader';
|
|
16
20
|
export * from './accounts/bulkUserSubscription';
|
|
17
21
|
export * from './accounts/bulkUserStatsSubscription';
|
package/src/types.ts
CHANGED