Skip to content

Commit

Permalink
Add update function to FutarchyOracle trait
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann committed Dec 9, 2024
1 parent 41d8752 commit 22068d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions primitives/src/traits/futarchy_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions zrml/futarchy/src/mock/types/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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()
}
}
8 changes: 7 additions & 1 deletion zrml/neo-swaps/src/types/decision_market_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -63,11 +63,17 @@ impl<T> FutarchyOracle for DecisionMarketOracle<T>
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.
let value = self.try_evaluate().unwrap_or(false);

(T::WeightInfo::decision_market_oracle_evaluate(), value)
}

fn update(&self, _: Self::Data) -> Weight {
Zero::zero()
}
}

0 comments on commit 22068d8

Please sign in to comment.