@drift-labs/sdk 2.94.0-beta.0 → 2.94.0-beta.1
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/driftClient.d.ts +8 -1
- package/lib/driftClient.js +40 -3
- package/package.json +1 -1
- package/src/driftClient.ts +48 -3
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.94.0-beta.
|
|
1
|
+
2.94.0-beta.1
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -121,12 +121,19 @@ export declare class DriftClient {
|
|
|
121
121
|
* @param includeDelegates
|
|
122
122
|
*/
|
|
123
123
|
updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number, includeDelegates?: boolean, authoritySubaccountMap?: Map<string, number[]>): Promise<boolean>;
|
|
124
|
+
/**
|
|
125
|
+
* Update the subscribed accounts to a given authority, while leaving the
|
|
126
|
+
* connected wallet intact. This allows a user to emulate another user's
|
|
127
|
+
* account on the UI and sign permissionless transactions with their own wallet.
|
|
128
|
+
* @param emulateAuthority
|
|
129
|
+
*/
|
|
130
|
+
emulateAccount(emulateAuthority: PublicKey): Promise<boolean>;
|
|
124
131
|
switchActiveUser(subAccountId: number, authority?: PublicKey): Promise<void>;
|
|
125
132
|
addUser(subAccountId: number, authority?: PublicKey, userAccount?: UserAccount): Promise<boolean>;
|
|
126
133
|
/**
|
|
127
134
|
* Adds and subscribes to users based on params set by the constructor or by updateWallet.
|
|
128
135
|
*/
|
|
129
|
-
addAndSubscribeToUsers(): Promise<boolean>;
|
|
136
|
+
addAndSubscribeToUsers(authority?: PublicKey): Promise<boolean>;
|
|
130
137
|
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo, txParams?: TxParams): Promise<[TransactionSignature, PublicKey]>;
|
|
131
138
|
getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
132
139
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
package/lib/driftClient.js
CHANGED
|
@@ -407,6 +407,43 @@ class DriftClient {
|
|
|
407
407
|
}
|
|
408
408
|
return success;
|
|
409
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Update the subscribed accounts to a given authority, while leaving the
|
|
412
|
+
* connected wallet intact. This allows a user to emulate another user's
|
|
413
|
+
* account on the UI and sign permissionless transactions with their own wallet.
|
|
414
|
+
* @param emulateAuthority
|
|
415
|
+
*/
|
|
416
|
+
async emulateAccount(emulateAuthority) {
|
|
417
|
+
var _a, _b, _c;
|
|
418
|
+
this.skipLoadUsers = false;
|
|
419
|
+
// Update provider for txSender with new wallet details
|
|
420
|
+
this.authority = emulateAuthority;
|
|
421
|
+
this.userStatsAccountPublicKey = undefined;
|
|
422
|
+
this.includeDelegates = true;
|
|
423
|
+
const walletSupportsVersionedTxns =
|
|
424
|
+
//@ts-ignore
|
|
425
|
+
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
426
|
+
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
427
|
+
this.authoritySubAccountMap = new Map();
|
|
428
|
+
/* Reset user stats account */
|
|
429
|
+
if ((_c = this.userStats) === null || _c === void 0 ? void 0 : _c.isSubscribed) {
|
|
430
|
+
await this.userStats.unsubscribe();
|
|
431
|
+
}
|
|
432
|
+
this.userStats = undefined;
|
|
433
|
+
this.userStats = new userStats_1.UserStats({
|
|
434
|
+
driftClient: this,
|
|
435
|
+
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
436
|
+
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
437
|
+
});
|
|
438
|
+
await this.userStats.subscribe();
|
|
439
|
+
let success = true;
|
|
440
|
+
if (this.isSubscribed) {
|
|
441
|
+
await Promise.all(this.unsubscribeUsers());
|
|
442
|
+
this.users.clear();
|
|
443
|
+
success = await this.addAndSubscribeToUsers(emulateAuthority);
|
|
444
|
+
}
|
|
445
|
+
return success;
|
|
446
|
+
}
|
|
410
447
|
async switchActiveUser(subAccountId, authority) {
|
|
411
448
|
var _a;
|
|
412
449
|
const authorityChanged = authority && !((_a = this.authority) === null || _a === void 0 ? void 0 : _a.equals(authority));
|
|
@@ -445,7 +482,7 @@ class DriftClient {
|
|
|
445
482
|
/**
|
|
446
483
|
* Adds and subscribes to users based on params set by the constructor or by updateWallet.
|
|
447
484
|
*/
|
|
448
|
-
async addAndSubscribeToUsers() {
|
|
485
|
+
async addAndSubscribeToUsers(authority) {
|
|
449
486
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
450
487
|
// save the rpc calls if driftclient is initialized without a real wallet
|
|
451
488
|
if (this.skipLoadUsers)
|
|
@@ -465,9 +502,9 @@ class DriftClient {
|
|
|
465
502
|
else {
|
|
466
503
|
let userAccounts = [];
|
|
467
504
|
let delegatedAccounts = [];
|
|
468
|
-
const userAccountsPromise = this.getUserAccountsForAuthority(this.wallet.publicKey);
|
|
505
|
+
const userAccountsPromise = this.getUserAccountsForAuthority(authority !== null && authority !== void 0 ? authority : this.wallet.publicKey);
|
|
469
506
|
if (this.includeDelegates) {
|
|
470
|
-
const delegatedAccountsPromise = this.getUserAccountsForDelegate(this.wallet.publicKey);
|
|
507
|
+
const delegatedAccountsPromise = this.getUserAccountsForDelegate(authority !== null && authority !== void 0 ? authority : this.wallet.publicKey);
|
|
471
508
|
[userAccounts, delegatedAccounts] = await Promise.all([
|
|
472
509
|
userAccountsPromise,
|
|
473
510
|
delegatedAccountsPromise,
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -714,6 +714,51 @@ export class DriftClient {
|
|
|
714
714
|
return success;
|
|
715
715
|
}
|
|
716
716
|
|
|
717
|
+
/**
|
|
718
|
+
* Update the subscribed accounts to a given authority, while leaving the
|
|
719
|
+
* connected wallet intact. This allows a user to emulate another user's
|
|
720
|
+
* account on the UI and sign permissionless transactions with their own wallet.
|
|
721
|
+
* @param emulateAuthority
|
|
722
|
+
*/
|
|
723
|
+
public async emulateAccount(emulateAuthority: PublicKey): Promise<boolean> {
|
|
724
|
+
this.skipLoadUsers = false;
|
|
725
|
+
// Update provider for txSender with new wallet details
|
|
726
|
+
this.authority = emulateAuthority;
|
|
727
|
+
this.userStatsAccountPublicKey = undefined;
|
|
728
|
+
this.includeDelegates = true;
|
|
729
|
+
const walletSupportsVersionedTxns =
|
|
730
|
+
//@ts-ignore
|
|
731
|
+
this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
|
|
732
|
+
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
733
|
+
|
|
734
|
+
this.authoritySubAccountMap = new Map<string, number[]>();
|
|
735
|
+
|
|
736
|
+
/* Reset user stats account */
|
|
737
|
+
if (this.userStats?.isSubscribed) {
|
|
738
|
+
await this.userStats.unsubscribe();
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
this.userStats = undefined;
|
|
742
|
+
|
|
743
|
+
this.userStats = new UserStats({
|
|
744
|
+
driftClient: this,
|
|
745
|
+
userStatsAccountPublicKey: this.getUserStatsAccountPublicKey(),
|
|
746
|
+
accountSubscription: this.userStatsAccountSubscriptionConfig,
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
await this.userStats.subscribe();
|
|
750
|
+
|
|
751
|
+
let success = true;
|
|
752
|
+
|
|
753
|
+
if (this.isSubscribed) {
|
|
754
|
+
await Promise.all(this.unsubscribeUsers());
|
|
755
|
+
this.users.clear();
|
|
756
|
+
success = await this.addAndSubscribeToUsers(emulateAuthority);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return success;
|
|
760
|
+
}
|
|
761
|
+
|
|
717
762
|
public async switchActiveUser(subAccountId: number, authority?: PublicKey) {
|
|
718
763
|
const authorityChanged = authority && !this.authority?.equals(authority);
|
|
719
764
|
|
|
@@ -771,7 +816,7 @@ export class DriftClient {
|
|
|
771
816
|
/**
|
|
772
817
|
* Adds and subscribes to users based on params set by the constructor or by updateWallet.
|
|
773
818
|
*/
|
|
774
|
-
public async addAndSubscribeToUsers(): Promise<boolean> {
|
|
819
|
+
public async addAndSubscribeToUsers(authority?: PublicKey): Promise<boolean> {
|
|
775
820
|
// save the rpc calls if driftclient is initialized without a real wallet
|
|
776
821
|
if (this.skipLoadUsers) return true;
|
|
777
822
|
|
|
@@ -799,12 +844,12 @@ export class DriftClient {
|
|
|
799
844
|
let delegatedAccounts = [];
|
|
800
845
|
|
|
801
846
|
const userAccountsPromise = this.getUserAccountsForAuthority(
|
|
802
|
-
this.wallet.publicKey
|
|
847
|
+
authority ?? this.wallet.publicKey
|
|
803
848
|
);
|
|
804
849
|
|
|
805
850
|
if (this.includeDelegates) {
|
|
806
851
|
const delegatedAccountsPromise = this.getUserAccountsForDelegate(
|
|
807
|
-
this.wallet.publicKey
|
|
852
|
+
authority ?? this.wallet.publicKey
|
|
808
853
|
);
|
|
809
854
|
[userAccounts, delegatedAccounts] = await Promise.all([
|
|
810
855
|
userAccountsPromise,
|