feat(core): add TOML config loader with ${ENV_VAR} substitution#29
Merged
Conversation
Introduce the Config struct hierarchy covering bot-level knobs, per-chain
RPC endpoints, per-protocol addresses, flash-loan sources, and deployed
liquidator contracts. Keyed by short names (HashMap<String, T>) so adding
new chains/protocols later is a config change rather than a schema change.
Config::load(path):
1. reads the TOML file
2. substitutes \${VAR} placeholders from process env (errors if unset)
3. deserializes into Config via serde
Ship config/default.toml with real BSC addresses for Venus Unitroller and
Aave V3 Pool (flashLoanSimple source). Liquidator contract address is a
placeholder until CharonLiquidator.sol is deployed.
.env.example documents the two required env vars (BNB_WS_URL, BNB_HTTP_URL)
with public-node defaults for testing.
This was referenced Apr 22, 2026
…dation, ConfigError - Integer money: BotConfig.min_profit_usd -> min_profit_usd_1e6: u64 (USD × 1e6 fixed-point); BotConfig.max_gas_gwei -> max_gas_wei: U256 via decimal-or-hex string deser. Removes f64 precision/NaN risk and lets gas caps express sub-gwei priority fees. - Secret redaction: ChainConfig and Config now have manual Debug impls that print '<redacted>' for ws_url / http_url and '<N chains redacted>' so the log sink and panic messages cannot leak API keys embedded in RPC URLs. - Cross-reference validation: Config::load now calls validate() which rejects protocol/flashloan/liquidator entries whose does not exist in [chain.*] and rejects zero addresses. Empty [chain.*] errors. - #[serde(deny_unknown_fields)] on every config struct so typos (e.g. ) error at load instead of silently defaulting the profit floor to zero. - Env-var substitution is now TOML-escape-aware (\, ", \n, \r, \t in values do not break the enclosing string), supports default, and rejects invalid env-var names. - Structured ConfigError (NotFound / Io / UnsetEnvVar / InvalidEnvVarName / UnterminatedInterp / Parse / Parse / Validation) with #[non_exhaustive] so the CLI can map to exit codes and operators see actionable messages. - Config::from_str added for unit tests; config/default.toml updated to the new field names and the zero-address liquidator placeholder is removed (validation now rejects it). Closes #75 #76 #77 #78 #79 #80 #81
This was referenced Apr 23, 2026
…oader # Conflicts: # Cargo.lock # crates/charon-core/Cargo.toml # crates/charon-core/src/lib.rs
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #5
Loads
config/default.toml, substitutes${ENV_VAR}placeholders from the environment at load time, and parses into strongly-typed structs.Config— top-level (bot,chain,protocol,flashloan,liquidator)BotConfig—min_profit_usd,max_gas_gwei, scan intervalChainConfig,ProtocolConfig,FlashLoanConfig,LiquidatorConfig.env.exampledocuments the expected variables; real secrets never touch TOMLDefault v0.1 config targets Venus on BNB Chain (single chain, single protocol, single flash-loan source).
Depends on #4 (
feat/03-lending-protocol-trait).