spl: Add init and close open orders instructions to the dex (#245)

This commit is contained in:
Armani Ferrante 2021-05-31 11:52:46 -07:00 committed by GitHub
parent d187dc5be9
commit 265eedc5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 3 deletions

4
Cargo.lock generated
View File

@ -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",

View File

@ -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"] }

View File

@ -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>,
}