pumpfun-toolkit 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pumpfun_toolkit/__init__.py +79 -0
- pumpfun_toolkit/borsh.py +68 -0
- pumpfun_toolkit/constants.py +27 -0
- pumpfun_toolkit/curve.py +147 -0
- pumpfun_toolkit/errors.py +44 -0
- pumpfun_toolkit/events.py +260 -0
- pumpfun_toolkit/fees.py +64 -0
- pumpfun_toolkit/mint.py +134 -0
- pumpfun_toolkit/py.typed +0 -0
- pumpfun_toolkit/redact.py +138 -0
- pumpfun_toolkit/risk.py +375 -0
- pumpfun_toolkit/rpc.py +422 -0
- pumpfun_toolkit/text.py +12 -0
- pumpfun_toolkit-0.1.1.dist-info/METADATA +290 -0
- pumpfun_toolkit-0.1.1.dist-info/RECORD +17 -0
- pumpfun_toolkit-0.1.1.dist-info/WHEEL +4 -0
- pumpfun_toolkit-0.1.1.dist-info/licenses/LICENSE +21 -0
pumpfun_toolkit/mint.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Parse a mint account (SPL Token and Token-2022), including its extensions.
|
|
2
|
+
|
|
3
|
+
Layout according to ``solana-program/token`` and ``solana-program/token-2022``:
|
|
4
|
+
|
|
5
|
+
- The first 82 bytes are identical in both programs: mint authority, supply,
|
|
6
|
+
decimals, initialized flag, freeze authority.
|
|
7
|
+
- Token-2022 pads with zeros up to byte 165, stores the account type at byte 165
|
|
8
|
+
(1 = mint) and from byte 166 the extensions as a sequence of type (u16),
|
|
9
|
+
length (u16) and value.
|
|
10
|
+
|
|
11
|
+
Extensions can make a token unsellable or give the issuer access to other
|
|
12
|
+
people's balances. Hence the rule: anything not explicitly known to be harmless
|
|
13
|
+
is reported.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import struct
|
|
17
|
+
from dataclasses import dataclass, field
|
|
18
|
+
|
|
19
|
+
from solders.pubkey import Pubkey
|
|
20
|
+
|
|
21
|
+
from pumpfun_toolkit.constants import TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID
|
|
22
|
+
from pumpfun_toolkit.errors import MintDecodeError
|
|
23
|
+
|
|
24
|
+
MINT_BASE_LENGTH = 82
|
|
25
|
+
_ACCOUNT_TYPE_OFFSET = 165
|
|
26
|
+
_ACCOUNT_TYPE_MINT = 1
|
|
27
|
+
|
|
28
|
+
# Numbers from ``ExtensionType`` in token-2022 (interface/src/extension/mod.rs).
|
|
29
|
+
EXTENSION_NAMES = {
|
|
30
|
+
1: "TransferFeeConfig",
|
|
31
|
+
3: "MintCloseAuthority",
|
|
32
|
+
4: "ConfidentialTransferMint",
|
|
33
|
+
6: "DefaultAccountState",
|
|
34
|
+
9: "NonTransferable",
|
|
35
|
+
10: "InterestBearingConfig",
|
|
36
|
+
12: "PermanentDelegate",
|
|
37
|
+
14: "TransferHook",
|
|
38
|
+
16: "ConfidentialTransferFeeConfig",
|
|
39
|
+
18: "MetadataPointer",
|
|
40
|
+
19: "TokenMetadata",
|
|
41
|
+
20: "GroupPointer",
|
|
42
|
+
21: "TokenGroup",
|
|
43
|
+
22: "GroupMemberPointer",
|
|
44
|
+
23: "TokenGroupMember",
|
|
45
|
+
24: "ConfidentialMintBurn",
|
|
46
|
+
25: "ScaledUiAmount",
|
|
47
|
+
26: "Pausable",
|
|
48
|
+
28: "PermissionedBurn",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# Metadata only: they do not change who may move or freeze tokens.
|
|
52
|
+
HARMLESS_EXTENSIONS = frozenset({18, 19})
|
|
53
|
+
|
|
54
|
+
# Can block selling, seize balances, divert fees or change the supply.
|
|
55
|
+
DANGEROUS_EXTENSIONS = {
|
|
56
|
+
1: "The issuer can withhold a fee on every transfer.",
|
|
57
|
+
3: "The issuer can close the mint account.",
|
|
58
|
+
4: "Confidential transfers: balances cannot be audited.",
|
|
59
|
+
6: "New accounts can be created frozen; selling may be impossible.",
|
|
60
|
+
9: "The token cannot be transferred.",
|
|
61
|
+
10: "Displayed balances change through an interest rate.",
|
|
62
|
+
12: "A permanent delegate can move tokens out of any account.",
|
|
63
|
+
14: "Every transfer calls a third-party program that can reject it.",
|
|
64
|
+
16: "Confidential fees: withheld amounts cannot be audited.",
|
|
65
|
+
24: "Tokens can be minted and burned invisibly.",
|
|
66
|
+
25: "The issuer can scale displayed balances.",
|
|
67
|
+
26: "The issuer can pause all transfers.",
|
|
68
|
+
28: "Burning requires the issuer's approval.",
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass(frozen=True)
|
|
73
|
+
class MintInfo:
|
|
74
|
+
"""The security-relevant fields of a mint account."""
|
|
75
|
+
|
|
76
|
+
program: str
|
|
77
|
+
mint_authority: str | None
|
|
78
|
+
freeze_authority: str | None
|
|
79
|
+
supply: int
|
|
80
|
+
decimals: int
|
|
81
|
+
extensions: list[int] = field(default_factory=list)
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def is_token_2022(self) -> bool:
|
|
85
|
+
return self.program == TOKEN_2022_PROGRAM_ID
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _optional_key(data: bytes, offset: int) -> str | None:
|
|
89
|
+
tag = struct.unpack_from("<I", data, offset)[0]
|
|
90
|
+
if tag == 0:
|
|
91
|
+
return None
|
|
92
|
+
if tag != 1:
|
|
93
|
+
raise MintDecodeError("invalid option tag for an authority")
|
|
94
|
+
return str(Pubkey.from_bytes(data[offset + 4 : offset + 36]))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def parse_mint(owner_program: str, data: bytes) -> MintInfo:
|
|
98
|
+
"""Decode the raw data of a mint account.
|
|
99
|
+
|
|
100
|
+
``owner_program`` is the account owner as returned by ``getAccountInfo``.
|
|
101
|
+
Raises :class:`~pumpfun_toolkit.errors.MintDecodeError` for anything that is
|
|
102
|
+
not an initialized mint of one of the two token programs.
|
|
103
|
+
"""
|
|
104
|
+
if owner_program not in (TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID):
|
|
105
|
+
raise MintDecodeError("account is not owned by a token program")
|
|
106
|
+
if len(data) < MINT_BASE_LENGTH:
|
|
107
|
+
raise MintDecodeError("account is too short for a mint")
|
|
108
|
+
if data[45] != 1:
|
|
109
|
+
raise MintDecodeError("mint is not initialized")
|
|
110
|
+
|
|
111
|
+
extensions: list[int] = []
|
|
112
|
+
if owner_program == TOKEN_2022_PROGRAM_ID and len(data) > _ACCOUNT_TYPE_OFFSET:
|
|
113
|
+
if data[_ACCOUNT_TYPE_OFFSET] != _ACCOUNT_TYPE_MINT:
|
|
114
|
+
raise MintDecodeError("account is not a mint")
|
|
115
|
+
offset = _ACCOUNT_TYPE_OFFSET + 1
|
|
116
|
+
while offset + 4 <= len(data):
|
|
117
|
+
kind, length = struct.unpack_from("<HH", data, offset)
|
|
118
|
+
if kind == 0: # Uninitialized: only padding from here on
|
|
119
|
+
break
|
|
120
|
+
if offset + 4 + length > len(data):
|
|
121
|
+
raise MintDecodeError("an extension extends beyond the account")
|
|
122
|
+
extensions.append(kind)
|
|
123
|
+
offset += 4 + length
|
|
124
|
+
elif owner_program == TOKEN_PROGRAM_ID and len(data) != MINT_BASE_LENGTH:
|
|
125
|
+
raise MintDecodeError("unexpected length for an SPL mint")
|
|
126
|
+
|
|
127
|
+
return MintInfo(
|
|
128
|
+
program=owner_program,
|
|
129
|
+
mint_authority=_optional_key(data, 0),
|
|
130
|
+
freeze_authority=_optional_key(data, 46),
|
|
131
|
+
supply=struct.unpack_from("<Q", data, 36)[0],
|
|
132
|
+
decimals=data[44],
|
|
133
|
+
extensions=extensions,
|
|
134
|
+
)
|
pumpfun_toolkit/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Masking of RPC endpoint URLs.
|
|
2
|
+
|
|
3
|
+
RPC providers put API keys into the URL: into the query (``?api-key=...``), into
|
|
4
|
+
the path (``/v2/<key>``) or into the user info (``https://user:token@host``).
|
|
5
|
+
This module turns such a URL into a form that is safe to show and keeps its
|
|
6
|
+
secret parts out of the log lines written by ``httpx``.
|
|
7
|
+
|
|
8
|
+
:func:`redact_url` is public. The log filter is internal: ``SolanaRpcClient``
|
|
9
|
+
installs it on the ``httpx`` logger only when you pass in your own
|
|
10
|
+
``httpx.AsyncClient`` (see the README section "API keys and logging").
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import threading
|
|
15
|
+
|
|
16
|
+
import httpx
|
|
17
|
+
|
|
18
|
+
REDACTED = "***"
|
|
19
|
+
INVALID_URL = "<invalid URL>"
|
|
20
|
+
|
|
21
|
+
# Path segments and query values shorter than this are not treated as secrets
|
|
22
|
+
# ("v2", "rpc", "mainnet"); real API keys are much longer.
|
|
23
|
+
MIN_SECRET_LENGTH = 8
|
|
24
|
+
|
|
25
|
+
_HTTPX_LOGGER = "httpx"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _has_secret_parts(url: httpx.URL) -> bool:
|
|
29
|
+
return bool(url.query or url.userinfo or url.fragment or url.path not in ("", "/"))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def redact_url(url: "str | httpx.URL") -> str:
|
|
33
|
+
"""Return ``url`` with everything except scheme, host and port masked.
|
|
34
|
+
|
|
35
|
+
``https://mainnet.helius-rpc.com/?api-key=abc`` becomes
|
|
36
|
+
``https://mainnet.helius-rpc.com/***``. A URL without user info, path or
|
|
37
|
+
query is returned unchanged. Anything that is not an absolute URL becomes
|
|
38
|
+
``"<invalid URL>"``, so the input is never echoed.
|
|
39
|
+
"""
|
|
40
|
+
try:
|
|
41
|
+
parsed = httpx.URL(url)
|
|
42
|
+
except (httpx.InvalidURL, TypeError):
|
|
43
|
+
return INVALID_URL
|
|
44
|
+
if not parsed.scheme or not parsed.host:
|
|
45
|
+
return INVALID_URL
|
|
46
|
+
if not _has_secret_parts(parsed):
|
|
47
|
+
return str(parsed)
|
|
48
|
+
return f"{parsed.scheme}://{parsed.netloc.decode('ascii')}/{REDACTED}"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def secret_replacements(url: "str | httpx.URL") -> tuple[tuple[str, str], ...]:
|
|
52
|
+
"""Pairs of (secret text, replacement) for one endpoint URL, longest first.
|
|
53
|
+
|
|
54
|
+
The complete URL (as given and as ``httpx`` prints it) is replaced by its
|
|
55
|
+
redacted form; user name, password, path segments and query values of at
|
|
56
|
+
least :data:`MIN_SECRET_LENGTH` characters are replaced by ``***``, in both
|
|
57
|
+
decoded and percent-encoded spelling.
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
parsed = httpx.URL(url)
|
|
61
|
+
except (httpx.InvalidURL, TypeError):
|
|
62
|
+
return ()
|
|
63
|
+
if not _has_secret_parts(parsed):
|
|
64
|
+
return ()
|
|
65
|
+
display = redact_url(parsed)
|
|
66
|
+
pairs: dict[str, str] = {str(url): display, str(parsed): display}
|
|
67
|
+
|
|
68
|
+
tokens = {parsed.username, parsed.password, parsed.userinfo.decode("ascii")}
|
|
69
|
+
tokens.update(parsed.path.split("/"))
|
|
70
|
+
tokens.update(parsed.raw_path.decode("ascii").split("?")[0].split("/"))
|
|
71
|
+
query = parsed.query.decode("ascii")
|
|
72
|
+
tokens.add(query)
|
|
73
|
+
for part in query.split("&"):
|
|
74
|
+
tokens.update(part.split("=", 1))
|
|
75
|
+
for _, value in parsed.params.multi_items():
|
|
76
|
+
tokens.add(value)
|
|
77
|
+
for token in tokens:
|
|
78
|
+
if len(token) >= MIN_SECRET_LENGTH and token not in pairs:
|
|
79
|
+
pairs[token] = REDACTED
|
|
80
|
+
return tuple(sorted(pairs.items(), key=lambda pair: len(pair[0]), reverse=True))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def mask(text: str, replacements: tuple[tuple[str, str], ...]) -> str:
|
|
84
|
+
"""Replace every secret of ``replacements`` in ``text``."""
|
|
85
|
+
for secret, replacement in replacements:
|
|
86
|
+
text = text.replace(secret, replacement)
|
|
87
|
+
return text
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class SecretLogFilter(logging.Filter):
|
|
91
|
+
"""Rewrites log records that contain a registered endpoint secret.
|
|
92
|
+
|
|
93
|
+
Records without such a secret pass through untouched, including their
|
|
94
|
+
``msg`` and ``args``. The filter never drops a record.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
def __init__(self) -> None:
|
|
98
|
+
super().__init__()
|
|
99
|
+
self._lock = threading.Lock()
|
|
100
|
+
self._replacements: tuple[tuple[str, str], ...] = ()
|
|
101
|
+
|
|
102
|
+
def register(self, replacements: tuple[tuple[str, str], ...]) -> None:
|
|
103
|
+
with self._lock:
|
|
104
|
+
merged = dict(self._replacements)
|
|
105
|
+
merged.update(replacements)
|
|
106
|
+
self._replacements = tuple(
|
|
107
|
+
sorted(merged.items(), key=lambda pair: len(pair[0]), reverse=True)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
111
|
+
replacements = self._replacements
|
|
112
|
+
if not replacements:
|
|
113
|
+
return True
|
|
114
|
+
try:
|
|
115
|
+
message = record.getMessage()
|
|
116
|
+
except Exception: # a broken record: leave it to logging's own error handling
|
|
117
|
+
return True
|
|
118
|
+
masked = mask(message, replacements)
|
|
119
|
+
if masked != message:
|
|
120
|
+
record.msg, record.args = masked, ()
|
|
121
|
+
return True
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
_LOG_FILTER = SecretLogFilter()
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def protect_httpx_log(replacements: tuple[tuple[str, str], ...]) -> None:
|
|
128
|
+
"""Register secrets and make sure the filter sits on the ``httpx`` logger.
|
|
129
|
+
|
|
130
|
+
The filter is added once. It changes neither levels nor handlers, and it
|
|
131
|
+
only rewrites records that contain one of the registered secrets.
|
|
132
|
+
"""
|
|
133
|
+
if not replacements:
|
|
134
|
+
return
|
|
135
|
+
_LOG_FILTER.register(replacements)
|
|
136
|
+
logger = logging.getLogger(_HTTPX_LOGGER)
|
|
137
|
+
if _LOG_FILTER not in logger.filters:
|
|
138
|
+
logger.addFilter(_LOG_FILTER)
|
pumpfun_toolkit/risk.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"""Heuristic risk assessment of a Pump.fun token. A pure function over collected facts.
|
|
2
|
+
|
|
3
|
+
The result is a score from 0 to 100 (100 = no red flag found) and a verdict:
|
|
4
|
+
|
|
5
|
+
- ``blocked``: there is a critical finding, or required information is missing.
|
|
6
|
+
The score is then irrelevant.
|
|
7
|
+
- ``risky``: no blocking reason, but the score is below the threshold.
|
|
8
|
+
- ``passed``: no blocking reason and the score is at or above the threshold.
|
|
9
|
+
|
|
10
|
+
.. warning::
|
|
11
|
+
``passed`` is **not** a buy signal and not financial advice. It only means
|
|
12
|
+
that these particular checks found nothing. Many kinds of fraud are not
|
|
13
|
+
detected by any of these rules. The penalties and thresholds are assumptions
|
|
14
|
+
and have **not** been validated against market data.
|
|
15
|
+
|
|
16
|
+
The caller supplies the facts. On-chain facts (mint, bonding curve) can be read
|
|
17
|
+
with :mod:`pumpfun_toolkit.mint` and :mod:`pumpfun_toolkit.curve`; trading facts
|
|
18
|
+
(holders, volumes, sellers) must be derived by the caller, for example from
|
|
19
|
+
decoded :class:`~pumpfun_toolkit.events.TradeEvent` objects.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from dataclasses import dataclass, field
|
|
23
|
+
from decimal import Decimal
|
|
24
|
+
from typing import Literal
|
|
25
|
+
|
|
26
|
+
from pumpfun_toolkit.constants import LAMPORTS_PER_SOL
|
|
27
|
+
from pumpfun_toolkit.curve import BondingCurveAccount
|
|
28
|
+
from pumpfun_toolkit.mint import (
|
|
29
|
+
DANGEROUS_EXTENSIONS,
|
|
30
|
+
EXTENSION_NAMES,
|
|
31
|
+
HARMLESS_EXTENSIONS,
|
|
32
|
+
MintInfo,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
Severity = Literal["critical", "high", "medium", "low"]
|
|
36
|
+
Verdict = Literal["blocked", "risky", "passed"]
|
|
37
|
+
|
|
38
|
+
PASS_THRESHOLD = 60
|
|
39
|
+
MIN_DISTINCT_SELLERS = 2
|
|
40
|
+
|
|
41
|
+
_SEVERITY_ORDER = ("critical", "high", "medium", "low")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class Finding:
|
|
46
|
+
"""One red flag. ``penalty`` is subtracted from the score; critical findings block."""
|
|
47
|
+
|
|
48
|
+
code: str
|
|
49
|
+
severity: Severity
|
|
50
|
+
message: str
|
|
51
|
+
penalty: int = 0
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class TokenFacts:
|
|
56
|
+
"""What the caller observed about the token since its creation."""
|
|
57
|
+
|
|
58
|
+
mint: str
|
|
59
|
+
creator: str
|
|
60
|
+
quote_is_sol: bool
|
|
61
|
+
is_mayhem_mode: bool
|
|
62
|
+
creator_sold: bool
|
|
63
|
+
token_total_supply: int
|
|
64
|
+
buy_volume_lamports: int
|
|
65
|
+
sell_volume_lamports: int
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True)
|
|
69
|
+
class HolderFacts:
|
|
70
|
+
"""Holdings and trading per wallet, as derived by the caller from observed trades.
|
|
71
|
+
|
|
72
|
+
Transfers between wallets are not visible in trade events; the real
|
|
73
|
+
distribution may differ.
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
holders: int
|
|
77
|
+
top1_tokens: int
|
|
78
|
+
top10_tokens: int
|
|
79
|
+
creator_tokens: int
|
|
80
|
+
distinct_sellers: int
|
|
81
|
+
top_buyer_lamports: int
|
|
82
|
+
buyers_in_first_seconds: int
|
|
83
|
+
network_members: int
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass(frozen=True)
|
|
87
|
+
class SecurityInputs:
|
|
88
|
+
"""All inputs of :func:`assess`. Missing parts are ``None`` and block the verdict."""
|
|
89
|
+
|
|
90
|
+
mint: str
|
|
91
|
+
token: TokenFacts | None = None
|
|
92
|
+
mint_info: MintInfo | None = None
|
|
93
|
+
mint_error: str | None = None
|
|
94
|
+
curve: BondingCurveAccount | None = None
|
|
95
|
+
curve_error: str | None = None
|
|
96
|
+
holders: HolderFacts | None = None
|
|
97
|
+
creator_token_count: int = 0
|
|
98
|
+
trade_lamports: int = LAMPORTS_PER_SOL // 20
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@dataclass(frozen=True)
|
|
102
|
+
class Assessment:
|
|
103
|
+
"""The result of :func:`assess`."""
|
|
104
|
+
|
|
105
|
+
mint: str
|
|
106
|
+
score: int
|
|
107
|
+
verdict: Verdict
|
|
108
|
+
findings: list[Finding] = field(default_factory=list)
|
|
109
|
+
missing: list[str] = field(default_factory=list)
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def blocked(self) -> bool:
|
|
113
|
+
return self.verdict == "blocked"
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _share(part: int, total: int) -> Decimal:
|
|
117
|
+
return Decimal(part) / total if total > 0 else Decimal(0)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _percent(value: Decimal) -> str:
|
|
121
|
+
return f"{(value * 100).quantize(Decimal('0.1'))}%"
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _check_mint(info: MintInfo, token: TokenFacts | None) -> list[Finding]:
|
|
125
|
+
findings = []
|
|
126
|
+
if info.mint_authority is not None:
|
|
127
|
+
findings.append(
|
|
128
|
+
Finding(
|
|
129
|
+
"MINT_AUTHORITY",
|
|
130
|
+
"critical",
|
|
131
|
+
"The mint authority is active: new tokens can be minted at any time.",
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
if info.freeze_authority is not None:
|
|
135
|
+
findings.append(
|
|
136
|
+
Finding(
|
|
137
|
+
"FREEZE_AUTHORITY",
|
|
138
|
+
"critical",
|
|
139
|
+
"The freeze authority is active: balances can be frozen.",
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
for kind in info.extensions:
|
|
143
|
+
if kind in HARMLESS_EXTENSIONS:
|
|
144
|
+
continue
|
|
145
|
+
name = EXTENSION_NAMES.get(kind, f"number {kind}")
|
|
146
|
+
reason = DANGEROUS_EXTENSIONS.get(kind, "Unknown extension; its effect cannot be assessed.")
|
|
147
|
+
findings.append(Finding("TOKEN_EXTENSION", "critical", f"Token extension {name}: {reason}"))
|
|
148
|
+
if token and info.supply > token.token_total_supply:
|
|
149
|
+
findings.append(
|
|
150
|
+
Finding(
|
|
151
|
+
"SUPPLY_INFLATED",
|
|
152
|
+
"critical",
|
|
153
|
+
"More tokens are in circulation than the bonding curve reports.",
|
|
154
|
+
)
|
|
155
|
+
)
|
|
156
|
+
elif token and info.supply < token.token_total_supply:
|
|
157
|
+
# Burned tokens reduce the supply. That does not harm holders, so it costs
|
|
158
|
+
# no points; it is only noted.
|
|
159
|
+
burned = _share(token.token_total_supply - info.supply, token.token_total_supply)
|
|
160
|
+
findings.append(
|
|
161
|
+
Finding("SUPPLY_BURNED", "low", f"{_percent(burned)} of the tokens have been burned.")
|
|
162
|
+
)
|
|
163
|
+
return findings
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def _check_curve(
|
|
167
|
+
curve: BondingCurveAccount, token: TokenFacts, trade_lamports: int
|
|
168
|
+
) -> list[Finding]:
|
|
169
|
+
findings = []
|
|
170
|
+
if curve.creator != token.creator:
|
|
171
|
+
findings.append(
|
|
172
|
+
Finding(
|
|
173
|
+
"CREATOR_MISMATCH",
|
|
174
|
+
"critical",
|
|
175
|
+
"The on-chain creator differs from the observed creator.",
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
if not curve.quote_is_sol:
|
|
179
|
+
findings.append(
|
|
180
|
+
Finding("NOT_SOL", "critical", "The quote asset is not SOL; cannot be assessed.")
|
|
181
|
+
)
|
|
182
|
+
if curve.state.complete:
|
|
183
|
+
findings.append(
|
|
184
|
+
Finding(
|
|
185
|
+
"CURVE_COMPLETE",
|
|
186
|
+
"critical",
|
|
187
|
+
"The bonding curve is complete; it can no longer be traded.",
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
return findings
|
|
191
|
+
|
|
192
|
+
liquidity = curve.state.liquidity_lamports
|
|
193
|
+
if liquidity < 1 * LAMPORTS_PER_SOL:
|
|
194
|
+
findings.append(Finding("LOW_LIQUIDITY", "high", "Less than 1 SOL sits in the curve.", 20))
|
|
195
|
+
elif liquidity < 3 * LAMPORTS_PER_SOL:
|
|
196
|
+
findings.append(Finding("LOW_LIQUIDITY", "medium", "Less than 3 SOL sit in the curve.", 10))
|
|
197
|
+
impact = curve.state.price_impact(trade_lamports)
|
|
198
|
+
if impact is not None and impact > Decimal("0.02"):
|
|
199
|
+
findings.append(
|
|
200
|
+
Finding(
|
|
201
|
+
"PRICE_IMPACT",
|
|
202
|
+
"medium",
|
|
203
|
+
f"A buy of the configured trade size lifts the price by {_percent(impact)}.",
|
|
204
|
+
10,
|
|
205
|
+
)
|
|
206
|
+
)
|
|
207
|
+
return findings
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _check_trading(token: TokenFacts, holders: HolderFacts, creator_tokens: int) -> list[Finding]:
|
|
211
|
+
findings = []
|
|
212
|
+
supply = token.token_total_supply
|
|
213
|
+
|
|
214
|
+
if token.creator_sold:
|
|
215
|
+
findings.append(Finding("CREATOR_SOLD", "critical", "The creator has already sold."))
|
|
216
|
+
|
|
217
|
+
top1 = _share(holders.top1_tokens, supply)
|
|
218
|
+
if top1 > Decimal("0.20"):
|
|
219
|
+
findings.append(
|
|
220
|
+
Finding("TOP_HOLDER", "high", f"One wallet holds {_percent(top1)} of all tokens.", 30)
|
|
221
|
+
)
|
|
222
|
+
elif top1 > Decimal("0.10"):
|
|
223
|
+
findings.append(
|
|
224
|
+
Finding("TOP_HOLDER", "medium", f"One wallet holds {_percent(top1)} of all tokens.", 15)
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
top10 = _share(holders.top10_tokens, supply)
|
|
228
|
+
if top10 > Decimal("0.60"):
|
|
229
|
+
findings.append(
|
|
230
|
+
Finding("TOP10_HOLDERS", "high", f"Ten wallets hold {_percent(top10)}.", 25)
|
|
231
|
+
)
|
|
232
|
+
elif top10 > Decimal("0.40"):
|
|
233
|
+
findings.append(
|
|
234
|
+
Finding("TOP10_HOLDERS", "medium", f"Ten wallets hold {_percent(top10)}.", 10)
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
creator = _share(holders.creator_tokens, supply)
|
|
238
|
+
if creator > Decimal("0.10"):
|
|
239
|
+
findings.append(
|
|
240
|
+
Finding("CREATOR_SHARE", "high", f"The creator holds {_percent(creator)}.", 25)
|
|
241
|
+
)
|
|
242
|
+
elif creator > Decimal("0.05"):
|
|
243
|
+
findings.append(
|
|
244
|
+
Finding("CREATOR_SHARE", "medium", f"The creator holds {_percent(creator)}.", 10)
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
if holders.holders < 10:
|
|
248
|
+
findings.append(
|
|
249
|
+
Finding("FEW_HOLDERS", "medium", f"Only {holders.holders} wallets hold the token.", 10)
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
buyer_share = _share(holders.top_buyer_lamports, token.buy_volume_lamports)
|
|
253
|
+
if buyer_share > Decimal("0.40"):
|
|
254
|
+
findings.append(
|
|
255
|
+
Finding(
|
|
256
|
+
"VOLUME_CONCENTRATION",
|
|
257
|
+
"medium",
|
|
258
|
+
f"One wallet accounts for {_percent(buyer_share)} of the buy volume.",
|
|
259
|
+
15,
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
pressure = _share(token.sell_volume_lamports, token.buy_volume_lamports)
|
|
264
|
+
if pressure > Decimal("0.80"):
|
|
265
|
+
findings.append(
|
|
266
|
+
Finding(
|
|
267
|
+
"SELL_PRESSURE",
|
|
268
|
+
"medium",
|
|
269
|
+
f"Sell volume amounts to {_percent(pressure)} of buy volume.",
|
|
270
|
+
15,
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
if holders.buyers_in_first_seconds >= 5:
|
|
275
|
+
findings.append(
|
|
276
|
+
Finding(
|
|
277
|
+
"BUNDLED_LAUNCH",
|
|
278
|
+
"medium",
|
|
279
|
+
f"{holders.buyers_in_first_seconds} wallets bought within the first two seconds.",
|
|
280
|
+
15,
|
|
281
|
+
)
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
if holders.network_members >= 3:
|
|
285
|
+
findings.append(
|
|
286
|
+
Finding(
|
|
287
|
+
"WALLET_NETWORK",
|
|
288
|
+
"high",
|
|
289
|
+
f"{holders.network_members} early buyers belong to a detected wallet network.",
|
|
290
|
+
20,
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
if creator_tokens >= 10:
|
|
295
|
+
findings.append(
|
|
296
|
+
Finding(
|
|
297
|
+
"SERIAL_CREATOR",
|
|
298
|
+
"high",
|
|
299
|
+
f"The creator launched {creator_tokens} tokens within a short time.",
|
|
300
|
+
30,
|
|
301
|
+
)
|
|
302
|
+
)
|
|
303
|
+
elif creator_tokens >= 3:
|
|
304
|
+
findings.append(
|
|
305
|
+
Finding(
|
|
306
|
+
"SERIAL_CREATOR",
|
|
307
|
+
"medium",
|
|
308
|
+
f"The creator launched {creator_tokens} tokens within a short time.",
|
|
309
|
+
15,
|
|
310
|
+
)
|
|
311
|
+
)
|
|
312
|
+
return findings
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def assess(inputs: SecurityInputs) -> Assessment:
|
|
316
|
+
"""Assess a token from the given facts. See the module docstring for the caveats."""
|
|
317
|
+
findings: list[Finding] = []
|
|
318
|
+
missing: list[str] = []
|
|
319
|
+
token = inputs.token
|
|
320
|
+
|
|
321
|
+
if token is None:
|
|
322
|
+
missing.append("The token was not observed since its creation.")
|
|
323
|
+
else:
|
|
324
|
+
if not token.quote_is_sol:
|
|
325
|
+
findings.append(
|
|
326
|
+
Finding("NOT_SOL", "critical", "The quote asset is not SOL; cannot be assessed.")
|
|
327
|
+
)
|
|
328
|
+
if token.is_mayhem_mode:
|
|
329
|
+
findings.append(
|
|
330
|
+
Finding(
|
|
331
|
+
"MAYHEM_MODE",
|
|
332
|
+
"critical",
|
|
333
|
+
"Mayhem mode: the curve behaves differently and cannot be assessed.",
|
|
334
|
+
)
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
if inputs.mint_info is None:
|
|
338
|
+
missing.append(inputs.mint_error or "The mint account could not be read.")
|
|
339
|
+
else:
|
|
340
|
+
findings.extend(_check_mint(inputs.mint_info, token))
|
|
341
|
+
|
|
342
|
+
if inputs.curve is None:
|
|
343
|
+
missing.append(inputs.curve_error or "The bonding curve could not be read.")
|
|
344
|
+
elif token is not None:
|
|
345
|
+
findings.extend(_check_curve(inputs.curve, token, inputs.trade_lamports))
|
|
346
|
+
|
|
347
|
+
if token is not None:
|
|
348
|
+
if inputs.holders is None:
|
|
349
|
+
missing.append("No trading data about the holders is available.")
|
|
350
|
+
else:
|
|
351
|
+
findings.extend(_check_trading(token, inputs.holders, inputs.creator_token_count))
|
|
352
|
+
if inputs.holders.distinct_sellers < MIN_DISTINCT_SELLERS:
|
|
353
|
+
missing.append(
|
|
354
|
+
"Sellability not demonstrated: fewer than "
|
|
355
|
+
f"{MIN_DISTINCT_SELLERS} distinct wallets have sold successfully."
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
# List identical findings from two sources (such as NOT_SOL) only once.
|
|
359
|
+
unique: dict[tuple[str, str], Finding] = {}
|
|
360
|
+
for finding in findings:
|
|
361
|
+
unique.setdefault((finding.code, finding.message), finding)
|
|
362
|
+
findings = sorted(
|
|
363
|
+
unique.values(),
|
|
364
|
+
key=lambda f: (_SEVERITY_ORDER.index(f.severity), -f.penalty, f.code),
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
score = max(0, 100 - sum(f.penalty for f in findings))
|
|
368
|
+
critical = any(f.severity == "critical" for f in findings)
|
|
369
|
+
if critical or missing:
|
|
370
|
+
verdict: Verdict = "blocked"
|
|
371
|
+
if critical:
|
|
372
|
+
score = 0
|
|
373
|
+
else:
|
|
374
|
+
verdict = "passed" if score >= PASS_THRESHOLD else "risky"
|
|
375
|
+
return Assessment(inputs.mint, score, verdict, findings, missing)
|