Skip to content

Commit

Permalink
Attempt fix cli and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jgur-psyops committed Aug 28, 2024
1 parent b29cbb6 commit 1f07a9b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
4 changes: 4 additions & 0 deletions clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ pub enum GroupCommand {
default_value = "60"
)]
oracle_max_age: u16,
#[clap(long)]
global_fee_wallet: Pubkey,
},
HandleBankruptcy {
accounts: Vec<Pubkey>,
Expand Down Expand Up @@ -576,6 +578,7 @@ fn group(subcmd: GroupCommand, global_options: &GlobalOptions) -> Result<()> {
risk_tier,
oracle_type,
oracle_max_age,
global_fee_wallet,
} => processor::group_add_bank(
config,
profile,
Expand All @@ -600,6 +603,7 @@ fn group(subcmd: GroupCommand, global_options: &GlobalOptions) -> Result<()> {
risk_tier,
oracle_max_age,
global_options.compute_unit_price,
global_fee_wallet,
),

GroupCommand::HandleBankruptcy { accounts } => {
Expand Down
13 changes: 11 additions & 2 deletions clients/rust/marginfi-cli/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use {
utils::{
bank_to_oracle_key, calc_emissions_rate, create_oracle_key_array,
find_bank_emssions_auth_pda, find_bank_emssions_token_account_pda,
find_bank_vault_authority_pda, find_bank_vault_pda, load_observation_account_metas,
process_transaction, EXP_10_I80F48,
find_bank_vault_authority_pda, find_bank_vault_pda, find_fee_state_pda,
load_observation_account_metas, process_transaction, EXP_10_I80F48,
},
},
anchor_client::{
Expand Down Expand Up @@ -317,6 +317,7 @@ pub fn group_add_bank(
risk_tier: crate::RiskTierArg,
oracle_max_age: u16,
compute_unit_price: Option<u64>,
global_fee_wallet: Pubkey,
) -> Result<()> {
let rpc_client = config.mfi_program.rpc();

Expand Down Expand Up @@ -384,6 +385,7 @@ pub fn group_add_bank(
oracle_setup,
risk_tier,
oracle_max_age,
global_fee_wallet,
)?
} else {
create_bank_ix(
Expand All @@ -404,6 +406,7 @@ pub fn group_add_bank(
oracle_setup,
risk_tier,
oracle_max_age,
global_fee_wallet,
)?
};

Expand Down Expand Up @@ -445,6 +448,7 @@ fn create_bank_ix_with_seed(
oracle_setup: crate::OracleTypeArg,
risk_tier: crate::RiskTierArg,
oracle_max_age: u16,
global_fee_wallet: Pubkey,
) -> Result<Vec<Instruction>> {
use solana_sdk::commitment_config::CommitmentConfig;

Expand Down Expand Up @@ -514,6 +518,8 @@ fn create_bank_ix_with_seed(
token_program,
system_program: system_program::id(),
fee_payer: config.authority(),
fee_state: find_fee_state_pda(&config.program_id).0,
global_fee_wallet,
})
.accounts(AccountMeta::new_readonly(oracle_key, false))
.args(marginfi::instruction::LendingPoolAddBankWithSeed {
Expand Down Expand Up @@ -562,6 +568,7 @@ fn create_bank_ix(
oracle_setup: crate::OracleTypeArg,
risk_tier: crate::RiskTierArg,
oracle_max_age: u16,
global_fee_wallet: Pubkey,
) -> Result<Vec<Instruction>> {
let add_bank_ixs_builder = config.mfi_program.request();
let add_bank_ixs = add_bank_ixs_builder
Expand Down Expand Up @@ -610,6 +617,8 @@ fn create_bank_ix(
token_program,
system_program: system_program::id(),
fee_payer: config.explicit_fee_payer(),
fee_state: find_fee_state_pda(&config.program_id).0,
global_fee_wallet,
})
.accounts(AccountMeta::new_readonly(oracle_key, false))
.args(marginfi::instruction::LendingPoolAddBank {
Expand Down
10 changes: 8 additions & 2 deletions clients/rust/marginfi-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use {
marginfi::{
bank_authority_seed, bank_seed,
constants::{
EMISSIONS_AUTH_SEED, EMISSIONS_TOKEN_ACCOUNT_SEED, MAX_ORACLE_KEYS,
PYTH_PUSH_PYTH_SPONSORED_SHARD_ID,
EMISSIONS_AUTH_SEED, EMISSIONS_TOKEN_ACCOUNT_SEED, FEE_STATE_SEED, MAX_ORACLE_KEYS, PYTH_PUSH_PYTH_SPONSORED_SHARD_ID
},
state::{
marginfi_account::MarginfiAccount,
Expand Down Expand Up @@ -126,6 +125,13 @@ pub fn find_bank_emssions_token_account_pda(
)
}

pub fn find_fee_state_pda(
program_id: &Pubkey,
) -> (Pubkey, u8) {
Pubkey::find_program_address(&[FEE_STATE_SEED.as_bytes()], program_id)
}


pub fn create_oracle_key_array(oracle_key: Pubkey) -> [Pubkey; MAX_ORACLE_KEYS] {
let mut oracle_keys = [Pubkey::default(); MAX_ORACLE_KEYS];
oracle_keys[0] = oracle_key;
Expand Down
10 changes: 7 additions & 3 deletions programs/marginfi/src/instructions/marginfi_group/add_pool.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::{
constants::{
FEE_STATE_SEED, FEE_VAULT_AUTHORITY_SEED, FEE_VAULT_SEED, INSURANCE_VAULT_AUTHORITY_SEED, INSURANCE_VAULT_SEED, LIQUIDITY_VAULT_AUTHORITY_SEED, LIQUIDITY_VAULT_SEED
FEE_STATE_SEED, FEE_VAULT_AUTHORITY_SEED, FEE_VAULT_SEED, INSURANCE_VAULT_AUTHORITY_SEED,
INSURANCE_VAULT_SEED, LIQUIDITY_VAULT_AUTHORITY_SEED, LIQUIDITY_VAULT_SEED,
},
events::{GroupEventHeader, LendingPoolBankCreateEvent},
state::{fee_state::FeeState, marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup}},
state::{
fee_state::FeeState,
marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup},
},
MarginfiResult,
};
use anchor_lang::prelude::*;
Expand Down Expand Up @@ -99,7 +103,7 @@ pub struct LendingPoolAddBank<'info> {

// Note: there is just one FeeState per program, so no further check is required.
#[account(
seeds = [FEE_STATE_SEED.as_bytes()],
seeds = [FEE_STATE_SEED.as_bytes()],
bump,
has_one = global_fee_wallet
)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use crate::{
constants::{
FEE_STATE_SEED, FEE_VAULT_AUTHORITY_SEED, FEE_VAULT_SEED, INSURANCE_VAULT_AUTHORITY_SEED, INSURANCE_VAULT_SEED, LIQUIDITY_VAULT_AUTHORITY_SEED, LIQUIDITY_VAULT_SEED
FEE_STATE_SEED, FEE_VAULT_AUTHORITY_SEED, FEE_VAULT_SEED, INSURANCE_VAULT_AUTHORITY_SEED,
INSURANCE_VAULT_SEED, LIQUIDITY_VAULT_AUTHORITY_SEED, LIQUIDITY_VAULT_SEED,
},
events::{GroupEventHeader, LendingPoolBankCreateEvent},
state::{fee_state::FeeState, marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup}},
state::{
fee_state::FeeState,
marginfi_group::{Bank, BankConfig, BankConfigCompact, MarginfiGroup},
},
MarginfiResult,
};
use anchor_lang::prelude::*;
Expand Down Expand Up @@ -99,7 +103,7 @@ pub struct LendingPoolAddBankWithSeed<'info> {

// Note: there is just one FeeState per program, so no further check is required.
#[account(
seeds = [FEE_STATE_SEED.as_bytes()],
seeds = [FEE_STATE_SEED.as_bytes()],
bump,
has_one = global_fee_wallet
)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Global fee admin calls this to edit the fee rate or the fee wallet.

use crate::state::fee_state;
use crate::constants::FEE_STATE_SEED;
use crate::state::fee_state;
use anchor_lang::prelude::*;
use fee_state::FeeState;

Expand All @@ -26,7 +26,7 @@ pub struct EditFeeState<'info> {
// Note: there is just one FeeState per program, so no further check is required.
#[account(
mut,
seeds = [FEE_STATE_SEED.as_bytes()],
seeds = [FEE_STATE_SEED.as_bytes()],
bump,
has_one = global_fee_admin
)]
Expand Down
2 changes: 1 addition & 1 deletion programs/marginfi/src/state/fee_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ pub struct FeeState {

impl FeeState {
pub const LEN: usize = std::mem::size_of::<FeeState>();
}
}

0 comments on commit 1f07a9b

Please sign in to comment.