Skip to content

Commit

Permalink
Rust client: Allow sending transactions to multiple rpcs (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckamm authored Jan 19, 2024
1 parent 8383109 commit 43b9cac
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 74 deletions.
16 changes: 8 additions & 8 deletions bin/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ enum Command {
impl Rpc {
fn client(&self, override_fee_payer: Option<&str>) -> anyhow::Result<Client> {
let fee_payer = keypair_from_cli(override_fee_payer.unwrap_or(&self.fee_payer));
Ok(Client::new(
anchor_client::Cluster::from_str(&self.url)?,
solana_sdk::commitment_config::CommitmentConfig::confirmed(),
Arc::new(fee_payer),
None,
TransactionBuilderConfig {
Ok(Client::builder()
.cluster(anchor_client::Cluster::from_str(&self.url)?)
.commitment(solana_sdk::commitment_config::CommitmentConfig::confirmed())
.fee_payer(Some(Arc::new(fee_payer)))
.transaction_builder_config(TransactionBuilderConfig {
prioritization_micro_lamports: Some(5),
compute_budget_per_instruction: Some(250_000),
},
))
})
.build()
.unwrap())
}
}

Expand Down
6 changes: 3 additions & 3 deletions bin/cli/src/save_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub async fn save_snapshot(
}
fs::create_dir_all(out_path).unwrap();

let rpc_url = client.cluster.url().to_string();
let ws_url = client.cluster.ws_url().to_string();
let rpc_url = client.config().cluster.url().to_string();
let ws_url = client.config().cluster.ws_url().to_string();

let group_context = MangoGroupContext::new_from_rpc(&client.rpc_async(), mango_group).await?;
let group_context = MangoGroupContext::new_from_rpc(client.rpc_async(), mango_group).await?;

let oracles_and_vaults = group_context
.tokens
Expand Down
10 changes: 7 additions & 3 deletions bin/liquidator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ struct Cli {
#[clap(short, long, env)]
rpc_url: String,

#[clap(long, env, value_delimiter = ';')]
override_send_transaction_url: Option<Vec<String>>,

#[clap(long, env)]
liqor_mango_account: Pubkey,

Expand Down Expand Up @@ -207,7 +210,7 @@ async fn main() -> anyhow::Result<()> {
.cluster(cluster.clone())
.commitment(commitment)
.fee_payer(Some(liqor_owner.clone()))
.timeout(Some(rpc_timeout))
.timeout(rpc_timeout)
.jupiter_v4_url(cli.jupiter_v4_url)
.jupiter_v6_url(cli.jupiter_v6_url)
.jupiter_token(cli.jupiter_token)
Expand All @@ -217,6 +220,7 @@ async fn main() -> anyhow::Result<()> {
// Liquidation and tcs triggers set their own budgets, this is a default for other tx
compute_budget_per_instruction: Some(250_000),
})
.override_send_transaction_urls(cli.override_send_transaction_url)
.build()
.unwrap();

Expand All @@ -225,7 +229,7 @@ async fn main() -> anyhow::Result<()> {
// Reading accounts from chain_data
let account_fetcher = Arc::new(chain_data::AccountFetcher {
chain_data: chain_data.clone(),
rpc: client.rpc_async(),
rpc: client.new_rpc_async(),
});

let mango_account = account_fetcher
Expand All @@ -238,7 +242,7 @@ async fn main() -> anyhow::Result<()> {
warn!("rebalancing on delegated accounts will be unable to free token positions reliably, withdraw dust manually");
}

let group_context = MangoGroupContext::new_from_rpc(&client.rpc_async(), mango_group).await?;
let group_context = MangoGroupContext::new_from_rpc(client.rpc_async(), mango_group).await?;

let mango_oracles = group_context
.tokens
Expand Down
2 changes: 1 addition & 1 deletion bin/liquidator/src/trigger_tcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ impl Context {
address_lookup_tables: vec![],
payer: fee_payer.pubkey(),
signers: vec![self.mango_client.owner.clone(), fee_payer],
config: self.mango_client.client.transaction_builder_config,
config: self.mango_client.client.config().transaction_builder_config,
}
};

Expand Down
2 changes: 1 addition & 1 deletion bin/service-mango-crank/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn main() -> anyhow::Result<()> {
);
let group_pk = Pubkey::from_str(&config.mango_group).unwrap();
let group_context =
Arc::new(MangoGroupContext::new_from_rpc(&client.rpc_async(), group_pk).await?);
Arc::new(MangoGroupContext::new_from_rpc(client.rpc_async(), group_pk).await?);

let perp_queue_pks: Vec<_> = group_context
.perp_markets
Expand Down
2 changes: 1 addition & 1 deletion bin/service-mango-fills/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ async fn main() -> anyhow::Result<()> {
);
let group_context = Arc::new(
MangoGroupContext::new_from_rpc(
&client.rpc_async(),
client.rpc_async(),
Pubkey::from_str(&config.mango_group).unwrap(),
)
.await?,
Expand Down
2 changes: 1 addition & 1 deletion bin/service-mango-orderbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ async fn main() -> anyhow::Result<()> {
);
let group_context = Arc::new(
MangoGroupContext::new_from_rpc(
&client.rpc_async(),
client.rpc_async(),
Pubkey::from_str(&config.mango_group).unwrap(),
)
.await?,
Expand Down
4 changes: 2 additions & 2 deletions bin/service-mango-pnl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,15 @@ async fn main() -> anyhow::Result<()> {
);
let group_context = Arc::new(
MangoGroupContext::new_from_rpc(
&client.rpc_async(),
client.rpc_async(),
Pubkey::from_str(&config.pnl.mango_group).unwrap(),
)
.await?,
);
let chain_data = Arc::new(RwLock::new(chain_data::ChainData::new()));
let account_fetcher = Arc::new(chain_data::AccountFetcher {
chain_data: chain_data.clone(),
rpc: client.rpc_async(),
rpc: client.new_rpc_async(),
});

let metrics_tx = metrics::start(config.metrics, "pnl".into());
Expand Down
4 changes: 2 additions & 2 deletions bin/settler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ async fn main() -> anyhow::Result<()> {
// Reading accounts from chain_data
let account_fetcher = Arc::new(chain_data::AccountFetcher {
chain_data: chain_data.clone(),
rpc: client.rpc_async(),
rpc: client.new_rpc_async(),
});

let mango_account = account_fetcher
.fetch_fresh_mango_account(&cli.settler_mango_account)
.await?;
let mango_group = mango_account.fixed.group;

let group_context = MangoGroupContext::new_from_rpc(&client.rpc_async(), mango_group).await?;
let group_context = MangoGroupContext::new_from_rpc(client.rpc_async(), mango_group).await?;

let mango_oracles = group_context
.tokens
Expand Down
13 changes: 3 additions & 10 deletions bin/settler/src/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use mango_v4::accounts_zerocopy::KeyedAccountSharedData;
use mango_v4::health::HealthType;
use mango_v4::state::{OracleAccountInfos, PerpMarket, PerpMarketIndex};
use mango_v4_client::{
chain_data, health_cache, prettify_solana_client_error, MangoClient, PreparedInstructions,
TransactionBuilder,
chain_data, health_cache, MangoClient, PreparedInstructions, TransactionBuilder,
};
use solana_sdk::address_lookup_table_account::AddressLookupTableAccount;
use solana_sdk::commitment_config::CommitmentConfig;
Expand Down Expand Up @@ -273,7 +272,7 @@ impl<'a> SettleBatchProcessor<'a> {
address_lookup_tables: self.address_lookup_tables.clone(),
payer: fee_payer.pubkey(),
signers: vec![fee_payer],
config: client.transaction_builder_config,
config: client.config().transaction_builder_config,
}
.transaction_with_blockhash(self.blockhash)
}
Expand All @@ -286,13 +285,7 @@ impl<'a> SettleBatchProcessor<'a> {
let tx = self.transaction()?;
self.instructions.clear();

let send_result = self
.mango_client
.client
.rpc_async()
.send_transaction_with_config(&tx, self.mango_client.client.rpc_send_transaction_config)
.await
.map_err(prettify_solana_client_error);
let send_result = self.mango_client.client.send_transaction(&tx).await;

if let Err(err) = send_result {
info!("error while sending settle batch: {}", err);
Expand Down
Loading

0 comments on commit 43b9cac

Please sign in to comment.