Skip to content

refactor(sdk): allow user client input for cancel orders #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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