@drift-labs/sdk 2.42.0-beta.4 → 2.42.0-beta.6
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 +1 -1
- package/lib/driftClient.js +17 -20
- package/lib/types.d.ts +2 -2
- package/lib/types.js +2 -2
- package/package.json +1 -1
- package/src/driftClient.ts +21 -26
- package/src/types.ts +2 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.42.0-beta.
|
|
1
|
+
2.42.0-beta.6
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -269,7 +269,7 @@ export declare class DriftClient {
|
|
|
269
269
|
* @param bracketOrdersParams
|
|
270
270
|
* @returns
|
|
271
271
|
*/
|
|
272
|
-
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo
|
|
272
|
+
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[], txParams?: TxParams, bracketOrdersParams?: OptionalOrderParams[], referrerInfo?: ReferrerInfo): Promise<{
|
|
273
273
|
txSig: TransactionSignature;
|
|
274
274
|
signedFillTx: Transaction;
|
|
275
275
|
}>;
|
package/lib/driftClient.js
CHANGED
|
@@ -294,6 +294,7 @@ class DriftClient {
|
|
|
294
294
|
* @param includeDelegates
|
|
295
295
|
*/
|
|
296
296
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
297
|
+
var _a, _b;
|
|
297
298
|
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
298
299
|
// @ts-ignore
|
|
299
300
|
newWallet, this.opts);
|
|
@@ -308,6 +309,10 @@ class DriftClient {
|
|
|
308
309
|
this.activeSubAccountId = activeSubAccountId;
|
|
309
310
|
this.userStatsAccountPublicKey = undefined;
|
|
310
311
|
this.includeDelegates = includeDelegates !== null && includeDelegates !== void 0 ? includeDelegates : false;
|
|
312
|
+
const walletSupportsVersionedTxns =
|
|
313
|
+
//@ts-ignore
|
|
314
|
+
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
315
|
+
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
311
316
|
if (includeDelegates && subAccountIds) {
|
|
312
317
|
throw new Error('Can only pass one of includeDelegates or subAccountIds. If you want to specify subaccount ids for multiple authorities, pass authoritySubaccountMap instead');
|
|
313
318
|
}
|
|
@@ -341,7 +346,7 @@ class DriftClient {
|
|
|
341
346
|
}
|
|
342
347
|
async switchActiveUser(subAccountId, authority) {
|
|
343
348
|
var _a;
|
|
344
|
-
const authorityChanged = !((_a = this.authority) === null || _a === void 0 ? void 0 : _a.equals(authority));
|
|
349
|
+
const authorityChanged = authority && !((_a = this.authority) === null || _a === void 0 ? void 0 : _a.equals(authority));
|
|
345
350
|
this.activeSubAccountId = subAccountId;
|
|
346
351
|
this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
|
|
347
352
|
this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
|
|
@@ -939,28 +944,25 @@ class DriftClient {
|
|
|
939
944
|
* @param reduceOnly
|
|
940
945
|
*/
|
|
941
946
|
async deposit(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly = false) {
|
|
942
|
-
const tx = new web3_js_1.Transaction();
|
|
943
|
-
tx.add(web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
944
|
-
units: 600000,
|
|
945
|
-
}));
|
|
946
947
|
const additionalSigners = [];
|
|
947
948
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
948
949
|
const isSolMarket = spotMarketAccount.mint.equals(spotMarkets_1.WRAPPED_SOL_MINT);
|
|
949
950
|
const signerAuthority = this.wallet.publicKey;
|
|
950
951
|
const createWSOLTokenAccount = isSolMarket && associatedTokenAccount.equals(signerAuthority);
|
|
952
|
+
const instructions = [];
|
|
951
953
|
if (createWSOLTokenAccount) {
|
|
952
954
|
const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(amount, true);
|
|
953
955
|
associatedTokenAccount = pubkey;
|
|
954
|
-
|
|
955
|
-
tx.add(ix);
|
|
956
|
-
});
|
|
956
|
+
instructions.push(...ixs);
|
|
957
957
|
}
|
|
958
958
|
const depositCollateralIx = await this.getDepositInstruction(amount, marketIndex, associatedTokenAccount, subAccountId, reduceOnly, true);
|
|
959
|
-
|
|
959
|
+
instructions.push(depositCollateralIx);
|
|
960
960
|
// Close the wrapped sol account at the end of the transaction
|
|
961
961
|
if (createWSOLTokenAccount) {
|
|
962
|
-
|
|
962
|
+
instructions.push((0, spl_token_1.createCloseAccountInstruction)(associatedTokenAccount, signerAuthority, signerAuthority, []));
|
|
963
963
|
}
|
|
964
|
+
const txParams = { ...this.txParams, computeUnits: 600000 };
|
|
965
|
+
const tx = await this.buildTransaction(instructions, txParams);
|
|
964
966
|
const { txSig, slot } = await this.sendTransaction(tx, additionalSigners, this.opts);
|
|
965
967
|
this.spotMarketLastSlotCache.set(marketIndex, slot);
|
|
966
968
|
return txSig;
|
|
@@ -1363,8 +1365,7 @@ class DriftClient {
|
|
|
1363
1365
|
* @param bracketOrdersParams
|
|
1364
1366
|
* @returns
|
|
1365
1367
|
*/
|
|
1366
|
-
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo
|
|
1367
|
-
var _a, _b;
|
|
1368
|
+
async sendMarketOrderAndGetSignedFillTx(orderParams, userAccountPublicKey, userAccount, makerInfo, txParams, bracketOrdersParams = new Array(), referrerInfo) {
|
|
1368
1369
|
const marketIndex = orderParams.marketIndex;
|
|
1369
1370
|
const orderId = userAccount.nextOrderId;
|
|
1370
1371
|
const bracketOrderIxs = [];
|
|
@@ -1377,11 +1378,8 @@ class DriftClient {
|
|
|
1377
1378
|
orderId,
|
|
1378
1379
|
marketIndex,
|
|
1379
1380
|
}, makerInfo, referrerInfo);
|
|
1380
|
-
const walletSupportsVersionedTxns =
|
|
1381
|
-
//@ts-ignore
|
|
1382
|
-
(_b = (_a = this.wallet.supportedTransactionVersions) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0 > 1;
|
|
1383
1381
|
// use versioned transactions if there is a lookup table account and wallet is compatible
|
|
1384
|
-
if (
|
|
1382
|
+
if (this.txVersion === 0) {
|
|
1385
1383
|
const versionedMarketOrderTx = await this.buildTransaction([placePerpOrderIx].concat(bracketOrderIxs), txParams, 0);
|
|
1386
1384
|
const versionedFillTx = await this.buildTransaction([fillPerpOrderIx], txParams, 0);
|
|
1387
1385
|
const [signedVersionedMarketOrderTx, signedVersionedFillTx] = await this.provider.wallet.signAllTransactions([
|
|
@@ -3252,12 +3250,11 @@ class DriftClient {
|
|
|
3252
3250
|
return undefined;
|
|
3253
3251
|
}
|
|
3254
3252
|
sendTransaction(tx, additionalSigners, opts, preSigned) {
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
3253
|
+
if (tx instanceof web3_js_1.VersionedTransaction) {
|
|
3254
|
+
return this.txSender.sendVersionedTransaction(tx, additionalSigners, opts, preSigned);
|
|
3258
3255
|
}
|
|
3259
3256
|
else {
|
|
3260
|
-
return this.txSender.
|
|
3257
|
+
return this.txSender.send(tx, additionalSigners, opts, preSigned);
|
|
3261
3258
|
}
|
|
3262
3259
|
}
|
|
3263
3260
|
async buildTransaction(instructions, txParams, txVersion, lookupTables) {
|
package/lib/types.d.ts
CHANGED
|
@@ -317,10 +317,10 @@ export declare class StakeAction {
|
|
|
317
317
|
unstake: {};
|
|
318
318
|
};
|
|
319
319
|
static readonly UNSTAKE_TRANSFER: {
|
|
320
|
-
|
|
320
|
+
unstakeTransfer: {};
|
|
321
321
|
};
|
|
322
322
|
static readonly STAKE_TRANSFER: {
|
|
323
|
-
|
|
323
|
+
stakeTransfer: {};
|
|
324
324
|
};
|
|
325
325
|
}
|
|
326
326
|
export declare function isVariant(object: unknown, type: string): boolean;
|
package/lib/types.js
CHANGED
|
@@ -201,8 +201,8 @@ StakeAction.STAKE = { stake: {} };
|
|
|
201
201
|
StakeAction.UNSTAKE_REQUEST = { unstakeRequest: {} };
|
|
202
202
|
StakeAction.UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
|
|
203
203
|
StakeAction.UNSTAKE = { unstake: {} };
|
|
204
|
-
StakeAction.UNSTAKE_TRANSFER = {
|
|
205
|
-
StakeAction.STAKE_TRANSFER = {
|
|
204
|
+
StakeAction.UNSTAKE_TRANSFER = { unstakeTransfer: {} };
|
|
205
|
+
StakeAction.STAKE_TRANSFER = { stakeTransfer: {} };
|
|
206
206
|
function isVariant(object, type) {
|
|
207
207
|
return object.hasOwnProperty(type);
|
|
208
208
|
}
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -539,6 +539,10 @@ export class DriftClient {
|
|
|
539
539
|
this.activeSubAccountId = activeSubAccountId;
|
|
540
540
|
this.userStatsAccountPublicKey = undefined;
|
|
541
541
|
this.includeDelegates = includeDelegates ?? false;
|
|
542
|
+
const walletSupportsVersionedTxns =
|
|
543
|
+
//@ts-ignore
|
|
544
|
+
this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
|
|
545
|
+
this.txVersion = walletSupportsVersionedTxns ? 0 : 'legacy';
|
|
542
546
|
|
|
543
547
|
if (includeDelegates && subAccountIds) {
|
|
544
548
|
throw new Error(
|
|
@@ -589,7 +593,7 @@ export class DriftClient {
|
|
|
589
593
|
}
|
|
590
594
|
|
|
591
595
|
public async switchActiveUser(subAccountId: number, authority?: PublicKey) {
|
|
592
|
-
const authorityChanged = !this.authority?.equals(authority);
|
|
596
|
+
const authorityChanged = authority && !this.authority?.equals(authority);
|
|
593
597
|
|
|
594
598
|
this.activeSubAccountId = subAccountId;
|
|
595
599
|
this.authority = authority ?? this.authority;
|
|
@@ -1574,13 +1578,6 @@ export class DriftClient {
|
|
|
1574
1578
|
subAccountId?: number,
|
|
1575
1579
|
reduceOnly = false
|
|
1576
1580
|
): Promise<TransactionSignature> {
|
|
1577
|
-
const tx = new Transaction();
|
|
1578
|
-
tx.add(
|
|
1579
|
-
ComputeBudgetProgram.setComputeUnitLimit({
|
|
1580
|
-
units: 600_000,
|
|
1581
|
-
})
|
|
1582
|
-
);
|
|
1583
|
-
|
|
1584
1581
|
const additionalSigners: Array<Signer> = [];
|
|
1585
1582
|
|
|
1586
1583
|
const spotMarketAccount = this.getSpotMarketAccount(marketIndex);
|
|
@@ -1592,6 +1589,8 @@ export class DriftClient {
|
|
|
1592
1589
|
const createWSOLTokenAccount =
|
|
1593
1590
|
isSolMarket && associatedTokenAccount.equals(signerAuthority);
|
|
1594
1591
|
|
|
1592
|
+
const instructions = [];
|
|
1593
|
+
|
|
1595
1594
|
if (createWSOLTokenAccount) {
|
|
1596
1595
|
const { ixs, pubkey } = await this.getWrappedSolAccountCreationIxs(
|
|
1597
1596
|
amount,
|
|
@@ -1600,9 +1599,7 @@ export class DriftClient {
|
|
|
1600
1599
|
|
|
1601
1600
|
associatedTokenAccount = pubkey;
|
|
1602
1601
|
|
|
1603
|
-
|
|
1604
|
-
tx.add(ix);
|
|
1605
|
-
});
|
|
1602
|
+
instructions.push(...ixs);
|
|
1606
1603
|
}
|
|
1607
1604
|
|
|
1608
1605
|
const depositCollateralIx = await this.getDepositInstruction(
|
|
@@ -1614,11 +1611,11 @@ export class DriftClient {
|
|
|
1614
1611
|
true
|
|
1615
1612
|
);
|
|
1616
1613
|
|
|
1617
|
-
|
|
1614
|
+
instructions.push(depositCollateralIx);
|
|
1618
1615
|
|
|
1619
1616
|
// Close the wrapped sol account at the end of the transaction
|
|
1620
1617
|
if (createWSOLTokenAccount) {
|
|
1621
|
-
|
|
1618
|
+
instructions.push(
|
|
1622
1619
|
createCloseAccountInstruction(
|
|
1623
1620
|
associatedTokenAccount,
|
|
1624
1621
|
signerAuthority,
|
|
@@ -1628,6 +1625,10 @@ export class DriftClient {
|
|
|
1628
1625
|
);
|
|
1629
1626
|
}
|
|
1630
1627
|
|
|
1628
|
+
const txParams = { ...this.txParams, computeUnits: 600_000 };
|
|
1629
|
+
|
|
1630
|
+
const tx = await this.buildTransaction(instructions, txParams);
|
|
1631
|
+
|
|
1631
1632
|
const { txSig, slot } = await this.sendTransaction(
|
|
1632
1633
|
tx,
|
|
1633
1634
|
additionalSigners,
|
|
@@ -2442,8 +2443,7 @@ export class DriftClient {
|
|
|
2442
2443
|
makerInfo?: MakerInfo | MakerInfo[],
|
|
2443
2444
|
txParams?: TxParams,
|
|
2444
2445
|
bracketOrdersParams = new Array<OptionalOrderParams>(),
|
|
2445
|
-
referrerInfo?: ReferrerInfo
|
|
2446
|
-
useVersionedTx = true
|
|
2446
|
+
referrerInfo?: ReferrerInfo
|
|
2447
2447
|
): Promise<{ txSig: TransactionSignature; signedFillTx: Transaction }> {
|
|
2448
2448
|
const marketIndex = orderParams.marketIndex;
|
|
2449
2449
|
const orderId = userAccount.nextOrderId;
|
|
@@ -2469,12 +2469,8 @@ export class DriftClient {
|
|
|
2469
2469
|
referrerInfo
|
|
2470
2470
|
);
|
|
2471
2471
|
|
|
2472
|
-
const walletSupportsVersionedTxns =
|
|
2473
|
-
//@ts-ignore
|
|
2474
|
-
this.wallet.supportedTransactionVersions?.size ?? 0 > 1;
|
|
2475
|
-
|
|
2476
2472
|
// use versioned transactions if there is a lookup table account and wallet is compatible
|
|
2477
|
-
if (
|
|
2473
|
+
if (this.txVersion === 0) {
|
|
2478
2474
|
const versionedMarketOrderTx = await this.buildTransaction(
|
|
2479
2475
|
[placePerpOrderIx].concat(bracketOrderIxs),
|
|
2480
2476
|
txParams,
|
|
@@ -5852,17 +5848,16 @@ export class DriftClient {
|
|
|
5852
5848
|
opts?: ConfirmOptions,
|
|
5853
5849
|
preSigned?: boolean
|
|
5854
5850
|
): Promise<TxSigAndSlot> {
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
tx as Transaction,
|
|
5851
|
+
if (tx instanceof VersionedTransaction) {
|
|
5852
|
+
return this.txSender.sendVersionedTransaction(
|
|
5853
|
+
tx as VersionedTransaction,
|
|
5859
5854
|
additionalSigners,
|
|
5860
5855
|
opts,
|
|
5861
5856
|
preSigned
|
|
5862
5857
|
);
|
|
5863
5858
|
} else {
|
|
5864
|
-
return this.txSender.
|
|
5865
|
-
tx as
|
|
5859
|
+
return this.txSender.send(
|
|
5860
|
+
tx as Transaction,
|
|
5866
5861
|
additionalSigners,
|
|
5867
5862
|
opts,
|
|
5868
5863
|
preSigned
|
package/src/types.ts
CHANGED
|
@@ -200,8 +200,8 @@ export class StakeAction {
|
|
|
200
200
|
static readonly UNSTAKE_REQUEST = { unstakeRequest: {} };
|
|
201
201
|
static readonly UNSTAKE_CANCEL_REQUEST = { unstakeCancelRequest: {} };
|
|
202
202
|
static readonly UNSTAKE = { unstake: {} };
|
|
203
|
-
static readonly UNSTAKE_TRANSFER = {
|
|
204
|
-
static readonly STAKE_TRANSFER = {
|
|
203
|
+
static readonly UNSTAKE_TRANSFER = { unstakeTransfer: {} };
|
|
204
|
+
static readonly STAKE_TRANSFER = { stakeTransfer: {} };
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
export function isVariant(object: unknown, type: string) {
|