From 0a55184ec7057393ff86e6e2de64c9ac27179034 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Fri, 22 Dec 2023 08:28:58 +0100 Subject: [PATCH] liquidator: stop withdraw attempts on delgated accounts --- bin/liquidator/src/main.rs | 7 +++++++ bin/liquidator/src/rebalance.rs | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/liquidator/src/main.rs b/bin/liquidator/src/main.rs index 056dbda6b..1e44ea799 100644 --- a/bin/liquidator/src/main.rs +++ b/bin/liquidator/src/main.rs @@ -16,6 +16,7 @@ use mango_v4_client::{ use itertools::Itertools; use solana_sdk::commitment_config::CommitmentConfig; use solana_sdk::pubkey::Pubkey; +use solana_sdk::signer::Signer; use tracing::*; pub mod liquidate; @@ -194,6 +195,11 @@ async fn main() -> anyhow::Result<()> { .await?; let mango_group = mango_account.fixed.group; + let signer_is_owner = mango_account.fixed.owner == liqor_owner.pubkey(); + if cli.rebalance == BoolArg::True && !signer_is_owner { + 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 mango_oracles = group_context @@ -322,6 +328,7 @@ async fn main() -> anyhow::Result<()> { .filter(|v| !v.is_empty()) .map(|name| mango_client.context.token_by_name(name).token_index) .collect(), + allow_withdraws: signer_is_owner, }; let rebalancer = Arc::new(rebalance::Rebalancer { diff --git a/bin/liquidator/src/rebalance.rs b/bin/liquidator/src/rebalance.rs index 08b4a361d..5ab2bcd12 100644 --- a/bin/liquidator/src/rebalance.rs +++ b/bin/liquidator/src/rebalance.rs @@ -28,6 +28,7 @@ pub struct Config { pub refresh_timeout: Duration, pub jupiter_version: jupiter::Version, pub skip_tokens: Vec, + pub allow_withdraws: bool, } fn token_bank( @@ -387,7 +388,11 @@ impl Rebalancer { // Any remainder that could not be sold just gets withdrawn to ensure the // TokenPosition is freed up - if amount > 0 && amount <= dust_threshold && !token_position.is_in_use() { + if amount > 0 + && amount <= dust_threshold + && !token_position.is_in_use() + && self.config.allow_withdraws + { let allow_borrow = false; let txsig = self .mango_client