copy structs from v3, next goal is to see what we can retain and what to change

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2022-02-10 09:07:34 +01:00
parent d7229d7a48
commit 5ab8f6e09e
17 changed files with 281 additions and 6 deletions

View File

@ -6,6 +6,6 @@ use crate::error::*;
pub struct Initialize {}
pub fn handler(ctx: Context<Initialize>) -> ProgramResult {
require!(1==1, ErrorCode::SomeError);
require!(1 == 1, ErrorCode::SomeError);
Ok(())
}
}

View File

@ -1,3 +1,3 @@
pub use initialiaze::*;
pub mod initialiaze;
pub mod initialiaze;

View File

@ -3,9 +3,9 @@ extern crate static_assertions;
use anchor_lang::prelude::*;
mod state;
mod instructions;
mod error;
mod instructions;
mod state;
use instructions::*;
@ -18,7 +18,6 @@ pub mod mango_v4 {
pub fn initialize(ctx: Context<Initialize>) -> ProgramResult {
instructions::initialiaze::handler(ctx)
}
}
#[derive(Clone)]

View File

@ -0,0 +1,30 @@
pub struct AnyAdvancedOrder {
pub advanced_order_type: AdvancedOrderType,
pub is_active: bool,
pub padding: [u8; ADVANCED_ORDER_SIZE - 2],
}
pub struct PerpTriggerOrder {
pub advanced_order_type: AdvancedOrderType,
pub is_active: bool,
pub market_index: u8,
pub order_type: OrderType,
pub side: Side,
pub trigger_condition: TriggerCondition, // Bid & Below => Take profit on short, Bid & Above => stop loss on short
pub reduce_only: bool, // only valid on perp order
pub padding0: [u8; 1],
pub client_order_id: u64,
pub price: i64,
pub quantity: i64,
pub trigger_price: I80F48,
/// Padding for expansion
pub padding1: [u8; 32],
}
pub struct AdvancedOrders {
pub meta_data: MetaData,
pub orders: [AnyAdvancedOrder; MAX_ADVANCED_ORDERS],
}

View File

@ -0,0 +1,24 @@
pub struct PriceCache {
pub price: I80F48, // unit is interpreted as how many quote native tokens for 1 base native token
pub last_update: u64,
}
pub struct RootBankCache {
pub deposit_index: I80F48,
pub borrow_index: I80F48,
pub last_update: u64,
}
pub struct PerpMarketCache {
pub long_funding: I80F48,
pub short_funding: I80F48,
pub last_update: u64,
}
pub struct MangoCache {
pub meta_data: MetaData,
pub price_cache: [PriceCache; MAX_PAIRS],
pub root_bank_cache: [RootBankCache; MAX_TOKENS],
pub perp_market_cache: [PerpMarketCache; MAX_PAIRS],
}

View File

@ -0,0 +1,16 @@
pub struct UserActiveAssets {
pub spot: [bool; MAX_PAIRS],
pub perps: [bool; MAX_PAIRS],
}
pub struct HealthCache {
pub active_assets: UserActiveAssets,
/// Vec of length MAX_PAIRS containing worst case spot vals; unweighted
spot: Vec<(I80F48, I80F48)>,
perp: Vec<(I80F48, I80F48)>,
quote: I80F48,
/// This will be zero until update_health is called for the first time
health: [Option<I80F48>; 2],
}

View File

@ -0,0 +1,46 @@
pub struct MangoAccount {
pub meta_data: MetaData,
pub mango_group: Pubkey,
pub owner: Pubkey,
pub in_margin_basket: [bool; MAX_PAIRS],
pub num_in_margin_basket: u8,
// Spot and Margin related data
pub deposits: [I80F48; MAX_TOKENS],
pub borrows: [I80F48; MAX_TOKENS],
pub spot_open_orders: [Pubkey; MAX_PAIRS],
// Perps related data
pub perp_accounts: [PerpAccount; MAX_PAIRS],
pub order_market: [u8; MAX_PERP_OPEN_ORDERS],
pub order_side: [Side; MAX_PERP_OPEN_ORDERS],
pub orders: [i128; MAX_PERP_OPEN_ORDERS],
pub client_order_ids: [u64; MAX_PERP_OPEN_ORDERS],
pub msrm_amount: u64,
/// This account cannot open new positions or borrow until `init_health >= 0`
pub being_liquidated: bool,
/// This account cannot do anything except go through `resolve_bankruptcy`
pub is_bankrupt: bool,
pub info: [u8; INFO_LEN],
/// Starts off as zero pubkey and points to the AdvancedOrders account
pub advanced_orders_key: Pubkey,
/// Can this account be upgraded to v1 so it can be closed
pub not_upgradable: bool,
// Alternative authority/signer of transactions for a mango account
pub delegate: Pubkey,
/// padding for expansions
/// Note: future expansion can also be just done via isolated PDAs
/// which can be computed independently and dont need to be linked from
/// this account
pub padding: [u8; 5],
}

View File

