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
  • Loading branch information
ckamm authored Aug 11, 2023
1 parent 4eca3eb commit 8746060
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 @@ -48,6 +48,7 @@ more advanced parameters
- `REBALANCE_SLIPPAGE_BPS` - slippage liquidator should tolerate when offloading tokens (default 100)
- `PRIORITIZATION_MICRO_LAMPORTS` - how much priority fee to pay (default 0)
- `COMPUTE_LIMIT_FOR_LIQUIDATION` - compute to request for liq instructions (default 250k)
- `COMPUTE_LIMIT_FOR_TCS` - compute to request for token conditional swap trigger instructions (default 300k)
- `SNAPSHOT_INTERVAL_SECS` - how frequently to request a full on-chain snapshot (default 5min)
- `PARALLEL_RPC_REQUESTS` - number of allowed parallel rpc calls (default 10)
- `TELEMETRY` - report the liquidator's existence and pubkey occasionally (default true)
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 @@ -95,6 +95,10 @@ struct Cli {
#[clap(long, env, default_value = "250000")]
compute_limit_for_liquidation: u32,

/// 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 @@ -260,6 +264,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 @@ -26,6 +26,7 @@ pub struct Config {
pub max_trigger_quote_amount: u64,
pub refresh_timeout: Duration,
pub mock_jupiter: bool,
pub compute_limit_for_trigger: u32,
}

fn tcs_is_in_price_range(
Expand Down Expand Up @@ -238,14 +239,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 @@ -274,9 +281,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 {
Ok(ix)
}

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 8746060

Please sign in to comment.