Coverage for yield_analysis_sdk\type.py: 100%

77 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-07-02 22:32 +0800

1from enum import Enum 

2from typing import Any, List, Optional, Tuple 

3 

4from pydantic import BaseModel, Field 

5 

6from .validators import ( 

7 ChainValidatorMixin, 

8 UnderlyingTokenValidatorMixin, 

9 VaultAddressValidatorMixin, 

10) 

11 

12 

13class Chain(Enum): 

14 ETHEREUM = "ethereum" 

15 ARBITRUM = "arbitrum" 

16 BASE = "base" 

17 OPTIMISM = "optimism" 

18 POLYGON = "polygon" 

19 BSC = "bsc" 

20 GNOS = "gnos" 

21 AVALANCHE = "avalanche" 

22 FANTOM = "fantom" 

23 HARMONY = "harmony" 

24 MOONBEAM = "moonbeam" 

25 MOONRIVER = "moonriver" 

26 OTHER = "other" 

27 

28 @classmethod 

29 def _missing_(cls, value: Any) -> "Chain": 

30 """Handle unknown chain values by returning OTHER.""" 

31 return cls.OTHER 

32 

33 

34class StrategyType(Enum): 

35 # Core Yield Strategies 

36 LIQUID_STAKING = "liquid_staking" 

37 LIQUID_RESTAKING = "liquid_restaking" 

38 LENDING = "lending" 

39 YIELD_AGGREGATOR = "yield_aggregator" 

40 

41 # Trading & DeFi 

42 BASIS_TRADING = "basis_trading" 

43 ARBITRAGE = "arbitrage" 

44 CDP = "cdp" 

45 DEXES = "dexes" 

46 

47 # Index & Basket 

48 INDEXES = "index" 

49 BASKET = "basket" 

50 

51 # Farming 

52 YIELD_FARMING = "yield_farming" 

53 LIQUIDITY_MINING = "liquidity_mining" 

54 

55 # Other 

56 OTHER = "other" 

57 

58 

59class AuditStatus(Enum): 

60 AUDITED = "audited" 

61 NOT_AUDITED = "not_audited" 

62 PARTIALLY_AUDITED = "partially_audited" 

63 UNKNOWN = "unknown" 

64 

65 

66class VaultRegistrationRequest( 

67 VaultAddressValidatorMixin, ChainValidatorMixin, BaseModel 

68): 

69 chain: Chain 

70 vault_address: str 

71 

72 

73class VaultRegistrationResponse(BaseModel): 

74 is_registered: bool 

75 message: str 

76 contract_tx_hash: Optional[str] = None 

77 

78 

79class AnalysisRequest(UnderlyingTokenValidatorMixin, ChainValidatorMixin, BaseModel): 

80 chain: Chain = Field(..., description="The chain of vaults to analyze") 

81 underlying_token: str = Field( 

82 ..., description="The underlying token of vaults to analyze" 

83 ) 

84 

85 

86class VaultInfo(VaultAddressValidatorMixin, ChainValidatorMixin, BaseModel): 

87 # Basic Vault Information 

88 chain: Chain 

89 vault_address: str 

90 vault_name: str 

91 

92 # Fee Structure (Critical for allocation decisions) 

93 entry_fee_bps: int = Field(0, description="Entry fee rate in basis points") 

94 exit_fee_bps: int = Field(0, description="Exit fee rate in basis points") 

95 

96 # Vault Capacity 

97 max_deposit_amount: float = Field( 

98 0.0, 

99 description="Maximum amount of underlying token that can be deposited into the vault", 

100 ) 

101 

102 # Analysis Context 

103 risk_free_rate: float = Field( 

104 0.05, description="Risk-free rate used for Sharpe ratio calculation" 

105 ) 

106 

107 # Analysis Metadata 

108 last_updated_timestamp: int = Field( 

109 ..., description="Last update timestamp in seconds" 

110 ) 

111 

112 

113class PerformanceAnalysis(BaseModel): 

114 # Core Performance Metrics (Mandatory for allocation decisions) 

115 apy_7d: float = Field(..., description="7-day annualized percentage yield") 

116 apy_30d: float = Field(..., description="30-day annualized percentage yield") 

117 apy_90d: float = Field(..., description="90-day annualized percentage yield") 

118 

119 # Essential Risk Metrics 

120 volatility_30d: float = Field(..., description="30-day APY volatility") 

121 max_drawdown: float = Field( 

122 ..., description="Maximum historical drawdown percentage" 

123 ) 

124 sharpe_ratio: float = Field(..., description="Risk-adjusted return ratio") 

125 

126 # Current State 

127 current_price: float = Field(..., description="Current share price") 

128 

129 # Analysis Metadata 

130 analysis_period_days: int = Field( 

131 ..., description="Number of days in the analysis period" 

132 ) 

133 

134 

135class VaultPerformanceAnalysis(BaseModel): 

136 # Combined vault info and performance analysis 

137 vault_info: VaultInfo 

138 performance: PerformanceAnalysis 

139 

140 

141class AnalysisResponse(BaseModel): 

142 analyses: list[VaultPerformanceAnalysis] = Field( 

143 ..., description="List of vault analyses" 

144 ) 

145 

146 

147class SharePriceHistory(VaultAddressValidatorMixin, BaseModel): 

148 vault_name: str 

149 vault_address: str 

150 price_history: List[Tuple[int, float]]