Skip to content

Commit

Permalink
feat(oracle): change generic entry value type to u256 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt authored Aug 2, 2024
1 parent 00b9520 commit 9a36381
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/entry/structs.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct SpotEntry {
struct GenericEntry {
base: BaseEntry,
key: felt252,
value: u128,
value: u256,
}

#[derive(Copy, Drop, PartialOrd, Serde)]
Expand Down Expand Up @@ -245,7 +245,7 @@ impl FHasPriceImpl of HasPrice<FutureEntry> {

impl GHasPriceImpl of HasPrice<GenericEntry> {
fn get_price(self: @GenericEntry) -> u128 {
(*self).value
(*self).value.try_into().unwrap()
}
}
impl ResponseHasPriceImpl of HasPrice<PragmaPricesResponse> {
Expand Down
6 changes: 3 additions & 3 deletions src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ mod Oracle {
timestamp: _entry.timestamp, source: source, publisher: publisher
},
key: key,
value: _entry.price
value: _entry.price.into()
}
)
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ mod Oracle {
timestamp: last_updated_timestamp, source: source, publisher: 0
},
key: key,
value: median
value: median.into()
}
);
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ mod Oracle {
let element = EntryStorage {
timestamp: generic_entry.base.timestamp,
volume: 0,
price: generic_entry.value,
price: generic_entry.value.try_into().unwrap(),
};
set_entry_storage(
ref self,
Expand Down
4 changes: 3 additions & 1 deletion src/tests/test_oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ fn test_get_data() {
let entry = oracle.get_data(DataType::FutureEntry((5, 11111110)), AggregationMode::Median(()));
assert(entry.price == (5 * 1000000), 'wrong price');
}

fn data_treatment(entry: PossibleEntries) -> (u128, u64, u128) {
match entry {
PossibleEntries::Spot(entry) => {
Expand All @@ -456,10 +457,11 @@ fn data_treatment(entry: PossibleEntries) -> (u128, u64, u128) {
(entry.price, entry.base.timestamp, entry.volume)
},
PossibleEntries::Generic(entry) => {
(entry.value, entry.base.timestamp, 0)
(entry.value.try_into().unwrap(), entry.base.timestamp, 0)
}
}
}

#[test]
#[available_gas(10000000000)]
fn test_get_admin_address() {
Expand Down

0 comments on commit 9a36381

Please sign in to comment.