levana_perpswap_cosmos/contracts/market/
delta_neutrality_fee.rs

1//! Events around the delta neutrality fee
2use crate::prelude::*;
3use cosmwasm_std::Event;
4
5/// Event when a delta neutrality payment is made.
6#[derive(Clone)]
7pub struct DeltaNeutralityFeeEvent {
8    /// Amount of the fee. Negative means paid to trader.
9    pub amount: Signed<Collateral>,
10    /// Fund size before
11    pub total_funds_before: Collateral,
12    /// Fund size after
13    pub total_funds_after: Collateral,
14    /// Action taken by trader
15    pub reason: DeltaNeutralityFeeReason,
16    /// Amount taken for the protocol tax
17    pub protocol_amount: Collateral,
18}
19
20impl From<DeltaNeutralityFeeEvent> for Event {
21    fn from(src: DeltaNeutralityFeeEvent) -> Self {
22        Event::new("delta-neutrality-fee").add_attributes(vec![
23            ("amount", src.amount.to_string()),
24            ("total-funds-before", src.total_funds_before.to_string()),
25            ("total-funds-after", src.total_funds_after.to_string()),
26            ("reason", src.reason.as_str().to_string()),
27        ])
28    }
29}
30
31/// Action taken by trader to incur a delta neutrality fee
32#[derive(Clone, Copy, Debug, Eq, PartialEq)]
33pub enum DeltaNeutralityFeeReason {
34    /// Open a new position
35    PositionOpen,
36    /// Update an existing position
37    PositionUpdate,
38    /// Close a position
39    PositionClose,
40}
41
42impl DeltaNeutralityFeeReason {
43    /// Express the reason as a string
44    pub const fn as_str(&self) -> &'static str {
45        match self {
46            Self::PositionOpen => "open",
47            Self::PositionUpdate => "update",
48            Self::PositionClose => "close",
49        }
50    }
51}