We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f8970d6 commit 4dffeb3Copy full SHA for 4dffeb3
pyth-sdk/src/price.rs
@@ -96,17 +96,20 @@ impl Price {
96
/// basket_price.price, basket_price.conf, basket_price.expo);
97
/// ```
98
pub fn price_basket(amounts: &[(Price, i64, i32)], result_expo: i32) -> Option<Price> {
99
- assert!(amounts.len() > 0);
+ if amounts.is_empty() {
100
+ return None;
101
+ }
102
+
103
let mut res = Price {
104
price: 0,
105
conf: 0,
106
expo: result_expo,
107
};
- for i in 0..amounts.len() {
108
+ for amount in amounts {
109
res = res.add(
- &amounts[i]
110
+ &amount
111
.0
- .cmul(amounts[i].1, amounts[i].2)?
112
+ .cmul(amount.1, amount.2)?
113
.scale_to_exponent(result_expo)?,
114
)?
115
}
0 commit comments