2022-02-22 04:31:03 -08:00
|
|
|
use anchor_lang::prelude::*;
|
|
|
|
|
2023-02-14 23:42:07 -08:00
|
|
|
use crate::accounts_ix::*;
|
2022-02-28 06:42:14 -08:00
|
|
|
use crate::error::*;
|
2022-02-22 04:31:03 -08:00
|
|
|
use crate::state::*;
|
2022-08-12 07:05:32 -07:00
|
|
|
use crate::util::fill_from_str;
|
2022-02-22 04:31:03 -08:00
|
|
|
|
2022-07-25 07:07:53 -07:00
|
|
|
pub fn account_create(
|
|
|
|
ctx: Context<AccountCreate>,
|
2022-08-01 09:46:45 -07:00
|
|
|
account_num: u32,
|
2022-08-07 05:16:06 -07:00
|
|
|
token_count: u8,
|
|
|
|
serum3_count: u8,
|
|
|
|
perp_count: u8,
|
|
|
|
perp_oo_count: u8,
|
2022-07-25 07:07:53 -07:00
|
|
|
name: String,
|
|
|
|
) -> Result<()> {
|
2022-12-29 02:48:46 -08:00
|
|
|
let mut account = ctx.accounts.account.load_full_init()?;
|
2022-06-21 02:45:38 -07:00
|
|
|
|
2022-08-04 00:25:19 -07:00
|
|
|
msg!(
|
|
|
|
"Initialized account with header version {}",
|
|
|
|
account.header_version()
|
|
|
|
);
|
|
|
|
|
2022-08-12 07:05:32 -07:00
|
|
|
account.fixed.name = fill_from_str(&name)?;
|
2022-07-25 07:07:53 -07:00
|
|
|
account.fixed.group = ctx.accounts.group.key();
|
|
|
|
account.fixed.owner = ctx.accounts.owner.key();
|
|
|
|
account.fixed.account_num = account_num;
|
|
|
|
account.fixed.bump = *ctx.bumps.get("account").ok_or(MangoError::SomeError)?;
|
|
|
|
account.fixed.delegate = Pubkey::default();
|
|
|
|
account.fixed.set_being_liquidated(false);
|
|
|
|
|
2022-08-07 05:16:06 -07:00
|
|
|
account.expand_dynamic_content(token_count, serum3_count, perp_count, perp_oo_count)?;
|
2022-02-28 06:42:14 -08:00
|
|
|
|
2022-02-22 04:31:03 -08:00
|
|
|
Ok(())
|
|
|
|
}
|