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    pub keywords: Keywords,
14}
15
16impl Instance {
17    #[must_use]
18    pub fn new(id: impl Into<String>, keywords: Keywords) -> Self {
19        Instance { id: id.into(), keywords }
20    }
21
22    #[must_use]
23    pub fn wire(&self) -> Map {
24        Map::new().put("id", self.id.clone()).put("keywordToValue", self.keywords.wire())
25    }
26
27    /// With the fee scale a standalone outcome or a question carries, last.
28    pub(super) fn wire_with(&self, fee_scale: FeeScale) -> Map {
29        self.wire().put("deployerFeeScale", fee_scale.to_wire())
30    }
31}