Skip to content

Commit 43aeebd

Browse files
committed
feat: init swift user orders on user account creation if needed
1 parent 6fd02a3 commit 43aeebd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sdk/src/driftClient.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,24 @@ export class DriftClient {
17381738
return ix;
17391739
}
17401740

1741+
/**
1742+
* Checks if a Swift User Orders account exists for the given authority.
1743+
* The account pubkey is derived using the program ID and authority as seeds.
1744+
* Makes an RPC call to check if the account exists on-chain.
1745+
*
1746+
* @param authority The authority public key to check for
1747+
* @returns Promise that resolves to true if the account exists, false otherwise
1748+
*/
1749+
public async isSwiftUserOrdersAccountInitialized(
1750+
authority: PublicKey
1751+
): Promise<boolean> {
1752+
const swiftUserOrdersAccountPublicKey = getSwiftUserAccountPublicKey(
1753+
this.program.programId,
1754+
authority
1755+
);
1756+
return this.checkIfAccountExists(swiftUserOrdersAccountPublicKey);
1757+
}
1758+
17411759
public async reclaimRent(
17421760
subAccountId = 0,
17431761
txParams?: TxParams
@@ -2530,6 +2548,18 @@ export class DriftClient {
25302548
referrerInfo
25312549
);
25322550

2551+
const isSwiftUserOrdersAccountInitialized =
2552+
await this.isSwiftUserOrdersAccountInitialized(this.wallet.publicKey);
2553+
2554+
if (!isSwiftUserOrdersAccountInitialized) {
2555+
ixs.push(
2556+
await this.getInitializeSwiftUserOrdersAccountIx(
2557+
this.wallet.publicKey,
2558+
8
2559+
)
2560+
);
2561+
}
2562+
25332563
const spotMarket = this.getSpotMarketAccount(marketIndex);
25342564

25352565
const isSolMarket = spotMarket.mint.equals(WRAPPED_SOL_MINT);

0 commit comments

Comments
 (0)