Skip to content

Commit

Permalink
🔧 forward buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Apr 10, 2024
1 parent e5b2ba7 commit 4e1077c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion deployments/mainnet/declarations.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pragma_Oracle": "0x25abeffbd83906d362db31c461a2c72b71a9b106d3c29fa054bf2d23949ae26",
"pragma_Oracle": "0x1e36e19e57bd8956e59c4ae0604de92e0bbf648efbf697467c2bfb2de92a953",
"pragma_Ownable": "0x7b50a7a9bbb75d08248135003f1c87f0d44ba23018dc0ca480ac37a901531f3",
"pragma_PublisherRegistry": "0x306288971002bd7906e3a607d504dfb28dcbdc7655a115984e567dce3b67e8f",
"pragma_SummaryStats": "0x3b5bf1c2f918de14620b3c63e2c6543cf0a138df258bce3d03e3fb0b7d2183a",
Expand Down
36 changes: 13 additions & 23 deletions src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ trait IOracleABI<TContractState> {
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<felt252>;
fn get_all_sources(self: @TContractState, data_type: DataType) -> Span<felt252>;
fn publish_data(ref self: TContractState, new_entry: PossibleEntries);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -322,7 +322,7 @@ mod Oracle {

#[derive(Drop, starknet::Event)]
struct CheckpointSpotEntry {
pair_id: felt252,
pair_id: felt252,
}

#[derive(Drop, starknet::Event)]
Expand Down Expand Up @@ -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<felt252>,
self: @ContractState, data_type: DataType, sources: Span<felt252>,
) -> (Span<PossibleEntries>, 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);
Expand Down Expand Up @@ -480,7 +480,7 @@ mod Oracle {
self: @ContractState, data_type: DataType, sources: Span<felt252>
) -> PragmaPricesResponse {
let prices_response: PragmaPricesResponse = IOracleABI::get_data_for_sources(
self, data_type, AggregationMode::Median(()), sources,
self, data_type, AggregationMode::Median(()), sources,
);
prices_response
}
Expand Down Expand Up @@ -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
}
)
},
Expand All @@ -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
}
)
}
Expand Down Expand Up @@ -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
}
);
},
Expand Down Expand Up @@ -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
}
);
}
Expand Down Expand Up @@ -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<felt252>,
self: @ContractState, data_type: DataType, sources: Span<felt252>,
) -> u64 {
let mut cur_idx = 0;
let mut latest_timestamp = 0;
Expand Down Expand Up @@ -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<T, impl THasBaseEntry: HasBaseEntry<T>, impl TDrop: Drop<T>>(
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 {
Expand Down

0 comments on commit 4e1077c

Please sign in to comment.