mm-strk 0.3.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.
mm_strk/__init__.py ADDED
File without changes
mm_strk/balance.py ADDED
@@ -0,0 +1,36 @@
1
+ import aiohttp
2
+ from aiohttp_socks import ProxyConnector
3
+ from mm_std import Result
4
+ from starknet_py.net.account.account import Account
5
+ from starknet_py.net.full_node_client import FullNodeClient
6
+ from starknet_py.net.models.chains import StarknetChainId
7
+ from starknet_py.net.signer.key_pair import KeyPair
8
+
9
+ ETH_ADDRESS_MAINNET = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
10
+ ETH_DECIMALS = 18
11
+ DAI_ADDRESS_MAINNET = "0x00da114221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3"
12
+ DAI_DECIMALS = 18
13
+ USDC_ADDRESS_MAINNET = "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8"
14
+ USDC_DECIMALS = 6
15
+ USDT_ADDRESS_MAINNET = "0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb8"
16
+ USDT_DECIMALS = 6
17
+ STRK_ADDRESS_MAINNET = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
18
+ STRK_DECIMALS = 18
19
+
20
+
21
+ async def get_balance(rpc_url: str, address: str, token: str, timeout: float = 5, proxy: str | None = None) -> Result[int]:
22
+ try:
23
+ timeout_config = aiohttp.ClientTimeout(total=timeout)
24
+ connector = ProxyConnector.from_url(proxy) if proxy else None
25
+ async with aiohttp.ClientSession(connector=connector, timeout=timeout_config) as session:
26
+ client = FullNodeClient(node_url=rpc_url, session=session)
27
+ account = Account(
28
+ address=address,
29
+ client=client,
30
+ chain=StarknetChainId.MAINNET,
31
+ key_pair=KeyPair(private_key=654, public_key=321),
32
+ )
33
+ balance = await account.get_balance(token_address=token)
34
+ return Result.success(balance)
35
+ except Exception as e:
36
+ return Result.failure(e)
File without changes
mm_strk/cli/cli.py ADDED
@@ -0,0 +1,28 @@
1
+ from typing import Annotated
2
+
3
+ import typer
4
+ from mm_std import print_plain
5
+
6
+ from mm_strk.cli import cli_utils
7
+ from mm_strk.cli.cmd import node_cmd
8
+
9
+ app = typer.Typer(no_args_is_help=True, pretty_exceptions_enable=False, add_completion=False)
10
+
11
+
12
+ def version_callback(value: bool) -> None:
13
+ if value:
14
+ print_plain(f"mm-strk: {cli_utils.get_version()}")
15
+ raise typer.Exit
16
+
17
+
18
+ @app.callback()
19
+ def main(_version: bool = typer.Option(None, "--version", callback=version_callback, is_eager=True)) -> None:
20
+ pass
21
+
22
+
23
+ @app.command(name="node", help="Checks RPC URLs for availability and status")
24
+ def node_command(
25
+ urls: Annotated[list[str], typer.Argument()],
26
+ proxy: Annotated[str | None, typer.Option("--proxy", "-p", help="Proxy")] = None,
27
+ ) -> None:
28
+ node_cmd.run(urls, proxy)
@@ -0,0 +1,5 @@
1
+ import importlib.metadata
2
+
3
+
4
+ def get_version() -> str:
5
+ return importlib.metadata.version("mm-strk")
File without changes
@@ -0,0 +1,49 @@
1
+ import asyncio
2
+
3
+ import typer
4
+ from mm_std import print_json
5
+ from pydantic import BaseModel
6
+ from starknet_py.net.client_models import SyncStatus
7
+ from starknet_py.net.full_node_client import FullNodeClient
8
+
9
+
10
+ class NodeStatus(BaseModel):
11
+ block_number: int | str
12
+ chain_id: int | str
13
+ syncing_status: bool | SyncStatus | str
14
+
15
+
16
+ def run(urls: list[str], proxy: str | None) -> None:
17
+ if proxy:
18
+ typer.echo("proxy is not supported yet")
19
+ raise typer.Exit(code=1)
20
+ asyncio.run(_run(urls))
21
+
22
+
23
+ async def _run(urls: list[str]) -> None:
24
+ result = {}
25
+ for url in urls:
26
+ result[url] = (await _node_status(url)).model_dump()
27
+
28
+ print_json(result)
29
+
30
+
31
+ async def _node_status(url: str) -> NodeStatus:
32
+ client = FullNodeClient(node_url=url)
33
+
34
+ try:
35
+ block_number: int | str = await client.get_block_number()
36
+ except Exception as e:
37
+ block_number = str(e)
38
+
39
+ try:
40
+ chain_id: int | str = int(await client.get_chain_id(), 16)
41
+ except Exception as e:
42
+ chain_id = str(e)
43
+
44
+ try:
45
+ syncing_status: bool | SyncStatus | str = await client.get_syncing_status()
46
+ except Exception as e:
47
+ syncing_status = str(e)
48
+
49
+ return NodeStatus(block_number=block_number, chain_id=chain_id, syncing_status=syncing_status)
mm_strk/domain.py ADDED
@@ -0,0 +1,18 @@
1
+ from mm_std import Result, http_request, str_contains_any
2
+
3
+
4
+ async def address_to_domain(address: str, timeout: float = 5.0, proxy: str | None = None) -> Result[str | None]:
5
+ url = "https://api.starknet.id/addr_to_domain"
6
+ res = await http_request(url, params={"addr": address}, proxy=proxy, timeout=timeout)
7
+ if (
8
+ res.status_code == 400
9
+ and res.body is not None
10
+ and str_contains_any(res.body.lower(), ["no data found", "no domain found"])
11
+ ):
12
+ return res.to_result_success(None)
13
+ if res.is_error():
14
+ return res.to_result_failure()
15
+ domain = res.parse_json_body("domain")
16
+ if domain:
17
+ return res.to_result_success(domain)
18
+ return res.to_result_failure("unknown_response")
mm_strk/py.typed ADDED
File without changes
@@ -0,0 +1,7 @@
1
+ Metadata-Version: 2.4
2
+ Name: mm-strk
3
+ Version: 0.3.1
4
+ Requires-Python: >=3.12
5
+ Requires-Dist: mm-crypto-utils>=0.3.1
6
+ Requires-Dist: starknet-py~=0.26.2
7
+ Requires-Dist: typer>=0.15.2
@@ -0,0 +1,13 @@
1
+ mm_strk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ mm_strk/balance.py,sha256=SGC0ZqCwQD6uWsn_Buj0aVyB6GTF8dmunUS5HQiZBAw,1685
3
+ mm_strk/domain.py,sha256=Sj6fGnOnfAGNYU02Jhv7Q7phiSjeEUHGmmHKyAMu7Tw,740
4
+ mm_strk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ mm_strk/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ mm_strk/cli/cli.py,sha256=SvIfjDq83HcFsiK_4S7Oez3Z_7OpYDIJreKALzWVUVQ,796
7
+ mm_strk/cli/cli_utils.py,sha256=4_QLJ_rEotHK90PRQqsvCuFydDOXPrXrnMndBffMPIg,103
8
+ mm_strk/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ mm_strk/cli/cmd/node_cmd.py,sha256=ApBpGXmkQ1cGp2NPqTdqlAYS1SGNBzy81da-quVEHNo,1282
10
+ mm_strk-0.3.1.dist-info/METADATA,sha256=fc_gIPRR3SZVQmBMNEuo_soW2HZbZUNPCImpmxdX9UI,177
11
+ mm_strk-0.3.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
+ mm_strk-0.3.1.dist-info/entry_points.txt,sha256=X6zWJaYaUkTgJrY4LAVpcov8O43PmUU4cQ1ue8prYqQ,48
13
+ mm_strk-0.3.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mm-strk = mm_strk.cli.cli:app