mm-sol 0.5.0__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_sol/balance.py +20 -32
- mm_sol/cli/cmd/example_cmd.py +2 -2
- mm_sol/cli/cmd/node_cmd.py +5 -3
- {mm_sol-0.5.0.dist-info → mm_sol-0.5.2.dist-info}/METADATA +3 -2
- {mm_sol-0.5.0.dist-info → mm_sol-0.5.2.dist-info}/RECORD +7 -7
- {mm_sol-0.5.0.dist-info → mm_sol-0.5.2.dist-info}/WHEEL +0 -0
- {mm_sol-0.5.0.dist-info → mm_sol-0.5.2.dist-info}/entry_points.txt +0 -0
mm_sol/balance.py
CHANGED
|
@@ -2,8 +2,10 @@ import httpx
|
|
|
2
2
|
from mm_crypto_utils import Nodes, Proxies, random_node, random_proxy
|
|
3
3
|
from mm_std import Err, Ok, Result
|
|
4
4
|
from solana.exceptions import SolanaRpcException
|
|
5
|
-
from solana.rpc.
|
|
5
|
+
from solana.rpc.core import RPCException
|
|
6
6
|
from solders.pubkey import Pubkey
|
|
7
|
+
from solders.rpc.errors import InvalidParamsMessage
|
|
8
|
+
from spl.token.instructions import get_associated_token_address
|
|
7
9
|
|
|
8
10
|
from mm_sol import rpc
|
|
9
11
|
from mm_sol.utils import get_client
|
|
@@ -31,42 +33,32 @@ def get_token_balance(
|
|
|
31
33
|
token_account: str | None = None,
|
|
32
34
|
timeout: float = 10,
|
|
33
35
|
proxy: str | None = None,
|
|
34
|
-
no_token_accounts_return_zero: bool = True,
|
|
35
36
|
) -> Result[int]:
|
|
36
|
-
data: list[object] = []
|
|
37
37
|
try:
|
|
38
38
|
client = get_client(node, proxy=proxy, timeout=timeout)
|
|
39
|
-
if token_account:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if not token_account:
|
|
40
|
+
token_account = str(
|
|
41
|
+
get_associated_token_address(Pubkey.from_string(owner_address), Pubkey.from_string(token_mint_address))
|
|
42
|
+
)
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
Pubkey.from_string(owner_address),
|
|
46
|
-
TokenAccountOpts(mint=Pubkey.from_string(token_mint_address)),
|
|
47
|
-
)
|
|
48
|
-
data.append(res_accounts)
|
|
44
|
+
res = client.get_token_account_balance(Pubkey.from_string(token_account))
|
|
49
45
|
|
|
50
|
-
|
|
46
|
+
# Sometimes it not raise an error, but it returns this :(
|
|
47
|
+
if isinstance(res, InvalidParamsMessage) and "could not find account" in res.message:
|
|
51
48
|
return Ok(0)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
data.append(res)
|
|
60
|
-
if res.value: # type:ignore[truthy-bool]
|
|
61
|
-
balances.append(int(res.value.amount))
|
|
62
|
-
|
|
63
|
-
return Ok(sum(balances))
|
|
49
|
+
return Ok(int(res.value.amount), data=res)
|
|
50
|
+
except RPCException as e:
|
|
51
|
+
if len(e.args) > 1:
|
|
52
|
+
s = e.args[0]
|
|
53
|
+
if isinstance(s, InvalidParamsMessage) and "could not find account" in s.message:
|
|
54
|
+
return Ok(0)
|
|
55
|
+
return Err(e)
|
|
64
56
|
except httpx.HTTPStatusError as e:
|
|
65
|
-
return Err(f"http error: {e}"
|
|
57
|
+
return Err(f"http error: {e}")
|
|
66
58
|
except SolanaRpcException as e:
|
|
67
|
-
return Err(e.error_msg
|
|
59
|
+
return Err(e.error_msg)
|
|
68
60
|
except Exception as e:
|
|
69
|
-
return Err(e
|
|
61
|
+
return Err(e)
|
|
70
62
|
|
|
71
63
|
|
|
72
64
|
def get_token_balance_with_retries(
|
|
@@ -77,7 +69,6 @@ def get_token_balance_with_retries(
|
|
|
77
69
|
token_account: str | None = None,
|
|
78
70
|
timeout: float = 10,
|
|
79
71
|
proxies: Proxies = None,
|
|
80
|
-
no_token_accounts_return_zero: bool = True,
|
|
81
72
|
) -> Result[int]:
|
|
82
73
|
res: Result[int] = Err("not started yet")
|
|
83
74
|
for _ in range(retries):
|
|
@@ -88,11 +79,8 @@ def get_token_balance_with_retries(
|
|
|
88
79
|
token_account,
|
|
89
80
|
timeout=timeout,
|
|
90
81
|
proxy=random_proxy(proxies),
|
|
91
|
-
no_token_accounts_return_zero=no_token_accounts_return_zero,
|
|
92
82
|
)
|
|
93
83
|
if res.is_ok():
|
|
94
84
|
return res
|
|
95
|
-
if isinstance(res, Err) and res.err == "no_token_accounts":
|
|
96
|
-
return res
|
|
97
85
|
|
|
98
86
|
return res
|
mm_sol/cli/cmd/example_cmd.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from mm_std import
|
|
3
|
+
from mm_std import pretty_print_toml
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def run(module: str) -> None:
|
|
7
7
|
example_file = Path(Path(__file__).parent.absolute(), "../examples", f"{module}.toml")
|
|
8
|
-
|
|
8
|
+
pretty_print_toml(example_file.read_text())
|
mm_sol/cli/cmd/node_cmd.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from mm_std import print_json
|
|
2
2
|
|
|
3
3
|
from mm_sol import rpc
|
|
4
|
+
from mm_sol.cli import cli_utils
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def run(urls: list[str], proxy: str | None) -> None:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
result = {}
|
|
9
|
+
for url in [cli_utils.public_rpc_url(u) for u in urls]:
|
|
10
|
+
result[url] = rpc.get_block_height(url, proxy=proxy, timeout=10).ok_or_err()
|
|
11
|
+
print_json(data=result)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mm-sol
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Requires-Python: >=3.12
|
|
5
5
|
Requires-Dist: base58~=2.1.1
|
|
6
6
|
Requires-Dist: jinja2>=3.1.5
|
|
7
|
-
Requires-Dist: mm-crypto-utils>=0.2.
|
|
7
|
+
Requires-Dist: mm-crypto-utils>=0.2.6
|
|
8
8
|
Requires-Dist: mnemonic==0.21
|
|
9
9
|
Requires-Dist: solana~=0.36.5
|
|
10
|
+
Requires-Dist: solders~=0.23.0
|
|
10
11
|
Requires-Dist: typer>=0.15.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
mm_sol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
mm_sol/account.py,sha256=0pjvNxwhpmDHoXY3oTY2fNlQHoWPmlS77r8JcP8lAy4,4545
|
|
3
|
-
mm_sol/balance.py,sha256=
|
|
3
|
+
mm_sol/balance.py,sha256=hBL35J7xyiFwhGoJGArdzZuWzqfeueYAF6AFrkY_Gow,2793
|
|
4
4
|
mm_sol/block.py,sha256=4Lc4TANgpGvPflVumC9MR-3vIl1dedGyci3cgzczuds,1794
|
|
5
5
|
mm_sol/constants.py,sha256=WSpfz5_cq_8XbIrNFJGu9okwbfPTL00zsyR_k9-7O0o,29
|
|
6
6
|
mm_sol/converters.py,sha256=rBxe3SIADZS8hG7TYl4FgjmvKH-ykaTmNbnWWQDiFZ4,1430
|
|
@@ -18,15 +18,15 @@ mm_sol/cli/validators.py,sha256=M_Rr7JoG3TUYTDAGkjQLDH6l9i9FOrSpss30KdY3UlM,1379
|
|
|
18
18
|
mm_sol/cli/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
19
|
mm_sol/cli/cmd/balance_cmd.py,sha256=DfUZY3-Hr-F7Y0xp1faol0yLnPu6iDU3b839VhdwAbw,2587
|
|
20
20
|
mm_sol/cli/cmd/balances_cmd.py,sha256=gMRZXAnCOPESsKRqz33ALPzSOqGGeZF225kMRO6sV-c,2876
|
|
21
|
-
mm_sol/cli/cmd/example_cmd.py,sha256=
|
|
22
|
-
mm_sol/cli/cmd/node_cmd.py,sha256
|
|
21
|
+
mm_sol/cli/cmd/example_cmd.py,sha256=ZLTy1-cmapiCyYvjFInVE-pQCGKZzDgYKUhsOwtbSIY,234
|
|
22
|
+
mm_sol/cli/cmd/node_cmd.py,sha256=-T3AvUOHPKEQWET7gyDVtwNT24SFX0_9rsgfSjnM_Cw,331
|
|
23
23
|
mm_sol/cli/cmd/transfer_cmd.py,sha256=eQzD7LispR4KFMUlXdXMBGbXs7b0A-iHJHs7VkxH1UA,11021
|
|
24
24
|
mm_sol/cli/cmd/wallet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
25
|
mm_sol/cli/cmd/wallet/keypair_cmd.py,sha256=cRHVVTs9zNYmUozZ8ZlJoutn9V6r8I1AEHBrszR7dTE,538
|
|
26
26
|
mm_sol/cli/cmd/wallet/mnemonic_cmd.py,sha256=IiON_fJT5AFfIr_E1LR6_iDYZ3c_jWCFc-wSYqk61V8,648
|
|
27
27
|
mm_sol/cli/examples/balances.toml,sha256=333g2EkyYBDW7OWFGMIWVZGkdFQMMo0Ag-bg-BvS4Zg,349
|
|
28
28
|
mm_sol/cli/examples/transfer.toml,sha256=kOCdmuwmhlOam4LVtlcYTKF0PoZYHWMlv9gWxNSXMOk,1624
|
|
29
|
-
mm_sol-0.5.
|
|
30
|
-
mm_sol-0.5.
|
|
31
|
-
mm_sol-0.5.
|
|
32
|
-
mm_sol-0.5.
|
|
29
|
+
mm_sol-0.5.2.dist-info/METADATA,sha256=Cb75u6Cpw3Zg6puOe78hHHltWFedIolbe7wTAKS48Dc,290
|
|
30
|
+
mm_sol-0.5.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
31
|
+
mm_sol-0.5.2.dist-info/entry_points.txt,sha256=MrYnosumy9nsITSAw5TiR3WXDwsdoF0YvUIlZ38TLLs,46
|
|
32
|
+
mm_sol-0.5.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|