liquidator: Allow excluding tokens from rebalance (#774)
This commit is contained in:
parent
c49efb2213
commit
0ad26d845f
|
@ -107,6 +107,10 @@ struct Cli {
|
|||
#[clap(long, env, default_value = "100")]
|
||||
rebalance_slippage_bps: u64,
|
||||
|
||||
/// tokens to not rebalance (in addition to USDC); use a comma separated list of names
|
||||
#[clap(long, env, default_value = "")]
|
||||
rebalance_skip_tokens: String,
|
||||
|
||||
/// if taking tcs orders is enabled
|
||||
///
|
||||
/// typically only disabled for tests where swaps are unavailable
|
||||
|
@ -312,6 +316,12 @@ async fn main() -> anyhow::Result<()> {
|
|||
borrow_settle_excess: 1.05,
|
||||
refresh_timeout: Duration::from_secs(30),
|
||||
jupiter_version: cli.jupiter_version.into(),
|
||||
skip_tokens: cli
|
||||
.rebalance_skip_tokens
|
||||
.split(',')
|
||||
.filter(|v| !v.is_empty())
|
||||
.map(|name| mango_client.context.token_by_name(name).token_index)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
let rebalancer = Arc::new(rebalance::Rebalancer {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use itertools::Itertools;
|
||||
use mango_v4::accounts_zerocopy::KeyedAccountSharedData;
|
||||
use mango_v4::state::{
|
||||
Bank, BookSide, MangoAccountValue, PerpPosition, PlaceOrderType, Side, QUOTE_TOKEN_INDEX,
|
||||
Bank, BookSide, MangoAccountValue, PerpPosition, PlaceOrderType, Side, TokenIndex,
|
||||
QUOTE_TOKEN_INDEX,
|
||||
};
|
||||
use mango_v4_client::{
|
||||
chain_data, jupiter, perp_pnl, MangoClient, PerpMarketContext, TokenContext,
|
||||
|
@ -26,6 +27,7 @@ pub struct Config {
|
|||
pub borrow_settle_excess: f64,
|
||||
pub refresh_timeout: Duration,
|
||||
pub jupiter_version: jupiter::Version,
|
||||
pub skip_tokens: Vec<TokenIndex>,
|
||||
}
|
||||
|
||||
fn token_bank(
|
||||
|
@ -298,7 +300,9 @@ impl Rebalancer {
|
|||
for token_position in account.active_token_positions() {
|
||||
let token_index = token_position.token_index;
|
||||
let token = self.mango_client.context.token(token_index);
|
||||
if token_index == quote_token.token_index {
|
||||
if token_index == quote_token.token_index
|
||||
|| self.config.skip_tokens.contains(&token_index)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let token_mint = token.mint_info.mint;
|
||||
|
|
|
@ -162,11 +162,23 @@ impl MangoGroupContext {
|
|||
|
||||
pub fn token_by_mint(&self, mint: &Pubkey) -> anyhow::Result<&TokenContext> {
|
||||
self.tokens
|
||||
.iter()
|
||||
.find_map(|(_, tc)| (tc.mint_info.mint == *mint).then(|| tc))
|
||||
.values()
|
||||
.find(|tc| tc.mint_info.mint == *mint)
|
||||
.ok_or_else(|| anyhow::anyhow!("no token for mint {}", mint))
|
||||
}
|
||||
|
||||
pub fn token_by_name(&self, name: &str) -> &TokenContext {
|
||||
let mut tc_iter = self.tokens.values().filter(|tc| tc.name == name);
|
||||
let tc = tc_iter.next();
|
||||
assert!(
|
||||
tc.is_some(),
|
||||
"token {name} not found; names {:?}",
|
||||
self.tokens.values().map(|tc| tc.name.clone()).collect_vec()
|
||||
);
|
||||
assert!(tc_iter.next().is_none(), "multiple token {name} found");
|
||||
tc.unwrap()
|
||||
}
|
||||
|
||||
pub async fn new_from_rpc(rpc: &RpcClientAsync, group: Pubkey) -> anyhow::Result<Self> {
|
||||
let program = mango_v4::ID;
|
||||
|
||||
|
|
Loading…
Reference in New Issue