Skip to content

[PR #29] BotConfig.min_profit_usd: f64 — floats forbidden for money values #75

@obchain

Description

@obchain

PR: #29 (feat/04-toml-config-loader)
File: crates/charon-core/src/config.rs, line 36 (BotConfig.min_profit_usd)

f64 for financial threshold. Project rule: USD / token values never in f64/f32. Same issue PR #27 addressed for net_profit_wei. Threshold comparison against oracle-derived profit (currently slated to land as U256 after issue #66) will require a lossy cast.

Impact:

  1. Precision loss on large denominations.
  2. NaN-safety: any arithmetic that produces NaN compares false against all thresholds — profitable liquidation silently dropped.
  3. Inconsistent with net_profit representation after [PR #27] net_profit_usd_cents: u64 is lossy USD denomination — use U256 token-native #66 fix.

Fix: Two options:

  • min_profit_wei: U256 with config value as decimal string, parsed via custom serde deser. Denomination tied to a reference token (USDT on BSC — 18 dec).
  • min_profit_usd_1e6: u64 fixed-point 6-decimal. Simpler to render in config.

Prefer the latter for human-authored TOML ergonomics. Update config/default.toml accordingly:

min_profit_usd_1e6 = 5000000   # $5.00

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p0-blockerBlocks the critical path

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions