@drift-labs/sdk 2.138.0-beta.2 → 2.138.0-beta.3
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 +22 -0
- package/lib/browser/accounts/laserProgramAccountSubscriber.js +155 -0
- package/lib/browser/accounts/types.d.ts +1 -0
- package/lib/browser/orderSubscriber/grpcSubscription.js +12 -3
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -0
- package/lib/node/accounts/laserProgramAccountSubscriber.js +155 -0
- package/lib/node/accounts/types.d.ts +1 -0
- package/lib/node/accounts/types.d.ts.map +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.d.ts.map +1 -1
- package/lib/node/orderSubscriber/grpcSubscription.js +12 -3
- package/package.json +2 -1
- package/src/accounts/laserProgramAccountSubscriber.ts +215 -0
- package/src/accounts/types.ts +1 -0
- package/src/orderSubscriber/grpcSubscription.ts +30 -12
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.138.0-beta.
|
|
1
|
+
2.138.0-beta.3
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { GrpcConfigs, ResubOpts } from './types';
|
|
4
|
+
import { Program } from '@coral-xyz/anchor';
|
|
5
|
+
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
6
|
+
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
|
|
7
|
+
import { CommitmentLevel as LaserCommitmentLevel } from 'helius-laserstream';
|
|
8
|
+
type LaserCommitment = (typeof LaserCommitmentLevel)[keyof typeof LaserCommitmentLevel];
|
|
9
|
+
export declare class LaserstreamProgramAccountSubscriber<T> extends WebSocketProgramAccountSubscriber<T> {
|
|
10
|
+
private stream;
|
|
11
|
+
private commitmentLevel;
|
|
12
|
+
listenerId?: number;
|
|
13
|
+
private readonly laserConfig;
|
|
14
|
+
private constructor();
|
|
15
|
+
static create<U>(grpcConfigs: GrpcConfigs, subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options?: {
|
|
16
|
+
filters: MemcmpFilter[];
|
|
17
|
+
}, resubOpts?: ResubOpts): Promise<LaserstreamProgramAccountSubscriber<U>>;
|
|
18
|
+
subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
19
|
+
unsubscribe(onResub?: boolean): Promise<void>;
|
|
20
|
+
toLaserCommitment(level: string | number | undefined): LaserCommitment;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LaserstreamProgramAccountSubscriber = void 0;
|
|
27
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
28
|
+
const Buffer = __importStar(require("buffer"));
|
|
29
|
+
const webSocketProgramAccountSubscriber_1 = require("./webSocketProgramAccountSubscriber");
|
|
30
|
+
const helius_laserstream_1 = require("helius-laserstream");
|
|
31
|
+
const yellowstone_grpc_1 = require("@triton-one/yellowstone-grpc");
|
|
32
|
+
class LaserstreamProgramAccountSubscriber extends webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber {
|
|
33
|
+
constructor(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = { filters: [] }, resubOpts) {
|
|
34
|
+
super(subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
35
|
+
this.laserConfig = laserConfig;
|
|
36
|
+
this.commitmentLevel = this.toLaserCommitment(commitmentLevel);
|
|
37
|
+
}
|
|
38
|
+
static async create(grpcConfigs, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = {
|
|
39
|
+
filters: [],
|
|
40
|
+
}, resubOpts) {
|
|
41
|
+
var _a;
|
|
42
|
+
const laserConfig = {
|
|
43
|
+
apiKey: grpcConfigs.token,
|
|
44
|
+
endpoint: grpcConfigs.endpoint,
|
|
45
|
+
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
|
|
46
|
+
channelOptions: {
|
|
47
|
+
'grpc.default_compression_algorithm': helius_laserstream_1.CompressionAlgorithms.zstd,
|
|
48
|
+
'grpc.max_receive_message_length': 1000000000,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const commitmentLevel = (_a = grpcConfigs.commitmentLevel) !== null && _a !== void 0 ? _a : yellowstone_grpc_1.CommitmentLevel.CONFIRMED;
|
|
52
|
+
return new LaserstreamProgramAccountSubscriber(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
53
|
+
}
|
|
54
|
+
async subscribe(onChange) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (this.listenerId != null || this.isUnsubscribing)
|
|
57
|
+
return;
|
|
58
|
+
this.onChange = onChange;
|
|
59
|
+
const filters = this.options.filters.map((filter) => {
|
|
60
|
+
return {
|
|
61
|
+
memcmp: {
|
|
62
|
+
offset: filter.memcmp.offset,
|
|
63
|
+
base58: filter.memcmp.bytes,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
const request = {
|
|
68
|
+
slots: {},
|
|
69
|
+
accounts: {
|
|
70
|
+
drift: {
|
|
71
|
+
account: [],
|
|
72
|
+
owner: [this.program.programId.toBase58()],
|
|
73
|
+
filters,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
transactions: {},
|
|
77
|
+
blocks: {},
|
|
78
|
+
blocksMeta: {},
|
|
79
|
+
accountsDataSlice: [],
|
|
80
|
+
commitment: this.commitmentLevel,
|
|
81
|
+
entry: {},
|
|
82
|
+
transactionsStatus: {},
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const stream = await (0, helius_laserstream_1.subscribe)(this.laserConfig, request, async (update) => {
|
|
86
|
+
var _a;
|
|
87
|
+
if (update.account) {
|
|
88
|
+
const slot = Number(update.account.slot);
|
|
89
|
+
const acc = update.account.account;
|
|
90
|
+
const accountInfo = {
|
|
91
|
+
owner: new web3_js_1.PublicKey(acc.owner),
|
|
92
|
+
lamports: Number(acc.lamports),
|
|
93
|
+
data: Buffer.Buffer.from(acc.data),
|
|
94
|
+
executable: acc.executable,
|
|
95
|
+
rentEpoch: Number(acc.rentEpoch),
|
|
96
|
+
};
|
|
97
|
+
const payload = {
|
|
98
|
+
accountId: new web3_js_1.PublicKey(acc.pubkey),
|
|
99
|
+
accountInfo,
|
|
100
|
+
};
|
|
101
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
102
|
+
this.receivingData = true;
|
|
103
|
+
clearTimeout(this.timeoutId);
|
|
104
|
+
this.handleRpcResponse({ slot }, payload);
|
|
105
|
+
this.setTimeout();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.handleRpcResponse({ slot }, payload);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, async (error) => {
|
|
112
|
+
console.error('LaserStream client error:', error);
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
115
|
+
this.stream = stream;
|
|
116
|
+
this.listenerId = 1;
|
|
117
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
118
|
+
this.receivingData = true;
|
|
119
|
+
this.setTimeout();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
console.error('Failed to start LaserStream client:', err);
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async unsubscribe(onResub = false) {
|
|
128
|
+
if (!onResub && this.resubOpts) {
|
|
129
|
+
this.resubOpts.resubTimeoutMs = undefined;
|
|
130
|
+
}
|
|
131
|
+
this.isUnsubscribing = true;
|
|
132
|
+
clearTimeout(this.timeoutId);
|
|
133
|
+
this.timeoutId = undefined;
|
|
134
|
+
if (this.listenerId != null && this.stream) {
|
|
135
|
+
try {
|
|
136
|
+
this.stream.cancel();
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
this.listenerId = undefined;
|
|
140
|
+
this.isUnsubscribing = false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.isUnsubscribing = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
toLaserCommitment(level) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
if (typeof level === 'string') {
|
|
150
|
+
return ((_a = helius_laserstream_1.CommitmentLevel[level.toUpperCase()]) !== null && _a !== void 0 ? _a : helius_laserstream_1.CommitmentLevel.CONFIRMED);
|
|
151
|
+
}
|
|
152
|
+
return (_b = level) !== null && _b !== void 0 ? _b : helius_laserstream_1.CommitmentLevel.CONFIRMED;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.LaserstreamProgramAccountSubscriber = LaserstreamProgramAccountSubscriber;
|
|
@@ -165,6 +165,7 @@ export type GrpcConfigs = {
|
|
|
165
165
|
* Defaults to false, will throw on connection loss.
|
|
166
166
|
*/
|
|
167
167
|
enableReconnect?: boolean;
|
|
168
|
+
client?: 'yellowstone' | 'lazer';
|
|
168
169
|
};
|
|
169
170
|
export interface HighLeverageModeConfigAccountSubscriber {
|
|
170
171
|
eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.grpcSubscription = void 0;
|
|
4
4
|
const grpcProgramAccountSubscriber_1 = require("../accounts/grpcProgramAccountSubscriber");
|
|
5
5
|
const memcmp_1 = require("../memcmp");
|
|
6
|
+
const laserProgramAccountSubscriber_1 = require("../accounts/laserProgramAccountSubscriber");
|
|
6
7
|
class grpcSubscription {
|
|
7
8
|
constructor({ grpcConfigs, orderSubscriber, skipInitialLoad = false, resubOpts, resyncIntervalMs, decoded = true, }) {
|
|
8
9
|
this.orderSubscriber = orderSubscriber;
|
|
@@ -16,9 +17,17 @@ class grpcSubscription {
|
|
|
16
17
|
if (this.subscriber) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (this.grpcConfigs.client === 'lazer') {
|
|
21
|
+
this.subscriber =
|
|
22
|
+
await laserProgramAccountSubscriber_1.LaserstreamProgramAccountSubscriber.create(this.grpcConfigs, 'OrderSubscriber', 'User', this.orderSubscriber.driftClient.program, this.orderSubscriber.decodeFn, {
|
|
23
|
+
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getNonIdleUserFilter)()],
|
|
24
|
+
}, this.resubOpts);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'OrderSubscriber', 'User', this.orderSubscriber.driftClient.program, this.orderSubscriber.decodeFn, {
|
|
28
|
+
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getNonIdleUserFilter)()],
|
|
29
|
+
}, this.resubOpts);
|
|
30
|
+
}
|
|
22
31
|
await this.subscriber.subscribe((accountId, account, context, buffer) => {
|
|
23
32
|
var _a;
|
|
24
33
|
const userKey = accountId.toBase58();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { GrpcConfigs, ResubOpts } from './types';
|
|
4
|
+
import { Program } from '@coral-xyz/anchor';
|
|
5
|
+
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
6
|
+
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
|
|
7
|
+
import { CommitmentLevel as LaserCommitmentLevel } from 'helius-laserstream';
|
|
8
|
+
type LaserCommitment = (typeof LaserCommitmentLevel)[keyof typeof LaserCommitmentLevel];
|
|
9
|
+
export declare class LaserstreamProgramAccountSubscriber<T> extends WebSocketProgramAccountSubscriber<T> {
|
|
10
|
+
private stream;
|
|
11
|
+
private commitmentLevel;
|
|
12
|
+
listenerId?: number;
|
|
13
|
+
private readonly laserConfig;
|
|
14
|
+
private constructor();
|
|
15
|
+
static create<U>(grpcConfigs: GrpcConfigs, subscriptionName: string, accountDiscriminator: string, program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options?: {
|
|
16
|
+
filters: MemcmpFilter[];
|
|
17
|
+
}, resubOpts?: ResubOpts): Promise<LaserstreamProgramAccountSubscriber<U>>;
|
|
18
|
+
subscribe(onChange: (accountId: PublicKey, data: T, context: Context, buffer: Buffer) => void): Promise<void>;
|
|
19
|
+
unsubscribe(onResub?: boolean): Promise<void>;
|
|
20
|
+
toLaserCommitment(level: string | number | undefined): LaserCommitment;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=laserProgramAccountSubscriber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"laserProgramAccountSubscriber.d.ts","sourceRoot":"","sources":["../../../src/accounts/laserProgramAccountSubscriber.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EACN,eAAe,IAAI,oBAAoB,EAMvC,MAAM,oBAAoB,CAAC;AAG5B,KAAK,eAAe,GACnB,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAC;AAElE,qBAAa,mCAAmC,CAC/C,CAAC,CACA,SAAQ,iCAAiC,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,MAAM,CAMD;IAEb,OAAO,CAAC,eAAe,CAAkB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAEhD,OAAO;WAsBa,MAAM,CAAC,CAAC,EAC3B,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,MAAM,EACxB,oBAAoB,EAAE,MAAM,EAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,CAAC,EACtD,OAAO,GAAE;QAAE,OAAO,EAAE,YAAY,EAAE,CAAA;KAEjC,EACD,SAAS,CAAC,EAAE,SAAS,GACnB,OAAO,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC;IA0B5C,SAAS,CACd,QAAQ,EAAE,CACT,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,KACV,IAAI,GACP,OAAO,CAAC,IAAI,CAAC;IAmFH,WAAW,CAAC,OAAO,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBjD,iBAAiB,CACvB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAChC,eAAe;CASlB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.LaserstreamProgramAccountSubscriber = void 0;
|
|
27
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
28
|
+
const Buffer = __importStar(require("buffer"));
|
|
29
|
+
const webSocketProgramAccountSubscriber_1 = require("./webSocketProgramAccountSubscriber");
|
|
30
|
+
const helius_laserstream_1 = require("helius-laserstream");
|
|
31
|
+
const yellowstone_grpc_1 = require("@triton-one/yellowstone-grpc");
|
|
32
|
+
class LaserstreamProgramAccountSubscriber extends webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber {
|
|
33
|
+
constructor(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = { filters: [] }, resubOpts) {
|
|
34
|
+
super(subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
35
|
+
this.laserConfig = laserConfig;
|
|
36
|
+
this.commitmentLevel = this.toLaserCommitment(commitmentLevel);
|
|
37
|
+
}
|
|
38
|
+
static async create(grpcConfigs, subscriptionName, accountDiscriminator, program, decodeBufferFn, options = {
|
|
39
|
+
filters: [],
|
|
40
|
+
}, resubOpts) {
|
|
41
|
+
var _a;
|
|
42
|
+
const laserConfig = {
|
|
43
|
+
apiKey: grpcConfigs.token,
|
|
44
|
+
endpoint: grpcConfigs.endpoint,
|
|
45
|
+
maxReconnectAttempts: grpcConfigs.enableReconnect ? 10 : 0,
|
|
46
|
+
channelOptions: {
|
|
47
|
+
'grpc.default_compression_algorithm': helius_laserstream_1.CompressionAlgorithms.zstd,
|
|
48
|
+
'grpc.max_receive_message_length': 1000000000,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const commitmentLevel = (_a = grpcConfigs.commitmentLevel) !== null && _a !== void 0 ? _a : yellowstone_grpc_1.CommitmentLevel.CONFIRMED;
|
|
52
|
+
return new LaserstreamProgramAccountSubscriber(laserConfig, commitmentLevel, subscriptionName, accountDiscriminator, program, decodeBufferFn, options, resubOpts);
|
|
53
|
+
}
|
|
54
|
+
async subscribe(onChange) {
|
|
55
|
+
var _a;
|
|
56
|
+
if (this.listenerId != null || this.isUnsubscribing)
|
|
57
|
+
return;
|
|
58
|
+
this.onChange = onChange;
|
|
59
|
+
const filters = this.options.filters.map((filter) => {
|
|
60
|
+
return {
|
|
61
|
+
memcmp: {
|
|
62
|
+
offset: filter.memcmp.offset,
|
|
63
|
+
base58: filter.memcmp.bytes,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
const request = {
|
|
68
|
+
slots: {},
|
|
69
|
+
accounts: {
|
|
70
|
+
drift: {
|
|
71
|
+
account: [],
|
|
72
|
+
owner: [this.program.programId.toBase58()],
|
|
73
|
+
filters,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
transactions: {},
|
|
77
|
+
blocks: {},
|
|
78
|
+
blocksMeta: {},
|
|
79
|
+
accountsDataSlice: [],
|
|
80
|
+
commitment: this.commitmentLevel,
|
|
81
|
+
entry: {},
|
|
82
|
+
transactionsStatus: {},
|
|
83
|
+
};
|
|
84
|
+
try {
|
|
85
|
+
const stream = await (0, helius_laserstream_1.subscribe)(this.laserConfig, request, async (update) => {
|
|
86
|
+
var _a;
|
|
87
|
+
if (update.account) {
|
|
88
|
+
const slot = Number(update.account.slot);
|
|
89
|
+
const acc = update.account.account;
|
|
90
|
+
const accountInfo = {
|
|
91
|
+
owner: new web3_js_1.PublicKey(acc.owner),
|
|
92
|
+
lamports: Number(acc.lamports),
|
|
93
|
+
data: Buffer.Buffer.from(acc.data),
|
|
94
|
+
executable: acc.executable,
|
|
95
|
+
rentEpoch: Number(acc.rentEpoch),
|
|
96
|
+
};
|
|
97
|
+
const payload = {
|
|
98
|
+
accountId: new web3_js_1.PublicKey(acc.pubkey),
|
|
99
|
+
accountInfo,
|
|
100
|
+
};
|
|
101
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
102
|
+
this.receivingData = true;
|
|
103
|
+
clearTimeout(this.timeoutId);
|
|
104
|
+
this.handleRpcResponse({ slot }, payload);
|
|
105
|
+
this.setTimeout();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
this.handleRpcResponse({ slot }, payload);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, async (error) => {
|
|
112
|
+
console.error('LaserStream client error:', error);
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
115
|
+
this.stream = stream;
|
|
116
|
+
this.listenerId = 1;
|
|
117
|
+
if ((_a = this.resubOpts) === null || _a === void 0 ? void 0 : _a.resubTimeoutMs) {
|
|
118
|
+
this.receivingData = true;
|
|
119
|
+
this.setTimeout();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
console.error('Failed to start LaserStream client:', err);
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async unsubscribe(onResub = false) {
|
|
128
|
+
if (!onResub && this.resubOpts) {
|
|
129
|
+
this.resubOpts.resubTimeoutMs = undefined;
|
|
130
|
+
}
|
|
131
|
+
this.isUnsubscribing = true;
|
|
132
|
+
clearTimeout(this.timeoutId);
|
|
133
|
+
this.timeoutId = undefined;
|
|
134
|
+
if (this.listenerId != null && this.stream) {
|
|
135
|
+
try {
|
|
136
|
+
this.stream.cancel();
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
this.listenerId = undefined;
|
|
140
|
+
this.isUnsubscribing = false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.isUnsubscribing = false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
toLaserCommitment(level) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
if (typeof level === 'string') {
|
|
150
|
+
return ((_a = helius_laserstream_1.CommitmentLevel[level.toUpperCase()]) !== null && _a !== void 0 ? _a : helius_laserstream_1.CommitmentLevel.CONFIRMED);
|
|
151
|
+
}
|
|
152
|
+
return (_b = level) !== null && _b !== void 0 ? _b : helius_laserstream_1.CommitmentLevel.CONFIRMED;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.LaserstreamProgramAccountSubscriber = LaserstreamProgramAccountSubscriber;
|
|
@@ -165,6 +165,7 @@ export type GrpcConfigs = {
|
|
|
165
165
|
* Defaults to false, will throw on connection loss.
|
|
166
166
|
*/
|
|
167
167
|
enableReconnect?: boolean;
|
|
168
|
+
client?: 'yellowstone' | 'lazer';
|
|
168
169
|
};
|
|
169
170
|
export interface HighLeverageModeConfigAccountSubscriber {
|
|
170
171
|
eventEmitter: StrictEventEmitter<EventEmitter, HighLeverageModeConfigAccountEvents>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/accounts/types.ts"],"names":[],"mappings":";;;AAAA,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,MAAM,UAAU,CAAC;AAClB,OAAO,kBAAkB,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErE,MAAM,WAAW,iBAAiB,CAAC,CAAC;IACnC,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC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CAAC,EAAE,sBAAsB,GACpD,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,uCAAuC,IAAI,WAAW,CAAC,sBAAsB,CAAC,CAAC;CAC/E;AAED,MAAM,WAAW,mCAAmC;IACnD,mCAAmC,EAAE,CACpC,OAAO,EAAE,sBAAsB,KAC3B,IAAI,CAAC;IACV,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grpcSubscription.d.ts","sourceRoot":"","sources":["../../../src/orderSubscriber/grpcSubscription.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"grpcSubscription.d.ts","sourceRoot":"","sources":["../../../src/orderSubscriber/grpcSubscription.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAK3D,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,gBAAgB,CAAC,CAAS;IAElC,OAAO,CAAC,UAAU,CAAC,CAEiC;IACpD,OAAO,CAAC,eAAe,CAAC,CAAgC;IAExD,OAAO,CAAC,OAAO,CAAC,CAAU;IAE1B,OAAO,CAAC,WAAW,CAAc;gBAErB,EACX,WAAW,EACX,eAAe,EACf,eAAuB,EACvB,SAAS,EACT,gBAAgB,EAChB,OAAc,GACd,EAAE;QACF,WAAW,EAAE,WAAW,CAAC;QACzB,eAAe,EAAE,eAAe,CAAC;QACjC,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;KAClB;IASY,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAkF1B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CASzC"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.grpcSubscription = void 0;
|
|
4
4
|
const grpcProgramAccountSubscriber_1 = require("../accounts/grpcProgramAccountSubscriber");
|
|
5
5
|
const memcmp_1 = require("../memcmp");
|
|
6
|
+
const laserProgramAccountSubscriber_1 = require("../accounts/laserProgramAccountSubscriber");
|
|
6
7
|
class grpcSubscription {
|
|
7
8
|
constructor({ grpcConfigs, orderSubscriber, skipInitialLoad = false, resubOpts, resyncIntervalMs, decoded = true, }) {
|
|
8
9
|
this.orderSubscriber = orderSubscriber;
|
|
@@ -16,9 +17,17 @@ class grpcSubscription {
|
|
|
16
17
|
if (this.subscriber) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (this.grpcConfigs.client === 'lazer') {
|
|
21
|
+
this.subscriber =
|
|
22
|
+
await laserProgramAccountSubscriber_1.LaserstreamProgramAccountSubscriber.create(this.grpcConfigs, 'OrderSubscriber', 'User', this.orderSubscriber.driftClient.program, this.orderSubscriber.decodeFn, {
|
|
23
|
+
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getNonIdleUserFilter)()],
|
|
24
|
+
}, this.resubOpts);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.subscriber = await grpcProgramAccountSubscriber_1.grpcProgramAccountSubscriber.create(this.grpcConfigs, 'OrderSubscriber', 'User', this.orderSubscriber.driftClient.program, this.orderSubscriber.decodeFn, {
|
|
28
|
+
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getNonIdleUserFilter)()],
|
|
29
|
+
}, this.resubOpts);
|
|
30
|
+
}
|
|
22
31
|
await this.subscriber.subscribe((accountId, account, context, buffer) => {
|
|
23
32
|
var _a;
|
|
24
33
|
const userKey = accountId.toBase58();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.138.0-beta.
|
|
3
|
+
"version": "2.138.0-beta.3",
|
|
4
4
|
"main": "lib/node/index.js",
|
|
5
5
|
"types": "lib/node/index.d.ts",
|
|
6
6
|
"browser": "./lib/browser/index.js",
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"@triton-one/yellowstone-grpc": "1.3.0",
|
|
56
56
|
"anchor-bankrun": "0.3.0",
|
|
57
57
|
"gill": "^0.10.2",
|
|
58
|
+
"helius-laserstream": "^0.1.7",
|
|
58
59
|
"nanoid": "3.3.4",
|
|
59
60
|
"node-cache": "5.1.2",
|
|
60
61
|
"rpc-websockets": "7.5.1",
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { GrpcConfigs, ResubOpts } from './types';
|
|
2
|
+
import { Program } from '@coral-xyz/anchor';
|
|
3
|
+
import { Context, MemcmpFilter, PublicKey } from '@solana/web3.js';
|
|
4
|
+
import * as Buffer from 'buffer';
|
|
5
|
+
import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CommitmentLevel as LaserCommitmentLevel,
|
|
9
|
+
subscribe as LaserSubscribe,
|
|
10
|
+
LaserstreamConfig,
|
|
11
|
+
SubscribeRequest,
|
|
12
|
+
SubscribeUpdate,
|
|
13
|
+
CompressionAlgorithms,
|
|
14
|
+
} from 'helius-laserstream';
|
|
15
|
+
import { CommitmentLevel } from '@triton-one/yellowstone-grpc';
|
|
16
|
+
|
|
17
|
+
type LaserCommitment =
|
|
18
|
+
(typeof LaserCommitmentLevel)[keyof typeof LaserCommitmentLevel];
|
|
19
|
+
|
|
20
|
+
export class LaserstreamProgramAccountSubscriber<
|
|
21
|
+
T,
|
|
22
|
+
> extends WebSocketProgramAccountSubscriber<T> {
|
|
23
|
+
private stream:
|
|
24
|
+
| {
|
|
25
|
+
id: string;
|
|
26
|
+
cancel: () => void;
|
|
27
|
+
write?: (req: SubscribeRequest) => Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
| undefined;
|
|
30
|
+
|
|
31
|
+
private commitmentLevel: CommitmentLevel;
|
|
32
|
+
public listenerId?: number;
|
|
33
|
+
|
|
34
|
+
private readonly laserConfig: LaserstreamConfig;
|
|
35
|
+
|
|
36
|
+
private constructor(
|
|
37
|
+
laserConfig: LaserstreamConfig,
|
|
38
|
+
commitmentLevel: CommitmentLevel,
|
|
39
|
+
subscriptionName: string,
|
|
40
|
+
accountDiscriminator: string,
|
|
41
|
+
program: Program,
|
|
42
|
+
decodeBufferFn: (accountName: string, ix: Buffer) => T,
|
|
43
|
+
options: { filters: MemcmpFilter[] } = { filters: [] },
|
|
44
|
+
resubOpts?: ResubOpts
|
|
45
|
+
) {
|
|
46
|
+
super(
|
|
47
|
+
subscriptionName,
|
|
48
|
+
accountDiscriminator,
|
|
49
|
+
program,
|
|
50
|
+
decodeBufferFn,
|
|
51
|
+
options,
|
|
52
|
+
resubOpts
|
|
53
|
+
);
|
|
54
|
+
this.laserConfig = laserConfig;
|
|
55
|
+
this.commitmentLevel = this.toLaserCommitment(commitmentLevel);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public static async create<U>(
|
|
59
|
+
grpcConfigs: GrpcConfigs,
|
|
60
|
+
subscriptionName: string,
|
|
61
|
+
accountDiscriminator: string,
|
|
62
|
+
program: Program,
|
|
63
|
+
decodeBufferFn: (accountName: string, ix: Buffer) => U,
|
|
64
|
+
options: { filters: MemcmpFilter[] } = {
|
|
65
|
+
filters: [],
|
|
66
|
+
},
|
|
67
|
+
resubOpts?: ResubOpts
|
|
68
|
+
): Promise<LaserstreamProgramAccountSubscriber<U>> {
|
|
69
|
+
const laserConfig: LaserstreamConfig = {
|
|
70
|
+
apiKey: grpcConfigs.token,
|
|
71
|
+
endpoint: grpcConfigs.endpoint,
|
|
72
|
+
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
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const commitmentLevel =
|
|
80
|
+
grpcConfigs.commitmentLevel ?? CommitmentLevel.CONFIRMED;
|
|
81
|
+
|
|
82
|
+
return new LaserstreamProgramAccountSubscriber<U>(
|
|
83
|
+
laserConfig,
|
|
84
|
+
commitmentLevel,
|
|
85
|
+
subscriptionName,
|
|
86
|
+
accountDiscriminator,
|
|
87
|
+
program,
|
|
88
|
+
decodeBufferFn,
|
|
89
|
+
options,
|
|
90
|
+
resubOpts
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async subscribe(
|
|
95
|
+
onChange: (
|
|
96
|
+
accountId: PublicKey,
|
|
97
|
+
data: T,
|
|
98
|
+
context: Context,
|
|
99
|
+
buffer: Buffer
|
|
100
|
+
) => void
|
|
101
|
+
): Promise<void> {
|
|
102
|
+
if (this.listenerId != null || this.isUnsubscribing) return;
|
|
103
|
+
|
|
104
|
+
this.onChange = onChange;
|
|
105
|
+
|
|
106
|
+
const filters = this.options.filters.map((filter) => {
|
|
107
|
+
return {
|
|
108
|
+
memcmp: {
|
|
109
|
+
offset: filter.memcmp.offset,
|
|
110
|
+
base58: filter.memcmp.bytes,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const request: SubscribeRequest = {
|
|
116
|
+
slots: {},
|
|
117
|
+
accounts: {
|
|
118
|
+
drift: {
|
|
119
|
+
account: [],
|
|
120
|
+
owner: [this.program.programId.toBase58()],
|
|
121
|
+
filters,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
transactions: {},
|
|
125
|
+
blocks: {},
|
|
126
|
+
blocksMeta: {},
|
|
127
|
+
accountsDataSlice: [],
|
|
128
|
+
commitment: this.commitmentLevel,
|
|
129
|
+
entry: {},
|
|
130
|
+
transactionsStatus: {},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const stream = await LaserSubscribe(
|
|
135
|
+
this.laserConfig,
|
|
136
|
+
request,
|
|
137
|
+
async (update: SubscribeUpdate) => {
|
|
138
|
+
if (update.account) {
|
|
139
|
+
const slot = Number(update.account.slot);
|
|
140
|
+
const acc = update.account.account;
|
|
141
|
+
|
|
142
|
+
const accountInfo = {
|
|
143
|
+
owner: new PublicKey(acc.owner),
|
|
144
|
+
lamports: Number(acc.lamports),
|
|
145
|
+
data: Buffer.Buffer.from(acc.data),
|
|
146
|
+
executable: acc.executable,
|
|
147
|
+
rentEpoch: Number(acc.rentEpoch),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const payload = {
|
|
151
|
+
accountId: new PublicKey(acc.pubkey),
|
|
152
|
+
accountInfo,
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
if (this.resubOpts?.resubTimeoutMs) {
|
|
156
|
+
this.receivingData = true;
|
|
157
|
+
clearTimeout(this.timeoutId);
|
|
158
|
+
this.handleRpcResponse({ slot }, payload);
|
|
159
|
+
this.setTimeout();
|
|
160
|
+
} else {
|
|
161
|
+
this.handleRpcResponse({ slot }, payload);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
async (error) => {
|
|
166
|
+
console.error('LaserStream client error:', error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
this.stream = stream;
|
|
172
|
+
this.listenerId = 1;
|
|
173
|
+
|
|
174
|
+
if (this.resubOpts?.resubTimeoutMs) {
|
|
175
|
+
this.receivingData = true;
|
|
176
|
+
this.setTimeout();
|
|
177
|
+
}
|
|
178
|
+
} catch (err) {
|
|
179
|
+
console.error('Failed to start LaserStream client:', err);
|
|
180
|
+
throw err;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public async unsubscribe(onResub = false): Promise<void> {
|
|
185
|
+
if (!onResub && this.resubOpts) {
|
|
186
|
+
this.resubOpts.resubTimeoutMs = undefined;
|
|
187
|
+
}
|
|
188
|
+
this.isUnsubscribing = true;
|
|
189
|
+
clearTimeout(this.timeoutId);
|
|
190
|
+
this.timeoutId = undefined;
|
|
191
|
+
|
|
192
|
+
if (this.listenerId != null && this.stream) {
|
|
193
|
+
try {
|
|
194
|
+
this.stream.cancel();
|
|
195
|
+
} finally {
|
|
196
|
+
this.listenerId = undefined;
|
|
197
|
+
this.isUnsubscribing = false;
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
this.isUnsubscribing = false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public toLaserCommitment(
|
|
205
|
+
level: string | number | undefined
|
|
206
|
+
): LaserCommitment {
|
|
207
|
+
if (typeof level === 'string') {
|
|
208
|
+
return (
|
|
209
|
+
(LaserCommitmentLevel as any)[level.toUpperCase()] ??
|
|
210
|
+
LaserCommitmentLevel.CONFIRMED
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return (level as LaserCommitment) ?? LaserCommitmentLevel.CONFIRMED;
|
|
214
|
+
}
|
|
215
|
+
}
|
package/src/accounts/types.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { OrderSubscriber } from './OrderSubscriber';
|
|
|
5
5
|
import { GrpcConfigs, ResubOpts } from '../accounts/types';
|
|
6
6
|
import { UserAccount } from '../types';
|
|
7
7
|
import { getUserFilter, getNonIdleUserFilter } from '../memcmp';
|
|
8
|
+
import { LaserstreamProgramAccountSubscriber } from '../accounts/laserProgramAccountSubscriber';
|
|
8
9
|
|
|
9
10
|
export class grpcSubscription {
|
|
10
11
|
private orderSubscriber: OrderSubscriber;
|
|
@@ -12,7 +13,9 @@ export class grpcSubscription {
|
|
|
12
13
|
private resubOpts?: ResubOpts;
|
|
13
14
|
private resyncIntervalMs?: number;
|
|
14
15
|
|
|
15
|
-
private subscriber?:
|
|
16
|
+
private subscriber?:
|
|
17
|
+
| grpcProgramAccountSubscriber<UserAccount>
|
|
18
|
+
| LaserstreamProgramAccountSubscriber<UserAccount>;
|
|
16
19
|
private resyncTimeoutId?: ReturnType<typeof setTimeout>;
|
|
17
20
|
|
|
18
21
|
private decoded?: boolean;
|
|
@@ -47,17 +50,32 @@ export class grpcSubscription {
|
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
if (this.grpcConfigs.client === 'lazer') {
|
|
54
|
+
this.subscriber =
|
|
55
|
+
await LaserstreamProgramAccountSubscriber.create<UserAccount>(
|
|
56
|
+
this.grpcConfigs,
|
|
57
|
+
'OrderSubscriber',
|
|
58
|
+
'User',
|
|
59
|
+
this.orderSubscriber.driftClient.program,
|
|
60
|
+
this.orderSubscriber.decodeFn,
|
|
61
|
+
{
|
|
62
|
+
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
63
|
+
},
|
|
64
|
+
this.resubOpts
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
67
|
+
this.subscriber = await grpcProgramAccountSubscriber.create<UserAccount>(
|
|
68
|
+
this.grpcConfigs,
|
|
69
|
+
'OrderSubscriber',
|
|
70
|
+
'User',
|
|
71
|
+
this.orderSubscriber.driftClient.program,
|
|
72
|
+
this.orderSubscriber.decodeFn,
|
|
73
|
+
{
|
|
74
|
+
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
75
|
+
},
|
|
76
|
+
this.resubOpts
|
|
77
|
+
);
|
|
78
|
+
}
|
|
61
79
|
|
|
62
80
|
await this.subscriber.subscribe(
|
|
63
81
|
(
|