Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Lou-Kamades committed Jan 11, 2024
1 parent 7756368 commit e73d551
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 55 deletions.
3 changes: 1 addition & 2 deletions bin/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Args, Parser, Subcommand};
use mango_v4_client::{
keypair_from_cli, pubkey_from_cli, Client, FallbackOracleConfig, MangoClient,
keypair_from_cli, pubkey_from_cli, Client, MangoClient,
TransactionBuilderConfig,
};
use solana_sdk::pubkey::Pubkey;
Expand Down Expand Up @@ -139,7 +139,6 @@ impl Rpc {
solana_sdk::commitment_config::CommitmentConfig::confirmed(),
Arc::new(fee_payer),
None,
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig {
prioritization_micro_lamports: Some(5),
compute_budget_per_instruction: Some(250_000),
Expand Down
5 changes: 1 addition & 4 deletions bin/keeper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use std::time::Duration;
use anchor_client::Cluster;

use clap::{Parser, Subcommand};
use mango_v4_client::{
keypair_from_cli, Client, FallbackOracleConfig, MangoClient, TransactionBuilderConfig,
};
use mango_v4_client::{keypair_from_cli, Client, MangoClient, TransactionBuilderConfig};
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;
use tokio::time;
Expand Down Expand Up @@ -105,7 +103,6 @@ async fn main() -> Result<(), anyhow::Error> {
commitment,
owner.clone(),
Some(Duration::from_secs(cli.timeout)),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig {
prioritization_micro_lamports: (cli.prioritization_micro_lamports > 0)
.then_some(cli.prioritization_micro_lamports),
Expand Down
30 changes: 14 additions & 16 deletions bin/liquidator/src/liquidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Duration;
use itertools::Itertools;
use mango_v4::health::{HealthCache, HealthType};
use mango_v4::state::{MangoAccountValue, PerpMarketIndex, Side, TokenIndex, QUOTE_TOKEN_INDEX};
use mango_v4_client::{chain_data, health_cache, MangoClient};
use mango_v4_client::{chain_data, MangoClient};
use solana_sdk::signature::Signature;

use futures::{stream, StreamExt, TryStreamExt};
Expand Down Expand Up @@ -155,9 +155,11 @@ impl<'a> LiquidateHelper<'a> {
.await
.context("getting liquidator account")?;
liqor.ensure_perp_position(*perp_market_index, QUOTE_TOKEN_INDEX)?;
let mut health_cache = self.client.health_cache(&liqor, self.account_fetcher)
.await
.expect("always ok");
let mut health_cache = self
.client
.health_cache(&liqor, self.account_fetcher)
.await
.expect("always ok");
let quote_bank = self
.client
.first_bank(QUOTE_TOKEN_INDEX)
Expand Down Expand Up @@ -588,12 +590,10 @@ pub async fn maybe_liquidate_account(
let liqor_min_health_ratio = I80F48::from_num(config.min_health_ratio);

let account = account_fetcher.fetch_mango_account(pubkey)?;
let health_cache = mango_client.health_cache(
&account,
account_fetcher,
)
.await
.context("creating health cache 1")?;
let health_cache = mango_client
.health_cache(&account, account_fetcher)
.await
.context("creating health cache 1")?;
let maint_health = health_cache.health(HealthType::Maint);
if !health_cache.is_liquidatable() {
return Ok(false);
Expand All @@ -609,12 +609,10 @@ pub async fn maybe_liquidate_account(
// This is -- unfortunately -- needed because the websocket streams seem to not
// be great at providing timely updates to the account data.
let account = account_fetcher.fetch_fresh_mango_account(pubkey).await?;
let health_cache = mango_client.health_cache(
&account,
account_fetcher,
)
.await
.context("creating health cache 2")?;
let health_cache = mango_client
.health_cache(&account, account_fetcher)
.await
.context("creating health cache 2")?;
if !health_cache.is_liquidatable() {
return Ok(false);
}
Expand Down
24 changes: 11 additions & 13 deletions bin/liquidator/src/trigger_tcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mango_v4::{
i80f48::ClampToInt,
state::{Bank, MangoAccountValue, TokenConditionalSwap, TokenIndex},
};
use mango_v4_client::{chain_data, health_cache, jupiter, MangoClient, TransactionBuilder};
use mango_v4_client::{chain_data, jupiter, MangoClient, TransactionBuilder};

use anyhow::Context as AnyhowContext;
use solana_sdk::{signature::Signature, signer::Signer};
Expand Down Expand Up @@ -666,12 +666,11 @@ impl Context {
tcs_id: u64,
) -> anyhow::Result<Option<PreparedExecution>> {
let fetcher = self.account_fetcher.as_ref();
let health_cache = self.mango_client.health_cache(
liqee_old,
fetcher,
)
.await
.context("creating health cache 1")?;
let health_cache = self
.mango_client
.health_cache(liqee_old, fetcher)
.await
.context("creating health cache 1")?;
if health_cache.is_liquidatable() {
trace!("account is liquidatable (pre-fetch)");
return Ok(None);
Expand All @@ -688,12 +687,11 @@ impl Context {
return Ok(None);
}

let health_cache = self.mango_client.health_cache(
&liqee,
fetcher,
)
.await
.context("creating health cache 2")?;
let health_cache = self
.mango_client
.health_cache(&liqee, fetcher)
.await
.context("creating health cache 2")?;
if health_cache.is_liquidatable() {
trace!("account is liquidatable (post-fetch)");
return Ok(None);
Expand Down
3 changes: 1 addition & 2 deletions bin/service-mango-crank/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod transaction_sender;
use anchor_client::Cluster;
use bytemuck::bytes_of;
use log::*;
use mango_v4_client::{Client, FallbackOracleConfig, MangoGroupContext, TransactionBuilderConfig};
use mango_v4_client::{Client, MangoGroupContext, TransactionBuilderConfig};
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;
Expand Down Expand Up @@ -74,7 +74,6 @@ async fn main() -> anyhow::Result<()> {
CommitmentConfig::processed(),
Arc::new(Keypair::new()),
Some(rpc_timeout),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig::default(),
);
let group_pk = Pubkey::from_str(&config.mango_group).unwrap();
Expand Down
3 changes: 1 addition & 2 deletions bin/service-mango-fills/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use mango_feeds_connector::{
};
use mango_feeds_lib::MarketConfig;
use mango_feeds_lib::StatusResponse;
use mango_v4_client::{Client, FallbackOracleConfig, MangoGroupContext, TransactionBuilderConfig};
use mango_v4_client::{Client, MangoGroupContext, TransactionBuilderConfig};
use service_mango_fills::{Command, FillCheckpoint, FillEventFilterMessage, FillEventType};
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::signature::Keypair;
Expand Down Expand Up @@ -369,7 +369,6 @@ async fn main() -> anyhow::Result<()> {
CommitmentConfig::processed(),
Arc::new(Keypair::new()),
Some(rpc_timeout),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig::default(),
);
let group_context = Arc::new(
Expand Down
3 changes: 1 addition & 2 deletions bin/service-mango-orderbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use futures_util::{
};
use itertools::Itertools;
use log::*;
use mango_v4_client::{Client, FallbackOracleConfig, MangoGroupContext, TransactionBuilderConfig};
use mango_v4_client::{Client, MangoGroupContext, TransactionBuilderConfig};
use solana_sdk::commitment_config::CommitmentConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Keypair;
Expand Down Expand Up @@ -353,7 +353,6 @@ async fn main() -> anyhow::Result<()> {
CommitmentConfig::processed(),
Arc::new(Keypair::new()),
Some(rpc_timeout),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig::default(),
);
let group_context = Arc::new(
Expand Down
3 changes: 1 addition & 2 deletions bin/service-mango-pnl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn compute_pnl(
) -> anyhow::Result<Vec<(PerpMarketIndex, I80F48)>> {
let health_cache = health_cache::new(
&context,
&FallbackOracleConfig::Never,
&FallbackOracleConfig::Dynamic,
account_fetcher.as_ref(),
account,
)
Expand Down Expand Up @@ -268,7 +268,6 @@ async fn main() -> anyhow::Result<()> {
commitment,
Arc::new(Keypair::new()),
Some(rpc_timeout),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig::default(),
);
let group_context = Arc::new(
Expand Down
3 changes: 1 addition & 2 deletions bin/settler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use clap::Parser;
use mango_v4::state::{PerpMarketIndex, TokenIndex};
use mango_v4_client::{
account_update_stream, chain_data, keypair_from_cli, snapshot_source, websocket_source, Client,
FallbackOracleConfig, MangoClient, MangoGroupContext, TransactionBuilderConfig,
MangoClient, MangoGroupContext, TransactionBuilderConfig,
};
use tracing::*;

Expand Down Expand Up @@ -100,7 +100,6 @@ async fn main() -> anyhow::Result<()> {
commitment,
settler_owner.clone(),
Some(rpc_timeout),
Some(FallbackOracleConfig::Never),
TransactionBuilderConfig {
prioritization_micro_lamports: (cli.prioritization_micro_lamports > 0)
.then_some(cli.prioritization_micro_lamports),
Expand Down
13 changes: 5 additions & 8 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, prettify_solana_client_error, MangoClient, PreparedInstructions, TransactionBuilder,
};
use solana_sdk::address_lookup_table_account::AddressLookupTableAccount;
use solana_sdk::commitment_config::CommitmentConfig;
Expand Down Expand Up @@ -114,12 +113,10 @@ impl SettlementState {
continue;
}

let health_cache = mango_client.health_cache(
&account,
account_fetcher,
)
.await
.context("creating health cache")?;
let health_cache = mango_client
.health_cache(&account, account_fetcher)
.await
.context("creating health cache")?;
let liq_end_health = health_cache.health(HealthType::LiquidationEnd);

for perp_market_index in perp_indexes {
Expand Down
2 changes: 0 additions & 2 deletions lib/client/src/gpa.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use anchor_lang::{AccountDeserialize, Discriminator};

use mango_v4::accounts_zerocopy::KeyedAccountSharedData;
use mango_v4::state::{Bank, MangoAccount, MangoAccountValue, MintInfo, PerpMarket, Serum3Market};

use solana_account_decoder::UiAccountEncoding;
Expand Down
2 changes: 2 additions & 0 deletions lib/client/src/jupiter/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ impl<'a> JupiterV4<'a> {
.collect::<Vec<_>>();

let owner = self.mango_client.owner();
let account = &self.mango_client.mango_account().await?;

let token_ams = [source_token.mint, target_token.mint]
.into_iter()
Expand All @@ -246,6 +247,7 @@ impl<'a> JupiterV4<'a> {
let (health_ams, _health_cu) = self
.mango_client
.derive_health_check_remaining_account_metas(
account,
vec![source_token.token_index, target_token.token_index],
vec![source_token.token_index, target_token.token_index],
vec![],
Expand Down

0 comments on commit e73d551

Please sign in to comment.