af_iperps/
slo.rs

1//! Helpers for stop-loss orders.
2
3use af_utilities::types::Fixed;
4use fastcrypto::hash::{Blake2b256, HashFunction};
5use sui_framework_sdk::object::ID;
6
7use crate::order_helpers::{OrderType, Side};
8
9/// The details to be hashed for the `encrypted_details` argument of `create_stop_order_ticket`.
10#[derive(Debug, serde::Serialize)]
11pub struct StopOrderTicketDetails {
12    pub clearing_house_id: ID,
13    /// The `Clock` value after (>=) which the order isn't valid anymore
14    pub expire_timestamp: u64,
15    /// `true` if limit order, `false` if market order
16    pub is_limit_order: bool,
17    pub stop_index_price: Fixed,
18    /// `true` means the order can be placed when oracle index price is >= than chosen
19    /// `stop_index_price`
20    pub ge_stop_index_price: bool,
21    pub side: Side,
22    pub size: u64,
23    /// Can be set at random value if `is_limit_order` is false
24    pub price: u64,
25    /// Can be set at random value if `is_limit_order` is false
26    pub order_type: OrderType,
27}
28
29impl StopOrderTicketDetails {
30    /// Pure transaction input to use when calling `create_stop_order_ticket`.
31    pub fn encrypted_details(&self, salt: Vec<u8>) -> bcs::Result<Vec<u8>> {
32        let mut bytes = bcs::to_bytes(self)?;
33        bytes.extend(salt);
34        Ok(Blake2b256::digest(bytes).to_vec())
35    }
36}