From 939a31e771425b44686c0f0c1de933bf6adaefa2 Mon Sep 17 00:00:00 2001 From: Lou-Kamades Date: Sat, 30 Dec 2023 13:50:29 -0600 Subject: [PATCH 1/2] add cancel functions to rust client --- lib/client/src/client.rs | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index b1eee5adb..0cf3fbc19 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -492,6 +492,64 @@ impl OpenBookClient { self.send_and_confirm_owner_tx(vec![ix]).await } + #[allow(clippy::too_many_arguments)] + pub async fn cancel_order( + &self, + market: Market, + market_address: Pubkey, + order_id: u128, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::CancelOrder { + open_orders_account: self.open_orders_account, + signer: self.owner(), + market: market_address, + bids: market.bids, + asks: market.asks, + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelOrder { + order_id + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + + #[allow(clippy::too_many_arguments)] + pub async fn cancel_all_orders( + &self, + market: Market, + market_address: Pubkey, + side_option: Option, + limit: u8, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::CancelOrder { + open_orders_account: self.open_orders_account, + signer: self.owner(), + market: market_address, + bids: market.bids, + asks: market.asks, + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelAllOrders { + side_option, + limit + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + #[allow(clippy::too_many_arguments)] pub async fn deposit( &self, From af8a88a9dec58a0f6d4cd29ba826e2343bbe5709 Mon Sep 17 00:00:00 2001 From: Lou-Kamades Date: Sat, 30 Dec 2023 14:56:48 -0600 Subject: [PATCH 2/2] add consume events to rust client --- lib/client/src/client.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index 0cf3fbc19..131f4b36c 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -514,7 +514,7 @@ impl OpenBookClient { ) }, data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelOrder { - order_id + order_id, }), }; self.send_and_confirm_owner_tx(vec![ix]).await @@ -544,7 +544,7 @@ impl OpenBookClient { }, data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelAllOrders { side_option, - limit + limit, }), }; self.send_and_confirm_owner_tx(vec![ix]).await @@ -623,6 +623,32 @@ impl OpenBookClient { self.send_and_confirm_owner_tx(vec![ix]).await } + #[allow(clippy::too_many_arguments)] + pub async fn consume_events( + &self, + market: Market, + market_address: Pubkey, + limit: usize, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::ConsumeEvents { + consume_events_admin: market.consume_events_admin.into(), + market: market_address, + event_heap: market.event_heap, + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::ConsumeEvents { + limit, + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + pub async fn send_and_confirm_owner_tx( &self, instructions: Vec,