Skip to content

Commit

Permalink
fix: timestamp and volume control
Browse files Browse the repository at this point in the history
  • Loading branch information
JordyRo1 committed Oct 23, 2023
1 parent ac75aab commit 3a62a7e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ mod Oracle {
const MAX_FELT: u256 =
3618502788666131213697322783095070105623107215331596699973092056135872020480; //max felt value
const TIMESTAMP_SHIFT_U32: felt252 = 0x100000000;
const TIMESTAMP_SHIFT_MASK_U32 : u128 = 0xffffffff;
const VOLUME_SHIFT_U132: felt252 = 0x1000000000000000000000000000000000;
const VOLUME_SHIFT_MASK_U100: u128 = 0xfffffffffffffffffffffffff;


//For the checkpoint storage
Expand Down Expand Up @@ -370,6 +372,9 @@ mod Oracle {

impl EntryStorePacking of StorePacking<EntryStorage, felt252> {
fn pack(value: EntryStorage) -> felt252 {
// entries verifications (no overflow)
assert(value.timestamp.into() == value.timestamp.into() & TIMESTAMP_SHIFT_MASK_U32, 'EntryStorePack:tmp too big');
assert(value.volume.into() == value.volume.into() & VOLUME_SHIFT_MASK_U100, 'EntryStorePack:volume too big');
let pack_value: felt252 = value.timestamp.into()
+ value.volume.into() * TIMESTAMP_SHIFT_U32
+ value.price.into() * VOLUME_SHIFT_U132;
Expand Down Expand Up @@ -400,12 +405,10 @@ mod Oracle {
impl CheckpointStorePacking of StorePacking<Checkpoint, felt252> {
fn pack(value: Checkpoint) -> felt252 {
let converted_agg_mode: u8 = value.aggregation_mode.into();
let pack_value: felt252 = value.timestamp.into()
value.timestamp.into()
+ value.value.into() * CHECKPOINT_TIMESTAMP_SHIFT_U32
+ converted_agg_mode.into() * CHECKPOINT_VALUE_SHIFT_U160
+ value.num_sources_aggregated.into() * CHECKPOINT_AGGREGATION_MODE_SHIFT_U172;
assert(pack_value.into() < MAX_FELT, 'CheckpointPacking:value too big');
pack_value
+ value.num_sources_aggregated.into() * CHECKPOINT_AGGREGATION_MODE_SHIFT_U172
}
fn unpack(value: felt252) -> Checkpoint {
let value: u256 = value.into();
Expand Down

0 comments on commit 3a62a7e

Please sign in to comment.