Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor state #276

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use marginfi::state::marginfi_account::TRANSFER_AUTHORITY_ALLOWED_FLAG;
use marginfi::{
prelude::*,
state::{
bank::{Bank, BankConfig, BankConfigOpt},
interest_rate::{InterestRateConfig, InterestRateConfigOpt},
marginfi_account::{Balance, LendingAccount, MarginfiAccount, FLASHLOAN_ENABLED_FLAG},
marginfi_group::{
Bank, BankConfig, BankConfigOpt, BankOperationalState, InterestRateConfig,
InterestRateConfigOpt, OracleConfig, RiskTier, WrappedI80F48,
},
marginfi_group::{BankOperationalState, OracleConfig, RiskTier, WrappedI80F48},
price::OracleSetup,
},
};
Expand Down Expand Up @@ -753,7 +752,7 @@ fn bank(subcmd: BankCommand, global_options: &GlobalOptions) -> Result<()> {
} => {
let bank = config
.mfi_program
.account::<marginfi::state::marginfi_group::Bank>(bank_pk)
.account::<marginfi::state::bank::Bank>(bank_pk)
.unwrap();
processor::bank_configure(
config,
Expand Down Expand Up @@ -859,10 +858,7 @@ fn inspect_padding() -> Result<()> {
println!("MarginfiGroup: {}", MarginfiGroup::type_layout());
println!("GroupConfig: {}", GroupConfig::type_layout());
println!("InterestRateConfig: {}", InterestRateConfig::type_layout());
println!(
"Bank: {}",
marginfi::state::marginfi_group::Bank::type_layout()
);
println!("Bank: {}", marginfi::state::bank::Bank::type_layout());
println!("BankConfig: {}", BankConfig::type_layout());
println!("OracleConfig: {}", OracleConfig::type_layout());
println!("BankConfigOpt: {}", BankConfigOpt::type_layout());
Expand All @@ -881,10 +877,7 @@ fn inspect_size() -> Result<()> {
println!("MarginfiGroup: {}", size_of::<MarginfiGroup>());
println!("GroupConfig: {}", size_of::<GroupConfig>());
println!("InterestRateConfig: {}", size_of::<InterestRateConfig>());
println!(
"Bank: {}",
size_of::<marginfi::state::marginfi_group::Bank>()
);
println!("Bank: {}", size_of::<marginfi::state::bank::Bank>());
println!("BankConfig: {}", size_of::<BankConfig>());
println!("OracleConfig: {}", size_of::<OracleConfig>());
println!("BankConfigOpt: {}", size_of::<BankConfigOpt>());
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/marginfi-cli/src/processor/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anchor_spl::associated_token;
use anyhow::Result;
use marginfi::{
bank_authority_seed,
state::marginfi_group::{Bank, BankVaultType},
state::{bank::Bank, marginfi_group::BankVaultType},
};
use solana_sdk::{
instruction::Instruction, message::Message, pubkey::Pubkey, transaction::Transaction,
Expand Down
2 changes: 1 addition & 1 deletion clients/rust/marginfi-cli/src/processor/group.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{config::Config, profile::Profile, utils};
use anyhow::Result;
use log::{debug, info, warn};
use marginfi::state::marginfi_group::Bank;
use marginfi::state::bank::Bank;
use solana_address_lookup_table_program::{
instruction::{create_lookup_table, extend_lookup_table},
state::AddressLookupTable,
Expand Down
7 changes: 3 additions & 4 deletions clients/rust/marginfi-cli/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ use {
},
prelude::*,
state::{
bank::{Bank, BankConfig, BankConfigOpt},
interest_rate::InterestRateConfig,
marginfi_account::{BankAccountWrapper, MarginfiAccount},
marginfi_group::{
Bank, BankConfig, BankConfigOpt, BankOperationalState, BankVaultType,
InterestRateConfig, WrappedI80F48,
},
marginfi_group::{BankOperationalState, BankVaultType, WrappedI80F48},
price::{OraclePriceFeedAdapter, OracleSetup, PriceAdapter, PythPushOraclePriceFeed},
},
utils::NumTraitsWithTolerance,
Expand Down
3 changes: 2 additions & 1 deletion clients/rust/marginfi-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ use {
PYTH_PUSH_PYTH_SPONSORED_SHARD_ID,
},
state::{
bank::{Bank, BankConfig},
marginfi_account::MarginfiAccount,
marginfi_group::{Bank, BankConfig, BankVaultType},
marginfi_group::BankVaultType,
price::PythPushOraclePriceFeed,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use anchor_lang::prelude::*;
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
use marginfi::state::marginfi_group::Bank;
use marginfi::state::bank::Bank;
use std::mem::size_of;

pub fn process<'info>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anchor_spl::{
token_2022::{close_account, CloseAccount},
token_interface::{Mint, TokenAccount, TokenInterface},
};
use marginfi::{program::Marginfi, state::marginfi_group::Bank};
use marginfi::{program::Marginfi, state::bank::Bank};
use std::mem::size_of;

/// Creates a new deposit in an active liquidity incentive campaign (LIP).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anchor_spl::{
token_interface::{Mint, TokenAccount, TokenInterface},
};
use fixed::types::I80F48;
use marginfi::{program::Marginfi, state::marginfi_group::Bank};
use marginfi::{program::Marginfi, state::bank::Bank};

use crate::{
constants::{
Expand Down
2 changes: 1 addition & 1 deletion programs/marginfi/fuzz/fuzz_targets/lend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use arbitrary::Arbitrary;
use fixed::types::I80F48;
use lazy_static::lazy_static;
use libfuzzer_sys::fuzz_target;
use marginfi::{assert_eq_with_tolerance, prelude::MarginfiGroup, state::marginfi_group::Bank};
use marginfi::{assert_eq_with_tolerance, prelude::MarginfiGroup, state::bank::Bank};
use marginfi_fuzz::{
account_state::AccountsState, arbitrary_helpers::*, metrics::Metrics, MarginfiFuzzContext,
};
Expand Down
4 changes: 3 additions & 1 deletion programs/marginfi/fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ use marginfi::{
instructions::LendingPoolAddBankBumps,
prelude::MarginfiGroup,
state::{
bank::{Bank, BankConfig},
interest_rate::InterestRateConfig,
marginfi_account::MarginfiAccount,
marginfi_group::{Bank, BankConfig, BankVaultType, InterestRateConfig},
marginfi_group::BankVaultType,
},
};
use metrics::{MetricAction, Metrics};
Expand Down
2 changes: 1 addition & 1 deletion programs/marginfi/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{prelude::*, state::marginfi_group::BankConfigOpt};
use crate::{prelude::*, state::bank::BankConfigOpt};
use anchor_lang::prelude::*;

// Event headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use crate::{
math_error,
prelude::{MarginfiError, MarginfiGroup, MarginfiResult},
state::{
marginfi_account::{BankAccountWrapper, MarginfiAccount, RiskEngine, DISABLED_FLAG},
marginfi_group::{Bank, BankVaultType},
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::BankVaultType,
risk_engine::RiskEngine,
},
utils::{self, validate_asset_tags},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
check,
prelude::*,
state::{
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::Bank,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
events::{AccountEventHeader, LendingAccountDepositEvent},
prelude::*,
state::{
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::Bank,
},
utils::{self, validate_asset_tags},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use crate::{
debug,
prelude::{MarginfiError, MarginfiResult},
state::{
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::{Bank, MarginfiGroup},
marginfi_group::MarginfiGroup,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use solana_program::{
use crate::{
check,
prelude::*,
state::marginfi_account::{MarginfiAccount, RiskEngine, DISABLED_FLAG, IN_FLASHLOAN_FLAG},
state::{
marginfi_account::{MarginfiAccount, DISABLED_FLAG},
risk_engine::{RiskEngine, IN_FLASHLOAN_FLAG},
},
};

pub fn lending_account_start_flashloan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use crate::constants::{
INSURANCE_VAULT_SEED, LIQUIDATION_INSURANCE_FEE, LIQUIDATION_LIQUIDATOR_FEE,
};
use crate::events::{AccountEventHeader, LendingAccountLiquidateEvent, LiquidationBalances};
use crate::state::marginfi_account::{calc_amount, calc_value, RiskEngine};
use crate::state::marginfi_group::{Bank, BankVaultType};
use crate::state::price::{OraclePriceFeedAdapter, OraclePriceType, PriceAdapter, PriceBias};
use crate::state::{
bank::Bank,
marginfi_account::{calc_amount, calc_value},
marginfi_group::BankVaultType,
risk_engine::RiskEngine,
};
use crate::utils::{validate_asset_tags, validate_bank_asset_tags};
use crate::{
bank_signer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
events::{AccountEventHeader, LendingAccountRepayEvent},
prelude::{MarginfiError, MarginfiGroup, MarginfiResult},
state::{
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::Bank,
},
utils,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use crate::{
events::{AccountEventHeader, LendingAccountWithdrawEvent},
prelude::*,
state::{
marginfi_account::{BankAccountWrapper, MarginfiAccount, RiskEngine, DISABLED_FLAG},
marginfi_group::{Bank, BankVaultType},
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::BankVaultType,
risk_engine::RiskEngine,
},
utils,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
state::marginfi_group::{Bank, MarginfiGroup},
state::{bank::Bank, marginfi_group::MarginfiGroup},
MarginfiResult,
};
use anchor_lang::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::{
},
events::{GroupEventHeader, LendingPoolBankCreateEvent},
state::{
bank::{Bank, BankConfig, BankConfigCompact},
fee_state::FeeState,
marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup},
marginfi_group::MarginfiGroup,
},
MarginfiError, MarginfiResult,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::{
},
events::{GroupEventHeader, LendingPoolBankCreateEvent},
state::{
marginfi_group::{
Bank, BankConfigCompact, BankOperationalState, InterestRateConfig, MarginfiGroup,
},
bank::{Bank, BankConfigCompact},
interest_rate::InterestRateConfig,
marginfi_group::{BankOperationalState, MarginfiGroup},
price::OracleSetup,
staked_settings::StakedSettings,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::{
},
events::{GroupEventHeader, LendingPoolBankCreateEvent},
state::{
bank::{Bank, BankConfig, BankConfigCompact},
fee_state::FeeState,
marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup},
marginfi_group::MarginfiGroup,
},
MarginfiError, MarginfiResult,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use crate::{
FEE_VAULT_SEED, INSURANCE_VAULT_SEED, LIQUIDITY_VAULT_AUTHORITY_SEED, LIQUIDITY_VAULT_SEED,
},
math_error,
state::marginfi_group::{Bank, BankVaultType, MarginfiGroup},
state::{
bank::Bank,
marginfi_group::{BankVaultType, MarginfiGroup},
},
MarginfiResult,
};
use crate::{check, utils, MarginfiError};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ pub struct UnsetAccountFlag<'info> {

#[cfg(test)]
mod tests {
use crate::state::marginfi_account::{
DISABLED_FLAG, FLASHLOAN_ENABLED_FLAG, IN_FLASHLOAN_FLAG, TRANSFER_AUTHORITY_ALLOWED_FLAG,
use crate::state::{
marginfi_account::{
DISABLED_FLAG, FLASHLOAN_ENABLED_FLAG, TRANSFER_AUTHORITY_ALLOWED_FLAG,
},
risk_engine::IN_FLASHLOAN_FLAG,
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::events::{
use crate::prelude::MarginfiError;
use crate::{check, math_error, utils};
use crate::{
state::marginfi_group::{Bank, BankConfigOpt, MarginfiGroup},
state::{
bank::{Bank, BankConfigOpt},
marginfi_group::MarginfiGroup,
},
MarginfiResult,
};
use anchor_lang::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ use crate::{
math_error,
prelude::MarginfiError,
state::{
marginfi_account::{BankAccountWrapper, MarginfiAccount, RiskEngine, DISABLED_FLAG},
marginfi_group::{Bank, BankVaultType, MarginfiGroup},
bank::Bank,
marginfi_account::{BankAccountWrapper, MarginfiAccount, DISABLED_FLAG},
marginfi_group::{BankVaultType, MarginfiGroup},
risk_engine::RiskEngine,
},
utils, MarginfiResult,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::constants::ASSET_TAG_STAKED;
// Permissionless ix to propagate a group's staked collateral settings to any bank in that group
use crate::state::marginfi_group::Bank;
use crate::state::staked_settings::StakedSettings;
use crate::state::{bank::Bank, staked_settings::StakedSettings};
use crate::MarginfiGroup;
use anchor_lang::prelude::*;

Expand Down
6 changes: 4 additions & 2 deletions programs/marginfi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ pub mod utils;
use anchor_lang::prelude::*;
use instructions::*;
use prelude::*;
use state::marginfi_group::WrappedI80F48;
use state::marginfi_group::{BankConfigCompact, BankConfigOpt};
use state::{
bank::{BankConfigCompact, BankConfigOpt},
marginfi_group::WrappedI80F48,
};

cfg_if::cfg_if! {
if #[cfg(feature = "mainnet-beta")] {
Expand Down
Loading