Skip to content

Commit

Permalink
wip: add readconfig state
Browse files Browse the repository at this point in the history
  • Loading branch information
willyrgf committed Dec 17, 2023
1 parent 95158a5 commit b9d94e7
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ members = [
"mfm_cli",
"mfm_machine",
"mfm_machine_derive",
"mfm_core",
]
9 changes: 9 additions & 0 deletions mfm_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "mfm_core"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = "1.0.193"
88 changes: 88 additions & 0 deletions mfm_core/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum Kind {
EVM,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Network {
pub name: String,
pub kind: Kind,
pub symbol: String,
pub decimals: Option<u8>,
pub chain_id: u32,
pub node_url: String,
pub node_url_failover: Option<String>,
pub blockexplorer_url: Option<String>,
pub min_balance_coin: f64,
pub wrapped_asset: Option<Token>,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Networks(HashMap<String, Network>);
impl Networks {
pub fn get(&self, key: &str) -> Option<&Network> {
self.0.get(key)
}
pub fn hashmap(&self) -> &HashMap<String, Network> {
&self.0
}
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct Dex {
pub name: String,
pub kind: Kind,
pub router_address: String,
pub factory_address: String,
pub network_id: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct Dexes(HashMap<String, Dex>);
impl Dexes {
pub fn hashmap(&self) -> &HashMap<String, Dex> {
&self.0
}
pub fn get(&self, key: &str) -> Option<&Dex> {
self.0.get(key)
}
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct TokenNetwork {
pub(crate) name: String,
pub(crate) network_id: String,
pub(crate) address: String,
pub(crate) slippage: f64,
pub(crate) path_asset: String,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct TokenNetworks(HashMap<String, TokenNetwork>);

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Token {
pub(crate) kind: String,
pub(crate) networks: TokenNetworks,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Tokens(HashMap<String, Token>);
impl Tokens {
pub fn hashmap(&self) -> &HashMap<String, Token> {
&self.0
}

pub fn get(&self, key: &str) -> Option<&Token> {
self.0.get(key)
}
}

pub struct Config {
pub networks: Networks,
pub dexes: Dexes,
pub tokens: Tokens,
}
4 changes: 4 additions & 0 deletions mfm_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod config;
pub mod states;
pub mod tasks;

5 changes: 5 additions & 0 deletions mfm_core/src/states/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::config::Config;

pub struct ReadConfig {
pub config: Config,
}
1 change: 1 addition & 0 deletions mfm_core/src/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit b9d94e7

Please sign in to comment.