@@ -244,40 +244,43 @@ def test_limit_order_at_current_price(self):
244244 assert result ["taking_amount" ] == "100000000000"
245245
246246 def test_limit_order_buy_the_dip (self ):
247- """Should calculate limit order for buying at lower price ."""
247+ """Should calculate limit order for buying the dip (get more output by waiting) ."""
248248 result = calculate_limit_order_amounts (
249249 input_usd_amount = "10" ,
250250 input_price_usd = "140" , # SOL
251251 input_decimals = 9 ,
252252 output_price_usd = "0.00001" , # BONK
253253 output_decimals = 5 ,
254- price_change_percentage = "- 0.5" , # Buy when 0.5% lower
254+ price_change_percentage = "0.5" , # Want 0.5% MORE output (buy the dip)
255255 )
256256 # making_amount unchanged
257257 assert result ["making_amount" ] == "71428571"
258- # taking_amount: at 0.995 price, get MORE tokens
259- # $10 / $0.00000995 * 10^5 = 100,502,512,562 (rounded down)
258+ # taking_amount: with +0.5%, we're asking for MORE output (1.005x)
259+ # $10 * 1.005 / $0.00001 * 10^5 = 100,500,000,000
260260 taking = int (result ["taking_amount" ])
261261 assert taking > 100000000000 # More than at current price
262262 assert taking < 101000000000 # But not too much more
263263
264264 def test_limit_order_sell_high (self ):
265- """Should calculate limit order for selling at higher price."""
265+ """Should calculate limit order for selling at higher price (get more output) ."""
266266 result = calculate_limit_order_amounts (
267267 input_usd_amount = "10" ,
268268 input_price_usd = "0.00001" , # BONK
269269 input_decimals = 5 ,
270270 output_price_usd = "140" , # SOL
271271 output_decimals = 9 ,
272- price_change_percentage = "10 " , # Sell when SOL is 10% higher
272+ price_change_percentage = "5 " , # Want 5% MORE output (sell high)
273273 )
274- # At 10% higher SOL price ($154), get LESS SOL for same USD
274+ # making: $10 / $0.00001 * 10^5 = 100,000,000,000
275275 making = int (result ["making_amount" ])
276- # $10 / $0.00001 * 10^5 = 100,000,000,000
277276 assert making == 100000000000
278- # taking: $10 / $154 * 10^9 = 64,935,064 (less SOL)
277+ # taking: $10 * 1.05 / $140 * 10^9 = 75,000,000 (5% more SOL than current )
279278 taking = int (result ["taking_amount" ])
280- assert taking < 71428571 # Less than at current price
279+ # Current would be $10 / $140 * 10^9 = 71,428,571
280+ assert (
281+ taking > 71428571
282+ ) # More than at current price (we're asking for premium)
283+ assert taking < 80000000 # Reasonable upper bound
281284
282285
283286class TestCalculateLimitOrderInfo :
@@ -1084,7 +1087,7 @@ async def test_scenario_swap_2_dollars_of_sol(self, math_tool):
10841087 async def test_scenario_limit_buy_bonk_with_10_dollars_sol (self , math_tool ):
10851088 """
10861089 Scenario: "limit buy BONK when price drops 0.5% with $10 of SOL"
1087- From the agent config example .
1090+ User wants 0.5% MORE BONK than current market (buy the dip) .
10881091 """
10891092 # From Birdeye: SOL price=$140, decimals=9, BONK price=$0.00001, decimals=5
10901093 result = await math_tool .execute (
@@ -1098,7 +1101,7 @@ async def test_scenario_limit_buy_bonk_with_10_dollars_sol(self, math_tool):
10981101 input_decimals = 9 ,
10991102 output_price_usd = "0.00001" , # BONK
11001103 output_decimals = 5 ,
1101- price_change_percentage = "- 0.5" , # 0.5% lower
1104+ price_change_percentage = "0.5" , # Want 0.5% MORE output (buy the dip)
11021105 )
11031106 assert result ["status" ] == "success"
11041107
@@ -1108,12 +1111,13 @@ async def test_scenario_limit_buy_bonk_with_10_dollars_sol(self, math_tool):
11081111 assert making == 71428571
11091112
11101113 # Verify taking_amount (BONK to receive)
1111- # Target price = $0.00001 * 0.995 = $0.00000995
1112- # $10 / $0.00000995 = 1,005,025.125... BONK
1113- # In smallest units: 1,005,025.125 * 100,000 = 100,502,512,562
1114+ # With +0.5%, we want 0.5% more BONK
1115+ # Current: $10 / $0.00001 = 1,000,000 BONK
1116+ # With +0.5%: 1,000,000 * 1.005 = 1,005,000 BONK
1117+ # In smallest units: 1,005,000 * 100,000 = 100,500,000,000
11141118 taking = int (result ["taking_amount" ])
11151119 # Should be around 100.5 billion (12 digits)
1116- assert len (str (taking )) == 12 # Verify digit count matches agent example
1120+ assert len (str (taking )) == 12 # Verify digit count
11171121 assert taking > 100000000000 # More than at current price
11181122
11191123 @pytest .mark .asyncio
0 commit comments