spl: Add prune ix to dex middleware (#543)

This commit is contained in:
Armani Ferrante 2021-07-21 22:01:13 -07:00 committed by GitHub
parent c1109721b5
commit 0998422348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 5 deletions

7
Cargo.lock generated
View File

@ -192,6 +192,7 @@ dependencies = [
"bytemuck",
"solana-program",
"thiserror",
"zeroize",
]
[[package]]
@ -2811,7 +2812,7 @@ dependencies = [
[[package]]
name = "serum_dex"
version = "0.3.1"
source = "git+https://github.com/project-serum/serum-dex?branch=armani/auth#2037a646f82e689f8e7a00c8a34b30e20253ba11"
source = "git+https://github.com/project-serum/serum-dex?branch=armani/auth#814c1fd05b00ae99d68d8f9617cc3868b7aceae1"
dependencies = [
"arrayref",
"bincode",
@ -4359,9 +4360,9 @@ checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71"
[[package]]
name = "zeroize"
version = "1.2.0"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81a974bcdd357f0dca4d41677db03436324d45a4c9ed2d0b873a5a360ce41c36"
checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd"
dependencies = [
"zeroize_derive",
]

@ -1 +1 @@
Subproject commit 2037a646f82e689f8e7a00c8a34b30e20253ba11
Subproject commit 814c1fd05b00ae99d68d8f9617cc3868b7aceae1

View File

@ -75,6 +75,10 @@ pub trait MarketMiddleware {
Ok(())
}
fn prune(&self, _ctx: &mut Context) -> ProgramResult {
Ok(())
}
/// Called when the instruction data doesn't match any DEX instruction.
fn fallback(&self, _ctx: &mut Context) -> ProgramResult {
Ok(())
@ -344,6 +348,20 @@ impl MarketMiddleware for OpenOrdersPda {
Ok(())
}
/// Accounts:
///
/// ..
///
/// Data:
///
/// 0. Discriminant.
/// ..
fn prune(&self, ctx: &mut Context) -> ProgramResult {
// Set owner of open orders to be itself.
ctx.accounts[5] = ctx.accounts[4].clone();
Ok(())
}
}
/// Logs each request.
@ -471,7 +489,7 @@ macro_rules! open_orders_init_authority {
// Errors.
#[error]
#[error(offset = 500)]
pub enum ErrorCode {
#[msg("Program ID does not match the Serum DEX")]
InvalidDexPid,

View File

@ -95,6 +95,12 @@ impl<'a> MarketProxy<'a> {
mw.close_open_orders(&mut ctx)?;
}
}
Some(MarketInstruction::Prune) => {
require!(ctx.accounts.len() >= 7, ErrorCode::NotEnoughAccounts);
for mw in &self.middlewares {
mw.prune(&mut ctx)?;
}
}
_ => {
for mw in &self.middlewares {
mw.fallback(&mut ctx)?;