liquidator: increase tx budget for tcs trigger instructions (#674)

(cherry picked from commit 8746060be0)
This commit is contained in:
Christian Kamm 2023-08-11 12:48:50 +02:00
parent b684c32e1e
commit 72cb639ec9
4 changed files with 21 additions and 7 deletions

View File

@ -46,6 +46,7 @@ more advanced parameters
- `MIN_HEALTH_RATIO` - minimum health ratio the liquidator should retain (default 50%)
- `REBALANCE_SLIPPAGE_BPS` - slippage liquidator should tolerate when offloading tokens (default 100)
- `COMPUTE_LIMIT_FOR_TCS` - compute to request for token conditional swap trigger instructions (default 300k)
```shell
cargo run --bin liquidator

View File

@ -90,6 +90,10 @@ struct Cli {
#[clap(long, env, default_value = "0")]
prioritization_micro_lamports: u64,
/// compute limit requested for tcs trigger instructions
#[clap(long, env, default_value = "300000")]
compute_limit_for_tcs: u32,
/// use a jupiter mock instead of actual queries
///
/// This is required for devnet testing.
@ -250,6 +254,7 @@ async fn main() -> anyhow::Result<()> {
min_health_ratio: cli.min_health_ratio,
max_trigger_quote_amount: 1_000_000_000, // TODO: config, $1000
mock_jupiter: cli.mock_jupiter == BoolArg::True,
compute_limit_for_trigger: cli.compute_limit_for_tcs,
// TODO: config
refresh_timeout: Duration::from_secs(30),
};

View File

@ -14,6 +14,7 @@ pub struct Config {
pub max_trigger_quote_amount: u64,
pub refresh_timeout: Duration,
pub mock_jupiter: bool,
pub compute_limit_for_trigger: u32,
}
async fn tcs_is_in_price_range(
@ -212,14 +213,20 @@ async fn execute_token_conditional_swap(
"executing token conditional swap",
);
let txsig = mango_client
.token_conditional_swap_trigger(
let compute_ix = solana_sdk::compute_budget::ComputeBudgetInstruction::set_compute_unit_limit(
config.compute_limit_for_trigger,
);
let trigger_ix = mango_client
.token_conditional_swap_trigger_instruction(
(pubkey, &liqee),
tcs.id,
max_buy_token_to_liqee,
max_sell_token_to_liqor,
)
.await?;
let txsig = mango_client
.send_and_confirm_owner_tx(vec![compute_ix, trigger_ix])
.await?;
info!(
%txsig,
"Executed token conditional swap",
@ -248,9 +255,10 @@ pub async fn remove_expired_token_conditional_swap(
liqee: &MangoAccountValue,
tcs_id: u64,
) -> anyhow::Result<bool> {
let txsig = mango_client
.token_conditional_swap_trigger((pubkey, &liqee), tcs_id, 0, 0)
let ix = mango_client
.token_conditional_swap_trigger_instruction((pubkey, &liqee), tcs_id, 0, 0)
.await?;
let txsig = mango_client.send_and_confirm_owner_tx(vec![ix]).await?;
info!(
%txsig,
"Removed expired token conditional swap",

View File

@ -1258,13 +1258,13 @@ impl MangoClient {
self.send_and_confirm_owner_tx(vec![ix]).await
}
pub async fn token_conditional_swap_trigger(
pub async fn token_conditional_swap_trigger_instruction(
&self,
liqee: (&Pubkey, &MangoAccountValue),
token_conditional_swap_id: u64,
max_buy_token_to_liqee: u64,
max_sell_token_to_liqor: u64,
) -> anyhow::Result<Signature> {
) -> anyhow::Result<Instruction> {
let (tcs_index, tcs) = liqee
.1
.token_conditional_swap_by_id(token_conditional_swap_id)?;
@ -1302,7 +1302,7 @@ impl MangoClient {
},
),
};
self.send_and_confirm_owner_tx(vec![ix]).await
Ok(ix)
}
// health region