@ -0,0 +1,31 @@
pub struct MangoGroup {
pub meta_data: MetaData,
pub num_oracles: usize, // incremented every time add_oracle is called
pub tokens: [TokenInfo; MAX_TOKENS],
pub spot_markets: [SpotMarketInfo; MAX_PAIRS],
pub perp_markets: [PerpMarketInfo; MAX_PAIRS],
pub oracles: [Pubkey; MAX_PAIRS],
pub signer_nonce: u64,
pub signer_key: Pubkey,
pub admin: Pubkey, // Used to add new markets and adjust risk params
pub dex_program_id: Pubkey, // Consider allowing more
pub mango_cache: Pubkey,
pub valid_interval: u64,
// insurance vault is funded by the Mango DAO with USDC and can be withdrawn by the DAO
pub insurance_vault: Pubkey,
pub srm_vault: Pubkey,
pub msrm_vault: Pubkey,
pub fees_vault: Pubkey,
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 padding: [u8; 8], // padding used for future expansions
}

View File

@ -0,0 +1,12 @@
mod cache;
mod health;
mod mango_account;
mod mango_group;
mod node_bank;
mod order_book_state_header;
mod perp_account;
mod perp_market;
mod perp_market_info;
mod referrer;
mod root_bank;
mod spot_market_info;

View File

@ -0,0 +1,7 @@
pub struct NodeBank {
pub meta_data: MetaData,
pub deposits: I80F48,
pub borrows: I80F48,
pub vault: Pubkey,
}

View File

@ -0,0 +1,3 @@
pub struct OrderBookStateHeader {
pub account_flags: u64, // Initialized, (Bids or Asks)
}

View File

@ -0,0 +1,17 @@
pub struct PerpAccount {
pub base_position: i64, // measured in base lots
pub quote_position: I80F48, // measured in native quote
pub long_settled_funding: I80F48,
pub short_settled_funding: I80F48,
// orders related info
pub bids_quantity: i64, // total contracts in sell orders
pub asks_quantity: i64, // total quote currency in buy orders
/// Amount that's on EventQueue waiting to be processed
pub taker_base: i64,
pub taker_quote: i64,
pub mngo_accrued: u64,
}

View File

@ -0,0 +1,44 @@
pub struct LiquidityMiningInfo {
/// Used to convert liquidity points to MNGO
pub rate: I80F48,
pub max_depth_bps: I80F48, // instead of max depth bps, this should be max num contracts
/// start timestamp of current liquidity incentive period; gets updated when mngo_left goes to 0
pub period_start: u64,
/// Target time length of a period in seconds
pub target_period_length: u64,
/// Paper MNGO left for this period
pub mngo_left: u64,
/// Total amount of MNGO allocated for current period
pub mngo_per_period: u64,
}
pub struct PerpMarket {
pub meta_data: MetaData,
pub mango_group: Pubkey,
pub bids: Pubkey,
pub asks: Pubkey,
pub event_queue: Pubkey,
pub quote_lot_size: i64, // number of quote native that reresents min tick
pub base_lot_size: i64, // represents number of base native quantity; greater than 0
// TODO - consider just moving this into the cache
pub long_funding: I80F48,
pub short_funding: I80F48,
pub open_interest: i64, // This is i64 to keep consistent with the units of contracts, but should always be > 0
pub last_updated: u64,
pub seq_num: u64,
pub fees_accrued: I80F48, // native quote currency
pub liquidity_mining_info: LiquidityMiningInfo,
// mngo_vault holds mango tokens to be disbursed as liquidity incentives for this perp market
pub mngo_vault: Pubkey,
}

View File

@ -0,0 +1,12 @@
pub struct PerpMarketInfo {
pub perp_market: Pubkey, // One of these may be empty
pub maint_asset_weight: I80F48,
pub init_asset_weight: I80F48,
pub maint_liab_weight: I80F48,
pub init_liab_weight: I80F48,
pub liquidation_fee: I80F48,
pub maker_fee: I80F48,
pub taker_fee: I80F48,
pub base_lot_size: i64, // The lot size of the underlying
pub quote_lot_size: i64, // min tick
}

View File

@ -0,0 +1,10 @@
pub struct ReferrerMemory {
pub meta_data: MetaData,
pub referrer_mango_account: Pubkey,
}
pub struct ReferrerIdRecord {
pub meta_data: MetaData,
pub referrer_mango_account: Pubkey,
pub id: [u8; INFO_LEN], // this id is one of the seeds
}

View File

@ -0,0 +1,16 @@
pub struct RootBank {
pub meta_data: MetaData,
pub optimal_util: I80F48,
pub optimal_rate: I80F48,
pub max_rate: I80F48,
pub num_node_banks: usize,
pub node_banks: [Pubkey; MAX_NODE_BANKS],
pub deposit_index: I80F48,
pub borrow_index: I80F48,
pub last_updated: u64,
padding: [u8; 64], // used for future expansions
}

View File

@ -0,0 +1,8 @@
pub struct SpotMarketInfo {
pub spot_market: Pubkey,
pub maint_asset_weight: I80F48,
pub init_asset_weight: I80F48,
pub maint_liab_weight: I80F48,
pub init_liab_weight: I80F48,
pub liquidation_fee: I80F48,
}