From 2e3bd7585f01e8b1d451109d7a57b42c933afa3f Mon Sep 17 00:00:00 2001 From: Binye Barwe Date: Wed, 27 Dec 2023 10:37:53 +0100 Subject: [PATCH] Revert "remove penalty fee payer" This reverts commit 47e1b5e103c343b987f715f3e201c6366576ee6e. --- lib/client/src/client.rs | 1 + lib/client/src/jup.rs | 1 + programs/openbook-v2/fuzz/Cargo.lock | 12 ------------ programs/openbook-v2/fuzz/src/lib.rs | 2 ++ .../openbook-v2/src/accounts_ix/place_take_order.rs | 2 ++ programs/openbook-v2/src/accounts_ix/settle_funds.rs | 2 ++ .../src/accounts_ix/settle_funds_expired.rs | 3 +++ .../openbook-v2/src/instructions/settle_funds.rs | 10 ++++++++++ .../openbook-v2/src/state/open_orders_account.rs | 3 ++- programs/openbook-v2/tests/program_test/client.rs | 3 +++ 10 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index c6b29717a..dc9ac3760 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -541,6 +541,7 @@ impl OpenBookClient { anchor_lang::ToAccountMetas::to_account_metas( &openbook_v2::accounts::SettleFunds { owner: self.owner(), + penalty_payer: self.owner(), open_orders_account: self.open_orders_account, market: market_address, market_authority: market.market_authority, diff --git a/lib/client/src/jup.rs b/lib/client/src/jup.rs index 518142996..4c289a54f 100644 --- a/lib/client/src/jup.rs +++ b/lib/client/src/jup.rs @@ -205,6 +205,7 @@ impl Amm for OpenBookMarket { let accounts = PlaceTakeOrder { signer: *user_transfer_authority, + penalty_payer: *user_transfer_authority, market: self.key, market_authority: self.market.market_authority, bids: self.market.bids, diff --git a/programs/openbook-v2/fuzz/Cargo.lock b/programs/openbook-v2/fuzz/Cargo.lock index cab94afd9..256fa1b5b 100644 --- a/programs/openbook-v2/fuzz/Cargo.lock +++ b/programs/openbook-v2/fuzz/Cargo.lock @@ -1005,17 +1005,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "default-env" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f753eb82d29277e79efc625e84aecacfd4851ee50e05a8573a4740239a77bfd3" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - [[package]] name = "derivation-path" version = "0.2.0" @@ -2250,7 +2239,6 @@ dependencies = [ "arbitrary", "arrayref", "bytemuck", - "default-env", "derivative", "fixed", "itertools 0.10.5", diff --git a/programs/openbook-v2/fuzz/src/lib.rs b/programs/openbook-v2/fuzz/src/lib.rs index c8dc0539f..be364ce42 100644 --- a/programs/openbook-v2/fuzz/src/lib.rs +++ b/programs/openbook-v2/fuzz/src/lib.rs @@ -469,6 +469,7 @@ impl FuzzContext { let accounts = openbook_v2::accounts::PlaceTakeOrder { signer: user.owner, + penalty_payer: user.owner, user_base_account: user.base_vault, user_quote_account: user.quote_vault, market: self.market, @@ -764,6 +765,7 @@ impl FuzzContext { let accounts = openbook_v2::accounts::SettleFunds { owner: user.owner, + penalty_payer: user.owner, open_orders_account: user.open_orders, user_base_account: user.base_vault, user_quote_account: user.quote_vault, diff --git a/programs/openbook-v2/src/accounts_ix/place_take_order.rs b/programs/openbook-v2/src/accounts_ix/place_take_order.rs index 274cb22d4..f41a239ad 100644 --- a/programs/openbook-v2/src/accounts_ix/place_take_order.rs +++ b/programs/openbook-v2/src/accounts_ix/place_take_order.rs @@ -8,6 +8,8 @@ use anchor_spl::token::{Token, TokenAccount}; pub struct PlaceTakeOrder<'info> { #[account(mut)] pub signer: Signer<'info>, + #[account(mut)] + pub penalty_payer: Signer<'info>, #[account( mut, diff --git a/programs/openbook-v2/src/accounts_ix/settle_funds.rs b/programs/openbook-v2/src/accounts_ix/settle_funds.rs index faa73800f..50eb5ecc3 100644 --- a/programs/openbook-v2/src/accounts_ix/settle_funds.rs +++ b/programs/openbook-v2/src/accounts_ix/settle_funds.rs @@ -7,6 +7,8 @@ use anchor_spl::token::{Token, TokenAccount}; pub struct SettleFunds<'info> { #[account(mut)] pub owner: Signer<'info>, + #[account(mut)] + pub penalty_payer: Signer<'info>, #[account( mut, diff --git a/programs/openbook-v2/src/accounts_ix/settle_funds_expired.rs b/programs/openbook-v2/src/accounts_ix/settle_funds_expired.rs index 34e754278..23f712547 100644 --- a/programs/openbook-v2/src/accounts_ix/settle_funds_expired.rs +++ b/programs/openbook-v2/src/accounts_ix/settle_funds_expired.rs @@ -9,6 +9,8 @@ pub struct SettleFundsExpired<'info> { pub close_market_admin: Signer<'info>, #[account(mut)] pub owner: Signer<'info>, + #[account(mut)] + pub penalty_payer: Signer<'info>, #[account( mut, has_one = market, @@ -54,6 +56,7 @@ impl<'info> SettleFundsExpired<'info> { pub fn to_settle_funds_accounts(&self) -> SettleFunds<'info> { SettleFunds { owner: self.owner.clone(), + penalty_payer: self.penalty_payer.clone(), open_orders_account: self.open_orders_account.clone(), market: self.market.clone(), market_authority: self.market_authority.clone(), diff --git a/programs/openbook-v2/src/instructions/settle_funds.rs b/programs/openbook-v2/src/instructions/settle_funds.rs index 77d3a2bc7..7f19b87e8 100644 --- a/programs/openbook-v2/src/instructions/settle_funds.rs +++ b/programs/openbook-v2/src/instructions/settle_funds.rs @@ -34,6 +34,16 @@ pub fn settle_funds<'info>(ctx: Context<'_, '_, '_, 'info, SettleFunds<'info>>) drop(market); + if pa.penalty_heap_count > 0 { + system_program_transfer( + pa.penalty_heap_count * PENALTY_EVENT_HEAP, + &ctx.accounts.system_program, + &ctx.accounts.penalty_payer, + &ctx.accounts.market, + )?; + pa.penalty_heap_count = 0; + } + if let Some(referrer_account) = &ctx.accounts.referrer_account { token_transfer_signed( referrer_rebate, diff --git a/programs/openbook-v2/src/state/open_orders_account.rs b/programs/openbook-v2/src/state/open_orders_account.rs index 67a87533b..66a8d0767 100644 --- a/programs/openbook-v2/src/state/open_orders_account.rs +++ b/programs/openbook-v2/src/state/open_orders_account.rs @@ -340,7 +340,8 @@ pub struct Position { pub locked_maker_fees: u64, pub referrer_rebates_available: u64, - /// Not implemented at the moment + /// Count of ixs when events are added to the heap + /// To avoid this, send remaining accounts in order to process the events pub penalty_heap_count: u64, /// Cumulative maker volume in quote native units (display only) diff --git a/programs/openbook-v2/tests/program_test/client.rs b/programs/openbook-v2/tests/program_test/client.rs index 05698205d..1255ecb6a 100644 --- a/programs/openbook-v2/tests/program_test/client.rs +++ b/programs/openbook-v2/tests/program_test/client.rs @@ -589,6 +589,7 @@ impl ClientInstruction for PlaceTakeOrderInstruction { oracle_a: market.oracle_a.into(), oracle_b: market.oracle_b.into(), signer: self.signer.pubkey(), + penalty_payer: self.signer.pubkey(), user_base_account: self.user_base_account, user_quote_account: self.user_quote_account, market_base_vault: self.market_base_vault, @@ -833,6 +834,7 @@ impl ClientInstruction for SettleFundsInstruction { let market: Market = account_loader.load(&self.market).await.unwrap(); let accounts = Self::Accounts { owner: self.owner.pubkey(), + penalty_payer: self.owner.pubkey(), open_orders_account: self.open_orders_account, market: self.market, market_authority: market.market_authority, @@ -880,6 +882,7 @@ impl ClientInstruction for SettleFundsExpiredInstruction { let accounts = Self::Accounts { close_market_admin: self.close_market_admin.pubkey(), owner: self.owner.pubkey(), + penalty_payer: self.owner.pubkey(), open_orders_account: self.open_orders_account, market: self.market, market_authority: market.market_authority,