@drift-labs/sdk 2.96.0-beta.1 → 2.96.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/accounts/types.d.ts +0 -8
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketProgramAccountSubscriber.d.ts +1 -1
- package/lib/driftClient.js +14 -35
- package/lib/driftClientConfig.d.ts +0 -6
- package/lib/events/eventSubscriber.d.ts +7 -0
- package/lib/events/eventSubscriber.js +69 -32
- package/lib/events/eventsServerLogProvider.d.ts +21 -0
- package/lib/events/eventsServerLogProvider.js +121 -0
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +12 -5
- package/lib/events/types.js +5 -1
- package/lib/events/webSocketLogProvider.js +2 -2
- package/lib/orderSubscriber/OrderSubscriber.d.ts +1 -2
- package/lib/orderSubscriber/OrderSubscriber.js +4 -19
- package/lib/orderSubscriber/types.d.ts +0 -9
- package/lib/user.js +4 -11
- package/lib/userConfig.d.ts +1 -6
- package/lib/userMap/userMap.js +0 -14
- package/lib/userMap/userMapConfig.d.ts +0 -7
- package/lib/userStatsConfig.d.ts +0 -6
- package/package.json +1 -3
- package/src/accounts/types.ts +0 -9
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +3 -3
- package/src/accounts/webSocketProgramAccountSubscriber.ts +1 -1
- package/src/driftClient.ts +0 -28
- package/src/driftClientConfig.ts +0 -7
- package/src/events/eventSubscriber.ts +125 -54
- package/src/events/eventsServerLogProvider.ts +152 -0
- package/src/events/pollingLogProvider.ts +1 -1
- package/src/events/types.ts +29 -6
- package/src/events/webSocketLogProvider.ts +4 -4
- package/src/orderSubscriber/OrderSubscriber.ts +1 -15
- package/src/orderSubscriber/types.ts +0 -10
- package/src/user.ts +0 -11
- package/src/userConfig.ts +1 -7
- package/src/userMap/userMap.ts +1 -17
- package/src/userMap/userMapConfig.ts +0 -8
- package/src/userStatsConfig.ts +0 -7
- package/lib/accounts/grpcAccountSubscriber.d.ts +0 -16
- package/lib/accounts/grpcAccountSubscriber.js +0 -155
- package/lib/accounts/grpcDriftClientAccountSubscriber.d.ts +0 -13
- package/lib/accounts/grpcDriftClientAccountSubscriber.js +0 -96
- package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcInsuranceFundStakeAccountSubscriber.js +0 -30
- package/lib/accounts/grpcProgramAccountSubscriber.d.ts +0 -19
- package/lib/accounts/grpcProgramAccountSubscriber.js +0 -161
- package/lib/accounts/grpcUserAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcUserAccountSubscriber.js +0 -28
- package/lib/accounts/grpcUserStatsAccountSubscriber.d.ts +0 -10
- package/lib/accounts/grpcUserStatsAccountSubscriber.js +0 -28
- package/lib/orderSubscriber/grpcSubscription.d.ts +0 -25
- package/lib/orderSubscriber/grpcSubscription.js +0 -68
- package/lib/userMap/grpcSubscription.d.ts +0 -26
- package/lib/userMap/grpcSubscription.js +0 -42
- package/src/accounts/grpcAccountSubscriber.ts +0 -158
- package/src/accounts/grpcDriftClientAccountSubscriber.ts +0 -196
- package/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +0 -62
- package/src/accounts/grpcProgramAccountSubscriber.ts +0 -181
- package/src/accounts/grpcUserAccountSubscriber.ts +0 -48
- package/src/accounts/grpcUserStatsAccountSubscriber.ts +0 -51
- package/src/orderSubscriber/grpcSubscription.ts +0 -126
- package/src/userMap/grpcSubscription.ts +0 -83
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Commitment, Context, PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
3
|
-
import { grpcProgramAccountSubscriber } from '../accounts/grpcProgramAccountSubscriber';
|
|
4
|
-
import { OrderSubscriber } from './OrderSubscriber';
|
|
5
|
-
import { GrpcConfigs, ResubOpts } from '../accounts/types';
|
|
6
|
-
import { UserAccount } from '../types';
|
|
7
|
-
import { getNonIdleUserFilter, getUserFilter } from '../memcmp';
|
|
8
|
-
|
|
9
|
-
export class grpcSubscription {
|
|
10
|
-
private orderSubscriber: OrderSubscriber;
|
|
11
|
-
private commitment: Commitment;
|
|
12
|
-
private skipInitialLoad: boolean;
|
|
13
|
-
private resubOpts?: ResubOpts;
|
|
14
|
-
private resyncIntervalMs?: number;
|
|
15
|
-
|
|
16
|
-
private subscriber?: grpcProgramAccountSubscriber<UserAccount>;
|
|
17
|
-
private resyncTimeoutId?: NodeJS.Timeout;
|
|
18
|
-
|
|
19
|
-
private decoded?: boolean;
|
|
20
|
-
|
|
21
|
-
private grpcConfigs: GrpcConfigs;
|
|
22
|
-
|
|
23
|
-
constructor({
|
|
24
|
-
grpcConfigs,
|
|
25
|
-
orderSubscriber,
|
|
26
|
-
commitment,
|
|
27
|
-
skipInitialLoad = false,
|
|
28
|
-
resubOpts,
|
|
29
|
-
resyncIntervalMs,
|
|
30
|
-
decoded = true,
|
|
31
|
-
}: {
|
|
32
|
-
grpcConfigs: GrpcConfigs;
|
|
33
|
-
orderSubscriber: OrderSubscriber;
|
|
34
|
-
commitment: Commitment;
|
|
35
|
-
skipInitialLoad?: boolean;
|
|
36
|
-
resubOpts?: ResubOpts;
|
|
37
|
-
resyncIntervalMs?: number;
|
|
38
|
-
decoded?: boolean;
|
|
39
|
-
}) {
|
|
40
|
-
this.orderSubscriber = orderSubscriber;
|
|
41
|
-
this.commitment = commitment;
|
|
42
|
-
this.skipInitialLoad = skipInitialLoad;
|
|
43
|
-
this.resubOpts = resubOpts;
|
|
44
|
-
this.resyncIntervalMs = resyncIntervalMs;
|
|
45
|
-
this.decoded = decoded;
|
|
46
|
-
this.grpcConfigs = grpcConfigs;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public async subscribe(): Promise<void> {
|
|
50
|
-
if (this.subscriber) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.subscriber = new grpcProgramAccountSubscriber<UserAccount>(
|
|
55
|
-
this.grpcConfigs,
|
|
56
|
-
'OrderSubscriber',
|
|
57
|
-
'User',
|
|
58
|
-
this.orderSubscriber.driftClient.program,
|
|
59
|
-
this.orderSubscriber.decodeFn,
|
|
60
|
-
{
|
|
61
|
-
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
62
|
-
commitment: this.commitment,
|
|
63
|
-
},
|
|
64
|
-
this.resubOpts
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
await this.subscriber.subscribe(
|
|
68
|
-
(
|
|
69
|
-
accountId: PublicKey,
|
|
70
|
-
account: UserAccount,
|
|
71
|
-
context: Context,
|
|
72
|
-
buffer: Buffer
|
|
73
|
-
) => {
|
|
74
|
-
const userKey = accountId.toBase58();
|
|
75
|
-
if (this.decoded ?? true) {
|
|
76
|
-
this.orderSubscriber.tryUpdateUserAccount(
|
|
77
|
-
userKey,
|
|
78
|
-
'decoded',
|
|
79
|
-
account,
|
|
80
|
-
context.slot
|
|
81
|
-
);
|
|
82
|
-
} else {
|
|
83
|
-
this.orderSubscriber.tryUpdateUserAccount(
|
|
84
|
-
userKey,
|
|
85
|
-
'buffer',
|
|
86
|
-
buffer,
|
|
87
|
-
context.slot
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
if (!this.skipInitialLoad) {
|
|
94
|
-
await this.orderSubscriber.fetch();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (this.resyncIntervalMs) {
|
|
98
|
-
const recursiveResync = () => {
|
|
99
|
-
this.resyncTimeoutId = setTimeout(() => {
|
|
100
|
-
this.orderSubscriber
|
|
101
|
-
.fetch()
|
|
102
|
-
.catch((e) => {
|
|
103
|
-
console.error('Failed to resync in OrderSubscriber');
|
|
104
|
-
console.log(e);
|
|
105
|
-
})
|
|
106
|
-
.finally(() => {
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
|
-
if (!this.resyncTimeoutId) return;
|
|
109
|
-
recursiveResync();
|
|
110
|
-
});
|
|
111
|
-
}, this.resyncIntervalMs);
|
|
112
|
-
};
|
|
113
|
-
recursiveResync();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public async unsubscribe(): Promise<void> {
|
|
118
|
-
if (!this.subscriber) return;
|
|
119
|
-
await this.subscriber.unsubscribe();
|
|
120
|
-
this.subscriber = undefined;
|
|
121
|
-
if (this.resyncTimeoutId !== undefined) {
|
|
122
|
-
clearTimeout(this.resyncTimeoutId);
|
|
123
|
-
this.resyncTimeoutId = undefined;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { UserMap } from './userMap';
|
|
2
|
-
import { getNonIdleUserFilter, getUserFilter } from '../memcmp';
|
|
3
|
-
import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramAccountSubscriber';
|
|
4
|
-
import { UserAccount } from '../types';
|
|
5
|
-
import { Commitment, Context, PublicKey } from '@solana/web3.js';
|
|
6
|
-
import { GrpcConfigs, ResubOpts } from '../accounts/types';
|
|
7
|
-
import { grpcProgramAccountSubscriber } from '../accounts/grpcProgramAccountSubscriber';
|
|
8
|
-
|
|
9
|
-
export class grpcSubscription {
|
|
10
|
-
private configs: GrpcConfigs;
|
|
11
|
-
private userMap: UserMap;
|
|
12
|
-
private commitment: Commitment;
|
|
13
|
-
private skipInitialLoad: boolean;
|
|
14
|
-
private resubOpts?: ResubOpts;
|
|
15
|
-
private includeIdle?: boolean;
|
|
16
|
-
private decodeFn: (name: string, data: Buffer) => UserAccount;
|
|
17
|
-
|
|
18
|
-
private subscriber: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
19
|
-
|
|
20
|
-
constructor({
|
|
21
|
-
configs,
|
|
22
|
-
userMap,
|
|
23
|
-
commitment,
|
|
24
|
-
skipInitialLoad = false,
|
|
25
|
-
resubOpts,
|
|
26
|
-
includeIdle = false,
|
|
27
|
-
decodeFn,
|
|
28
|
-
}: {
|
|
29
|
-
configs: GrpcConfigs;
|
|
30
|
-
userMap: UserMap;
|
|
31
|
-
commitment: Commitment;
|
|
32
|
-
skipInitialLoad?: boolean;
|
|
33
|
-
resubOpts?: ResubOpts;
|
|
34
|
-
includeIdle?: boolean;
|
|
35
|
-
decodeFn: (name: string, data: Buffer) => UserAccount;
|
|
36
|
-
}) {
|
|
37
|
-
this.userMap = userMap;
|
|
38
|
-
this.commitment = commitment;
|
|
39
|
-
this.skipInitialLoad = skipInitialLoad;
|
|
40
|
-
this.resubOpts = resubOpts;
|
|
41
|
-
this.includeIdle = includeIdle || false;
|
|
42
|
-
this.decodeFn = decodeFn;
|
|
43
|
-
this.configs = configs;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public async subscribe(): Promise<void> {
|
|
47
|
-
if (!this.subscriber) {
|
|
48
|
-
const filters = [getUserFilter()];
|
|
49
|
-
if (!this.includeIdle) {
|
|
50
|
-
filters.push(getNonIdleUserFilter());
|
|
51
|
-
}
|
|
52
|
-
this.subscriber = new grpcProgramAccountSubscriber<UserAccount>(
|
|
53
|
-
this.configs,
|
|
54
|
-
'UserMap',
|
|
55
|
-
'User',
|
|
56
|
-
this.userMap.driftClient.program,
|
|
57
|
-
this.decodeFn,
|
|
58
|
-
{
|
|
59
|
-
filters,
|
|
60
|
-
commitment: this.commitment,
|
|
61
|
-
},
|
|
62
|
-
this.resubOpts
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
await this.subscriber.subscribe(
|
|
67
|
-
(accountId: PublicKey, account: UserAccount, context: Context) => {
|
|
68
|
-
const userKey = accountId.toBase58();
|
|
69
|
-
this.userMap.updateUserAccount(userKey, account, context.slot);
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
if (!this.skipInitialLoad) {
|
|
74
|
-
await this.userMap.sync();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public async unsubscribe(): Promise<void> {
|
|
79
|
-
if (!this.subscriber) return;
|
|
80
|
-
await this.subscriber.unsubscribe();
|
|
81
|
-
this.subscriber = undefined;
|
|
82
|
-
}
|
|
83
|
-
}
|