Skip to content

Commit

Permalink
feat: clean 🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Jul 3, 2023
1 parent 1c359bf commit d4552b3
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 1,118 deletions.
2 changes: 0 additions & 2 deletions src/account.cairo

This file was deleted.

21 changes: 0 additions & 21 deletions src/account/interface.cairo

This file was deleted.

9 changes: 6 additions & 3 deletions src/entry/entry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ mod Entry {
index = index + 1;
}
}

// @notice returns the median value from an entries array
// @param entries_len: length of entries array
// @param entries: pointer to first Entry in array
// @param entries: array of entries to aggregate
// @return value: the median value from the array of entries

fn entries_median<
T,
impl TCopy: Copy<T>,
Expand All @@ -138,6 +137,10 @@ mod Entry {
(median_entry_1 + median_entry_2) / (2.into())
}
}

// @notice Returns the mean value from an entries array
// @param entries: entries array to aggregate
// @return value: the mean value from the array of entries
fn entries_mean<T, impl THasPrice: HasPrice<T>, impl TCopy: Copy<T>, impl TDrop: Drop<T>>(
entries: @Array<T>
) -> u256 {
Expand Down
6 changes: 4 additions & 2 deletions src/entry/structs.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ struct FutureEntryStorage {
///
/// * `Spot` - Spot price
/// * `Future` - Future price
/// * `Generic` - Generic price
/// * `Option` - Option price
#[derive(Drop, Copy, Serde)]
enum DataType {
SpotEntry: felt252,
Expand All @@ -98,7 +98,7 @@ enum PossibleEntryStorage {
}

#[derive(Drop, Copy, Serde)]
enum simpleDataType {
enum SimpleDataType {
SpotEntry: (),
FutureEntry: (),
// OptionEntry: (),
Expand Down Expand Up @@ -142,6 +142,7 @@ struct Checkpoint {
aggregation_mode: AggregationMode,
num_sources_aggregated: u32,
}

#[derive(Serde, Drop, Copy)]
struct PragmaPricesResponse {
price: u256,
Expand All @@ -154,5 +155,6 @@ struct PragmaPricesResponse {
#[derive(Serde, Drop, Copy)]
enum AggregationMode {
Median: (),
// Mean: (),
Error: (),
}
1 change: 0 additions & 1 deletion src/introspection.cairo

This file was deleted.

45 changes: 0 additions & 45 deletions src/introspection/erc165.cairo

This file was deleted.

2 changes: 0 additions & 2 deletions src/operations/tests.cairo

This file was deleted.

15 changes: 13 additions & 2 deletions src/operations/time_series/metrics.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ use array::{ArrayTrait, SpanTrait};
use traits::{Into, TryInto};
use option::OptionTrait;
use box::BoxTrait;

const ONE_YEAR_IN_SECONDS: u128 = 31536000_u128;

#[derive(Copy, Drop)]
enum Operations {
SUBSTRACTION: (),
MULTIPLICATION: (),
}


/// Returns an array of `u128` from `TickElem` array
fn extract_value(tick_arr: Span<TickElem>) -> Array<u128> {
let mut output = ArrayTrait::<u128>::new();
let mut cur_idx = 0;
Expand All @@ -28,6 +30,7 @@ fn extract_value(tick_arr: Span<TickElem>) -> Array<u128> {
output
}

/// Sum the values of an array of `TickElem`
fn sum_tick_array(tick_arr: Span<TickElem>) -> u128 {
let mut output = 0;
let mut cur_idx = 0;
Expand All @@ -42,6 +45,7 @@ fn sum_tick_array(tick_arr: Span<TickElem>) -> u128 {
output
}

/// Sum the elements of an array of `u128`
fn sum_array(tick_arr: Span<u128>) -> u128 {
let mut output = 0;
let mut cur_idx = 0;
Expand All @@ -56,14 +60,15 @@ fn sum_array(tick_arr: Span<u128>) -> u128 {
output
}


/// Computes the mean of a `TickElem` array
fn mean(tick_arr: Span<TickElem>) -> u128 {
let sum_ = sum_tick_array(tick_arr);
let felt_count: felt252 = tick_arr.len().into();
let count: u128 = felt_count.try_into().unwrap();
sum_ / count
}

/// Computes the variance of a `TickElem` array
fn variance(tick_arr: Span<TickElem>) -> u128 {
let arr_ = extract_value(tick_arr);
let arr_len = arr_.len();
Expand All @@ -81,13 +86,16 @@ fn variance(tick_arr: Span<TickElem>) -> u128 {
return variance_;
}

/// Computes the standard deviation of a `TickElem` array
/// Calls `variance` and computes the squared root
fn standard_deviation(arr: Span<TickElem>) -> Fixed {
let variance_ = variance(arr);
let fixed_variance_ = FixedTrait::new(variance_, false);
let std = sqrt(fixed_variance_);
std
}

/// Compute the volatility of a `TickElem` array
fn volatility(arr: Span<TickElem>) -> Fixed {
let _volatility_sum = _sum_volatility(arr);
let arr_len = arr.len();
Expand Down Expand Up @@ -127,6 +135,8 @@ fn _sum_volatility(arr: Span<TickElem>) -> Fixed {
sum
}

/// Computes a result array given two arrays and one operation
/// e.g : [1, 2, 3] + [1, 2, 3] = [2, 4, 6]
fn pairwise_1D(operation: Operations, x_len: u32, x: Span<u128>, y: Span<u128>) -> Span<u128> {
let mut cur_idx: u32 = 0;
let mut output = ArrayTrait::<u128>::new();
Expand Down Expand Up @@ -157,6 +167,7 @@ fn pairwise_1D(operation: Operations, x_len: u32, x: Span<u128>, y: Span<u128>)
output.span()
}

/// Fills an array with one `value`
fn fill_1d(arr_len: u32, value: u128) -> Array<u128> {
let mut cur_idx = 0;
let mut output = ArrayTrait::new();
Expand Down
2 changes: 2 additions & 0 deletions src/operations/time_series/scaler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ fn calculate_slope(x1: i129, x2: i129, y1: i129, y2: i129) -> i129 {
(y2 - y1) / (x2 - x1)
}

/// Scales an array of `TickElem` by returning an array of `TickElem` with `num_intervals` elements
/// Takes a start and end tick as an input.
fn scale_data(
start_tick: u64, end_tick: u64, tick_array: Span<TickElem>, num_intervals: u32
) -> Array<TickElem> {
Expand Down
2 changes: 1 addition & 1 deletion src/operations/time_series/structs.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use array::ArrayTrait;
use integer::u32;

#[derive(Drop, Copy)]
struct TickElem {
tick: u64,
value: u128
}


struct List {
length: u32,
size: u32,
Expand Down
Loading

0 comments on commit d4552b3

Please sign in to comment.