eth-portfolio 0.5.8__cp311-cp311-musllinux_1_2_x86_64.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.
- eth_portfolio/__init__.py +24 -0
- eth_portfolio/_argspec.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_argspec.py +43 -0
- eth_portfolio/_cache.py +119 -0
- eth_portfolio/_config.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_config.py +4 -0
- eth_portfolio/_db/__init__.py +0 -0
- eth_portfolio/_db/decorators.py +147 -0
- eth_portfolio/_db/entities.py +311 -0
- eth_portfolio/_db/utils.py +619 -0
- eth_portfolio/_decimal.py +154 -0
- eth_portfolio/_decorators.py +84 -0
- eth_portfolio/_exceptions.py +65 -0
- eth_portfolio/_ledgers/__init__.py +0 -0
- eth_portfolio/_ledgers/address.py +917 -0
- eth_portfolio/_ledgers/portfolio.py +328 -0
- eth_portfolio/_loaders/__init__.py +33 -0
- eth_portfolio/_loaders/_nonce.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_loaders/_nonce.py +193 -0
- eth_portfolio/_loaders/balances.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_loaders/balances.py +95 -0
- eth_portfolio/_loaders/token_transfer.py +215 -0
- eth_portfolio/_loaders/transaction.py +240 -0
- eth_portfolio/_loaders/utils.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_loaders/utils.py +67 -0
- eth_portfolio/_shitcoins.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_shitcoins.py +342 -0
- eth_portfolio/_stableish.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/_stableish.py +42 -0
- eth_portfolio/_submodules.py +72 -0
- eth_portfolio/_utils.py +229 -0
- eth_portfolio/_ydb/__init__.py +0 -0
- eth_portfolio/_ydb/token_transfers.py +144 -0
- eth_portfolio/address.py +396 -0
- eth_portfolio/buckets.py +212 -0
- eth_portfolio/constants.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio/constants.py +87 -0
- eth_portfolio/portfolio.py +669 -0
- eth_portfolio/protocols/__init__.py +64 -0
- eth_portfolio/protocols/_base.py +107 -0
- eth_portfolio/protocols/convex.py +17 -0
- eth_portfolio/protocols/dsr.py +50 -0
- eth_portfolio/protocols/lending/README.md +6 -0
- eth_portfolio/protocols/lending/__init__.py +50 -0
- eth_portfolio/protocols/lending/_base.py +56 -0
- eth_portfolio/protocols/lending/compound.py +186 -0
- eth_portfolio/protocols/lending/liquity.py +108 -0
- eth_portfolio/protocols/lending/maker.py +110 -0
- eth_portfolio/protocols/lending/unit.py +44 -0
- eth_portfolio/protocols/liquity.py +17 -0
- eth_portfolio/py.typed +0 -0
- eth_portfolio/structs/__init__.py +43 -0
- eth_portfolio/structs/modified.py +69 -0
- eth_portfolio/structs/structs.py +628 -0
- eth_portfolio/typing/__init__.py +1418 -0
- eth_portfolio/typing/balance/single.py +176 -0
- eth_portfolio-0.5.8.dist-info/METADATA +28 -0
- eth_portfolio-0.5.8.dist-info/RECORD +83 -0
- eth_portfolio-0.5.8.dist-info/WHEEL +5 -0
- eth_portfolio-0.5.8.dist-info/entry_points.txt +2 -0
- eth_portfolio-0.5.8.dist-info/top_level.txt +3 -0
- eth_portfolio__mypyc.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio_scripts/__init__.py +17 -0
- eth_portfolio_scripts/_args.py +26 -0
- eth_portfolio_scripts/_logging.py +14 -0
- eth_portfolio_scripts/_portfolio.py +209 -0
- eth_portfolio_scripts/_utils.py +106 -0
- eth_portfolio_scripts/balances.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio_scripts/balances.py +56 -0
- eth_portfolio_scripts/docker/.grafana/dashboards/Portfolio/Balances.json +1962 -0
- eth_portfolio_scripts/docker/.grafana/dashboards/dashboards.yaml +10 -0
- eth_portfolio_scripts/docker/.grafana/datasources/datasources.yml +11 -0
- eth_portfolio_scripts/docker/__init__.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio_scripts/docker/__init__.py +16 -0
- eth_portfolio_scripts/docker/check.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio_scripts/docker/check.py +66 -0
- eth_portfolio_scripts/docker/docker-compose.yaml +61 -0
- eth_portfolio_scripts/docker/docker_compose.cpython-311-x86_64-linux-musl.so +0 -0
- eth_portfolio_scripts/docker/docker_compose.py +97 -0
- eth_portfolio_scripts/main.py +118 -0
- eth_portfolio_scripts/py.typed +1 -0
- eth_portfolio_scripts/victoria/__init__.py +72 -0
- eth_portfolio_scripts/victoria/types.py +38 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from asyncio import Task, create_task, sleep
|
|
3
|
+
from collections.abc import AsyncGenerator
|
|
4
|
+
from datetime import datetime, timedelta, timezone
|
|
5
|
+
from typing import Any, Final
|
|
6
|
+
|
|
7
|
+
from brownie import chain
|
|
8
|
+
|
|
9
|
+
timedelta_pattern: Final = re.compile(r"(\d+)([dhms]?)")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_timedelta(value: str) -> timedelta:
|
|
13
|
+
days, hours, minutes, seconds = 0, 0, 0, 0
|
|
14
|
+
|
|
15
|
+
for val, unit in timedelta_pattern.findall(value):
|
|
16
|
+
val = int(val)
|
|
17
|
+
if unit == "d":
|
|
18
|
+
days = val
|
|
19
|
+
elif unit == "h":
|
|
20
|
+
hours = val
|
|
21
|
+
elif unit == "m":
|
|
22
|
+
minutes = val
|
|
23
|
+
elif unit == "s":
|
|
24
|
+
seconds = val
|
|
25
|
+
|
|
26
|
+
return timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
async def aiter_timestamps(
|
|
30
|
+
*,
|
|
31
|
+
start: datetime | None = None,
|
|
32
|
+
interval: timedelta = timedelta(days=1),
|
|
33
|
+
run_forever: bool = False,
|
|
34
|
+
) -> AsyncGenerator[datetime, None]:
|
|
35
|
+
"""
|
|
36
|
+
Generates the timestamps to be queried based on the specified range and interval.
|
|
37
|
+
"""
|
|
38
|
+
if not isinstance(run_forever, bool):
|
|
39
|
+
raise TypeError(f"`run_forever` must be boolean. You passed {run_forever}")
|
|
40
|
+
|
|
41
|
+
if start is None:
|
|
42
|
+
start = datetime.now(tz=timezone.utc)
|
|
43
|
+
|
|
44
|
+
block0_ts = datetime.fromtimestamp(chain[0].timestamp, tz=timezone.utc)
|
|
45
|
+
helper = datetime(
|
|
46
|
+
year=block0_ts.year,
|
|
47
|
+
month=block0_ts.month,
|
|
48
|
+
day=block0_ts.day,
|
|
49
|
+
hour=block0_ts.hour,
|
|
50
|
+
minute=block0_ts.minute,
|
|
51
|
+
tzinfo=timezone.utc,
|
|
52
|
+
)
|
|
53
|
+
while helper + interval < start:
|
|
54
|
+
helper += interval
|
|
55
|
+
start = helper
|
|
56
|
+
if start < block0_ts:
|
|
57
|
+
start += interval
|
|
58
|
+
|
|
59
|
+
timestamp = start
|
|
60
|
+
|
|
61
|
+
timestamps = []
|
|
62
|
+
while timestamp <= datetime.now(tz=timezone.utc):
|
|
63
|
+
timestamps.append(timestamp)
|
|
64
|
+
timestamp = timestamp + interval
|
|
65
|
+
|
|
66
|
+
# cycle between yielding earliest, latest, and middle from `timestamps` until complete
|
|
67
|
+
while timestamps:
|
|
68
|
+
# yield the earliest timestamp
|
|
69
|
+
yield timestamps.pop(0)
|
|
70
|
+
# yield the most recent timestamp if there is one
|
|
71
|
+
if timestamps:
|
|
72
|
+
yield timestamps.pop(-1)
|
|
73
|
+
# yield the most middle timestamp if there is one
|
|
74
|
+
if timestamps:
|
|
75
|
+
yield timestamps.pop(len(timestamps) // 2)
|
|
76
|
+
|
|
77
|
+
del timestamps
|
|
78
|
+
|
|
79
|
+
while run_forever:
|
|
80
|
+
while timestamp > datetime.now(tz=timezone.utc):
|
|
81
|
+
await _get_waiter(timestamp)
|
|
82
|
+
yield timestamp
|
|
83
|
+
timestamp += interval
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
_waiters: dict[datetime, "Task[None]"] = {}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _get_waiter(timestamp: datetime) -> "Task[None]":
|
|
90
|
+
if timestamp not in _waiters:
|
|
91
|
+
waiter = create_task(sleep_until(timestamp))
|
|
92
|
+
waiter.add_done_callback(_sleep_done_callback)
|
|
93
|
+
_waiters[timestamp] = waiter
|
|
94
|
+
return _waiters[timestamp]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
async def sleep_until(until: datetime) -> None:
|
|
98
|
+
now = datetime.now(tz=timezone.utc)
|
|
99
|
+
await sleep((until - now).total_seconds())
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _sleep_done_callback(t: "Task[Any]") -> None:
|
|
103
|
+
low_to_hi = sorted(_waiters)
|
|
104
|
+
for k in low_to_hi:
|
|
105
|
+
if _waiters[k] is t:
|
|
106
|
+
_waiters.pop(k)
|
|
Binary file
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from argparse import Namespace
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
import a_sync
|
|
6
|
+
import a_sync.asyncio
|
|
7
|
+
from eth_typing import HexAddress
|
|
8
|
+
|
|
9
|
+
from eth_portfolio_scripts import docker
|
|
10
|
+
from eth_portfolio_scripts._utils import aiter_timestamps, parse_timedelta
|
|
11
|
+
|
|
12
|
+
_UTC: Final = timezone.utc
|
|
13
|
+
|
|
14
|
+
create_task: Final = a_sync.create_task
|
|
15
|
+
yield_to_loop: Final = a_sync.asyncio.sleep0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@docker.ensure_containers
|
|
19
|
+
async def export_balances(
|
|
20
|
+
args: Namespace,
|
|
21
|
+
custom_buckets: dict[HexAddress, str] | None = None,
|
|
22
|
+
) -> None:
|
|
23
|
+
import dank_mids
|
|
24
|
+
|
|
25
|
+
from eth_portfolio_scripts._portfolio import ExportablePortfolio
|
|
26
|
+
|
|
27
|
+
if args.daemon is True:
|
|
28
|
+
raise NotImplementedError("This feature must be implemented")
|
|
29
|
+
|
|
30
|
+
interval = parse_timedelta(args.interval)
|
|
31
|
+
portfolio = ExportablePortfolio(
|
|
32
|
+
args.wallet,
|
|
33
|
+
label=args.label,
|
|
34
|
+
start_block=args.first_tx_block,
|
|
35
|
+
concurrency=args.concurrency,
|
|
36
|
+
custom_buckets=custom_buckets,
|
|
37
|
+
load_prices=False,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if export_start_block := args.export_start_block or args.first_tx_block:
|
|
41
|
+
start_ts = await dank_mids.eth.get_block_timestamp(export_start_block)
|
|
42
|
+
start = datetime.fromtimestamp(start_ts, tz=timezone.utc)
|
|
43
|
+
else:
|
|
44
|
+
start = None
|
|
45
|
+
|
|
46
|
+
print(f"Exporting {portfolio}")
|
|
47
|
+
async for ts in aiter_timestamps(start=start, interval=interval, run_forever=True):
|
|
48
|
+
create_task(
|
|
49
|
+
coro=portfolio.export_snapshot(ts, sync=False),
|
|
50
|
+
name=f"eth-portfolio export snapshot {ts}",
|
|
51
|
+
skip_gc_until_done=True,
|
|
52
|
+
)
|
|
53
|
+
# get some work in before yielding the next task
|
|
54
|
+
await yield_to_loop()
|
|
55
|
+
await yield_to_loop()
|
|
56
|
+
await yield_to_loop()
|