Skip to content

Commit

Permalink
Merge pull request #52 from butaneprotocol/weight-reliability
Browse files Browse the repository at this point in the history
fix: weight reliability by unit
  • Loading branch information
SupernaviX authored Mar 3, 2025
2 parents fa65492 + 7a38264 commit ce3e659
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/price_aggregator/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ impl<'a> TokenPriceConverter<'a> {
continue;
};
for source in &price.sources {
value += &source.value * &conversion_factor * &source.reliability;
reliability += &source.reliability;
let normalized_reliability = &source.reliability * &conversion_factor;
value += &source.value * &conversion_factor * &normalized_reliability;
reliability += &normalized_reliability;
}
}

Expand Down Expand Up @@ -585,7 +586,7 @@ mod tests {
PriceInfo {
token: "USDT".into(),
unit: "USD".into(),
value: Decimal::new(1005, 3),
value: Decimal::new(5, 1),
reliability: Decimal::ONE,
},
),
Expand All @@ -594,7 +595,7 @@ mod tests {
PriceInfo {
token: "BTC".into(),
unit: "USD".into(),
value: Decimal::new(5000, 0),
value: Decimal::new(4995, 0),
reliability: Decimal::ONE,
},
),
Expand All @@ -603,8 +604,8 @@ mod tests {
PriceInfo {
token: "BTC".into(),
unit: "USDT".into(),
value: Decimal::new(5000, 0),
reliability: Decimal::ONE,
value: Decimal::new(10010, 0),
reliability: Decimal::TWO,
},
),
];
Expand All @@ -619,7 +620,7 @@ mod tests {

assert_eq!(
converter.value_in_usd("BTC"),
Some(decimal_rational(50125, 1))
Some(decimal_rational(5000, 0))
);
}

Expand Down

0 comments on commit ce3e659

Please sign in to comment.