diff --git a/libs/cache/solbot_cache/launch.py b/libs/cache/solbot_cache/launch.py index 230e920..1db711f 100644 --- a/libs/cache/solbot_cache/launch.py +++ b/libs/cache/solbot_cache/launch.py @@ -1,6 +1,7 @@ from solbot_common.constants import PUMP_FUN_PROGRAM from solbot_common.log import logger -from solbot_common.utils.utils import get_async_client, get_bonding_curve_account +from solbot_common.utils.utils import (get_async_client, + get_bonding_curve_account) from solders.pubkey import Pubkey from .cached import cached @@ -20,12 +21,14 @@ def __init__(self) -> None: def __repr__(self) -> str: return "LaunchCache()" - @cached(ttl=None, noself=True) + @cached(ttl=None, noself=True, skip_cache_func=lambda result: not result) async def is_pump_token_graduated(self, mint: str | Pubkey) -> bool: """Examine if a Pump.fun token has graduated. By checking if the token has completed the bonding curve. + Only cache the result upon graduation. + Args: mint (str): 代币的 mint 地址 diff --git a/libs/common/solbot_common/utils/pump.py b/libs/common/solbot_common/utils/pump.py index 38e77d1..da88481 100644 --- a/libs/common/solbot_common/utils/pump.py +++ b/libs/common/solbot_common/utils/pump.py @@ -4,7 +4,7 @@ from solbot_common.utils.shyft import ShyftAPI -@cached(ttl=None, noself=True) +@cached(ttl=None) async def is_pumpfun_token(mint_address): shyft_api = ShyftAPI(settings.api.shyft_api_key) resp = await shyft_api.get_token_info(mint_address) diff --git a/tests/trading/conftest.py b/tests/trading/conftest.py index 2a1b92f..2d515b2 100644 --- a/tests/trading/conftest.py +++ b/tests/trading/conftest.py @@ -278,4 +278,60 @@ def swap_event_from_logs_fifth(tx_event_from_logs_fifth) -> SwapEvent: max_slippage_bps=None, program_id="6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P", tx_event=tx_event_from_logs_fifth, - ) \ No newline at end of file + ) + + +@pytest.fixture +def tx_event_from_logs_sixth() -> TxEvent: + """Sixth TxEvent instance derived from updated logged example (#6).""" + return TxEvent( + signature="2cbwMNFKr5zgNMJAWx1PczcurPZpP2aMT2urDzJVJJhznNy68jjGmca8GE8EVQQ5HU8xSkCFtjud3MJUBiojwpZZ", + from_amount=3000025000, + from_decimals=9, + to_amount=29165361138622, + to_decimals=6, + mint="2vdx1WyotkxA3UKc6VWnEAYobhL6iWpqj55N6g4hpump", + who="8rvAsDKeAcEjEkiZMug9k8v1y8mW6gQQiMobd89Uy7qR", + tx_type=TxType.OPEN_POSITION, + tx_direction="buy", + timestamp=1758522230, + pre_token_amount=0, + post_token_amount=29165361138622, + program_id=None, + ) + + + +@pytest.fixture +def swap_event_from_logs_sixth(tx_event_from_logs_sixth) -> SwapEvent: + """Sixth SwapEvent matching the updated commented example (#6).""" + return SwapEvent( + user_pubkey="5b9tuvErmHAXpfGNv4wyRDQx6mLhYp4tKry52gxhToBa", + swap_mode="ExactIn", + input_mint="So11111111111111111111111111111111111111112", + output_mint="2vdx1WyotkxA3UKc6VWnEAYobhL6iWpqj55N6g4hpump", + amount=50000000, + ui_amount=0.05, + timestamp=1758522230, + amount_pct=None, + swap_in_type="qty", + priority_fee=0.002, + slippage_bps=250, + by="copytrade", + dynamic_slippage=False, + min_slippage_bps=None, + max_slippage_bps=None, + program_id=None, + tx_event=tx_event_from_logs_sixth, + ) + + +@pytest.fixture +def swapper_for_sixth(rpc_client): + """Swapper instance for SwapEvent #6 via TradingService.use_route.""" + from app.trading.trading.transaction import TradingRoute, TradingService + + service = TradingService(rpc_client) + # For #6, route via Pump (token ends with 'pump' and program_id is None) + return service.use_route(TradingRoute.PUMP) + diff --git a/tests/trading/test_executor.py b/tests/trading/test_executor.py index 549c3d6..ced9609 100644 --- a/tests/trading/test_executor.py +++ b/tests/trading/test_executor.py @@ -4,7 +4,11 @@ @pytest.mark.asyncio -async def test_exec(executor, swap_event_from_logs_second): +async def test_exec_second(executor, swap_event_from_logs_second): sig = await executor.exec(swap_event_from_logs_second) assert sig is not None +@pytest.mark.asyncio +async def test_exec_sixth(executor, swap_event_from_logs_sixth): + sig = await executor.exec(swap_event_from_logs_sixth) + assert sig is not None diff --git a/tests/trading/test_route.py b/tests/trading/test_route.py index d4c1844..af8a5b5 100644 --- a/tests/trading/test_route.py +++ b/tests/trading/test_route.py @@ -12,10 +12,11 @@ @pytest.mark.asyncio @pytest.mark.parametrize("swap_event_fixture,expected_route", [ ("swap_event_from_logs", TradingRoute.PUMP), - ("swap_event_from_logs_second", TradingRoute.PUMP), + ("swap_event_from_logs_second", TradingRoute.DEX), ("swap_event_from_logs_third", TradingRoute.DEX), ("swap_event_from_logs_fourth", TradingRoute.PUMP), ("swap_event_from_logs_fifth", TradingRoute.DEX), + ("swap_event_from_logs_sixth", TradingRoute.PUMP), ]) async def test_find_route(executor, request, swap_event_fixture, expected_route): """Test the find_trading_route method with both log examples"""