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/rpc.py
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"""A small, read-only asynchronous JSON-RPC client for Solana.
|
|
2
|
+
|
|
3
|
+
The client only knows reading and simulating methods. ``sendTransaction`` and
|
|
4
|
+
anything else that changes the state of the blockchain is not on the allowlist
|
|
5
|
+
and is rejected before a request leaves the process. This package never signs
|
|
6
|
+
or sends transactions.
|
|
7
|
+
|
|
8
|
+
The node URL may contain an API key. The client keeps it out of its error
|
|
9
|
+
messages, exception details, ``repr`` and log lines, and out of the log lines of
|
|
10
|
+
``httpx``:
|
|
11
|
+
|
|
12
|
+
- With the client's own HTTP client (no ``http`` argument), ``httpx`` only ever
|
|
13
|
+
sees the redacted URL (``https://host/***``). A private transport puts the real
|
|
14
|
+
URL in at the last step, just before the request goes to the network. Nothing
|
|
15
|
+
in the logging configuration changes.
|
|
16
|
+
- With an ``httpx.AsyncClient`` you pass in, the request has to carry the real
|
|
17
|
+
URL. The client then adds a filter to the ``httpx`` logger that masks this URL
|
|
18
|
+
and its secret parts and leaves every other record untouched.
|
|
19
|
+
|
|
20
|
+
See :mod:`pumpfun_toolkit.redact` and the README section "API keys and logging".
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import asyncio
|
|
24
|
+
import base64
|
|
25
|
+
import logging
|
|
26
|
+
import time
|
|
27
|
+
from dataclasses import dataclass, field
|
|
28
|
+
from types import TracebackType
|
|
29
|
+
from typing import Any
|
|
30
|
+
|
|
31
|
+
import httpx
|
|
32
|
+
|
|
33
|
+
from pumpfun_toolkit.constants import TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID
|
|
34
|
+
from pumpfun_toolkit.errors import InvalidRpcUrlError, MethodNotAllowedError, SolanaRpcError
|
|
35
|
+
from pumpfun_toolkit.redact import mask, protect_httpx_log, redact_url, secret_replacements
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
# Documented methods of the Solana JSON-RPC API (https://solana.com/developers/docs/rpc) that
|
|
40
|
+
# do not change chain state.
|
|
41
|
+
READ_ONLY_METHODS = frozenset(
|
|
42
|
+
{
|
|
43
|
+
"getHealth",
|
|
44
|
+
"getSlot",
|
|
45
|
+
"getBalance",
|
|
46
|
+
"getAccountInfo",
|
|
47
|
+
"getSignaturesForAddress",
|
|
48
|
+
"getTransaction",
|
|
49
|
+
"getTokenAccountsByOwner",
|
|
50
|
+
"getLatestBlockhash",
|
|
51
|
+
"getFeeForMessage",
|
|
52
|
+
"getRecentPrioritizationFees",
|
|
53
|
+
"simulateTransaction",
|
|
54
|
+
"getSignatureStatuses",
|
|
55
|
+
"getBlockHeight",
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
_RETRY_STATUS = {429, 500, 502, 503, 504}
|
|
60
|
+
|
|
61
|
+
# Nodes reject queries for transactions newer than the version given here. Mainnet
|
|
62
|
+
# has carried version-1 transactions since 2026.
|
|
63
|
+
MAX_TRANSACTION_VERSION = 1
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass(frozen=True)
|
|
67
|
+
class TokenBalance:
|
|
68
|
+
mint: str
|
|
69
|
+
amount: int # base units
|
|
70
|
+
decimals: int
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def ui_amount(self) -> str:
|
|
74
|
+
"""The amount as a decimal string without trailing zeros."""
|
|
75
|
+
if self.decimals == 0:
|
|
76
|
+
return str(self.amount)
|
|
77
|
+
whole, frac = divmod(self.amount, 10**self.decimals)
|
|
78
|
+
return f"{whole}.{frac:0{self.decimals}d}".rstrip("0").rstrip(".")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass(frozen=True)
|
|
82
|
+
class SimulationResult:
|
|
83
|
+
ok: bool
|
|
84
|
+
error: Any
|
|
85
|
+
logs: list[str] = field(default_factory=list)
|
|
86
|
+
units_consumed: int | None = None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@dataclass(frozen=True)
|
|
90
|
+
class SignatureStatus:
|
|
91
|
+
confirmed: bool
|
|
92
|
+
error: Any
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _parse_endpoint(url: str) -> tuple[httpx.URL, httpx.Auth | None]:
|
|
96
|
+
"""Validate the endpoint and move ``user:password@`` into a Basic auth header.
|
|
97
|
+
|
|
98
|
+
Errors never repeat the URL, and their exception context is suppressed,
|
|
99
|
+
because ``httpx`` messages may quote parts of it.
|
|
100
|
+
"""
|
|
101
|
+
try:
|
|
102
|
+
parsed = httpx.URL(url)
|
|
103
|
+
except (httpx.InvalidURL, TypeError):
|
|
104
|
+
raise InvalidRpcUrlError("The RPC URL is not a valid URL.") from None
|
|
105
|
+
if parsed.scheme not in ("http", "https") or not parsed.host:
|
|
106
|
+
raise InvalidRpcUrlError("The RPC URL must be an absolute http:// or https:// URL.")
|
|
107
|
+
if not parsed.userinfo:
|
|
108
|
+
return parsed, None
|
|
109
|
+
auth = httpx.BasicAuth(parsed.username, parsed.password)
|
|
110
|
+
return parsed.copy_with(userinfo=b""), auth
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class _EndpointTransport(httpx.AsyncBaseTransport):
|
|
114
|
+
"""Transport of the HTTP client that ``SolanaRpcClient`` creates itself.
|
|
115
|
+
|
|
116
|
+
That HTTP client only ever sees the redacted URL, so ``httpx`` log lines,
|
|
117
|
+
exceptions and ``response.request`` never contain the API key. The request
|
|
118
|
+
is pointed at the real endpoint here, at the last step.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
def __init__(self, endpoint: httpx.URL) -> None:
|
|
122
|
+
self._endpoint = endpoint
|
|
123
|
+
self._network = httpx.AsyncHTTPTransport()
|
|
124
|
+
|
|
125
|
+
def __repr__(self) -> str:
|
|
126
|
+
return f"{type(self).__name__}({redact_url(self._endpoint)!r})"
|
|
127
|
+
|
|
128
|
+
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
|
|
129
|
+
forwarded = httpx.Request(
|
|
130
|
+
request.method,
|
|
131
|
+
self._endpoint,
|
|
132
|
+
headers=request.headers,
|
|
133
|
+
stream=request.stream,
|
|
134
|
+
extensions=request.extensions,
|
|
135
|
+
)
|
|
136
|
+
return await self._network.handle_async_request(forwarded)
|
|
137
|
+
|
|
138
|
+
async def aclose(self) -> None:
|
|
139
|
+
await self._network.aclose()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class SolanaRpcClient:
|
|
143
|
+
"""Read-only Solana RPC client.
|
|
144
|
+
|
|
145
|
+
Pass your own ``httpx.AsyncClient`` to share a connection pool, or omit it and
|
|
146
|
+
use the client as an async context manager::
|
|
147
|
+
|
|
148
|
+
async with SolanaRpcClient("https://api.mainnet-beta.solana.com") as rpc:
|
|
149
|
+
slot = await rpc.get_slot()
|
|
150
|
+
|
|
151
|
+
Transient failures (timeouts, connection errors, HTTP 429/5xx) are retried
|
|
152
|
+
with exponential backoff. RPC-level errors are not retried.
|
|
153
|
+
|
|
154
|
+
The URL may contain an API key; it is kept out of errors, ``repr`` and logs
|
|
155
|
+
(see the module docstring). ``user:password@`` in the URL is sent as a Basic
|
|
156
|
+
auth header. The client's own HTTP client ignores proxy environment
|
|
157
|
+
variables; pass your own ``httpx.AsyncClient(proxy=...)`` if you need one.
|
|
158
|
+
Raises :class:`InvalidRpcUrlError` for anything but an absolute http(s) URL.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
def __init__(
|
|
162
|
+
self,
|
|
163
|
+
url: str,
|
|
164
|
+
http: httpx.AsyncClient | None = None,
|
|
165
|
+
*,
|
|
166
|
+
timeout_seconds: float = 10.0,
|
|
167
|
+
max_retries: int = 2,
|
|
168
|
+
backoff_seconds: float = 0.3,
|
|
169
|
+
) -> None:
|
|
170
|
+
endpoint, auth = _parse_endpoint(url)
|
|
171
|
+
self._endpoint = redact_url(endpoint)
|
|
172
|
+
self._secrets = secret_replacements(url)
|
|
173
|
+
self._auth = auth if auth is not None else httpx.USE_CLIENT_DEFAULT
|
|
174
|
+
self._owns_http = http is None
|
|
175
|
+
if http is None:
|
|
176
|
+
# httpx only ever sees the redacted URL; the transport adds the real one.
|
|
177
|
+
self._request_url = httpx.URL(self._endpoint)
|
|
178
|
+
self._http = httpx.AsyncClient(transport=_EndpointTransport(endpoint))
|
|
179
|
+
else:
|
|
180
|
+
# A caller's client must receive the real URL, so mask it in httpx's log.
|
|
181
|
+
self._request_url = endpoint
|
|
182
|
+
self._http = http
|
|
183
|
+
protect_httpx_log(self._secrets)
|
|
184
|
+
self._timeout = timeout_seconds
|
|
185
|
+
self._max_retries = max_retries
|
|
186
|
+
self._backoff = backoff_seconds
|
|
187
|
+
self._next_id = 0
|
|
188
|
+
|
|
189
|
+
@property
|
|
190
|
+
def endpoint(self) -> str:
|
|
191
|
+
"""The endpoint with API keys masked, safe to log (``https://host/***``)."""
|
|
192
|
+
return self._endpoint
|
|
193
|
+
|
|
194
|
+
def __repr__(self) -> str: # only the redacted endpoint: the URL may contain an API key
|
|
195
|
+
return f"{type(self).__name__}(url={self._endpoint!r})"
|
|
196
|
+
|
|
197
|
+
async def aclose(self) -> None:
|
|
198
|
+
"""Close the HTTP client if this instance created it."""
|
|
199
|
+
if self._owns_http:
|
|
200
|
+
await self._http.aclose()
|
|
201
|
+
|
|
202
|
+
async def __aenter__(self) -> "SolanaRpcClient":
|
|
203
|
+
return self
|
|
204
|
+
|
|
205
|
+
async def __aexit__(
|
|
206
|
+
self,
|
|
207
|
+
exc_type: type[BaseException] | None,
|
|
208
|
+
exc: BaseException | None,
|
|
209
|
+
tb: TracebackType | None,
|
|
210
|
+
) -> None:
|
|
211
|
+
await self.aclose()
|
|
212
|
+
|
|
213
|
+
async def call(self, method: str, params: list[Any] | None = None) -> Any:
|
|
214
|
+
"""Call an allowed method and return its ``result`` field."""
|
|
215
|
+
if method not in READ_ONLY_METHODS:
|
|
216
|
+
raise MethodNotAllowedError(f"RPC method '{method}' is not allowed.")
|
|
217
|
+
|
|
218
|
+
self._next_id += 1
|
|
219
|
+
payload = {"jsonrpc": "2.0", "id": self._next_id, "method": method, "params": params or []}
|
|
220
|
+
last_problem = "unknown"
|
|
221
|
+
|
|
222
|
+
for attempt in range(self._max_retries + 1):
|
|
223
|
+
if attempt:
|
|
224
|
+
await asyncio.sleep(self._backoff * 2 ** (attempt - 1))
|
|
225
|
+
try:
|
|
226
|
+
response = await self._http.post(
|
|
227
|
+
self._request_url, json=payload, timeout=self._timeout, auth=self._auth
|
|
228
|
+
)
|
|
229
|
+
except httpx.TimeoutException:
|
|
230
|
+
last_problem = "timeout"
|
|
231
|
+
continue
|
|
232
|
+
except httpx.HTTPError as exc:
|
|
233
|
+
last_problem = f"connection error ({type(exc).__name__})"
|
|
234
|
+
continue
|
|
235
|
+
|
|
236
|
+
if response.status_code in _RETRY_STATUS:
|
|
237
|
+
last_problem = f"HTTP {response.status_code}"
|
|
238
|
+
continue
|
|
239
|
+
if response.status_code != 200:
|
|
240
|
+
raise SolanaRpcError(
|
|
241
|
+
f"The RPC node answered with HTTP {response.status_code}.",
|
|
242
|
+
details={"method": method},
|
|
243
|
+
)
|
|
244
|
+
try:
|
|
245
|
+
body = response.json()
|
|
246
|
+
except ValueError:
|
|
247
|
+
# No exception chaining: the decode error carries the response body,
|
|
248
|
+
# and an error page may quote the requested URL.
|
|
249
|
+
raise SolanaRpcError(
|
|
250
|
+
"The RPC node did not return a valid response.",
|
|
251
|
+
details={"method": method},
|
|
252
|
+
) from None
|
|
253
|
+
|
|
254
|
+
if "error" in body:
|
|
255
|
+
error = body["error"] or {}
|
|
256
|
+
# The node knows the full URL and might echo it; mask it in its message.
|
|
257
|
+
message = mask(str(error.get("message", "no message")), self._secrets)
|
|
258
|
+
raise SolanaRpcError(
|
|
259
|
+
f"RPC error in {method}: {message}",
|
|
260
|
+
details={"method": method, "rpc_code": error.get("code")},
|
|
261
|
+
)
|
|
262
|
+
return body.get("result")
|
|
263
|
+
|
|
264
|
+
logger.warning("RPC %s failed: %s", method, last_problem)
|
|
265
|
+
raise SolanaRpcError(
|
|
266
|
+
f"The RPC node is unreachable ({last_problem}).",
|
|
267
|
+
details={"method": method, "attempts": self._max_retries + 1},
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
# ---------- Read-only queries ----------
|
|
271
|
+
|
|
272
|
+
async def get_slot(self) -> int:
|
|
273
|
+
return int(await self.call("getSlot", [{"commitment": "confirmed"}]))
|
|
274
|
+
|
|
275
|
+
async def ping(self) -> tuple[int, float]:
|
|
276
|
+
"""Return the current slot and the round-trip time in milliseconds."""
|
|
277
|
+
started = time.perf_counter()
|
|
278
|
+
slot = await self.get_slot()
|
|
279
|
+
return slot, round((time.perf_counter() - started) * 1000, 1)
|
|
280
|
+
|
|
281
|
+
async def get_balance(self, address: str) -> int:
|
|
282
|
+
"""SOL balance in lamports."""
|
|
283
|
+
result = await self.call("getBalance", [address, {"commitment": "confirmed"}])
|
|
284
|
+
return int(result["value"])
|
|
285
|
+
|
|
286
|
+
async def get_account_data(self, address: str) -> tuple[str, bytes] | None:
|
|
287
|
+
"""Owner program and raw data of an account; ``None`` if it does not exist."""
|
|
288
|
+
result = await self.call(
|
|
289
|
+
"getAccountInfo", [address, {"encoding": "base64", "commitment": "confirmed"}]
|
|
290
|
+
)
|
|
291
|
+
value = result.get("value")
|
|
292
|
+
if value is None:
|
|
293
|
+
return None
|
|
294
|
+
return str(value["owner"]), base64.b64decode(value["data"][0])
|
|
295
|
+
|
|
296
|
+
async def get_account_lamports(self, address: str) -> int | None:
|
|
297
|
+
"""Balance of an account; ``None`` if it does not exist."""
|
|
298
|
+
result = await self.call(
|
|
299
|
+
"getAccountInfo", [address, {"encoding": "base64", "commitment": "confirmed"}]
|
|
300
|
+
)
|
|
301
|
+
value = result.get("value")
|
|
302
|
+
return None if value is None else int(value["lamports"])
|
|
303
|
+
|
|
304
|
+
async def get_signatures_for_address(self, address: str, limit: int = 25) -> list[dict]:
|
|
305
|
+
"""The latest transactions of an address, newest first (``limit`` 1-1000)."""
|
|
306
|
+
result = await self.call(
|
|
307
|
+
"getSignaturesForAddress",
|
|
308
|
+
[address, {"limit": max(1, min(limit, 1000)), "commitment": "confirmed"}],
|
|
309
|
+
)
|
|
310
|
+
return list(result or [])
|
|
311
|
+
|
|
312
|
+
async def get_transaction(self, signature: str) -> dict[str, Any] | None:
|
|
313
|
+
"""The confirmed transaction including balances before and after."""
|
|
314
|
+
return await self.call(
|
|
315
|
+
"getTransaction",
|
|
316
|
+
[
|
|
317
|
+
signature,
|
|
318
|
+
{
|
|
319
|
+
"encoding": "json",
|
|
320
|
+
"maxSupportedTransactionVersion": MAX_TRANSACTION_VERSION,
|
|
321
|
+
"commitment": "confirmed",
|
|
322
|
+
},
|
|
323
|
+
],
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
async def get_transaction_logs(self, signature: str) -> list[str] | None:
|
|
327
|
+
"""Log lines of a transaction; ``None`` if it is unknown or failed."""
|
|
328
|
+
result = await self.get_transaction(signature)
|
|
329
|
+
meta = (result or {}).get("meta") or {}
|
|
330
|
+
if meta.get("err") is not None:
|
|
331
|
+
return None
|
|
332
|
+
return meta.get("logMessages")
|
|
333
|
+
|
|
334
|
+
async def get_token_balances(self, owner: str) -> list[TokenBalance]:
|
|
335
|
+
"""Token balances from both token programs, merged per mint."""
|
|
336
|
+
totals: dict[str, tuple[int, int]] = {}
|
|
337
|
+
for program_id in (TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID):
|
|
338
|
+
result = await self.call(
|
|
339
|
+
"getTokenAccountsByOwner",
|
|
340
|
+
[owner, {"programId": program_id}, {"encoding": "jsonParsed"}],
|
|
341
|
+
)
|
|
342
|
+
for entry in result.get("value", []):
|
|
343
|
+
try:
|
|
344
|
+
info = entry["account"]["data"]["parsed"]["info"]
|
|
345
|
+
mint = str(info["mint"])
|
|
346
|
+
amount = int(info["tokenAmount"]["amount"])
|
|
347
|
+
decimals = int(info["tokenAmount"]["decimals"])
|
|
348
|
+
except (KeyError, TypeError, ValueError):
|
|
349
|
+
logger.warning("Skipped a token account with an unexpected layout")
|
|
350
|
+
continue
|
|
351
|
+
previous = totals.get(mint, (0, decimals))[0]
|
|
352
|
+
totals[mint] = (previous + amount, decimals)
|
|
353
|
+
return sorted(
|
|
354
|
+
(
|
|
355
|
+
TokenBalance(mint, amount, decimals)
|
|
356
|
+
for mint, (amount, decimals) in totals.items()
|
|
357
|
+
if amount > 0
|
|
358
|
+
),
|
|
359
|
+
key=lambda t: t.mint,
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
async def get_latest_blockhash(self) -> str:
|
|
363
|
+
return (await self.get_blockhash_with_expiry())[0]
|
|
364
|
+
|
|
365
|
+
async def get_blockhash_with_expiry(self) -> tuple[str, int]:
|
|
366
|
+
"""Blockhash and the block height up to which a transaction using it stays valid."""
|
|
367
|
+
result = await self.call("getLatestBlockhash", [{"commitment": "confirmed"}])
|
|
368
|
+
value = result["value"]
|
|
369
|
+
return str(value["blockhash"]), int(value["lastValidBlockHeight"])
|
|
370
|
+
|
|
371
|
+
async def get_block_height(self) -> int:
|
|
372
|
+
return int(await self.call("getBlockHeight", [{"commitment": "confirmed"}]))
|
|
373
|
+
|
|
374
|
+
async def get_signature_status(self, signature: str) -> SignatureStatus | None:
|
|
375
|
+
"""Status of a transaction; ``None`` while the node does not know it."""
|
|
376
|
+
result = await self.call(
|
|
377
|
+
"getSignatureStatuses", [[signature], {"searchTransactionHistory": False}]
|
|
378
|
+
)
|
|
379
|
+
value = (result.get("value") or [None])[0]
|
|
380
|
+
if value is None:
|
|
381
|
+
return None
|
|
382
|
+
return SignatureStatus(
|
|
383
|
+
confirmed=value.get("confirmationStatus") in ("confirmed", "finalized"),
|
|
384
|
+
error=value.get("err"),
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
async def get_fee_for_message(self, message_base64: str) -> int | None:
|
|
388
|
+
"""Base fee of a message in lamports; ``None`` for an unknown blockhash."""
|
|
389
|
+
result = await self.call("getFeeForMessage", [message_base64, {"commitment": "confirmed"}])
|
|
390
|
+
value = result.get("value")
|
|
391
|
+
return None if value is None else int(value)
|
|
392
|
+
|
|
393
|
+
async def get_recent_prioritization_fees(self) -> list[int]:
|
|
394
|
+
"""Priority fees of recent slots in micro-lamports per compute unit."""
|
|
395
|
+
result = await self.call("getRecentPrioritizationFees", [[]])
|
|
396
|
+
return [int(entry["prioritizationFee"]) for entry in result or []]
|
|
397
|
+
|
|
398
|
+
async def simulate_transaction(self, transaction_base64: str) -> SimulationResult:
|
|
399
|
+
"""Simulate a transaction without sending it.
|
|
400
|
+
|
|
401
|
+
``sigVerify`` is off, so unsigned transactions can be simulated;
|
|
402
|
+
``replaceRecentBlockhash`` keeps the blockhash from going stale.
|
|
403
|
+
"""
|
|
404
|
+
result = await self.call(
|
|
405
|
+
"simulateTransaction",
|
|
406
|
+
[
|
|
407
|
+
transaction_base64,
|
|
408
|
+
{
|
|
409
|
+
"encoding": "base64",
|
|
410
|
+
"sigVerify": False,
|
|
411
|
+
"replaceRecentBlockhash": True,
|
|
412
|
+
"commitment": "confirmed",
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
)
|
|
416
|
+
value = result["value"]
|
|
417
|
+
return SimulationResult(
|
|
418
|
+
ok=value.get("err") is None,
|
|
419
|
+
error=value.get("err"),
|
|
420
|
+
logs=list(value.get("logs") or []),
|
|
421
|
+
units_consumed=value.get("unitsConsumed"),
|
|
422
|
+
)
|
pumpfun_toolkit/text.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Helpers for untrusted text from the chain."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def clean_text(value: str, max_length: int) -> str:
|
|
5
|
+
"""Remove non-printable characters from untrusted text and truncate it.
|
|
6
|
+
|
|
7
|
+
Token names, symbols and URIs are chosen by whoever creates the token. Strip
|
|
8
|
+
control characters (including terminal escape sequences' ESC byte) before
|
|
9
|
+
logging or displaying them.
|
|
10
|
+
"""
|
|
11
|
+
cleaned = "".join(ch for ch in value if ch.isprintable()).strip()
|
|
12
|
+
return cleaned[:max_length]
|