Skip to content

Commit 0656f34

Browse files
committed
chore: add grpc client to order subscriber
1 parent 2791cb0 commit 0656f34

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

sdk/src/accounts/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export type GrpcConfigs = {
234234
* Defaults to false, will throw on connection loss.
235235
*/
236236
enableReconnect?: boolean;
237+
client?: 'yellowstone' | 'laser';
237238
};
238239

239240
export interface HighLeverageModeConfigAccountSubscriber {

sdk/src/orderSubscriber/grpcSubscription.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import { OrderSubscriber } from './OrderSubscriber';
55
import { GrpcConfigs, ResubOpts } from '../accounts/types';
66
import { UserAccount } from '../types';
77
import { getUserFilter, getNonIdleUserFilter } from '../memcmp';
8+
import { LaserstreamProgramAccountSubscriber } from '../accounts/laserProgramAccountSubscriber';
89

910
export class grpcSubscription {
1011
private orderSubscriber: OrderSubscriber;
1112
private skipInitialLoad: boolean;
1213
private resubOpts?: ResubOpts;
1314
private resyncIntervalMs?: number;
1415

15-
private subscriber?: grpcProgramAccountSubscriber<UserAccount>;
16+
private subscriber?:
17+
| grpcProgramAccountSubscriber<UserAccount>
18+
| LaserstreamProgramAccountSubscriber<UserAccount>;
1619
private resyncTimeoutId?: ReturnType<typeof setTimeout>;
1720

1821
private decoded?: boolean;
@@ -47,17 +50,32 @@ export class grpcSubscription {
4750
return;
4851
}
4952

50-
this.subscriber = await grpcProgramAccountSubscriber.create<UserAccount>(
51-
this.grpcConfigs,
52-
'OrderSubscriber',
53-
'User',
54-
this.orderSubscriber.driftClient.program,
55-
this.orderSubscriber.decodeFn,
56-
{
57-
filters: [getUserFilter(), getNonIdleUserFilter()],
58-
},
59-
this.resubOpts
60-
);
53+
if (this.grpcConfigs.client === 'laser') {
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+
}
6179

6280
await this.subscriber.subscribe(
6381
(

0 commit comments

Comments
 (0)