keep-starknet-strange / satoru

Synthetics platform for Starknet, inspired by GMX v2 design.
https://book.satoru.run/
MIT License
110 stars 73 forks source link

dev: refactoring OracleUtils library functions #512

Closed Cevedale closed 12 months ago

Cevedale commented 12 months ago

/// OracleUtils Library

/// Validates whether a block number is within a specified range. fn validate_block_number_within_range( min_oracle_block_numbers: Array<u128, max_oracle_block_numbers: Array<u128, block_number: u128 ) { // Initialize a variable indicating whether the block number is within the range. let is_within_range: bool = false;

// Check if the block is within the range.
for i in 0..min_oracle_block_numbers.len() {
    if block_number >= min_oracle_block_numbers[i] && block_number <= max_oracle_block_numbers[i] {
        is_within_range = true;
        break;
    }
}

// If the block is not within the range, you can raise an error or take appropriate actions.
if !is_within_range {
    // Raise an error or perform necessary actions.
}

}

/// Validates whether a block number is within a specified range and returns true or false. fn is_block_number_within_range( min_oracle_block_numbers: Array<u128, max_oracle_block_numbers: Array<u128, block_number: u128 ) -> bool { // Initialize a variable indicating whether the block number is within the range. let is_within_range: bool = false;

// Check if the block is within the range.
for i in 0..min_oracle_block_numbers.len() {
    if block_number >= min_oracle_block_numbers[i] && block_number <= max_oracle_block_numbers[i] {
        is_within_range = true;
        break;
    }
}

return is_within_range;

}

/// Get the uncompacted price at the specified index. fn get_uncompacted_price(compacted_prices: Array<u128, index: u128) -> u128 { // Ensure the index is valid. assert(index < compacted_prices.len(), "Invalid index");

// Return the uncompacted price at the specified index.
return compacted_prices[index];

}

/// Get the uncompacted decimal at the specified index. fn get_uncompacted_decimal(compacted_decimals: Array<u128, index: u128) -> u128 { // Ensure the index is valid. assert(index < compacted_decimals.len(), "Invalid index");

// Return the uncompacted decimal at the specified index.
return compacted_decimals[index];

}

VictorONN commented 12 months ago

Hello, I wanna take this

Sk8erboi84 commented 12 months ago

Someone is already working on that issue

Cevedale commented 12 months ago

yeah, they told me yesterday