eth-portfolio 0.5.8__cp310-cp310-win_amd64.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.

Potentially problematic release.


This version of eth-portfolio might be problematic. Click here for more details.

Files changed (83) hide show
  1. eth_portfolio/__init__.py +24 -0
  2. eth_portfolio/_argspec.cp310-win_amd64.pyd +0 -0
  3. eth_portfolio/_argspec.py +43 -0
  4. eth_portfolio/_cache.py +119 -0
  5. eth_portfolio/_config.cp310-win_amd64.pyd +0 -0
  6. eth_portfolio/_config.py +4 -0
  7. eth_portfolio/_db/__init__.py +0 -0
  8. eth_portfolio/_db/decorators.py +147 -0
  9. eth_portfolio/_db/entities.py +311 -0
  10. eth_portfolio/_db/utils.py +619 -0
  11. eth_portfolio/_decimal.py +154 -0
  12. eth_portfolio/_decorators.py +84 -0
  13. eth_portfolio/_exceptions.py +65 -0
  14. eth_portfolio/_ledgers/__init__.py +0 -0
  15. eth_portfolio/_ledgers/address.py +917 -0
  16. eth_portfolio/_ledgers/portfolio.py +328 -0
  17. eth_portfolio/_loaders/__init__.py +33 -0
  18. eth_portfolio/_loaders/_nonce.cp310-win_amd64.pyd +0 -0
  19. eth_portfolio/_loaders/_nonce.py +193 -0
  20. eth_portfolio/_loaders/balances.cp310-win_amd64.pyd +0 -0
  21. eth_portfolio/_loaders/balances.py +95 -0
  22. eth_portfolio/_loaders/token_transfer.py +215 -0
  23. eth_portfolio/_loaders/transaction.py +240 -0
  24. eth_portfolio/_loaders/utils.cp310-win_amd64.pyd +0 -0
  25. eth_portfolio/_loaders/utils.py +67 -0
  26. eth_portfolio/_shitcoins.cp310-win_amd64.pyd +0 -0
  27. eth_portfolio/_shitcoins.py +342 -0
  28. eth_portfolio/_stableish.cp310-win_amd64.pyd +0 -0
  29. eth_portfolio/_stableish.py +42 -0
  30. eth_portfolio/_submodules.py +72 -0
  31. eth_portfolio/_utils.py +229 -0
  32. eth_portfolio/_ydb/__init__.py +0 -0
  33. eth_portfolio/_ydb/token_transfers.py +144 -0
  34. eth_portfolio/address.py +396 -0
  35. eth_portfolio/buckets.py +212 -0
  36. eth_portfolio/constants.cp310-win_amd64.pyd +0 -0
  37. eth_portfolio/constants.py +87 -0
  38. eth_portfolio/portfolio.py +669 -0
  39. eth_portfolio/protocols/__init__.py +64 -0
  40. eth_portfolio/protocols/_base.py +107 -0
  41. eth_portfolio/protocols/convex.py +17 -0
  42. eth_portfolio/protocols/dsr.py +50 -0
  43. eth_portfolio/protocols/lending/README.md +6 -0
  44. eth_portfolio/protocols/lending/__init__.py +50 -0
  45. eth_portfolio/protocols/lending/_base.py +56 -0
  46. eth_portfolio/protocols/lending/compound.py +186 -0
  47. eth_portfolio/protocols/lending/liquity.py +108 -0
  48. eth_portfolio/protocols/lending/maker.py +110 -0
  49. eth_portfolio/protocols/lending/unit.py +44 -0
  50. eth_portfolio/protocols/liquity.py +17 -0
  51. eth_portfolio/py.typed +0 -0
  52. eth_portfolio/structs/__init__.py +43 -0
  53. eth_portfolio/structs/modified.py +69 -0
  54. eth_portfolio/structs/structs.py +628 -0
  55. eth_portfolio/typing/__init__.py +1418 -0
  56. eth_portfolio/typing/balance/single.py +176 -0
  57. eth_portfolio-0.5.8.dist-info/METADATA +28 -0
  58. eth_portfolio-0.5.8.dist-info/RECORD +83 -0
  59. eth_portfolio-0.5.8.dist-info/WHEEL +5 -0
  60. eth_portfolio-0.5.8.dist-info/entry_points.txt +2 -0
  61. eth_portfolio-0.5.8.dist-info/top_level.txt +3 -0
  62. eth_portfolio__mypyc.cp310-win_amd64.pyd +0 -0
  63. eth_portfolio_scripts/__init__.py +17 -0
  64. eth_portfolio_scripts/_args.py +26 -0
  65. eth_portfolio_scripts/_logging.py +14 -0
  66. eth_portfolio_scripts/_portfolio.py +209 -0
  67. eth_portfolio_scripts/_utils.py +106 -0
  68. eth_portfolio_scripts/balances.cp310-win_amd64.pyd +0 -0
  69. eth_portfolio_scripts/balances.py +56 -0
  70. eth_portfolio_scripts/docker/.grafana/dashboards/Portfolio/Balances.json +1962 -0
  71. eth_portfolio_scripts/docker/.grafana/dashboards/dashboards.yaml +10 -0
  72. eth_portfolio_scripts/docker/.grafana/datasources/datasources.yml +11 -0
  73. eth_portfolio_scripts/docker/__init__.cp310-win_amd64.pyd +0 -0
  74. eth_portfolio_scripts/docker/__init__.py +16 -0
  75. eth_portfolio_scripts/docker/check.cp310-win_amd64.pyd +0 -0
  76. eth_portfolio_scripts/docker/check.py +66 -0
  77. eth_portfolio_scripts/docker/docker-compose.yaml +61 -0
  78. eth_portfolio_scripts/docker/docker_compose.cp310-win_amd64.pyd +0 -0
  79. eth_portfolio_scripts/docker/docker_compose.py +97 -0
  80. eth_portfolio_scripts/main.py +118 -0
  81. eth_portfolio_scripts/py.typed +1 -0
  82. eth_portfolio_scripts/victoria/__init__.py +72 -0
  83. eth_portfolio_scripts/victoria/types.py +38 -0
