-
Notifications
You must be signed in to change notification settings - Fork 213
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
feat(fortuna): add eip1559_fee_multiplier_pct to adjust gas fees #2191
Closed
devin-ai-integration
wants to merge
6
commits into
main
from
devin/1734012868-add-eip1559-fee-multiplier
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5cc054e
feat(fortuna): add eip1559_fee_multiplier_pct to adjust gas fees
devin-ai-integration[bot] b3aaeb8
refactor: address PR feedback
devin-ai-integration[bot] c6a438e
refactor: restore original tracking functionality and fix balance con…
devin-ai-integration[bot] a1bb2ac
refactor: move fee multiplier to GasOracle
devin-ai-integration[bot] 632183b
style: apply cargo fmt changes
devin-ai-integration[bot] ec4d078
refactor: remove unnecessary span tracking and clean up keeper.rs
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,18 +266,25 @@ pub async fn run_keeper_threads( | |
); | ||
|
||
// Spawn a thread that periodically adjusts the provider fee. | ||
let config_for_fee = chain_eth_config.clone(); | ||
let provider_address = chain_state.provider_address; | ||
let contract_for_fee = contract.clone(); | ||
spawn( | ||
adjust_fee_wrapper( | ||
contract.clone(), | ||
chain_state.provider_address, | ||
ADJUST_FEE_INTERVAL, | ||
chain_eth_config.legacy_tx, | ||
chain_eth_config.gas_limit, | ||
chain_eth_config.min_profit_pct, | ||
chain_eth_config.target_profit_pct, | ||
chain_eth_config.max_profit_pct, | ||
chain_eth_config.fee, | ||
) | ||
async move { | ||
adjust_fee_wrapper( | ||
contract_for_fee, | ||
provider_address, | ||
ADJUST_FEE_INTERVAL, | ||
config_for_fee.legacy_tx, | ||
config_for_fee.gas_limit, | ||
config_for_fee.min_profit_pct, | ||
config_for_fee.target_profit_pct, | ||
config_for_fee.max_profit_pct, | ||
config_for_fee.fee, | ||
config_for_fee.eip1559_fee_multiplier_pct, | ||
) | ||
.await | ||
} | ||
.in_current_span(), | ||
); | ||
|
||
|
@@ -807,8 +814,7 @@ pub async fn process_backlog( | |
tracing::info!("Backlog processed"); | ||
} | ||
|
||
/// tracks the balance of the given address on the given chain | ||
/// if there was an error, the function will just return | ||
/// Track the balance of an account. If there was an error, the function will just return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't change this comment |
||
#[tracing::instrument(skip_all)] | ||
pub async fn track_balance( | ||
chain_id: String, | ||
|
@@ -838,8 +844,7 @@ pub async fn track_balance( | |
.set(balance); | ||
} | ||
|
||
/// tracks the collected fees and the hashchain data of the given provider address on the given chain | ||
/// if there is a error the function will just return | ||
/// Track the provider info. If there is a error the function will just return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't change this comment |
||
#[tracing::instrument(skip_all)] | ||
pub async fn track_provider( | ||
chain_id: ChainId, | ||
|
@@ -997,6 +1002,7 @@ pub async fn adjust_fee_wrapper( | |
target_profit_pct: u64, | ||
max_profit_pct: u64, | ||
min_fee_wei: u128, | ||
eip1559_fee_multiplier_pct: u64, | ||
) { | ||
// The maximum balance of accrued fees + provider wallet balance. None if we haven't observed a value yet. | ||
let mut high_water_pnl: Option<U256> = None; | ||
|
@@ -1014,6 +1020,7 @@ pub async fn adjust_fee_wrapper( | |
min_fee_wei, | ||
&mut high_water_pnl, | ||
&mut sequence_number_of_last_fee_update, | ||
eip1559_fee_multiplier_pct, | ||
) | ||
.in_current_span() | ||
.await | ||
|
@@ -1097,6 +1104,7 @@ pub async fn adjust_fee_if_necessary( | |
min_fee_wei: u128, | ||
high_water_pnl: &mut Option<U256>, | ||
sequence_number_of_last_fee_update: &mut Option<u64>, | ||
eip1559_fee_multiplier_pct: u64, | ||
) -> Result<()> { | ||
let provider_info = contract | ||
.get_provider_info(provider_address) | ||
|
@@ -1109,9 +1117,14 @@ pub async fn adjust_fee_if_necessary( | |
} | ||
|
||
// Calculate target window for the on-chain fee. | ||
let max_callback_cost: u128 = estimate_tx_cost(contract.clone(), legacy_tx, gas_limit.into()) | ||
.await | ||
.map_err(|e| anyhow!("Could not estimate transaction cost. error {:?}", e))?; | ||
let max_callback_cost: u128 = estimate_tx_cost( | ||
contract.clone(), | ||
legacy_tx, | ||
gas_limit.into(), | ||
eip1559_fee_multiplier_pct, | ||
) | ||
.await | ||
.map_err(|e| anyhow!("Could not estimate transaction cost. error {:?}", e))?; | ||
let target_fee_min = std::cmp::max( | ||
(max_callback_cost * (100 + u128::from(min_profit_pct))) / 100, | ||
min_fee_wei, | ||
|
@@ -1197,6 +1210,7 @@ pub async fn estimate_tx_cost( | |
contract: Arc<InstrumentedSignablePythContract>, | ||
use_legacy_tx: bool, | ||
gas_used: u128, | ||
eip1559_fee_multiplier_pct: u64, | ||
) -> Result<u128> { | ||
let middleware = contract.client(); | ||
|
||
|
@@ -1212,7 +1226,11 @@ pub async fn estimate_tx_cost( | |
.estimate_eip1559_fees(Some(eip1559_default_estimator)) | ||
.await?; | ||
|
||
(max_fee_per_gas + max_priority_fee_per_gas) | ||
let multiplier = U256::from(eip1559_fee_multiplier_pct); | ||
let base = max_fee_per_gas + max_priority_fee_per_gas; | ||
let adjusted = (base * multiplier) / U256::from(100); | ||
|
||
adjusted | ||
.try_into() | ||
.map_err(|e| anyhow!("gas price doesn't fit into 128 bits. error: {:?}", e))? | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this async move , the await, and the clones above are unnecessary