Coverage for yield_analysis_sdk\type.py: 100%
81 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-08-15 13:20 +0800
« prev ^ index » next coverage.py v7.9.1, created at 2025-08-15 13:20 +0800
1from enum import Enum
2from typing import Any, Dict, List, Optional, Tuple
4from pydantic import BaseModel, Field
6from .validators import (
7 ChainMixin,
8 UnderlyingTokenValidatorMixin,
9 VaultAddressValidatorMixin,
10)
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"
28 @classmethod
29 def _missing_(cls, value: Any) -> "Chain":
30 """Handle unknown chain values by returning OTHER."""
31 return cls.OTHER
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"
41 # Trading & DeFi
42 BASIS_TRADING = "basis_trading"
43 ARBITRAGE = "arbitrage"
44 CDP = "cdp"
45 DEXES = "dexes"
47 # Index & Basket
48 INDEXES = "index"
49 BASKET = "basket"
51 # Farming
52 YIELD_FARMING = "yield_farming"
53 LIQUIDITY_MINING = "liquidity_mining"
55 # Other
56 OTHER = "other"
59class AuditStatus(Enum):
60 AUDITED = "audited"
61 NOT_AUDITED = "not_audited"
62 PARTIALLY_AUDITED = "partially_audited"
63 UNKNOWN = "unknown"
66class RegistrationRequest(VaultAddressValidatorMixin, ChainMixin, BaseModel):
67 chain: Chain
68 vault_address: str
71class RegistrationResponse(BaseModel):
72 is_registered: bool
73 message: str
74 contract_tx_hash: Optional[str] = None
77class Strategy(BaseModel):
78 chainId: int
79 address: str
82class AnalysisRequest(BaseModel):
83 strategies: List[Strategy]
86class VaultInfo(VaultAddressValidatorMixin, ChainMixin, BaseModel):
87 # Basic Vault Information
88 chain: Chain
89 vault_address: str
90 vault_name: str
91 protocol: str = Field(
92 ..., description="The protocol/platform this vault belongs to"
93 )
95 # Fee Structure (Critical for allocation decisions)
96 entry_fee_bps: int = Field(0, description="Entry fee rate in basis points")
97 exit_fee_bps: int = Field(0, description="Exit fee rate in basis points")
99 # Vault Capacity
100 max_deposit_amount: float = Field(
101 1_000_000_000_000.00,
102 description="Maximum amount of underlying token that can be deposited into the vault.",
103 )
105 # Analysis Context
106 risk_free_rate: float = Field(
107 0.05, description="Risk-free rate used for Sharpe ratio calculation"
108 )
110 # Analysis Metadata
111 last_updated_timestamp: int = Field(
112 ..., description="Last update timestamp in seconds"
113 )
116class PerformanceAnalysis(BaseModel):
117 # Core Performance Metrics (Mandatory for allocation decisions)
118 apy_7d: float = Field(..., description="7-day annualized percentage yield")
119 apy_30d: float = Field(..., description="30-day annualized percentage yield")
120 apy_90d: float = Field(..., description="90-day annualized percentage yield")
122 # Essential Risk Metrics
123 volatility_30d: float = Field(..., description="30-day APY volatility")
124 max_drawdown: float = Field(
125 ..., description="Maximum historical drawdown percentage"
126 )
127 sharpe_ratio: float = Field(..., description="Risk-adjusted return ratio")
129 # Current State
130 current_price: float = Field(..., description="Current share price")
132 # Analysis Metadata
133 analysis_period_days: int = Field(
134 ..., description="Number of days in the analysis period"
135 )
138class AnalysisResult(BaseModel):
139 # Combined vault info and performance analysis
140 vault_info: VaultInfo
141 performance: PerformanceAnalysis
142 extra_info: Optional[Dict[str, Any]] = Field(
143 default=None, description="Additional information about the vault"
144 )
147class AnalysisResponse(BaseModel):
148 analyses: List[AnalysisResult] = Field(..., description="List of vault analyses")
151class SharePriceHistory(VaultAddressValidatorMixin, BaseModel):
152 vault_name: str
153 vault_address: str
154 price_history: List[Tuple[int, float]]