From e090104c694ee7e6b179546fd8c93a5b058e4215 Mon Sep 17 00:00:00 2001 From: Serge Farny Date: Tue, 9 Apr 2024 10:50:35 +0200 Subject: [PATCH] keeper: add CU estimate for perp update funding, perp consume events and token update index & rates (#937) --- bin/keeper/src/crank.rs | 37 +++++++++++++++++++++++++++++++------ lib/client/src/context.rs | 8 ++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/bin/keeper/src/crank.rs b/bin/keeper/src/crank.rs index 0e7c5b3fc..82359c859 100644 --- a/bin/keeper/src/crank.rs +++ b/bin/keeper/src/crank.rs @@ -193,7 +193,7 @@ pub async fn loop_update_index_and_rate( .map(|token_index| client.context.token(*token_index).name.to_owned()) .join(","); - let mut instructions = vec![]; + let mut instructions = PreparedInstructions::new(); for token_index in token_indices_clone.iter() { let token = client.context.token(*token_index); let banks_for_a_token = token.banks(); @@ -225,7 +225,14 @@ pub async fn loop_update_index_and_rate( ix.accounts.append(&mut banks); - let sim_result = match client.simulate(vec![ix.clone()]).await { + let pix = PreparedInstructions::from_single( + ix, + client + .context + .compute_estimates + .cu_token_update_index_and_rates, + ); + let sim_result = match client.simulate(pix.clone().to_instructions()).await { Ok(response) => response.value, Err(e) => { error!(token.name, "simulation request error: {e:?}"); @@ -238,11 +245,12 @@ pub async fn loop_update_index_and_rate( continue; } - instructions.push(ix); + instructions.append(pix); } + let pre = Instant::now(); let sig_result = client - .send_and_confirm_permissionless_tx(instructions) + .send_and_confirm_permissionless_tx(instructions.to_instructions()) .await; let duration_ms = pre.elapsed().as_millis(); @@ -358,7 +366,18 @@ pub async fn loop_consume_events( }), }; - let sig_result = client.send_and_confirm_permissionless_tx(vec![ix]).await; + let ixs = PreparedInstructions::from_single( + ix, + client.context.compute_estimates.cu_perp_consume_events_base + + num_of_events + * client + .context + .compute_estimates + .cu_perp_consume_events_per_event, + ); + let sig_result = client + .send_and_confirm_permissionless_tx(ixs.to_instructions()) + .await; let duration_ms = pre.elapsed().as_millis(); @@ -411,7 +430,13 @@ pub async fn loop_update_funding( ), data: anchor_lang::InstructionData::data(&mango_v4::instruction::PerpUpdateFunding {}), }; - let sig_result = client.send_and_confirm_permissionless_tx(vec![ix]).await; + let ixs = PreparedInstructions::from_single( + ix, + client.context.compute_estimates.cu_perp_update_funding, + ); + let sig_result = client + .send_and_confirm_permissionless_tx(ixs.to_instructions()) + .await; let duration_ms = pre.elapsed().as_millis(); diff --git a/lib/client/src/context.rs b/lib/client/src/context.rs index 8c8bf4d8b..73e31018c 100644 --- a/lib/client/src/context.rs +++ b/lib/client/src/context.rs @@ -123,6 +123,10 @@ pub struct ComputeEstimates { pub cu_per_charge_collateral_fees: u32, pub cu_per_charge_collateral_fees_token: u32, pub cu_per_associated_token_account_creation: u32, + pub cu_perp_update_funding: u32, + pub cu_perp_consume_events_base: u32, + pub cu_perp_consume_events_per_event: u32, + pub cu_token_update_index_and_rates: u32, } impl Default for ComputeEstimates { @@ -147,6 +151,10 @@ impl Default for ComputeEstimates { // per-chargable-token cost cu_per_charge_collateral_fees_token: 15_000, cu_per_associated_token_account_creation: 21_000, + cu_perp_update_funding: 40_000, + cu_perp_consume_events_base: 10_000, + cu_perp_consume_events_per_event: 18_000, + cu_token_update_index_and_rates: 90_000, } } }