Skip to content

Commit cbaeb69

Browse files
authored
add helper to build swiftDepositTrade tx (#1868)
* add helper to build swiftDepositTrade tx
1 parent d1ecfa7 commit cbaeb69

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

sdk/src/driftClient.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,59 @@ export class DriftClient {
26312631
return instructions;
26322632
}
26332633

2634+
public async buildSwiftDepositTx(
2635+
signedOrderParams: SignedMsgOrderParams,
2636+
takerInfo: {
2637+
taker: PublicKey;
2638+
takerStats: PublicKey;
2639+
takerUserAccount: UserAccount;
2640+
signingAuthority: PublicKey;
2641+
},
2642+
depositAmount: BN,
2643+
depositSpotMarketIndex: number,
2644+
tradePerpMarketIndex: number,
2645+
subAccountId: number,
2646+
takerAssociatedTokenAccount: PublicKey,
2647+
initSwiftAccount = false
2648+
) {
2649+
const instructions = await this.getDepositTxnIx(
2650+
depositAmount,
2651+
depositSpotMarketIndex,
2652+
takerAssociatedTokenAccount,
2653+
subAccountId,
2654+
false
2655+
);
2656+
2657+
if (initSwiftAccount) {
2658+
const isSignedMsgUserOrdersAccountInitialized =
2659+
await this.isSignedMsgUserOrdersAccountInitialized(
2660+
this.wallet.publicKey
2661+
);
2662+
2663+
if (!isSignedMsgUserOrdersAccountInitialized) {
2664+
const [, initializeSignedMsgUserOrdersAccountIx] =
2665+
await this.getInitializeSignedMsgUserOrdersAccountIx(
2666+
this.wallet.publicKey,
2667+
8
2668+
);
2669+
2670+
instructions.push(initializeSignedMsgUserOrdersAccountIx);
2671+
}
2672+
}
2673+
2674+
const ixsWithPlace = await this.getPlaceSignedMsgTakerPerpOrderIxs(
2675+
signedOrderParams,
2676+
tradePerpMarketIndex,
2677+
takerInfo,
2678+
instructions
2679+
);
2680+
2681+
await this.buildTransaction(ixsWithPlace, {
2682+
computeUnitsPrice: 1_000,
2683+
computeUnits: 100_000,
2684+
});
2685+
}
2686+
26342687
public async createDepositTxn(
26352688
amount: BN,
26362689
marketIndex: number,
@@ -6448,7 +6501,7 @@ export class DriftClient {
64486501
/**
64496502
* Builds a deposit and place request for Swift service
64506503
*
6451-
* @param depositTx - The signed tx containing a drift deposit (e.g. see `createDepositTxn`)
6504+
* @param depositTx - The signed tx containing a drift deposit (e.g. see `buildSwiftDepositTx`)
64526505
* @param orderParamsMessage - The order parameters message to sign
64536506
* @param delegateSigner - Whether this is a delegate signer
64546507
*

0 commit comments

Comments
 (0)