Skip to content

Commit

Permalink
add fee adjusting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantk committed Jun 17, 2024
1 parent ef3c1ee commit 1f24d5c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/fortuna/src/keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ pub async fn adjust_fee_wrapper(
min_fee: u128,
) {
let mut high_water_pnl: Option<U256> = None;
let mut last_sequence_number: Option<u64> = None;
loop {
if let Err(e) = adjust_fee_if_necessary(
contract.clone(),
Expand All @@ -974,6 +975,7 @@ pub async fn adjust_fee_wrapper(
gas_limit,
min_fee,
&mut high_water_pnl,
&mut last_sequence_number,
)
.in_current_span()
.await
Expand All @@ -992,6 +994,7 @@ pub async fn adjust_fee_if_necessary(
gas_limit: u64,
min_fee: u128,
high_water_pnl: &mut Option<U256>,
last_sequence_number: &mut Option<u64>,
) -> Result<()> {
let provider = contract.provider();
let wallet = contract.wallet();
Expand Down Expand Up @@ -1027,8 +1030,14 @@ pub async fn adjust_fee_if_necessary(

// FIXME
// Don't adjust the fee on chains that are inactive. This check avoids spending keeper gas on chains
// where there's no
let is_chain_active: bool = false;
// where there's no activity.
let is_chain_active: bool = match last_sequence_number {
Some(n) => provider_info.sequence_number > *n,
None => {
*last_sequence_number = Some(provider_info.sequence_number);
false
}
};

if is_chain_active
&& high_water_pnl.is_some()
Expand Down Expand Up @@ -1058,6 +1067,8 @@ pub async fn adjust_fee_if_necessary(
"Set provider fee. Receipt: {:?}",
tx_result,
);

*last_sequence_number = Some(provider_info.sequence_number);
} else {
tracing::warn!(
"Skipping fee adjustment. Current: {:?} Target: {:?}",
Expand All @@ -1066,6 +1077,8 @@ pub async fn adjust_fee_if_necessary(
)
}

*high_water_pnl = Some(current_pnl);

Ok(())
}

Expand Down

0 comments on commit 1f24d5c

Please sign in to comment.