Skip to content

Commit 8a31bab

Browse files
authored
feat(fortuna): Add a couple more config values (#2251)
* feat(fortuna): Add a couple more config values * doc * gr * allow negative profits * right version * fix error
1 parent 5fc0f0d commit 8a31bab

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

apps/fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "7.1.0"
3+
version = "7.2.0"
44
edition = "2021"
55

66
[dependencies]

apps/fortuna/src/config.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,23 @@ pub struct EthereumConfig {
143143
pub escalation_policy: EscalationPolicyConfig,
144144

145145
/// The minimum percentage profit to earn as a function of the callback cost.
146-
/// For example, 20 means a profit of 20% over the cost of the callback.
146+
/// For example, 20 means a profit of 20% over the cost of a callback that uses the full gas limit.
147147
/// The fee will be raised if the profit is less than this number.
148-
pub min_profit_pct: u64,
148+
/// The minimum value for this is -100. If set to < 0, it means the keeper may lose money on callbacks that use the full gas limit.
149+
pub min_profit_pct: i64,
149150

150151
/// The target percentage profit to earn as a function of the callback cost.
151-
/// For example, 20 means a profit of 20% over the cost of the callback.
152+
/// For example, 20 means a profit of 20% over the cost of a callback that uses the full gas limit.
152153
/// The fee will be set to this target whenever it falls outside the min/max bounds.
153-
pub target_profit_pct: u64,
154+
/// The minimum value for this is -100. If set to < 0, it means the keeper may lose money on callbacks that use the full gas limit.
155+
pub target_profit_pct: i64,
154156

155157
/// The maximum percentage profit to earn as a function of the callback cost.
156-
/// For example, 100 means a profit of 100% over the cost of the callback.
158+
/// For example, 100 means a profit of 100% over the cost of a callback that uses the full gas limit.
157159
/// The fee will be lowered if it is more profitable than specified here.
158160
/// Must be larger than min_profit_pct.
159-
pub max_profit_pct: u64,
161+
/// The minimum value for this is -100. If set to < 0, it means the keeper may lose money on callbacks that use the full gas limit.
162+
pub max_profit_pct: i64,
160163

161164
/// Minimum wallet balance for the keeper. If the balance falls below this level, the keeper will
162165
/// withdraw fees from the contract to top up. This functionality requires the keeper to be the fee
@@ -182,15 +185,20 @@ fn default_priority_fee_multiplier_pct() -> u64 {
182185

183186
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
184187
pub struct EscalationPolicyConfig {
185-
/// The initial gas multiplier to apply to the gas limit.
188+
// The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit.
189+
// Default value is 110, meaning a 10% tolerance over the configured value.
190+
#[serde(default = "default_gas_limit_tolerance_pct")]
191+
pub gas_limit_tolerance_pct: u64,
192+
193+
/// The initial gas multiplier to apply to the tx gas estimate
186194
#[serde(default = "default_initial_gas_multiplier_pct")]
187195
pub initial_gas_multiplier_pct: u64,
188196

189-
/// The gas multiplier to apply to the gas limit during backoff retries.
197+
/// The gas multiplier to apply to the tx gas estimate during backoff retries.
190198
/// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`.
191199
#[serde(default = "default_gas_multiplier_pct")]
192200
pub gas_multiplier_pct: u64,
193-
/// The maximum gas multiplier to apply to the gas limit during backoff retries.
201+
/// The maximum gas multiplier to apply to the tx gas estimate during backoff retries.
194202
#[serde(default = "default_gas_multiplier_cap_pct")]
195203
pub gas_multiplier_cap_pct: u64,
196204

@@ -203,6 +211,10 @@ pub struct EscalationPolicyConfig {
203211
pub fee_multiplier_cap_pct: u64,
204212
}
205213

214+
fn default_gas_limit_tolerance_pct() -> u64 {
215+
110
216+
}
217+
206218
fn default_initial_gas_multiplier_pct() -> u64 {
207219
125
208220
}
@@ -226,6 +238,7 @@ fn default_fee_multiplier_cap_pct() -> u64 {
226238
impl Default for EscalationPolicyConfig {
227239
fn default() -> Self {
228240
Self {
241+
gas_limit_tolerance_pct: default_gas_limit_tolerance_pct(),
229242
initial_gas_multiplier_pct: default_initial_gas_multiplier_pct(),
230243
gas_multiplier_pct: default_gas_multiplier_pct(),
231244
gas_multiplier_cap_pct: default_gas_multiplier_cap_pct(),

apps/fortuna/src/keeper.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,13 @@ pub async fn run_keeper_threads(
338338
// In the unlikely event that the keeper fees aren't sufficient, the solution to this is to configure the target
339339
// fee percentage to be higher on that specific chain.
340340
chain_eth_config.gas_limit,
341-
chain_eth_config.min_profit_pct,
342-
chain_eth_config.target_profit_pct,
343-
chain_eth_config.max_profit_pct,
341+
// NOTE: unwrap() here so we panic early if someone configures these values below -100.
342+
u64::try_from(100 + chain_eth_config.min_profit_pct)
343+
.expect("min_profit_pct must be >= -100"),
344+
u64::try_from(100 + chain_eth_config.target_profit_pct)
345+
.expect("target_profit_pct must be >= -100"),
346+
u64::try_from(100 + chain_eth_config.max_profit_pct)
347+
.expect("max_profit_pct must be >= -100"),
344348
chain_eth_config.fee,
345349
)
346350
.in_current_span(),
@@ -435,7 +439,7 @@ pub async fn process_event_with_backoff(
435439
&event,
436440
&chain_state,
437441
&contract,
438-
gas_limit,
442+
gas_limit.saturating_mul(escalation_policy.gas_limit_tolerance_pct.into()) / 100,
439443
gas_multiplier_pct,
440444
fee_multiplier_pct,
441445
metrics.clone(),
@@ -1253,15 +1257,15 @@ pub async fn adjust_fee_if_necessary(
12531257
.await
12541258
.map_err(|e| anyhow!("Could not estimate transaction cost. error {:?}", e))?;
12551259
let target_fee_min = std::cmp::max(
1256-
(max_callback_cost * (100 + u128::from(min_profit_pct))) / 100,
1260+
(max_callback_cost * u128::from(min_profit_pct)) / 100,
12571261
min_fee_wei,
12581262
);
12591263
let target_fee = std::cmp::max(
1260-
(max_callback_cost * (100 + u128::from(target_profit_pct))) / 100,
1264+
(max_callback_cost * u128::from(target_profit_pct)) / 100,
12611265
min_fee_wei,
12621266
);
12631267
let target_fee_max = std::cmp::max(
1264-
(max_callback_cost * (100 + u128::from(max_profit_pct))) / 100,
1268+
(max_callback_cost * u128::from(max_profit_pct)) / 100,
12651269
min_fee_wei,
12661270
);
12671271

0 commit comments

Comments
 (0)