Skip to content

Commit d422a1b

Browse files
committed
Ocean model weightage as u32
1 parent 5ec692f commit d422a1b

5 files changed

Lines changed: 13 additions & 18 deletions

File tree

lib/ain-dftx/src/types/oracles.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bitcoin::{hash_types::Txid, io, ScriptBuf};
44
use super::{
55
common::CompactVec,
66
price::{CurrencyPair, TokenPrice},
7+
Weightage,
78
};
89

910
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
@@ -21,14 +22,14 @@ pub struct RemoveOracle {
2122
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
2223
pub struct AppointOracle {
2324
pub script: ScriptBuf,
24-
pub weightage: u8,
25+
pub weightage: Weightage,
2526
pub price_feeds: CompactVec<CurrencyPair>,
2627
}
2728

2829
#[derive(ConsensusEncoding, Debug, PartialEq, Eq)]
2930
pub struct UpdateOracle {
3031
pub oracle_id: Txid,
3132
pub script: ScriptBuf,
32-
pub weightage: u8,
33+
pub weightage: Weightage,
3334
pub price_feeds: CompactVec<CurrencyPair>,
3435
}

lib/ain-ocean/src/api/prices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct OraclePriceAggregatedResponse {
4646
#[serde(rename_all = "camelCase")]
4747
pub struct OraclePriceAggregatedAggregatedResponse {
4848
pub amount: String,
49-
pub weightage: Weightage,
49+
pub weightage: u32,
5050
pub oracles: OraclePriceActiveNextOracles,
5151
}
5252

lib/ain-ocean/src/indexer/oracle.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn map_price_aggregated(
402402

403403
let mut aggregated_total = Decimal::zero();
404404
let mut aggregated_count = 0;
405-
let mut aggregated_weightage = 0u8;
405+
let mut aggregated_weightage = 0u32;
406406

407407
let oracles_len = oracles.len();
408408
for oracle in oracles {
@@ -424,12 +424,7 @@ fn map_price_aggregated(
424424
let time_diff = Decimal::from(feed.time) - Decimal::from(context.block.time);
425425
if Decimal::abs(&time_diff) < dec!(3600) {
426426
aggregated_count += 1;
427-
aggregated_weightage =
428-
aggregated_weightage
429-
.checked_add(oracle.weightage)
430-
.context(OtherSnafu {
431-
msg: "Error adding oracle weightage",
432-
})?;
427+
aggregated_weightage += oracle.weightage as u32;
433428
log::trace!(
434429
"SetOracleData weightage: {:?} * oracle_price.amount: {:?}",
435430
aggregated_weightage,
@@ -785,8 +780,8 @@ pub fn invalidate_oracle_interval(
785780
aggregated: OraclePriceAggregatedIntervalAggregated {
786781
amount: aggregated_amount.to_string(),
787782
weightage: aggregated_weightage
788-
.to_u8()
789-
.context(ToPrimitiveSnafu { msg: "to_u8" })?,
783+
.to_u32()
784+
.context(ToPrimitiveSnafu { msg: "to_u32" })?,
790785
count,
791786
oracles: OraclePriceAggregatedIntervalAggregatedOracles {
792787
active: aggregated_active
@@ -847,8 +842,8 @@ fn forward_aggregate(
847842
aggregated: OraclePriceAggregatedIntervalAggregated {
848843
amount: aggregated_amount.to_string(),
849844
weightage: aggregated_weightage
850-
.to_u8()
851-
.context(ToPrimitiveSnafu { msg: "to_u8" })?,
845+
.to_u32()
846+
.context(ToPrimitiveSnafu { msg: "to_u32" })?,
852847
count,
853848
oracles: OraclePriceAggregatedIntervalAggregatedOracles {
854849
active: aggregated_active

lib/ain-ocean/src/model/oracle_price_active.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use ain_dftx::Weightage;
21
use rust_decimal::Decimal;
32
use serde::{Deserialize, Serialize};
43

@@ -23,7 +22,7 @@ pub struct OraclePriceActive {
2322
pub struct OraclePriceActiveNext {
2423
#[serde(with = "rust_decimal::serde::str")]
2524
pub amount: Decimal,
26-
pub weightage: Weightage,
25+
pub weightage: u32,
2726
pub oracles: OraclePriceActiveNextOracles,
2827
}
2928

lib/ain-ocean/src/model/oracle_price_aggregated_interval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ain_dftx::{Currency, Token, Weightage};
1+
use ain_dftx::{Currency, Token};
22
use serde::{Deserialize, Serialize};
33

44
use super::BlockContext;
@@ -32,7 +32,7 @@ pub struct OraclePriceAggregatedInterval {
3232
#[serde(rename_all = "camelCase")]
3333
pub struct OraclePriceAggregatedIntervalAggregated {
3434
pub amount: String,
35-
pub weightage: Weightage,
35+
pub weightage: u32,
3636
pub count: i32,
3737
pub oracles: OraclePriceAggregatedIntervalAggregatedOracles,
3838
}

0 commit comments

Comments
 (0)