1616from langchain_core .output_parsers import StrOutputParser
1717from langchain .chat_models import init_chat_model
1818from openagent .agent .config import ModelConfig
19+ from openagent .core .constants .chain_ids import CHAIN_ID_TO_NETWORK
1920from openagent .core .database .engine import create_engine
2021from openagent .core .tool import Tool
2122from openagent .core .utils .fetch_json import fetch_json
@@ -28,19 +29,22 @@ class PendleMarketData:
2829 """Data of a Pendle market, required for analysis"""
2930
3031 symbol : str
32+ chain : str
33+ expiry : str
3134 protocol : str
32- isNewPool : bool
33- liquidityChange24h : float
34- impliedApyChange24h : float
35+ is_new_pool : bool
36+ liquidity_change_24h : float
37+ fixed_apy : float
38+ fixed_apy_change_24h : float
3539
3640
3741@dataclass
3842class PendleMarketSnapshot :
3943 markets : list [PendleMarketData ]
40- liquidityIncreaseList : list [str ]
41- newMarketLiquidityIncreaseList : list [str ]
42- apyIncreaseList : list [str ]
43- newMarketApyIncreaseList : list [str ]
44+ liquidity_increase_list : list [str ]
45+ new_market_liquidity_increaseList : list [str ]
46+ apy_increase_list : list [str ]
47+ new_market_apy_increase_list : list [str ]
4448
4549
4650class PendleMarket (Base ):
@@ -137,20 +141,23 @@ async def setup(self, config: PendleMarketConfig) -> None:
137141 ### Data Structure
138142 - Markets: List of market objects with:
139143 - `symbol`: Name
144+ - `chain`: Chain
145+ - `expiry`: Expiry date
140146 - `protocol`: Issuing protocol
141- - `isNewPool`: Boolean (new market)
142- - `liquidityChange24h`: 24h liquidity change
143- - `impliedApyChange24h`: 24h APY change
147+ - `is_new_pool`: Boolean (new market)
148+ - `liquidity_change_24h`: 24h liquidity change in percentage
149+ - `fixed_apy`: Fixed APY in percentage
150+ - `fixed_apy_change_24h`: 24h APY change in percentage
144151
145152 - Rankings
146- - `liquidityIncreaseList `: Top 3 by liquidity change
147- - `newMarketLiquidityIncreaseList `: Top 3 new markets by liquidity change
148- - `apyIncreaseList `: Top 3 by APY increase
149- - `newMarketApyIncreaseList `: Top 3 new markets by APY increase
153+ - `liquidity_increase_list `: Top 3 by liquidity change
154+ - `new_market_liquidity_increaseList `: Top 3 new markets by liquidity change
155+ - `apy_increase_list `: Top 3 by APY increase
156+ - `new_market_apy_increase_list `: Top 3 new markets by APY increase
150157
151158 ### Task
152159 For each market in the rankings, provide an analysis:
153- - Must be concise with 1 sentence per market, must include `symbol`, `protocol`, `liquidityChange24h `, `impliedApyChange24h `
160+ - Must be concise with 1 sentence per market, must include `symbol`, `protocol`, `chain `, `expiry`, `liquidity_change_24h`, `fixed_apy`, `fixed_apy_change_24h `
154161 - For new markets: add "New Pool"
155162 - Do not provide personal opinions or financial advice\
156163 """
@@ -212,27 +219,39 @@ async def _fetch_pendle_market_data(self) -> PendleMarket:
212219 def _process_market_data (results : dict ) -> PendleMarketSnapshot :
213220 """Process raw market data into a structured snapshot"""
214221
222+ def format_timestamp (timestamp : int ) -> str :
223+ return datetime .fromtimestamp (timestamp ).strftime ('%Y-%m-%d' )
224+
225+ def to_percentage (value : float ) -> float :
226+ return value * 100 if value is not None else 0.0
227+
215228 # Create market list
216229 markets = [
217230 PendleMarketData (
218231 symbol = symbol ,
219- isNewPool = is_new ,
232+ chain = CHAIN_ID_TO_NETWORK .get (chain_id , "chain" ),
233+ expiry = format_timestamp (expiry ),
234+ is_new_pool = is_new ,
220235 protocol = protocol ,
221- liquidityChange24h = liquidity ,
222- impliedApyChange24h = apy ,
236+ liquidity_change_24h = to_percentage (liquidity_change_24h ),
237+ fixed_apy = to_percentage (fixed_apy ),
238+ fixed_apy_change_24h = to_percentage (fixed_apy_change_24h ),
223239 )
224- for symbol , is_new , protocol , liquidity , apy in zip (
240+ for symbol , chain_id , expiry , is_new , protocol , liquidity_change_24h , fixed_apy , fixed_apy_change_24h in zip (
225241 results ["symbolList" ],
242+ results ["chainIdList" ],
243+ results ["expiryList" ],
226244 results ["isNewList" ],
227245 results ["protocolList" ],
228246 results ["liquidityChange24hList" ],
247+ results ["impliedApyList" ],
229248 results ["impliedApyChange24hList" ],
230249 )
231250 ]
232251
233252 # Split the markets into new and existing
234- new_markets = [market for market in markets if market .isNewPool ]
235- existing_markets = [market for market in markets if not market .isNewPool ]
253+ new_markets = [market for market in markets if market .is_new_pool ]
254+ existing_markets = [market for market in markets if not market .is_new_pool ]
236255
237256 def get_top_markets (
238257 markets : list [PendleMarketData ], key_attr : str , n : int = 3
@@ -244,12 +263,12 @@ def get_top_markets(
244263 return nlargest (n , filtered_markets , key = lambda x : getattr (x , key_attr ))
245264
246265 # Get top markets for both liquidity and APY
247- liquidity_increase = get_top_markets (existing_markets , "liquidityChange24h " )
266+ liquidity_increase = get_top_markets (existing_markets , "liquidity_change_24h " )
248267 new_market_liquidity_increase = get_top_markets (
249- new_markets , "liquidityChange24h "
268+ new_markets , "liquidity_change_24h "
250269 )
251- apy_increase = get_top_markets (existing_markets , "impliedApyChange24h " )
252- new_market_apy_increase = get_top_markets (new_markets , "impliedApyChange24h " )
270+ apy_increase = get_top_markets (existing_markets , "fixed_apy_change_24h " )
271+ new_market_apy_increase = get_top_markets (new_markets , "fixed_apy_change_24h " )
253272
254273 # Extract symbols from sorted markets in one step
255274 liquidity_increase_top_symbols = {
@@ -278,8 +297,8 @@ def get_top_markets(
278297
279298 return PendleMarketSnapshot (
280299 markets = filtered_markets ,
281- liquidityIncreaseList = list (liquidity_increase_top_symbols ),
282- newMarketLiquidityIncreaseList = list (new_market_liquidity_increase_symbols ),
283- apyIncreaseList = list (apy_increase_symbols ),
284- newMarketApyIncreaseList = list (new_market_apy_increase_symbols ),
300+ liquidity_increase_list = list (liquidity_increase_top_symbols ),
301+ new_market_liquidity_increaseList = list (new_market_liquidity_increase_symbols ),
302+ apy_increase_list = list (apy_increase_symbols ),
303+ new_market_apy_increase_list = list (new_market_apy_increase_symbols ),
285304 )
0 commit comments