account_create_v2: fix bad account size (#685)
This commit is contained in:
parent
3480b62945
commit
6fd158ff6c
|
@ -25,3 +25,27 @@ pub struct AccountCreate<'info> {
|
|||
|
||||
pub system_program: Program<'info, System>,
|
||||
}
|
||||
|
||||
#[derive(Accounts)]
|
||||
#[instruction(account_num: u32, token_count: u8, serum3_count: u8, perp_count: u8, perp_oo_count: u8, token_conditional_swap_count: u8)]
|
||||
pub struct AccountCreateV2<'info> {
|
||||
#[account(
|
||||
constraint = group.load()?.is_ix_enabled(IxGate::AccountCreate) @ MangoError::IxIsDisabled,
|
||||
)]
|
||||
pub group: AccountLoader<'info, Group>,
|
||||
|
||||
#[account(
|
||||
init,
|
||||
seeds = [b"MangoAccount".as_ref(), group.key().as_ref(), owner.key().as_ref(), &account_num.to_le_bytes()],
|
||||
bump,
|
||||
payer = payer,
|
||||
space = MangoAccount::space(token_count, serum3_count, perp_count, perp_oo_count, token_conditional_swap_count)?,
|
||||
)]
|
||||
pub account: AccountLoader<'info, MangoAccountFixed>,
|
||||
pub owner: Signer<'info>,
|
||||
|
||||
#[account(mut)]
|
||||
pub payer: Signer<'info>,
|
||||
|
||||
pub system_program: Program<'info, System>,
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use anchor_lang::prelude::*;
|
||||
|
||||
use crate::accounts_ix::*;
|
||||
use crate::error::*;
|
||||
use crate::state::*;
|
||||
use crate::util::fill_from_str;
|
||||
|
||||
pub fn account_create(
|
||||
ctx: Context<AccountCreate>,
|
||||
account_ai: &AccountLoader<MangoAccountFixed>,
|
||||
account_bump: u8,
|
||||
group: Pubkey,
|
||||
owner: Pubkey,
|
||||
account_num: u32,
|
||||
token_count: u8,
|
||||
serum3_count: u8,
|
||||
|
@ -15,7 +16,7 @@ pub fn account_create(
|
|||
token_conditional_swap_count: u8,
|
||||
name: String,
|
||||
) -> Result<()> {
|
||||
let mut account = ctx.accounts.account.load_full_init()?;
|
||||
let mut account = account_ai.load_full_init()?;
|
||||
|
||||
msg!(
|
||||
"Initialized account with header version {}",
|
||||
|
@ -23,10 +24,10 @@ pub fn account_create(
|
|||
);
|
||||
|
||||
account.fixed.name = fill_from_str(&name)?;
|
||||
account.fixed.group = ctx.accounts.group.key();
|
||||
account.fixed.owner = ctx.accounts.owner.key();
|
||||
account.fixed.group = group;
|
||||
account.fixed.owner = owner;
|
||||
account.fixed.account_num = account_num;
|
||||
account.fixed.bump = *ctx.bumps.get("account").ok_or(MangoError::SomeError)?;
|
||||
account.fixed.bump = account_bump;
|
||||
account.fixed.delegate = Pubkey::default();
|
||||
account.fixed.set_being_liquidated(false);
|
||||
|
||||
|
|
|
@ -288,7 +288,10 @@ pub mod mango_v4 {
|
|||
) -> Result<()> {
|
||||
#[cfg(feature = "enable-gpl")]
|
||||
instructions::account_create(
|
||||
ctx,
|
||||
&ctx.accounts.account,
|
||||
*ctx.bumps.get("account").ok_or(MangoError::SomeError)?,
|
||||
ctx.accounts.group.key(),
|
||||
ctx.accounts.owner.key(),
|
||||
account_num,
|
||||
token_count,
|
||||
serum3_count,
|
||||
|
@ -301,7 +304,7 @@ pub mod mango_v4 {
|
|||
}
|
||||
|
||||
pub fn account_create_v2(
|
||||
ctx: Context<AccountCreate>,
|
||||
ctx: Context<AccountCreateV2>,
|
||||
account_num: u32,
|
||||
token_count: u8,
|
||||
serum3_count: u8,
|
||||
|
@ -312,7 +315,10 @@ pub mod mango_v4 {
|
|||
) -> Result<()> {
|
||||
#[cfg(feature = "enable-gpl")]
|
||||
instructions::account_create(
|
||||
ctx,
|
||||
&ctx.accounts.account,
|
||||
*ctx.bumps.get("account").ok_or(MangoError::SomeError)?,
|
||||
ctx.accounts.group.key(),
|
||||
ctx.accounts.owner.key(),
|
||||
account_num,
|
||||
token_count,
|
||||
serum3_count,
|
||||
|
|
Loading…
Reference in New Issue