@velocity-exchange/sdk 0.0.2 → 0.0.5
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/CHANGELOG.md +15 -0
- package/README.md +5 -6
- package/bunfig.toml +3 -0
- package/lib/browser/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/browser/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/browser/auctionSubscriber/types.d.ts +4 -2
- package/lib/browser/config.d.ts +3 -8
- package/lib/browser/config.js +14 -22
- package/lib/browser/constituentMap/constituentMap.d.ts +4 -2
- package/lib/browser/constituentMap/constituentMap.js +14 -10
- package/lib/browser/core/VelocityCore.d.ts +4 -0
- package/lib/browser/core/VelocityCore.js +3 -1
- package/lib/browser/decode/user.js +5 -5
- package/lib/browser/dlob/DLOB.js +1 -1
- package/lib/browser/dlob/DLOBNode.js +1 -2
- package/lib/browser/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/browser/dlob/DLOBSubscriber.js +19 -10
- package/lib/browser/dlob/types.d.ts +3 -1
- package/lib/browser/idl/drift.d.ts +59 -6
- package/lib/browser/idl/drift.json +6049 -806
- package/lib/browser/math/auction.d.ts +1 -1
- package/lib/browser/math/auction.js +2 -9
- package/lib/browser/math/orders.js +3 -3
- package/lib/browser/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/browser/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/browser/orderSubscriber/types.d.ts +3 -1
- package/lib/browser/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/browser/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/browser/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/browser/priorityFee/types.d.ts +9 -5
- package/lib/browser/priorityFee/types.js +1 -1
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/browser/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/browser/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/browser/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/browser/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/browser/swift/swiftOrderSubscriber.js +19 -11
- package/lib/browser/types.d.ts +2 -2
- package/lib/browser/user.d.ts +3 -1
- package/lib/browser/user.js +93 -86
- package/lib/browser/userConfig.d.ts +4 -2
- package/lib/browser/userMap/referrerMap.d.ts +5 -3
- package/lib/browser/userMap/referrerMap.js +18 -14
- package/lib/browser/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/browser/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/browser/userMap/userMap.d.ts +3 -1
- package/lib/browser/userMap/userMap.js +24 -19
- package/lib/browser/userMap/userMapConfig.d.ts +4 -2
- package/lib/browser/userMap/userStatsMap.d.ts +5 -3
- package/lib/browser/userMap/userStatsMap.js +15 -11
- package/lib/browser/userStats.d.ts +3 -1
- package/lib/browser/userStats.js +21 -15
- package/lib/browser/userStatsConfig.d.ts +4 -2
- package/lib/browser/util/deprecatedAlias.d.ts +26 -0
- package/lib/browser/util/deprecatedAlias.js +10 -0
- package/lib/browser/velocityClient.d.ts +6 -6
- package/lib/browser/velocityClient.js +6 -6
- package/lib/browser/velocityClientConfig.d.ts +7 -4
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriber.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriber.js +9 -4
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts +4 -2
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.d.ts.map +1 -1
- package/lib/node/auctionSubscriber/auctionSubscriberGrpc.js +9 -4
- package/lib/node/auctionSubscriber/types.d.ts +4 -2
- package/lib/node/auctionSubscriber/types.d.ts.map +1 -1
- package/lib/node/config.d.ts +3 -8
- package/lib/node/config.d.ts.map +1 -1
- package/lib/node/config.js +14 -22
- package/lib/node/constituentMap/constituentMap.d.ts +4 -2
- package/lib/node/constituentMap/constituentMap.d.ts.map +1 -1
- package/lib/node/constituentMap/constituentMap.js +14 -10
- package/lib/node/core/VelocityCore.d.ts +4 -0
- package/lib/node/core/VelocityCore.d.ts.map +1 -1
- package/lib/node/core/VelocityCore.js +3 -1
- package/lib/node/decode/user.js +5 -5
- package/lib/node/dlob/DLOB.js +1 -1
- package/lib/node/dlob/DLOBNode.js +1 -2
- package/lib/node/dlob/DLOBSubscriber.d.ts +3 -1
- package/lib/node/dlob/DLOBSubscriber.d.ts.map +1 -1
- package/lib/node/dlob/DLOBSubscriber.js +19 -10
- package/lib/node/dlob/types.d.ts +3 -1
- package/lib/node/dlob/types.d.ts.map +1 -1
- package/lib/node/idl/drift.d.ts +59 -6
- package/lib/node/idl/drift.d.ts.map +1 -1
- package/lib/node/idl/drift.json +6049 -806
- package/lib/node/math/auction.d.ts +1 -1
- package/lib/node/math/auction.d.ts.map +1 -1
- package/lib/node/math/auction.js +2 -9
- package/lib/node/math/orders.d.ts.map +1 -1
- package/lib/node/math/orders.js +3 -3
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts +3 -1
- package/lib/node/orderSubscriber/OrderSubscriber.d.ts.map +1 -1
- package/lib/node/orderSubscriber/OrderSubscriber.js +19 -11
- package/lib/node/orderSubscriber/types.d.ts +3 -1
- package/lib/node/orderSubscriber/types.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts +4 -2
- package/lib/node/priorityFee/priorityFeeSubscriber.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriber.js +15 -11
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts +11 -9
- package/lib/node/priorityFee/priorityFeeSubscriberMap.d.ts.map +1 -1
- package/lib/node/priorityFee/priorityFeeSubscriberMap.js +18 -18
- package/lib/node/priorityFee/types.d.ts +9 -5
- package/lib/node/priorityFee/types.d.ts.map +1 -1
- package/lib/node/priorityFee/types.js +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts +3 -12
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/grpcSignedMsgUserAccountSubscriber.js +3 -9
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts +11 -8
- package/lib/node/swift/signedMsgUserAccountSubscriber.d.ts.map +1 -1
- package/lib/node/swift/signedMsgUserAccountSubscriber.js +10 -5
- package/lib/node/swift/swiftOrderSubscriber.d.ts +7 -4
- package/lib/node/swift/swiftOrderSubscriber.d.ts.map +1 -1
- package/lib/node/swift/swiftOrderSubscriber.js +19 -11
- package/lib/node/types.d.ts +2 -2
- package/lib/node/types.d.ts.map +1 -1
- package/lib/node/user.d.ts +3 -1
- package/lib/node/user.d.ts.map +1 -1
- package/lib/node/user.js +93 -86
- package/lib/node/userConfig.d.ts +4 -2
- package/lib/node/userConfig.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.d.ts +5 -3
- package/lib/node/userMap/referrerMap.d.ts.map +1 -1
- package/lib/node/userMap/referrerMap.js +18 -14
- package/lib/node/userMap/revenueShareEscrowMap.d.ts +5 -3
- package/lib/node/userMap/revenueShareEscrowMap.d.ts.map +1 -1
- package/lib/node/userMap/revenueShareEscrowMap.js +18 -14
- package/lib/node/userMap/userMap.d.ts +3 -1
- package/lib/node/userMap/userMap.d.ts.map +1 -1
- package/lib/node/userMap/userMap.js +24 -19
- package/lib/node/userMap/userMapConfig.d.ts +4 -2
- package/lib/node/userMap/userMapConfig.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.d.ts +5 -3
- package/lib/node/userMap/userStatsMap.d.ts.map +1 -1
- package/lib/node/userMap/userStatsMap.js +15 -11
- package/lib/node/userStats.d.ts +3 -1
- package/lib/node/userStats.d.ts.map +1 -1
- package/lib/node/userStats.js +21 -15
- package/lib/node/userStatsConfig.d.ts +4 -2
- package/lib/node/userStatsConfig.d.ts.map +1 -1
- package/lib/node/util/deprecatedAlias.d.ts +27 -0
- package/lib/node/util/deprecatedAlias.d.ts.map +1 -0
- package/lib/node/util/deprecatedAlias.js +10 -0
- package/lib/node/velocityClient.d.ts +6 -6
- package/lib/node/velocityClient.d.ts.map +1 -1
- package/lib/node/velocityClient.js +6 -6
- package/lib/node/velocityClientConfig.d.ts +7 -4
- package/lib/node/velocityClientConfig.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auctionSubscriber/auctionSubscriber.ts +12 -6
- package/src/auctionSubscriber/auctionSubscriberGrpc.ts +12 -6
- package/src/auctionSubscriber/types.ts +5 -2
- package/src/config.ts +38 -27
- package/src/constituentMap/constituentMap.ts +17 -9
- package/src/core/VelocityCore.ts +6 -0
- package/src/decode/user.ts +5 -5
- package/src/dlob/DLOB.ts +1 -1
- package/src/dlob/DLOBNode.ts +1 -1
- package/src/dlob/DLOBSubscriber.ts +21 -11
- package/src/dlob/types.ts +3 -1
- package/src/idl/drift.json +23940 -18697
- package/src/idl/drift.ts +59 -6
- package/src/math/auction.ts +3 -10
- package/src/math/orders.ts +3 -6
- package/src/orderSubscriber/OrderSubscriber.ts +17 -7
- package/src/orderSubscriber/types.ts +3 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +13 -9
- package/src/priorityFee/priorityFeeSubscriberMap.ts +23 -25
- package/src/priorityFee/types.ts +19 -9
- package/src/swift/grpcSignedMsgUserAccountSubscriber.ts +10 -23
- package/src/swift/signedMsgUserAccountSubscriber.ts +22 -14
- package/src/swift/swiftOrderSubscriber.ts +24 -16
- package/src/types.ts +2 -2
- package/src/user.ts +93 -82
- package/src/userConfig.ts +5 -2
- package/src/userMap/referrerMap.ts +19 -15
- package/src/userMap/revenueShareEscrowMap.ts +20 -16
- package/src/userMap/userMap.ts +20 -15
- package/src/userMap/userMapConfig.ts +6 -3
- package/src/userMap/userStatsMap.ts +19 -15
- package/src/userStats.ts +13 -7
- package/src/userStatsConfig.ts +5 -2
- package/src/util/deprecatedAlias.ts +21 -0
- package/src/velocityClient.ts +12 -12
- package/src/velocityClientConfig.ts +27 -42
- package/tests/auctions/test.ts +4 -4
- package/tests/decode/test.ts +1 -1
- package/tests/dlob/test.ts +5 -5
- package/tests/user/helpers.ts +1 -1
|
@@ -28,7 +28,11 @@ export class ReferrerMap {
|
|
|
28
28
|
* Will be undefined if the referrer is not in the map yet.
|
|
29
29
|
*/
|
|
30
30
|
private referrerReferrerInfoMap = new Map<string, ReferrerInfo>();
|
|
31
|
-
private
|
|
31
|
+
private velocityClient: VelocityClient;
|
|
32
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
33
|
+
private get driftClient(): VelocityClient {
|
|
34
|
+
return this.velocityClient;
|
|
35
|
+
}
|
|
32
36
|
private parallelSync: boolean;
|
|
33
37
|
|
|
34
38
|
private fetchPromise?: Promise<void>;
|
|
@@ -37,10 +41,10 @@ export class ReferrerMap {
|
|
|
37
41
|
/**
|
|
38
42
|
* Creates a new UserStatsMap instance.
|
|
39
43
|
*
|
|
40
|
-
* @param {VelocityClient}
|
|
44
|
+
* @param {VelocityClient} velocityClient - The VelocityClient instance.
|
|
41
45
|
*/
|
|
42
|
-
constructor(
|
|
43
|
-
this.
|
|
46
|
+
constructor(velocityClient: VelocityClient, parallelSync?: boolean) {
|
|
47
|
+
this.velocityClient = velocityClient;
|
|
44
48
|
this.parallelSync = parallelSync !== undefined ? parallelSync : true;
|
|
45
49
|
}
|
|
46
50
|
|
|
@@ -52,7 +56,7 @@ export class ReferrerMap {
|
|
|
52
56
|
return;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
await this.
|
|
59
|
+
await this.velocityClient.subscribe();
|
|
56
60
|
await this.sync();
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -69,11 +73,11 @@ export class ReferrerMap {
|
|
|
69
73
|
this.authorityReferrerMap.set(authority, referrer);
|
|
70
74
|
} else if (referrer === undefined) {
|
|
71
75
|
const userStatsAccountPublicKey = getUserStatsAccountPublicKey(
|
|
72
|
-
this.
|
|
76
|
+
this.velocityClient.program.programId,
|
|
73
77
|
new PublicKey(authority)
|
|
74
78
|
);
|
|
75
79
|
const buffer = (
|
|
76
|
-
await this.
|
|
80
|
+
await this.velocityClient.connection.getAccountInfo(
|
|
77
81
|
userStatsAccountPublicKey,
|
|
78
82
|
'processed'
|
|
79
83
|
)
|
|
@@ -118,12 +122,12 @@ export class ReferrerMap {
|
|
|
118
122
|
const referrerKey = new PublicKey(referrer);
|
|
119
123
|
const referrerInfo = {
|
|
120
124
|
referrer: getUserAccountPublicKeySync(
|
|
121
|
-
this.
|
|
125
|
+
this.velocityClient.program.programId,
|
|
122
126
|
referrerKey,
|
|
123
127
|
0
|
|
124
128
|
),
|
|
125
129
|
referrerStats: getUserStatsAccountPublicKey(
|
|
126
|
-
this.
|
|
130
|
+
this.velocityClient.program.programId,
|
|
127
131
|
referrerKey
|
|
128
132
|
),
|
|
129
133
|
};
|
|
@@ -171,9 +175,9 @@ export class ReferrerMap {
|
|
|
171
175
|
|
|
172
176
|
public async syncAll(): Promise<void> {
|
|
173
177
|
const rpcRequestArgs = [
|
|
174
|
-
this.
|
|
178
|
+
this.velocityClient.program.programId.toBase58(),
|
|
175
179
|
{
|
|
176
|
-
commitment: this.
|
|
180
|
+
commitment: this.velocityClient.opts.commitment,
|
|
177
181
|
filters: [getUserStatsFilter()],
|
|
178
182
|
encoding: 'base64',
|
|
179
183
|
dataSlice: {
|
|
@@ -186,7 +190,7 @@ export class ReferrerMap {
|
|
|
186
190
|
|
|
187
191
|
const rpcJSONResponse: any =
|
|
188
192
|
// @ts-ignore
|
|
189
|
-
await this.
|
|
193
|
+
await this.velocityClient.connection._rpcRequest(
|
|
190
194
|
'getProgramAccounts',
|
|
191
195
|
rpcRequestArgs
|
|
192
196
|
);
|
|
@@ -211,9 +215,9 @@ export class ReferrerMap {
|
|
|
211
215
|
|
|
212
216
|
async syncReferrer(referrerFilter: MemcmpFilter): Promise<void> {
|
|
213
217
|
const rpcRequestArgs = [
|
|
214
|
-
this.
|
|
218
|
+
this.velocityClient.program.programId.toBase58(),
|
|
215
219
|
{
|
|
216
|
-
commitment: this.
|
|
220
|
+
commitment: this.velocityClient.opts.commitment,
|
|
217
221
|
filters: [getUserStatsFilter(), referrerFilter],
|
|
218
222
|
encoding: 'base64',
|
|
219
223
|
dataSlice: {
|
|
@@ -226,7 +230,7 @@ export class ReferrerMap {
|
|
|
226
230
|
|
|
227
231
|
const rpcJSONResponse: any =
|
|
228
232
|
// @ts-ignore
|
|
229
|
-
await this.
|
|
233
|
+
await this.velocityClient.connection._rpcRequest(
|
|
230
234
|
'getProgramAccounts',
|
|
231
235
|
rpcRequestArgs
|
|
232
236
|
);
|
|
@@ -9,7 +9,11 @@ export class RevenueShareEscrowMap {
|
|
|
9
9
|
* map from authority pubkey to RevenueShareEscrow account data.
|
|
10
10
|
*/
|
|
11
11
|
private authorityEscrowMap = new Map<string, RevenueShareEscrowAccount>();
|
|
12
|
-
private
|
|
12
|
+
private velocityClient: VelocityClient;
|
|
13
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
14
|
+
private get driftClient(): VelocityClient {
|
|
15
|
+
return this.velocityClient;
|
|
16
|
+
}
|
|
13
17
|
private parallelSync: boolean;
|
|
14
18
|
|
|
15
19
|
private fetchPromise?: Promise<void>;
|
|
@@ -18,11 +22,11 @@ export class RevenueShareEscrowMap {
|
|
|
18
22
|
/**
|
|
19
23
|
* Creates a new RevenueShareEscrowMap instance.
|
|
20
24
|
*
|
|
21
|
-
* @param {VelocityClient}
|
|
25
|
+
* @param {VelocityClient} velocityClient - The VelocityClient instance.
|
|
22
26
|
* @param {boolean} parallelSync - Whether to sync accounts in parallel.
|
|
23
27
|
*/
|
|
24
|
-
constructor(
|
|
25
|
-
this.
|
|
28
|
+
constructor(velocityClient: VelocityClient, parallelSync?: boolean) {
|
|
29
|
+
this.velocityClient = velocityClient;
|
|
26
30
|
this.parallelSync = parallelSync !== undefined ? parallelSync : true;
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -34,7 +38,7 @@ export class RevenueShareEscrowMap {
|
|
|
34
38
|
return;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
await this.
|
|
41
|
+
await this.velocityClient.subscribe();
|
|
38
42
|
await this.sync();
|
|
39
43
|
}
|
|
40
44
|
|
|
@@ -65,19 +69,19 @@ export class RevenueShareEscrowMap {
|
|
|
65
69
|
|
|
66
70
|
public async addRevenueShareEscrow(authority: string) {
|
|
67
71
|
const escrowAccountPublicKey = getRevenueShareEscrowAccountPublicKey(
|
|
68
|
-
this.
|
|
72
|
+
this.velocityClient.program.programId,
|
|
69
73
|
new PublicKey(authority)
|
|
70
74
|
);
|
|
71
75
|
|
|
72
76
|
try {
|
|
73
|
-
const accountInfo = await this.
|
|
77
|
+
const accountInfo = await this.velocityClient.connection.getAccountInfo(
|
|
74
78
|
escrowAccountPublicKey,
|
|
75
79
|
'processed'
|
|
76
80
|
);
|
|
77
81
|
|
|
78
82
|
if (accountInfo && accountInfo.data) {
|
|
79
83
|
const escrow = (
|
|
80
|
-
this.
|
|
84
|
+
this.velocityClient.program.account as any
|
|
81
85
|
).revenueShareEscrow.coder.accounts.decode(
|
|
82
86
|
'revenueShareEscrow',
|
|
83
87
|
accountInfo.data
|
|
@@ -123,15 +127,15 @@ export class RevenueShareEscrowMap {
|
|
|
123
127
|
return this.fetchPromise;
|
|
124
128
|
}
|
|
125
129
|
for (const authority of this.authorityEscrowMap.keys()) {
|
|
126
|
-
const accountInfo = await this.
|
|
130
|
+
const accountInfo = await this.velocityClient.connection.getAccountInfo(
|
|
127
131
|
getRevenueShareEscrowAccountPublicKey(
|
|
128
|
-
this.
|
|
132
|
+
this.velocityClient.program.programId,
|
|
129
133
|
new PublicKey(authority)
|
|
130
134
|
),
|
|
131
135
|
'confirmed'
|
|
132
136
|
);
|
|
133
137
|
const escrowNew = (
|
|
134
|
-
this.
|
|
138
|
+
this.velocityClient.program.account as any
|
|
135
139
|
).revenueShareEscrow.coder.accounts.decode(
|
|
136
140
|
'revenueShareEscrow',
|
|
137
141
|
accountInfo.data
|
|
@@ -142,9 +146,9 @@ export class RevenueShareEscrowMap {
|
|
|
142
146
|
|
|
143
147
|
public async syncAll(): Promise<void> {
|
|
144
148
|
const rpcRequestArgs = [
|
|
145
|
-
this.
|
|
149
|
+
this.velocityClient.program.programId.toBase58(),
|
|
146
150
|
{
|
|
147
|
-
commitment: this.
|
|
151
|
+
commitment: this.velocityClient.opts.commitment,
|
|
148
152
|
filters: [getRevenueShareEscrowFilter()],
|
|
149
153
|
encoding: 'base64',
|
|
150
154
|
withContext: true,
|
|
@@ -153,7 +157,7 @@ export class RevenueShareEscrowMap {
|
|
|
153
157
|
|
|
154
158
|
const rpcJSONResponse: any =
|
|
155
159
|
// @ts-ignore
|
|
156
|
-
await this.
|
|
160
|
+
await this.velocityClient.connection._rpcRequest(
|
|
157
161
|
'getProgramAccounts',
|
|
158
162
|
rpcRequestArgs
|
|
159
163
|
);
|
|
@@ -182,7 +186,7 @@ export class RevenueShareEscrowMap {
|
|
|
182
186
|
);
|
|
183
187
|
|
|
184
188
|
const escrow = (
|
|
185
|
-
this.
|
|
189
|
+
this.velocityClient.program.account as any
|
|
186
190
|
).revenueShareEscrow.coder.accounts.decode(
|
|
187
191
|
'revenueShareEscrow',
|
|
188
192
|
buffer
|
|
@@ -209,7 +213,7 @@ export class RevenueShareEscrowMap {
|
|
|
209
213
|
);
|
|
210
214
|
|
|
211
215
|
const escrow = (
|
|
212
|
-
this.
|
|
216
|
+
this.velocityClient.program.account as any
|
|
213
217
|
).revenueShareEscrow.coder.accounts.decode(
|
|
214
218
|
'revenueShareEscrow',
|
|
215
219
|
buffer
|
package/src/userMap/userMap.ts
CHANGED
|
@@ -77,7 +77,11 @@ export interface UserMapInterface {
|
|
|
77
77
|
|
|
78
78
|
export class UserMap implements UserMapInterface {
|
|
79
79
|
private userMap = new Map<string, DataAndSlot<User>>();
|
|
80
|
-
|
|
80
|
+
velocityClient: VelocityClient;
|
|
81
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
82
|
+
public get driftClient(): VelocityClient {
|
|
83
|
+
return this.velocityClient;
|
|
84
|
+
}
|
|
81
85
|
eventEmitter: StrictEventEmitter<EventEmitter, UserEvents>;
|
|
82
86
|
private connection: Connection;
|
|
83
87
|
private commitment: Commitment;
|
|
@@ -109,18 +113,19 @@ export class UserMap implements UserMapInterface {
|
|
|
109
113
|
* Constructs a new UserMap instance.
|
|
110
114
|
*/
|
|
111
115
|
constructor(config: UserMapConfig) {
|
|
112
|
-
|
|
116
|
+
// Type-system guarantees at least one of the two is supplied.
|
|
117
|
+
this.velocityClient = (config.velocityClient ?? config.driftClient)!;
|
|
113
118
|
if (config.connection) {
|
|
114
119
|
this.connection = config.connection;
|
|
115
120
|
} else {
|
|
116
|
-
this.connection = this.
|
|
121
|
+
this.connection = this.velocityClient.connection;
|
|
117
122
|
}
|
|
118
123
|
this.commitment =
|
|
119
124
|
config.subscriptionConfig.type === 'websocket' ||
|
|
120
125
|
config.subscriptionConfig.type === 'polling'
|
|
121
126
|
? config.subscriptionConfig.commitment ??
|
|
122
|
-
this.
|
|
123
|
-
: this.
|
|
127
|
+
this.velocityClient.opts.commitment
|
|
128
|
+
: this.velocityClient.opts.commitment;
|
|
124
129
|
this.includeIdle = config.includeIdle ?? false;
|
|
125
130
|
this.filterByPoolId = config.filterByPoolId;
|
|
126
131
|
this.additionalFilters = config.additionalFilters;
|
|
@@ -132,9 +137,9 @@ export class UserMap implements UserMapInterface {
|
|
|
132
137
|
decodeFn = (name, buffer) => decodeUser(buffer);
|
|
133
138
|
} else {
|
|
134
139
|
decodeFn = (
|
|
135
|
-
this.
|
|
140
|
+
this.velocityClient.program.account as any
|
|
136
141
|
).user.coder.accounts.decodeUnchecked.bind(
|
|
137
|
-
(this.
|
|
142
|
+
(this.velocityClient.program.account as any).user.coder.accounts
|
|
138
143
|
);
|
|
139
144
|
}
|
|
140
145
|
this.decode = decodeFn;
|
|
@@ -183,11 +188,11 @@ export class UserMap implements UserMapInterface {
|
|
|
183
188
|
return;
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
await this.
|
|
191
|
+
await this.velocityClient.subscribe();
|
|
187
192
|
this.lastNumberOfSubAccounts =
|
|
188
|
-
this.
|
|
193
|
+
this.velocityClient.getStateAccount().numberOfSubAccounts;
|
|
189
194
|
if (!this.disableSyncOnTotalAccountsChange) {
|
|
190
|
-
this.
|
|
195
|
+
this.velocityClient.eventEmitter.on(
|
|
191
196
|
'stateAccountUpdate',
|
|
192
197
|
this.stateAccountUpdateCallback
|
|
193
198
|
);
|
|
@@ -203,13 +208,13 @@ export class UserMap implements UserMapInterface {
|
|
|
203
208
|
accountSubscription?: UserSubscriptionConfig
|
|
204
209
|
) {
|
|
205
210
|
const user = new User({
|
|
206
|
-
|
|
211
|
+
velocityClient: this.velocityClient,
|
|
207
212
|
userAccountPublicKey,
|
|
208
213
|
accountSubscription: accountSubscription ?? {
|
|
209
214
|
type: 'custom',
|
|
210
215
|
// OneShotUserAccountSubscriber used here so we don't load up the RPC with AccountSubscribes
|
|
211
216
|
userAccountSubscriber: new OneShotUserAccountSubscriber(
|
|
212
|
-
this.
|
|
217
|
+
this.velocityClient.program,
|
|
213
218
|
userAccountPublicKey,
|
|
214
219
|
userAccount,
|
|
215
220
|
slot,
|
|
@@ -428,7 +433,7 @@ export class UserMap implements UserMapInterface {
|
|
|
428
433
|
|
|
429
434
|
try {
|
|
430
435
|
const rpcRequestArgs = [
|
|
431
|
-
this.
|
|
436
|
+
this.velocityClient.program.programId.toBase58(),
|
|
432
437
|
{
|
|
433
438
|
commitment: this.commitment,
|
|
434
439
|
filters: this.getFilters(),
|
|
@@ -526,7 +531,7 @@ export class UserMap implements UserMapInterface {
|
|
|
526
531
|
|
|
527
532
|
try {
|
|
528
533
|
const accountsPrefetch = await this.connection.getProgramAccounts(
|
|
529
|
-
this.
|
|
534
|
+
this.velocityClient.program.programId,
|
|
530
535
|
{
|
|
531
536
|
dataSlice: { offset: 0, length: 0 },
|
|
532
537
|
filters: this.getFilters(),
|
|
@@ -642,7 +647,7 @@ export class UserMap implements UserMapInterface {
|
|
|
642
647
|
|
|
643
648
|
if (this.lastNumberOfSubAccounts) {
|
|
644
649
|
if (!this.disableSyncOnTotalAccountsChange) {
|
|
645
|
-
this.
|
|
650
|
+
this.velocityClient.eventEmitter.removeListener(
|
|
646
651
|
'stateAccountUpdate',
|
|
647
652
|
this.stateAccountUpdateCallback
|
|
648
653
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Commitment, Connection, MemcmpFilter } from '@solana/web3.js';
|
|
2
2
|
import { VelocityClient } from '../velocityClient';
|
|
3
3
|
import { GrpcConfigs } from '../accounts/types';
|
|
4
|
+
import { AtLeastOne } from '../util/deprecatedAlias';
|
|
4
5
|
|
|
5
6
|
// passed into UserMap.getUniqueAuthorities to filter users
|
|
6
7
|
export type UserAccountFilterCriteria = {
|
|
@@ -18,9 +19,8 @@ export type SyncConfig =
|
|
|
18
19
|
concurrencyLimit?: number;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// connection object to use specifically for the UserMap. If undefined, will use the driftClient's connection
|
|
22
|
+
type UserMapConfigBase = {
|
|
23
|
+
// connection object to use specifically for the UserMap. If undefined, will use the velocityClient's connection
|
|
24
24
|
connection?: Connection;
|
|
25
25
|
subscriptionConfig:
|
|
26
26
|
| {
|
|
@@ -64,3 +64,6 @@ export type UserMapConfig = {
|
|
|
64
64
|
|
|
65
65
|
additionalFilters?: MemcmpFilter[];
|
|
66
66
|
};
|
|
67
|
+
|
|
68
|
+
export type UserMapConfig = UserMapConfigBase &
|
|
69
|
+
AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
|
|
@@ -26,7 +26,11 @@ export class UserStatsMap {
|
|
|
26
26
|
* map from authority pubkey to UserStats
|
|
27
27
|
*/
|
|
28
28
|
private userStatsMap = new Map<string, UserStats>();
|
|
29
|
-
private
|
|
29
|
+
private velocityClient: VelocityClient;
|
|
30
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
31
|
+
private get driftClient(): VelocityClient {
|
|
32
|
+
return this.velocityClient;
|
|
33
|
+
}
|
|
30
34
|
private bulkAccountLoader: BulkAccountLoader;
|
|
31
35
|
private decode;
|
|
32
36
|
private syncConfig: SyncConfig;
|
|
@@ -37,19 +41,19 @@ export class UserStatsMap {
|
|
|
37
41
|
/**
|
|
38
42
|
* Creates a new UserStatsMap instance.
|
|
39
43
|
*
|
|
40
|
-
* @param {VelocityClient}
|
|
44
|
+
* @param {VelocityClient} velocityClient - The VelocityClient instance.
|
|
41
45
|
* @param {BulkAccountLoader} [bulkAccountLoader] - If not provided, a new BulkAccountLoader with polling disabled will be created.
|
|
42
46
|
*/
|
|
43
47
|
constructor(
|
|
44
|
-
|
|
48
|
+
velocityClient: VelocityClient,
|
|
45
49
|
bulkAccountLoader?: BulkAccountLoader,
|
|
46
50
|
syncConfig?: SyncConfig
|
|
47
51
|
) {
|
|
48
|
-
this.
|
|
52
|
+
this.velocityClient = velocityClient;
|
|
49
53
|
if (!bulkAccountLoader) {
|
|
50
54
|
bulkAccountLoader = new BulkAccountLoader(
|
|
51
|
-
|
|
52
|
-
|
|
55
|
+
velocityClient.connection,
|
|
56
|
+
velocityClient.opts.commitment,
|
|
53
57
|
0
|
|
54
58
|
);
|
|
55
59
|
}
|
|
@@ -60,9 +64,9 @@ export class UserStatsMap {
|
|
|
60
64
|
};
|
|
61
65
|
|
|
62
66
|
this.decode = (
|
|
63
|
-
this.
|
|
67
|
+
this.velocityClient.program.account as any
|
|
64
68
|
).userStats.coder.accounts.decodeUnchecked.bind(
|
|
65
|
-
(this.
|
|
69
|
+
(this.velocityClient.program.account as any).userStats.coder.accounts
|
|
66
70
|
);
|
|
67
71
|
}
|
|
68
72
|
|
|
@@ -71,7 +75,7 @@ export class UserStatsMap {
|
|
|
71
75
|
return;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
await this.
|
|
78
|
+
await this.velocityClient.subscribe();
|
|
75
79
|
await this.sync(authorities);
|
|
76
80
|
}
|
|
77
81
|
|
|
@@ -87,9 +91,9 @@ export class UserStatsMap {
|
|
|
87
91
|
skipFetch?: boolean
|
|
88
92
|
) {
|
|
89
93
|
const userStat = new UserStats({
|
|
90
|
-
|
|
94
|
+
velocityClient: this.velocityClient,
|
|
91
95
|
userStatsAccountPublicKey: getUserStatsAccountPublicKey(
|
|
92
|
-
this.
|
|
96
|
+
this.velocityClient.program.programId,
|
|
93
97
|
authority
|
|
94
98
|
),
|
|
95
99
|
accountSubscription: {
|
|
@@ -252,8 +256,8 @@ export class UserStatsMap {
|
|
|
252
256
|
let accountsToLoad = authorities;
|
|
253
257
|
if (authorities.length === 0) {
|
|
254
258
|
const accountsPrefetch =
|
|
255
|
-
await this.
|
|
256
|
-
this.
|
|
259
|
+
await this.velocityClient.connection.getProgramAccounts(
|
|
260
|
+
this.velocityClient.program.programId,
|
|
257
261
|
{
|
|
258
262
|
dataSlice: { offset: 0, length: 0 },
|
|
259
263
|
filters: [getUserStatsFilter()],
|
|
@@ -295,10 +299,10 @@ export class UserStatsMap {
|
|
|
295
299
|
const chunk = accountsToLoad.slice(i, i + chunkSize);
|
|
296
300
|
tasks.push(async () => {
|
|
297
301
|
const accountInfos =
|
|
298
|
-
await this.
|
|
302
|
+
await this.velocityClient.connection.getMultipleAccountsInfoAndContext(
|
|
299
303
|
chunk,
|
|
300
304
|
{
|
|
301
|
-
commitment: this.
|
|
305
|
+
commitment: this.velocityClient.opts.commitment,
|
|
302
306
|
}
|
|
303
307
|
);
|
|
304
308
|
|
package/src/userStats.ts
CHANGED
|
@@ -17,24 +17,30 @@ import {
|
|
|
17
17
|
import { grpcUserStatsAccountSubscriber } from './accounts/grpcUserStatsAccountSubscriber';
|
|
18
18
|
|
|
19
19
|
export class UserStats {
|
|
20
|
-
|
|
20
|
+
velocityClient: VelocityClient;
|
|
21
|
+
/** @deprecated Use `velocityClient` instead. `driftClient` will be removed in a future major. */
|
|
22
|
+
public get driftClient(): VelocityClient {
|
|
23
|
+
return this.velocityClient;
|
|
24
|
+
}
|
|
21
25
|
userStatsAccountPublicKey: PublicKey;
|
|
22
26
|
accountSubscriber: UserStatsAccountSubscriber;
|
|
23
27
|
isSubscribed: boolean;
|
|
24
28
|
|
|
25
29
|
public constructor(config: UserStatsConfig) {
|
|
26
|
-
|
|
30
|
+
// Type-system guarantees at least one of the two is supplied.
|
|
31
|
+
const velocityClient = (config.velocityClient ?? config.driftClient)!;
|
|
32
|
+
this.velocityClient = velocityClient;
|
|
27
33
|
this.userStatsAccountPublicKey = config.userStatsAccountPublicKey;
|
|
28
34
|
if (config.accountSubscription?.type === 'polling') {
|
|
29
35
|
this.accountSubscriber = new PollingUserStatsAccountSubscriber(
|
|
30
|
-
|
|
36
|
+
velocityClient.program,
|
|
31
37
|
config.userStatsAccountPublicKey,
|
|
32
38
|
config.accountSubscription.accountLoader
|
|
33
39
|
);
|
|
34
40
|
} else if (config.accountSubscription?.type === 'grpc') {
|
|
35
41
|
this.accountSubscriber = new grpcUserStatsAccountSubscriber(
|
|
36
42
|
config.accountSubscription.grpcConfigs,
|
|
37
|
-
|
|
43
|
+
velocityClient.program,
|
|
38
44
|
config.userStatsAccountPublicKey,
|
|
39
45
|
{
|
|
40
46
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
@@ -43,7 +49,7 @@ export class UserStats {
|
|
|
43
49
|
);
|
|
44
50
|
} else if (config.accountSubscription?.type === 'websocket') {
|
|
45
51
|
this.accountSubscriber = new WebSocketUserStatsAccountSubscriber(
|
|
46
|
-
|
|
52
|
+
velocityClient.program,
|
|
47
53
|
config.userStatsAccountPublicKey,
|
|
48
54
|
{
|
|
49
55
|
resubTimeoutMs: config.accountSubscription?.resubTimeoutMs,
|
|
@@ -95,12 +101,12 @@ export class UserStats {
|
|
|
95
101
|
} else {
|
|
96
102
|
return {
|
|
97
103
|
referrer: getUserAccountPublicKeySync(
|
|
98
|
-
this.
|
|
104
|
+
this.velocityClient.program.programId,
|
|
99
105
|
this.getAccount().referrer,
|
|
100
106
|
0
|
|
101
107
|
),
|
|
102
108
|
referrerStats: getUserStatsAccountPublicKey(
|
|
103
|
-
this.
|
|
109
|
+
this.velocityClient.program.programId,
|
|
104
110
|
this.getAccount().referrer
|
|
105
111
|
),
|
|
106
112
|
};
|
package/src/userStatsConfig.ts
CHANGED
|
@@ -2,13 +2,16 @@ import { VelocityClient } from './velocityClient';
|
|
|
2
2
|
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BulkAccountLoader } from './accounts/bulkAccountLoader';
|
|
4
4
|
import { GrpcConfigs, UserStatsAccountSubscriber } from './accounts/types';
|
|
5
|
+
import { AtLeastOne } from './util/deprecatedAlias';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
type UserStatsConfigBase = {
|
|
7
8
|
accountSubscription?: UserStatsSubscriptionConfig;
|
|
8
|
-
driftClient: VelocityClient;
|
|
9
9
|
userStatsAccountPublicKey: PublicKey;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
export type UserStatsConfig = UserStatsConfigBase &
|
|
13
|
+
AtLeastOne<'velocityClient', 'driftClient', VelocityClient>;
|
|
14
|
+
|
|
12
15
|
export type UserStatsSubscriptionConfig =
|
|
13
16
|
| {
|
|
14
17
|
type: 'websocket';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type helpers for expressing the Drift → Velocity rename surface.
|
|
3
|
+
*
|
|
4
|
+
* The SDK exposes paired keys (`velocityX` canonical, `driftX` deprecated) on
|
|
5
|
+
* several config objects. {@link AtLeastOne} captures the "callers must supply
|
|
6
|
+
* one of the two" contract at the type level so the runtime fallback in the
|
|
7
|
+
* consuming class can rely on the value being present.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `AtLeastOne<A, B, T>` requires the caller to set at least one of two keys
|
|
12
|
+
* (`A` canonical, `B` deprecated) to a value of type `T`. Whichever the caller
|
|
13
|
+
* omits remains optional.
|
|
14
|
+
*
|
|
15
|
+
* Use this to express "rename `B` to `A`, but keep `B` accepted until the next
|
|
16
|
+
* major" on a config object without dropping back to "both optional + runtime
|
|
17
|
+
* throw".
|
|
18
|
+
*/
|
|
19
|
+
export type AtLeastOne<A extends string, B extends string, T> =
|
|
20
|
+
| ({ [K in A]: T } & { [K in B]?: T })
|
|
21
|
+
| ({ [K in A]?: T } & { [K in B]: T });
|
package/src/velocityClient.ts
CHANGED
|
@@ -429,7 +429,7 @@ export class VelocityClient {
|
|
|
429
429
|
|
|
430
430
|
if (config.userStats) {
|
|
431
431
|
this.userStats = new UserStats({
|
|
432
|
-
|
|
432
|
+
velocityClient: this,
|
|
433
433
|
userStatsAccountPublicKey: getUserStatsAccountPublicKey(
|
|
434
434
|
this.program.programId,
|
|
435
435
|
this.authority
|
|
@@ -539,7 +539,7 @@ export class VelocityClient {
|
|
|
539
539
|
);
|
|
540
540
|
|
|
541
541
|
return new User({
|
|
542
|
-
|
|
542
|
+
velocityClient: this,
|
|
543
543
|
userAccountPublicKey,
|
|
544
544
|
accountSubscription: accountSubscriptionConfig,
|
|
545
545
|
});
|
|
@@ -820,7 +820,7 @@ export class VelocityClient {
|
|
|
820
820
|
this.userStats = undefined;
|
|
821
821
|
|
|
822
822
|
this.userStats = new UserStats({
|
|
823
|
-
|
|
823
|
+
velocityClient: this,
|
|
824
824
|
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
825
825
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
826
826
|
});
|
|
@@ -868,7 +868,7 @@ export class VelocityClient {
|
|
|
868
868
|
this.userStats = undefined;
|
|
869
869
|
|
|
870
870
|
this.userStats = new UserStats({
|
|
871
|
-
|
|
871
|
+
velocityClient: this,
|
|
872
872
|
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
873
873
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
874
874
|
});
|
|
@@ -903,7 +903,7 @@ export class VelocityClient {
|
|
|
903
903
|
}
|
|
904
904
|
|
|
905
905
|
this.userStats = new UserStats({
|
|
906
|
-
|
|
906
|
+
velocityClient: this,
|
|
907
907
|
userStatsAccountPublicKey: this.userStatsAccountPublicKey,
|
|
908
908
|
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
909
909
|
});
|
|
@@ -5322,7 +5322,7 @@ export class VelocityClient {
|
|
|
5322
5322
|
withBuilder = hasBuilder(userOrder);
|
|
5323
5323
|
}
|
|
5324
5324
|
} else if (isSignedMsg) {
|
|
5325
|
-
// Order hasn't been placed yet, we
|
|
5325
|
+
// Order hasn't been placed yet, we can't tell if it has a builder or not.
|
|
5326
5326
|
// Include it optimistically
|
|
5327
5327
|
withBuilder = true;
|
|
5328
5328
|
}
|
|
@@ -7305,7 +7305,7 @@ export class VelocityClient {
|
|
|
7305
7305
|
orderId: number,
|
|
7306
7306
|
newBaseAmount?: BN,
|
|
7307
7307
|
newLimitPrice?: BN,
|
|
7308
|
-
newOraclePriceOffset?:
|
|
7308
|
+
newOraclePriceOffset?: BN
|
|
7309
7309
|
): Promise<TransactionSignature> {
|
|
7310
7310
|
return this.modifyOrder({
|
|
7311
7311
|
orderId,
|
|
@@ -7328,7 +7328,7 @@ export class VelocityClient {
|
|
|
7328
7328
|
userOrderId: number,
|
|
7329
7329
|
newBaseAmount?: BN,
|
|
7330
7330
|
newLimitPrice?: BN,
|
|
7331
|
-
newOraclePriceOffset?:
|
|
7331
|
+
newOraclePriceOffset?: BN
|
|
7332
7332
|
): Promise<TransactionSignature> {
|
|
7333
7333
|
return this.modifyOrderByUserOrderId({
|
|
7334
7334
|
userOrderId,
|
|
@@ -7362,7 +7362,7 @@ export class VelocityClient {
|
|
|
7362
7362
|
newDirection?: PositionDirection;
|
|
7363
7363
|
newBaseAmount?: BN;
|
|
7364
7364
|
newLimitPrice?: BN;
|
|
7365
|
-
newOraclePriceOffset?:
|
|
7365
|
+
newOraclePriceOffset?: BN;
|
|
7366
7366
|
newTriggerPrice?: BN;
|
|
7367
7367
|
newTriggerCondition?: OrderTriggerCondition;
|
|
7368
7368
|
auctionDuration?: number;
|
|
@@ -7416,7 +7416,7 @@ export class VelocityClient {
|
|
|
7416
7416
|
newDirection?: PositionDirection;
|
|
7417
7417
|
newBaseAmount?: BN;
|
|
7418
7418
|
newLimitPrice?: BN;
|
|
7419
|
-
newOraclePriceOffset?:
|
|
7419
|
+
newOraclePriceOffset?: BN;
|
|
7420
7420
|
newTriggerPrice?: BN;
|
|
7421
7421
|
newTriggerCondition?: OrderTriggerCondition;
|
|
7422
7422
|
auctionDuration?: number;
|
|
@@ -7502,7 +7502,7 @@ export class VelocityClient {
|
|
|
7502
7502
|
newDirection?: PositionDirection;
|
|
7503
7503
|
newBaseAmount?: BN;
|
|
7504
7504
|
newLimitPrice?: BN;
|
|
7505
|
-
newOraclePriceOffset?:
|
|
7505
|
+
newOraclePriceOffset?: BN;
|
|
7506
7506
|
newTriggerPrice?: BN;
|
|
7507
7507
|
newTriggerCondition?: OrderTriggerCondition;
|
|
7508
7508
|
auctionDuration?: number;
|
|
@@ -7550,7 +7550,7 @@ export class VelocityClient {
|
|
|
7550
7550
|
newDirection?: PositionDirection;
|
|
7551
7551
|
newBaseAmount?: BN;
|
|
7552
7552
|
newLimitPrice?: BN;
|
|
7553
|
-
newOraclePriceOffset?:
|
|
7553
|
+
newOraclePriceOffset?: BN;
|
|
7554
7554
|
newTriggerPrice?: BN;
|
|
7555
7555
|
newTriggerCondition?: OrderTriggerCondition;
|
|
7556
7556
|
auctionDuration?: number;
|