From 22068d8578b99f018eb54ee450e9e75141c69ae7 Mon Sep 17 00:00:00 2001 From: Malte Kliemann Date: Mon, 9 Dec 2024 14:15:33 +0100 Subject: [PATCH] Add `update` function to `FutarchyOracle` trait --- primitives/src/traits/futarchy_oracle.rs | 5 +++++ zrml/futarchy/src/mock/types/oracle.rs | 7 +++++++ zrml/neo-swaps/src/types/decision_market_oracle.rs | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/primitives/src/traits/futarchy_oracle.rs b/primitives/src/traits/futarchy_oracle.rs index 0a4530a6d..19ed93761 100644 --- a/primitives/src/traits/futarchy_oracle.rs +++ b/primitives/src/traits/futarchy_oracle.rs @@ -18,7 +18,12 @@ use frame_support::pallet_prelude::Weight; pub trait FutarchyOracle { + type Data; + /// Evaluates the query at the current block and returns the weight consumed and a `bool` /// indicating whether the query evaluated positively. fn evaluate(&self) -> (Weight, bool); + + /// Updates the oracle's data and returns the weight consumed. + fn update(&self, data: Self::Data) -> Weight; } diff --git a/zrml/futarchy/src/mock/types/oracle.rs b/zrml/futarchy/src/mock/types/oracle.rs index 4b8a7f7e4..ac0053abc 100644 --- a/zrml/futarchy/src/mock/types/oracle.rs +++ b/zrml/futarchy/src/mock/types/oracle.rs @@ -19,6 +19,7 @@ use alloc::fmt::Debug; use frame_support::pallet_prelude::Weight; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +use sp_runtime::traits::Zero; use zeitgeist_primitives::traits::FutarchyOracle; #[derive(Clone, Debug, Decode, Encode, Eq, MaxEncodedLen, PartialEq, TypeInfo)] @@ -40,7 +41,13 @@ impl MockOracle { } impl FutarchyOracle for MockOracle { + type Data = (); + fn evaluate(&self) -> (Weight, bool) { (self.weight, self.value) } + + fn update(&self, _: Self::Data) -> Weight { + Zero::zero() + } } diff --git a/zrml/neo-swaps/src/types/decision_market_oracle.rs b/zrml/neo-swaps/src/types/decision_market_oracle.rs index 2d27f247b..5903df421 100644 --- a/zrml/neo-swaps/src/types/decision_market_oracle.rs +++ b/zrml/neo-swaps/src/types/decision_market_oracle.rs @@ -19,7 +19,7 @@ use crate::{traits::PoolOperations, weights::WeightInfoZeitgeist, AssetOf, Confi use frame_support::pallet_prelude::Weight; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_runtime::DispatchError; +use sp_runtime::{traits::Zero, DispatchError}; use zeitgeist_primitives::traits::FutarchyOracle; #[derive(Clone, Debug, Decode, Encode, Eq, MaxEncodedLen, PartialEq, TypeInfo)] @@ -63,6 +63,8 @@ impl FutarchyOracle for DecisionMarketOracle where T: Config, { + type Data = (); + fn evaluate(&self) -> (Weight, bool) { // Err on the side of caution if the pool is not found or a calculation fails by not // enacting the policy. @@ -70,4 +72,8 @@ where (T::WeightInfo::decision_market_oracle_evaluate(), value) } + + fn update(&self, _: Self::Data) -> Weight { + Zero::zero() + } }