Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: amount in usd bug #30

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 11 additions & 9 deletions crates/routing-engine/src/routing_engine.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::cmp;
use std::collections::HashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down