Skip to content

feat(config): centralize solver defaults into a layered config file - #320

Open
zizou0x wants to merge 1 commit into
mainfrom
zz/eng-6176-config-file
Open

feat(config): centralize solver defaults into a layered config file#320
zizou0x wants to merge 1 commit into
mainfrom
zz/eng-6176-config-file

Conversation

@zizou0x

@zizou0x zizou0x commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

What

All solver-tuning defaults now live in one file,
fynd-core/src/config/default_config.toml, embedded in the binary. It
deserializes directly into a complete config::Config (every field
required except the chain-specific min_tvl), so adding a config field
without updating the file fails the build's tests.

Configuration resolves field by field through three layers, highest
priority first:

  1. CLI flags (only flags the user actually set)
  2. Local config file: --config-file / CONFIG_FILE, default ./fynd.toml
  3. Embedded default config

Library API

  • config::embedded_default() returns the cached, complete default Config
  • Config::apply(&PartialConfig) overlays a layer (exhaustive
    destructuring: a new PartialConfig field without an overlay arm is a
    compile error)
  • Config::validate() range-checks the resolved result;
    FyndBuilder::apply_config(&Config) validates automatically
  • FyndBuilder::new seeds its defaults from the embedded config

Backward compatibility

  • worker_pools.toml (file or --worker-pools-config/WORKER_POOLS_CONFIG)
    keeps working; its pools override the config file's so existing
    deployments keep their pools. A deprecation warning points to fynd.toml.
  • The repo's worker_pools.toml is renamed to fynd.toml and extended
    into a full config example; docker-compose and the record-market /
    integration-test includes follow.
  • Breaking for lib consumers: the tuning constants in
    fynd_core::solver::defaults (and their fynd-rpc re-exports) are
    removed; read config::embedded_default() instead.

Behavior

Defaults are unchanged — the embedded values match the previous
constants, and --help now renders them from the config file. Startup
logs the full resolved config.

🤖 Generated with Claude Code

All tuning defaults live in an embedded default_config.toml, overlaid
field by field by the local config file (fynd.toml) and CLI flags.
The legacy worker_pools.toml is still honored but deprecated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zizou0x
zizou0x force-pushed the zz/eng-6176-config-file branch from 98178eb to 5167d62 Compare July 17, 2026 08:30
@github-actions

Copy link
Copy Markdown

Breaking API Changes (Intentional)

Breaking API changes detected and declared in the PR title.
Ensure the minor version is bumped before merging (breaking changes on 0.x.x bump the minor).

semver-checks output
Checking fynd-core v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   1.054s] 196 checks: 194 pass, 2 fail, 0 warn, 49 skip

--- failure auto_trait_impl_removed: auto trait no longer implemented ---

Description:
A public type has stopped implementing one or more auto traits. This can break downstream code that depends on the traits being implemented.
        ref: https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/auto_trait_impl_removed.ron

Failed in:
  type SolverBuildError is no longer UnwindSafe, in fynd-core/src/solver.rs:255
  type SolverBuildError is no longer RefUnwindSafe, in fynd-core/src/solver.rs:255
  type SolverBuildError is no longer UnwindSafe, in fynd-core/src/solver.rs:255
  type SolverBuildError is no longer RefUnwindSafe, in fynd-core/src/solver.rs:255

--- failure pub_module_level_const_missing: pub module-level const is missing ---

Description:
A public const is missing or renamed
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/pub_module_level_const_missing.ron

Failed in:
  MIN_TOKEN_QUALITY in file fynd-core/src/solver.rs:63
  GAS_REFRESH_INTERVAL in file fynd-core/src/solver.rs:69
  ROUTER_MIN_RESPONSES in file fynd-core/src/solver.rs:76
  TRADED_N_DAYS_AGO in file fynd-core/src/solver.rs:65
  TVL_BUFFER_RATIO in file fynd-core/src/solver.rs:67
  RECONNECT_DELAY in file fynd-core/src/solver.rs:73

     Summary semver requires new major version: 2 major and 0 minor checks failed
    Finished [   1.444s] fynd-core
    Checking fynd-test-fixtures v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.119s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.181s] fynd-test-fixtures
    Checking fynd-rpc v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.112s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.173s] fynd-rpc
    Checking fynd-rpc-types v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.193s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.292s] fynd-rpc-types
    Checking fynd-client v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.240s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.376s] fynd-client
    Checking fynd-tools-common v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.091s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.143s] fynd-tools-common
    Checking erc20-overrides v0.90.2 -> v0.90.2 (no change; assume minor)
     Checked [   0.092s] 196 checks: 196 pass, 49 skip
     Summary no semver update required
    Finished [   0.132s] erc20-overrides

@brunoguerios
brunoguerios self-requested a review July 17, 2026 16:13

@brunoguerios brunoguerios left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Elegant solution! 😃
LGTM ✅

Comment thread fynd-core/src/solver.rs
protocols: Vec<String>,
min_tvl: f64,
) -> Self {
let embedded = crate::config::embedded_default();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these inline imports intentional?
Should we move them to the top of the file?

Comment thread src/cli.rs
/// Path to worker pools TOML config file
#[arg(short, long, env, default_value = "worker_pools.toml")]
pub worker_pools_config: PathBuf,
#[arg(long, help = cfg_help("Only include tokens traded within this many days", embedded_default().traded_n_days_ago))]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice cleanup/improvement 👏

Comment on lines +26 to +32
//! let overrides = PartialConfig { worker_router_timeout_ms: Some(50), ..Default::default() };
//! let config = embedded_default()
//! .clone()
//! .apply(&PartialConfig::from_file("fynd.toml")?)
//! .apply(&overrides);
//! let builder = FyndBuilder::new(chain, tycho_url, rpc_url, config.protocols.clone(), min_tvl)
//! .apply_config(&config)?; // validates the config

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice flow 👏

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