Skip to content

Commit

Permalink
Merge remote-tracking branch 'public/main' into test-remix
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Aug 22, 2024
2 parents ac1f8d7 + 063fcbf commit c0a3a29
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 6 deletions.
3 changes: 3 additions & 0 deletions clients/rust/marginfi-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub struct GlobalOptions {
default_value_t = false
)]
pub skip_confirmation: bool,

#[clap(global = true, long)]
pub compute_unit_price: Option<u64>,
}

#[derive(Copy, Clone, Debug)]
Expand Down
19 changes: 16 additions & 3 deletions clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ pub enum GroupCommand {
#[clap(long)]
borrow_limit_ui: u64,
#[clap(long)]
pyth_oracle: Pubkey,
oracle_key: Pubkey,
#[clap(long)]
feed_id: Option<Pubkey>,
#[clap(long)]
optimal_utilization_rate: f64,
#[clap(long)]
Expand Down Expand Up @@ -340,6 +342,8 @@ pub enum ProfileCommand {
Update {
name: String,
#[clap(long)]
new_name: Option<String>,
#[clap(long)]
cluster: Option<Cluster>,
#[clap(long)]
keypair_path: Option<String>,
Expand All @@ -356,6 +360,9 @@ pub enum ProfileCommand {
#[clap(long)]
account: Option<Pubkey>,
},
Delete {
name: String,
},
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -502,9 +509,11 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
commitment,
group,
name,
new_name,
account,
} => processor::configure_profile(
name,
new_name,
cluster,
keypair_path,
multisig,
Expand All @@ -514,6 +523,7 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
group,
account,
),
ProfileCommand::Delete { name } => processor::delete_profile(name),
}
}

