diff --git a/programs/mango-v4/src/instructions/perp_cancel_all_orders.rs b/programs/mango-v4/src/instructions/perp_cancel_all_orders.rs index 269fa534b..e99c32824 100644 --- a/programs/mango-v4/src/instructions/perp_cancel_all_orders.rs +++ b/programs/mango-v4/src/instructions/perp_cancel_all_orders.rs @@ -14,6 +14,7 @@ pub struct PerpCancelAllOrders<'info> { mut, has_one = group, constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen + // owner is checked at #1 )] pub account: AccountLoader<'info, MangoAccountFixed>, pub owner: Signer<'info>, @@ -33,6 +34,7 @@ pub struct PerpCancelAllOrders<'info> { pub fn perp_cancel_all_orders(ctx: Context, limit: u8) -> Result<()> { let mut account = ctx.accounts.account.load_full_mut()?; + // account constraint #1 require!( account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()), MangoError::SomeError diff --git a/programs/mango-v4/src/instructions/perp_cancel_all_orders_by_side.rs b/programs/mango-v4/src/instructions/perp_cancel_all_orders_by_side.rs index 4de2fda30..fffe9750d 100644 --- a/programs/mango-v4/src/instructions/perp_cancel_all_orders_by_side.rs +++ b/programs/mango-v4/src/instructions/perp_cancel_all_orders_by_side.rs @@ -16,6 +16,7 @@ pub struct PerpCancelAllOrdersBySide<'info> { mut, has_one = group, constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen + // owner is checked at #1 )] pub account: AccountLoader<'info, MangoAccountFixed>, pub owner: Signer<'info>, @@ -39,6 +40,7 @@ pub fn perp_cancel_all_orders_by_side( limit: u8, ) -> Result<()> { let mut account = ctx.accounts.account.load_full_mut()?; + // account constraint #1 require!( account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()), MangoError::SomeError diff --git a/programs/mango-v4/src/instructions/perp_cancel_order.rs b/programs/mango-v4/src/instructions/perp_cancel_order.rs index 192792250..05be2a176 100644 --- a/programs/mango-v4/src/instructions/perp_cancel_order.rs +++ b/programs/mango-v4/src/instructions/perp_cancel_order.rs @@ -14,6 +14,7 @@ pub struct PerpCancelOrder<'info> { mut, has_one = group, constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen + // owner is checked at #1 )] pub account: AccountLoader<'info, MangoAccountFixed>, pub owner: Signer<'info>, @@ -33,6 +34,7 @@ pub struct PerpCancelOrder<'info> { pub fn perp_cancel_order(ctx: Context, order_id: u128) -> Result<()> { let mut account = ctx.accounts.account.load_full_mut()?; + // account constraint #1 require!( account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()), MangoError::SomeError diff --git a/programs/mango-v4/src/instructions/perp_cancel_order_by_client_order_id.rs b/programs/mango-v4/src/instructions/perp_cancel_order_by_client_order_id.rs index f2f66d11f..32b64062b 100644 --- a/programs/mango-v4/src/instructions/perp_cancel_order_by_client_order_id.rs +++ b/programs/mango-v4/src/instructions/perp_cancel_order_by_client_order_id.rs @@ -14,6 +14,7 @@ pub struct PerpCancelOrderByClientOrderId<'info> { mut, has_one = group, constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen + // owner is checked at #1 )] pub account: AccountLoader<'info, MangoAccountFixed>, pub owner: Signer<'info>, @@ -36,6 +37,7 @@ pub fn perp_cancel_order_by_client_order_id( client_order_id: u64, ) -> Result<()> { let mut account = ctx.accounts.account.load_full_mut()?; + // account constraint #1 require!( account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()), MangoError::SomeError diff --git a/programs/mango-v4/src/instructions/perp_place_order.rs b/programs/mango-v4/src/instructions/perp_place_order.rs index a96ba98d6..8f145fff0 100644 --- a/programs/mango-v4/src/instructions/perp_place_order.rs +++ b/programs/mango-v4/src/instructions/perp_place_order.rs @@ -20,6 +20,7 @@ pub struct PerpPlaceOrder<'info> { mut, has_one = group, constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen + // owner is checked at #1 )] pub account: AccountLoader<'info, MangoAccountFixed>, pub owner: Signer<'info>, @@ -73,6 +74,7 @@ pub fn perp_place_order(ctx: Context, mut order: Order, limit: u } let mut account = ctx.accounts.account.load_full_mut()?; + // account constraint #1 require!( account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()), MangoError::SomeError diff --git a/programs/mango-v4/src/instructions/perp_settle_fees.rs b/programs/mango-v4/src/instructions/perp_settle_fees.rs index 04501965e..fa9bb6bcd 100644 --- a/programs/mango-v4/src/instructions/perp_settle_fees.rs +++ b/programs/mango-v4/src/instructions/perp_settle_fees.rs @@ -31,6 +31,7 @@ pub struct PerpSettleFees<'info> { /// CHECK: Oracle can have different account types, constrained by address in perp_market pub oracle: UncheckedAccount<'info>, + // bank correctness is checked at #2 #[account(mut, has_one = group)] pub settle_bank: AccountLoader<'info, Bank>, @@ -47,12 +48,12 @@ pub fn perp_settle_fees(ctx: Context, max_settle_amount: u64) -> ); let mut account = ctx.accounts.account.load_full_mut()?; - let mut bank = ctx.accounts.settle_bank.load_mut()?; + let mut settle_bank = ctx.accounts.settle_bank.load_mut()?; let mut perp_market = ctx.accounts.perp_market.load_mut()?; - // Verify that the bank is the quote currency bank + // Verify that the bank is the quote currency bank (#2) require_eq!( - bank.token_index, + settle_bank.token_index, perp_market.settle_token_index, MangoError::InvalidBank ); @@ -118,7 +119,7 @@ pub fn perp_settle_fees(ctx: Context, max_settle_amount: u64) -> let token_position = account .token_position_mut(perp_market.settle_token_index)? .0; - bank.withdraw_without_fee( + settle_bank.withdraw_without_fee( token_position, settlement, Clock::get()?.unix_timestamp.try_into().unwrap(), @@ -132,8 +133,8 @@ pub fn perp_settle_fees(ctx: Context, max_settle_amount: u64) -> mango_account: ctx.accounts.account.key(), token_index: perp_market.settle_token_index, indexed_position: token_position.indexed_position.to_bits(), - deposit_index: bank.deposit_index.to_bits(), - borrow_index: bank.borrow_index.to_bits(), + deposit_index: settle_bank.deposit_index.to_bits(), + borrow_index: settle_bank.borrow_index.to_bits(), }); emit!(PerpSettleFeesLog { @@ -144,7 +145,7 @@ pub fn perp_settle_fees(ctx: Context, max_settle_amount: u64) -> }); // Bank & perp_market are dropped to prevent re-borrow from remaining_accounts - drop(bank); + drop(settle_bank); drop(perp_market); // Verify that the result of settling did not violate the health of the account that lost money diff --git a/programs/mango-v4/src/instructions/perp_settle_pnl.rs b/programs/mango-v4/src/instructions/perp_settle_pnl.rs index de23060af..92ff60d59 100644 --- a/programs/mango-v4/src/instructions/perp_settle_pnl.rs +++ b/programs/mango-v4/src/instructions/perp_settle_pnl.rs @@ -45,6 +45,7 @@ pub struct PerpSettlePnl<'info> { /// CHECK: Oracle can have different account types, constrained by address in perp_market pub oracle: UncheckedAccount<'info>, + // bank correctness is checked at #2 #[account(mut, has_one = group)] pub settle_bank: AccountLoader<'info, Bank>, @@ -95,7 +96,7 @@ pub fn perp_settle_pnl(ctx: Context) -> Result<()> { let mut settle_bank = ctx.accounts.settle_bank.load_mut()?; let perp_market = ctx.accounts.perp_market.load()?; - // Verify that the bank is the quote currency bank + // Verify that the bank is the quote currency bank (#2) require!( settle_bank.token_index == settle_token_index, MangoError::InvalidBank