@drift-labs/sdk 2.48.0-beta.17 → 2.48.0-beta.19
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/orderSubscriber/OrderSubscriber.d.ts +2 -0
- package/lib/orderSubscriber/OrderSubscriber.js +3 -1
- package/lib/orderSubscriber/WebsocketSubscription.d.ts +4 -1
- package/lib/orderSubscriber/WebsocketSubscription.js +3 -2
- package/lib/orderSubscriber/types.d.ts +3 -1
- package/lib/user.js +2 -2
- package/package.json +1 -1
- package/src/orderSubscriber/OrderSubscriber.ts +5 -2
- package/src/orderSubscriber/WebsocketSubscription.ts +6 -2
- package/src/orderSubscriber/types.ts +3 -1
- package/src/user.ts +2 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.48.0-beta.
|
|
1
|
+
2.48.0-beta.19
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DriftClient } from '../driftClient';
|
|
3
3
|
import { UserAccount } from '../types';
|
|
4
|
+
import { Commitment } from '@solana/web3.js';
|
|
4
5
|
import { DLOB } from '../dlob/DLOB';
|
|
5
6
|
import { OrderSubscriberConfig, OrderSubscriberEvents } from './types';
|
|
6
7
|
import { PollingSubscription } from './PollingSubscription';
|
|
@@ -14,6 +15,7 @@ export declare class OrderSubscriber {
|
|
|
14
15
|
userAccount: UserAccount;
|
|
15
16
|
}>;
|
|
16
17
|
subscription: PollingSubscription | WebsocketSubscription;
|
|
18
|
+
commitment: Commitment;
|
|
17
19
|
eventEmitter: StrictEventEmitter<EventEmitter, OrderSubscriberEvents>;
|
|
18
20
|
fetchPromise?: Promise<void>;
|
|
19
21
|
fetchPromiseResolver: () => void;
|
|
@@ -12,6 +12,7 @@ class OrderSubscriber {
|
|
|
12
12
|
constructor(config) {
|
|
13
13
|
this.usersAccounts = new Map();
|
|
14
14
|
this.driftClient = config.driftClient;
|
|
15
|
+
this.commitment = config.subscriptionConfig.commitment || 'processed';
|
|
15
16
|
if (config.subscriptionConfig.type === 'polling') {
|
|
16
17
|
this.subscription = new PollingSubscription_1.PollingSubscription({
|
|
17
18
|
orderSubscriber: this,
|
|
@@ -21,6 +22,7 @@ class OrderSubscriber {
|
|
|
21
22
|
else {
|
|
22
23
|
this.subscription = new WebsocketSubscription_1.WebsocketSubscription({
|
|
23
24
|
orderSubscriber: this,
|
|
25
|
+
commitment: this.commitment,
|
|
24
26
|
skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
|
|
25
27
|
resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
|
|
26
28
|
});
|
|
@@ -41,7 +43,7 @@ class OrderSubscriber {
|
|
|
41
43
|
const rpcRequestArgs = [
|
|
42
44
|
this.driftClient.program.programId.toBase58(),
|
|
43
45
|
{
|
|
44
|
-
commitment: this.
|
|
46
|
+
commitment: this.commitment,
|
|
45
47
|
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getUserWithOrderFilter)()],
|
|
46
48
|
encoding: 'base64',
|
|
47
49
|
withContext: true,
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { OrderSubscriber } from './OrderSubscriber';
|
|
2
|
+
import { Commitment } from '@solana/web3.js';
|
|
2
3
|
export declare class WebsocketSubscription {
|
|
3
4
|
private orderSubscriber;
|
|
5
|
+
private commitment;
|
|
4
6
|
private skipInitialLoad;
|
|
5
7
|
private resubTimeoutMs?;
|
|
6
8
|
private subscriber;
|
|
7
|
-
constructor({ orderSubscriber, skipInitialLoad, resubTimeoutMs, }: {
|
|
9
|
+
constructor({ orderSubscriber, commitment, skipInitialLoad, resubTimeoutMs, }: {
|
|
8
10
|
orderSubscriber: OrderSubscriber;
|
|
11
|
+
commitment: Commitment;
|
|
9
12
|
skipInitialLoad?: boolean;
|
|
10
13
|
resubTimeoutMs?: number;
|
|
11
14
|
});
|
|
@@ -4,8 +4,9 @@ exports.WebsocketSubscription = void 0;
|
|
|
4
4
|
const memcmp_1 = require("../memcmp");
|
|
5
5
|
const webSocketProgramAccountSubscriber_1 = require("../accounts/webSocketProgramAccountSubscriber");
|
|
6
6
|
class WebsocketSubscription {
|
|
7
|
-
constructor({ orderSubscriber, skipInitialLoad = false, resubTimeoutMs, }) {
|
|
7
|
+
constructor({ orderSubscriber, commitment, skipInitialLoad = false, resubTimeoutMs, }) {
|
|
8
8
|
this.orderSubscriber = orderSubscriber;
|
|
9
|
+
this.commitment = commitment;
|
|
9
10
|
this.skipInitialLoad = skipInitialLoad;
|
|
10
11
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
11
12
|
}
|
|
@@ -13,7 +14,7 @@ class WebsocketSubscription {
|
|
|
13
14
|
if (!this.subscriber) {
|
|
14
15
|
this.subscriber = new webSocketProgramAccountSubscriber_1.WebSocketProgramAccountSubscriber('OrderSubscriber', 'User', this.orderSubscriber.driftClient.program, this.orderSubscriber.driftClient.program.account.user.coder.accounts.decode.bind(this.orderSubscriber.driftClient.program.account.user.coder.accounts), {
|
|
15
16
|
filters: [(0, memcmp_1.getUserFilter)(), (0, memcmp_1.getNonIdleUserFilter)()],
|
|
16
|
-
commitment: this.
|
|
17
|
+
commitment: this.commitment,
|
|
17
18
|
}, this.resubTimeoutMs);
|
|
18
19
|
}
|
|
19
20
|
await this.subscriber.subscribe((accountId, account, context) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { Order, UserAccount } from '../types';
|
|
3
3
|
import { DriftClient } from '../driftClient';
|
|
4
4
|
export type OrderSubscriberConfig = {
|
|
@@ -6,10 +6,12 @@ export type OrderSubscriberConfig = {
|
|
|
6
6
|
subscriptionConfig: {
|
|
7
7
|
type: 'polling';
|
|
8
8
|
frequency: number;
|
|
9
|
+
commitment?: Commitment;
|
|
9
10
|
} | {
|
|
10
11
|
type: 'websocket';
|
|
11
12
|
skipInitialLoad?: boolean;
|
|
12
13
|
resubTimeoutMs?: number;
|
|
14
|
+
commitment?: Commitment;
|
|
13
15
|
};
|
|
14
16
|
};
|
|
15
17
|
export interface OrderSubscriberEvents {
|
package/lib/user.js
CHANGED
|
@@ -22,7 +22,7 @@ class User {
|
|
|
22
22
|
this._isSubscribed = val;
|
|
23
23
|
}
|
|
24
24
|
constructor(config) {
|
|
25
|
-
var _a, _b;
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
26
|
this._isSubscribed = false;
|
|
27
27
|
this.driftClient = config.driftClient;
|
|
28
28
|
this.userAccountPublicKey = config.userAccountPublicKey;
|
|
@@ -33,7 +33,7 @@ class User {
|
|
|
33
33
|
this.accountSubscriber = config.accountSubscription.userAccountSubscriber;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, config.accountSubscription.resubTimeoutMs, config.accountSubscription.commitment);
|
|
36
|
+
this.accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.driftClient.program, config.userAccountPublicKey, (_c = config.accountSubscription) === null || _c === void 0 ? void 0 : _c.resubTimeoutMs, (_d = config.accountSubscription) === null || _d === void 0 ? void 0 : _d.commitment);
|
|
37
37
|
}
|
|
38
38
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DriftClient } from '../driftClient';
|
|
2
2
|
import { UserAccount } from '../types';
|
|
3
3
|
import { getUserFilter, getUserWithOrderFilter } from '../memcmp';
|
|
4
|
-
import { PublicKey, RpcResponseAndContext } from '@solana/web3.js';
|
|
4
|
+
import { Commitment, PublicKey, RpcResponseAndContext } from '@solana/web3.js';
|
|
5
5
|
import { Buffer } from 'buffer';
|
|
6
6
|
import { DLOB } from '../dlob/DLOB';
|
|
7
7
|
import { OrderSubscriberConfig, OrderSubscriberEvents } from './types';
|
|
@@ -14,6 +14,7 @@ export class OrderSubscriber {
|
|
|
14
14
|
driftClient: DriftClient;
|
|
15
15
|
usersAccounts = new Map<string, { slot: number; userAccount: UserAccount }>();
|
|
16
16
|
subscription: PollingSubscription | WebsocketSubscription;
|
|
17
|
+
commitment: Commitment;
|
|
17
18
|
eventEmitter: StrictEventEmitter<EventEmitter, OrderSubscriberEvents>;
|
|
18
19
|
|
|
19
20
|
fetchPromise?: Promise<void>;
|
|
@@ -23,6 +24,7 @@ export class OrderSubscriber {
|
|
|
23
24
|
|
|
24
25
|
constructor(config: OrderSubscriberConfig) {
|
|
25
26
|
this.driftClient = config.driftClient;
|
|
27
|
+
this.commitment = config.subscriptionConfig.commitment || 'processed';
|
|
26
28
|
if (config.subscriptionConfig.type === 'polling') {
|
|
27
29
|
this.subscription = new PollingSubscription({
|
|
28
30
|
orderSubscriber: this,
|
|
@@ -31,6 +33,7 @@ export class OrderSubscriber {
|
|
|
31
33
|
} else {
|
|
32
34
|
this.subscription = new WebsocketSubscription({
|
|
33
35
|
orderSubscriber: this,
|
|
36
|
+
commitment: this.commitment,
|
|
34
37
|
skipInitialLoad: config.subscriptionConfig.skipInitialLoad,
|
|
35
38
|
resubTimeoutMs: config.subscriptionConfig.resubTimeoutMs,
|
|
36
39
|
});
|
|
@@ -55,7 +58,7 @@ export class OrderSubscriber {
|
|
|
55
58
|
const rpcRequestArgs = [
|
|
56
59
|
this.driftClient.program.programId.toBase58(),
|
|
57
60
|
{
|
|
58
|
-
commitment: this.
|
|
61
|
+
commitment: this.commitment,
|
|
59
62
|
filters: [getUserFilter(), getUserWithOrderFilter()],
|
|
60
63
|
encoding: 'base64',
|
|
61
64
|
withContext: true,
|
|
@@ -2,10 +2,11 @@ import { OrderSubscriber } from './OrderSubscriber';
|
|
|
2
2
|
import { getNonIdleUserFilter, getUserFilter } from '../memcmp';
|
|
3
3
|
import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramAccountSubscriber';
|
|
4
4
|
import { UserAccount } from '../types';
|
|
5
|
-
import { Context, PublicKey } from '@solana/web3.js';
|
|
5
|
+
import { Commitment, Context, PublicKey } from '@solana/web3.js';
|
|
6
6
|
|
|
7
7
|
export class WebsocketSubscription {
|
|
8
8
|
private orderSubscriber: OrderSubscriber;
|
|
9
|
+
private commitment: Commitment;
|
|
9
10
|
private skipInitialLoad: boolean;
|
|
10
11
|
private resubTimeoutMs?: number;
|
|
11
12
|
|
|
@@ -13,14 +14,17 @@ export class WebsocketSubscription {
|
|
|
13
14
|
|
|
14
15
|
constructor({
|
|
15
16
|
orderSubscriber,
|
|
17
|
+
commitment,
|
|
16
18
|
skipInitialLoad = false,
|
|
17
19
|
resubTimeoutMs,
|
|
18
20
|
}: {
|
|
19
21
|
orderSubscriber: OrderSubscriber;
|
|
22
|
+
commitment: Commitment;
|
|
20
23
|
skipInitialLoad?: boolean;
|
|
21
24
|
resubTimeoutMs?: number;
|
|
22
25
|
}) {
|
|
23
26
|
this.orderSubscriber = orderSubscriber;
|
|
27
|
+
this.commitment = commitment;
|
|
24
28
|
this.skipInitialLoad = skipInitialLoad;
|
|
25
29
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
26
30
|
}
|
|
@@ -36,7 +40,7 @@ export class WebsocketSubscription {
|
|
|
36
40
|
),
|
|
37
41
|
{
|
|
38
42
|
filters: [getUserFilter(), getNonIdleUserFilter()],
|
|
39
|
-
commitment: this.
|
|
43
|
+
commitment: this.commitment,
|
|
40
44
|
},
|
|
41
45
|
this.resubTimeoutMs
|
|
42
46
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { Commitment, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { Order, UserAccount } from '../types';
|
|
3
3
|
import { DriftClient } from '../driftClient';
|
|
4
4
|
|
|
@@ -8,11 +8,13 @@ export type OrderSubscriberConfig = {
|
|
|
8
8
|
| {
|
|
9
9
|
type: 'polling';
|
|
10
10
|
frequency: number;
|
|
11
|
+
commitment?: Commitment;
|
|
11
12
|
}
|
|
12
13
|
| {
|
|
13
14
|
type: 'websocket';
|
|
14
15
|
skipInitialLoad?: boolean;
|
|
15
16
|
resubTimeoutMs?: number;
|
|
17
|
+
commitment?: Commitment;
|
|
16
18
|
};
|
|
17
19
|
};
|
|
18
20
|
|
package/src/user.ts
CHANGED
|
@@ -113,8 +113,8 @@ export class User {
|
|
|
113
113
|
this.accountSubscriber = new WebSocketUserAccountSubscriber(
|
|
114
114
|
config.driftClient.program,
|
|
115
115
|
config.userAccountPublicKey,
|
|
116
|
-
config.accountSubscription
|
|
117
|
-
config.accountSubscription
|
|
116
|
+
config.accountSubscription?.resubTimeoutMs,
|
|
117
|
+
config.accountSubscription?.commitment
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|