diff --git a/config.yaml b/config.yaml index 8db2d0b..1ed7b26 100644 --- a/config.yaml +++ b/config.yaml @@ -22,15 +22,15 @@ tokens: "42161": is_enabled: true decimals: 6 - address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" + address: "0xaf88d065e77c8cc2239327c5edb3a432268e5831" "10": is_enabled: true decimals: 6 - address: "0x7F5c764cBc14f9669B88837ca1490cCa17c31607" + address: "0x7f5c764cbc14f9669b88837ca1490cca17c31607" "8453": is_enabled: true decimals: 6 - address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" + address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" - symbol: USDT is_enabled: true coingecko_symbol: tether @@ -42,11 +42,11 @@ tokens: "10": is_enabled: true decimals: 6 - address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58" + address: "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58" "8453": is_enabled: true decimals: 6 - address: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2" + address: "0xfde4c96c8593536e31f229ea8f37b2ada2699bb2" - symbol: ETH is_enabled: true coingecko_symbol: ethereum diff --git a/crates/routing-engine/src/routing_engine.rs b/crates/routing-engine/src/routing_engine.rs index bf8df3a..712ea71 100644 --- a/crates/routing-engine/src/routing_engine.rs +++ b/crates/routing-engine/src/routing_engine.rs @@ -1,3 +1,4 @@ +use std::cmp; use std::collections::HashMap; use std::sync::Arc; @@ -153,9 +154,10 @@ impl RoutingEngine { let mut assets_sorted_by_bridging_cost: Vec<(TokenWithBalance, f64)> = stream::iter(assets.into_iter()) .then(|balance| async move { + let balance_taken = cmp::min_by(to_value_usd, balance.amount_in_usd, |a, b| a.partial_cmp(b).unwrap_or_else(|| cmp::Ordering::Less)); let fee_cost = self .estimate_bridging_cost( - balance.amount_in_usd, + balance_taken, PathQuery( balance.chain_id, to_chain, @@ -193,10 +195,10 @@ impl RoutingEngine { if total_amount_needed <= 0.0 { break; } - let amount_to_take = if balance.amount >= total_amount_needed { + let amount_to_take = if balance.amount_in_usd >= total_amount_needed { total_amount_needed } else { - balance.amount + balance.amount_in_usd }; total_amount_needed -= amount_to_take; total_cost += fee; @@ -359,7 +361,7 @@ mod tests { DataPoint { x: 1.0, y: 1.0 }, DataPoint { x: 2.0, y: 2.0 }, ]) - .unwrap(); + .unwrap(); let serialized_estimator = serde_json::to_string(&dummy_estimator)?; // Create a cache with a dummy bucket @@ -374,8 +376,8 @@ mod tests { "test".to_string(), true, ) - .await - .unwrap(); + .await + .unwrap(); let aas_client = Arc::new(AccountAggregationService::new( user_db_provider.clone(), @@ -424,8 +426,8 @@ mod tests { "test".to_string(), true, ) - .await - .unwrap(); + .await + .unwrap(); let aas_client = Arc::new(AccountAggregationService::new( user_db_provider.clone(), user_db_provider.clone(), @@ -460,7 +462,7 @@ mod tests { DataPoint { x: 1.0, y: 1.0 }, DataPoint { x: 2.0, y: 2.0 }, ]) - .unwrap(); + .unwrap(); let serialized_estimator = serde_json::to_string(&dummy_estimator)?; // Create a cache with a dummy bucket let key1 = buckets[0].get_hash().to_string();