@drift-labs/sdk 2.62.0-beta.0 → 2.62.0-beta.2
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/accounts/webSocketAccountSubscriber.js +4 -0
- package/lib/driftClient.d.ts +5 -1
- package/lib/driftClient.js +12 -5
- package/lib/slot/SlotSubscriber.js +4 -0
- package/package.json +1 -1
- package/src/accounts/webSocketAccountSubscriber.ts +6 -0
- package/src/driftClient.ts +24 -6
- package/src/slot/SlotSubscriber.ts +6 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.62.0-beta.
|
|
1
|
+
2.62.0-beta.2
|
|
@@ -10,6 +10,9 @@ class WebSocketAccountSubscriber {
|
|
|
10
10
|
this.accountPublicKey = accountPublicKey;
|
|
11
11
|
this.decodeBufferFn = decodeBuffer;
|
|
12
12
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
13
|
+
if (this.resubTimeoutMs < 1000) {
|
|
14
|
+
console.log('resubTimeoutMs should be at least 1000ms to avoid spamming resub');
|
|
15
|
+
}
|
|
13
16
|
this.receivingData = false;
|
|
14
17
|
this.commitment =
|
|
15
18
|
commitment !== null && commitment !== void 0 ? commitment : this.program.provider.opts.commitment;
|
|
@@ -34,6 +37,7 @@ class WebSocketAccountSubscriber {
|
|
|
34
37
|
}
|
|
35
38
|
}, this.commitment);
|
|
36
39
|
if (this.resubTimeoutMs) {
|
|
40
|
+
this.receivingData = true;
|
|
37
41
|
this.setTimeout();
|
|
38
42
|
}
|
|
39
43
|
}
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -129,7 +129,11 @@ export declare class DriftClient {
|
|
|
129
129
|
subAccountId: number;
|
|
130
130
|
}[]): Promise<TransactionSignature>;
|
|
131
131
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
132
|
-
updateUserAdvancedLp(
|
|
132
|
+
updateUserAdvancedLp(updates: {
|
|
133
|
+
advancedLp: boolean;
|
|
134
|
+
subAccountId: number;
|
|
135
|
+
}[]): Promise<TransactionSignature>;
|
|
136
|
+
getUpdateAdvancedDlpIx(advancedLp: boolean, subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
|
|
133
137
|
fetchAllUserAccounts(includeIdle?: boolean): Promise<ProgramAccount<UserAccount>[]>;
|
|
134
138
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
135
139
|
getUserAccountsAndAddressesForAuthority(authority: PublicKey): Promise<ProgramAccount<UserAccount>[]>;
|
package/lib/driftClient.js
CHANGED
|
@@ -600,15 +600,22 @@ class DriftClient {
|
|
|
600
600
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
601
601
|
return txSig;
|
|
602
602
|
}
|
|
603
|
-
async updateUserAdvancedLp(
|
|
604
|
-
const
|
|
603
|
+
async updateUserAdvancedLp(updates) {
|
|
604
|
+
const ixs = await Promise.all(updates.map(async ({ advancedLp, subAccountId }) => {
|
|
605
|
+
return await this.getUpdateAdvancedDlpIx(advancedLp, subAccountId);
|
|
606
|
+
}));
|
|
607
|
+
const tx = await this.buildTransaction(ixs, this.txParams);
|
|
608
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
609
|
+
return txSig;
|
|
610
|
+
}
|
|
611
|
+
async getUpdateAdvancedDlpIx(advancedLp, subAccountId) {
|
|
612
|
+
const ix = await this.program.instruction.updateUserAdvancedLp(subAccountId, advancedLp, {
|
|
605
613
|
accounts: {
|
|
606
|
-
user:
|
|
614
|
+
user: (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId),
|
|
607
615
|
authority: this.wallet.publicKey,
|
|
608
616
|
},
|
|
609
617
|
});
|
|
610
|
-
|
|
611
|
-
return txSig;
|
|
618
|
+
return ix;
|
|
612
619
|
}
|
|
613
620
|
async fetchAllUserAccounts(includeIdle = true) {
|
|
614
621
|
let filters = undefined;
|
|
@@ -9,6 +9,9 @@ class SlotSubscriber {
|
|
|
9
9
|
this.receivingData = false;
|
|
10
10
|
this.eventEmitter = new events_1.EventEmitter();
|
|
11
11
|
this.resubTimeoutMs = config === null || config === void 0 ? void 0 : config.resubTimeoutMs;
|
|
12
|
+
if (this.resubTimeoutMs < 1000) {
|
|
13
|
+
console.log('resubTimeoutMs should be at least 1000ms to avoid spamming resub');
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
async subscribe() {
|
|
14
17
|
if (this.subscriptionId != null) {
|
|
@@ -27,6 +30,7 @@ class SlotSubscriber {
|
|
|
27
30
|
}
|
|
28
31
|
});
|
|
29
32
|
if (this.resubTimeoutMs) {
|
|
33
|
+
this.receivingData = true;
|
|
30
34
|
this.setTimeout();
|
|
31
35
|
}
|
|
32
36
|
}
|
package/package.json
CHANGED
|
@@ -34,6 +34,11 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
34
34
|
this.accountPublicKey = accountPublicKey;
|
|
35
35
|
this.decodeBufferFn = decodeBuffer;
|
|
36
36
|
this.resubTimeoutMs = resubTimeoutMs;
|
|
37
|
+
if (this.resubTimeoutMs < 1000) {
|
|
38
|
+
console.log(
|
|
39
|
+
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
40
|
+
);
|
|
41
|
+
}
|
|
37
42
|
this.receivingData = false;
|
|
38
43
|
this.commitment =
|
|
39
44
|
commitment ?? (this.program.provider as AnchorProvider).opts.commitment;
|
|
@@ -65,6 +70,7 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
65
70
|
);
|
|
66
71
|
|
|
67
72
|
if (this.resubTimeoutMs) {
|
|
73
|
+
this.receivingData = true;
|
|
68
74
|
this.setTimeout();
|
|
69
75
|
}
|
|
70
76
|
}
|
package/src/driftClient.ts
CHANGED
|
@@ -1025,22 +1025,40 @@ export class DriftClient {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
|
|
1027
1027
|
public async updateUserAdvancedLp(
|
|
1028
|
-
advancedLp: boolean
|
|
1029
|
-
subAccountId = 0
|
|
1028
|
+
updates: { advancedLp: boolean; subAccountId: number }[]
|
|
1030
1029
|
): Promise<TransactionSignature> {
|
|
1031
|
-
const
|
|
1030
|
+
const ixs = await Promise.all(
|
|
1031
|
+
updates.map(async ({ advancedLp, subAccountId }) => {
|
|
1032
|
+
return await this.getUpdateAdvancedDlpIx(advancedLp, subAccountId);
|
|
1033
|
+
})
|
|
1034
|
+
);
|
|
1035
|
+
|
|
1036
|
+
const tx = await this.buildTransaction(ixs, this.txParams);
|
|
1037
|
+
|
|
1038
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1039
|
+
return txSig;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
public async getUpdateAdvancedDlpIx(
|
|
1043
|
+
advancedLp: boolean,
|
|
1044
|
+
subAccountId: number
|
|
1045
|
+
) {
|
|
1046
|
+
const ix = await this.program.instruction.updateUserAdvancedLp(
|
|
1032
1047
|
subAccountId,
|
|
1033
1048
|
advancedLp,
|
|
1034
1049
|
{
|
|
1035
1050
|
accounts: {
|
|
1036
|
-
user:
|
|
1051
|
+
user: getUserAccountPublicKeySync(
|
|
1052
|
+
this.program.programId,
|
|
1053
|
+
this.wallet.publicKey,
|
|
1054
|
+
subAccountId
|
|
1055
|
+
),
|
|
1037
1056
|
authority: this.wallet.publicKey,
|
|
1038
1057
|
},
|
|
1039
1058
|
}
|
|
1040
1059
|
);
|
|
1041
1060
|
|
|
1042
|
-
|
|
1043
|
-
return txSig;
|
|
1061
|
+
return ix;
|
|
1044
1062
|
}
|
|
1045
1063
|
|
|
1046
1064
|
public async fetchAllUserAccounts(
|
|
@@ -28,6 +28,11 @@ export class SlotSubscriber {
|
|
|
28
28
|
) {
|
|
29
29
|
this.eventEmitter = new EventEmitter();
|
|
30
30
|
this.resubTimeoutMs = config?.resubTimeoutMs;
|
|
31
|
+
if (this.resubTimeoutMs < 1000) {
|
|
32
|
+
console.log(
|
|
33
|
+
'resubTimeoutMs should be at least 1000ms to avoid spamming resub'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
public async subscribe(): Promise<void> {
|
|
@@ -50,6 +55,7 @@ export class SlotSubscriber {
|
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
if (this.resubTimeoutMs) {
|
|
58
|
+
this.receivingData = true;
|
|
53
59
|
this.setTimeout();
|
|
54
60
|
}
|
|
55
61
|
}
|