@drift-labs/sdk 2.112.0-beta.6 → 2.112.0-beta.7
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/driftClient.d.ts +1 -0
- package/lib/browser/driftClient.js +16 -13
- package/lib/browser/types.d.ts +2 -1
- package/lib/node/driftClient.d.ts +1 -0
- package/lib/node/driftClient.js +16 -13
- package/lib/node/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/driftClient.ts +14 -9
- package/src/types.ts +5 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.112.0-beta.
|
|
1
|
+
2.112.0-beta.7
|
|
@@ -125,6 +125,7 @@ export declare class DriftClient {
|
|
|
125
125
|
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
126
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
127
|
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
128
|
+
private getTxVersionForNewWallet;
|
|
128
129
|
/**
|
|
129
130
|
* Update the wallet to use for drift transactions and linked user account
|
|
130
131
|
* @param newWallet
|
|
@@ -110,7 +110,8 @@ class DriftClient {
|
|
|
110
110
|
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
111
111
|
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
112
112
|
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
113
|
-
this.txVersion =
|
|
113
|
+
this.txVersion =
|
|
114
|
+
(_h = config.txVersion) !== null && _h !== void 0 ? _h : this.getTxVersionForNewWallet(config.wallet);
|
|
114
115
|
this.txParams = {
|
|
115
116
|
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
116
117
|
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
@@ -395,6 +396,14 @@ class DriftClient {
|
|
|
395
396
|
this.lookupTableAccounts = lookupTableAccounts;
|
|
396
397
|
return lookupTableAccounts;
|
|
397
398
|
}
|
|
399
|
+
getTxVersionForNewWallet(newWallet) {
|
|
400
|
+
var _a, _b, _c;
|
|
401
|
+
if (!(newWallet === null || newWallet === void 0 ? void 0 : newWallet.supportedTransactionVersions))
|
|
402
|
+
return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
403
|
+
const walletSupportsVersionedTxns = ((_a = newWallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.has(0)) ||
|
|
404
|
+
((_c = (_b = newWallet.supportedTransactionVersions) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1;
|
|
405
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
406
|
+
}
|
|
398
407
|
/**
|
|
399
408
|
* Update the wallet to use for drift transactions and linked user account
|
|
400
409
|
* @param newWallet
|
|
@@ -403,7 +412,7 @@ class DriftClient {
|
|
|
403
412
|
* @param includeDelegates
|
|
404
413
|
*/
|
|
405
414
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
406
|
-
var _a
|
|
415
|
+
var _a;
|
|
407
416
|
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
408
417
|
// @ts-ignore
|
|
409
418
|
newWallet, this.opts);
|
|
@@ -419,10 +428,7 @@ class DriftClient {
|
|
|
419
428
|
this.activeSubAccountId = activeSubAccountId;
|
|
420
429
|
this.userStatsAccountPublicKey = undefined;
|
|
421
430
|
this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
|
|
422
|
-
|
|
423
|
-
//@ts-expect-error
|
|
424
|
-
((_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 1;
|
|
425
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
431
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
426
432
|
if (includeDelegates && subAccountIds) {
|
|
427
433
|
throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
|
|
428
434
|
}
|
|
@@ -438,7 +444,7 @@ class DriftClient {
|
|
|
438
444
|
? new Map([[this.authority.toString(), subAccountIds]])
|
|
439
445
|
: new Map();
|
|
440
446
|
/* Reset user stats account */
|
|
441
|
-
if ((
|
|
447
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
442
448
|
await this.userStats.unsubscribe();
|
|
443
449
|
}
|
|
444
450
|
this.userStats = undefined;
|
|
@@ -467,19 +473,16 @@ class DriftClient {
|
|
|
467
473
|
* @param emulateAuthority
|
|
468
474
|
*/
|
|
469
475
|
async emulateAccount(emulateAuthority) {
|
|
470
|
-
var _a
|
|
476
|
+
var _a;
|
|
471
477
|
this.skipLoadUsers = false;
|
|
472
478
|
// Update provider for txSender with new wallet details
|
|
473
479
|
this.authority = emulateAuthority;
|
|
474
480
|
this.userStatsAccountPublicKey = undefined;
|
|
475
481
|
this.includeDelegates = true;
|
|
476
|
-
|
|
477
|
-
//@ts-ignore
|
|
478
|
-
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
479
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
482
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
480
483
|
this.authoritySubAccountMap = new Map();
|
|
481
484
|
/* Reset user stats account */
|
|
482
|
-
if ((
|
|
485
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
483
486
|
await this.userStats.unsubscribe();
|
|
484
487
|
}
|
|
485
488
|
this.userStats = undefined;
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { Keypair, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { Keypair, PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
5
5
|
import { BN } from '.';
|
|
6
6
|
export type MappedRecord<A extends Record<string, unknown>, B> = {
|
|
7
7
|
[K in keyof A]: B;
|
|
@@ -1262,6 +1262,7 @@ export interface IWallet {
|
|
|
1262
1262
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1263
1263
|
publicKey: PublicKey;
|
|
1264
1264
|
payer?: Keypair;
|
|
1265
|
+
supportedTransactionVersions?: ReadonlySet<TransactionVersion> | null | undefined;
|
|
1265
1266
|
}
|
|
1266
1267
|
export interface IVersionedWallet {
|
|
1267
1268
|
signVersionedTransaction(tx: VersionedTransaction): Promise<VersionedTransaction>;
|
|
@@ -125,6 +125,7 @@ export declare class DriftClient {
|
|
|
125
125
|
/** @deprecated use fetchAllLookupTableAccounts() */
|
|
126
126
|
fetchMarketLookupTableAccount(): Promise<AddressLookupTableAccount>;
|
|
127
127
|
fetchAllLookupTableAccounts(): Promise<AddressLookupTableAccount[]>;
|
|
128
|
+
private getTxVersionForNewWallet;
|
|
128
129
|
/**
|
|
129
130
|
* Update the wallet to use for drift transactions and linked user account
|
|
130
131
|
* @param newWallet
|
package/lib/node/driftClient.js
CHANGED
|
@@ -110,7 +110,8 @@ class DriftClient {
|
|
|
110
110
|
this.authority = (_e = config.authority) !== null && _e !== void 0 ? _e : this.wallet.publicKey;
|
|
111
111
|
this.activeSubAccountId = (_f = config.activeSubAccountId) !== null && _f !== void 0 ? _f : 0;
|
|
112
112
|
this.skipLoadUsers = (_g = config.skipLoadUsers) !== null && _g !== void 0 ? _g : false;
|
|
113
|
-
this.txVersion =
|
|
113
|
+
this.txVersion =
|
|
114
|
+
(_h = config.txVersion) !== null && _h !== void 0 ? _h : this.getTxVersionForNewWallet(config.wallet);
|
|
114
115
|
this.txParams = {
|
|
115
116
|
computeUnits: (_k = (_j = config.txParams) === null || _j === void 0 ? void 0 : _j.computeUnits) !== null && _k !== void 0 ? _k : 600000,
|
|
116
117
|
computeUnitsPrice: (_m = (_l = config.txParams) === null || _l === void 0 ? void 0 : _l.computeUnitsPrice) !== null && _m !== void 0 ? _m : 0,
|
|
@@ -395,6 +396,14 @@ class DriftClient {
|
|
|
395
396
|
this.lookupTableAccounts = lookupTableAccounts;
|
|
396
397
|
return lookupTableAccounts;
|
|
397
398
|
}
|
|
399
|
+
getTxVersionForNewWallet(newWallet) {
|
|
400
|
+
var _a, _b, _c;
|
|
401
|
+
if (!(newWallet === null || newWallet === void 0 ? void 0 : newWallet.supportedTransactionVersions))
|
|
402
|
+
return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
403
|
+
const walletSupportsVersionedTxns = ((_a = newWallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.has(0)) ||
|
|
404
|
+
((_c = (_b = newWallet.supportedTransactionVersions) === null || _b === void 0 ? void 0 : _b.size) !== null && _c !== void 0 ? _c : 0) > 1;
|
|
405
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
406
|
+
}
|
|
398
407
|
/**
|
|
399
408
|
* Update the wallet to use for drift transactions and linked user account
|
|
400
409
|
* @param newWallet
|
|
@@ -403,7 +412,7 @@ class DriftClient {
|
|
|
403
412
|
* @param includeDelegates
|
|
404
413
|
*/
|
|
405
414
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
406
|
-
var _a
|
|
415
|
+
var _a;
|
|
407
416
|
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
408
417
|
// @ts-ignore
|
|
409
418
|
newWallet, this.opts);
|
|
@@ -419,10 +428,7 @@ class DriftClient {
|
|
|
419
428
|
this.activeSubAccountId = activeSubAccountId;
|
|
420
429
|
this.userStatsAccountPublicKey = undefined;
|
|
421
430
|
this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
|
|
422
|
-
|
|
423
|
-
//@ts-expect-error
|
|
424
|
-
((_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 1;
|
|
425
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
431
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
426
432
|
if (includeDelegates && subAccountIds) {
|
|
427
433
|
throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
|
|
428
434
|
}
|
|
@@ -438,7 +444,7 @@ class DriftClient {
|
|
|
438
444
|
? new Map([[this.authority.toString(), subAccountIds]])
|
|
439
445
|
: new Map();
|
|
440
446
|
/* Reset user stats account */
|
|
441
|
-
if ((
|
|
447
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
442
448
|
await this.userStats.unsubscribe();
|
|
443
449
|
}
|
|
444
450
|
this.userStats = undefined;
|
|
@@ -467,19 +473,16 @@ class DriftClient {
|
|
|
467
473
|
* @param emulateAuthority
|
|
468
474
|
*/
|
|
469
475
|
async emulateAccount(emulateAuthority) {
|
|
470
|
-
var _a
|
|
476
|
+
var _a;
|
|
471
477
|
this.skipLoadUsers = false;
|
|
472
478
|
// Update provider for txSender with new wallet details
|
|
473
479
|
this.authority = emulateAuthority;
|
|
474
480
|
this.userStatsAccountPublicKey = undefined;
|
|
475
481
|
this.includeDelegates = true;
|
|
476
|
-
|
|
477
|
-
//@ts-ignore
|
|
478
|
-
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
479
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
482
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
480
483
|
this.authoritySubAccountMap = new Map();
|
|
481
484
|
/* Reset user stats account */
|
|
482
|
-
if ((
|
|
485
|
+
if ((_a = this.userStats) === null || _a === void 0 ? void 0 : _a.isSubscribed) {
|
|
483
486
|
await this.userStats.unsubscribe();
|
|
484
487
|
}
|
|
485
488
|
this.userStats = undefined;
|
package/lib/node/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
|
-
import { Keypair, PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
import { Keypair, PublicKey, Transaction, TransactionVersion, VersionedTransaction } from '@solana/web3.js';
|
|
5
5
|
import { BN } from '.';
|
|
6
6
|
export type MappedRecord<A extends Record<string, unknown>, B> = {
|
|
7
7
|
[K in keyof A]: B;
|
|
@@ -1262,6 +1262,7 @@ export interface IWallet {
|
|
|
1262
1262
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1263
1263
|
publicKey: PublicKey;
|
|
1264
1264
|
payer?: Keypair;
|
|
1265
|
+
supportedTransactionVersions?: ReadonlySet<TransactionVersion> | null | undefined;
|
|
1265
1266
|
}
|
|
1266
1267
|
export interface IVersionedWallet {
|
|
1267
1268
|
signVersionedTransaction(tx: VersionedTransaction): Promise<VersionedTransaction>;
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -278,7 +278,8 @@ export class DriftClient {
|
|
|
278
278
|
this.authority = config.authority ?? this.wallet.publicKey;
|
|
279
279
|
this.activeSubAccountId = config.activeSubAccountId ?? 0;
|
|
280
280
|
this.skipLoadUsers = config.skipLoadUsers ?? false;
|
|
281
|
-
this.txVersion =
|
|
281
|
+
this.txVersion =
|
|
282
|
+
config.txVersion ?? this.getTxVersionForNewWallet(config.wallet);
|
|
282
283
|
this.txParams = {
|
|
283
284
|
computeUnits: config.txParams?.computeUnits ?? 600_000,
|
|
284
285
|
computeUnitsPrice: config.txParams?.computeUnitsPrice ?? 0,
|
|
@@ -732,6 +733,16 @@ export class DriftClient {
|
|
|
732
733
|
return lookupTableAccounts;
|
|
733
734
|
}
|
|
734
735
|
|
|
736
|
+
private getTxVersionForNewWallet(newWallet: IWallet) {
|
|
737
|
+
if (!newWallet?.supportedTransactionVersions) return 0; // Assume versioned txs supported if wallet doesn't have a supportedTransactionVersions property
|
|
738
|
+
|
|
739
|
+
const walletSupportsVersionedTxns =
|
|
740
|
+
newWallet.supportedTransactionVersions?.has(0) ||
|
|
741
|
+
(newWallet.supportedTransactionVersions?.size ?? 0) > 1;
|
|
742
|
+
|
|
743
|
+
return walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
744
|
+
}
|
|
745
|
+
|
|
735
746
|
/**
|
|
736
747
|
* Update the wallet to use for drift transactions and linked user account
|
|
737
748
|
* @param newWallet
|
|
@@ -769,10 +780,7 @@ export class DriftClient {
|
|
|
769
780
|
this.activeSubAccountId = activeSubAccountId;
|
|
770
781
|
this.userStatsAccountPublicKey = undefined;
|
|
771
782
|
this.includeDelegates = includeDelegates ?? false;
|
|
772
|
-
|
|
773
|
-
//@ts-expect-error
|
|
774
|
-
(this.wallet.supportedTransactionVersions?.size ?? 0) > 1;
|
|
775
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
783
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
776
784
|
|
|
777
785
|
if (includeDelegates && subAccountIds) {
|
|
778
786
|
throw new Error(
|
|
@@ -842,10 +850,7 @@ export class DriftClient {
|
|
|
842
850
|
this.authority = emulateAuthority;
|
|
843
851
|
this.userStatsAccountPublicKey = undefined;
|
|
844
852
|
this.includeDelegates = true;
|
|
845
|
-
|
|
846
|
-
//@ts-ignore
|
|
847
|
-
this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
|
|
848
|
-
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
853
|
+
this.txVersion = this.getTxVersionForNewWallet(this.wallet);
|
|
849
854
|
|
|
850
855
|
this.authoritySubAccountMap = new Map<string, number[]>();
|
|
851
856
|
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Keypair,
|
|
3
3
|
PublicKey,
|
|
4
4
|
Transaction,
|
|
5
|
+
TransactionVersion,
|
|
5
6
|
VersionedTransaction,
|
|
6
7
|
} from '@solana/web3.js';
|
|
7
8
|
import { BN, ZERO } from '.';
|
|
@@ -1232,6 +1233,10 @@ export interface IWallet {
|
|
|
1232
1233
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
1233
1234
|
publicKey: PublicKey;
|
|
1234
1235
|
payer?: Keypair;
|
|
1236
|
+
supportedTransactionVersions?:
|
|
1237
|
+
| ReadonlySet<TransactionVersion>
|
|
1238
|
+
| null
|
|
1239
|
+
| undefined;
|
|
1235
1240
|
}
|
|
1236
1241
|
export interface IVersionedWallet {
|
|
1237
1242
|
signVersionedTransaction(
|