From 1f07a9b22c2c7a99086764d3853636068cb45ab1 Mon Sep 17 00:00:00 2001 From: Jon Gurary Date: Wed, 28 Aug 2024 04:08:59 -0400 Subject: [PATCH] Attempt fix cli and lint --- clients/rust/marginfi-cli/src/entrypoint.rs | 4 ++++ clients/rust/marginfi-cli/src/processor/mod.rs | 13 +++++++++++-- clients/rust/marginfi-cli/src/utils.rs | 10 ++++++++-- .../src/instructions/marginfi_group/add_pool.rs | 10 +++++++--- .../marginfi_group/add_pool_with_seed.rs | 10 +++++++--- .../instructions/marginfi_group/edit_global_fee.rs | 4 ++-- programs/marginfi/src/state/fee_state.rs | 2 +- 7 files changed, 40 insertions(+), 13 deletions(-) diff --git a/clients/rust/marginfi-cli/src/entrypoint.rs b/clients/rust/marginfi-cli/src/entrypoint.rs index 9e7a62b42..052fea9af 100644 --- a/clients/rust/marginfi-cli/src/entrypoint.rs +++ b/clients/rust/marginfi-cli/src/entrypoint.rs @@ -145,6 +145,8 @@ pub enum GroupCommand { default_value = "60" )] oracle_max_age: u16, + #[clap(long)] + global_fee_wallet: Pubkey, }, HandleBankruptcy { accounts: Vec, @@ -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, @@ -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 } => { diff --git a/clients/rust/marginfi-cli/src/processor/mod.rs b/clients/rust/marginfi-cli/src/processor/mod.rs index 061c31326..b3c1666f2 100644 --- a/clients/rust/marginfi-cli/src/processor/mod.rs +++ b/clients/rust/marginfi-cli/src/processor/mod.rs @@ -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::{ @@ -317,6 +317,7 @@ pub fn group_add_bank( risk_tier: crate::RiskTierArg, oracle_max_age: u16, compute_unit_price: Option, + global_fee_wallet: Pubkey, ) -> Result<()> { let rpc_client = config.mfi_program.rpc(); @@ -384,6 +385,7 @@ pub fn group_add_bank( oracle_setup, risk_tier, oracle_max_age, + global_fee_wallet, )? } else { create_bank_ix( @@ -404,6 +406,7 @@ pub fn group_add_bank( oracle_setup, risk_tier, oracle_max_age, + global_fee_wallet, )? }; @@ -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> { use solana_sdk::commitment_config::CommitmentConfig; @@ -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 { @@ -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> { let add_bank_ixs_builder = config.mfi_program.request(); let add_bank_ixs = add_bank_ixs_builder @@ -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 { diff --git a/clients/rust/marginfi-cli/src/utils.rs b/clients/rust/marginfi-cli/src/utils.rs index e41e75474..e07ce17ea 100644 --- a/clients/rust/marginfi-cli/src/utils.rs +++ b/clients/rust/marginfi-cli/src/utils.rs @@ -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, @@ -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; diff --git a/programs/marginfi/src/instructions/marginfi_group/add_pool.rs b/programs/marginfi/src/instructions/marginfi_group/add_pool.rs index b9de03eab..7b1610323 100644 --- a/programs/marginfi/src/instructions/marginfi_group/add_pool.rs +++ b/programs/marginfi/src/instructions/marginfi_group/add_pool.rs @@ -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::*; @@ -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 )] diff --git a/programs/marginfi/src/instructions/marginfi_group/add_pool_with_seed.rs b/programs/marginfi/src/instructions/marginfi_group/add_pool_with_seed.rs index 97199c2cc..a0bcee795 100644 --- a/programs/marginfi/src/instructions/marginfi_group/add_pool_with_seed.rs +++ b/programs/marginfi/src/instructions/marginfi_group/add_pool_with_seed.rs @@ -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::*; @@ -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 )] diff --git a/programs/marginfi/src/instructions/marginfi_group/edit_global_fee.rs b/programs/marginfi/src/instructions/marginfi_group/edit_global_fee.rs index e05138f5a..05558836f 100644 --- a/programs/marginfi/src/instructions/marginfi_group/edit_global_fee.rs +++ b/programs/marginfi/src/instructions/marginfi_group/edit_global_fee.rs @@ -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; @@ -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 )] diff --git a/programs/marginfi/src/state/fee_state.rs b/programs/marginfi/src/state/fee_state.rs index daf6d88d2..1d7e00295 100644 --- a/programs/marginfi/src/state/fee_state.rs +++ b/programs/marginfi/src/state/fee_state.rs @@ -32,4 +32,4 @@ pub struct FeeState { impl FeeState { pub const LEN: usize = std::mem::size_of::(); -} \ No newline at end of file +}