Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libs/cache/solbot_cache/launch.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 地址

Expand Down
2 changes: 1 addition & 1 deletion libs/common/solbot_common/utils/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 57 additions & 1 deletion tests/trading/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)


@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)

6 changes: 5 additions & 1 deletion tests/trading/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/trading/test_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down