@drift-labs/sdk 2.0.12 → 2.0.13
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/lib/userMap/userMap.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { User, DriftClient, OrderRecord, UserSubscriptionConfig } from '..';
|
|
1
|
+
import { User, DriftClient, OrderRecord, UserSubscriptionConfig, WrappedEvent } from '..';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
export interface UserMapInterface {
|
|
4
4
|
fetchAllUsers(): Promise<void>;
|
|
@@ -37,6 +37,7 @@ export declare class UserMap implements UserMapInterface {
|
|
|
37
37
|
*/
|
|
38
38
|
getUserAuthority(key: string): PublicKey | undefined;
|
|
39
39
|
updateWithOrderRecord(record: OrderRecord): Promise<void>;
|
|
40
|
+
updateWithEventRecord(record: WrappedEvent<any>): Promise<void>;
|
|
40
41
|
values(): IterableIterator<User>;
|
|
41
42
|
size(): number;
|
|
42
43
|
}
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -80,6 +80,46 @@ class UserMap {
|
|
|
80
80
|
await this.addPubkey(record.user);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
async updateWithEventRecord(record) {
|
|
84
|
+
if (record.eventType === 'DepositRecord') {
|
|
85
|
+
const depositRecord = record;
|
|
86
|
+
await this.mustGet(depositRecord.user.toString());
|
|
87
|
+
}
|
|
88
|
+
else if (record.eventType === 'FundingPaymentRecord') {
|
|
89
|
+
const fundingPaymentRecord = record;
|
|
90
|
+
await this.mustGet(fundingPaymentRecord.user.toString());
|
|
91
|
+
}
|
|
92
|
+
else if (record.eventType === 'LiquidationRecord') {
|
|
93
|
+
const liqRecord = record;
|
|
94
|
+
await this.mustGet(liqRecord.user.toString());
|
|
95
|
+
await this.mustGet(liqRecord.liquidator.toString());
|
|
96
|
+
}
|
|
97
|
+
else if (record.eventType === 'OrderRecord') {
|
|
98
|
+
const orderRecord = record;
|
|
99
|
+
await this.updateWithOrderRecord(orderRecord);
|
|
100
|
+
}
|
|
101
|
+
else if (record.eventType === 'OrderActionRecord') {
|
|
102
|
+
const actionRecord = record;
|
|
103
|
+
if (actionRecord.taker) {
|
|
104
|
+
await this.mustGet(actionRecord.taker.toString());
|
|
105
|
+
}
|
|
106
|
+
if (actionRecord.maker) {
|
|
107
|
+
await this.mustGet(actionRecord.maker.toString());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (record.eventType === 'SettlePnlRecord') {
|
|
111
|
+
const settlePnlRecord = record;
|
|
112
|
+
await this.mustGet(settlePnlRecord.user.toString());
|
|
113
|
+
}
|
|
114
|
+
else if (record.eventType === 'NewUserRecord') {
|
|
115
|
+
const newUserRecord = record;
|
|
116
|
+
await this.mustGet(newUserRecord.user.toString());
|
|
117
|
+
}
|
|
118
|
+
else if (record.eventType === 'LPRecord') {
|
|
119
|
+
const lpRecord = record;
|
|
120
|
+
await this.mustGet(lpRecord.user.toString());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
83
123
|
values() {
|
|
84
124
|
return this.userMap.values();
|
|
85
125
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DriftClient, OrderRecord, UserStats, UserStatsSubscriptionConfig } from '..';
|
|
1
|
+
import { DriftClient, OrderRecord, UserStats, UserStatsSubscriptionConfig, WrappedEvent } from '..';
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { UserMap } from './userMap';
|
|
4
4
|
export declare class UserStatsMap {
|
|
@@ -12,6 +12,7 @@ export declare class UserStatsMap {
|
|
|
12
12
|
fetchAllUserStats(): Promise<void>;
|
|
13
13
|
addUserStat(authority: PublicKey): Promise<void>;
|
|
14
14
|
updateWithOrderRecord(record: OrderRecord, userMap: UserMap): Promise<void>;
|
|
15
|
+
updateWithEventRecord(record: WrappedEvent<any>, userMap?: UserMap): Promise<void>;
|
|
15
16
|
has(authorityPublicKey: string): boolean;
|
|
16
17
|
get(authorityPublicKey: string): UserStats;
|
|
17
18
|
mustGet(authorityPublicKey: string): Promise<UserStats>;
|
|
@@ -49,6 +49,71 @@ class UserStatsMap {
|
|
|
49
49
|
this.addUserStat(user.getUserAccount().authority);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
+
async updateWithEventRecord(record, userMap) {
|
|
53
|
+
if (record.eventType === 'DepositRecord') {
|
|
54
|
+
const depositRecord = record;
|
|
55
|
+
await this.mustGet(depositRecord.userAuthority.toString());
|
|
56
|
+
}
|
|
57
|
+
else if (record.eventType === 'FundingPaymentRecord') {
|
|
58
|
+
const fundingPaymentRecord = record;
|
|
59
|
+
await this.mustGet(fundingPaymentRecord.userAuthority.toString());
|
|
60
|
+
}
|
|
61
|
+
else if (record.eventType === 'LiquidationRecord') {
|
|
62
|
+
if (!userMap) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const liqRecord = record;
|
|
66
|
+
const user = await userMap.mustGet(liqRecord.user.toString());
|
|
67
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
68
|
+
const liquidatorUser = await userMap.mustGet(liqRecord.liquidator.toString());
|
|
69
|
+
await this.mustGet(liquidatorUser.getUserAccount().authority.toString());
|
|
70
|
+
}
|
|
71
|
+
else if (record.eventType === 'OrderRecord') {
|
|
72
|
+
if (!userMap) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const orderRecord = record;
|
|
76
|
+
await userMap.updateWithOrderRecord(orderRecord);
|
|
77
|
+
}
|
|
78
|
+
else if (record.eventType === 'OrderActionRecord') {
|
|
79
|
+
if (!userMap) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const actionRecord = record;
|
|
83
|
+
if (actionRecord.taker) {
|
|
84
|
+
const taker = await userMap.mustGet(actionRecord.taker.toString());
|
|
85
|
+
await this.mustGet(taker.getUserAccount().authority.toString());
|
|
86
|
+
}
|
|
87
|
+
if (actionRecord.maker) {
|
|
88
|
+
const maker = await userMap.mustGet(actionRecord.maker.toString());
|
|
89
|
+
await this.mustGet(maker.getUserAccount().authority.toString());
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (record.eventType === 'SettlePnlRecord') {
|
|
93
|
+
if (!userMap) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const settlePnlRecord = record;
|
|
97
|
+
const user = await userMap.mustGet(settlePnlRecord.user.toString());
|
|
98
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
99
|
+
}
|
|
100
|
+
else if (record.eventType === 'NewUserRecord') {
|
|
101
|
+
const newUserRecord = record;
|
|
102
|
+
await this.mustGet(newUserRecord.userAuthority.toString());
|
|
103
|
+
}
|
|
104
|
+
else if (record.eventType === 'LPRecord') {
|
|
105
|
+
if (!userMap) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const lpRecord = record;
|
|
109
|
+
const user = await userMap.mustGet(lpRecord.user.toString());
|
|
110
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
111
|
+
}
|
|
112
|
+
else if (record.eventType === 'InsuranceFundStakeRecord') {
|
|
113
|
+
const ifStakeRecord = record;
|
|
114
|
+
await this.mustGet(ifStakeRecord.userAuthority.toString());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
52
117
|
has(authorityPublicKey) {
|
|
53
118
|
return this.userStatsMap.has(authorityPublicKey);
|
|
54
119
|
}
|
package/package.json
CHANGED
package/src/userMap/userMap.ts
CHANGED
|
@@ -5,6 +5,14 @@ import {
|
|
|
5
5
|
bulkPollingUserSubscribe,
|
|
6
6
|
OrderRecord,
|
|
7
7
|
UserSubscriptionConfig,
|
|
8
|
+
WrappedEvent,
|
|
9
|
+
DepositRecord,
|
|
10
|
+
FundingPaymentRecord,
|
|
11
|
+
LiquidationRecord,
|
|
12
|
+
OrderActionRecord,
|
|
13
|
+
SettlePnlRecord,
|
|
14
|
+
NewUserRecord,
|
|
15
|
+
LPRecord,
|
|
8
16
|
} from '..';
|
|
9
17
|
import { ProgramAccount } from '@project-serum/anchor';
|
|
10
18
|
|
|
@@ -120,6 +128,42 @@ export class UserMap implements UserMapInterface {
|
|
|
120
128
|
}
|
|
121
129
|
}
|
|
122
130
|
|
|
131
|
+
public async updateWithEventRecord(record: WrappedEvent<any>) {
|
|
132
|
+
if (record.eventType === 'DepositRecord') {
|
|
133
|
+
const depositRecord = record as DepositRecord;
|
|
134
|
+
await this.mustGet(depositRecord.user.toString());
|
|
135
|
+
} else if (record.eventType === 'FundingPaymentRecord') {
|
|
136
|
+
const fundingPaymentRecord = record as FundingPaymentRecord;
|
|
137
|
+
await this.mustGet(fundingPaymentRecord.user.toString());
|
|
138
|
+
} else if (record.eventType === 'LiquidationRecord') {
|
|
139
|
+
const liqRecord = record as LiquidationRecord;
|
|
140
|
+
|
|
141
|
+
await this.mustGet(liqRecord.user.toString());
|
|
142
|
+
await this.mustGet(liqRecord.liquidator.toString());
|
|
143
|
+
} else if (record.eventType === 'OrderRecord') {
|
|
144
|
+
const orderRecord = record as OrderRecord;
|
|
145
|
+
await this.updateWithOrderRecord(orderRecord);
|
|
146
|
+
} else if (record.eventType === 'OrderActionRecord') {
|
|
147
|
+
const actionRecord = record as OrderActionRecord;
|
|
148
|
+
|
|
149
|
+
if (actionRecord.taker) {
|
|
150
|
+
await this.mustGet(actionRecord.taker.toString());
|
|
151
|
+
}
|
|
152
|
+
if (actionRecord.maker) {
|
|
153
|
+
await this.mustGet(actionRecord.maker.toString());
|
|
154
|
+
}
|
|
155
|
+
} else if (record.eventType === 'SettlePnlRecord') {
|
|
156
|
+
const settlePnlRecord = record as SettlePnlRecord;
|
|
157
|
+
await this.mustGet(settlePnlRecord.user.toString());
|
|
158
|
+
} else if (record.eventType === 'NewUserRecord') {
|
|
159
|
+
const newUserRecord = record as NewUserRecord;
|
|
160
|
+
await this.mustGet(newUserRecord.user.toString());
|
|
161
|
+
} else if (record.eventType === 'LPRecord') {
|
|
162
|
+
const lpRecord = record as LPRecord;
|
|
163
|
+
await this.mustGet(lpRecord.user.toString());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
123
167
|
public values(): IterableIterator<User> {
|
|
124
168
|
return this.userMap.values();
|
|
125
169
|
}
|
|
@@ -6,6 +6,15 @@ import {
|
|
|
6
6
|
UserStats,
|
|
7
7
|
UserStatsSubscriptionConfig,
|
|
8
8
|
bulkPollingUserStatsSubscribe,
|
|
9
|
+
WrappedEvent,
|
|
10
|
+
DepositRecord,
|
|
11
|
+
FundingPaymentRecord,
|
|
12
|
+
LiquidationRecord,
|
|
13
|
+
OrderActionRecord,
|
|
14
|
+
SettlePnlRecord,
|
|
15
|
+
NewUserRecord,
|
|
16
|
+
LPRecord,
|
|
17
|
+
InsuranceFundStakeRecord,
|
|
9
18
|
} from '..';
|
|
10
19
|
import { ProgramAccount } from '@project-serum/anchor';
|
|
11
20
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -87,6 +96,73 @@ export class UserStatsMap {
|
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
|
|
99
|
+
public async updateWithEventRecord(
|
|
100
|
+
record: WrappedEvent<any>,
|
|
101
|
+
userMap?: UserMap
|
|
102
|
+
) {
|
|
103
|
+
if (record.eventType === 'DepositRecord') {
|
|
104
|
+
const depositRecord = record as DepositRecord;
|
|
105
|
+
await this.mustGet(depositRecord.userAuthority.toString());
|
|
106
|
+
} else if (record.eventType === 'FundingPaymentRecord') {
|
|
107
|
+
const fundingPaymentRecord = record as FundingPaymentRecord;
|
|
108
|
+
await this.mustGet(fundingPaymentRecord.userAuthority.toString());
|
|
109
|
+
} else if (record.eventType === 'LiquidationRecord') {
|
|
110
|
+
if (!userMap) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const liqRecord = record as LiquidationRecord;
|
|
115
|
+
|
|
116
|
+
const user = await userMap.mustGet(liqRecord.user.toString());
|
|
117
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
118
|
+
|
|
119
|
+
const liquidatorUser = await userMap.mustGet(
|
|
120
|
+
liqRecord.liquidator.toString()
|
|
121
|
+
);
|
|
122
|
+
await this.mustGet(liquidatorUser.getUserAccount().authority.toString());
|
|
123
|
+
} else if (record.eventType === 'OrderRecord') {
|
|
124
|
+
if (!userMap) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const orderRecord = record as OrderRecord;
|
|
128
|
+
await userMap.updateWithOrderRecord(orderRecord);
|
|
129
|
+
} else if (record.eventType === 'OrderActionRecord') {
|
|
130
|
+
if (!userMap) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const actionRecord = record as OrderActionRecord;
|
|
134
|
+
|
|
135
|
+
if (actionRecord.taker) {
|
|
136
|
+
const taker = await userMap.mustGet(actionRecord.taker.toString());
|
|
137
|
+
await this.mustGet(taker.getUserAccount().authority.toString());
|
|
138
|
+
}
|
|
139
|
+
if (actionRecord.maker) {
|
|
140
|
+
const maker = await userMap.mustGet(actionRecord.maker.toString());
|
|
141
|
+
await this.mustGet(maker.getUserAccount().authority.toString());
|
|
142
|
+
}
|
|
143
|
+
} else if (record.eventType === 'SettlePnlRecord') {
|
|
144
|
+
if (!userMap) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const settlePnlRecord = record as SettlePnlRecord;
|
|
148
|
+
const user = await userMap.mustGet(settlePnlRecord.user.toString());
|
|
149
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
150
|
+
} else if (record.eventType === 'NewUserRecord') {
|
|
151
|
+
const newUserRecord = record as NewUserRecord;
|
|
152
|
+
await this.mustGet(newUserRecord.userAuthority.toString());
|
|
153
|
+
} else if (record.eventType === 'LPRecord') {
|
|
154
|
+
if (!userMap) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const lpRecord = record as LPRecord;
|
|
158
|
+
const user = await userMap.mustGet(lpRecord.user.toString());
|
|
159
|
+
await this.mustGet(user.getUserAccount().authority.toString());
|
|
160
|
+
} else if (record.eventType === 'InsuranceFundStakeRecord') {
|
|
161
|
+
const ifStakeRecord = record as InsuranceFundStakeRecord;
|
|
162
|
+
await this.mustGet(ifStakeRecord.userAuthority.toString());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
90
166
|
public has(authorityPublicKey: string): boolean {
|
|
91
167
|
return this.userStatsMap.has(authorityPublicKey);
|
|
92
168
|
}
|