Skip to content

Commit

Permalink
Configurable solution interactions iternalization (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz authored Jul 23, 2024
1 parent 7b41c80 commit f2c869c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/domain/solver/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub struct Dex {
/// Amount of gas that gets added to each swap to tweak the cost coverage of
/// the solver.
gas_offset: eth::Gas,

/// Whether to internalize the solution interactions using the Settlement
/// contract buffer.
internalize_interactions: bool,
}

/// The amount of time we aim the solver to finish before the final deadline is
Expand All @@ -67,6 +71,7 @@ impl Dex {
fills: Fills::new(config.smallest_partial_fill),
rate_limiter,
gas_offset: config.gas_offset,
internalize_interactions: config.internalize_interactions,
}
}

Expand Down Expand Up @@ -202,6 +207,10 @@ impl Dex {
// Maybe some liquidity appeared that enables a bigger fill.
self.fills.increase_next_try(order.uid);

Some(solution.with_buffers_internalizations(tokens))
if self.internalize_interactions {
Some(solution.with_buffers_internalizations(tokens))
} else {
Some(solution)
}
}
}
10 changes: 10 additions & 0 deletions src/infra/config/dex/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ struct Config {
/// This is useful for caching requests on an egress proxy.
#[serde(with = "humantime_serde", default)]
current_block_poll_interval: Option<Duration>,

/// Whether to internalize the solution interactions using the Settlement
/// contract buffers.
#[serde(default = "default_internalize_interactions")]
internalize_interactions: bool,
}

fn default_relative_slippage() -> BigDecimal {
Expand Down Expand Up @@ -103,6 +108,10 @@ fn default_gas_offset() -> eth::U256 {
106_391.into()
}

fn default_internalize_interactions() -> bool {
true
}

/// Loads the base solver configuration from a TOML file.
///
/// # Panics
Expand Down Expand Up @@ -167,6 +176,7 @@ pub async fn load<T: DeserializeOwned>(path: &Path) -> (super::Config, T) {
.unwrap(),
gas_offset: eth::Gas(config.gas_offset),
block_stream,
internalize_interactions: config.internalize_interactions,
};
(config, dex)
}
1 change: 1 addition & 0 deletions src/infra/config/dex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ pub struct Config {
pub rate_limiting_strategy: rate_limit::Strategy,
pub gas_offset: eth::Gas,
pub block_stream: Option<CurrentBlockStream>,
pub internalize_interactions: bool,
}

0 comments on commit f2c869c

Please sign in to comment.