From 4e1077cbb8f111094f74379700eb19ac0b5ac306 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Wed, 10 Apr 2024 16:25:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20forward=20buffer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deployments/mainnet/declarations.json | 2 +- src/oracle/oracle.cairo | 36 ++++++++++----------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/deployments/mainnet/declarations.json b/deployments/mainnet/declarations.json index 6887d929..bccd7f84 100644 --- a/deployments/mainnet/declarations.json +++ b/deployments/mainnet/declarations.json @@ -1,5 +1,5 @@ { - "pragma_Oracle": "0x25abeffbd83906d362db31c461a2c72b71a9b106d3c29fa054bf2d23949ae26", + "pragma_Oracle": "0x1e36e19e57bd8956e59c4ae0604de92e0bbf648efbf697467c2bfb2de92a953", "pragma_Ownable": "0x7b50a7a9bbb75d08248135003f1c87f0d44ba23018dc0ca480ac37a901531f3", "pragma_PublisherRegistry": "0x306288971002bd7906e3a607d504dfb28dcbdc7655a115984e567dce3b67e8f", "pragma_SummaryStats": "0x3b5bf1c2f918de14620b3c63e2c6543cf0a138df258bce3d03e3fb0b7d2183a", diff --git a/src/oracle/oracle.cairo b/src/oracle/oracle.cairo index 670a58b0..e878dfb3 100644 --- a/src/oracle/oracle.cairo +++ b/src/oracle/oracle.cairo @@ -77,8 +77,8 @@ trait IOracleABI { checkpoint_index: u64, aggregation_mode: AggregationMode ) -> Checkpoint; - fn get_sources_threshold(self: @TContractState,) -> u32; - fn get_admin_address(self: @TContractState,) -> ContractAddress; + fn get_sources_threshold(self: @TContractState, ) -> u32; + fn get_admin_address(self: @TContractState, ) -> ContractAddress; fn get_all_publishers(self: @TContractState, data_type: DataType) -> Span; fn get_all_sources(self: @TContractState, data_type: DataType) -> Span; fn publish_data(ref self: TContractState, new_entry: PossibleEntries); @@ -196,7 +196,7 @@ mod Oracle { use cmp::{max, min}; use option::OptionTrait; const BACKWARD_TIMESTAMP_BUFFER: u64 = 3600; // 1 hour - const FORWARD_TIMESTAMP_BUFFER: u64 = 120; // 2 minutes + const FORWARD_TIMESTAMP_BUFFER: u64 = 420; // 7 minutes #[storage] @@ -322,7 +322,7 @@ mod Oracle { #[derive(Drop, starknet::Event)] struct CheckpointSpotEntry { - pair_id: felt252, + pair_id: felt252, } #[derive(Drop, starknet::Event)] @@ -427,12 +427,12 @@ mod Oracle { // @returns a span of PossibleEntries, which can be spot entries, future entries, generic entries ... // @returns the last updated timestamp fn get_data_entries_for_sources( - self: @ContractState, data_type: DataType, sources: Span, + self: @ContractState, data_type: DataType, sources: Span, ) -> (Span, u64) { if (sources.len() == 0) { let all_sources = IOracleABI::get_all_sources(self, data_type); let last_updated_timestamp = get_latest_entry_timestamp( - self, data_type, all_sources, + self, data_type, all_sources, ); let current_timestamp: u64 = get_block_timestamp(); let conservative_current_timestamp = min(last_updated_timestamp, current_timestamp); @@ -480,7 +480,7 @@ mod Oracle { self: @ContractState, data_type: DataType, sources: Span ) -> PragmaPricesResponse { let prices_response: PragmaPricesResponse = IOracleABI::get_data_for_sources( - self, data_type, AggregationMode::Median(()), sources, + self, data_type, AggregationMode::Median(()), sources, ); prices_response } @@ -971,10 +971,7 @@ mod Oracle { SpotEntry { base: BaseEntry { timestamp: _entry.timestamp, source: source, publisher: publisher - }, - pair_id: pair_id, - price: _entry.price, - volume: _entry.volume + }, pair_id: pair_id, price: _entry.price, volume: _entry.volume } ) }, @@ -998,9 +995,7 @@ mod Oracle { GenericEntry { base: BaseEntry { timestamp: _entry.timestamp, source: source, publisher: publisher - }, - key: key, - value: _entry.price + }, key: key, value: _entry.price } ) } @@ -1048,10 +1043,7 @@ mod Oracle { SpotEntry { base: BaseEntry { timestamp: last_updated_timestamp, source: source, publisher: 0 - }, - pair_id: pair_id, - price: median, - volume: median_volume + }, pair_id: pair_id, price: median, volume: median_volume } ); }, @@ -1128,9 +1120,7 @@ mod Oracle { GenericEntry { base: BaseEntry { timestamp: last_updated_timestamp, source: source, publisher: 0 - }, - key: key, - value: median + }, key: key, value: median } ); } @@ -2050,7 +2040,7 @@ mod Oracle { // @param a span of sources // @returns the latest timestamp fn get_latest_entry_timestamp( - self: @ContractState, data_type: DataType, sources: Span, + self: @ContractState, data_type: DataType, sources: Span, ) -> u64 { let mut cur_idx = 0; let mut latest_timestamp = 0; @@ -2388,7 +2378,7 @@ mod Oracle { // @param new_entry : an entry (spot entry, future entry, ... ) // @param last_entry : an entry (with the same nature as new_entry) fn validate_data_timestamp, impl TDrop: Drop>( - ref self: ContractState, new_entry: PossibleEntries, last_entry: T, + ref self: ContractState, new_entry: PossibleEntries, last_entry: T, ) { let current_timestamp = get_block_timestamp(); match new_entry {