mm-eth 0.1.5__tar.gz → 0.2.1__tar.gz
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-0.2.1/PKG-INFO +7 -0
- mm_eth-0.2.1/pyproject.toml +75 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/abi.py +3 -3
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/account.py +1 -1
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/anvil.py +2 -2
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/erc20.py +8 -7
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/rpc.py +8 -8
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/solc.py +2 -3
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/tx.py +3 -5
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/utils.py +11 -16
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/vault.py +5 -5
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/conftest.py +5 -6
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_abi.py +2 -2
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_tx.py +3 -3
- {mm_eth-0.1.5 → mm_eth-0.2.1}/uv.lock +96 -160
- mm_eth-0.1.5/PKG-INFO +0 -9
- mm_eth-0.1.5/pyproject.toml +0 -71
- mm_eth-0.1.5/src/mm_eth/abi/zksync.json +0 -2092
- mm_eth-0.1.5/src/mm_eth/cli/calcs.py +0 -88
- mm_eth-0.1.5/src/mm_eth/cli/cli.py +0 -237
- mm_eth-0.1.5/src/mm_eth/cli/cli_helpers.py +0 -195
- mm_eth-0.1.5/src/mm_eth/cli/cli_utils.py +0 -148
- mm_eth-0.1.5/src/mm_eth/cli/cmd/__init__.py +0 -0
- mm_eth-0.1.5/src/mm_eth/cli/cmd/balance_cmd.py +0 -59
- mm_eth-0.1.5/src/mm_eth/cli/cmd/balances_cmd.py +0 -121
- mm_eth-0.1.5/src/mm_eth/cli/cmd/call_contract_cmd.py +0 -44
- mm_eth-0.1.5/src/mm_eth/cli/cmd/config_example_cmd.py +0 -9
- mm_eth-0.1.5/src/mm_eth/cli/cmd/deploy_cmd.py +0 -41
- mm_eth-0.1.5/src/mm_eth/cli/cmd/encode_input_data_cmd.py +0 -10
- mm_eth-0.1.5/src/mm_eth/cli/cmd/mnemonic_cmd.py +0 -27
- mm_eth-0.1.5/src/mm_eth/cli/cmd/node_cmd.py +0 -47
- mm_eth-0.1.5/src/mm_eth/cli/cmd/private_key_cmd.py +0 -10
- mm_eth-0.1.5/src/mm_eth/cli/cmd/rpc_cmd.py +0 -81
- mm_eth-0.1.5/src/mm_eth/cli/cmd/send_contract_cmd.py +0 -247
- mm_eth-0.1.5/src/mm_eth/cli/cmd/solc_cmd.py +0 -25
- mm_eth-0.1.5/src/mm_eth/cli/cmd/token_cmd.py +0 -29
- mm_eth-0.1.5/src/mm_eth/cli/cmd/transfer_erc20_cmd.py +0 -275
- mm_eth-0.1.5/src/mm_eth/cli/cmd/transfer_eth_cmd.py +0 -252
- mm_eth-0.1.5/src/mm_eth/cli/cmd/vault_cmd.py +0 -16
- mm_eth-0.1.5/src/mm_eth/cli/config_examples/balances.yml +0 -15
- mm_eth-0.1.5/src/mm_eth/cli/config_examples/call_contract.yml +0 -5
- mm_eth-0.1.5/src/mm_eth/cli/config_examples/transfer_erc20.yml +0 -26
- mm_eth-0.1.5/src/mm_eth/cli/config_examples/transfer_eth.yml +0 -24
- mm_eth-0.1.5/src/mm_eth/cli/validators.py +0 -84
- mm_eth-0.1.5/src/mm_eth/services/__init__.py +0 -0
- mm_eth-0.1.5/src/mm_eth/zksync.py +0 -203
- mm_eth-0.1.5/tests/__init__.py +0 -0
- mm_eth-0.1.5/tests/cli/__init__.py +0 -0
- mm_eth-0.1.5/tests/cli/cmd/__init__.py +0 -0
- mm_eth-0.1.5/tests/cli/cmd/test_balance_cmd.py +0 -11
- mm_eth-0.1.5/tests/cli/cmd/test_mnemonic_cmd.py +0 -10
- mm_eth-0.1.5/tests/cli/cmd/test_node_cmd.py +0 -10
- mm_eth-0.1.5/tests/cli/cmd/test_private_key_cmd.py +0 -8
- mm_eth-0.1.5/tests/cli/cmd/test_solc_cmd.py +0 -10
- mm_eth-0.1.5/tests/cli/test_calcs.py +0 -33
- mm_eth-0.1.5/tests/contracts/ERC20.sol +0 -207
- mm_eth-0.1.5/tests/contracts/abi/ERC20.json +0 -72
- mm_eth-0.1.5/tests/test_zksync.py +0 -7
- {mm_eth-0.1.5 → mm_eth-0.2.1}/.gitignore +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/README.txt +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/justfile +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/__init__.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/deploy.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/ens.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/ethernodes.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/py.typed +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/src/mm_eth/types.py +0 -0
- {mm_eth-0.1.5/src/mm_eth/cli → mm_eth-0.2.1/tests}/__init__.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_account.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_ethernodes.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_rpc.py +0 -0
- {mm_eth-0.1.5 → mm_eth-0.2.1}/tests/test_utils.py +0 -0
mm_eth-0.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mm-eth"
|
|
3
|
+
version = "0.2.1"
|
|
4
|
+
description = ""
|
|
5
|
+
requires-python = ">=3.12"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"mm-std~=0.1.10",
|
|
8
|
+
"websocket-client~=1.8.0",
|
|
9
|
+
"web3~=7.7.0",
|
|
10
|
+
|
|
11
|
+
]
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling"]
|
|
14
|
+
build-backend = "hatchling.build"
|
|
15
|
+
|
|
16
|
+
[tool.uv]
|
|
17
|
+
dev-dependencies = [
|
|
18
|
+
"pytest~=8.3.4",
|
|
19
|
+
"pytest-xdist~=3.6.1",
|
|
20
|
+
"ruff~=0.9.2",
|
|
21
|
+
"pip-audit~=2.7.3",
|
|
22
|
+
"bandit~=1.8.2",
|
|
23
|
+
"mypy~=1.14.1",
|
|
24
|
+
"types-PyYAML~=6.0.12.20241230",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.13"
|
|
29
|
+
mypy_path = "stubs"
|
|
30
|
+
warn_no_return = false
|
|
31
|
+
implicit_reexport = true
|
|
32
|
+
strict = true
|
|
33
|
+
enable_error_code = ["truthy-bool", "possibly-undefined"]
|
|
34
|
+
exclude = ["^tests/", "^tmp/"]
|
|
35
|
+
[[tool.mypy.overrides]]
|
|
36
|
+
module = ["rlp", "rlp.sedes"]
|
|
37
|
+
ignore_missing_imports = true
|
|
38
|
+
|
|
39
|
+
[tool.ruff]
|
|
40
|
+
line-length = 130
|
|
41
|
+
target-version = "py313"
|
|
42
|
+
[tool.ruff.lint]
|
|
43
|
+
select = ["ALL"]
|
|
44
|
+
ignore = [
|
|
45
|
+
"A005", # flake8-builtins: stdlib-module-shadowing
|
|
46
|
+
"ERA001", # eradicate: commented-out-code
|
|
47
|
+
"PT", # flake8-pytest-style
|
|
48
|
+
"D", # pydocstyle
|
|
49
|
+
"FIX", # flake8-fixme
|
|
50
|
+
"PLR0911", # refactor: too-many-return-statements
|
|
51
|
+
"PLR0913", # pylint: too-many-arguments
|
|
52
|
+
"PLR2004", # pylint: magic-value-comparison
|
|
53
|
+
"PLC0414", # pylint: useless-import-alias
|
|
54
|
+
"FBT", # flake8-boolean-trap
|
|
55
|
+
"EM", # flake8-errmsg
|
|
56
|
+
"TRY003", # tryceratops: raise-vanilla-args
|
|
57
|
+
"C901", # mccabe: complex-structure,
|
|
58
|
+
"BLE001", # flake8-blind-except
|
|
59
|
+
"S311", # bandit: suspicious-non-cryptographic-random-usage
|
|
60
|
+
"TD002", # flake8-todos: missing-todo-author
|
|
61
|
+
"TD003", # flake8-todos: missing-todo-link
|
|
62
|
+
"COM812", # it's used in ruff formatter
|
|
63
|
+
]
|
|
64
|
+
[tool.ruff.lint.per-file-ignores]
|
|
65
|
+
"tests/*.py" = ["ANN", "S"]
|
|
66
|
+
[tool.ruff.format]
|
|
67
|
+
quote-style = "double"
|
|
68
|
+
indent-style = "space"
|
|
69
|
+
|
|
70
|
+
[tool.bandit]
|
|
71
|
+
exclude_dirs = ["tests"]
|
|
72
|
+
skips = ["B311"]
|
|
73
|
+
|
|
74
|
+
[tool.pytest.ini_options]
|
|
75
|
+
markers = ["infura"]
|
|
@@ -64,7 +64,7 @@ def decode_function_input(contract_abi: ABI, tx_input: str) -> FunctionInput:
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def get_function_abi(contr_abi: ABI, fn_name: str) -> ABIFunction:
|
|
67
|
-
abi = pydash.find(contr_abi, lambda x: x.get("name", None) == fn_name and x.get("type", None) == "function") # type:ignore
|
|
67
|
+
abi = pydash.find(contr_abi, lambda x: x.get("name", None) == fn_name and x.get("type", None) == "function") # type: ignore[call-overload, attr-defined]
|
|
68
68
|
if not abi:
|
|
69
69
|
raise ValueError("can't find abi for function: " + fn_name)
|
|
70
70
|
return cast(ABIFunction, abi)
|
|
@@ -122,8 +122,8 @@ def parse_function_signatures(contract_abi: ABI) -> dict[str, str]:
|
|
|
122
122
|
result: dict[str, str] = {}
|
|
123
123
|
for item in contract_abi:
|
|
124
124
|
if item.get("type", None) == "function":
|
|
125
|
-
function_name = item["name"] # type: ignore
|
|
126
|
-
types = ",".join([i["type"] for i in item["inputs"]]) # type: ignore
|
|
125
|
+
function_name = item["name"] # type: ignore[typeddict-item]
|
|
126
|
+
types = ",".join([i["type"] for i in item["inputs"]]) # type: ignore[typeddict-item]
|
|
127
127
|
function_name_and_types = f"{function_name}({types})"
|
|
128
128
|
result[function_name_and_types] = encode_function_signature(function_name_and_types)
|
|
129
129
|
return result
|
|
@@ -67,6 +67,6 @@ def create_private_keys_dict(private_keys: list[str]) -> dict[str, str]: # addr
|
|
|
67
67
|
def is_private_key(private_key: str) -> bool:
|
|
68
68
|
try:
|
|
69
69
|
key_api.PrivateKey(decode_hex(private_key)).public_key.to_address()
|
|
70
|
-
return True
|
|
70
|
+
return True # noqa: TRY300
|
|
71
71
|
except Exception:
|
|
72
72
|
return False
|
|
@@ -10,7 +10,7 @@ from mm_eth import account, rpc
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class Anvil:
|
|
13
|
-
def __init__(self, *, chain_id: int, port: int, mnemonic: str):
|
|
13
|
+
def __init__(self, *, chain_id: int, port: int, mnemonic: str) -> None:
|
|
14
14
|
self.chain_id = chain_id
|
|
15
15
|
self.port = port
|
|
16
16
|
self.mnemonic = mnemonic
|
|
@@ -18,7 +18,7 @@ class Anvil:
|
|
|
18
18
|
|
|
19
19
|
def start_process(self) -> None:
|
|
20
20
|
cmd = f"anvil -m '{self.mnemonic}' -p {self.port} --chain-id {self.chain_id}"
|
|
21
|
-
self.process = Popen(cmd, shell=True) # nosec
|
|
21
|
+
self.process = Popen(cmd, shell=True) # noqa: S602 # nosec
|
|
22
22
|
time.sleep(3)
|
|
23
23
|
|
|
24
24
|
def stop(self) -> None:
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import string
|
|
4
|
-
from collections.abc import Sequence
|
|
5
4
|
from dataclasses import dataclass
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
6
|
|
|
7
7
|
import eth_abi
|
|
8
8
|
import eth_utils
|
|
@@ -11,11 +11,15 @@ from eth_utils import to_checksum_address, to_hex
|
|
|
11
11
|
from mm_std import Err, Ok, Result
|
|
12
12
|
|
|
13
13
|
from mm_eth import rpc
|
|
14
|
-
from mm_eth.rpc import Log
|
|
15
14
|
from mm_eth.tx import SignedTx, sign_legacy_tx, sign_tx
|
|
16
|
-
from mm_eth.types import Nodes, Proxies
|
|
17
15
|
from mm_eth.utils import hex_str_to_int, hex_to_bytes, log_topic_to_address
|
|
18
16
|
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from collections.abc import Sequence
|
|
19
|
+
|
|
20
|
+
from mm_eth.rpc import Log
|
|
21
|
+
from mm_eth.types import Nodes, Proxies
|
|
22
|
+
|
|
19
23
|
TRANSFER_METHOD = "0xa9059cbb"
|
|
20
24
|
TRANSFER_TOPIC = HexStr("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
|
|
21
25
|
|
|
@@ -108,10 +112,7 @@ def get_decimals(rpc_urls: Nodes, address: str, timeout: int = 10, proxies: Prox
|
|
|
108
112
|
if res.ok == "0x":
|
|
109
113
|
return Err("no_decimals", data=res.data)
|
|
110
114
|
|
|
111
|
-
if len(res.ok) > 66
|
|
112
|
-
result = eth_utils.to_int(hexstr=res.ok[0:66])
|
|
113
|
-
else:
|
|
114
|
-
result = eth_utils.to_int(hexstr=res.ok)
|
|
115
|
+
result = eth_utils.to_int(hexstr=res.ok[0:66]) if len(res.ok) > 66 else eth_utils.to_int(hexstr=res.ok)
|
|
115
116
|
return Ok(result, data=res.data)
|
|
116
117
|
|
|
117
118
|
except Exception as e:
|
|
@@ -2,16 +2,19 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import Any, Literal, cast
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal, cast
|
|
6
6
|
|
|
7
7
|
import websocket
|
|
8
8
|
from mm_std import Err, Ok, Result, hr, random_choice
|
|
9
9
|
from pydantic import BaseModel
|
|
10
|
-
from web3.types import BlockIdentifier
|
|
11
10
|
|
|
12
|
-
from mm_eth.types import Nodes, Proxies
|
|
13
11
|
from mm_eth.utils import hex_str_to_int, random_node, random_proxy
|
|
14
12
|
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from web3.types import BlockIdentifier
|
|
15
|
+
|
|
16
|
+
from mm_eth.types import Nodes, Proxies
|
|
17
|
+
|
|
15
18
|
|
|
16
19
|
@dataclass
|
|
17
20
|
class TxReceipt:
|
|
@@ -85,10 +88,7 @@ def rpc_call(
|
|
|
85
88
|
res: Result[Any] = Err("not started yet")
|
|
86
89
|
for _ in range(attempts):
|
|
87
90
|
node = random_node(nodes)
|
|
88
|
-
if node.startswith("http")
|
|
89
|
-
res = _http_call(node, data, timeout, random_proxy(proxies))
|
|
90
|
-
else:
|
|
91
|
-
res = _ws_call(node, data, timeout)
|
|
91
|
+
res = _http_call(node, data, timeout, random_proxy(proxies)) if node.startswith("http") else _ws_call(node, data, timeout)
|
|
92
92
|
if isinstance(res, Ok):
|
|
93
93
|
return res
|
|
94
94
|
return res
|
|
@@ -444,7 +444,7 @@ def eth_syncing(rpc_urls: Nodes, timeout: int = 10, proxies: Proxies = None, att
|
|
|
444
444
|
result[k] = int(v, 16)
|
|
445
445
|
else:
|
|
446
446
|
result[k] = v
|
|
447
|
-
if result.get("currentBlock"
|
|
447
|
+
if result.get("currentBlock") and result.get("highestBlock"):
|
|
448
448
|
result["remaining"] = result["highestBlock"] - result["currentBlock"]
|
|
449
449
|
return Ok(result, res.data)
|
|
450
450
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import os.path
|
|
2
1
|
import random
|
|
3
2
|
import shutil
|
|
4
3
|
from dataclasses import dataclass
|
|
@@ -15,9 +14,9 @@ class SolcResult:
|
|
|
15
14
|
|
|
16
15
|
def solc(contract_name: str, contract_path: str, tmp_dir: str) -> Result[SolcResult]:
|
|
17
16
|
if tmp_dir.startswith("~"):
|
|
18
|
-
tmp_dir =
|
|
17
|
+
tmp_dir = Path(tmp_dir).expanduser().as_posix()
|
|
19
18
|
if contract_path.startswith("~"):
|
|
20
|
-
contract_path =
|
|
19
|
+
contract_path = Path(contract_path).expanduser().as_posix()
|
|
21
20
|
work_dir = f"{tmp_dir}/solc_{contract_name}_{random.randint(0, 100_000_000)}"
|
|
22
21
|
abi_path = f"{work_dir}/{contract_name}.abi"
|
|
23
22
|
bin_path = f"{work_dir}/{contract_name}.bin"
|
|
@@ -44,14 +44,12 @@ class RPLTransaction(rlp.Serializable): # type: ignore[misc]
|
|
|
44
44
|
to: str | None = None,
|
|
45
45
|
) -> RPLTransaction:
|
|
46
46
|
if to:
|
|
47
|
-
to = hex_to_bytes(to) # type:ignore
|
|
47
|
+
to = hex_to_bytes(to) # type: ignore[assignment]
|
|
48
48
|
if data:
|
|
49
|
-
data = hex_to_bytes(data) # type:ignore
|
|
49
|
+
data = hex_to_bytes(data) # type: ignore[assignment]
|
|
50
50
|
if not value:
|
|
51
51
|
value = 0
|
|
52
|
-
|
|
53
|
-
s = int(s, 16) # type:ignore
|
|
54
|
-
return RPLTransaction(nonce, gas_price, gas, to, value, data, v, r, s)
|
|
52
|
+
return RPLTransaction(nonce, gas_price, gas, to, value, data, v, int(r, 16), int(s, 16))
|
|
55
53
|
|
|
56
54
|
|
|
57
55
|
class DecodedRawTx(BaseModel):
|
|
@@ -16,23 +16,22 @@ from mm_eth.types import Nodes, Proxies
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
def parse_addresses(data: str) -> list[str]:
|
|
19
|
-
data = data.lower()
|
|
20
19
|
result = []
|
|
21
|
-
for word in data.split():
|
|
20
|
+
for word in data.lower().split():
|
|
22
21
|
if len(word) == 42 and re.match("0x[a-f0-9]{40}", word):
|
|
23
|
-
result.append(word)
|
|
22
|
+
result.append(word) # noqa: PERF401
|
|
24
23
|
return pydash.uniq(result)
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
def to_token_wei(value: str | int, decimals: int) -> int:
|
|
28
27
|
if isinstance(value, int):
|
|
29
28
|
return value
|
|
30
|
-
|
|
29
|
+
if isinstance(value, str):
|
|
31
30
|
value = value.lower().replace(" ", "").strip()
|
|
32
31
|
if value.endswith("t"):
|
|
33
32
|
value = value.replace("t", "")
|
|
34
33
|
return int(Decimal(value) * 10**decimals)
|
|
35
|
-
|
|
34
|
+
if value.isdigit():
|
|
36
35
|
return int(value)
|
|
37
36
|
|
|
38
37
|
raise ValueError("wrong value" + value)
|
|
@@ -41,11 +40,11 @@ def to_token_wei(value: str | int, decimals: int) -> int:
|
|
|
41
40
|
def to_wei(value: str | int | Decimal, decimals: int | None = None) -> Wei:
|
|
42
41
|
if isinstance(value, int):
|
|
43
42
|
return Wei(value)
|
|
44
|
-
|
|
43
|
+
if isinstance(value, Decimal):
|
|
45
44
|
if value != value.to_integral_value():
|
|
46
45
|
raise ValueError(f"value must be integral number: {value}")
|
|
47
46
|
return Wei(int(value))
|
|
48
|
-
|
|
47
|
+
if isinstance(value, str):
|
|
49
48
|
value = value.lower().replace(" ", "").strip()
|
|
50
49
|
if value.endswith("navax"): # https://snowtrace.io/unitconverter
|
|
51
50
|
value = value.replace("navax", "")
|
|
@@ -68,8 +67,7 @@ def to_wei(value: str | int | Decimal, decimals: int | None = None) -> Wei:
|
|
|
68
67
|
return Wei(int(value))
|
|
69
68
|
raise ValueError("wrong value " + value)
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
raise ValueError(f"value has a wrong type: {type(value)}")
|
|
70
|
+
raise ValueError(f"value has a wrong type: {type(value)}")
|
|
73
71
|
|
|
74
72
|
|
|
75
73
|
def from_wei(
|
|
@@ -125,11 +123,11 @@ def from_token_wei_str(value: int, decimals: int, symbol: str = "", round_ndigit
|
|
|
125
123
|
def to_wei_token(value: str | int | Decimal, symbol: str, decimals: int) -> int:
|
|
126
124
|
if isinstance(value, int):
|
|
127
125
|
return value
|
|
128
|
-
|
|
126
|
+
if isinstance(value, Decimal):
|
|
129
127
|
if value != value.to_integral_value():
|
|
130
128
|
raise ValueError(f"value must be integral number: {value}")
|
|
131
129
|
return int(value)
|
|
132
|
-
|
|
130
|
+
if isinstance(value, str):
|
|
133
131
|
value = value.lower().replace(" ", "").strip()
|
|
134
132
|
if value.isdigit():
|
|
135
133
|
return int(value)
|
|
@@ -138,7 +136,7 @@ def to_wei_token(value: str | int | Decimal, symbol: str, decimals: int) -> int:
|
|
|
138
136
|
except Exception as e:
|
|
139
137
|
raise ValueError from e
|
|
140
138
|
else:
|
|
141
|
-
raise
|
|
139
|
+
raise TypeError(f"value has a wrong type: {type(value)}")
|
|
142
140
|
|
|
143
141
|
|
|
144
142
|
def to_checksum_address(address: str) -> str:
|
|
@@ -185,10 +183,7 @@ def truncate_hex_str(hex_str: str, digits: int = 4, replace_str: str = "...") ->
|
|
|
185
183
|
|
|
186
184
|
|
|
187
185
|
def log_topic_to_address(topic: HexBytes | str) -> str:
|
|
188
|
-
if isinstance(topic, HexBytes):
|
|
189
|
-
result = topic.hex()[-40:]
|
|
190
|
-
else:
|
|
191
|
-
result = topic[-40:]
|
|
186
|
+
result = topic.hex()[-40:] if isinstance(topic, HexBytes) else topic[-40:]
|
|
192
187
|
if not result.startswith("0x"):
|
|
193
188
|
result = f"0x{result}"
|
|
194
189
|
return result
|
|
@@ -15,7 +15,8 @@ def read_keys_from_vault(keys_url: str, token: str) -> Result[dict[str, str]]:
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def set_keys_from_vault(keys_url: str, token: str, private_keys: list[str], verify_tls: bool = True) -> Result[bool]:
|
|
18
|
-
"""It works with KV version=1 only!!!"""
|
|
18
|
+
"""It works with KV version=1 only!!!"""
|
|
19
|
+
# TODO: check that keys_url is kv1 version and error if it's kv2
|
|
19
20
|
data = None
|
|
20
21
|
try:
|
|
21
22
|
# keys_url example, https://vault.site.com:8200/v1/kv/keys1
|
|
@@ -23,16 +24,15 @@ def set_keys_from_vault(keys_url: str, token: str, private_keys: list[str], veri
|
|
|
23
24
|
for private_key in private_keys:
|
|
24
25
|
address = private_to_address(private_key)
|
|
25
26
|
if address is None:
|
|
26
|
-
|
|
27
|
+
return Err("wrong private key", data=data)
|
|
27
28
|
keys[address] = private_key
|
|
28
29
|
|
|
29
30
|
res = hr(keys_url, method="post", headers={"X-Vault-Token": token}, params=keys, verify=verify_tls)
|
|
30
31
|
data = res.json
|
|
31
32
|
if res.code == 204:
|
|
32
33
|
return Ok(res.code == 204, data=data)
|
|
33
|
-
|
|
34
|
+
if res.code == 403:
|
|
34
35
|
return Err("permission denied", data=data)
|
|
35
|
-
|
|
36
|
-
return Err(res.error or "error", data=data)
|
|
36
|
+
return Err(res.error or "error", data=data)
|
|
37
37
|
except Exception as e:
|
|
38
38
|
return Err(f"exception: {e}", data=data)
|
|
@@ -9,12 +9,12 @@ from mm_eth.anvil import Anvil
|
|
|
9
9
|
|
|
10
10
|
@pytest.fixture()
|
|
11
11
|
def mnemonic() -> str:
|
|
12
|
-
return "diet render mix evil relax apology hazard bamboo desert sign fence usage baby athlete cannon season busy ten jaguar silk rebel identify foster shrimp" # noqa
|
|
12
|
+
return "diet render mix evil relax apology hazard bamboo desert sign fence usage baby athlete cannon season busy ten jaguar silk rebel identify foster shrimp" # noqa: E501
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@pytest.fixture()
|
|
16
16
|
def erc20_token_abi_str() -> str:
|
|
17
|
-
return r'[{"inputs":[{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"totalSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]' # noqa
|
|
17
|
+
return r'[{"inputs":[{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"totalSupply","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]' # noqa: E501
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
@pytest.fixture()
|
|
@@ -24,14 +24,14 @@ def erc20_abi(erc20_token_abi_str) -> ABI:
|
|
|
24
24
|
|
|
25
25
|
@pytest.fixture()
|
|
26
26
|
def erc20_token_bin() -> str:
|
|
27
|
-
return "608060405234801562000010575f80fd5b5060405162000d1338038062000d138339810160408190526200003391620001dc565b60036200004183826200033b565b5060046200005083826200033b565b506005805460ff191660121790556200006a338262000072565b505062000423565b6001600160a01b038216620000ce5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064015b60405180910390fd5b600254620000dd90826200015d565b6002556001600160a01b0382165f908152602081905260409020546200010490826200015d565b6001600160a01b0383165f81815260208181526040808320949094559251848152919290917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b5f806200016b838562000403565b905083811015620001bf5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401620000c5565b90505b92915050565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215620001ee575f80fd5b82516001600160401b038082111562000205575f80fd5b818501915085601f83011262000219575f80fd5b8151818111156200022e576200022e620001c8565b604051601f8201601f19908116603f01168101908382118183101715620002595762000259620001c8565b8160405282815260209350888484870101111562000275575f80fd5b5f91505b8282101562000298578482018401518183018501529083019062000279565b5f928101840192909252509401519395939450505050565b600181811c90821680620002c557607f821691505b602082108103620002e457634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111562000158575f81815260208120601f850160051c81016020861015620003125750805b601f850160051c820191505b8181101562000333578281556001016200031e565b505050505050565b81516001600160401b03811115620003575762000357620001c8565b6200036f81620003688454620002b0565b84620002ea565b602080601f831160018114620003a5575f84156200038d5750858301515b5f19600386901b1c1916600185901b17855562000333565b5f85815260208120601f198616915b82811015620003d557888601518255948401946001909101908401620003b4565b5085821015620003f357878501515f19600388901b60f8161c191681555b5050505050600190811b01905550565b80820180821115620001c257634e487b7160e01b5f52601160045260245ffd5b6108e280620004315f395ff3fe608060405234801561000f575f80fd5b50600436106100a6575f3560e01c8063395093511161006e578063395093511461012557806370a082311461013857806395d89b4114610160578063a457c2d714610168578063a9059cbb1461017b578063dd62ed3e1461018e575f80fd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f80fd5b6100b26101c6565b6040516100bf91906106b6565b60405180910390f35b6100db6100d636600461071c565b610256565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610744565b61026c565b60055460405160ff90911681526020016100bf565b6100db61013336600461071c565b6102d3565b6100ef61014636600461077d565b6001600160a01b03165f9081526020819052604090205490565b6100b2610308565b6100db61017636600461071c565b610317565b6100db61018936600461071c565b610364565b6100ef61019c366004610796565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546101d5906107c7565b80601f0160208091040260200160405190810160405280929190818152602001828054610201906107c7565b801561024c5780601f106102235761010080835404028352916020019161024c565b820191905f5260205f20905b81548152906001019060200180831161022f57829003601f168201915b5050505050905090565b5f610262338484610370565b5060015b92915050565b5f610278848484610499565b6102c984336102c485604051806060016040528060288152602001610860602891396001600160a01b038a165f9081526001602090815260408083203384529091529020549190610619565b610370565b5060019392505050565b335f8181526001602090815260408083206001600160a01b038716845290915281205490916102629185906102c49086610651565b6060600480546101d5906107c7565b5f61026233846102c48560405180606001604052806025815260200161088860259139335f9081526001602090815260408083206001600160a01b038d1684529091529020549190610619565b5f610262338484610499565b6001600160a01b0383166103d75760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084015b60405180910390fd5b6001600160a01b0382166104385760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016103ce565b6001600160a01b038381165f8181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b0383166104fd5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016103ce565b6001600160a01b03821661055f5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016103ce565b61059b8160405180606001604052806026815260200161083a602691396001600160a01b0386165f908152602081905260409020549190610619565b6001600160a01b038085165f9081526020819052604080822093909355908416815220546105c99082610651565b6001600160a01b038381165f818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910161048c565b5f818484111561063c5760405162461bcd60e51b81526004016103ce91906106b6565b505f6106488486610813565b95945050505050565b5f8061065d8385610826565b9050838110156106af5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016103ce565b9392505050565b5f6020808352835180828501525f5b818110156106e1578581018301518582016040015282016106c5565b505f604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610717575f80fd5b919050565b5f806040838503121561072d575f80fd5b61073683610701565b946020939093013593505050565b5f805f60608486031215610756575f80fd5b61075f84610701565b925061076d60208501610701565b9150604084013590509250925092565b5f6020828403121561078d575f80fd5b6106af82610701565b5f80604083850312156107a7575f80fd5b6107b083610701565b91506107be60208401610701565b90509250929050565b600181811c908216806107db57607f821691505b6020821081036107f957634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610266576102666107ff565b80820180821115610266576102666107ff56fe45524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220fdf5850518272abc852e84db2b1c5e730e5de114aa27c25a2f3447b021fb005064736f6c63430008140033" # noqa
|
|
27
|
+
return "608060405234801562000010575f80fd5b5060405162000d1338038062000d138339810160408190526200003391620001dc565b60036200004183826200033b565b5060046200005083826200033b565b506005805460ff191660121790556200006a338262000072565b505062000423565b6001600160a01b038216620000ce5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064015b60405180910390fd5b600254620000dd90826200015d565b6002556001600160a01b0382165f908152602081905260409020546200010490826200015d565b6001600160a01b0383165f81815260208181526040808320949094559251848152919290917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b5f806200016b838562000403565b905083811015620001bf5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f7700000000006044820152606401620000c5565b90505b92915050565b634e487b7160e01b5f52604160045260245ffd5b5f8060408385031215620001ee575f80fd5b82516001600160401b038082111562000205575f80fd5b818501915085601f83011262000219575f80fd5b8151818111156200022e576200022e620001c8565b604051601f8201601f19908116603f01168101908382118183101715620002595762000259620001c8565b8160405282815260209350888484870101111562000275575f80fd5b5f91505b8282101562000298578482018401518183018501529083019062000279565b5f928101840192909252509401519395939450505050565b600181811c90821680620002c557607f821691505b602082108103620002e457634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111562000158575f81815260208120601f850160051c81016020861015620003125750805b601f850160051c820191505b8181101562000333578281556001016200031e565b505050505050565b81516001600160401b03811115620003575762000357620001c8565b6200036f81620003688454620002b0565b84620002ea565b602080601f831160018114620003a5575f84156200038d5750858301515b5f19600386901b1c1916600185901b17855562000333565b5f85815260208120601f198616915b82811015620003d557888601518255948401946001909101908401620003b4565b5085821015620003f357878501515f19600388901b60f8161c191681555b5050505050600190811b01905550565b80820180821115620001c257634e487b7160e01b5f52601160045260245ffd5b6108e280620004315f395ff3fe608060405234801561000f575f80fd5b50600436106100a6575f3560e01c8063395093511161006e578063395093511461012557806370a082311461013857806395d89b4114610160578063a457c2d714610168578063a9059cbb1461017b578063dd62ed3e1461018e575f80fd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f80fd5b6100b26101c6565b6040516100bf91906106b6565b60405180910390f35b6100db6100d636600461071c565b610256565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610744565b61026c565b60055460405160ff90911681526020016100bf565b6100db61013336600461071c565b6102d3565b6100ef61014636600461077d565b6001600160a01b03165f9081526020819052604090205490565b6100b2610308565b6100db61017636600461071c565b610317565b6100db61018936600461071c565b610364565b6100ef61019c366004610796565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546101d5906107c7565b80601f0160208091040260200160405190810160405280929190818152602001828054610201906107c7565b801561024c5780601f106102235761010080835404028352916020019161024c565b820191905f5260205f20905b81548152906001019060200180831161022f57829003601f168201915b5050505050905090565b5f610262338484610370565b5060015b92915050565b5f610278848484610499565b6102c984336102c485604051806060016040528060288152602001610860602891396001600160a01b038a165f9081526001602090815260408083203384529091529020549190610619565b610370565b5060019392505050565b335f8181526001602090815260408083206001600160a01b038716845290915281205490916102629185906102c49086610651565b6060600480546101d5906107c7565b5f61026233846102c48560405180606001604052806025815260200161088860259139335f9081526001602090815260408083206001600160a01b038d1684529091529020549190610619565b5f610262338484610499565b6001600160a01b0383166103d75760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084015b60405180910390fd5b6001600160a01b0382166104385760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016103ce565b6001600160a01b038381165f8181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b0383166104fd5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016103ce565b6001600160a01b03821661055f5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016103ce565b61059b8160405180606001604052806026815260200161083a602691396001600160a01b0386165f908152602081905260409020549190610619565b6001600160a01b038085165f9081526020819052604080822093909355908416815220546105c99082610651565b6001600160a01b038381165f818152602081815260409182902094909455518481529092918616917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910161048c565b5f818484111561063c5760405162461bcd60e51b81526004016103ce91906106b6565b505f6106488486610813565b95945050505050565b5f8061065d8385610826565b9050838110156106af5760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016103ce565b9392505050565b5f6020808352835180828501525f5b818110156106e1578581018301518582016040015282016106c5565b505f604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610717575f80fd5b919050565b5f806040838503121561072d575f80fd5b61073683610701565b946020939093013593505050565b5f805f60608486031215610756575f80fd5b61075f84610701565b925061076d60208501610701565b9150604084013590509250925092565b5f6020828403121561078d575f80fd5b6106af82610701565b5f80604083850312156107a7575f80fd5b6107b083610701565b91506107be60208401610701565b90509250929050565b600181811c908216806107db57607f821691505b6020821081036107f957634e487b7160e01b5f52602260045260245ffd5b50919050565b634e487b7160e01b5f52601160045260245ffd5b81810381811115610266576102666107ff565b80820180821115610266576102666107ff56fe45524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e636545524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e636545524332303a2064656372656173656420616c6c6f77616e63652062656c6f77207a65726fa2646970667358221220fdf5850518272abc852e84db2b1c5e730e5de114aa27c25a2f3447b021fb005064736f6c63430008140033" # noqa: E501
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
@pytest.fixture()
|
|
31
31
|
def anvil(mnemonic):
|
|
32
32
|
res = Anvil.launch(mnemonic=mnemonic)
|
|
33
33
|
if isinstance(res, Err):
|
|
34
|
-
raise
|
|
34
|
+
raise RuntimeError(f"can't start anvil: {res.err}") # noqa: TRY004
|
|
35
35
|
a = res.ok
|
|
36
36
|
try:
|
|
37
37
|
yield a
|
|
@@ -59,8 +59,7 @@ def infura():
|
|
|
59
59
|
def _infura(network="mainnet", ws=False):
|
|
60
60
|
if ws:
|
|
61
61
|
return f"wss://{network}.infura.io/ws/v3/{infura}"
|
|
62
|
-
|
|
63
|
-
return f"https://{network}.infura.io/v3/{infura}"
|
|
62
|
+
return f"https://{network}.infura.io/v3/{infura}"
|
|
64
63
|
|
|
65
64
|
return _infura
|
|
66
65
|
|
|
@@ -13,7 +13,7 @@ def test_get_function_abi(erc20_abi):
|
|
|
13
13
|
|
|
14
14
|
def test_encode_function_input_by_abi(erc20_abi):
|
|
15
15
|
res = abi.encode_function_input_by_abi(erc20_abi, "transfer", ["0x2D88bd70Eb6c20302D4cdD69abeBEea02deEBEAE", 123456])
|
|
16
|
-
input_data = "0xa9059cbb0000000000000000000000002d88bd70eb6c20302d4cdd69abebeea02deebeae000000000000000000000000000000000000000000000000000000000001e240" # noqa
|
|
16
|
+
input_data = "0xa9059cbb0000000000000000000000002d88bd70eb6c20302d4cdd69abebeea02deebeae000000000000000000000000000000000000000000000000000000000001e240" # noqa: E501
|
|
17
17
|
assert res == input_data
|
|
18
18
|
|
|
19
19
|
|
|
@@ -22,5 +22,5 @@ def test_encode_function_input_by_signature():
|
|
|
22
22
|
"transfer(address,uint256)",
|
|
23
23
|
["0x2D88bd70Eb6c20302D4cdD69abeBEea02deEBEAE", 123456],
|
|
24
24
|
)
|
|
25
|
-
input_data = "0xa9059cbb0000000000000000000000002d88bd70eb6c20302d4cdd69abebeea02deebeae000000000000000000000000000000000000000000000000000000000001e240" # noqa
|
|
25
|
+
input_data = "0xa9059cbb0000000000000000000000002d88bd70eb6c20302d4cdd69abebeea02deebeae000000000000000000000000000000000000000000000000000000000001e240" # noqa: E501
|
|
26
26
|
assert res == input_data
|
|
@@ -2,7 +2,7 @@ from mm_eth import tx
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
def test_sign_legacy_tx(private_0, address_1):
|
|
5
|
-
raw_tx = "0xf8601f0b169458487485c3858109f5a37e42546fe87473f79a4b218312399926a00739cb05ce6b1370b4dd53745e51202c2416427d47f60dd19cedbbec1ae8d5d0a064eea36637d9bd09b6e2efa8d20a906fd0146a6798a1b4db29457b6e9539862b" # noqa
|
|
5
|
+
raw_tx = "0xf8601f0b169458487485c3858109f5a37e42546fe87473f79a4b218312399926a00739cb05ce6b1370b4dd53745e51202c2416427d47f60dd19cedbbec1ae8d5d0a064eea36637d9bd09b6e2efa8d20a906fd0146a6798a1b4db29457b6e9539862b" # noqa: E501
|
|
6
6
|
res = tx.sign_legacy_tx(
|
|
7
7
|
nonce=31,
|
|
8
8
|
gas_price=11,
|
|
@@ -18,14 +18,14 @@ def test_sign_legacy_tx(private_0, address_1):
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def test_decode_raw_tx(address_1):
|
|
21
|
-
raw_tx = "0xf8601f0b169458487485c3858109f5a37e42546fe87473f79a4b218312399926a00739cb05ce6b1370b4dd53745e51202c2416427d47f60dd19cedbbec1ae8d5d0a064eea36637d9bd09b6e2efa8d20a906fd0146a6798a1b4db29457b6e9539862b" # noqa
|
|
21
|
+
raw_tx = "0xf8601f0b169458487485c3858109f5a37e42546fe87473f79a4b218312399926a00739cb05ce6b1370b4dd53745e51202c2416427d47f60dd19cedbbec1ae8d5d0a064eea36637d9bd09b6e2efa8d20a906fd0146a6798a1b4db29457b6e9539862b" # noqa: E501
|
|
22
22
|
res = tx.decode_raw_tx(raw_tx)
|
|
23
23
|
assert res.tx_hash == "0x0400cadbd22ce24ef98ffa0ffe337997758edbde5e4faebe6cda63d8246f545c"
|
|
24
24
|
assert res.to == address_1
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def test_encode_raw_tx_with_signature():
|
|
28
|
-
raw_tx = "0xf8601f0b16949e8daea6fed7e024d9d4c802115a81e908905a8e218312399925a0bd1601a62708068a486c1b0fc793f368fbe629823cb9fd861c9c3c2a37aa7ca6a07dfc3abd01cbfa177fb77595b883ee1062d5146bc006b2c8afa6199defac1dc1" # noqa
|
|
28
|
+
raw_tx = "0xf8601f0b16949e8daea6fed7e024d9d4c802115a81e908905a8e218312399925a0bd1601a62708068a486c1b0fc793f368fbe629823cb9fd861c9c3c2a37aa7ca6a07dfc3abd01cbfa177fb77595b883ee1062d5146bc006b2c8afa6199defac1dc1" # noqa: E501
|
|
29
29
|
decoded_tx = tx.decode_raw_tx(raw_tx)
|
|
30
30
|
res = tx.encode_raw_tx_with_signature(
|
|
31
31
|
nonce=decoded_tx.nonce,
|