Rearrange accounts to avoid padding bytes
This commit is contained in:
parent
9cf4f1a748
commit
56e3bd8740
|
@ -43,7 +43,7 @@ pub fn create_account(ctx: Context<CreateAccount>, account_num: u8) -> Result<()
|
|||
is_bankrupt: 0,
|
||||
account_num,
|
||||
bump: *ctx.bumps.get("account").ok_or(MangoError::SomeError)?,
|
||||
reserved: [0; 4],
|
||||
reserved: Default::default(),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -104,6 +104,7 @@ pub fn register_token(
|
|||
liquidation_fee: I80F48::from_num(liquidation_fee),
|
||||
dust: I80F48::ZERO,
|
||||
token_index,
|
||||
reserved: Default::default(),
|
||||
};
|
||||
|
||||
// TODO: ALTs are unavailable
|
||||
|
@ -122,6 +123,7 @@ pub fn register_token(
|
|||
address_lookup_table: address_lookup_table,
|
||||
address_lookup_table_bank_index: alt_previous_size as u8,
|
||||
address_lookup_table_oracle_index: alt_previous_size as u8 + 1,
|
||||
reserved: Default::default(),
|
||||
};
|
||||
|
||||
// TODO: ALTs are unavailable
|
||||
|
|
|
@ -69,6 +69,7 @@ pub fn serum3_register_market(
|
|||
base_token_index: base_bank.token_index,
|
||||
quote_token_index: quote_bank.token_index,
|
||||
bump: *ctx.bumps.get("serum_market").ok_or(MangoError::SomeError)?,
|
||||
reserved: Default::default(),
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use anchor_lang::prelude::*;
|
||||
use fixed::types::I80F48;
|
||||
use static_assertions::const_assert_eq;
|
||||
use std::mem::size_of;
|
||||
|
||||
use super::{TokenAccount, TokenIndex};
|
||||
use crate::util::checked_math as cm;
|
||||
|
@ -42,7 +44,11 @@ pub struct Bank {
|
|||
|
||||
// Index into TokenInfo on the group
|
||||
pub token_index: TokenIndex,
|
||||
|
||||
pub reserved: [u8; 6],
|
||||
}
|
||||
const_assert_eq!(size_of::<Bank>(), 32 * 4 + 16 * 10 + 2 + 6);
|
||||
const_assert_eq!(size_of::<Bank>() % 8, 0);
|
||||
|
||||
impl Bank {
|
||||
pub fn native_total_deposits(&self) -> I80F48 {
|
||||
|
@ -206,7 +212,7 @@ mod tests {
|
|||
indexed_value: I80F48::ZERO,
|
||||
token_index: 0,
|
||||
in_use_count: if is_in_use { 1 } else { 0 },
|
||||
reserved: [0; 5],
|
||||
reserved: Default::default(),
|
||||
};
|
||||
|
||||
account.indexed_value = indexed(I80F48::from_num(start), &bank);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use anchor_lang::prelude::*;
|
||||
use static_assertions::const_assert_eq;
|
||||
use std::mem::size_of;
|
||||
|
||||
// TODO: Assuming we allow up to 65536 different tokens
|
||||
pub type TokenIndex = u16;
|
||||
|
@ -10,31 +12,11 @@ pub struct Group {
|
|||
// pub meta_data: MetaData,
|
||||
pub admin: Pubkey,
|
||||
|
||||
//pub num_oracles: usize, // incremented every time add_oracle is called
|
||||
//pub oracles: [Pubkey; MAX_PAIRS],
|
||||
|
||||
//pub spot_markets: [SpotMarketInfo; MAX_PAIRS],
|
||||
//pub perp_markets: [PerpMarketInfo; MAX_PAIRS],
|
||||
|
||||
//pub signer_nonce: u64,
|
||||
//pub signer_key: Pubkey,
|
||||
// todo: which more dex'es do we want to support? orca for pure swap?
|
||||
//pub dex_program_id: Pubkey,
|
||||
|
||||
//pub cache_valid_interval: u64,
|
||||
|
||||
// todo: do we need this limit? afaik this was for ts liquidator to keep on working, maybe
|
||||
// with liquidatable-accounts-feed we have some sort of scaling? maybe we bought
|
||||
// some more breathing space?
|
||||
//pub max_mango_accounts: u32, // limits maximum number of MangoAccounts.v1 (closeable) accounts
|
||||
//pub num_mango_accounts: u32, // number of MangoAccounts.v1
|
||||
|
||||
//pub ref_surcharge_centibps: u32, // 100
|
||||
//pub ref_share_centibps: u32, // 80 (must be less than surcharge)
|
||||
//pub ref_mngo_required: u64,
|
||||
pub bump: u8,
|
||||
pub reserved: [u8; 7],
|
||||
}
|
||||
// TODO: static assert the size and alignment
|
||||
const_assert_eq!(size_of::<Group>(), 40);
|
||||
const_assert_eq!(size_of::<Group>() % 8, 0);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! group_seeds {
|
||||
|
|
|
@ -81,7 +81,7 @@ impl TokenAccountMap {
|
|||
indexed_value: I80F48::ZERO,
|
||||
token_index: TokenIndex::MAX,
|
||||
in_use_count: 0,
|
||||
reserved: [0; 5],
|
||||
reserved: Default::default(),
|
||||
}; MAX_INDEXED_POSITIONS],
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl TokenAccountMap {
|
|||
indexed_value: I80F48::ZERO,
|
||||
token_index,
|
||||
in_use_count: 0,
|
||||
reserved: [0; 5],
|
||||
reserved: Default::default(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ impl Default for Serum3Account {
|
|||
market_index: Serum3MarketIndex::MAX,
|
||||
base_token_index: TokenIndex::MAX,
|
||||
quote_token_index: TokenIndex::MAX,
|
||||
reserved: [0; 2],
|
||||
reserved: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ impl Default for PerpAccount {
|
|||
asks_quantity: 0,
|
||||
taker_base: 0,
|
||||
taker_quote: 0,
|
||||
reserved: [0; 6],
|
||||
reserved: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use anchor_lang::prelude::*;
|
||||
use static_assertions::const_assert_eq;
|
||||
use std::mem::size_of;
|
||||
|
||||
use super::TokenIndex;
|
||||
|
||||
|
@ -13,10 +15,15 @@ pub struct MintInfo {
|
|||
pub bank: Pubkey,
|
||||
pub vault: Pubkey,
|
||||
pub oracle: Pubkey,
|
||||
pub address_lookup_table: Pubkey,
|
||||
|
||||
pub token_index: TokenIndex,
|
||||
|
||||
// describe what address map relevant accounts are found on
|
||||
pub address_lookup_table: Pubkey,
|
||||
pub address_lookup_table_bank_index: u8,
|
||||
pub address_lookup_table_oracle_index: u8,
|
||||
|
||||
pub reserved: [u8; 4],
|
||||
}
|
||||
const_assert_eq!(size_of::<MintInfo>(), 5 * 32 + 2 + 2 + 4);
|
||||
const_assert_eq!(size_of::<MintInfo>() % 8, 0);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use anchor_lang::prelude::*;
|
||||
use static_assertions::const_assert_eq;
|
||||
use std::mem::size_of;
|
||||
|
||||
use crate::state::*;
|
||||
|
||||
|
@ -15,8 +17,10 @@ pub struct Serum3Market {
|
|||
pub quote_token_index: TokenIndex,
|
||||
|
||||
pub bump: u8,
|
||||
pub reserved: [u8; 1],
|
||||
}
|
||||
// TODO: static assert the size and alignment
|
||||
const_assert_eq!(size_of::<Serum3Market>(), 32 * 3 + 3 * 2 + 1 + 1);
|
||||
const_assert_eq!(size_of::<Serum3Market>() % 8, 0);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! serum_market_seeds {
|
||||
|
|
Loading…
Reference in New Issue