Skip to content

Commit

Permalink
spl: Add init and close open orders instructions to the dex (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored May 31, 2021
1 parent d187dc5 commit 265eedc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
51 changes: 51 additions & 0 deletions spl/src/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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>,
}

0 comments on commit 265eedc

Please sign in to comment.