kabu_types_entities/strategy_config.rs
1use alloy_primitives::Address;
2use serde::de::DeserializeOwned;
3use std::path::PathBuf;
4use thiserror::Error;
5use tokio::fs;
6
7#[derive(Debug, Error)]
8pub enum LoadConfigError {
9 #[error("IO error: {0}")]
10 IoError(#[from] std::io::Error),
11 #[error("TOML error: {0}")]
12 TomlError(#[from] toml::de::Error),
13}
14
15pub trait StrategyConfig {
16 /// If None is returned, the strategy will use a random signer in the swap router.
17 fn eoa(&self) -> Option<Address>;
18}
19
20pub async fn load_from_file<C: DeserializeOwned>(file_path: PathBuf) -> Result<C, LoadConfigError> {
21 let contents = fs::read_to_string(file_path).await?;
22 let config: C = toml::from_str(&contents)?;
23 Ok(config)
24}