@@ -68,12 +68,18 @@ async def execute(self, token_info: TokenInfo) -> TradeResult:
6868 # Regular behavior with RPC call
6969 # Fetch pool state to get price and mayhem mode status
7070 pool_state = await curve_manager .get_pool_state (pool_address )
71- token_price_sol = pool_state .get ("price_per_token" , 0 )
71+ token_price_sol = pool_state .get ("price_per_token" )
72+
73+ # Validate price_per_token is present and positive
74+ if token_price_sol is None or token_price_sol <= 0 :
75+ raise ValueError (
76+ f"Invalid price_per_token: { token_price_sol } for pool { pool_address } "
77+ f"(mint: { token_info .mint } ) - cannot execute buy with zero/invalid price"
78+ )
79+
7280 # Set is_mayhem_mode from bonding curve state
7381 token_info .is_mayhem_mode = pool_state .get ("is_mayhem_mode" , False )
74- token_amount = (
75- self .amount / token_price_sol if token_price_sol > 0 else 0
76- )
82+ token_amount = self .amount / token_price_sol
7783
7884 # Calculate minimum token amount with slippage
7985 minimum_token_amount = token_amount * (1 - self .slippage )
@@ -231,7 +237,15 @@ async def execute(self, token_info: TokenInfo) -> TradeResult:
231237 pool_address = self ._get_pool_address (token_info , address_provider )
232238 # Fetch pool state to get price and mayhem mode status
233239 pool_state = await curve_manager .get_pool_state (pool_address )
234- token_price_sol = pool_state .get ("price_per_token" , 0 )
240+ token_price_sol = pool_state .get ("price_per_token" )
241+
242+ # Validate price_per_token is present and positive
243+ if token_price_sol is None or token_price_sol <= 0 :
244+ raise ValueError (
245+ f"Invalid price_per_token: { token_price_sol } for pool { pool_address } "
246+ f"(mint: { token_info .mint } ) - cannot execute sell with zero/invalid price"
247+ )
248+
235249 # Set is_mayhem_mode from bonding curve state
236250 token_info .is_mayhem_mode = pool_state .get ("is_mayhem_mode" , False )
237251
0 commit comments