@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
package/src/idl/drift.json
CHANGED
|
@@ -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/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './constants/perpMarkets';
|
|
|
11
11
|
export * from './accounts/fetch';
|
|
12
12
|
export * from './accounts/webSocketDriftClientAccountSubscriber';
|
|
13
13
|
export * from './accounts/webSocketInsuranceFundStakeAccountSubscriber';
|
|
14
|
+
export * from './accounts/webSocketHighLeverageModeConfigAccountSubscriber';
|
|
14
15
|
export * from './accounts/bulkAccountLoader';
|
|
15
16
|
export * from './accounts/bulkUserSubscription';
|
|
16
17
|
export * from './accounts/bulkUserStatsSubscription';
|
|
@@ -20,6 +21,7 @@ export * from './accounts/pollingTokenAccountSubscriber';
|
|
|
20
21
|
export * from './accounts/pollingUserAccountSubscriber';
|
|
21
22
|
export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
22
23
|
export * from './accounts/pollingInsuranceFundStakeAccountSubscriber';
|
|
24
|
+
export * from './accounts/pollingHighLeverageModeConfigAccountSubscriber';
|
|
23
25
|
export * from './accounts/basicUserAccountSubscriber';
|
|
24
26
|
export * from './accounts/oneShotUserAccountSubscriber';
|
|
25
27
|
export * from './accounts/types';
|
|
@@ -65,6 +67,7 @@ export * from './math/tiers';
|
|
|
65
67
|
export * from './marinade';
|
|
66
68
|
export * from './orderParams';
|
|
67
69
|
export * from './slot/SlotSubscriber';
|
|
70
|
+
export * from './slot/SlothashSubscriber';
|
|
68
71
|
export * from './wallet';
|
|
69
72
|
export * from './keypair';
|
|
70
73
|
export * from './types';
|
|
@@ -105,6 +108,7 @@ export * from './dlob/DLOBApiClient';
|
|
|
105
108
|
export * from './dlob/types';
|
|
106
109
|
export * from './dlob/orderBookLevels';
|
|
107
110
|
export * from './userMap/userMap';
|
|
111
|
+
export * from './userMap/referrerMap';
|
|
108
112
|
export * from './userMap/userStatsMap';
|
|
109
113
|
export * from './userMap/userMapConfig';
|
|
110
114
|
export * from './math/bankruptcy';
|
package/src/memcmp.ts
CHANGED
|
@@ -56,3 +56,30 @@ export function getUserWithName(name: string): MemcmpFilter {
|
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
export function getUserStatsFilter(): MemcmpFilter {
|
|
61
|
+
return {
|
|
62
|
+
memcmp: {
|
|
63
|
+
offset: 0,
|
|
64
|
+
bytes: bs58.encode(BorshAccountsCoder.accountDiscriminator('UserStats')),
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function getUserStatsIsReferredFilter(): MemcmpFilter {
|
|
70
|
+
return {
|
|
71
|
+
memcmp: {
|
|
72
|
+
offset: 188,
|
|
73
|
+
bytes: bs58.encode(Buffer.from(Uint8Array.from([2]))),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getUserStatsIsReferredOrReferrerFilter(): MemcmpFilter {
|
|
79
|
+
return {
|
|
80
|
+
memcmp: {
|
|
81
|
+
offset: 188,
|
|
82
|
+
bytes: bs58.encode(Buffer.from(Uint8Array.from([3]))),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Commitment,
|
|
3
|
+
Connection,
|
|
4
|
+
SYSVAR_SLOT_HASHES_PUBKEY,
|
|
5
|
+
} from '@solana/web3.js';
|
|
6
|
+
import { bs58 } from '@coral-xyz/anchor/dist/cjs/utils/bytes';
|
|
7
|
+
import { BN } from '@coral-xyz/anchor';
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
10
|
+
type SlothashSubscriberConfig = {
|
|
11
|
+
resubTimeoutMs?: number;
|
|
12
|
+
commitment?: Commitment;
|
|
13
|
+
}; // for future customization
|
|
14
|
+
|
|
15
|
+
export type Slothash = {
|
|
16
|
+
slot: number;
|
|
17
|
+
hash: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export class SlothashSubscriber {
|
|
21
|
+
currentSlothash: Slothash;
|
|
22
|
+
subscriptionId: number;
|
|
23
|
+
commitment: Commitment;
|
|
24
|
+
|
|
25
|
+
// Reconnection
|
|
26
|
+
timeoutId?: NodeJS.Timeout;
|
|
27
|
+
resubTimeoutMs?: number;
|
|
28
|
+
isUnsubscribing = false;
|
|
29
|
+
receivingData = false;
|
|
30
|
+
|
|
31
|
+
public constructor(
|
|
32
|
+
private connection: Connection,
|
|
33
|
+
config?: SlothashSubscriberConfig
|
|
34
|
+
) {
|
|
35
|
+
this.resubTimeoutMs = config?.resubTimeoutMs;
|
|
36
|
+
this.commitment = config?.commitment ?? 'processed';
|
|
37
|
+
if (this.resubTimeoutMs < 1000) {
|
|
38
|
+
console.log(
|
|
39
|
+
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public async subscribe(): Promise<void> {
|
|
45
|
+
if (this.subscriptionId != null) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const currentAccountData = await this.connection.getAccountInfo(
|
|
50
|
+
SYSVAR_SLOT_HASHES_PUBKEY,
|
|
51
|
+
this.commitment
|
|
52
|
+
);
|
|
53
|
+
if (currentAccountData == null) {
|
|
54
|
+
throw new Error('Failed to retrieve current slot hash');
|
|
55
|
+
}
|
|
56
|
+
this.currentSlothash = deserializeSlothash(currentAccountData.data);
|
|
57
|
+
|
|
58
|
+
this.subscriptionId = this.connection.onAccountChange(
|
|
59
|
+
SYSVAR_SLOT_HASHES_PUBKEY,
|
|
60
|
+
(slothashInfo, context) => {
|
|
61
|
+
if (!this.currentSlothash || this.currentSlothash.slot < context.slot) {
|
|
62
|
+
if (this.resubTimeoutMs && !this.isUnsubscribing) {
|
|
63
|
+
this.receivingData = true;
|
|
64
|
+
clearTimeout(this.timeoutId);
|
|
65
|
+
this.setTimeout();
|
|
66
|
+
}
|
|
67
|
+
this.currentSlothash = deserializeSlothash(slothashInfo.data);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
this.commitment
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (this.resubTimeoutMs) {
|
|
74
|
+
this.receivingData = true;
|
|
75
|
+
this.setTimeout();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private setTimeout(): void {
|
|
80
|
+
this.timeoutId = setTimeout(async () => {
|
|
81
|
+
if (this.isUnsubscribing) {
|
|
82
|
+
// If we are in the process of unsubscribing, do not attempt to resubscribe
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.receivingData) {
|
|
87
|
+
console.log(
|
|
88
|
+
`No new slot in ${this.resubTimeoutMs}ms, slot subscriber resubscribing`
|
|
89
|
+
);
|
|
90
|
+
await this.unsubscribe(true);
|
|
91
|
+
this.receivingData = false;
|
|
92
|
+
await this.subscribe();
|
|
93
|
+
}
|
|
94
|
+
}, this.resubTimeoutMs);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public getSlothash(): Slothash {
|
|
98
|
+
return this.currentSlothash;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public async unsubscribe(onResub = false): Promise<void> {
|
|
102
|
+
if (!onResub) {
|
|
103
|
+
this.resubTimeoutMs = undefined;
|
|
104
|
+
}
|
|
105
|
+
this.isUnsubscribing = true;
|
|
106
|
+
clearTimeout(this.timeoutId);
|
|
107
|
+
this.timeoutId = undefined;
|
|
108
|
+
|
|
109
|
+
if (this.subscriptionId != null) {
|
|
110
|
+
await this.connection.removeSlotChangeListener(this.subscriptionId);
|
|
111
|
+
this.subscriptionId = undefined;
|
|
112
|
+
this.isUnsubscribing = false;
|
|
113
|
+
} else {
|
|
114
|
+
this.isUnsubscribing = false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function deserializeSlothash(data: Buffer): Slothash {
|
|
120
|
+
const slotNumber = new BN(data.subarray(8, 16), 10, 'le');
|
|
121
|
+
const hash = bs58.encode(data.subarray(16, 48));
|
|
122
|
+
return {
|
|
123
|
+
slot: slotNumber.toNumber(),
|
|
124
|
+
hash,
|
|
125
|
+
};
|
|
126
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -546,8 +546,9 @@ export type SwiftOrderRecord = {
|
|
|
546
546
|
user: PublicKey;
|
|
547
547
|
hash: string;
|
|
548
548
|
matchingOrderParams: OrderParams;
|
|
549
|
-
|
|
550
|
-
|
|
549
|
+
swiftOrderMaxSlot: BN;
|
|
550
|
+
swiftOrderUuid: Uint8Array;
|
|
551
|
+
userOrderId: number;
|
|
551
552
|
};
|
|
552
553
|
|
|
553
554
|
export type OrderRecord = {
|
|
@@ -1077,11 +1078,11 @@ export const DefaultOrderParams: OrderParams = {
|
|
|
1077
1078
|
export type SwiftServerMessage = {
|
|
1078
1079
|
slot: BN;
|
|
1079
1080
|
swiftOrderSignature: Uint8Array;
|
|
1081
|
+
uuid: Uint8Array; // From buffer of standard UUID string
|
|
1080
1082
|
};
|
|
1081
1083
|
|
|
1082
1084
|
export type SwiftOrderParamsMessage = {
|
|
1083
1085
|
swiftOrderParams: OptionalOrderParams;
|
|
1084
|
-
expectedOrderId: number;
|
|
1085
1086
|
subAccountId: number;
|
|
1086
1087
|
takeProfitOrderParams: SwiftTriggerOrderParams | null;
|
|
1087
1088
|
stopLossOrderParams: SwiftTriggerOrderParams | null;
|
package/src/user.ts
CHANGED
|
@@ -3475,6 +3475,10 @@ export class User {
|
|
|
3475
3475
|
|
|
3476
3476
|
let feeTierIndex = 0;
|
|
3477
3477
|
if (isVariant(marketType, 'perp')) {
|
|
3478
|
+
if (this.isHighLeverageMode()) {
|
|
3479
|
+
return state.perpFeeStructure.feeTiers[0];
|
|
3480
|
+
}
|
|
3481
|
+
|
|
3478
3482
|
const userStatsAccount: UserStatsAccount = this.driftClient
|
|
3479
3483
|
.getUserStats()
|
|
3480
3484
|
.getAccount();
|