diff --git a/bin/reflux/src/main.rs b/bin/reflux/src/main.rs index a3dbd5d..2292eda 100644 --- a/bin/reflux/src/main.rs +++ b/bin/reflux/src/main.rs @@ -101,8 +101,12 @@ async fn run_solver(config: Config) { let redis_client = RedisClient::build(&config.infra.redis_url) .await .expect("Failed to instantiate redis client"); - let routing_engine = - Arc::new(RoutingEngine::new(account_service.clone(), buckets, redis_client.clone())); + let routing_engine = Arc::new(RoutingEngine::new( + account_service.clone(), + buckets, + redis_client.clone(), + config.solver_config, + )); // Subscribe to cache update messages let cache_update_topic = config.indexer_config.indexer_update_topic.clone(); diff --git a/crates/account-aggregation/src/service.rs b/crates/account-aggregation/src/service.rs index c777911..1aa1369 100644 --- a/crates/account-aggregation/src/service.rs +++ b/crates/account-aggregation/src/service.rs @@ -1,4 +1,3 @@ -use log::debug; use std::sync::Arc; use thiserror::Error; @@ -230,7 +229,6 @@ impl AccountAggregationService { let mut balances = Vec::new(); let networks = self.networks.clone(); - debug!("Networks: {:?}", networks); // todo: parallelize this for user in accounts.iter() { @@ -239,14 +237,12 @@ impl AccountAggregationService { "{}/v1/{}/address/{}/balances_v2/?key={}", self.covalent_base_url, network, user, self.covalent_api_key ); - debug!("Requesting: {}", url); let response = self.client.get(&url).send().await?; let api_response: ApiResponse = response.json().await?; let user_balances = extract_balance_data(api_response)?; balances.extend(user_balances); } } - println!("{:?}", balances); Ok(balances) } diff --git a/crates/config/src/config.rs b/crates/config/src/config.rs index 54a55cd..51b02b4 100644 --- a/crates/config/src/config.rs +++ b/crates/config/src/config.rs @@ -4,8 +4,8 @@ use std::ops::Deref; use derive_more::{Display, From, Into}; use serde::Deserialize; -use serde_valid::{UniqueItemsError, Validate, ValidateUniqueItems}; use serde_valid::yaml::FromYamlStr; +use serde_valid::{UniqueItemsError, Validate, ValidateUniqueItems}; // Config Type #[derive(Debug)] @@ -29,6 +29,8 @@ pub struct Config { pub server: ServerConfig, // Configuration for the indexer pub indexer_config: IndexerConfig, + // Configuration for the solver + pub solver_config: SolverConfig, } impl Config { @@ -126,6 +128,7 @@ impl Config { infra: raw_config.infra, server: raw_config.server, indexer_config: raw_config.indexer_config, + solver_config: raw_config.solver_config, }) } } @@ -228,6 +231,7 @@ pub struct RawConfig { pub infra: InfraConfig, pub server: ServerConfig, pub indexer_config: IndexerConfig, + pub solver_config: SolverConfig, } #[derive(Debug, Deserialize, Validate, PartialOrd, Clone)] @@ -429,6 +433,14 @@ pub struct IndexerConfig { pub points_per_bucket: u64, } +#[derive(Debug, Deserialize, Validate)] +pub struct SolverConfig { + #[validate(minimum = 1.0)] + pub x_value: f64, + #[validate(minimum = 1.0)] + pub y_value: f64, +} + pub fn get_sample_config() -> Config { Config::from_file("../../config.yaml.example").unwrap() } diff --git a/crates/routing-engine/src/engine.rs b/crates/routing-engine/src/engine.rs index bdf3eff..72ab416 100644 --- a/crates/routing-engine/src/engine.rs +++ b/crates/routing-engine/src/engine.rs @@ -10,7 +10,7 @@ use tokio::sync::RwLock; use account_aggregation::service::AccountAggregationService; use account_aggregation::types::Balance; -use config::config::BucketConfig; +use config::{config::BucketConfig, SolverConfig}; use storage::{RedisClient, RedisClientError}; use crate::estimator::{Estimator, LinearRegressionEstimator}; @@ -51,12 +51,13 @@ pub enum RoutingEngineError { /// Routing Engine /// This struct is responsible for calculating the best cost path for a user -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct RoutingEngine { buckets: Vec, aas_client: AccountAggregationService, cache: Arc>>, // (hash(bucket), hash(estimator_value) redis_client: RedisClient, + estimates: SolverConfig, } impl RoutingEngine { @@ -64,10 +65,11 @@ impl RoutingEngine { aas_client: AccountAggregationService, buckets: Vec, redis_client: RedisClient, + solver_config: SolverConfig, ) -> Self { let cache = Arc::new(RwLock::new(HashMap::new())); - Self { aas_client, cache, buckets, redis_client } + Self { aas_client, cache, buckets, redis_client, estimates: solver_config } } pub async fn refresh_cache(&self) { @@ -110,8 +112,8 @@ impl RoutingEngine { debug!("Direct assets: {:?}", direct_assets); // Sort direct assets by A^x / C^y, here x=2 and y=1 - let x = 2.0; - let y = 1.0; + let x = self.estimates.x_value; + let y = self.estimates.y_value; let mut sorted_assets: Vec<(&Balance, f64)> = stream::iter(direct_assets.into_iter()) .then(|balance| async move { let fee_cost = self @@ -283,7 +285,7 @@ mod tests { use tokio::sync::RwLock; use account_aggregation::service::AccountAggregationService; - use config::BucketConfig; + use config::{BucketConfig, SolverConfig}; use storage::mongodb_client::MongoDBClient; use crate::engine::PathQuery; @@ -350,11 +352,16 @@ mod tests { ); let redis_client = storage::RedisClient::build(&"redis://localhost:6379".to_string()).await.unwrap(); + let estimates = SolverConfig { + x_value: 2.0, + y_value: 1.0, + }; let routing_engine = RoutingEngine { aas_client, buckets, cache: Arc::new(RwLock::new(cache)), redis_client, + estimates, }; // Define the target amount and path query @@ -429,11 +436,16 @@ mod tests { let redis_client = storage::RedisClient::build(&"redis://localhost:6379".to_string()).await.unwrap(); + let estimates = SolverConfig { + x_value: 2.0, + y_value: 1.0, + }; let routing_engine = RoutingEngine { aas_client, buckets, cache: Arc::new(RwLock::new(cache)), redis_client, + estimates, }; // should have USDT in bsc-mainnet > $0.5