From cf9c4ccf51e8294f4502392b296062a167295ee2 Mon Sep 17 00:00:00 2001 From: 0xevolve Date: Tue, 24 Dec 2024 18:08:15 +0100 Subject: [PATCH] feat: add oo interface + bump 2.9.2 --- .tool-versions | 2 +- Scarb.lock | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ Scarb.toml | 3 +- src/abi.cairo | 50 +++++++++++++++++++++- src/types.cairo | 26 ++++++++++++ 5 files changed, 187 insertions(+), 3 deletions(-) diff --git a/.tool-versions b/.tool-versions index a25f07c..8a183b2 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.9.1 \ No newline at end of file +scarb 2.9.2 \ No newline at end of file diff --git a/Scarb.lock b/Scarb.lock index f863e04..a51fe91 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -1,6 +1,115 @@ # Code generated by scarb DO NOT EDIT. version = 1 +[[package]] +name = "openzeppelin" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_finance", + "openzeppelin_governance", + "openzeppelin_introspection", + "openzeppelin_merkle_tree", + "openzeppelin_presets", + "openzeppelin_security", + "openzeppelin_token", + "openzeppelin_upgrades", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_access" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_introspection", +] + +[[package]] +name = "openzeppelin_account" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_finance" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_access", + "openzeppelin_token", +] + +[[package]] +name = "openzeppelin_governance" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_introspection" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" + +[[package]] +name = "openzeppelin_merkle_tree" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" + +[[package]] +name = "openzeppelin_presets" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_finance", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_upgrades", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_security" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" + +[[package]] +name = "openzeppelin_token" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_upgrades" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" + +[[package]] +name = "openzeppelin_utils" +version = "0.20.0" +source = "git+https://github.com/OpenZeppelin/cairo-contracts.git#7b4ff769c4d09f0eb247f95121c2c6c995bdf9b3" + [[package]] name = "pragma_lib" version = "1.0.0" +dependencies = [ + "openzeppelin", +] diff --git a/Scarb.toml b/Scarb.toml index ad3f6c8..ffc3031 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -7,4 +7,5 @@ homepage = "https://github.com/astraly-labs/pragma-oracle/tree/main" [lib] [dependencies] -starknet = "2.9.1" +starknet = "2.9.2" +openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git"} diff --git a/src/abi.cairo b/src/abi.cairo index 2e08f2a..7181fa2 100644 --- a/src/abi.cairo +++ b/src/abi.cairo @@ -1,8 +1,9 @@ use starknet::{ContractAddress, ClassHash}; use pragma_lib::types::{ DataType, AggregationMode, Currency, Pair, PossibleEntries, Checkpoint, SimpleDataType, - PragmaPricesResponse, YieldPoint, FutureKeyStatus, RequestStatus, OptionsFeedData, + PragmaPricesResponse, YieldPoint, FutureKeyStatus, RequestStatus, OptionsFeedData, Assertion }; +use openzeppelin::token::erc20::interface::ERC20ABIDispatcher; #[starknet::interface] trait IPragmaABI { @@ -238,3 +239,50 @@ trait IRandomness { fn get_admin_address(self: @TContractState,) -> ContractAddress; fn set_admin_address(ref self: TContractState, new_admin_address: ContractAddress); } + +#[starknet::interface] +pub trait IOptimisticOracle { + fn assert_truth_with_defaults( + ref self: TContractState, claim: ByteArray, asserter: ContractAddress + ) -> felt252; + + fn assert_truth( + ref self: TContractState, + claim: ByteArray, + asserter: ContractAddress, + callback_recipient: ContractAddress, + escalation_manager: ContractAddress, + liveness: u64, + currency: ERC20ABIDispatcher, + bond: u256, + identifier: felt252, + domain_id: u256 + ) -> felt252; + + fn dispute_assertion( + ref self: TContractState, assertion_id: felt252, disputer: ContractAddress + ); + + fn settle_assertion(ref self: TContractState, assertion_id: felt252); + + fn get_minimum_bond(self: @TContractState, currency: ContractAddress) -> u256; + + fn stamp_assertion(self: @TContractState, assertion_id: felt252) -> ByteArray; + + fn default_identifier(self: @TContractState,) -> felt252; + + fn get_assertion(self: @TContractState, assertion_id: felt252) -> Assertion; + + fn sync_params(ref self: TContractState, identifier: felt252, currency: ContractAddress); + + fn settle_and_get_assertion_result(ref self: TContractState, assertion_id: felt252) -> bool; + + fn get_assertion_result(self: @TContractState, assertion_id: felt252) -> bool; + + fn set_admin_properties( + ref self: TContractState, + default_currency: ContractAddress, + default_liveness: u64, + burned_bond_percentage: u256 + ); +} \ No newline at end of file diff --git a/src/types.cairo b/src/types.cairo index 3698187..363ef37 100644 --- a/src/types.cairo +++ b/src/types.cairo @@ -1,4 +1,5 @@ use starknet::{ContractAddress, ClassHash}; +use openzeppelin::token::erc20::interface::ERC20ABIDispatcher; #[derive(Serde, Drop, Copy, PartialEq, starknet::Store)] enum RequestStatus { @@ -176,3 +177,28 @@ enum AggregationMode { ConversionRate, Error: (), } + +#[derive(starknet::Store, Drop, Serde, Copy)] +pub struct EscalationManagerSettings { + pub arbitrate_via_escalation_manager: bool, + pub discard_oracle: bool, + pub validate_disputers: bool, + pub asserting_caller: ContractAddress, + pub escalation_manager: ContractAddress, +} + +#[derive(starknet::Store, Drop, Serde, Copy)] +pub struct Assertion { + pub escalation_manager_settings: EscalationManagerSettings, + pub asserter: ContractAddress, + pub assertion_time: u64, + pub settled: bool, + pub currency: ERC20ABIDispatcher, + pub expiration_time: u64, + pub settlement_resolution: bool, + pub domain_id: u256, + pub identifier: felt252, + pub bond: u256, + pub callback_recipient: ContractAddress, + pub disputer: ContractAddress, +}