Some clippy fixes (#776)
This commit is contained in:
parent
5ca5d8f78c
commit
7af1d58558
|
@ -67,7 +67,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let txsig = self
|
||||
.client
|
||||
.serum3_liq_force_cancel_orders(
|
||||
(self.pubkey, &self.liqee),
|
||||
(self.pubkey, self.liqee),
|
||||
serum_orders.market_index,
|
||||
&serum_orders.open_orders,
|
||||
)
|
||||
|
@ -84,7 +84,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let perp_force_cancels = self
|
||||
.liqee
|
||||
.active_perp_positions()
|
||||
.filter_map(|pp| pp.has_open_orders().then(|| pp.market_index))
|
||||
.filter_map(|pp| pp.has_open_orders().then_some(pp.market_index))
|
||||
.collect::<Vec<PerpMarketIndex>>();
|
||||
if perp_force_cancels.is_empty() {
|
||||
return Ok(None);
|
||||
|
@ -94,7 +94,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let perp_market_index = *perp_force_cancels.choose(&mut rand::thread_rng()).unwrap();
|
||||
let txsig = self
|
||||
.client
|
||||
.perp_liq_force_cancel_orders((self.pubkey, &self.liqee), perp_market_index)
|
||||
.perp_liq_force_cancel_orders((self.pubkey, self.liqee), perp_market_index)
|
||||
.await?;
|
||||
info!(
|
||||
perp_market_index,
|
||||
|
@ -126,7 +126,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
.await;
|
||||
let mut perp_base_positions = all_perp_base_positions?
|
||||
.into_iter()
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
perp_base_positions.sort_by(|a, b| a.3.cmp(&b.3));
|
||||
|
||||
|
@ -205,7 +205,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let mut liq_ixs = self
|
||||
.client
|
||||
.perp_liq_base_or_positive_pnl_instruction(
|
||||
(self.pubkey, &self.liqee),
|
||||
(self.pubkey, self.liqee),
|
||||
*perp_market_index,
|
||||
side_signum * max_base_transfer_abs,
|
||||
max_pnl_transfer,
|
||||
|
@ -251,7 +251,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let mut liq_ixs = self
|
||||
.client
|
||||
.perp_liq_negative_pnl_or_bankruptcy_instruction(
|
||||
(self.pubkey, &self.liqee),
|
||||
(self.pubkey, self.liqee),
|
||||
*perp_market_index,
|
||||
// Always use the max amount, since the health effect is >= 0
|
||||
u64::MAX,
|
||||
|
@ -373,7 +373,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let mut liq_ixs = self
|
||||
.client
|
||||
.token_liq_with_token_instruction(
|
||||
(self.pubkey, &self.liqee),
|
||||
(self.pubkey, self.liqee),
|
||||
asset_token_index,
|
||||
liab_token_index,
|
||||
max_liab_transfer,
|
||||
|
@ -433,7 +433,7 @@ impl<'a> LiquidateHelper<'a> {
|
|||
let mut liq_ixs = self
|
||||
.client
|
||||
.token_liq_bankruptcy_instruction(
|
||||
(self.pubkey, &self.liqee),
|
||||
(self.pubkey, self.liqee),
|
||||
liab_token_index,
|
||||
max_liab_transfer,
|
||||
)
|
||||
|
|
|
@ -671,8 +671,7 @@ impl LiquidationState {
|
|||
let now = Instant::now();
|
||||
let now_ts: u64 = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
.as_secs();
|
||||
|
||||
let tcs_context = trigger_tcs::Context {
|
||||
mango_client: self.mango_client.clone(),
|
||||
|
|
|
@ -433,8 +433,7 @@ impl Rebalancer {
|
|||
) -> anyhow::Result<bool> {
|
||||
let now_ts: u64 = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
.as_secs();
|
||||
|
||||
let base_lots = perp_position.base_position_lots();
|
||||
let effective_lots = perp_position.effective_base_position_lots();
|
||||
|
|
|
@ -259,14 +259,12 @@ impl JupiterQuoteCache {
|
|||
// if those break the specified limit
|
||||
let cached_collateral_to_buy = self.cached_price(collateral_mint, buy_mint).await;
|
||||
let cached_sell_to_collateral = self.cached_price(sell_mint, collateral_mint).await;
|
||||
match (cached_collateral_to_buy, cached_sell_to_collateral) {
|
||||
(Some(c_to_b), Some(s_to_c)) => {
|
||||
let s_to_b = s_to_c * c_to_b;
|
||||
if s_to_b > max_sell_per_buy_price {
|
||||
return Ok(JupiterQuoteCacheResult::BadPrice(s_to_b));
|
||||
}
|
||||
if let (Some(c_to_b), Some(s_to_c)) = (cached_collateral_to_buy, cached_sell_to_collateral)
|
||||
{
|
||||
let s_to_b = s_to_c * c_to_b;
|
||||
if s_to_b > max_sell_per_buy_price {
|
||||
return Ok(JupiterQuoteCacheResult::BadPrice(s_to_b));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Get fresh quotes
|
||||
|
@ -380,7 +378,7 @@ impl Context {
|
|||
base_price: f64,
|
||||
) -> anyhow::Result<bool> {
|
||||
// The premium the taker receives needs to take taker fees into account
|
||||
let taker_price = tcs.taker_price(tcs.premium_price(base_price, self.now_ts)) as f64;
|
||||
let taker_price = tcs.taker_price(tcs.premium_price(base_price, self.now_ts));
|
||||
|
||||
// Never take tcs where the fee exceeds the premium and the triggerer exchanges
|
||||
// tokens at below oracle price.
|
||||
|
@ -474,7 +472,7 @@ impl Context {
|
|||
let max_sell_ignoring_net_borrows = util::max_swap_source_ignore_net_borrows(
|
||||
&self.mango_client,
|
||||
&self.account_fetcher,
|
||||
&account,
|
||||
account,
|
||||
tcs.sell_token_index,
|
||||
tcs.buy_token_index,
|
||||
swap_price,
|
||||
|
@ -584,8 +582,7 @@ impl Context {
|
|||
) -> anyhow::Result<Option<PreparedExecution>> {
|
||||
let now_ts: u64 = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
.as_secs();
|
||||
let liqee = self.account_fetcher.fetch_mango_account(pubkey)?;
|
||||
let tcs = liqee.token_conditional_swap_by_id(tcs_id)?.1;
|
||||
|
||||
|
@ -617,7 +614,7 @@ impl Context {
|
|||
tcs_id: u64,
|
||||
) -> anyhow::Result<Option<PreparedExecution>> {
|
||||
let fetcher = self.account_fetcher.as_ref();
|
||||
let health_cache = health_cache::new(&self.mango_client.context, fetcher, &liqee_old)
|
||||
let health_cache = health_cache::new(&self.mango_client.context, fetcher, liqee_old)
|
||||
.await
|
||||
.context("creating health cache 1")?;
|
||||
if health_cache.is_liquidatable() {
|
||||
|
@ -705,7 +702,7 @@ impl Context {
|
|||
Mode::SwapSellIntoBuy
|
||||
}
|
||||
}
|
||||
m @ _ => m,
|
||||
m => m,
|
||||
};
|
||||
|
||||
let jupiter_slippage_fraction = 1.0 - self.config.jupiter_slippage_bps as f64 * 0.0001;
|
||||
|
@ -912,7 +909,7 @@ impl Context {
|
|||
/// Returns a list of transaction signatures as well as the pubkeys of liqees.
|
||||
pub async fn execute_tcs(
|
||||
&self,
|
||||
tcs: &mut Vec<(Pubkey, u64, u64)>,
|
||||
tcs: &mut [(Pubkey, u64, u64)],
|
||||
error_tracking: &mut ErrorTracking,
|
||||
) -> anyhow::Result<(Vec<Signature>, Vec<Pubkey>)> {
|
||||
use rand::distributions::{Distribution, WeightedError, WeightedIndex};
|
||||
|
@ -1016,8 +1013,7 @@ impl Context {
|
|||
let mut liqor = self.mango_client.mango_account().await?;
|
||||
let allowed_tokens = prepared_executions
|
||||
.iter()
|
||||
.map(|v| &v.token_indexes)
|
||||
.flatten()
|
||||
.flat_map(|v| &v.token_indexes)
|
||||
.copied()
|
||||
.unique()
|
||||
.filter(|&idx| liqor.ensure_token_position(idx).is_ok())
|
||||
|
@ -1068,7 +1064,7 @@ impl Context {
|
|||
}
|
||||
|
||||
let context = self.clone();
|
||||
let pubkey = pubkey.clone();
|
||||
let pubkey = *pubkey;
|
||||
let job = async move {
|
||||
PreparationResult {
|
||||
pubkey,
|
||||
|
|
|
@ -87,11 +87,8 @@ impl SettlementState {
|
|||
});
|
||||
}
|
||||
|
||||
async fn run_settles(&mut self, accounts: &Vec<Pubkey>) -> anyhow::Result<()> {
|
||||
let now_ts: u64 = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
async fn run_settles(&mut self, accounts: &[Pubkey]) -> anyhow::Result<()> {
|
||||
let now_ts: u64 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||
|
||||
let mango_client = &*self.mango_client;
|
||||
let account_fetcher = &*self.account_fetcher;
|
||||
|
@ -296,7 +293,7 @@ impl<'a> SettleBatchProcessor<'a> {
|
|||
.rpc_async()
|
||||
.send_transaction_with_config(&tx, self.mango_client.client.rpc_send_transaction_config)
|
||||
.await
|
||||
.map_err(|e| prettify_solana_client_error(e));
|
||||
.map_err(prettify_solana_client_error);
|
||||
|
||||
if let Err(err) = send_result {
|
||||
info!("error while sending settle batch: {}", err);
|
||||
|
|
|
@ -50,11 +50,8 @@ impl State {
|
|||
self.errors.log_persistent_errors("start_tcs", min_duration);
|
||||
}
|
||||
|
||||
async fn run_pass_inner(&mut self, accounts: &Vec<Pubkey>) -> anyhow::Result<()> {
|
||||
let now_ts: u64 = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
async fn run_pass_inner(&mut self, accounts: &[Pubkey]) -> anyhow::Result<()> {
|
||||
let now_ts: u64 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||
let now = Instant::now();
|
||||
|
||||
let mango_client = &*self.mango_client;
|
||||
|
|
|
@ -23,10 +23,7 @@ pub async fn fetch_top(
|
|||
count: usize,
|
||||
) -> anyhow::Result<Vec<(Pubkey, MangoAccountValue, I80F48)>> {
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
let now_ts: u64 = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)?
|
||||
.as_secs()
|
||||
.try_into()?;
|
||||
let now_ts: u64 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
|
||||
|
||||
let perp = context.perp(perp_market_index);
|
||||
let perp_market =
|
||||
|
|
Loading…
Reference in New Issue