1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use num_bigint::BigUint;
use num_traits::ToPrimitive;
use serde::{Deserialize, Serialize};

use crate::impl_from_uint_for;

/// Transaction type.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub enum TransactionType {
    /// Wallet register.
    WalletRegister = 100,

    /// Deposit.
    Deposit = 200,

    /// Withdrawal.
    Withdrawal = 201,

    /// Force withdrawal.
    ForceWithdrawal = 202,

    /// Transfer.
    Transfer = 300,

    /// Reset main secret.
    ResetMainSecret = 400,

    /// Create API secret.
    CreateApiSecret = 401,

    /// Destroy API secret.
    DestroyApiSecret = 402,

    /// Submit spot order.
    SubmitSpotOrder = 500,

    /// Cancel spot order.
    CancelSpotOrder = 501,

    /// Add spot liquidity.
    AddAmmV2Liquidity = 600,

    /// Remove spot liquidity.
    RemoveAmmV2Liquidity = 601,

    /// Register asset
    RegisterAsset = 700,

    /// Update global withdrawal fee to
    UpdateGlobalWithdrawalFeeTo = 701,

    /// Update asset withdrawal fee to
    UpdateAssetWithdrawalFeeTo = 702,

    /// Update chain confirmation times
    UpdateChainConfirmationTimes = 800,

    /// Register market
    RegisterSpotMarket = 900,

    /// Update spot market trading settings
    UpdateSpotMarketTradingSettings = 901,

    /// Update spot market initial fee to
    UpdateSpotMarketInitialFeeTo = 902,

    /// Update spot market fee to
    UpdateSpotMarketFeeTo = 903,

    /// Update spot market initial trading fee
    UpdateSpotMarketInitialTradingFee = 904,

    /// Update spot market trading fee
    UpdateSpotMarketTradingFee = 905,
}

impl TransactionType {
    pub fn iterator() -> impl Iterator<Item = TransactionType> {
        [
            TransactionType::WalletRegister,
            TransactionType::Deposit,
            TransactionType::Withdrawal,
            TransactionType::ForceWithdrawal,
            TransactionType::Transfer,
            TransactionType::ResetMainSecret,
            TransactionType::CreateApiSecret,
            TransactionType::DestroyApiSecret,
            TransactionType::SubmitSpotOrder,
            TransactionType::CancelSpotOrder,
            TransactionType::AddAmmV2Liquidity,
            TransactionType::RemoveAmmV2Liquidity,
            TransactionType::RegisterAsset,
            TransactionType::UpdateGlobalWithdrawalFeeTo,
            TransactionType::UpdateAssetWithdrawalFeeTo,
            TransactionType::UpdateChainConfirmationTimes,
            TransactionType::RegisterSpotMarket,
            TransactionType::UpdateSpotMarketTradingSettings,
            TransactionType::UpdateSpotMarketInitialFeeTo,
            TransactionType::UpdateSpotMarketFeeTo,
            TransactionType::UpdateSpotMarketInitialTradingFee,
            TransactionType::UpdateSpotMarketTradingFee,
        ]
        .iter()
        .copied()
    }
}

impl From<BigUint> for TransactionType {
    fn from(value: BigUint) -> Self {
        match value.to_u64().unwrap() {
            100 => TransactionType::WalletRegister,
            200 => TransactionType::Deposit,
            201 => TransactionType::Withdrawal,
            202 => TransactionType::ForceWithdrawal,
            300 => TransactionType::Transfer,
            400 => TransactionType::ResetMainSecret,
            401 => TransactionType::CreateApiSecret,
            402 => TransactionType::DestroyApiSecret,
            500 => TransactionType::SubmitSpotOrder,
            501 => TransactionType::CancelSpotOrder,
            600 => TransactionType::AddAmmV2Liquidity,
            601 => TransactionType::RemoveAmmV2Liquidity,
            700 => TransactionType::RegisterAsset,
            701 => TransactionType::UpdateGlobalWithdrawalFeeTo,
            702 => TransactionType::UpdateAssetWithdrawalFeeTo,
            800 => TransactionType::UpdateChainConfirmationTimes,
            900 => TransactionType::RegisterSpotMarket,
            901 => TransactionType::UpdateSpotMarketTradingSettings,
            902 => TransactionType::UpdateSpotMarketInitialFeeTo,
            903 => TransactionType::UpdateSpotMarketFeeTo,
            904 => TransactionType::UpdateSpotMarketInitialTradingFee,
            905 => TransactionType::UpdateSpotMarketTradingFee,
            _ => panic!("Invalid transaction type"),
        }
    }
}

impl Into<BigUint> for TransactionType {
    fn into(self) -> BigUint {
        BigUint::from(self as u128)
    }
}

impl_from_uint_for!(TransactionType, u32, u64, u128);