Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fortuna] Automated fee adjustment based on gas prices #1708

Merged
merged 11 commits into from
Jun 18, 2024
Merged

Conversation

jayantk
Copy link
Contributor

@jayantk jayantk commented Jun 17, 2024

This should save us from having to keep dialing up/down the blast fees. I've tried to set up the logic so that it ensures the provider is always profitable and doesn't adjust the fees too often, but we'll probably have to tune this. See inline comment explaining the update logic.

Copy link

vercel bot commented Jun 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Jun 18, 2024 7:48pm

@jayantk jayantk marked this pull request as ready for review June 17, 2024 18:28
@@ -940,3 +959,195 @@ pub async fn withdraw_fees_if_necessary(

Ok(())
}

#[tracing::instrument(name = "adjust_fee", skip_all, fields())]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to have fields() if you specify skip_all

@@ -940,3 +959,195 @@ pub async fn withdraw_fees_if_necessary(

Ok(())
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this logic to a separate module? we can probably have a separate module for each of these maintenance threads

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rather do this separately and refactor all of the similar functions here so we don't end up in an inconsistent state

.try_into()
.map_err(|e| anyhow!("gas price doesn't fit into 128 bits. error: {:?}", e))?;

Ok(gas_used * gas_price)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (OCD): in this branch it's gas_used * gas_price, in the other branch it's gas_price * gas_used. You can also just return the gas_price from both branch and do the multiplication outside

/// - either the fee is increasing or the keeper is earning a profit -- i.e., fees only decrease when the keeper is profitable
/// - at least one random number has been requested since the last fee update
///
/// These conditions are designed to prevent the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence seems a bit unfinished

gas_limit: u64,
min_profit_pct: u64,
max_profit_pct: u64,
min_fee: u128,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename this to fixed_min_fee to avoid confusion

provider_fee,
target_fee
);
let contract_call = contract.set_provider_fee_as_fee_manager(provider_address, target_fee);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the what we set the value to should be something between target_fee(which can be renamed to target_fee_min) and target_fee_max. Otherwise, small changes in one direction can trigger updates continuously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good point

Copy link
Collaborator

@m30m m30m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if you can add a metric inside track_provider function to gauge the fee. Otherwise, it would be difficult to monitor how the system is working

# on-chain fees to make between [min_profit_pct, max_profit_pct] of the max callback
# cost in profit per transaction.
min_profit_pct: 0
target_profit_pct: 20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want this level of customisation. We can set this as the average of min_profit_pct and max_profit_pct.

contract.clone(),
chain_state.provider_address.clone(),
ADJUST_FEE_INTERVAL,
chain_eth_config.legacy_tx,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just pass the whole config object down?

/// The maximum percentage profit to earn as a function of the callback cost.
/// For example, 100 means a profit of 100% over the cost of the callback.
/// The fee will be lowered if it is more profitable than specified here.
/// Must be larger than min_profit_pct.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably check this min_profit_pct < target_profit_pct < max_profit_pct inequality somewhere. I can imagine a misconfiguration resulting in constant fee updates and draining the fee manager because of gas usage.

@jayantk jayantk merged commit 1a181cc into main Jun 18, 2024
4 checks passed
@jayantk jayantk deleted the fortuna_fee branch June 18, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants