Skip to content

Commit

Permalink
Merge pull request #134 from mrgnlabs/man0s/cli-ms-support
Browse files Browse the repository at this point in the history
Cli ms support
  • Loading branch information
jkbpvsc authored Nov 12, 2023
2 parents 2825925 + 75276b5 commit 8e12ff6
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 290 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions clients/rust/marginfi-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ spl-token = "3.5.0"
spl-associated-token-account = "1.1.2"
chrono = "0.4.23"
switchboard-v2 = "0.1.22"
bincode = "1.3.1"
bs58 = "0.4.0"
32 changes: 26 additions & 6 deletions clients/rust/marginfi-cli/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use anchor_client::{Client, Cluster, Program};
use clap::Parser;
use serde::{Deserialize, Serialize};
use solana_sdk::{commitment_config::CommitmentConfig, pubkey::Pubkey, signature::Keypair};
use std::str::FromStr;
use {
anchor_client::{Client, Cluster, Program},
clap::Parser,
serde::{Deserialize, Serialize},
solana_sdk::{
commitment_config::CommitmentConfig,
pubkey::Pubkey,
signature::{Keypair, Signer},
},
std::str::FromStr,
};

#[derive(Default, Debug, Parser)]
pub struct GlobalOptions {
Expand Down Expand Up @@ -32,9 +38,23 @@ pub struct GlobalOptions {
pub skip_confirmation: bool,
}

pub enum CliSigner {
Keypair(Keypair),
Multisig(Pubkey),
}

impl CliSigner {
pub fn pubkey(&self) -> Pubkey {
match self {
CliSigner::Keypair(keypair) => keypair.pubkey(),
CliSigner::Multisig(pubkey) => *pubkey,
}
}
}

pub struct Config {
pub cluster: Cluster,
pub payer: Keypair,
pub signer: CliSigner,
pub program_id: Pubkey,
pub commitment: CommitmentConfig,
pub dry_run: bool,
Expand Down
11 changes: 10 additions & 1 deletion clients/rust/marginfi-cli/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ pub enum ProfileCommand {
#[clap(long)]
cluster: Cluster,
#[clap(long)]
keypair_path: String,
keypair_path: Option<String>,
#[clap(long)]
multisig: Option<Pubkey>,
#[clap(long)]
rpc_url: String,
#[clap(long)]
Expand All @@ -301,6 +303,8 @@ pub enum ProfileCommand {
#[clap(long)]
keypair_path: Option<String>,
#[clap(long)]
multisig: Option<Pubkey>,
#[clap(long)]
rpc_url: Option<String>,
#[clap(long)]
program_id: Option<Pubkey>,
Expand Down Expand Up @@ -388,6 +392,7 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
name,
cluster,
keypair_path,
multisig,
rpc_url,
program_id,
commitment,
Expand All @@ -397,6 +402,7 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
name,
cluster,
keypair_path,
multisig,
rpc_url,
program_id,
commitment,
Expand All @@ -409,6 +415,7 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
ProfileCommand::Update {
cluster,
keypair_path,
multisig,
rpc_url,
program_id,
commitment,
Expand All @@ -419,6 +426,7 @@ fn profile(subcmd: ProfileCommand) -> Result<()> {
name,
cluster,
keypair_path,
multisig,
rpc_url,
program_id,
commitment,
Expand Down Expand Up @@ -510,6 +518,7 @@ fn bank(subcmd: BankCommand, global_options: &GlobalOptions) -> Result<()> {
BankCommand::Get { .. } | BankCommand::GetAll { .. } => (),
#[cfg(feature = "dev")]
BankCommand::InspectPriceOracle { .. } => (),
#[allow(unreachable_patterns)]
_ => get_consent(&subcmd, &profile)?,
}
}
Expand Down
47 changes: 26 additions & 21 deletions clients/rust/marginfi-cli/src/processor/emissions.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
use anchor_client::anchor_lang::{AnchorSerialize, InstructionData, ToAccountMetas};
use anyhow::Result;
use marginfi::state::marginfi_account::MarginfiAccount;
use solana_client::rpc_filter::{Memcmp, RpcFilterType};
use solana_sdk::{
instruction::Instruction, pubkey::Pubkey, signer::Signer, transaction::Transaction,
use {
crate::{
config::{CliSigner, Config},
profile::Profile,
},
anchor_client::anchor_lang::{AnchorSerialize, InstructionData, ToAccountMetas},
anyhow::Result,
marginfi::state::marginfi_account::MarginfiAccount,
solana_client::rpc_filter::{Memcmp, RpcFilterType},
solana_sdk::{
instruction::Instruction, message::Message, pubkey::Pubkey, transaction::Transaction,
},
};

use crate::{config::Config, profile::Profile};

#[cfg(feature = "admin")]
const CHUNK_SIZE: usize = 22;
#[cfg(feature = "admin")]

pub fn claim_all_emissions_for_bank(
config: &Config,
profile: &Profile,
bank_pk: Pubkey,
) -> Result<()> {
let rpc_client = config.mfi_program.rpc();

let group = profile.marginfi_group.expect("group not set");

let signing_keypairs = if let CliSigner::Keypair(keypair) = &config.signer {
vec![keypair]
} else {
vec![]
};

let marginfi_accounts =
config
.mfi_program
Expand Down Expand Up @@ -60,19 +71,13 @@ pub fn claim_all_emissions_for_bank(
println!("Sending {} txs", ixs_batches_count);

for (i, ixs) in ixs_batches.enumerate() {
let blockhash = config.mfi_program.rpc().get_latest_blockhash()?;
let blockhash = rpc_client.get_latest_blockhash()?;

let tx = Transaction::new_signed_with_payer(
ixs,
Some(&config.payer.pubkey()),
&[&config.payer],
blockhash,
);
let message = Message::new(ixs, Some(&config.signer.pubkey()));
let mut transaction = Transaction::new_unsigned(message);
transaction.partial_sign(&signing_keypairs, blockhash);

let sig = config
.mfi_program
.rpc()
.send_and_confirm_transaction_with_spinner(&tx)?;
let sig = rpc_client.send_and_confirm_transaction_with_spinner(&transaction)?;

println!("Sent [{}/{}] {}", i + 1, ixs_batches_count, sig);
}
Expand Down
Loading

0 comments on commit 8e12ff6

Please sign in to comment.