Skip to content

Commit

Permalink
add cancelAll to client
Browse files Browse the repository at this point in the history
  • Loading branch information
binyebarwe committed Jan 30, 2024
1 parent 880ff9e commit c461b1a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openbook-dex/openbook-v2",
"version": "0.1.7",
"version": "0.1.8",
"description": "Typescript Client for openbook-v2 program.",
"repository": "https://github.com/openbook-dex/openbook-v2/",
"author": {
Expand Down
36 changes: 33 additions & 3 deletions ts/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import {
} from '@solana/web3.js';
import { IDL, type OpenbookV2 } from './openbook_v2';
import { sendTransaction } from './utils/rpc';
import { Side } from './utils/utils';
import { SideUtils } from './utils/utils';

export type IdsSource = 'api' | 'static' | 'get-program-accounts';
export type PlaceOrderArgs = IdlTypes<OpenbookV2>['PlaceOrderArgs'];
export type PlaceOrderType = IdlTypes<OpenbookV2>['PlaceOrderType'];
export type Side = IdlTypes<OpenbookV2>['Side'];
export type PlaceOrderPeggedArgs = IdlTypes<OpenbookV2>['PlaceOrderPeggedArgs'];
export type PlaceMultipleOrdersArgs =
IdlTypes<OpenbookV2>['PlaceMultipleOrdersArgs'];
Expand Down Expand Up @@ -627,7 +628,9 @@ export class OpenBookV2Client {
openOrdersDelegate?: Keypair,
): Promise<[TransactionInstruction, Signer[]]> {
const marketVault =
args.side === Side.Bid ? market.marketQuoteVault : market.marketBaseVault;
args.side === SideUtils.Bid
? market.marketQuoteVault
: market.marketBaseVault;
const accountsMeta: AccountMeta[] = remainingAccounts.map((remaining) => ({
pubkey: remaining,
isSigner: false,
Expand Down Expand Up @@ -673,7 +676,9 @@ export class OpenBookV2Client {
openOrdersDelegate?: Keypair,
): Promise<[TransactionInstruction, Signer[]]> {
const marketVault =
args.side === Side.Bid ? market.marketQuoteVault : market.marketBaseVault;
args.side === SideUtils.Bid
? market.marketQuoteVault
: market.marketBaseVault;
const accountsMeta: AccountMeta[] = remainingAccounts.map((remaining) => ({
pubkey: remaining,
isSigner: false,
Expand Down Expand Up @@ -846,6 +851,31 @@ export class OpenBookV2Client {
return [ix, signers];
}

public async cancelAllOrders(
openOrdersPublicKey: PublicKey,
openOrdersAccount: OpenOrdersAccount,
market: MarketAccount,
limit: number,
side: Side | null,
openOrdersDelegate?: Keypair,
): Promise<[TransactionInstruction, Signer[]]> {
const ix = await this.program.methods
.cancelAllOrders(side, limit)
.accounts({
signer: openOrdersAccount.owner,
asks: market.asks,
bids: market.bids,
market: openOrdersAccount.market,
openOrdersAccount: openOrdersPublicKey,
})
.instruction();
const signers: Signer[] = [];
if (openOrdersDelegate != null) {
signers.push(openOrdersDelegate);
}
return [ix, signers];
}

public async closeOpenOrdersIndexerIx(
owner: Keypair,
market: MarketAccount,
Expand Down
2 changes: 1 addition & 1 deletion ts/client/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TOKEN_PROGRAM_ID,
} from '@solana/spl-token';

export const Side = {
export const SideUtils = {
Bid: { bid: {} },
Ask: { ask: {} },
};
Expand Down

0 comments on commit c461b1a

Please sign in to comment.