From 9a36381b399a70405796d2b729c39e2a6bc64d38 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Fri, 2 Aug 2024 15:01:51 +0200 Subject: [PATCH] feat(oracle): change generic entry value type to u256 (#113) --- src/entry/structs.cairo | 4 ++-- src/oracle/oracle.cairo | 6 +++--- src/tests/test_oracle.cairo | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/entry/structs.cairo b/src/entry/structs.cairo index 8c1926a3..f4571748 100644 --- a/src/entry/structs.cairo +++ b/src/entry/structs.cairo @@ -44,7 +44,7 @@ struct SpotEntry { struct GenericEntry { base: BaseEntry, key: felt252, - value: u128, + value: u256, } #[derive(Copy, Drop, PartialOrd, Serde)] @@ -245,7 +245,7 @@ impl FHasPriceImpl of HasPrice { impl GHasPriceImpl of HasPrice { fn get_price(self: @GenericEntry) -> u128 { - (*self).value + (*self).value.try_into().unwrap() } } impl ResponseHasPriceImpl of HasPrice { diff --git a/src/oracle/oracle.cairo b/src/oracle/oracle.cairo index 54911a2c..85ea468b 100644 --- a/src/oracle/oracle.cairo +++ b/src/oracle/oracle.cairo @@ -1002,7 +1002,7 @@ mod Oracle { timestamp: _entry.timestamp, source: source, publisher: publisher }, key: key, - value: _entry.price + value: _entry.price.into() } ) } @@ -1132,7 +1132,7 @@ mod Oracle { timestamp: last_updated_timestamp, source: source, publisher: 0 }, key: key, - value: median + value: median.into() } ); } @@ -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, diff --git a/src/tests/test_oracle.cairo b/src/tests/test_oracle.cairo index 813cc14f..c4082769 100644 --- a/src/tests/test_oracle.cairo +++ b/src/tests/test_oracle.cairo @@ -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) => { @@ -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() {