Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4357,14 +4357,24 @@ export class DriftClient {
});
}

/**
* Sends a transaction to cancel the provided order ids.
*
* @param orderIds - The order ids to cancel.
* @param txParams - The transaction parameters.
* @param subAccountId - The sub account id to cancel the orders for.
* @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
* @returns The transaction signature.
*/
public async cancelOrdersByIds(
orderIds?: number[],
txParams?: TxParams,
subAccountId?: number
subAccountId?: number,
user?: User
): Promise<TransactionSignature> {
const { txSig } = await this.sendTransaction(
await this.buildTransaction(
await this.getCancelOrdersByIdsIx(orderIds, subAccountId),
await this.getCancelOrdersByIdsIx(orderIds, subAccountId, user),
txParams
),
[],
Expand All @@ -4373,21 +4383,34 @@ export class DriftClient {
return txSig;
}

/**
* Returns the transaction instruction to cancel the provided order ids.
*
* @param orderIds - The order ids to cancel.
* @param subAccountId - The sub account id to cancel the orders for.
* @param user - The user to cancel the orders for. If provided, it will be prioritized over the subAccountId.
* @returns The transaction instruction to cancel the orders.
*/
public async getCancelOrdersByIdsIx(
orderIds?: number[],
subAccountId?: number
subAccountId?: number,
user?: User
): Promise<TransactionInstruction> {
const user = await this.getUserAccountPublicKey(subAccountId);
const userAccountPubKey =
user?.userAccountPublicKey ??
(await this.getUserAccountPublicKey(subAccountId));
const userAccount =
user?.getUserAccount() ?? this.getUserAccount(subAccountId);

const remainingAccounts = this.getRemainingAccounts({
userAccounts: [this.getUserAccount(subAccountId)],
userAccounts: [userAccount],
useMarketLastSlotCache: true,
});

return await this.program.instruction.cancelOrdersByIds(orderIds, {
accounts: {
state: await this.getStatePublicKey(),
user,
user: userAccountPubKey,
authority: this.wallet.publicKey,
},
remainingAccounts,
Expand Down
Loading