Skip to content

Commit

Permalink
refine a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Jul 24, 2024
1 parent 3d46e01 commit eab4172
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/ain-ocean/src/indexer/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl Index for SetOracleData {
token_prices: self.token_prices,
};
let feeds = map_price_feeds(&set_oracle_data, context)?;
let mut pairs: Vec<(String, String, Txid)> = Vec::new();
let mut pairs = Vec::new();
for feed in &feeds {
pairs.push((feed.token.clone(), feed.currency.clone(), feed.oracle_id));
services.oracle_price_feed.by_key.put(&feed.key, &feed.id)?;
Expand All @@ -401,8 +401,7 @@ impl Index for SetOracleData {
OracleIntervalSeconds::OneDay,
];
for (token, currency, oracle) in pairs.iter() {
let oracle_token_id: (String, String, Txid) =
(token.to_string(), currency.to_string(), *oracle);
let oracle_token_id = (token.to_string(), currency.to_string(), *oracle);
let oracle_entries = services
.oracle_token_currency
.by_key
Expand Down Expand Up @@ -461,8 +460,7 @@ impl Index for SetOracleData {
if (oracle_price.time - context.block.time as i32) < 3600 {
count += 1;
weightage += oracle.weightage as i32;
let amount = oracle_price.amount;
let weighted_amount = amount * oracle.weightage as i64;
let weighted_amount = oracle_price.amount * oracle.weightage as i64;
total += Decimal::from(weighted_amount);
}
}
Expand All @@ -473,11 +471,10 @@ impl Index for SetOracleData {
}
}

let result = total
let amount = total
.checked_div(Decimal::from(weightage))
.unwrap_or(dec!(1));

let amount = format!("{:.8}", result);
let aggregated_value = Some(OraclePriceAggregated {
id: (
token.to_string(),
Expand All @@ -493,7 +490,7 @@ impl Index for SetOracleData {
token: token.to_string(),
currency: currency.to_string(),
aggregated: OraclePriceAggregatedAggregated {
amount,
amount: format!("{:.8}", amount),
weightage,
oracles: OraclePriceAggregatedAggregatedOracles {
active: count,
Expand Down

0 comments on commit eab4172

Please sign in to comment.