@drift-labs/sdk-browser 2.153.0-beta.4 ā 2.155.0-beta.1
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/laserProgramAccountSubscriber.d.ts +2 -2
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +8 -6
- package/lib/browser/accounts/types.d.ts +12 -4
- package/lib/browser/idl/drift.json +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +2 -2
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.js +8 -6
- package/lib/node/accounts/types.d.ts +12 -4
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/idl/drift.json +1 -1
- package/package.json +2 -2
- package/scripts/grpc-client-test-comparison.ts +2 -3
- package/scripts/grpc-multiuser-client-test-comparison.ts +140 -138
- package/scripts/single-grpc-client-test.ts +39 -21
- package/src/accounts/laserProgramAccountSubscriber.ts +9 -6
- package/src/accounts/types.ts +14 -4
- package/src/idl/drift.json +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.155.0-beta.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
3
|
+
import { LaserGrpcConfigs, ResubOpts } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
5
|
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
6
6
|
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
|
|
@@ -12,7 +12,7 @@ export declare class LaserstreamProgramAccountSubscriber<T> extends WebSocketPro
|
|
|
12
12
|
listenerId?: number;
|
|
13
13
|
private readonly laserConfig;
|
|
14
14
|
private constructor();
|
|
15
|
-
static create<U>(grpcConfigs:
|
|
15
|
+
static create<U>(grpcConfigs: LaserGrpcConfigs, subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options?: {
|
|
16
16
|
filters: MemcmpFilter[];
|
|
17
17
|
}, resubOpts?: ResubOpts): Promise<LaserstreamProgramAccountSubscriber<U>>;
|
|
18
18
|
subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
@@ -37,17 +37,19 @@ class LaserstreamProgramAccountSubscriber extends webSocketProgramAccountSubscri
|
|
|
37
37
|
static async create(grpcConfigs, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = {
|
|
38
38
|
filters: [],
|
|
39
39
|
}, resubOpts) {
|
|
40
|
-
var _a;
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const channelOptions = {
|
|
42
|
+
'grpc.default_compression_algorithm': grpc_1.CompressionAlgorithms.zstd,
|
|
43
|
+
'grpc.max_receive_message_length': 1000000000,
|
|
44
|
+
...((_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {}),
|
|
45
|
+
};
|
|
41
46
|
const laserConfig = {
|
|
42
47
|
apiKey: grpcConfigs.token,
|
|
43
48
|
endpoint: grpcConfigs.endpoint,
|
|
44
49
|
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
|
|
45
|
-
channelOptions
|
|
46
|
-
'grpc.default_compression_algorithm': grpc_1.CompressionAlgorithms.zstd,
|
|
47
|
-
'grpc.max_receive_message_length': 1000000000,
|
|
48
|
-
},
|
|
50
|
+
channelOptions,
|
|
49
51
|
};
|
|
50
|
-
const commitmentLevel = (
|
|
52
|
+
const commitmentLevel = (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
|
|
51
53
|
return new LaserstreamProgramAccountSubscriber(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
52
54
|
}
|
|
53
55
|
async subscribe(onChange) {
|
|
@@ -8,7 +8,7 @@ import { Context, PublicKey } from '@solana/web3.js';
|
|
|
8
8
|
import { Account } from '@solana/spl-token';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { User } from '../user';
|
|
11
|
-
import {
|
|
11
|
+
import { Client, CommitmentLevel, LaserstreamConfig } from '../isomorphic/grpc';
|
|
12
12
|
export interface AccountSubscriber<T> {
|
|
13
13
|
dataAndSlot?: DataAndSlot<T>;
|
|
14
14
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
@@ -155,18 +155,25 @@ export interface UserStatsAccountSubscriber {
|
|
|
155
155
|
unsubscribe(): Promise<void>;
|
|
156
156
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
type BaseGrpcConfigs = {
|
|
159
159
|
endpoint: string;
|
|
160
160
|
token: string;
|
|
161
161
|
commitmentLevel?: CommitmentLevel;
|
|
162
|
-
channelOptions?: ChannelOptions;
|
|
163
162
|
/**
|
|
164
163
|
* Whether to enable automatic reconnection on connection loss .
|
|
165
164
|
* Defaults to false, will throw on connection loss.
|
|
166
165
|
*/
|
|
167
166
|
enableReconnect?: boolean;
|
|
168
|
-
client?: 'yellowstone' | 'laser';
|
|
169
167
|
};
|
|
168
|
+
export type YellowstoneGrpcConfigs = BaseGrpcConfigs & {
|
|
169
|
+
client?: 'yellowstone';
|
|
170
|
+
channelOptions?: ConstructorParameters<typeof Client>[2];
|
|
171
|
+
};
|
|
172
|
+
export type LaserGrpcConfigs = BaseGrpcConfigs & {
|
|
173
|
+
client: 'laser';
|
|
174
|
+
channelOptions?: LaserstreamConfig['channelOptions'];
|
|
175
|
+
};
|
|
176
|
+
export type GrpcConfigs = YellowstoneGrpcConfigs | LaserGrpcConfigs;
|
|
170
177
|
export interface HighLeverageModeConfigAccountSubscriber {
|
|
171
178
|
eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
|
|
172
179
|
isSubscribed: boolean;
|
|
@@ -192,3 +199,4 @@ export interface ConstituentAccountEvents {
|
|
|
192
199
|
update: void;
|
|
193
200
|
error: (e: Error) => void;
|
|
194
201
|
}
|
|
202
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import {
|
|
3
|
+
import { LaserGrpcConfigs, ResubOpts } from './types';
|
|
4
4
|
import { Program } from '@coral-xyz/anchor';
|
|
5
5
|
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
6
6
|
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
|
|
@@ -12,7 +12,7 @@ export declare class LaserstreamProgramAccountSubscriber<T> extends WebSocketPro
|
|
|
12
12
|
listenerId?: number;
|
|
13
13
|
private readonly laserConfig;
|
|
14
14
|
private constructor();
|
|
15
|
-
static create<U>(grpcConfigs:
|
|
15
|
+
static create<U>(grpcConfigs: LaserGrpcConfigs, subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options?: {
|
|
16
16
|
filters: MemcmpFilter[];
|
|
17
17
|
}, resubOpts?: ResubOpts): Promise<LaserstreamProgramAccountSubscriber<U>>;
|
|
18
18
|
subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"laserProgramAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/laserProgramAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"laserProgramAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/laserProgramAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM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ends webSocketProgramAccountSubscri
|
|
|
37
37
|
static async create(grpcConfigs, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = {
|
|
38
38
|
filters: [],
|
|
39
39
|
}, resubOpts) {
|
|
40
|
-
var _a;
|
|
40
|
+
var _a, _b;
|
|
41
|
+
const channelOptions = {
|
|
42
|
+
'grpc.default_compression_algorithm': grpc_1.CompressionAlgorithms.zstd,
|
|
43
|
+
'grpc.max_receive_message_length': 1000000000,
|
|
44
|
+
...((_a = grpcConfigs.channelOptions) !== null && _a !== void 0 ? _a : {}),
|
|
45
|
+
};
|
|
41
46
|
const laserConfig = {
|
|
42
47
|
apiKey: grpcConfigs.token,
|
|
43
48
|
endpoint: grpcConfigs.endpoint,
|
|
44
49
|
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
|
|
45
|
-
channelOptions
|
|
46
|
-
'grpc.default_compression_algorithm': grpc_1.CompressionAlgorithms.zstd,
|
|
47
|
-
'grpc.max_receive_message_length': 1000000000,
|
|
48
|
-
},
|
|
50
|
+
channelOptions,
|
|
49
51
|
};
|
|
50
|
-
const commitmentLevel = (
|
|
52
|
+
const commitmentLevel = (_b = grpcConfigs.commitmentLevel) !== null && _b !== void 0 ? _b : grpc_1.CommitmentLevel.CONFIRMED;
|
|
51
53
|
return new LaserstreamProgramAccountSubscriber(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
52
54
|
}
|
|
53
55
|
async subscribe(onChange) {
|
|
@@ -8,7 +8,7 @@ import { Context, PublicKey } from '@solana/web3.js';
|
|
|
8
8
|
import { Account } from '@solana/spl-token';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { User } from '../user';
|
|
11
|
-
import {
|
|
11
|
+
import { Client, CommitmentLevel, LaserstreamConfig } from '../isomorphic/grpc';
|
|
12
12
|
export interface AccountSubscriber<T> {
|
|
13
13
|
dataAndSlot?: DataAndSlot<T>;
|
|
14
14
|
subscribe(onChange: (data: T) => void): Promise<void>;
|
|
@@ -155,18 +155,25 @@ export interface UserStatsAccountSubscriber {
|
|
|
155
155
|
unsubscribe(): Promise<void>;
|
|
156
156
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
type BaseGrpcConfigs = {
|
|
159
159
|
endpoint: string;
|
|
160
160
|
token: string;
|
|
161
161
|
commitmentLevel?: CommitmentLevel;
|
|
162
|
-
channelOptions?: ChannelOptions;
|
|
163
162
|
/**
|
|
164
163
|
* Whether to enable automatic reconnection on connection loss .
|
|
165
164
|
* Defaults to false, will throw on connection loss.
|
|
166
165
|
*/
|
|
167
166
|
enableReconnect?: boolean;
|
|
168
|
-
client?: 'yellowstone' | 'laser';
|
|
169
167
|
};
|
|
168
|
+
export type YellowstoneGrpcConfigs = BaseGrpcConfigs & {
|
|
169
|
+
client?: 'yellowstone';
|
|
170
|
+
channelOptions?: ConstructorParameters<typeof Client>[2];
|
|
171
|
+
};
|
|
172
|
+
export type LaserGrpcConfigs = BaseGrpcConfigs & {
|
|
173
|
+
client: 'laser';
|
|
174
|
+
channelOptions?: LaserstreamConfig['channelOptions'];
|
|
175
|
+
};
|
|
176
|
+
export type GrpcConfigs = YellowstoneGrpcConfigs | LaserGrpcConfigs;
|
|
170
177
|
export interface HighLeverageModeConfigAccountSubscriber {
|
|
171
178
|
eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
|
|
172
179
|
isSubscribed: boolean;
|
|
@@ -192,4 +199,5 @@ export interface ConstituentAccountEvents {
|
|
|
192
199
|
update: void;
|
|
193
200
|
error: (e: Error) => void;
|
|
194
201
|
}
|
|
202
|
+
export {};
|
|
195
203
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/accounts/types.ts"],"names":[],"mappings":";;;AAAA,OAAO,EACN,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AC,CAAC;IACrE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,wBAAwB;IACxC,eAAe,EAAE,CAChB,OAAO,EAAE,kBAAkB,EAC3B,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,KACR,IAAI,CAAC;IACV,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1B"}
|
package/lib/node/idl/drift.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.155.0-beta.1",
|
|
4
4
|
"main": "lib/node/index.js",
|
|
5
5
|
"types": "lib/node/index.d.ts",
|
|
6
6
|
"module": "./lib/browser/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@solana/web3.js": "1.98.0",
|
|
57
57
|
"@switchboard-xyz/common": "3.0.14",
|
|
58
58
|
"@switchboard-xyz/on-demand": "2.4.1",
|
|
59
|
-
"@triton-one/yellowstone-grpc": "
|
|
59
|
+
"@triton-one/yellowstone-grpc": "5.0.1",
|
|
60
60
|
"anchor-bankrun": "0.3.0",
|
|
61
61
|
"gill": "^0.10.2",
|
|
62
62
|
"helius-laserstream": "0.1.8",
|
|
@@ -96,9 +96,8 @@ async function initializeGrpcDriftClientV2VersusV1() {
|
|
|
96
96
|
token: TOKEN,
|
|
97
97
|
commitmentLevel: CommitmentLevel.PROCESSED,
|
|
98
98
|
channelOptions: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
'grpc.keepalive_permit_without_calls': 1,
|
|
99
|
+
grpcKeepAliveTimeout: 1_000,
|
|
100
|
+
grpcTcpKeepalive: 10_000,
|
|
102
101
|
},
|
|
103
102
|
},
|
|
104
103
|
};
|
|
@@ -13,144 +13,146 @@ const TOKEN = process.env.TOKEN;
|
|
|
13
13
|
const RPC_ENDPOINT = process.env.RPC_ENDPOINT;
|
|
14
14
|
|
|
15
15
|
const USER_ACCOUNT_PUBKEYS = [
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Add user account public keys here, e.g.:
|
|
17
|
+
// new PublicKey('...')
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
async function testGrpcUserAccountSubscriberV1VsV2() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
21
|
+
console.log('š Initializing User Account Subscriber V1 vs V2 Test...');
|
|
22
|
+
|
|
23
|
+
if (USER_ACCOUNT_PUBKEYS.length === 0) {
|
|
24
|
+
console.error(
|
|
25
|
+
'ā No user account public keys provided. Please add some to USER_ACCOUNT_PUBKEYS array.'
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const connection = new Connection(RPC_ENDPOINT);
|
|
31
|
+
const wallet = new Wallet(new Keypair());
|
|
32
|
+
|
|
33
|
+
const programId = new PublicKey(DRIFT_PROGRAM_ID);
|
|
34
|
+
const provider = new AnchorProvider(
|
|
35
|
+
connection,
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
wallet,
|
|
38
|
+
{
|
|
39
|
+
commitment: 'processed',
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const program = new Program(driftIDL as Idl, programId, provider);
|
|
44
|
+
|
|
45
|
+
const grpcConfigs = {
|
|
46
|
+
endpoint: GRPC_ENDPOINT,
|
|
47
|
+
token: TOKEN,
|
|
48
|
+
commitmentLevel: CommitmentLevel.PROCESSED,
|
|
49
|
+
channelOptions: {
|
|
50
|
+
grpcKeepAliveTimeout: 1_000,
|
|
51
|
+
grpcTcpKeepalive: 10_000,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
console.log(`š Testing ${USER_ACCOUNT_PUBKEYS.length} user accounts...`);
|
|
56
|
+
|
|
57
|
+
// V1: Create individual subscribers for each user account
|
|
58
|
+
const v1Subscribers = USER_ACCOUNT_PUBKEYS.map(
|
|
59
|
+
(pubkey) =>
|
|
60
|
+
new grpcUserAccountSubscriber(grpcConfigs, program, pubkey, {
|
|
61
|
+
logResubMessages: true,
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// V2: Create a single multi-subscriber and get per-user interfaces
|
|
66
|
+
const v2MultiSubscriber = new grpcMultiUserAccountSubscriber(
|
|
67
|
+
program,
|
|
68
|
+
grpcConfigs,
|
|
69
|
+
{ logResubMessages: true }
|
|
70
|
+
);
|
|
71
|
+
const v2Subscribers = USER_ACCOUNT_PUBKEYS.map((pubkey) =>
|
|
72
|
+
v2MultiSubscriber.forUser(pubkey)
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
// Subscribe all V1 subscribers
|
|
76
|
+
console.log('š Subscribing V1 subscribers...');
|
|
77
|
+
await Promise.all(v1Subscribers.map((sub) => sub.subscribe()));
|
|
78
|
+
console.log('ā
V1 subscribers ready');
|
|
79
|
+
|
|
80
|
+
// Subscribe all V2 subscribers
|
|
81
|
+
console.log('š Subscribing V2 subscribers...');
|
|
82
|
+
await v2MultiSubscriber.subscribe();
|
|
83
|
+
console.log('ā
V2 subscribers ready');
|
|
84
|
+
|
|
85
|
+
const compare = () => {
|
|
86
|
+
try {
|
|
87
|
+
let passedTests = 0;
|
|
88
|
+
let totalTests = 0;
|
|
89
|
+
|
|
90
|
+
// Test each user account
|
|
91
|
+
for (let i = 0; i < USER_ACCOUNT_PUBKEYS.length; i++) {
|
|
92
|
+
const pubkey = USER_ACCOUNT_PUBKEYS[i];
|
|
93
|
+
const v1Sub = v1Subscribers[i];
|
|
94
|
+
const v2Sub = v2Subscribers[i];
|
|
95
|
+
|
|
96
|
+
totalTests++;
|
|
97
|
+
|
|
98
|
+
// 1. Test isSubscribed
|
|
99
|
+
assert.strictEqual(
|
|
100
|
+
v1Sub.isSubscribed,
|
|
101
|
+
v2Sub.isSubscribed,
|
|
102
|
+
`User ${pubkey.toBase58()}: isSubscribed should match`
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// 2. Test getUserAccountAndSlot
|
|
106
|
+
const v1Data = v1Sub.getUserAccountAndSlot();
|
|
107
|
+
const v2Data = v2Sub.getUserAccountAndSlot();
|
|
108
|
+
|
|
109
|
+
// Compare the user account data
|
|
110
|
+
assert.deepStrictEqual(
|
|
111
|
+
v1Data.data,
|
|
112
|
+
v2Data.data,
|
|
113
|
+
`User ${pubkey.toBase58()}: account data should match`
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Slots might differ slightly due to timing, but let's check if they're close
|
|
117
|
+
const slotDiff = Math.abs(v1Data.slot - v2Data.slot);
|
|
118
|
+
if (slotDiff > 10) {
|
|
119
|
+
console.warn(
|
|
120
|
+
`ā ļø User ${pubkey.toBase58()}: slot difference is ${slotDiff} (v1: ${
|
|
121
|
+
v1Data.slot
|
|
122
|
+
}, v2: ${v2Data.slot})`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
passedTests++;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
console.log(
|
|
130
|
+
`ā
All comparisons passed (${passedTests}/${totalTests} user accounts)`
|
|
131
|
+
);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error('ā Comparison failed:', error);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Run initial comparison
|
|
138
|
+
compare();
|
|
139
|
+
|
|
140
|
+
// Run comparison every second to verify live updates
|
|
141
|
+
const interval = setInterval(compare, 1000);
|
|
142
|
+
|
|
143
|
+
const cleanup = async () => {
|
|
144
|
+
clearInterval(interval);
|
|
145
|
+
console.log('š§¹ Cleaning up...');
|
|
146
|
+
await Promise.all([
|
|
147
|
+
...v1Subscribers.map((sub) => sub.unsubscribe()),
|
|
148
|
+
...v2Subscribers.map((sub) => sub.unsubscribe()),
|
|
149
|
+
]);
|
|
150
|
+
console.log('ā
Cleanup complete');
|
|
151
|
+
process.exit(0);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
process.on('SIGINT', cleanup);
|
|
155
|
+
process.on('SIGTERM', cleanup);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
testGrpcUserAccountSubscriberV1VsV2().catch(console.error);
|
|
@@ -94,18 +94,18 @@ async function initializeSingleGrpcClient() {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
console.log(
|
|
97
|
+
console.log(
|
|
98
|
+
`š Markets: ${perpMarketIndexes.length} perp, ${spotMarketIndexes.length} spot`
|
|
99
|
+
);
|
|
98
100
|
console.log(`š® Oracles: ${oracleInfos.length}`);
|
|
99
101
|
|
|
100
|
-
|
|
101
102
|
const grpcConfigs = {
|
|
102
103
|
endpoint: GRPC_ENDPOINT,
|
|
103
104
|
token: TOKEN,
|
|
104
105
|
commitmentLevel: CommitmentLevel.PROCESSED,
|
|
105
106
|
channelOptions: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
'grpc.keepalive_permit_without_calls': 1,
|
|
107
|
+
grpcKeepAliveTimeout: 1_000,
|
|
108
|
+
grpcTcpKeepalive: 10_000,
|
|
109
109
|
},
|
|
110
110
|
};
|
|
111
111
|
|
|
@@ -171,7 +171,9 @@ async function initializeSingleGrpcClient() {
|
|
|
171
171
|
await client.subscribe();
|
|
172
172
|
|
|
173
173
|
console.log('ā
Client subscribed successfully!');
|
|
174
|
-
console.log(
|
|
174
|
+
console.log(
|
|
175
|
+
'š Starting high-load testing (50 reads/sec per perp market)...'
|
|
176
|
+
);
|
|
175
177
|
|
|
176
178
|
// High-frequency load testing - 50 reads per second per perp market
|
|
177
179
|
const loadTestInterval = setInterval(async () => {
|
|
@@ -179,25 +181,35 @@ async function initializeSingleGrpcClient() {
|
|
|
179
181
|
// Test getPerpMarketAccount for each perp market (50 times per second per market)
|
|
180
182
|
for (const marketIndex of perpMarketIndexes) {
|
|
181
183
|
const perpMarketAccount = client.getPerpMarketAccount(marketIndex);
|
|
182
|
-
console.log(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
console.log(
|
|
185
|
+
'perpMarketAccount name: ',
|
|
186
|
+
decodeName(perpMarketAccount.name)
|
|
187
|
+
);
|
|
188
|
+
console.log(
|
|
189
|
+
'perpMarketAccount data: ',
|
|
190
|
+
JSON.stringify({
|
|
191
|
+
marketIndex: perpMarketAccount.marketIndex,
|
|
192
|
+
name: decodeName(perpMarketAccount.name),
|
|
193
|
+
baseAssetReserve: perpMarketAccount.amm.baseAssetReserve.toString(),
|
|
194
|
+
quoteAssetReserve:
|
|
195
|
+
perpMarketAccount.amm.quoteAssetReserve.toString(),
|
|
196
|
+
})
|
|
197
|
+
);
|
|
189
198
|
}
|
|
190
199
|
|
|
191
200
|
// Test getMMOracleDataForPerpMarket for each perp market (50 times per second per market)
|
|
192
201
|
for (const marketIndex of perpMarketIndexes) {
|
|
193
202
|
try {
|
|
194
203
|
const oracleData = client.getMMOracleDataForPerpMarket(marketIndex);
|
|
195
|
-
console.log(
|
|
196
|
-
console.log(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
console.log('oracleData price: ', oracleData.price.toString());
|
|
205
|
+
console.log(
|
|
206
|
+
'oracleData: ',
|
|
207
|
+
JSON.stringify({
|
|
208
|
+
price: oracleData.price.toString(),
|
|
209
|
+
confidence: oracleData.confidence?.toString(),
|
|
210
|
+
slot: oracleData.slot?.toString(),
|
|
211
|
+
})
|
|
212
|
+
);
|
|
201
213
|
} catch (error) {
|
|
202
214
|
// Ignore errors for load testing
|
|
203
215
|
}
|
|
@@ -211,8 +223,14 @@ async function initializeSingleGrpcClient() {
|
|
|
211
223
|
const statsInterval = setInterval(() => {
|
|
212
224
|
console.log('\nš Event Counts:', eventCounts);
|
|
213
225
|
console.log(`ā±ļø Client subscribed: ${client.isSubscribed}`);
|
|
214
|
-
console.log(
|
|
215
|
-
|
|
226
|
+
console.log(
|
|
227
|
+
`š Account subscriber subscribed: ${client.accountSubscriber.isSubscribed}`
|
|
228
|
+
);
|
|
229
|
+
console.log(
|
|
230
|
+
`š„ Load: ${perpMarketIndexes.length * 50 * 2} reads/sec (${
|
|
231
|
+
perpMarketIndexes.length
|
|
232
|
+
} markets Ć 50 getPerpMarketAccount + 50 getMMOracleDataForPerpMarket)`
|
|
233
|
+
);
|
|
216
234
|
}, 5000);
|
|
217
235
|
|
|
218
236
|
// Handle shutdown signals - just exit without cleanup since they never unsubscribe
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LaserGrpcConfigs, ResubOpts } from './types';
|
|
2
2
|
import { Program } from '@coral-xyz/anchor';
|
|
3
3
|
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import * as Buffer from 'buffer';
|
|
@@ -56,7 +56,7 @@ export class LaserstreamProgramAccountSubscriber<
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
public static async create<U>(
|
|
59
|
-
grpcConfigs:
|
|
59
|
+
grpcConfigs: LaserGrpcConfigs,
|
|
60
60
|
subscriptionName: string,
|
|
61
61
|
accountDiscriminator: string,
|
|
62
62
|
program: Program,
|
|
@@ -66,14 +66,17 @@ export class LaserstreamProgramAccountSubscriber<
|
|
|
66
66
|
},
|
|
67
67
|
resubOpts?: ResubOpts
|
|
68
68
|
): Promise<LaserstreamProgramAccountSubscriber<U>> {
|
|
69
|
+
const channelOptions = {
|
|
70
|
+
'grpc.default_compression_algorithm': CompressionAlgorithms.zstd,
|
|
71
|
+
'grpc.max_receive_message_length': 1_000_000_000,
|
|
72
|
+
...(grpcConfigs.channelOptions ?? {}),
|
|
73
|
+
};
|
|
74
|
+
|
|
69
75
|
const laserConfig: LaserstreamConfig = {
|
|
70
76
|
apiKey: grpcConfigs.token,
|
|
71
77
|
endpoint: grpcConfigs.endpoint,
|
|
72
78
|
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
|
|
73
|
-
channelOptions
|
|
74
|
-
'grpc.default_compression_algorithm': CompressionAlgorithms.zstd,
|
|
75
|
-
'grpc.max_receive_message_length': 1_000_000_000,
|
|
76
|
-
},
|
|
79
|
+
channelOptions,
|
|
77
80
|
};
|
|
78
81
|
|
|
79
82
|
const commitmentLevel =
|
package/src/accounts/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { Context, PublicKey } from '@solana/web3.js';
|
|
|
15
15
|
import { Account } from '@solana/spl-token';
|
|
16
16
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
17
17
|
import { User } from '../user';
|
|
18
|
-
import {
|
|
18
|
+
import { Client, CommitmentLevel, LaserstreamConfig } from '../isomorphic/grpc';
|
|
19
19
|
|
|
20
20
|
export interface AccountSubscriber<T> {
|
|
21
21
|
dataAndSlot?: DataAndSlot<T>;
|
|
@@ -225,19 +225,29 @@ export interface UserStatsAccountSubscriber {
|
|
|
225
225
|
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
type BaseGrpcConfigs = {
|
|
229
229
|
endpoint: string;
|
|
230
230
|
token: string;
|
|
231
231
|
commitmentLevel?: CommitmentLevel;
|
|
232
|
-
channelOptions?: ChannelOptions;
|
|
233
232
|
/**
|
|
234
233
|
* Whether to enable automatic reconnection on connection loss .
|
|
235
234
|
* Defaults to false, will throw on connection loss.
|
|
236
235
|
*/
|
|
237
236
|
enableReconnect?: boolean;
|
|
238
|
-
client?: 'yellowstone' | 'laser';
|
|
239
237
|
};
|
|
240
238
|
|
|
239
|
+
export type YellowstoneGrpcConfigs = BaseGrpcConfigs & {
|
|
240
|
+
client?: 'yellowstone';
|
|
241
|
+
channelOptions?: ConstructorParameters<typeof Client>[2];
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export type LaserGrpcConfigs = BaseGrpcConfigs & {
|
|
245
|
+
client: 'laser';
|
|
246
|
+
channelOptions?: LaserstreamConfig['channelOptions'];
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export type GrpcConfigs = YellowstoneGrpcConfigs | LaserGrpcConfigs;
|
|
250
|
+
|
|
241
251
|
export interface HighLeverageModeConfigAccountSubscriber {
|
|
242
252
|
eventEmitter: StrictEventEmitter<
|
|
243
253
|
EventEmitter,
|
package/src/idl/drift.json
CHANGED