Serum: Comments on account constraints
This commit is contained in:
parent
4025624738
commit
1a95a84ed4
|
@ -7,12 +7,15 @@ use crate::state::*;
|
|||
pub struct Serum3CancelAllOrders<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(has_one = group)]
|
||||
#[account(
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -46,6 +49,7 @@ pub fn serum3_cancel_all_orders(ctx: Context<Serum3CancelAllOrders>, limit: u8)
|
|||
//
|
||||
{
|
||||
let account = ctx.accounts.account.load()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
|
@ -53,7 +57,7 @@ pub fn serum3_cancel_all_orders(ctx: Context<Serum3CancelAllOrders>, limit: u8)
|
|||
|
||||
let serum_market = ctx.accounts.serum_market.load()?;
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
|
|
@ -14,12 +14,16 @@ use checked_math as cm;
|
|||
pub struct Serum3CancelOrder<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(mut, has_one = group)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -59,12 +63,13 @@ pub fn serum3_cancel_order(
|
|||
//
|
||||
{
|
||||
let account = ctx.accounts.account.load()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
|
|
@ -7,7 +7,11 @@ use crate::state::*;
|
|||
pub struct Serum3CloseOpenOrders<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(mut, has_one = group)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
|
@ -23,7 +27,7 @@ pub struct Serum3CloseOpenOrders<'info> {
|
|||
pub serum_market_external: UncheckedAccount<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
|
@ -36,6 +40,7 @@ pub fn serum3_close_open_orders(ctx: Context<Serum3CloseOpenOrders>) -> Result<(
|
|||
// Validation
|
||||
//
|
||||
let mut account = ctx.accounts.account.load_mut()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
|
@ -43,7 +48,7 @@ pub fn serum3_close_open_orders(ctx: Context<Serum3CloseOpenOrders>) -> Result<(
|
|||
|
||||
let serum_market = ctx.accounts.serum_market.load()?;
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
|
|
@ -7,7 +7,11 @@ use crate::state::*;
|
|||
pub struct Serum3CreateOpenOrders<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(mut, has_one = group)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
|
@ -48,6 +52,7 @@ pub fn serum3_create_open_orders(ctx: Context<Serum3CreateOpenOrders>) -> Result
|
|||
let serum_market = ctx.accounts.serum_market.load()?;
|
||||
|
||||
let mut account = ctx.accounts.account.load_mut()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct Serum3LiqForceCancelOrders<'info> {
|
|||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -50,7 +50,7 @@ pub struct Serum3LiqForceCancelOrders<'info> {
|
|||
/// CHECK: Validated by the serum cpi call
|
||||
pub market_vault_signer: UncheckedAccount<'info>,
|
||||
|
||||
// token_index and bank.vault == vault is validated inline
|
||||
// token_index and bank.vault == vault is validated inline at #3
|
||||
#[account(mut, has_one = group)]
|
||||
pub quote_bank: AccountLoader<'info, Bank>,
|
||||
#[account(mut)]
|
||||
|
@ -74,7 +74,7 @@ pub fn serum3_liq_force_cancel_orders(
|
|||
{
|
||||
let account = ctx.accounts.account.load()?;
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
@ -84,7 +84,7 @@ pub fn serum3_liq_force_cancel_orders(
|
|||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate banks and vaults
|
||||
// Validate banks and vaults #3
|
||||
let quote_bank = ctx.accounts.quote_bank.load()?;
|
||||
require!(
|
||||
quote_bank.vault == ctx.accounts.quote_vault.key(),
|
||||
|
|
|
@ -101,12 +101,16 @@ pub enum Serum3Side {
|
|||
pub struct Serum3PlaceOrder<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(mut, has_one = group)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -146,11 +150,10 @@ pub struct Serum3PlaceOrder<'info> {
|
|||
pub market_vault_signer: UncheckedAccount<'info>,
|
||||
|
||||
// TODO: do we need to pass both, or just payer?
|
||||
// TODO: if we potentially settle immediately, they all need to be mut?
|
||||
// TODO: Can we reduce the number of accounts by requiring the banks
|
||||
// to be in the remainingAccounts (where they need to be anyway, for
|
||||
// health checks - but they need to be mut)
|
||||
// token_index and bank.vault == vault is validated inline
|
||||
// token_index and bank.vault == vault is validated inline at #3
|
||||
#[account(mut, has_one = group)]
|
||||
pub quote_bank: AccountLoader<'info, Bank>,
|
||||
#[account(mut)]
|
||||
|
@ -182,12 +185,13 @@ pub fn serum3_place_order(
|
|||
//
|
||||
{
|
||||
let account = ctx.accounts.account.load()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
@ -197,7 +201,7 @@ pub fn serum3_place_order(
|
|||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate banks and vaults
|
||||
// Validate banks and vaults #3
|
||||
let quote_bank = ctx.accounts.quote_bank.load()?;
|
||||
require!(
|
||||
quote_bank.vault == ctx.accounts.quote_vault.key(),
|
||||
|
|
|
@ -15,7 +15,6 @@ pub struct Serum3RegisterMarket<'info> {
|
|||
pub group: AccountLoader<'info, Group>,
|
||||
pub admin: Signer<'info>,
|
||||
|
||||
// TODO: limit?
|
||||
/// CHECK: Can register a market for any serum program
|
||||
pub serum_program: UncheckedAccount<'info>,
|
||||
/// CHECK: Can register any serum market
|
||||
|
@ -42,7 +41,6 @@ pub struct Serum3RegisterMarket<'info> {
|
|||
pub system_program: Program<'info, System>,
|
||||
}
|
||||
|
||||
// TODO: should this be "configure_serum_market", which allows reconfiguring?
|
||||
pub fn serum3_register_market(
|
||||
ctx: Context<Serum3RegisterMarket>,
|
||||
market_index: Serum3MarketIndex,
|
||||
|
|
|
@ -16,12 +16,16 @@ use crate::logs::LoanOriginationFeeInstruction;
|
|||
pub struct Serum3SettleFunds<'info> {
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(mut, has_one = group)]
|
||||
#[account(
|
||||
mut,
|
||||
has_one = group
|
||||
// owner is checked at #1
|
||||
)]
|
||||
pub account: AccountLoaderDynamic<'info, MangoAccount>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account
|
||||
/// CHECK: Validated inline by checking against the pubkey stored in the account at #2
|
||||
pub open_orders: UncheckedAccount<'info>,
|
||||
|
||||
#[account(
|
||||
|
@ -48,7 +52,7 @@ pub struct Serum3SettleFunds<'info> {
|
|||
/// CHECK: Validated by the serum cpi call
|
||||
pub market_vault_signer: UncheckedAccount<'info>,
|
||||
|
||||
// token_index and bank.vault == vault is validated inline
|
||||
// token_index and bank.vault == vault is validated inline at #3
|
||||
#[account(mut, has_one = group)]
|
||||
pub quote_bank: AccountLoader<'info, Bank>,
|
||||
#[account(mut)]
|
||||
|
@ -74,12 +78,13 @@ pub fn serum3_settle_funds(ctx: Context<Serum3SettleFunds>) -> Result<()> {
|
|||
//
|
||||
{
|
||||
let account = ctx.accounts.account.load()?;
|
||||
// account constraint #1
|
||||
require!(
|
||||
account.fixed.is_owner_or_delegate(ctx.accounts.owner.key()),
|
||||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate open_orders
|
||||
// Validate open_orders #2
|
||||
require!(
|
||||
account
|
||||
.serum3_orders(serum_market.market_index)
|
||||
|
@ -89,7 +94,7 @@ pub fn serum3_settle_funds(ctx: Context<Serum3SettleFunds>) -> Result<()> {
|
|||
MangoError::SomeError
|
||||
);
|
||||
|
||||
// Validate banks and vaults
|
||||
// Validate banks and vaults #3
|
||||
let quote_bank = ctx.accounts.quote_bank.load()?;
|
||||
require!(
|
||||
quote_bank.vault == ctx.accounts.quote_vault.key(),
|
||||
|
|
Loading…
Reference in New Issue