mm-eth 0.5.1__py3-none-any.whl → 0.5.2__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_eth/cli/cli.py CHANGED
@@ -53,6 +53,16 @@ def balance_command(
53
53
  balance_cmd.run(rpc_url, wallet_address, token_address, wei, print_format)
54
54
 
55
55
 
56
+ @app.command(name="balances", help="Print base and ERC20 token balances")
57
+ def balances_command(
58
+ config_path: Path,
59
+ print_config: bool = typer.Option(False, "--config", "-c", help="Print config and exit"),
60
+ nonce: bool = typer.Option(False, "--nonce", "-n", help="Print nonce also"),
61
+ wei: bool = typer.Option(False, "--wei", "-w", help="Show balances in WEI"),
62
+ ) -> None:
63
+ balances_cmd.run(BalancesCmdParams(config_path=config_path, print_config=print_config, wei=wei, show_nonce=nonce))
64
+
65
+
56
66
  @app.command(name="token", help="Get token info")
57
67
  def token_command(
58
68
  token_address: Annotated[str, typer.Argument()],
@@ -64,10 +74,10 @@ def token_command(
64
74
  @app.command(name="node", help="Check RPC url")
65
75
  def node_command(
66
76
  urls: Annotated[list[str], typer.Argument()],
67
- print_format: Annotated[PrintFormat, typer.Option("--format", "-f", help="Print format")] = PrintFormat.TABLE,
68
77
  proxy: Annotated[str | None, typer.Option("--proxy", "-p", help="Proxy")] = None,
78
+ print_format: Annotated[PrintFormat, typer.Option("--format", "-f", help="Print format")] = PrintFormat.TABLE,
69
79
  ) -> None:
70
- node_cmd.run(urls, print_format, proxy)
80
+ node_cmd.run(urls, proxy, print_format)
71
81
 
72
82
 
73
83
  @wallet_app.command(name="mnemonic", help="Generate eth accounts based on a mnemonic")
@@ -185,16 +195,6 @@ def transfer_command(
185
195
  # )
186
196
 
187
197
 
188
- @app.command(name="balances", help="Print base and ERC20 token balances")
189
- def balances_command(
190
- config_path: Path,
191
- print_config: bool = typer.Option(False, "--config", "-c", help="Print config and exit"),
192
- nonce: bool = typer.Option(False, "--nonce", "-n", help="Print nonce also"),
193
- wei: bool = typer.Option(False, "--wei", "-w", help="Show balances in WEI"),
194
- ) -> None:
195
- balances_cmd.run(BalancesCmdParams(config_path=config_path, print_config=print_config, wei=wei, show_nonce=nonce))
196
-
197
-
198
198
  @app.command(name="call-contract", help="Call a method on a contract")
199
199
  def call_contract_command(
200
200
  config_path: Path,
mm_eth/cli/cli_utils.py CHANGED
@@ -23,6 +23,8 @@ def public_rpc_url(url: str | None) -> str:
23
23
  match url.lower():
24
24
  case "mainnet" | "1":
25
25
  return "https://ethereum.publicnode.com"
26
+ case "sepolia" | "11155111":
27
+ return "https://ethereum-sepolia-rpc.publicnode.com"
26
28
  case "opbnb" | "204":
27
29
  return "https://opbnb-mainnet-rpc.bnbchain.org"
28
30
  case "base" | "8453":
@@ -1,4 +1,4 @@
1
- from mm_std import Err, Ok, PrintFormat, fatal, print_json, print_plain
1
+ from mm_std import PrintFormat, print_json, print_plain
2
2
 
3
3
  from mm_eth import erc20, rpc
4
4
  from mm_eth.cli.cli_utils import public_rpc_url
@@ -6,46 +6,42 @@ from mm_eth.utils import from_wei_str
6
6
 
7
7
 
8
8
  def run(rpc_url: str, wallet_address: str, token_address: str | None, wei: bool, print_format: PrintFormat) -> None:
9
+ result: dict[str, object] = {}
9
10
  rpc_url = public_rpc_url(rpc_url)
10
- json_result: dict[str, object] = {}
11
11
 
12
12
  # nonce
13
- nonce = rpc.eth_get_transaction_count(rpc_url, wallet_address).ok_or_err()
14
- print_plain(f"nonce: {nonce}", print_format)
15
- json_result["nonce"] = nonce
16
-
17
- # balance
18
- balance_res = rpc.eth_get_balance(rpc_url, wallet_address)
19
- if isinstance(balance_res, Ok):
20
- balance = str(balance_res.ok) if wei else from_wei_str(balance_res.ok, "eth")
21
- else:
22
- balance = balance_res.err
23
- print_plain(f"eth_balance: {balance}", print_format)
24
- json_result["eth_balance"] = balance
25
-
26
- if token_address is not None:
13
+ result["nonce"] = rpc.eth_get_transaction_count(rpc_url, wallet_address).ok_or_err()
14
+ if print_format == PrintFormat.PLAIN:
15
+ print_plain(f"nonce: {result['nonce']}")
16
+
17
+ # eth balance
18
+ result["eth_balance"] = (
19
+ rpc.eth_get_balance(rpc_url, wallet_address).map(lambda x: str(x) if wei else from_wei_str(x, "eth")).ok_or_err()
20
+ )
21
+ if print_format == PrintFormat.PLAIN:
22
+ print_plain(f"eth_balance: {result['eth_balance']}")
23
+
24
+ if token_address:
27
25
  # token decimal
28
- decimals_res = erc20.get_decimals(rpc_url, token_address)
29
- if isinstance(decimals_res, Err):
30
- fatal(f"error: can't get token decimals: {decimals_res.err}")
31
- decimals = decimals_res.ok
32
- print_plain(f"token_decimal: {decimals}", print_format)
33
- json_result["token_decimal"] = decimals
26
+ result["token_decimal"] = erc20.get_decimals(rpc_url, token_address).ok_or_err()
27
+ if print_format == PrintFormat.PLAIN:
28
+ print_plain(f"token_decimal: {result['token_decimal']}")
34
29
 
35
30
  # token symbol
36
- symbol_res = erc20.get_symbol(rpc_url, token_address)
37
- if isinstance(symbol_res, Err):
38
- fatal(f"error: can't get token symbol: {symbol_res.err}")
39
- symbol = symbol_res.ok
40
- print_plain(f"token_symbol: {symbol}", print_format)
41
- json_result["token_symbol"] = symbol
31
+ result["token_symbol"] = erc20.get_symbol(rpc_url, token_address).ok_or_err()
32
+ if print_format == PrintFormat.PLAIN:
33
+ print_plain(f"token_symbol: {result['token_symbol']}")
42
34
 
43
35
  # token balance
44
- balance_res = erc20.get_balance(rpc_url, token_address, wallet_address)
45
- if isinstance(balance_res, Err):
46
- fatal(f"error: can't get token balance: {balance_res.err}")
47
- balance = str(balance_res.ok) if wei else from_wei_str(balance_res.ok, "t", decimals=decimals)
48
- print_plain(f"token_balance: {balance}", print_format)
49
- json_result["token_balance"] = balance
50
-
51
- print_json(json_result, print_format=print_format)
36
+ result["token_balance"] = (
37
+ erc20.get_balance(rpc_url, token_address, wallet_address)
38
+ .map(
39
+ lambda x: str(x) if wei or not result["token_decimal"] else from_wei_str(x, "t", decimals=result["token_decimal"]) # type: ignore[arg-type]
40
+ )
41
+ .ok_or_err()
42
+ )
43
+ if print_format == PrintFormat.PLAIN:
44
+ print_plain(f"token_balance: {result['token_balance']}")
45
+
46
+ if print_format == PrintFormat.JSON:
47
+ print_json(data=result)
@@ -1,9 +1,9 @@
1
1
  from pathlib import Path
2
2
 
3
- from mm_std import print_plain
3
+ from mm_std import pretty_print_toml
4
4
 
5
5
 
6
6
  def run(command: str) -> None:
7
7
  command = command.replace("-", "_")
8
8
  example_file = Path(Path(__file__).parent.absolute(), "../examples", f"{command}.toml")
9
- print_plain(example_file.read_text())
9
+ pretty_print_toml(example_file.read_text())
@@ -1,4 +1,6 @@
1
- from mm_std import Ok, PrintFormat, print_json, print_plain
1
+ import pydash
2
+ from mm_std import Ok, PrintFormat, print_json
3
+ from pydantic import BaseModel
2
4
  from rich.live import Live
3
5
  from rich.table import Table
4
6
 
@@ -6,42 +8,71 @@ from mm_eth import rpc
6
8
  from mm_eth.utils import from_wei_str, name_network
7
9
 
8
10
 
9
- def run(urls: list[str], print_format: PrintFormat, proxy: str | None) -> None:
10
- json_result: dict[str, object] = {}
11
- table = Table(title="nodes")
12
- if print_format == PrintFormat.TABLE:
13
- table.add_column("url")
14
- table.add_column("chain_id")
15
- table.add_column("chain_name")
16
- table.add_column("block_number")
17
- table.add_column("base_fee")
18
-
19
- with Live(table, refresh_per_second=0.5):
20
- for url in urls:
21
- chain_id_res = rpc.eth_chain_id(url, timeout=10, proxies=proxy)
22
- chain_id = chain_id_res.ok_or_err()
23
- chain_name = ""
24
- if isinstance(chain_id_res, Ok):
25
- chain_name = name_network(chain_id_res.ok)
26
- block_number = rpc.eth_block_number(url, timeout=10, proxies=proxy).ok_or_err()
27
- base_fee = rpc.get_base_fee_per_gas(url, timeout=10, proxies=proxy).map_or_else(
28
- lambda err: err,
29
- lambda ok: from_wei_str(ok, "gwei"),
30
- )
31
-
32
- json_result[url] = {
33
- "chain_id": chain_id,
34
- "chain_name": chain_name,
35
- "block_number": block_number,
36
- "base_fee": base_fee,
37
- }
38
- if print_format == PrintFormat.TABLE:
39
- table.add_row(url, str(chain_id), chain_name, str(block_number), base_fee)
40
- print_plain(f"url: {url}", print_format)
41
- print_plain(f"chain_id: {chain_id}", print_format)
42
- print_plain(f"chain_name: {chain_name}", print_format)
43
- print_plain(f"block_number: {block_number}", print_format)
44
- print_plain(f"base_fee: {base_fee}", print_format)
45
- print_plain("", print_format)
46
-
47
- print_json(json_result, print_format=print_format)
11
+ class NodeInfo(BaseModel):
12
+ url: str
13
+ chain_id: int | str
14
+ chain_name: str
15
+ block_number: int | str
16
+ base_fee: str
17
+
18
+ def table_row(self) -> list[object]:
19
+ return [self.url, self.chain_id, self.chain_name, self.block_number, self.base_fee]
20
+
21
+
22
+ class LiveTable:
23
+ def __init__(self, table: Table, ignore: bool = False) -> None:
24
+ self.ignore = ignore
25
+ if ignore:
26
+ return
27
+ self.table = table
28
+ self.live = Live(table, auto_refresh=False)
29
+ self.live.start()
30
+
31
+ def add_row(self, *args: object) -> None:
32
+ if self.ignore:
33
+ return
34
+ self.table.add_row(*(str(a) for a in args))
35
+ self.live.refresh()
36
+
37
+ def stop(self) -> None:
38
+ if self.ignore:
39
+ return
40
+ self.live.stop()
41
+
42
+
43
+ def run(urls: list[str], proxy: str | None, print_format: PrintFormat) -> None:
44
+ urls = pydash.uniq(urls)
45
+ result = []
46
+ live_table = LiveTable(
47
+ Table("url", "chain_id", "chain_name", "block_number", "base_fee", title="nodes"),
48
+ ignore=print_format != PrintFormat.TABLE,
49
+ )
50
+ for url in urls:
51
+ node_info = _get_node_info(url, proxy)
52
+ live_table.add_row(*node_info.table_row())
53
+ result.append(node_info)
54
+
55
+ live_table.stop()
56
+
57
+ if print_format == PrintFormat.JSON:
58
+ print_json(data=result)
59
+ # print_json(data=result)
60
+ # table = Table(*["url", "chain_id", "chain_name", "block_number", "base_fee"], title="nodes")
61
+
62
+ # with Live(table, refresh_per_second=0.5):
63
+ # for url in urls:
64
+ # table.add_row(url, str(chain_id), chain_name, str(block_number), base_fee)
65
+
66
+
67
+ def _get_node_info(url: str, proxy: str | None) -> NodeInfo:
68
+ chain_id_res = rpc.eth_chain_id(url, timeout=10, proxies=proxy)
69
+ chain_id = chain_id_res.ok_or_err()
70
+ chain_name = ""
71
+ if isinstance(chain_id_res, Ok):
72
+ chain_name = name_network(chain_id_res.ok)
73
+ block_number = rpc.eth_block_number(url, timeout=10, proxies=proxy).ok_or_err()
74
+ base_fee = rpc.get_base_fee_per_gas(url, timeout=10, proxies=proxy).map_or_else(
75
+ lambda err: err,
76
+ lambda ok: from_wei_str(ok, "gwei"),
77
+ )
78
+ return NodeInfo(url=url, chain_id=chain_id, chain_name=chain_name, block_number=block_number, base_fee=base_fee)
@@ -1,5 +1,5 @@
1
- # from_address to_address value -- is a format for each transfer, value is optional
2
- # if value is not set, default_value will be used
1
+ # Each line is a transfer instruction, with format: from_address to_address [value]
2
+ # Value is optional. If value is not set, default_value will be used
3
3
  # value is an expression that can contain variable 'balance' and 'random' function
4
4
  transfers = """
5
5
  0x10fd602Bff689e64D4720D1DCCCD3494f1f16623 0x58487485c3858109f5A37e42546FE87473f79a4b 0.1t # comments are allowed here
@@ -16,13 +16,14 @@ file: /path/to/other_private_keys.txt
16
16
 
17
17
  token = "0x60631C856303731BE4deb81C0303F80B652aA5b4" # If not specified, it ETH transfers
18
18
 
19
- max_fee = "1.2base_fee+1gwei+random(1,200)" # supported var_name=base_fee
20
-
21
- max_fee_limit = "10.1gwei-random(1,10)" # optional
19
+ max_fee = "1.2base_fee+1gwei+random(1,200)" # 'base_fee' variable is supported
22
20
 
23
21
  priority_fee = "1gwei+random(1,12)"
24
22
 
25
- gas = "estimate+random(100,200)-19" # supported var_name=estimate
23
+ # Don't transfer if max_fee > max_fee_limit, optional
24
+ max_fee_limit = "10.1gwei-random(1,10)"
25
+
26
+ gas = "estimate+random(100,200)-19" # 'estimate' variable is supported
26
27
 
27
28
  # default_value is used if transfer.value is not set in transfers. It's optional.
28
29
  default_value = "0.5balance-random(1.5t,3t)+11t" # supported var_name=balance. For ERC20 token use 't' suffix.
@@ -1,8 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mm-eth
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Requires-Python: >=3.12
5
- Requires-Dist: mm-crypto-utils>=0.2.3
5
+ Requires-Dist: cryptography>=44.0.1
6
+ Requires-Dist: mm-crypto-utils>=0.2.4
6
7
  Requires-Dist: typer>=0.15.1
7
8
  Requires-Dist: web3~=7.8.0
8
9
  Requires-Dist: websocket-client~=1.8.0
@@ -16,19 +16,19 @@ mm_eth/utils.py,sha256=sSxt9GZEntZlT0RU8ht9Qon875HPhpd-1JjgqUBEfVo,7405
16
16
  mm_eth/vault.py,sha256=h8NyiOQh5YFskh1lZA3KyvnJUnxl9769ME2ChplG0CM,1477
17
17
  mm_eth/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  mm_eth/cli/calcs.py,sha256=cLFTYNAN-I53tUiSg-zFfVr2afjIZPftDDjHj16FBz0,1068
19
- mm_eth/cli/cli.py,sha256=nSOxvfjEu6HBXz6qFOCuiLFgw381pzeNB2tUGxdJIgA,9332
20
- mm_eth/cli/cli_utils.py,sha256=yBIS3dGid75zyxw8crPOQHA4p3Krk5BoA2g01turKmQ,1712
19
+ mm_eth/cli/cli.py,sha256=yunHFL67-cEBXfogVgYzqLIhtjPIlyHtC6UNZdNg9Mw,9332
20
+ mm_eth/cli/cli_utils.py,sha256=6TIGGEh3zGPTJQ6DKeOdz8JBg0XdL5gWt6WwppRThyk,1814
21
21
  mm_eth/cli/print_helpers.py,sha256=yOiOFjTKloumwf07AqNIHQswUo8t0yuT9bpeGBGl60Q,1470
22
22
  mm_eth/cli/rpc_helpers.py,sha256=FMV-QVNM3v9X8H_-DP0hjNRqmm7KOnfzkw9bP17Qbz0,4499
23
23
  mm_eth/cli/validators.py,sha256=KIAQUohl4_KKDvynbeqIeywtNnMWhTKYlnTdaxcjn6U,1690
24
24
  mm_eth/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- mm_eth/cli/cmd/balance_cmd.py,sha256=gkwUa8VGe1wXH0GDsit3-1NmRiijojaNLygi5zNcYSY,2110
25
+ mm_eth/cli/cmd/balance_cmd.py,sha256=aWJFteLnkgw9RqDsIV34a5_rh00fmFR9SXSJUtVyP3U,1856
26
26
  mm_eth/cli/cmd/balances_cmd.py,sha256=4UiWSNH9OCnkvcMGPTygEss8119do-rfG7QtsNMfWZs,4197
27
27
  mm_eth/cli/cmd/call_contract_cmd.py,sha256=RbBPvyUEQ45hQINYDKkx1yWhPygdymVKlRL26xI31uk,1264
28
28
  mm_eth/cli/cmd/deploy_cmd.py,sha256=0oBp_RZw_DIEtBFRc6QKdAw5oouwwpDIdeXvuyP9xdU,1272
29
29
  mm_eth/cli/cmd/encode_input_data_cmd.py,sha256=9UQ1MKPEFQJ8j_COsP3KGKhwOf9tT3feBezI8vvxTlw,267
30
- mm_eth/cli/cmd/example_cmd.py,sha256=o4NTll3fjmspbKjZ0sHGDRHTZ1RcFNHZDi9Ka0VNoDQ,264
31
- mm_eth/cli/cmd/node_cmd.py,sha256=Ae5yPxxnNiHw3tZcojS7KwNLM4gEfLhsTfhZp_86rqU,1956
30
+ mm_eth/cli/cmd/example_cmd.py,sha256=QLipRKoR6T1my9qnMpzk2uPtj61mbwcuCMNFmyqRgJo,276
31
+ mm_eth/cli/cmd/node_cmd.py,sha256=tFk4YECUUb-Rt_YIfMc_IGlqzxQjpsZmjp7OK2v0crI,2502
32
32
  mm_eth/cli/cmd/rpc_cmd.py,sha256=02q82YqgbPezfEBmV_QBCIeNReE7ktkPych8Xr9ann8,2186
33
33
  mm_eth/cli/cmd/solc_cmd.py,sha256=tBpeMdPfGs2iQIMaIJAAhMh1a3KyXHwyninfXPVpsgs,677
34
34
  mm_eth/cli/cmd/token_cmd.py,sha256=4y6ZQpLOJ33_iNuKpm9tZXh4RntWhmPUcizgaNNBzaw,1102
@@ -40,8 +40,8 @@ mm_eth/cli/cmd/wallet/mnemonic_cmd.py,sha256=xE-5Ux9BdYsTZYBy0dMn9jupGhW4ced-AgY
40
40
  mm_eth/cli/cmd/wallet/private_key_cmd.py,sha256=Fv_2OLog1h32pIP7PJITwl_pHdy3BXvaDRcXZsxY1xo,241
41
41
  mm_eth/cli/examples/balances.toml,sha256=i_ALpiEcf8-0TFiUg1cgJhxxfHYeBl9x0b3tnUWjswU,421
42
42
  mm_eth/cli/examples/call_contract.toml,sha256=ZQWK-409V_vLIZ2bsRD5RCWPPzShPz2KJTTRQY4YaGw,248
43
- mm_eth/cli/examples/transfer.toml,sha256=jyfrLlVL3xxf_pWShkMT0N_N8MnLD36DbIcfU2G4-Yw,1738
44
- mm_eth-0.5.1.dist-info/METADATA,sha256=zUVIU7_MwpgSao4s9BZrATHtaQqouhOL4m4vo5DLiNI,207
45
- mm_eth-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
46
- mm_eth-0.5.1.dist-info/entry_points.txt,sha256=aGhpsozl8NIrkuUcX5fSgURCcDhr3ShUdeTSIrJq4oc,46
47
- mm_eth-0.5.1.dist-info/RECORD,,
43
+ mm_eth/cli/examples/transfer.toml,sha256=8mWuphDquoSDJw-hb9VJqtonjmv3kJ5Ip8jJ4t5YnfM,1810
44
+ mm_eth-0.5.2.dist-info/METADATA,sha256=2raUNBANLfGusBbUHhjikWncc8_HSxioQz8_Ux0XXgI,243
45
+ mm_eth-0.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
46
+ mm_eth-0.5.2.dist-info/entry_points.txt,sha256=aGhpsozl8NIrkuUcX5fSgURCcDhr3ShUdeTSIrJq4oc,46
47
+ mm_eth-0.5.2.dist-info/RECORD,,
File without changes