@drift-labs/sdk 2.0.12 → 2.0.14
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/dlob/DLOB.d.ts +8 -3
- package/lib/dlob/DLOB.js +209 -146
- package/lib/driftClient.d.ts +19 -0
- package/lib/driftClient.js +32 -0
- package/lib/math/orders.d.ts +1 -2
- package/lib/math/orders.js +4 -20
- package/lib/userMap/userMap.d.ts +2 -1
- package/lib/userMap/userMap.js +40 -0
- package/lib/userMap/userStatsMap.d.ts +2 -1
- package/lib/userMap/userStatsMap.js +65 -0
- package/package.json +1 -1
- package/src/dlob/DLOB.ts +381 -197
- package/src/driftClient.ts +41 -0
- package/src/math/orders.ts +5 -22
- package/src/userMap/userMap.ts +44 -0
- package/src/userMap/userStatsMap.ts +76 -0
- package/tests/dlob/test.ts +295 -63
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
|
}
|