diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index 1e664f6be..15a6a3d26 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -6,10 +6,12 @@ use anchor_client::Cluster; use anchor_lang::prelude::System; use anchor_lang::{AccountDeserialize, Id}; +use anchor_spl::associated_token::AssociatedToken; use anchor_spl::token::Token; use itertools::Itertools; +use openbook_v2::state::OracleConfigParams; use openbook_v2::{ state::{Market, OpenOrdersAccount, PlaceOrderType, SelfTradeBehavior, Side}, PlaceOrderArgs, PlaceOrderPeggedArgs, @@ -298,6 +300,82 @@ impl OpenBookClient { .await } + #[allow(clippy::too_many_arguments)] + pub async fn create_market( + &self, + market: Pubkey, + market_authority: Pubkey, + bids: Pubkey, + asks: Pubkey, + event_heap: Pubkey, + base_mint: Pubkey, + quote_mint: Pubkey, + oracle_a: Option, + oracle_b: Option, + collect_fee_admin: Pubkey, + open_orders_admin: Option, + consume_events_admin: Option, + close_market_admin: Option, + event_authority: Pubkey, + name: String, + oracle_config: OracleConfigParams, + base_lot_size: i64, + quote_lot_size: i64, + maker_fee: i64, + taker_fee: i64, + time_expiry: i64, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::CreateMarket { + market, + market_authority, + bids, + asks, + event_heap, + payer: self.owner(), + market_base_vault: + spl_associated_token_account::get_associated_token_address( + &market_authority, + &base_mint, + ), + market_quote_vault: + spl_associated_token_account::get_associated_token_address( + &market_authority, + "e_mint, + ), + base_mint, + quote_mint, + system_program: solana_sdk::system_program::id(), + oracle_a, + oracle_b, + collect_fee_admin, + open_orders_admin, + consume_events_admin, + close_market_admin, + event_authority, + program: openbook_v2::id(), + token_program: Token::id(), + associated_token_program: AssociatedToken::id(), + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CreateMarket { + name, + oracle_config, + base_lot_size, + quote_lot_size, + maker_fee, + taker_fee, + time_expiry, + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + #[allow(clippy::too_many_arguments)] pub async fn place_order( &self,