@@ -0,0 +1,10 @@
1
+ apiVersion: 1
2
+
3
+ providers:
4
+ - name: 'Portfolio dashboards'
5
+ folder: 'Portfolio'
6
+ type: file
7
+ disableDeletion: true
8
+ editable: false
9
+ options:
10
+ path: /etc/grafana/provisioning/dashboards/Portfolio
@@ -0,0 +1,11 @@
1
+ apiVersion: 1
2
+
3
+ datasources:
4
+ - name: 'PROMETHEUS'
5
+ type: 'prometheus'
6
+ access: 'proxy'
7
+ org_id: 1
8
+ url: 'http://victoria-metrics:8428'
9
+ is_default: true
10
+ version: 1
11
+ editable: false
@@ -0,0 +1,16 @@
1
+ from eth_portfolio_scripts.docker.check import check_docker, check_docker_compose, check_system
2
+ from eth_portfolio_scripts.docker.docker_compose import build, down, ensure_containers, stop, up
3
+
4
+ __all__ = [
5
+ # commands
6
+ "build",
7
+ "up",
8
+ "down",
9
+ "stop",
10
+ # decorators
11
+ "ensure_containers",
12
+ # checks
13
+ "check_docker",
14
+ "check_docker_compose",
15
+ "check_system",
16
+ ]
@@ -0,0 +1,66 @@
1
+ from functools import lru_cache
2
+ from subprocess import CalledProcessError, check_output
3
+
4
+
5
+ def check_docker() -> None:
6
+ """
7
+ Check that docker is installed on the user's system.
8
+
9
+ Raises:
10
+ RuntimeError: If docker is not installed.
11
+ """
12
+ print(" 🔍 checking your computer for docker")
13
+ try:
14
+ check_output(["docker", "--version"])
15
+ except (CalledProcessError, FileNotFoundError):
16
+ raise RuntimeError(
17
+ "Docker is not installed. You must install Docker before using dao-treasury."
18
+ ) from None
19
+ else:
20
+ print(" ✔️ eth-portfolio found docker!")
21
+
22
+
23
+ def check_docker_compose() -> list[str]:
24
+ """
25
+ Check that either `docker-compose` or `docker compose` is installed on the user's system.
26
+
27
+ Returns:
28
+ A valid compose command.
29
+
30
+ Raises:
31
+ RuntimeError: If docker-compose is not installed.
32
+ """
33
+ for cmd in ["docker-compose", "docker compose"]:
34
+ print(f" 🔍 checking your computer for {cmd}")
35
+
36
+ try:
37
+ check_output([*cmd.split(" "), "--version"])
38
+ except (CalledProcessError, FileNotFoundError):
39
+ print(f" ❌ {cmd} not found")
40
+ continue
41
+ else:
42
+ print(f" ✔️ eth-portfolio found {cmd}!")
43
+ return cmd.split(" ")
44
+
45
+ raise RuntimeError(
46
+ "Docker Compose is not installed. You must install Docker Compose before using dao-treasury."
47
+ ) from None
48
+
49
+
50
+ @lru_cache(maxsize=None)
51
+ def check_system() -> list[str]:
52
+ """
53
+ Check that docker and docker-compose is installed on the user's system.
54
+
55
+ Returns:
56
+ A valid compose command.
57
+
58
+ Raises:
59
+ RuntimeError: If docker-compose is not installed.
60
+ """
61
+ print("eth-portfolio is checking for the required docker dependencies...")
62
+ check_docker()
63
+ return check_docker_compose()
64
+
65
+
66
+ __all__ = ["check_docker", "check_docker_compose", "check_system"]
@@ -0,0 +1,61 @@
1
+ networks:
2
+ eth_portfolio:
3
+
4
+ services:
5
+ grafana:
6
+ image: grafana/grafana:12.3.1
7
+ ports:
8
+ - 127.0.0.1:${GRAFANA_PORT:-3000}:3000
9
+ environment:
10
+ - GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER:-admin}
11
+ - GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD:-admin}
12
+ - GF_AUTH_ANONYMOUS_ENABLED=true
13
+ - GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/portfolio/Balances.json
14
+ - GF_SERVER_ROOT_URL
15
+ - GF_RENDERING_SERVER_URL=http://renderer:8091/render
16
+ - GF_RENDERING_CALLBACK_URL=http://grafana:3000/
17
+ - GF_LOG_FILTERS=rendering:debug
18
+ #- GF_INSTALL_PLUGINS=volkovlabs-variable-panel
19
+ #command: >
20
+ # sh -c "grafana-cli plugins install frser-sqlite-datasource && /run.sh"
21
+ volumes:
22
+ - ./.grafana/:/etc/grafana/provisioning/
23
+ networks:
24
+ - eth_portfolio
25
+ restart: always
26
+
27
+ renderer:
28
+ platform: linux/amd64
29
+ image: grafana/grafana-image-renderer:latest
30
+ ports:
31
+ - 127.0.0.1:${RENDERER_PORT:-8091}:8091
32
+ environment:
33
+ - ENABLE_METRICS=true
34
+ - HTTP_PORT=8091
35
+ networks:
36
+ - eth_portfolio
37
+ restart: always
38
+
39
+ vmagent:
40
+ image: victoriametrics/vmagent:heads-public-single-node-0-g52eb9c99e
41
+ command:
42
+ - "-remoteWrite.url=http://victoria-metrics:8428/api/v1/write"
43
+ depends_on:
44
+ - victoria-metrics
45
+ networks:
46
+ - eth_portfolio
47
+ restart: always
48
+
49
+ victoria-metrics:
50
+ image: victoriametrics/victoria-metrics:v1.134.0
51
+ volumes:
52
+ - ~/.eth-portfolio/data/victoria/:/victoria-metrics-data
53
+ command:
54
+ - '-memory.allowedBytes=3GB'
55
+ - "-retentionPeriod=10y"
56
+ - "-search.disableAutoCacheReset=true"
57
+ ports:
58
+ - 127.0.0.1:${VICTORIA_PORT:-8428}:8428
59
+ networks:
60
+ - eth_portfolio
61
+ restart: always
@@ -0,0 +1,97 @@
1
+ import logging
2
+ from collections.abc import Callable
3
+ from functools import wraps
4
+ from importlib import resources
5
+ from subprocess import CalledProcessError, check_output
6
+ from typing import Final, Literal, TypeVar
7
+
8
+ from typing_extensions import ParamSpec
9
+
10
+ from eth_portfolio_scripts.docker.check import check_system
11
+
12
+ logger: Final = logging.getLogger(__name__)
13
+
14
+ COMPOSE_FILE: Final = str(
15
+ resources.files("eth_portfolio_scripts").joinpath("docker/docker-compose.yaml")
16
+ )
17
+
18
+
19
+ def up(*services: str) -> None:
20
+ """Build and start the specified docker-compose services."""
21
+ build(*services)
22
+ _print_notice("starting", services)
23
+ _exec_command(["up", "-d", *services])
24
+
25
+
26
+ def down() -> None:
27
+ """Stop all of eth-portfolio's docker-compose services."""
28
+ _exec_command(["down"])
29
+
30
+
31
+ def build(*services: str) -> None:
32
+ """Build the specified docker-compose services."""
33
+ _print_notice("building", services)
34
+ _exec_command(["build", *services])
35
+
36
+
37
+ def stop(*services: str) -> None:
38
+ """Stop the specified docker-compose services, if running."""
39
+ _print_notice("stopping", services)
40
+ _exec_command(["stop", *services])
41
+
42
+
43
+ _P = ParamSpec("_P")
44
+ _T = TypeVar("_T")
45
+
46
+
47
+ def ensure_containers(fn: Callable[_P, _T]) -> Callable[_P, _T]:
48
+ @wraps(fn)
49
+ async def compose_wrap(*args: _P.args, **kwargs: _P.kwargs) -> _T:
50
+ # register shutdown sequence
51
+ # TODO: argument to leave them up
52
+ # NOTE: do we need both this and the finally?
53
+ # signal.signal(signal.SIGINT, down)
54
+
55
+ # start Grafana containers
56
+ up()
57
+
58
+ try:
59
+ # attempt to run `fn`
60
+ return await fn(*args, **kwargs)
61
+ finally:
62
+ # stop and remove containers
63
+ # down()
64
+ pass
65
+
66
+ return compose_wrap
67
+
68
+
69
+ def _print_notice(
70
+ doing: Literal["building", "starting", "stopping"],
71
+ services: tuple[str, ...],
72
+ ) -> None:
73
+ if len(services) == 0:
74
+ print(f"{doing} the backend containers")
75
+ elif len(services) == 1:
76
+ container = services[0]
77
+ print(f"{doing} the {container} container")
78
+ elif len(services) == 2:
79
+ first, second = services
80
+ print(f"{doing} the {first} and {second} containers")
81
+ else:
82
+ *all_but_last, last = services
83
+ print(f"{doing} the {', '.join(all_but_last)}, and {last} containers")
84
+
85
+
86
+ def _exec_command(
87
+ command: list[str],
88
+ *,
89
+ compose_file: str = COMPOSE_FILE,
90
+ compose_options: tuple[str, ...] = (),
91
+ ) -> None:
92
+ compose = check_system()
93
+ full_command = [*compose, *compose_options, "-f", compose_file, *command]
94
+ try:
95
+ check_output(full_command)
96
+ except (CalledProcessError, FileNotFoundError) as e:
97
+ raise RuntimeError(f"Error occurred while running `{' '.join(full_command)}`: {e}") from e
@@ -0,0 +1,118 @@
1
+ import asyncio
2
+ from argparse import ArgumentParser
3
+ from os import environ
4
+
5
+ import brownie
6
+
7
+ from eth_portfolio_scripts import docker
8
+ from eth_portfolio_scripts._args import add_infra_port_args
9
+ from eth_portfolio_scripts.balances import export_balances
10
+
11
+ parser = ArgumentParser(description="eth-portfolio")
12
+
13
+ subparsers = parser.add_subparsers(title="Commands", dest="command", required=True)
14
+
15
+ export_parser = subparsers.add_parser("export", help="Export a specific dataset for your portfolio")
16
+ export_parser.add_argument("target", help="Choose an exporter to run")
17
+ add_infra_port_args(export_parser)
18
+ export_parser.set_defaults(func=export_balances)
19
+
20
+ infra_parser = subparsers.add_parser(
21
+ "infra", help="Start the docker containers required to run any eth-portfolio service"
22
+ )
23
+ infra_parser.add_argument("cmd", help="What do you want to do?")
24
+ add_infra_port_args(infra_parser)
25
+ infra_parser.add_argument(
26
+ "--start-renderer",
27
+ action="store_true",
28
+ help="If set, starts the renderer container in addition to the default containers. By default, only grafana, victoria-metrics, and vmagent are started.",
29
+ )
30
+
31
+ export_parser.add_argument(
32
+ "--wallet",
33
+ type=str,
34
+ help="The address of a wallet to export. You can pass multiple, ie. `--wallet 0x123 0x234 0x345`",
35
+ required=True,
36
+ nargs="+",
37
+ )
38
+ export_parser.add_argument(
39
+ "--network",
40
+ type=str,
41
+ help="The brownie network identifier for the rpc you wish to use. default: mainnet",
42
+ default="mainnet",
43
+ )
44
+ export_parser.add_argument(
45
+ "--label",
46
+ type=str,
47
+ help='The label for this portfolio, if you want one. Defaults to "MyPortfolio".',
48
+ default="My Portfolio",
49
+ )
50
+ export_parser.add_argument(
51
+ "--interval",
52
+ type=str,
53
+ help="The time interval between datapoints. default: 6h",
54
+ default="6h",
55
+ )
56
+ export_parser.add_argument(
57
+ "--concurrency",
58
+ type=int,
59
+ help="The max number of historical blocks to export concurrently. default: 30",
60
+ default=30,
61
+ )
62
+ export_parser.add_argument(
63
+ "--first-tx-block",
64
+ type=int,
65
+ help=(
66
+ "The block of your portfolio's first transaction, if known. "
67
+ "This value, if provided, allows us to speed up processing of your data by limiting the block range we need to query. "
68
+ "If not provided, the whole blockchain will be scanned."
69
+ ),
70
+ default=0,
71
+ )
72
+ export_parser.add_argument(
73
+ "--export-start-block",
74
+ type=int,
75
+ help="The first block in the range you wish to export.",
76
+ default=0,
77
+ )
78
+ export_parser.add_argument(
79
+ "--daemon",
80
+ action="store_true",
81
+ help="TODO: If True, starts a daemon process instead of running in your terminal. Not currently supported.",
82
+ )
83
+
84
+ args = parser.parse_args()
85
+
86
+ if hasattr(args, "network"):
87
+ environ["BROWNIE_NETWORK_ID"] = args.network
88
+
89
+ environ["GRAFANA_PORT"] = str(args.grafana_port)
90
+ environ["RENDERER_PORT"] = str(args.renderer_port)
91
+ environ["VICTORIA_PORT"] = str(args.victoria_port)
92
+
93
+
94
+ # TODO: run forever arg
95
+ def main():
96
+ command = args.command
97
+ if command == "infra":
98
+ if args.cmd == "start":
99
+ # Start the backend containers
100
+ if getattr(args, "start_renderer", False):
101
+ docker.up()
102
+ else:
103
+ docker.up("grafana", "victoria-metrics", "vmagent")
104
+ elif args.cmd == "stop":
105
+ docker.down()
106
+ else:
107
+ raise ValueError(f"{args.target} is not a valid command")
108
+
109
+ else:
110
+ # The user's command is `export`
111
+ if args.target == "balances":
112
+ asyncio.run(args.func(args))
113
+ else:
114
+ raise ValueError(f"{args.target} is not a valid command")
115
+
116
+
117
+ if __name__ == "__main__":
118
+ brownie.project.run(__file__)
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,72 @@
1
+ from gzip import compress
2
+ from logging import getLogger
3
+ from os import environ
4
+ from typing import Final, List
5
+
6
+ import a_sync
7
+ from aiohttp import ClientError, ClientSession, ServerDisconnectedError
8
+ from msgspec import json
9
+
10
+ from eth_portfolio_scripts.victoria import types
11
+ from eth_portfolio_scripts.victoria.types import Metric
12
+
13
+ BASE_URL: Final = environ.get("VM_URL", "http://127.0.0.1:8430")
14
+
15
+ # this will be populated later
16
+ session: ClientSession = None # type: ignore [assignment]
17
+
18
+ logger: Final = getLogger("eth_portfolio.victoria")
19
+
20
+ encode: Final = json.encode
21
+ decode: Final = json.decode
22
+
23
+
24
+ class VictoriaMetricsError(ValueError): ...
25
+
26
+
27
+ def get_session() -> ClientSession:
28
+ sesh = session
29
+ if sesh is None:
30
+ sesh = ClientSession(BASE_URL, raise_for_status=True)
31
+ __set_session(sesh)
32
+ return sesh
33
+
34
+
35
+ async def get(url: str) -> bytes:
36
+ session = get_session()
37
+ while True:
38
+ try:
39
+ async with session.get(url=url, headers={"Connection": "close"}) as response:
40
+ return await response.read()
41
+ except ServerDisconnectedError:
42
+ continue
43
+
44
+
45
+ @a_sync.Semaphore(2)
46
+ async def post_data(metrics_to_export: list["Metric"]) -> None:
47
+ """Post all metrics at once."""
48
+ data = compress(b"\n".join(encode(metric) for metric in metrics_to_export))
49
+ attempts = 0
50
+ session = get_session()
51
+ while True:
52
+ try:
53
+ async with session.post(
54
+ "/api/v1/import",
55
+ headers={"Connection": "close", "Content-Encoding": "gzip"},
56
+ data=data,
57
+ ):
58
+ logger.debug(f"posted {len(data)} datas")
59
+ return
60
+ except ClientError as e:
61
+ attempts += 1
62
+ logger.debug("You had a ClientError: %s", e)
63
+ if attempts >= 10:
64
+ raise e
65
+
66
+
67
+ def __set_session(sesh: ClientSession) -> None:
68
+ global session
69
+ session = sesh
70
+
71
+
72
+ __all__ = ["Metric", "get", "post_data"]
@@ -0,0 +1,38 @@
1
+ """
2
+ These 2 helpers enable us to decode only the relevant data in the json response and discard the rest
3
+ They're in a separate file so mypyc doesn't try to compile them
4
+ """
5
+
6
+ from typing import TypedDict, final
7
+
8
+ from eth_typing import ChecksumAddress
9
+ from msgspec import Raw, Struct
10
+
11
+
12
+ @final
13
+ class Metric(TypedDict):
14
+ param: str
15
+ wallet: ChecksumAddress
16
+ token_address: ChecksumAddress
17
+ token: str
18
+ bucket: str
19
+ network: str
20
+ __name__: str
21
+
22
+
23
+ @final
24
+ class PrometheusItem(TypedDict):
25
+ metric: Metric
26
+ values: list[float]
27
+ timestamps: list[float]
28
+
29
+
30
+ @final
31
+ class Data(Struct):
32
+ result: tuple[Raw, ...]
33
+
34
+
35
+ @final
36
+ class Response(Struct):
37
+ status: str
38
+ data: Data