@drift-labs/sdk 2.82.0-beta.2 → 2.82.0-beta.20
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/README.md +65 -47
- package/VERSION +1 -1
- package/lib/accounts/types.d.ts +4 -3
- package/lib/accounts/webSocketAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketAccountSubscriber.js +16 -9
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +5 -5
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.d.ts +2 -2
- package/lib/accounts/webSocketInsuranceFundStakeAccountSubscriber.js +5 -3
- package/lib/accounts/webSocketProgramAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketProgramAccountSubscriber.js +15 -9
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +3 -3
- package/lib/accounts/webSocketUserAccountSubscriber.js +3 -3
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +3 -3
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +3 -3
- package/lib/auctionSubscriber/auctionSubscriber.d.ts +2 -2
- package/lib/auctionSubscriber/auctionSubscriber.js +3 -3
- package/lib/auctionSubscriber/types.d.ts +1 -0
- package/lib/clock/clockSubscriber.d.ts +29 -0
- package/lib/clock/clockSubscriber.js +74 -0
- package/lib/constants/perpMarkets.js +2 -2
- package/lib/constants/spotMarkets.js +11 -0
- package/lib/dlob/DLOB.js +2 -2
- package/lib/dlob/orderBookLevels.js +1 -0
- package/lib/driftClient.d.ts +21 -14
- package/lib/driftClient.js +192 -255
- package/lib/driftClientConfig.d.ts +3 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/jupiter/jupiterClient.d.ts +2 -1
- package/lib/jupiter/jupiterClient.js +10 -6
- package/lib/math/exchangeStatus.d.ts +2 -2
- package/lib/math/orders.d.ts +1 -1
- package/lib/math/orders.js +2 -2
- package/lib/orderSubscriber/OrderSubscriber.js +6 -3
- package/lib/orderSubscriber/WebsocketSubscription.d.ts +4 -3
- package/lib/orderSubscriber/WebsocketSubscription.js +3 -3
- package/lib/orderSubscriber/types.d.ts +1 -0
- package/lib/priorityFee/driftPriorityFeeMethod.d.ts +13 -3
- package/lib/priorityFee/driftPriorityFeeMethod.js +2 -2
- package/lib/priorityFee/index.d.ts +2 -0
- package/lib/priorityFee/index.js +2 -0
- package/lib/priorityFee/priorityFeeSubscriber.d.ts +1 -4
- package/lib/priorityFee/priorityFeeSubscriber.js +5 -4
- package/lib/priorityFee/priorityFeeSubscriberMap.d.ts +48 -0
- package/lib/priorityFee/priorityFeeSubscriberMap.js +88 -0
- package/lib/priorityFee/types.d.ts +8 -3
- package/lib/priorityFee/types.js +2 -1
- package/lib/tx/baseTxSender.d.ts +8 -6
- package/lib/tx/baseTxSender.js +9 -51
- package/lib/tx/fastSingleTxSender.d.ts +6 -6
- package/lib/tx/fastSingleTxSender.js +3 -31
- package/lib/tx/forwardOnlyTxSender.d.ts +4 -2
- package/lib/tx/forwardOnlyTxSender.js +2 -1
- package/lib/tx/retryTxSender.d.ts +4 -2
- package/lib/tx/retryTxSender.js +2 -1
- package/lib/tx/txHandler.d.ts +138 -0
- package/lib/tx/txHandler.js +396 -0
- package/lib/tx/txParamProcessor.d.ts +6 -10
- package/lib/tx/txParamProcessor.js +13 -17
- package/lib/tx/types.d.ts +8 -7
- package/lib/tx/types.js +12 -1
- package/lib/tx/whileValidTxSender.d.ts +7 -6
- package/lib/tx/whileValidTxSender.js +7 -28
- package/lib/types.d.ts +24 -4
- package/lib/types.js +10 -1
- package/lib/user.d.ts +0 -10
- package/lib/user.js +6 -29
- package/lib/userConfig.d.ts +1 -0
- package/lib/userMap/WebsocketSubscription.d.ts +4 -3
- package/lib/userMap/WebsocketSubscription.js +3 -3
- package/lib/userMap/userMap.js +4 -1
- package/lib/userMap/userMapConfig.d.ts +1 -0
- package/lib/userStats.js +6 -3
- package/lib/userStatsConfig.d.ts +1 -0
- package/lib/util/chainClock.d.ts +17 -0
- package/lib/util/chainClock.js +29 -0
- package/package.json +3 -3
- package/src/accounts/types.ts +5 -4
- package/src/accounts/webSocketAccountSubscriber.ts +35 -23
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +7 -6
- package/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +6 -4
- package/src/accounts/webSocketProgramAccountSubscriber.ts +32 -22
- package/src/accounts/webSocketUserAccountSubscriber.ts +5 -4
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +5 -4
- package/src/auctionSubscriber/auctionSubscriber.ts +10 -4
- package/src/auctionSubscriber/types.ts +1 -0
- package/src/clock/clockSubscriber.ts +113 -0
- package/src/constants/perpMarkets.ts +2 -2
- package/src/constants/spotMarkets.ts +13 -0
- package/src/dlob/DLOB.ts +2 -2
- package/src/dlob/orderBookLevels.ts +2 -0
- package/src/driftClient.ts +295 -386
- package/src/driftClientConfig.ts +3 -0
- package/src/index.ts +2 -0
- package/src/jupiter/jupiterClient.ts +15 -6
- package/src/math/exchangeStatus.ts +2 -1
- package/src/math/orders.ts +3 -2
- package/src/orderSubscriber/OrderSubscriber.ts +4 -1
- package/src/orderSubscriber/WebsocketSubscription.ts +6 -5
- package/src/orderSubscriber/types.ts +1 -0
- package/src/priorityFee/driftPriorityFeeMethod.ts +16 -4
- package/src/priorityFee/index.ts +2 -0
- package/src/priorityFee/priorityFeeSubscriber.ts +7 -7
- package/src/priorityFee/priorityFeeSubscriberMap.ts +112 -0
- package/src/priorityFee/types.ts +16 -3
- package/src/tx/baseTxSender.ts +29 -79
- package/src/tx/fastSingleTxSender.ts +10 -55
- package/src/tx/forwardOnlyTxSender.ts +5 -1
- package/src/tx/retryTxSender.ts +5 -1
- package/src/tx/txHandler.ts +625 -0
- package/src/tx/txParamProcessor.ts +16 -28
- package/src/tx/types.ts +14 -18
- package/src/tx/whileValidTxSender.ts +24 -48
- package/src/types.ts +26 -2
- package/src/user.ts +7 -32
- package/src/userConfig.ts +1 -0
- package/src/userMap/WebsocketSubscription.ts +6 -5
- package/src/userMap/userMap.ts +4 -1
- package/src/userMap/userMapConfig.ts +1 -0
- package/src/userStats.ts +4 -1
- package/src/userStatsConfig.ts +1 -0
- package/src/util/chainClock.ts +41 -0
- package/tests/dlob/helpers.ts +3 -0
- package/lib/tx/utils.d.ts +0 -6
- package/lib/tx/utils.js +0 -39
- package/src/tx/utils.ts +0 -64
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DataAndSlot,
|
|
3
|
+
BufferAndSlot,
|
|
4
|
+
ProgramAccountSubscriber,
|
|
5
|
+
ResubOpts,
|
|
6
|
+
} from './types';
|
|
2
7
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
3
8
|
import {
|
|
4
9
|
Commitment,
|
|
@@ -25,7 +30,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
25
30
|
buffer: Buffer
|
|
26
31
|
) => void;
|
|
27
32
|
listenerId?: number;
|
|
28
|
-
|
|
33
|
+
resubOpts?: ResubOpts;
|
|
29
34
|
isUnsubscribing = false;
|
|
30
35
|
timeoutId?: NodeJS.Timeout;
|
|
31
36
|
options: { filters: MemcmpFilter[]; commitment?: Commitment };
|
|
@@ -40,14 +45,14 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
40
45
|
options: { filters: MemcmpFilter[]; commitment?: Commitment } = {
|
|
41
46
|
filters: [],
|
|
42
47
|
},
|
|
43
|
-
|
|
48
|
+
resubOpts?: ResubOpts
|
|
44
49
|
) {
|
|
45
50
|
this.subscriptionName = subscriptionName;
|
|
46
51
|
this.accountDiscriminator = accountDiscriminator;
|
|
47
52
|
this.program = program;
|
|
48
53
|
this.decodeBuffer = decodeBufferFn;
|
|
49
|
-
this.
|
|
50
|
-
if (this.resubTimeoutMs < 1000) {
|
|
54
|
+
this.resubOpts = resubOpts;
|
|
55
|
+
if (this.resubOpts?.resubTimeoutMs < 1000) {
|
|
51
56
|
console.log(
|
|
52
57
|
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
53
58
|
);
|
|
@@ -73,7 +78,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
73
78
|
this.listenerId = this.program.provider.connection.onProgramAccountChange(
|
|
74
79
|
this.program.programId,
|
|
75
80
|
(keyedAccountInfo, context) => {
|
|
76
|
-
if (this.resubTimeoutMs) {
|
|
81
|
+
if (this.resubOpts?.resubTimeoutMs) {
|
|
77
82
|
this.receivingData = true;
|
|
78
83
|
clearTimeout(this.timeoutId);
|
|
79
84
|
this.handleRpcResponse(context, keyedAccountInfo);
|
|
@@ -87,7 +92,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
87
92
|
this.options.filters
|
|
88
93
|
);
|
|
89
94
|
|
|
90
|
-
if (this.resubTimeoutMs) {
|
|
95
|
+
if (this.resubOpts?.resubTimeoutMs) {
|
|
91
96
|
this.receivingData = true;
|
|
92
97
|
this.setTimeout();
|
|
93
98
|
}
|
|
@@ -97,21 +102,26 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
97
102
|
if (!this.onChange) {
|
|
98
103
|
throw new Error('onChange callback function must be set');
|
|
99
104
|
}
|
|
100
|
-
this.timeoutId = setTimeout(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
this.timeoutId = setTimeout(
|
|
106
|
+
async () => {
|
|
107
|
+
if (this.isUnsubscribing) {
|
|
108
|
+
// If we are in the process of unsubscribing, do not attempt to resubscribe
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
105
111
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
if (this.receivingData) {
|
|
113
|
+
if (this.resubOpts?.logResubMessages) {
|
|
114
|
+
console.log(
|
|
115
|
+
`No ws data from ${this.subscriptionName} in ${this.resubOpts?.resubTimeoutMs}ms, resubscribing`
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
await this.unsubscribe(true);
|
|
119
|
+
this.receivingData = false;
|
|
120
|
+
await this.subscribe(this.onChange);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
this.resubOpts?.resubTimeoutMs
|
|
124
|
+
);
|
|
115
125
|
}
|
|
116
126
|
|
|
117
127
|
handleRpcResponse(
|
|
@@ -163,7 +173,7 @@ export class WebSocketProgramAccountSubscriber<T>
|
|
|
163
173
|
|
|
164
174
|
unsubscribe(onResub = false): Promise<void> {
|
|
165
175
|
if (!onResub) {
|
|
166
|
-
this.resubTimeoutMs = undefined;
|
|
176
|
+
this.resubOpts.resubTimeoutMs = undefined;
|
|
167
177
|
}
|
|
168
178
|
this.isUnsubscribing = true;
|
|
169
179
|
clearTimeout(this.timeoutId);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
NotSubscribedError,
|
|
5
5
|
UserAccountEvents,
|
|
6
6
|
UserAccountSubscriber,
|
|
7
|
+
ResubOpts,
|
|
7
8
|
} from './types';
|
|
8
9
|
import { Program } from '@coral-xyz/anchor';
|
|
9
10
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -14,7 +15,7 @@ import { UserAccount } from '../types';
|
|
|
14
15
|
|
|
15
16
|
export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
16
17
|
isSubscribed: boolean;
|
|
17
|
-
|
|
18
|
+
resubOpts?: ResubOpts;
|
|
18
19
|
commitment?: Commitment;
|
|
19
20
|
program: Program;
|
|
20
21
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
@@ -25,14 +26,14 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
25
26
|
public constructor(
|
|
26
27
|
program: Program,
|
|
27
28
|
userAccountPublicKey: PublicKey,
|
|
28
|
-
|
|
29
|
+
resubOpts?: ResubOpts,
|
|
29
30
|
commitment?: Commitment
|
|
30
31
|
) {
|
|
31
32
|
this.isSubscribed = false;
|
|
32
33
|
this.program = program;
|
|
34
|
+
this.resubOpts = resubOpts;
|
|
33
35
|
this.userAccountPublicKey = userAccountPublicKey;
|
|
34
36
|
this.eventEmitter = new EventEmitter();
|
|
35
|
-
this.reconnectTimeoutMs = reconnectTimeoutMs;
|
|
36
37
|
this.commitment = commitment;
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -46,7 +47,7 @@ export class WebSocketUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
46
47
|
this.program,
|
|
47
48
|
this.userAccountPublicKey,
|
|
48
49
|
undefined,
|
|
49
|
-
this.
|
|
50
|
+
this.resubOpts,
|
|
50
51
|
this.commitment
|
|
51
52
|
);
|
|
52
53
|
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
NotSubscribedError,
|
|
5
5
|
UserStatsAccountSubscriber,
|
|
6
6
|
UserStatsAccountEvents,
|
|
7
|
+
ResubOpts,
|
|
7
8
|
} from './types';
|
|
8
9
|
import { Program } from '@coral-xyz/anchor';
|
|
9
10
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -16,7 +17,7 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
16
17
|
implements UserStatsAccountSubscriber
|
|
17
18
|
{
|
|
18
19
|
isSubscribed: boolean;
|
|
19
|
-
|
|
20
|
+
resubOpts?: ResubOpts;
|
|
20
21
|
commitment?: Commitment;
|
|
21
22
|
program: Program;
|
|
22
23
|
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
@@ -27,14 +28,14 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
27
28
|
public constructor(
|
|
28
29
|
program: Program,
|
|
29
30
|
userStatsAccountPublicKey: PublicKey,
|
|
30
|
-
|
|
31
|
+
resubOpts?: ResubOpts,
|
|
31
32
|
commitment?: Commitment
|
|
32
33
|
) {
|
|
33
34
|
this.isSubscribed = false;
|
|
34
35
|
this.program = program;
|
|
35
36
|
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
36
37
|
this.eventEmitter = new EventEmitter();
|
|
37
|
-
this.
|
|
38
|
+
this.resubOpts = resubOpts;
|
|
38
39
|
this.commitment = commitment;
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -48,7 +49,7 @@ export class WebSocketUserStatsAccountSubscriber
|
|
|
48
49
|
this.program,
|
|
49
50
|
this.userStatsAccountPublicKey,
|
|
50
51
|
undefined,
|
|
51
|
-
this.
|
|
52
|
+
this.resubOpts,
|
|
52
53
|
this.commitment
|
|
53
54
|
);
|
|
54
55
|
|
|
@@ -6,20 +6,26 @@ import { EventEmitter } from 'events';
|
|
|
6
6
|
import { UserAccount } from '../types';
|
|
7
7
|
import { ConfirmOptions, Context, PublicKey } from '@solana/web3.js';
|
|
8
8
|
import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramAccountSubscriber';
|
|
9
|
+
import { ResubOpts } from '../accounts/types';
|
|
9
10
|
|
|
10
11
|
export class AuctionSubscriber {
|
|
11
12
|
private driftClient: DriftClient;
|
|
12
13
|
private opts: ConfirmOptions;
|
|
13
|
-
private
|
|
14
|
+
private resubOpts?: ResubOpts;
|
|
14
15
|
|
|
15
16
|
eventEmitter: StrictEventEmitter<EventEmitter, AuctionSubscriberEvents>;
|
|
16
17
|
private subscriber: WebSocketProgramAccountSubscriber<UserAccount>;
|
|
17
18
|
|
|
18
|
-
constructor({
|
|
19
|
+
constructor({
|
|
20
|
+
driftClient,
|
|
21
|
+
opts,
|
|
22
|
+
resubTimeoutMs,
|
|
23
|
+
logResubMessages,
|
|
24
|
+
}: AuctionSubscriberConfig) {
|
|
19
25
|
this.driftClient = driftClient;
|
|
20
26
|
this.opts = opts || this.driftClient.opts;
|
|
21
27
|
this.eventEmitter = new EventEmitter();
|
|
22
|
-
this.
|
|
28
|
+
this.resubOpts = { resubTimeoutMs, logResubMessages };
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
public async subscribe() {
|
|
@@ -35,7 +41,7 @@ export class AuctionSubscriber {
|
|
|
35
41
|
filters: [getUserFilter(), getUserWithAuctionFilter()],
|
|
36
42
|
commitment: this.opts.commitment,
|
|
37
43
|
},
|
|
38
|
-
this.
|
|
44
|
+
this.resubOpts
|
|
39
45
|
);
|
|
40
46
|
}
|
|
41
47
|
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Commitment, Connection, SYSVAR_CLOCK_PUBKEY } from '@solana/web3.js';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import StrictEventEmitter from 'strict-event-emitter-types/types/src';
|
|
4
|
+
import { BN } from '..';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
7
|
+
type ClockSubscriberConfig = {
|
|
8
|
+
commitment: Commitment;
|
|
9
|
+
resubTimeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface ClockSubscriberEvent {
|
|
13
|
+
clockUpdate: (ts: number) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ClockSubscriber {
|
|
17
|
+
private latestSlot: number;
|
|
18
|
+
currentTs: number;
|
|
19
|
+
private subscriptionId: number;
|
|
20
|
+
commitment: Commitment;
|
|
21
|
+
eventEmitter: StrictEventEmitter<EventEmitter, ClockSubscriberEvent>;
|
|
22
|
+
|
|
23
|
+
// Reconnection
|
|
24
|
+
private timeoutId?: NodeJS.Timeout;
|
|
25
|
+
private resubTimeoutMs?: number;
|
|
26
|
+
private isUnsubscribing = false;
|
|
27
|
+
private receivingData = false;
|
|
28
|
+
|
|
29
|
+
public constructor(
|
|
30
|
+
private connection: Connection,
|
|
31
|
+
config?: ClockSubscriberConfig
|
|
32
|
+
) {
|
|
33
|
+
this.eventEmitter = new EventEmitter();
|
|
34
|
+
this.resubTimeoutMs = config?.resubTimeoutMs;
|
|
35
|
+
this.commitment = config?.commitment || 'confirmed';
|
|
36
|
+
if (this.resubTimeoutMs < 1000) {
|
|
37
|
+
console.log(
|
|
38
|
+
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async subscribe(): Promise<void> {
|
|
44
|
+
if (this.subscriptionId != null) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
this.subscriptionId = this.connection.onAccountChange(
|
|
49
|
+
SYSVAR_CLOCK_PUBKEY,
|
|
50
|
+
(acctInfo, context) => {
|
|
51
|
+
if (!this.latestSlot || this.latestSlot < context.slot) {
|
|
52
|
+
if (this.resubTimeoutMs && !this.isUnsubscribing) {
|
|
53
|
+
this.receivingData = true;
|
|
54
|
+
clearTimeout(this.timeoutId);
|
|
55
|
+
this.setTimeout();
|
|
56
|
+
}
|
|
57
|
+
this.latestSlot = context.slot;
|
|
58
|
+
this.currentTs = new BN(
|
|
59
|
+
acctInfo.data.subarray(32, 39),
|
|
60
|
+
undefined,
|
|
61
|
+
'le'
|
|
62
|
+
).toNumber();
|
|
63
|
+
this.eventEmitter.emit('clockUpdate', this.currentTs);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
this.commitment
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (this.resubTimeoutMs) {
|
|
70
|
+
this.receivingData = true;
|
|
71
|
+
this.setTimeout();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private setTimeout(): void {
|
|
76
|
+
this.timeoutId = setTimeout(async () => {
|
|
77
|
+
if (this.isUnsubscribing) {
|
|
78
|
+
// If we are in the process of unsubscribing, do not attempt to resubscribe
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (this.receivingData) {
|
|
83
|
+
console.log(
|
|
84
|
+
`No new slot in ${this.resubTimeoutMs}ms, slot subscriber resubscribing`
|
|
85
|
+
);
|
|
86
|
+
await this.unsubscribe(true);
|
|
87
|
+
this.receivingData = false;
|
|
88
|
+
await this.subscribe();
|
|
89
|
+
}
|
|
90
|
+
}, this.resubTimeoutMs);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public getUnixTs(): number {
|
|
94
|
+
return this.currentTs;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public async unsubscribe(onResub = false): Promise<void> {
|
|
98
|
+
if (!onResub) {
|
|
99
|
+
this.resubTimeoutMs = undefined;
|
|
100
|
+
}
|
|
101
|
+
this.isUnsubscribing = true;
|
|
102
|
+
clearTimeout(this.timeoutId);
|
|
103
|
+
this.timeoutId = undefined;
|
|
104
|
+
|
|
105
|
+
if (this.subscriptionId != null) {
|
|
106
|
+
await this.connection.removeAccountChangeListener(this.subscriptionId);
|
|
107
|
+
this.subscriptionId = undefined;
|
|
108
|
+
this.isUnsubscribing = false;
|
|
109
|
+
} else {
|
|
110
|
+
this.isUnsubscribing = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -553,9 +553,9 @@ export const MainnetPerpMarkets: PerpMarketConfig[] = [
|
|
|
553
553
|
symbol: 'KMNO-PERP',
|
|
554
554
|
baseAssetSymbol: 'KMNO',
|
|
555
555
|
marketIndex: 28,
|
|
556
|
-
oracle: new PublicKey('
|
|
556
|
+
oracle: new PublicKey('6ynsvjkE2UoiRScbDx7ZxbBsyn7wyvg5P1vENvhtkG1C'),
|
|
557
557
|
launchTs: 1712240681000,
|
|
558
|
-
oracleSource: OracleSource.
|
|
558
|
+
oracleSource: OracleSource.SWITCHBOARD,
|
|
559
559
|
},
|
|
560
560
|
{
|
|
561
561
|
fullName: 'Tensor',
|
|
@@ -240,6 +240,19 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
240
240
|
),
|
|
241
241
|
launchTs: 1712593532000,
|
|
242
242
|
},
|
|
243
|
+
{
|
|
244
|
+
symbol: 'DRIFT',
|
|
245
|
+
marketIndex: 15,
|
|
246
|
+
oracle: new PublicKey('PeNpQeGEm9UEFJ6MBCMauY4WW4h3YxoESPWbsqVKucE'),
|
|
247
|
+
oracleSource: OracleSource.SWITCHBOARD,
|
|
248
|
+
mint: new PublicKey('DriFtupJYLTosbwoN8koMbEYSx54aFAVLddWsbksjwg7'),
|
|
249
|
+
precision: new BN(10).pow(SIX),
|
|
250
|
+
precisionExp: SIX,
|
|
251
|
+
phoenixMarket: new PublicKey(
|
|
252
|
+
'8BV6rrWsUabnTDA3dE6A69oUDJAj3hMhtBHTJyXB7czp'
|
|
253
|
+
),
|
|
254
|
+
launchTs: 1715860800000,
|
|
255
|
+
},
|
|
243
256
|
];
|
|
244
257
|
|
|
245
258
|
export const SpotMarkets: { [key in DriftEnv]: SpotMarketConfig[] } = {
|
package/src/dlob/DLOB.ts
CHANGED
|
@@ -985,7 +985,7 @@ export class DLOB {
|
|
|
985
985
|
|
|
986
986
|
for (const bidGenerator of bidGenerators) {
|
|
987
987
|
for (const bid of bidGenerator) {
|
|
988
|
-
if (isOrderExpired(bid.order, ts, true)) {
|
|
988
|
+
if (isOrderExpired(bid.order, ts, true, 25)) {
|
|
989
989
|
nodesToFill.push({
|
|
990
990
|
node: bid,
|
|
991
991
|
makerNodes: [],
|
|
@@ -996,7 +996,7 @@ export class DLOB {
|
|
|
996
996
|
|
|
997
997
|
for (const askGenerator of askGenerators) {
|
|
998
998
|
for (const ask of askGenerator) {
|
|
999
|
-
if (isOrderExpired(ask.order, ts, true)) {
|
|
999
|
+
if (isOrderExpired(ask.order, ts, true, 25)) {
|
|
1000
1000
|
nodesToFill.push({
|
|
1001
1001
|
node: ask,
|
|
1002
1002
|
makerNodes: [],
|