Skip to main content

df_hyperliquid_core/deploy/outcomes/actions/
instance.rs

1//! A template instance: a template's id and a value for each of its keywords, which every register
2//! is made from.
3
4use crate::deploy::outcomes::actions::bounded::FeeScale;
5use crate::deploy::outcomes::actions::keywords::Keywords;
6use crate::utils::sign::Map;
7
8/// A template and a value for each of its keywords: `{"id","keywordToValue"}`.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct Instance {
11    /// The template's id in `outcomeTemplates`, such as `binaryPrice`.
12    pub id: String,
13    /// A value for each of the template's keywords (`keywordToValue`).
14    pub keywords: Keywords,
15}
16
17impl Instance {
18    /// An instance of the template `id` with `keywords`.
19    #[must_use]
20    pub fn new(id: impl Into<String>, keywords: Keywords) -> Self {
21        Instance { id: id.into(), keywords }
22    }
23
24    /// `{"id","keywordToValue"}`, with no fee scale.
25    #[must_use]
26    pub fn wire(&self) -> Map {
27        Map::new().put("id", self.id.clone()).put("keywordToValue", self.keywords.wire())
28    }
29
30    /// With the fee scale a standalone outcome or a question carries, last.
31    pub(super) fn wire_with(&self, fee_scale: FeeScale) -> Map {
32        self.wire().put("deployerFeeScale", fee_scale.to_wire())
33    }
34}