diff --git a/types/src/tx_type/validator.rs b/types/src/tx_type/validator.rs index d86a95f8..47ac7d40 100644 --- a/types/src/tx_type/validator.rs +++ b/types/src/tx_type/validator.rs @@ -131,7 +131,7 @@ pub fn boolean_validator(boolean: u8) -> Result<(), ValidationError> { /// Check direction flag value validation /// -/// - boolean should be 0 or 1 +/// - direction should <= 3 pub fn direction_validator(direction: u8) -> Result<(), ValidationError> { if direction > 3u8 { return Err(ValidationError::new( @@ -153,7 +153,7 @@ pub fn rate_validator(ratio: u16) -> Result<(), ValidationError> { /// Check margin currency ratio value validation /// -/// - fee_ratio should <= 10000 +/// - margin_ratio should <= 100 pub fn margin_rate_validator(margin_ratio: u8) -> Result<(), ValidationError> { if margin_ratio > 100u8 { return Err(ValidationError::new("margin ratio out of range")); @@ -204,8 +204,8 @@ pub fn margin_prices_validator(margin_prices: &[SpotPriceInfo]) -> Result<(), Va /// Check order matching price value validation /// -/// - price should > MIN_PRICE(1) -/// - price should < MAX_PRICE(\[(2 ** 15 - 1)/10 ^18\] * 10^18 = 1329227995784915872000000000000000000) +/// - price should > MIN_PRICE +/// - price should < MAX_PRICE pub fn price_validator(price: &BigUint) -> Result<(), ValidationError> { if *price <= BigUint::from(MIN_PRICE) || *price >= BigUint::from(MAX_PRICE) { return Err(ValidationError::new("price value out of range")); @@ -215,7 +215,7 @@ pub fn price_validator(price: &BigUint) -> Result<(), ValidationError> { /// Check contract matching price value validation /// -/// - price should < MAX_PRICE(\[(2 ** 15 - 1)/10 ^18\] * 10^18 = 1329227995784915872000000000000000000) +/// - price should < MAX_PRICE pub fn external_price_validator(price: &BigUint) -> Result<(), ValidationError> { if *price >= BigUint::from(MAX_PRICE) { return Err(ValidationError::new("price value out of range")); diff --git a/types/src/tx_type/zklink_tx.rs b/types/src/tx_type/zklink_tx.rs index 9f0e8dc7..bac4a9ae 100644 --- a/types/src/tx_type/zklink_tx.rs +++ b/types/src/tx_type/zklink_tx.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use validator::{Validate, ValidationErrors}; -use crate::basic_types::{tx_hash::TxHash, GetBytes, Nonce, SubAccountId}; +use crate::basic_types::{tx_hash::TxHash, Nonce, SubAccountId}; use crate::prelude::{AutoDeleveraging, ContractMatching, Funding, Liquidation, UpdateGlobalVar}; use crate::tx_type::change_pubkey::ChangePubKey; use crate::tx_type::deposit::Deposit; @@ -22,6 +22,11 @@ pub enum ZkLinkTxType { Withdraw, ForcedExit, OrderMatching, + ContractMatching, + Liquidation, + AutoDeleveraging, + UpdateGlobalVar, + Funding, } impl ZkLinkTxType { @@ -34,6 +39,11 @@ impl ZkLinkTxType { ZkLinkTxType::ChangePubKey => vec![ChangePubKey::TX_TYPE], ZkLinkTxType::ForcedExit => vec![ForcedExit::TX_TYPE], ZkLinkTxType::OrderMatching => vec![OrderMatching::TX_TYPE], + ZkLinkTxType::ContractMatching => vec![ContractMatching::TX_TYPE], + ZkLinkTxType::Liquidation => vec![Liquidation::TX_TYPE], + ZkLinkTxType::AutoDeleveraging => vec![AutoDeleveraging::TX_TYPE], + ZkLinkTxType::UpdateGlobalVar => vec![UpdateGlobalVar::TX_TYPE], + ZkLinkTxType::Funding => vec![Funding::TX_TYPE], } } } @@ -175,11 +185,11 @@ impl ZkLinkTx { ZkLinkTx::Deposit(tx) => tx.tx_hash(), ZkLinkTx::FullExit(tx) => tx.tx_hash(), ZkLinkTx::OrderMatching(tx) => tx.tx_hash(), - ZkLinkTx::ContractMatching(tx) => tx.get_bytes(), - ZkLinkTx::Liquidation(tx) => tx.get_bytes(), - ZkLinkTx::AutoDeleveraging(tx) => tx.get_bytes(), - ZkLinkTx::UpdateGlobalVar(tx) => tx.get_bytes(), - ZkLinkTx::Funding(tx) => tx.get_bytes(), + ZkLinkTx::ContractMatching(tx) => tx.tx_hash(), + ZkLinkTx::Liquidation(tx) => tx.tx_hash(), + ZkLinkTx::AutoDeleveraging(tx) => tx.tx_hash(), + ZkLinkTx::UpdateGlobalVar(tx) => tx.tx_hash(), + ZkLinkTx::Funding(tx) => tx.tx_hash(), }; let mut out = [0u8; 32];