-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Updated the Pragma Caller contract (#1506)
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #NA ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - `PragmaCaller` now calls `get_data` with `AggregationMode` - Added the `SummaryStats` contract calls for Pragma computational feeds - Updated tests with `get_data` & `MockPragmaSummaryStats` contract <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1506) <!-- Reviewable:end --> --------- Co-authored-by: Oba <[email protected]> Co-authored-by: enitrat <[email protected]>
- Loading branch information
1 parent
e3156b4
commit 6cbc820
Showing
10 changed files
with
610 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,14 @@ | ||
# Code generated by scarb DO NOT EDIT. | ||
version = 1 | ||
|
||
[[package]] | ||
name = "alexandria_data_structures" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4#46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4" | ||
|
||
[[package]] | ||
name = "alexandria_math" | ||
version = "0.2.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4#46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
] | ||
|
||
[[package]] | ||
name = "alexandria_sorting" | ||
version = "0.1.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4#46c8d8ab9e3bfb68b70a29b3246f809cd8bf70e4" | ||
|
||
[[package]] | ||
name = "alexandria_storage" | ||
version = "0.2.0" | ||
source = "git+https://github.com/keep-starknet-strange/alexandria.git?rev=92c3c1b4ac35a4a56c14abe992814581aee875a8#92c3c1b4ac35a4a56c14abe992814581aee875a8" | ||
|
||
[[package]] | ||
name = "cubit" | ||
version = "1.2.0" | ||
source = "git+https://github.com/influenceth/cubit?rev=2ccb2536dffa3f15ebd38b755c1be65fde1eab0c#2ccb2536dffa3f15ebd38b755c1be65fde1eab0c" | ||
|
||
[[package]] | ||
name = "mock_pragma" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"pragma", | ||
"pragma_lib", | ||
] | ||
|
||
[[package]] | ||
name = "openzeppelin" | ||
version = "0.7.0" | ||
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.7.0#bb8c56817577b66cea9f18a241fe59726db42dd5" | ||
|
||
[[package]] | ||
name = "pragma" | ||
name = "pragma_lib" | ||
version = "1.0.0" | ||
source = "git+https://github.com/astraly-labs/pragma-oracle?tag=v1.0.5#71e762dcb725b95a4a4966190219bca8380bc823" | ||
dependencies = [ | ||
"alexandria_data_structures", | ||
"alexandria_math", | ||
"alexandria_sorting", | ||
"alexandria_storage", | ||
"cubit", | ||
"openzeppelin", | ||
] | ||
source = "git+https://github.com/astraly-labs/pragma-lib?tag=2.3.1#24bb4da111ae7eb00e7cf40d4f1767c86d6447cd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod mock_pragma_oracle; | ||
mod mock_pragma_summary_stats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use pragma_lib::types::{DataType, AggregationMode}; | ||
|
||
#[starknet::interface] | ||
trait ISummaryStats<TContractState> { | ||
fn calculate_mean( | ||
self: @TContractState, | ||
data_type: DataType, | ||
start: u64, | ||
stop: u64, | ||
aggregation_mode: AggregationMode | ||
) -> (u128, u32); | ||
|
||
fn calculate_volatility( | ||
self: @TContractState, | ||
data_type: DataType, | ||
start_tick: u64, | ||
end_tick: u64, | ||
num_samples: u64, | ||
aggregation_mode: AggregationMode | ||
) -> (u128, u32); | ||
|
||
fn calculate_twap( | ||
self: @TContractState, | ||
data_type: DataType, | ||
aggregation_mode: AggregationMode, | ||
time: u64, | ||
start_time: u64, | ||
) -> (u128, u32); | ||
} | ||
|
||
#[starknet::contract] | ||
mod MockPragmaSummaryStats { | ||
use core::zeroable::Zeroable; | ||
use starknet::ContractAddress; | ||
use pragma_lib::types::{DataType, AggregationMode}; | ||
use pragma_lib::abi::{IPragmaABIDispatcher, IPragmaABIDispatcherTrait}; | ||
|
||
use super::ISummaryStats; | ||
|
||
#[storage] | ||
struct Storage { | ||
pragma_oracle: IPragmaABIDispatcher, | ||
} | ||
|
||
#[constructor] | ||
fn constructor(ref self: ContractState, pragma_oracle_address: ContractAddress) { | ||
assert(!pragma_oracle_address.is_zero(), 'Pragma Oracle cannot be 0'); | ||
let pragma_oracle = IPragmaABIDispatcher { contract_address: pragma_oracle_address }; | ||
self.pragma_oracle.write(pragma_oracle); | ||
} | ||
|
||
//! Must be compatible with Cairo 2.2.0 | ||
#[external(v0)] | ||
impl ISummaryStatsImpl of ISummaryStats<ContractState> { | ||
fn calculate_mean( | ||
self: @ContractState, | ||
data_type: DataType, | ||
start: u64, | ||
stop: u64, | ||
aggregation_mode: AggregationMode | ||
) -> (u128, u32) { | ||
let data = self.pragma_oracle.read().get_data(data_type, aggregation_mode); | ||
(data.price, data.decimals) | ||
} | ||
|
||
fn calculate_volatility( | ||
self: @ContractState, | ||
data_type: DataType, | ||
start_tick: u64, | ||
end_tick: u64, | ||
num_samples: u64, | ||
aggregation_mode: AggregationMode | ||
) -> (u128, u32) { | ||
let data = self.pragma_oracle.read().get_data(data_type, aggregation_mode); | ||
(data.price, data.decimals) | ||
} | ||
|
||
fn calculate_twap( | ||
self: @ContractState, | ||
data_type: DataType, | ||
aggregation_mode: AggregationMode, | ||
time: u64, | ||
start_time: u64, | ||
) -> (u128, u32) { | ||
let data = self.pragma_oracle.read().get_data(data_type, aggregation_mode); | ||
(data.price, data.decimals) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
pragma solidity ^0.8.13; | ||
|
||
import "forge-std/Script.sol"; | ||
import {PragmaCaller} from "../src/CairoPrecompiles/PragmaCaller.sol"; | ||
|
||
contract PragmaCallerScript is Script { | ||
function run() external { | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
uint256 pragmaOracleAddress = vm.envUint("PRAGMA_ORACLE_ADDRESS"); | ||
uint256 pragmaSummaryStatsAddress = vm.envUint("PRAGMA_SUMMARY_STATS_ADDRESS"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
PragmaCaller pragmaCaller = new PragmaCaller(pragmaOracleAddress, pragmaSummaryStatsAddress); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
Oops, something went wrong.