@drift-labs/sdk 2.98.0-beta.9 → 2.99.0-beta.0
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/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/browser/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/browser/accounts/types.d.ts +14 -1
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/browser/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/browser/addresses/pda.d.ts +1 -0
- package/lib/browser/addresses/pda.js +8 -1
- package/lib/browser/constants/perpMarkets.js +11 -0
- package/lib/browser/constants/spotMarkets.js +2 -2
- package/lib/browser/driftClient.d.ts +14 -4
- package/lib/browser/driftClient.js +58 -16
- package/lib/browser/idl/drift.json +199 -8
- package/lib/browser/index.d.ts +4 -0
- package/lib/browser/index.js +4 -0
- package/lib/browser/jupiter/jupiterClient.d.ts +6 -0
- package/lib/browser/memcmp.d.ts +3 -0
- package/lib/browser/memcmp.js +28 -1
- package/lib/browser/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/browser/slot/SlothashSubscriber.js +85 -0
- package/lib/browser/types.d.ts +4 -3
- package/lib/browser/user.js +3 -0
- package/lib/browser/userMap/referrerMap.d.ts +45 -0
- package/lib/browser/userMap/referrerMap.js +180 -0
- package/lib/browser/util/digest.d.ts +1 -0
- package/lib/browser/util/digest.js +5 -1
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.d.ts +29 -0
- package/lib/node/accounts/pollingHighLeverageModeConfigAccountSubscriber.js +111 -0
- package/lib/node/accounts/types.d.ts +14 -1
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.d.ts +23 -0
- package/lib/node/accounts/webSocketHighLeverageModeConfigAccountSubscriber.js +69 -0
- package/lib/node/addresses/pda.d.ts +1 -0
- package/lib/node/addresses/pda.js +8 -1
- package/lib/node/constants/perpMarkets.js +11 -0
- package/lib/node/constants/spotMarkets.js +2 -2
- package/lib/node/driftClient.d.ts +14 -4
- package/lib/node/driftClient.js +58 -16
- package/lib/node/idl/drift.json +199 -8
- package/lib/node/index.d.ts +4 -0
- package/lib/node/index.js +4 -0
- package/lib/node/jupiter/jupiterClient.d.ts +6 -0
- package/lib/node/memcmp.d.ts +3 -0
- package/lib/node/memcmp.js +28 -1
- package/lib/node/slot/SlothashSubscriber.d.ts +26 -0
- package/lib/node/slot/SlothashSubscriber.js +85 -0
- package/lib/node/types.d.ts +4 -3
- package/lib/node/user.js +3 -0
- package/lib/node/userMap/referrerMap.d.ts +45 -0
- package/lib/node/userMap/referrerMap.js +180 -0
- package/lib/node/util/digest.d.ts +1 -0
- package/lib/node/util/digest.js +5 -1
- package/package.json +1 -1
- package/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +189 -0
- package/src/accounts/types.ts +25 -1
- package/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +131 -0
- package/src/addresses/pda.ts +13 -0
- package/src/constants/perpMarkets.ts +12 -0
- package/src/constants/spotMarkets.ts +2 -2
- package/src/driftClient.ts +122 -33
- package/src/idl/drift.json +199 -8
- package/src/index.ts +4 -0
- package/src/jupiter/jupiterClient.ts +6 -0
- package/src/memcmp.ts +27 -0
- package/src/slot/SlothashSubscriber.ts +126 -0
- package/src/types.ts +4 -3
- package/src/user.ts +4 -0
- package/src/userMap/referrerMap.ts +283 -0
- package/src/util/digest.ts +4 -0
- package/tests/ci/verifyConstants.ts +16 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.
|
|
2
|
+
"version": "2.98.0",
|
|
3
3
|
"name": "drift",
|
|
4
4
|
"instructions": [
|
|
5
5
|
{
|
|
@@ -129,6 +129,42 @@
|
|
|
129
129
|
],
|
|
130
130
|
"args": []
|
|
131
131
|
},
|
|
132
|
+
{
|
|
133
|
+
"name": "initializeSwiftUserOrders",
|
|
134
|
+
"accounts": [
|
|
135
|
+
{
|
|
136
|
+
"name": "swiftUserOrders",
|
|
137
|
+
"isMut": true,
|
|
138
|
+
"isSigner": false
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"name": "authority",
|
|
142
|
+
"isMut": false,
|
|
143
|
+
"isSigner": true
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"name": "user",
|
|
147
|
+
"isMut": true,
|
|
148
|
+
"isSigner": false
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "payer",
|
|
152
|
+
"isMut": true,
|
|
153
|
+
"isSigner": true
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"name": "rent",
|
|
157
|
+
"isMut": false,
|
|
158
|
+
"isSigner": false
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "systemProgram",
|
|
162
|
+
"isMut": false,
|
|
163
|
+
"isSigner": false
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"args": []
|
|
167
|
+
},
|
|
132
168
|
{
|
|
133
169
|
"name": "initializeReferrerName",
|
|
134
170
|
"accounts": [
|
|
@@ -644,6 +680,63 @@
|
|
|
644
680
|
}
|
|
645
681
|
]
|
|
646
682
|
},
|
|
683
|
+
{
|
|
684
|
+
"name": "placeAndMakeSwiftPerpOrder",
|
|
685
|
+
"accounts": [
|
|
686
|
+
{
|
|
687
|
+
"name": "state",
|
|
688
|
+
"isMut": false,
|
|
689
|
+
"isSigner": false
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
"name": "user",
|
|
693
|
+
"isMut": true,
|
|
694
|
+
"isSigner": false
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
"name": "userStats",
|
|
698
|
+
"isMut": true,
|
|
699
|
+
"isSigner": false
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
"name": "taker",
|
|
703
|
+
"isMut": true,
|
|
704
|
+
"isSigner": false
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
"name": "takerStats",
|
|
708
|
+
"isMut": true,
|
|
709
|
+
"isSigner": false
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
"name": "takerSwiftUserOrders",
|
|
713
|
+
"isMut": false,
|
|
714
|
+
"isSigner": false
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
"name": "authority",
|
|
718
|
+
"isMut": false,
|
|
719
|
+
"isSigner": true
|
|
720
|
+
}
|
|
721
|
+
],
|
|
722
|
+
"args": [
|
|
723
|
+
{
|
|
724
|
+
"name": "params",
|
|
725
|
+
"type": {
|
|
726
|
+
"defined": "OrderParams"
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
"name": "swiftOrderUuid",
|
|
731
|
+
"type": {
|
|
732
|
+
"array": [
|
|
733
|
+
"u8",
|
|
734
|
+
8
|
|
735
|
+
]
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
]
|
|
739
|
+
},
|
|
647
740
|
{
|
|
648
741
|
"name": "placeSwiftTakerOrder",
|
|
649
742
|
"accounts": [
|
|
@@ -662,6 +755,11 @@
|
|
|
662
755
|
"isMut": true,
|
|
663
756
|
"isSigner": false
|
|
664
757
|
},
|
|
758
|
+
{
|
|
759
|
+
"name": "swiftUserOrders",
|
|
760
|
+
"isMut": true,
|
|
761
|
+
"isSigner": false
|
|
762
|
+
},
|
|
665
763
|
{
|
|
666
764
|
"name": "authority",
|
|
667
765
|
"isMut": false,
|
|
@@ -7468,6 +7566,29 @@
|
|
|
7468
7566
|
]
|
|
7469
7567
|
}
|
|
7470
7568
|
},
|
|
7569
|
+
{
|
|
7570
|
+
"name": "SwiftUserOrders",
|
|
7571
|
+
"type": {
|
|
7572
|
+
"kind": "struct",
|
|
7573
|
+
"fields": [
|
|
7574
|
+
{
|
|
7575
|
+
"name": "userPubkey",
|
|
7576
|
+
"type": "publicKey"
|
|
7577
|
+
},
|
|
7578
|
+
{
|
|
7579
|
+
"name": "swiftOrderData",
|
|
7580
|
+
"type": {
|
|
7581
|
+
"array": [
|
|
7582
|
+
{
|
|
7583
|
+
"defined": "SwiftOrderId"
|
|
7584
|
+
},
|
|
7585
|
+
32
|
|
7586
|
+
]
|
|
7587
|
+
}
|
|
7588
|
+
}
|
|
7589
|
+
]
|
|
7590
|
+
}
|
|
7591
|
+
},
|
|
7471
7592
|
{
|
|
7472
7593
|
"name": "User",
|
|
7473
7594
|
"type": {
|
|
@@ -8432,6 +8553,15 @@
|
|
|
8432
8553
|
"type": {
|
|
8433
8554
|
"kind": "struct",
|
|
8434
8555
|
"fields": [
|
|
8556
|
+
{
|
|
8557
|
+
"name": "uuid",
|
|
8558
|
+
"type": {
|
|
8559
|
+
"array": [
|
|
8560
|
+
"u8",
|
|
8561
|
+
8
|
|
8562
|
+
]
|
|
8563
|
+
}
|
|
8564
|
+
},
|
|
8435
8565
|
{
|
|
8436
8566
|
"name": "swiftOrderSignature",
|
|
8437
8567
|
"type": {
|
|
@@ -8459,10 +8589,6 @@
|
|
|
8459
8589
|
"defined": "OrderParams"
|
|
8460
8590
|
}
|
|
8461
8591
|
},
|
|
8462
|
-
{
|
|
8463
|
-
"name": "expectedOrderId",
|
|
8464
|
-
"type": "i32"
|
|
8465
|
-
},
|
|
8466
8592
|
{
|
|
8467
8593
|
"name": "subAccountId",
|
|
8468
8594
|
"type": "u16"
|
|
@@ -9642,6 +9768,31 @@
|
|
|
9642
9768
|
]
|
|
9643
9769
|
}
|
|
9644
9770
|
},
|
|
9771
|
+
{
|
|
9772
|
+
"name": "SwiftOrderId",
|
|
9773
|
+
"type": {
|
|
9774
|
+
"kind": "struct",
|
|
9775
|
+
"fields": [
|
|
9776
|
+
{
|
|
9777
|
+
"name": "uuid",
|
|
9778
|
+
"type": {
|
|
9779
|
+
"array": [
|
|
9780
|
+
"u8",
|
|
9781
|
+
8
|
|
9782
|
+
]
|
|
9783
|
+
}
|
|
9784
|
+
},
|
|
9785
|
+
{
|
|
9786
|
+
"name": "maxSlot",
|
|
9787
|
+
"type": "u64"
|
|
9788
|
+
},
|
|
9789
|
+
{
|
|
9790
|
+
"name": "orderId",
|
|
9791
|
+
"type": "u32"
|
|
9792
|
+
}
|
|
9793
|
+
]
|
|
9794
|
+
}
|
|
9795
|
+
},
|
|
9645
9796
|
{
|
|
9646
9797
|
"name": "UserFees",
|
|
9647
9798
|
"type": {
|
|
@@ -11541,13 +11692,28 @@
|
|
|
11541
11692
|
"index": false
|
|
11542
11693
|
},
|
|
11543
11694
|
{
|
|
11544
|
-
"name": "
|
|
11695
|
+
"name": "userOrderId",
|
|
11696
|
+
"type": "u32",
|
|
11697
|
+
"index": false
|
|
11698
|
+
},
|
|
11699
|
+
{
|
|
11700
|
+
"name": "swiftOrderMaxSlot",
|
|
11545
11701
|
"type": "u64",
|
|
11546
11702
|
"index": false
|
|
11547
11703
|
},
|
|
11548
11704
|
{
|
|
11549
|
-
"name": "
|
|
11550
|
-
"type":
|
|
11705
|
+
"name": "swiftOrderUuid",
|
|
11706
|
+
"type": {
|
|
11707
|
+
"array": [
|
|
11708
|
+
"u8",
|
|
11709
|
+
8
|
|
11710
|
+
]
|
|
11711
|
+
},
|
|
11712
|
+
"index": false
|
|
11713
|
+
},
|
|
11714
|
+
{
|
|
11715
|
+
"name": "ts",
|
|
11716
|
+
"type": "i64",
|
|
11551
11717
|
"index": false
|
|
11552
11718
|
}
|
|
11553
11719
|
]
|
|
@@ -13671,6 +13837,31 @@
|
|
|
13671
13837
|
"code": 6296,
|
|
13672
13838
|
"name": "InvalidRFQMatch",
|
|
13673
13839
|
"msg": "RFQ matches must be valid"
|
|
13840
|
+
},
|
|
13841
|
+
{
|
|
13842
|
+
"code": 6297,
|
|
13843
|
+
"name": "InvalidSwiftUserAccount",
|
|
13844
|
+
"msg": "Invalid swift user account"
|
|
13845
|
+
},
|
|
13846
|
+
{
|
|
13847
|
+
"code": 6298,
|
|
13848
|
+
"name": "SwiftUserAccountWrongMutability",
|
|
13849
|
+
"msg": "Swift account wrong mutability"
|
|
13850
|
+
},
|
|
13851
|
+
{
|
|
13852
|
+
"code": 6299,
|
|
13853
|
+
"name": "SwiftUserOrdersAccountFull",
|
|
13854
|
+
"msg": "SwiftUserAccount has too many active orders"
|
|
13855
|
+
},
|
|
13856
|
+
{
|
|
13857
|
+
"code": 6300,
|
|
13858
|
+
"name": "SwiftOrderDoesNotExist",
|
|
13859
|
+
"msg": "Order with swift uuid does not exist"
|
|
13860
|
+
},
|
|
13861
|
+
{
|
|
13862
|
+
"code": 6301,
|
|
13863
|
+
"name": "InvalidSwiftOrderId",
|
|
13864
|
+
"msg": "Swift order id cannot be 0s"
|
|
13674
13865
|
}
|
|
13675
13866
|
],
|
|
13676
13867
|
"metadata": {
|
package/lib/browser/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './constants/perpMarkets';
|
|
|
10
10
|
export * from './accounts/fetch';
|
|
11
11
|
export * from './accounts/webSocketDriftClientAccountSubscriber';
|
|
12
12
|
export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
|
|
13
|
+
export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
|
|
13
14
|
export * from './accounts/bulkAccountLoader';
|
|
14
15
|
export * from './accounts/bulkUserSubscription';
|
|
15
16
|
export * from './accounts/bulkUserStatsSubscription';
|
|
@@ -19,6 +20,7 @@ export * from './accounts/pollingTokenAccountSubscriber';
|
|
|
19
20
|
export * from './accounts/pollingUserAccountSubscriber';
|
|
20
21
|
export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
21
22
|
export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
|
|
23
|
+
export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
|
|
22
24
|
export * from './accounts/basicUserAccountSubscriber';
|
|
23
25
|
export * from './accounts/oneShotUserAccountSubscriber';
|
|
24
26
|
export * from './accounts/types';
|
|
@@ -64,6 +66,7 @@ export * from './math/tiers';
|
|
|
64
66
|
export * from './marinade';
|
|
65
67
|
export * from './orderParams';
|
|
66
68
|
export * from './slot/SlotSubscriber';
|
|
69
|
+
export * from './slot/SlothashSubscriber';
|
|
67
70
|
export * from './wallet';
|
|
68
71
|
export * from './keypair';
|
|
69
72
|
export * from './types';
|
|
@@ -104,6 +107,7 @@ export * from './dlob/DLOBApiClient';
|
|
|
104
107
|
export * from './dlob/types';
|
|
105
108
|
export * from './dlob/orderBookLevels';
|
|
106
109
|
export * from './userMap/userMap';
|
|
110
|
+
export * from './userMap/referrerMap';
|
|
107
111
|
export * from './userMap/userStatsMap';
|
|
108
112
|
export * from './userMap/userMapConfig';
|
|
109
113
|
export * from './math/bankruptcy';
|
package/lib/browser/index.js
CHANGED
|
@@ -33,6 +33,7 @@ __exportStar(require("./constants/perpMarkets"), exports);
|
|
|
33
33
|
__exportStar(require("./accounts/fetch"), exports);
|
|
34
34
|
__exportStar(require("./accounts/webSocketDriftClientAccountSubscriber"), exports);
|
|
35
35
|
__exportStar(require("./accounts/webSocketInsuranceFundStakeAccountSubscriber"), exports);
|
|
36
|
+
__exportStar(require("./accounts/webSocketHighLeverageModeConfigAccountSubscriber"), exports);
|
|
36
37
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
37
38
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
38
39
|
__exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
|
|
@@ -42,6 +43,7 @@ __exportStar(require("./accounts/pollingTokenAccountSubscriber"), exports);
|
|
|
42
43
|
__exportStar(require("./accounts/pollingUserAccountSubscriber"), exports);
|
|
43
44
|
__exportStar(require("./accounts/pollingUserStatsAccountSubscriber"), exports);
|
|
44
45
|
__exportStar(require("./accounts/pollingInsuranceFundStakeAccountSubscriber"), exports);
|
|
46
|
+
__exportStar(require("./accounts/pollingHighLeverageModeConfigAccountSubscriber"), exports);
|
|
45
47
|
__exportStar(require("./accounts/basicUserAccountSubscriber"), exports);
|
|
46
48
|
__exportStar(require("./accounts/oneShotUserAccountSubscriber"), exports);
|
|
47
49
|
__exportStar(require("./accounts/types"), exports);
|
|
@@ -87,6 +89,7 @@ __exportStar(require("./math/tiers"), exports);
|
|
|
87
89
|
__exportStar(require("./marinade"), exports);
|
|
88
90
|
__exportStar(require("./orderParams"), exports);
|
|
89
91
|
__exportStar(require("./slot/SlotSubscriber"), exports);
|
|
92
|
+
__exportStar(require("./slot/SlothashSubscriber"), exports);
|
|
90
93
|
__exportStar(require("./wallet"), exports);
|
|
91
94
|
__exportStar(require("./keypair"), exports);
|
|
92
95
|
__exportStar(require("./types"), exports);
|
|
@@ -127,6 +130,7 @@ __exportStar(require("./dlob/DLOBApiClient"), exports);
|
|
|
127
130
|
__exportStar(require("./dlob/types"), exports);
|
|
128
131
|
__exportStar(require("./dlob/orderBookLevels"), exports);
|
|
129
132
|
__exportStar(require("./userMap/userMap"), exports);
|
|
133
|
+
__exportStar(require("./userMap/referrerMap"), exports);
|
|
130
134
|
__exportStar(require("./userMap/userStatsMap"), exports);
|
|
131
135
|
__exportStar(require("./userMap/userMapConfig"), exports);
|
|
132
136
|
__exportStar(require("./math/bankruptcy"), exports);
|
|
@@ -201,6 +201,12 @@ export interface QuoteResponse {
|
|
|
201
201
|
* @memberof QuoteResponse
|
|
202
202
|
*/
|
|
203
203
|
error?: string;
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @type {string}
|
|
207
|
+
* @memberof QuoteResponse
|
|
208
|
+
*/
|
|
209
|
+
errorCode?: string;
|
|
204
210
|
}
|
|
205
211
|
export declare class JupiterClient {
|
|
206
212
|
url: string;
|
package/lib/browser/memcmp.d.ts
CHANGED
|
@@ -5,3 +5,6 @@ export declare function getUserWithOrderFilter(): MemcmpFilter;
|
|
|
5
5
|
export declare function getUserWithAuctionFilter(): MemcmpFilter;
|
|
6
6
|
export declare function getUserThatHasBeenLP(): MemcmpFilter;
|
|
7
7
|
export declare function getUserWithName(name: string): MemcmpFilter;
|
|
8
|
+
export declare function getUserStatsFilter(): MemcmpFilter;
|
|
9
|
+
export declare function getUserStatsIsReferredFilter(): MemcmpFilter;
|
|
10
|
+
export declare function getUserStatsIsReferredOrReferrerFilter(): MemcmpFilter;
|
package/lib/browser/memcmp.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getUserWithName = exports.getUserThatHasBeenLP = exports.getUserWithAuctionFilter = exports.getUserWithOrderFilter = exports.getNonIdleUserFilter = exports.getUserFilter = void 0;
|
|
6
|
+
exports.getUserStatsIsReferredOrReferrerFilter = exports.getUserStatsIsReferredFilter = exports.getUserStatsFilter = exports.getUserWithName = exports.getUserThatHasBeenLP = exports.getUserWithAuctionFilter = exports.getUserWithOrderFilter = exports.getNonIdleUserFilter = exports.getUserFilter = void 0;
|
|
7
7
|
const bs58_1 = __importDefault(require("bs58"));
|
|
8
8
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
9
9
|
const userName_1 = require("./userName");
|
|
@@ -61,3 +61,30 @@ function getUserWithName(name) {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
exports.getUserWithName = getUserWithName;
|
|
64
|
+
function getUserStatsFilter() {
|
|
65
|
+
return {
|
|
66
|
+
memcmp: {
|
|
67
|
+
offset: 0,
|
|
68
|
+
bytes: bs58_1.default.encode(anchor_1.BorshAccountsCoder.accountDiscriminator('UserStats')),
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
exports.getUserStatsFilter = getUserStatsFilter;
|
|
73
|
+
function getUserStatsIsReferredFilter() {
|
|
74
|
+
return {
|
|
75
|
+
memcmp: {
|
|
76
|
+
offset: 188,
|
|
77
|
+
bytes: bs58_1.default.encode(Buffer.from(Uint8Array.from([2]))),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
exports.getUserStatsIsReferredFilter = getUserStatsIsReferredFilter;
|
|
82
|
+
function getUserStatsIsReferredOrReferrerFilter() {
|
|
83
|
+
return {
|
|
84
|
+
memcmp: {
|
|
85
|
+
offset: 188,
|
|
86
|
+
bytes: bs58_1.default.encode(Buffer.from(Uint8Array.from([3]))),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.getUserStatsIsReferredOrReferrerFilter = getUserStatsIsReferredOrReferrerFilter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Commitment, Connection } from '@solana/web3.js';
|
|
3
|
+
type SlothashSubscriberConfig = {
|
|
4
|
+
resubTimeoutMs?: number;
|
|
5
|
+
commitment?: Commitment;
|
|
6
|
+
};
|
|
7
|
+
export type Slothash = {
|
|
8
|
+
slot: number;
|
|
9
|
+
hash: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class SlothashSubscriber {
|
|
12
|
+
private connection;
|
|
13
|
+
currentSlothash: Slothash;
|
|
14
|
+
subscriptionId: number;
|
|
15
|
+
commitment: Commitment;
|
|
16
|
+
timeoutId?: NodeJS.Timeout;
|
|
17
|
+
resubTimeoutMs?: number;
|
|
18
|
+
isUnsubscribing: boolean;
|
|
19
|
+
receivingData: boolean;
|
|
20
|
+
constructor(connection: Connection, config?: SlothashSubscriberConfig);
|
|
21
|
+
subscribe(): Promise<void>;
|
|
22
|
+
private setTimeout;
|
|
23
|
+
getSlothash(): Slothash;
|
|
24
|
+
unsubscribe(onResub?: boolean): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SlothashSubscriber = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
6
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
|
+
class SlothashSubscriber {
|
|
8
|
+
constructor(connection, config) {
|
|
9
|
+
var _a;
|
|
10
|
+
this.connection = connection;
|
|
11
|
+
this.isUnsubscribing = false;
|
|
12
|
+
this.receivingData = false;
|
|
13
|
+
this.resubTimeoutMs = config === null || config === void 0 ? void 0 : config.resubTimeoutMs;
|
|
14
|
+
this.commitment = (_a = config === null || config === void 0 ? void 0 : config.commitment) !== null && _a !== void 0 ? _a : 'processed';
|
|
15
|
+
if (this.resubTimeoutMs < 1000) {
|
|
16
|
+
console.log('resubTimeoutMs should be at least 1000ms to avoid spamming resub');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async subscribe() {
|
|
20
|
+
if (this.subscriptionId != null) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const currentAccountData = await this.connection.getAccountInfo(web3_js_1.SYSVAR_SLOT_HASHES_PUBKEY, this.commitment);
|
|
24
|
+
if (currentAccountData == null) {
|
|
25
|
+
throw new Error('Failed to retrieve current slot hash');
|
|
26
|
+
}
|
|
27
|
+
this.currentSlothash = deserializeSlothash(currentAccountData.data);
|
|
28
|
+
this.subscriptionId = this.connection.onAccountChange(web3_js_1.SYSVAR_SLOT_HASHES_PUBKEY, (slothashInfo, context) => {
|
|
29
|
+
if (!this.currentSlothash || this.currentSlothash.slot < context.slot) {
|
|
30
|
+
if (this.resubTimeoutMs && !this.isUnsubscribing) {
|
|
31
|
+
this.receivingData = true;
|
|
32
|
+
clearTimeout(this.timeoutId);
|
|
33
|
+
this.setTimeout();
|
|
34
|
+
}
|
|
35
|
+
this.currentSlothash = deserializeSlothash(slothashInfo.data);
|
|
36
|
+
}
|
|
37
|
+
}, this.commitment);
|
|
38
|
+
if (this.resubTimeoutMs) {
|
|
39
|
+
this.receivingData = true;
|
|
40
|
+
this.setTimeout();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setTimeout() {
|
|
44
|
+
this.timeoutId = setTimeout(async () => {
|
|
45
|
+
if (this.isUnsubscribing) {
|
|
46
|
+
// If we are in the process of unsubscribing, do not attempt to resubscribe
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (this.receivingData) {
|
|
50
|
+
console.log(`No new slot in ${this.resubTimeoutMs}ms, slot subscriber resubscribing`);
|
|
51
|
+
await this.unsubscribe(true);
|
|
52
|
+
this.receivingData = false;
|
|
53
|
+
await this.subscribe();
|
|
54
|
+
}
|
|
55
|
+
}, this.resubTimeoutMs);
|
|
56
|
+
}
|
|
57
|
+
getSlothash() {
|
|
58
|
+
return this.currentSlothash;
|
|
59
|
+
}
|
|
60
|
+
async unsubscribe(onResub = false) {
|
|
61
|
+
if (!onResub) {
|
|
62
|
+
this.resubTimeoutMs = undefined;
|
|
63
|
+
}
|
|
64
|
+
this.isUnsubscribing = true;
|
|
65
|
+
clearTimeout(this.timeoutId);
|
|
66
|
+
this.timeoutId = undefined;
|
|
67
|
+
if (this.subscriptionId != null) {
|
|
68
|
+
await this.connection.removeSlotChangeListener(this.subscriptionId);
|
|
69
|
+
this.subscriptionId = undefined;
|
|
70
|
+
this.isUnsubscribing = false;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.isUnsubscribing = false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SlothashSubscriber = SlothashSubscriber;
|
|
78
|
+
function deserializeSlothash(data) {
|
|
79
|
+
const slotNumber = new anchor_1.BN(data.subarray(8, 16), 10, 'le');
|
|
80
|
+
const hash = bytes_1.bs58.encode(data.subarray(16, 48));
|
|
81
|
+
return {
|
|
82
|
+
slot: slotNumber.toNumber(),
|
|
83
|
+
hash,
|
|
84
|
+
};
|
|
85
|
+
}
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -647,8 +647,9 @@ export type SwiftOrderRecord = {
|
|
|
647
647
|
user: PublicKey;
|
|
648
648
|
hash: string;
|
|
649
649
|
matchingOrderParams: OrderParams;
|
|
650
|
-
|
|
651
|
-
|
|
650
|
+
swiftOrderMaxSlot: BN;
|
|
651
|
+
swiftOrderUuid: Uint8Array;
|
|
652
|
+
userOrderId: number;
|
|
652
653
|
};
|
|
653
654
|
export type OrderRecord = {
|
|
654
655
|
ts: BN;
|
|
@@ -1118,10 +1119,10 @@ export declare const DefaultOrderParams: OrderParams;
|
|
|
1118
1119
|
export type SwiftServerMessage = {
|
|
1119
1120
|
slot: BN;
|
|
1120
1121
|
swiftOrderSignature: Uint8Array;
|
|
1122
|
+
uuid: Uint8Array;
|
|
1121
1123
|
};
|
|
1122
1124
|
export type SwiftOrderParamsMessage = {
|
|
1123
1125
|
swiftOrderParams: OptionalOrderParams;
|
|
1124
|
-
expectedOrderId: number;
|
|
1125
1126
|
subAccountId: number;
|
|
1126
1127
|
takeProfitOrderParams: SwiftTriggerOrderParams | null;
|
|
1127
1128
|
stopLossOrderParams: SwiftTriggerOrderParams | null;
|
package/lib/browser/user.js
CHANGED
|
@@ -1811,6 +1811,9 @@ class User {
|
|
|
1811
1811
|
const state = this.driftClient.getStateAccount();
|
|
1812
1812
|
let feeTierIndex = 0;
|
|
1813
1813
|
if ((0, types_1.isVariant)(marketType, 'perp')) {
|
|
1814
|
+
if (this.isHighLeverageMode()) {
|
|
1815
|
+
return state.perpFeeStructure.feeTiers[0];
|
|
1816
|
+
}
|
|
1814
1817
|
const userStatsAccount = this.driftClient
|
|
1815
1818
|
.getUserStats()
|
|
1816
1819
|
.getAccount();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { MemcmpFilter } from '@solana/web3.js';
|
|
2
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
3
|
+
import { DriftClient } from '../driftClient';
|
|
4
|
+
import { ReferrerInfo } from '../types';
|
|
5
|
+
export declare class ReferrerMap {
|
|
6
|
+
/**
|
|
7
|
+
* map from authority pubkey to ReferrerInfo.
|
|
8
|
+
* - if a user has not been entered into the map, the value is undefined
|
|
9
|
+
* - if a user has no referrer, the value is null
|
|
10
|
+
* - if a user has a referrer, the value is a ReferrerInfo object
|
|
11
|
+
*/
|
|
12
|
+
private referrerMap;
|
|
13
|
+
private driftClient;
|
|
14
|
+
private bulkAccountLoader;
|
|
15
|
+
private parallelSync;
|
|
16
|
+
private fetchPromise?;
|
|
17
|
+
private fetchPromiseResolver;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new UserStatsMap instance.
|
|
20
|
+
*
|
|
21
|
+
* @param {DriftClient} driftClient - The DriftClient instance.
|
|
22
|
+
* @param {BulkAccountLoader} [bulkAccountLoader] - If not provided, a new BulkAccountLoader with polling disabled will be created.
|
|
23
|
+
*/
|
|
24
|
+
constructor(driftClient: DriftClient, bulkAccountLoader?: BulkAccountLoader, parallelSync?: boolean);
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to all UserStats accounts.
|
|
27
|
+
*/
|
|
28
|
+
subscribe(): Promise<void>;
|
|
29
|
+
has(authorityPublicKey: string): boolean;
|
|
30
|
+
get(authorityPublicKey: string): ReferrerInfo | undefined;
|
|
31
|
+
addReferrerInfo(authority: string, referrerInfo?: ReferrerInfo | null): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Enforce that a UserStats will exist for the given authorityPublicKey,
|
|
34
|
+
* reading one from the blockchain if necessary.
|
|
35
|
+
* @param authorityPublicKey
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
mustGet(authorityPublicKey: string): Promise<ReferrerInfo | undefined>;
|
|
39
|
+
values(): IterableIterator<ReferrerInfo | null>;
|
|
40
|
+
size(): number;
|
|
41
|
+
sync(): Promise<void>;
|
|
42
|
+
syncAll(): Promise<void>;
|
|
43
|
+
syncReferrer(referrerFilter: MemcmpFilter): Promise<void>;
|
|
44
|
+
unsubscribe(): Promise<void>;
|
|
45
|
+
}
|