Skip to content

Commit

Permalink
liquidator: increase tx budget for tcs trigger instructions (#674)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8746060)
  • Loading branch information
ckamm committed Aug 11, 2023
1 parent b684c32 commit 72cb639
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions bin/liquidator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions bin/liquidator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
};
Expand Down
16 changes: 12 additions & 4 deletions bin/liquidator/src/trigger_tcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -1302,7 +1302,7 @@ impl MangoClient {
},
),
};
self.send_and_confirm_owner_tx(vec![ix]).await
Ok(ix)
}

// health region
Expand Down

0 comments on commit 72cb639

Please sign in to comment.