Skip to content

Commit b471c48

Browse files
authored
sdk: add optional initSwiftAccount on existing account deposits (#1660)
1 parent f43db4a commit b471c48

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

sdk/src/driftClient.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,8 @@ export class DriftClient {
25392539
associatedTokenAccount: PublicKey,
25402540
subAccountId?: number,
25412541
reduceOnly = false,
2542-
txParams?: TxParams
2542+
txParams?: TxParams,
2543+
initSwiftAccount = false
25432544
): Promise<VersionedTransaction | Transaction> {
25442545
const instructions = await this.getDepositTxnIx(
25452546
amount,
@@ -2549,7 +2550,24 @@ export class DriftClient {
25492550
reduceOnly
25502551
);
25512552

2552-
txParams = { ...(txParams ?? this.txParams), computeUnits: 600_000 };
2553+
if (initSwiftAccount) {
2554+
const isSignedMsgUserOrdersAccountInitialized =
2555+
await this.isSignedMsgUserOrdersAccountInitialized(
2556+
this.wallet.publicKey
2557+
);
2558+
2559+
if (!isSignedMsgUserOrdersAccountInitialized) {
2560+
const [, initializeSignedMsgUserOrdersAccountIx] =
2561+
await this.getInitializeSignedMsgUserOrdersAccountIx(
2562+
this.wallet.publicKey,
2563+
8
2564+
);
2565+
2566+
instructions.push(initializeSignedMsgUserOrdersAccountIx);
2567+
}
2568+
}
2569+
2570+
txParams = { ...(txParams ?? this.txParams), computeUnits: 800_000 };
25532571

25542572
const tx = await this.buildTransaction(instructions, txParams);
25552573

@@ -2571,15 +2589,17 @@ export class DriftClient {
25712589
associatedTokenAccount: PublicKey,
25722590
subAccountId?: number,
25732591
reduceOnly = false,
2574-
txParams?: TxParams
2592+
txParams?: TxParams,
2593+
initSwiftAccount = false
25752594
): Promise<TransactionSignature> {
25762595
const tx = await this.createDepositTxn(
25772596
amount,
25782597
marketIndex,
25792598
associatedTokenAccount,
25802599
subAccountId,
25812600
reduceOnly,
2582-
txParams
2601+
txParams,
2602+
initSwiftAccount
25832603
);
25842604

25852605
const { txSig, slot } = await this.sendTransaction(tx, [], this.opts);

0 commit comments

Comments
 (0)