Expand Down Expand Up @@ -550,7 +560,8 @@ fn group(subcmd: GroupCommand, global_options: &GlobalOptions) -> Result<()> {
asset_weight_maint,
liability_weight_init,
liability_weight_maint,
pyth_oracle,
oracle_key,
feed_id,
optimal_utilization_rate,
plateau_interest_rate,
max_interest_rate,
Expand All @@ -568,7 +579,8 @@ fn group(subcmd: GroupCommand, global_options: &GlobalOptions) -> Result<()> {
profile,
bank_mint,
seed,
pyth_oracle,
oracle_key,
feed_id,
oracle_type,
asset_weight_init,
asset_weight_maint,
Expand All @@ -585,6 +597,7 @@ fn group(subcmd: GroupCommand, global_options: &GlobalOptions) -> Result<()> {
protocol_ir_fee,
risk_tier,
oracle_max_age,
global_options.compute_unit_price,
),

GroupCommand::HandleBankruptcy { accounts } => {
Expand Down
30 changes: 27 additions & 3 deletions clients/rust/marginfi-cli/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ pub fn group_add_bank(
bank_mint: Pubkey,
seed: bool,
oracle_key: Pubkey,
feed_id: Option<Pubkey>,
oracle_setup: crate::OracleTypeArg,
asset_weight_init: f64,
asset_weight_maint: f64,
Expand All @@ -315,6 +316,7 @@ pub fn group_add_bank(
protocol_ir_fee: f64,
risk_tier: crate::RiskTierArg,
oracle_max_age: u16,
compute_unit_price: Option<u64>,
) -> Result<()> {
let rpc_client = config.mfi_program.rpc();

Expand Down Expand Up @@ -371,6 +373,7 @@ pub fn group_add_bank(
bank_mint,
token_program,
oracle_key,
feed_id,
asset_weight_init,
asset_weight_maint,
liability_weight_init,
Expand All @@ -390,6 +393,7 @@ pub fn group_add_bank(
token_program,
&bank_keypair,
oracle_key,
feed_id,
asset_weight_init,
asset_weight_maint,
liability_weight_init,
Expand All @@ -403,7 +407,9 @@ pub fn group_add_bank(
)?
};

let mut ixs = vec![ComputeBudgetInstruction::set_compute_unit_price(1)];
let mut ixs = vec![ComputeBudgetInstruction::set_compute_unit_price(
compute_unit_price.unwrap_or(1),
)];
ixs.extend(add_bank_ixs);

let recent_blockhash = rpc_client.get_latest_blockhash().unwrap();
Expand All @@ -428,6 +434,7 @@ fn create_bank_ix_with_seed(
bank_mint: Pubkey,
token_program: Pubkey,
oracle_key: Pubkey,
feed_id: Option<Pubkey>,
asset_weight_init: WrappedI80F48,
asset_weight_maint: WrappedI80F48,
liability_weight_init: WrappedI80F48,
Expand Down Expand Up @@ -520,7 +527,7 @@ fn create_bank_ix_with_seed(
interest_rate_config,
operational_state: BankOperationalState::Operational,
oracle_setup: oracle_setup.into(),
oracle_keys: create_oracle_key_array(oracle_key),
oracle_keys: create_oracle_key_array(feed_id.unwrap_or(oracle_key)),
risk_tier: risk_tier.into(),
oracle_max_age,
..BankConfig::default()
Expand All @@ -544,6 +551,7 @@ fn create_bank_ix(
token_program: Pubkey,
bank_keypair: &Keypair,
oracle_key: Pubkey,
feed_id: Option<Pubkey>,
asset_weight_init: WrappedI80F48,
asset_weight_maint: WrappedI80F48,
liability_weight_init: WrappedI80F48,
Expand Down Expand Up @@ -615,7 +623,7 @@ fn create_bank_ix(
interest_rate_config,
operational_state: BankOperationalState::Operational,
oracle_setup: oracle_setup.into(),
oracle_keys: create_oracle_key_array(oracle_key),
oracle_keys: create_oracle_key_array(feed_id.unwrap_or(oracle_key)),
risk_tier: risk_tier.into(),
oracle_max_age,
..BankConfig::default()
Expand Down Expand Up @@ -1670,6 +1678,7 @@ pub fn list_profiles() -> Result<()> {
#[allow(clippy::too_many_arguments)]
pub fn configure_profile(
name: String,
new_name: Option<String>,
cluster: Option<Cluster>,
keypair_path: Option<String>,
multisig: Option<Pubkey>,
Expand All @@ -1680,7 +1689,9 @@ pub fn configure_profile(
account: Option<Pubkey>,
) -> Result<()> {
let mut profile = profile::load_profile_by_name(&name)?;
let using_new_name = new_name.is_some();
profile.config(
new_name,
cluster,
keypair_path,
multisig,
Expand All @@ -1691,9 +1702,20 @@ pub fn configure_profile(
account,
)?;

if using_new_name {
if let Err(e) = profile::delete_profile_by_name(&name) {
println!("failed to delete old profile {name}: {e:?}");
return Err(e);
}
}

Ok(())
}

pub fn delete_profile(name: String) -> Result<()> {
profile::delete_profile_by_name(&name)
}

// --------------------------------------------------------------------------------------------------------------------
// Marginfi Accounts
// --------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1819,6 +1841,7 @@ pub fn marginfi_account_use(
None,
None,
None,
None,
Some(marginfi_account_pk),
)?;

Expand Down Expand Up @@ -2289,6 +2312,7 @@ pub fn marginfi_account_create(profile: &Profile, config: &Config) -> Result<()>
None,
None,
None,
None,
Some(marginfi_account_key.pubkey()),
)?;

Expand Down
25 changes: 25 additions & 0 deletions clients/rust/marginfi-cli/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Profile {
#[allow(clippy::too_many_arguments)]
pub fn config(
&mut self,
new_name: Option<String>,
cluster: Option<Cluster>,
keypair_path: Option<String>,
multisig: Option<Pubkey>,
Expand All @@ -124,6 +125,10 @@ impl Profile {
group: Option<Pubkey>,
account: Option<Pubkey>,
) -> Result<()> {
if let Some(name) = new_name {
self.name = name;
}

if let Some(cluster) = cluster {
self.cluster = cluster;
}
Expand Down Expand Up @@ -226,6 +231,26 @@ pub fn load_profile_by_name(name: &str) -> Result<Profile> {
Ok(profile)
}

pub fn delete_profile_by_name(name: &str) -> Result<()> {
let cli_config_dir = get_cli_config_dir();
let profile_file = cli_config_dir.join("profiles").join(format!("{name}.json"));

if !profile_file.exists() {
return Err(anyhow!("Profile {} does not exist", name));
}

match fs::remove_file(profile_file) {
Ok(()) => {
println!("successfully deleted profile {name}");
Ok(())
}
Err(e) => {
println!("failed to delete profile {name}: {e:?}");
Err(e.into())
}
}
}

pub fn get_cli_config_dir() -> PathBuf {
home_dir()
.expect("$HOME not set")
Expand Down

0 comments on commit c0a3a29

Please sign in to comment.