Skip to content

Commit

Permalink
Merge branch 'main' into deploy-next
Browse files Browse the repository at this point in the history
  • Loading branch information
microwavedcola1 committed Aug 26, 2024
2 parents 70a3e0d + 549b5c6 commit 0ffc40c
Show file tree
Hide file tree
Showing 45 changed files with 2,733 additions and 627 deletions.
25 changes: 18 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ Update this for each program release and mainnet deployment.

## not on mainnet

### v0.24.3, 2024-8-

- Program: Remove delegate account withdrawal limit (#939)
- Program: Allow the insurance fund to be for any bank (#946)
- Program: add a tier string in banks (#988)
- Program: Allow closing open orders account for force closed spot markets (#995)

## mainnet

### v0.24.2, 2024-7-

Deployment: Jul 29, 2024 at 10:46:28 Central European Summer Time,
https://explorer.solana.com/tx/8zFSfPVSw98NL7nnJgfjNEhXcUVJtaCxLxnj9jt6kAnLwBR8LvzrS1Q5p21CuwiueJisdQFurf1ujNy38GiUEB1

- Program: charge collateral fee directly on borrowed tokens (#973)

- Program: fix TokenUpdateIndexAndRateResilient IX (#979)

- Program: add support for pyth v2 account (#980)

## mainnet

### v0.24.1, 2024-7-9

Deployment: Jul 9, 2024 at 15:46:15 Central European Summer Time,
Expand All @@ -25,18 +35,18 @@ https://explorer.solana.com/tx/5KYBSXV4uRCUK6vaQoZjipNFhTqEY1b1DHJeSh5jo87UUVGBB

### v0.24.0, 2024-4-18

Deployment: Apr 18, 2024 at 14:53:24 Central European Summer Time,
Deployment: Apr 18, 2024 at 14:53:24 Central European Summer Time,
https://explorer.solana.com/tx/2TFCGXQkUjRvkuuojxmiKefUtHPp6q6rM1frYvALByWMGfpWbiGH5hGq5suWEH7TUKoz4jb4KCGxu9DRw7YcXNdh

- Allow skipping banks and invalid oracles when computing health (#891)

This is only possible when we know for sure that the operation would not put the account into negative health zone.
This is only possible when we know for sure that the operation would not put the account into negative health zone.

- Add support for Raydium CLMM as oracle fallback (#856)

- Add a `TokenBalanceLog` when charging collateral fees (#894)

- Withdraw instruction: remove overflow error and return appropriate error message instead (#910)
- Withdraw instruction: remove overflow error and return appropriate error message instead (#910)

- Banks: add more safety checks (#895)

Expand All @@ -46,7 +56,7 @@ https://explorer.solana.com/tx/2TFCGXQkUjRvkuuojxmiKefUtHPp6q6rM1frYvALByWMGfpWb

- Add a sequence check instruction (#909)

Assert that a transaction was emitted and run with a correct view of the current mango state.
Assert that a transaction was emitted and run with a correct view of the current mango state.

### v0.23.0, 2024-3-8

Expand Down Expand Up @@ -154,6 +164,7 @@ Deployment: Dec 13, 2023 at 09:02:46 Central European Standard Time, https://exp
The DAO had previously reduced the percentage amount as a mitigation.

With this change:

- low-health settlement incentives are capped at 2x the flat fee, removing
unlimited percentual incentive fees entirely
- incentives are only paid if at least 1% of position value is settled,
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

Binary file added audits/Audit_OtterSec_Mango_v0.24.3.pdf
Binary file not shown.
11 changes: 11 additions & 0 deletions bin/liquidator/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ pub struct Cli {
#[clap(long, env, default_value = "30")]
pub(crate) rebalance_refresh_timeout_secs: u64,

#[clap(long, env, value_enum, default_value = "false")]
pub(crate) rebalance_using_limit_order: BoolArg,

/// distance (in bps) from oracle price at which to place order for rebalancing
#[clap(long, env, default_value = "100")]
pub(crate) rebalance_limit_order_distance_from_oracle_price_bps: u64,

/// if taking tcs orders is enabled
///
/// typically only disabled for tests where swaps are unavailable
Expand Down Expand Up @@ -250,4 +257,8 @@ pub struct Cli {
/// override the sanctum http request timeout
#[clap(long, env, default_value = "30")]
pub(crate) sanctum_timeout_secs: u64,

/// max number of liquidation/tcs to do concurrently
#[clap(long, env, default_value = "5")]
pub(crate) max_parallel_operations: u64,
}
47 changes: 43 additions & 4 deletions bin/liquidator/src/liquidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use mango_v4_client::{chain_data, MangoClient, PreparedInstructions};
use solana_sdk::signature::Signature;

use futures::{stream, StreamExt, TryStreamExt};
use mango_v4::accounts_ix::HealthCheckKind::MaintRatio;
use rand::seq::SliceRandom;
use tracing::*;
use {anyhow::Context, fixed::types::I80F48, solana_sdk::pubkey::Pubkey};
Expand Down Expand Up @@ -260,7 +261,22 @@ impl<'a> LiquidateHelper<'a> {
)
.await
.context("creating perp_liq_base_or_positive_pnl_instruction")?;

liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix);

let liqor = &self.client.mango_account().await?;
liq_ixs.append(
self.client
.health_check_instruction(
liqor,
self.config.min_health_ratio,
vec![],
vec![*perp_market_index],
MaintRatio,
)
.await?,
);

let txsig = self
.client
.send_and_confirm_authority_tx(liq_ixs.to_instructions())
Expand Down Expand Up @@ -501,6 +517,20 @@ impl<'a> LiquidateHelper<'a> {
.await
.context("creating liq_token_with_token ix")?;
liq_ixs.cu = liq_ixs.cu.max(self.config.compute_limit_for_liq_ix);

let liqor = self.client.mango_account().await?;
liq_ixs.append(
self.client
.health_check_instruction(
&liqor,
self.config.min_health_ratio,
vec![asset_token_index, liab_token_index],
vec![],
MaintRatio,
)
.await?,
);

let txsig = self
.client
.send_and_confirm_authority_tx(liq_ixs.to_instructions())
Expand Down Expand Up @@ -651,14 +681,11 @@ impl<'a> LiquidateHelper<'a> {
}

#[allow(clippy::too_many_arguments)]
pub async fn maybe_liquidate_account(
pub async fn can_liquidate_account(
mango_client: &MangoClient,
account_fetcher: &chain_data::AccountFetcher,
pubkey: &Pubkey,
config: &Config,
) -> anyhow::Result<bool> {
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)
Expand All @@ -675,6 +702,18 @@ pub async fn maybe_liquidate_account(
"possible candidate",
);

Ok(true)
}

#[allow(clippy::too_many_arguments)]
pub async fn maybe_liquidate_account(
mango_client: &MangoClient,
account_fetcher: &chain_data::AccountFetcher,
pubkey: &Pubkey,
config: &Config,
) -> anyhow::Result<bool> {
let liqor_min_health_ratio = I80F48::from_num(config.min_health_ratio);

// Fetch a fresh account and re-compute
// This is -- unfortunately -- needed because the websocket streams seem to not
// be great at providing timely updates to the account data.
Expand Down
Loading

0 comments on commit 0ffc40c

Please sign in to comment.