From 265eedc5a319bcb27ccf72a773fbcf35fb621607 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Mon, 31 May 2021 11:52:46 -0700 Subject: [PATCH] spl: Add init and close open orders instructions to the dex (#245) --- Cargo.lock | 4 ++-- spl/Cargo.toml | 2 +- spl/src/dex.rs | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e18a7434..e57d86c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2781,8 +2781,8 @@ dependencies = [ [[package]] name = "serum_dex" -version = "0.3.0" -source = "git+https://github.com/project-serum/serum-dex#66904088599c1a8d42623f6a6d157cec46c8da62" +version = "0.3.1" +source = "git+https://github.com/project-serum/serum-dex?tag=v0.3.1#7d1d41538417aa8721aabea9503bf9d99eab7cc4" dependencies = [ "arrayref", "bincode", diff --git a/spl/Cargo.toml b/spl/Cargo.toml index 90cc359f..6754031b 100644 --- a/spl/Cargo.toml +++ b/spl/Cargo.toml @@ -12,6 +12,6 @@ devnet = [] [dependencies] anchor-lang = { path = "../lang", version = "0.6.0", features = ["derive"] } lazy_static = "1.4.0" -serum_dex = { git = "https://github.com/project-serum/serum-dex", version = "0.3.0", features = ["no-entrypoint"] } +serum_dex = { git = "https://github.com/project-serum/serum-dex", tag = "v0.3.1", version = "0.3.1", features = ["no-entrypoint"] } solana-program = "1.6.6" spl-token = { version = "3.0.1", features = ["no-entrypoint"] } diff --git a/spl/src/dex.rs b/spl/src/dex.rs index 9a799cf3..5e28ddb1 100644 --- a/spl/src/dex.rs +++ b/spl/src/dex.rs @@ -82,6 +82,41 @@ pub fn settle_funds<'info>( Ok(()) } +pub fn init_open_orders<'info>( + ctx: CpiContext<'_, '_, '_, 'info, InitOpenOrders<'info>>, +) -> ProgramResult { + let ix = serum_dex::instruction::init_open_orders( + &ID, + ctx.accounts.open_orders.key, + ctx.accounts.authority.key, + ctx.accounts.market.key, + )?; + solana_program::program::invoke_signed( + &ix, + &ToAccountInfos::to_account_infos(&ctx), + ctx.signer_seeds, + )?; + Ok(()) +} + +pub fn close_open_orders<'info>( + ctx: CpiContext<'_, '_, '_, 'info, CloseOpenOrders<'info>>, +) -> ProgramResult { + let ix = serum_dex::instruction::close_open_orders( + &ID, + ctx.accounts.open_orders.key, + ctx.accounts.authority.key, + ctx.accounts.destination.key, + ctx.accounts.market.key, + )?; + solana_program::program::invoke_signed( + &ix, + &ToAccountInfos::to_account_infos(&ctx), + ctx.signer_seeds, + )?; + Ok(()) +} + #[derive(Accounts)] pub struct NewOrderV3<'info> { pub market: AccountInfo<'info>, @@ -116,3 +151,19 @@ pub struct SettleFunds<'info> { pub vault_signer: AccountInfo<'info>, pub token_program: AccountInfo<'info>, } + +#[derive(Accounts)] +pub struct InitOpenOrders<'info> { + pub open_orders: AccountInfo<'info>, + pub authority: AccountInfo<'info>, + pub market: AccountInfo<'info>, + pub rent: AccountInfo<'info>, +} + +#[derive(Accounts)] +pub struct CloseOpenOrders<'info> { + pub open_orders: AccountInfo<'info>, + pub authority: AccountInfo<'info>, + pub destination: AccountInfo<'info>, + pub market: AccountInfo<'info>, +}