eth-portfolio 0.5.2__cp312-cp312-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.
Files changed (83) hide show
  1. eth_portfolio/__init__.py +25 -0
  2. eth_portfolio/_argspec.cpython-312-x86_64-linux-musl.so +0 -0
  3. eth_portfolio/_argspec.py +42 -0
  4. eth_portfolio/_cache.py +121 -0
  5. eth_portfolio/_config.cpython-312-x86_64-linux-musl.so +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 +610 -0
  11. eth_portfolio/_decimal.py +156 -0
  12. eth_portfolio/_decorators.py +84 -0
  13. eth_portfolio/_exceptions.py +67 -0
  14. eth_portfolio/_ledgers/__init__.py +0 -0
  15. eth_portfolio/_ledgers/address.py +937 -0
  16. eth_portfolio/_ledgers/portfolio.py +328 -0
  17. eth_portfolio/_loaders/__init__.py +33 -0
  18. eth_portfolio/_loaders/_nonce.cpython-312-x86_64-linux-musl.so +0 -0
  19. eth_portfolio/_loaders/_nonce.py +196 -0
  20. eth_portfolio/_loaders/balances.cpython-312-x86_64-linux-musl.so +0 -0
  21. eth_portfolio/_loaders/balances.py +94 -0
  22. eth_portfolio/_loaders/token_transfer.py +217 -0
  23. eth_portfolio/_loaders/transaction.py +241 -0
  24. eth_portfolio/_loaders/utils.cpython-312-x86_64-linux-musl.so +0 -0
  25. eth_portfolio/_loaders/utils.py +68 -0
  26. eth_portfolio/_shitcoins.cpython-312-x86_64-linux-musl.so +0 -0
  27. eth_portfolio/_shitcoins.py +340 -0
  28. eth_portfolio/_stableish.cpython-312-x86_64-linux-musl.so +0 -0
  29. eth_portfolio/_stableish.py +42 -0
  30. eth_portfolio/_submodules.py +73 -0
  31. eth_portfolio/_utils.py +225 -0
  32. eth_portfolio/_ydb/__init__.py +0 -0
  33. eth_portfolio/_ydb/token_transfers.py +146 -0
  34. eth_portfolio/address.py +397 -0
  35. eth_portfolio/buckets.py +212 -0
  36. eth_portfolio/constants.cpython-312-x86_64-linux-musl.so +0 -0
  37. eth_portfolio/constants.py +87 -0
  38. eth_portfolio/portfolio.py +661 -0
  39. eth_portfolio/protocols/__init__.py +67 -0
  40. eth_portfolio/protocols/_base.py +108 -0
  41. eth_portfolio/protocols/convex.py +17 -0
  42. eth_portfolio/protocols/dsr.py +51 -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 +57 -0
  46. eth_portfolio/protocols/lending/compound.py +187 -0
  47. eth_portfolio/protocols/lending/liquity.py +110 -0
  48. eth_portfolio/protocols/lending/maker.py +111 -0
  49. eth_portfolio/protocols/lending/unit.py +46 -0
  50. eth_portfolio/protocols/liquity.py +16 -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 +637 -0
  55. eth_portfolio/typing/__init__.py +1445 -0
  56. eth_portfolio/typing/balance/single.py +176 -0
  57. eth_portfolio-0.5.2.dist-info/METADATA +26 -0
  58. eth_portfolio-0.5.2.dist-info/RECORD +83 -0
  59. eth_portfolio-0.5.2.dist-info/WHEEL +5 -0
  60. eth_portfolio-0.5.2.dist-info/entry_points.txt +2 -0
  61. eth_portfolio-0.5.2.dist-info/top_level.txt +3 -0
  62. eth_portfolio__mypyc.cpython-312-x86_64-linux-musl.so +0 -0
  63. eth_portfolio_scripts/__init__.py +20 -0
  64. eth_portfolio_scripts/_args.py +26 -0
  65. eth_portfolio_scripts/_logging.py +15 -0
  66. eth_portfolio_scripts/_portfolio.py +209 -0
  67. eth_portfolio_scripts/_utils.py +106 -0
  68. eth_portfolio_scripts/balances.cpython-312-x86_64-linux-musl.so +0 -0
  69. eth_portfolio_scripts/balances.py +57 -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__.cpython-312-x86_64-linux-musl.so +0 -0
  74. eth_portfolio_scripts/docker/__init__.py +16 -0
  75. eth_portfolio_scripts/docker/check.cpython-312-x86_64-linux-musl.so +0 -0
  76. eth_portfolio_scripts/docker/check.py +67 -0
  77. eth_portfolio_scripts/docker/docker-compose.yaml +61 -0
  78. eth_portfolio_scripts/docker/docker_compose.cpython-312-x86_64-linux-musl.so +0 -0
  79. eth_portfolio_scripts/docker/docker_compose.py +99 -0
  80. eth_portfolio_scripts/main.py +119 -0
  81. eth_portfolio_scripts/py.typed +1 -0
  82. eth_portfolio_scripts/victoria/__init__.py +73 -0
  83. eth_portfolio_scripts/victoria/types.py +38 -0
@@ -0,0 +1,176 @@
1
+ from typing import Literal, Optional, Union, final
2
+
3
+ from dictstruct import DictStruct
4
+ from eth_typing import BlockNumber, ChecksumAddress
5
+ from mypy_extensions import mypyc_attr
6
+
7
+ from eth_portfolio._decimal import Decimal
8
+
9
+
10
+ @final
11
+ @mypyc_attr(native_class=False)
12
+ class Balance(
13
+ DictStruct, frozen=True, omit_defaults=True, repr_omit_defaults=True, forbid_unknown_fields=True
14
+ ):
15
+ """
16
+ Represents the balance of a single token, including its token amount and equivalent USD value.
17
+
18
+ Example:
19
+ >>> balance1 = Balance(Decimal('100'), Decimal('2000'))
20
+ >>> balance2 = Balance(Decimal('50'), Decimal('1000'))
21
+ >>> combined_balance = balance1 + balance2
22
+ >>> combined_balance.balance
23
+ Decimal('150')
24
+ >>> combined_balance.usd_value
25
+ Decimal('3000')
26
+ """
27
+
28
+ balance: Decimal = Decimal(0)
29
+ """
30
+ The amount of the token.
31
+ """
32
+
33
+ usd_value: Decimal = Decimal(0)
34
+ """
35
+ The USD equivalent value of the token amount.
36
+ """
37
+
38
+ token: Optional[ChecksumAddress] = None
39
+ """
40
+ The token the balance is of, if known.
41
+ """
42
+
43
+ block: Optional[BlockNumber] = None
44
+ """
45
+ The block from which the balance was taken, if known.
46
+ """
47
+
48
+ @property
49
+ def usd(self) -> Decimal:
50
+ """
51
+ An alias for `usd_value`. Returns the USD value of the token amount.
52
+ """
53
+ return self.usd_value
54
+
55
+ def __add__(self, other: "Balance") -> "Balance":
56
+ """
57
+ Adds two :class:`~eth_portfolio.typing.Balance` objects together. It is the user's responsibility to ensure that the two
58
+ :class:`~eth_portfolio.typing.Balance` instances represent the same token.
59
+
60
+ Args:
61
+ other: Another :class:`~eth_portfolio.typing.Balance` object.
62
+
63
+ Returns:
64
+ A new :class:`~eth_portfolio.typing.Balance` object with the summed values.
65
+
66
+ Raises:
67
+ TypeError: If the other object is not a :class:`~eth_portfolio.typing.Balance`.
68
+ Exception: If any other error occurs during addition.
69
+
70
+ Example:
71
+ >>> balance1 = Balance(Decimal('100'), Decimal('2000'))
72
+ >>> balance2 = Balance(Decimal('50'), Decimal('1000'))
73
+ >>> combined_balance = balance1 + balance2
74
+ >>> combined_balance.balance
75
+ Decimal('150')
76
+ >>> combined_balance.usd_value
77
+ Decimal('3000')
78
+ """
79
+ if not isinstance(other, Balance):
80
+ raise TypeError(f"{other} is not a `Balance` object")
81
+ if self.token != other.token:
82
+ raise ValueError(
83
+ f"These Balance objects represent balances of different tokens ({self.token} and {other.token})"
84
+ )
85
+ if self.block != other.block:
86
+ raise ValueError(
87
+ f"These Balance objects represent balances from different blocks ({self.block} and {other.block})"
88
+ )
89
+ try:
90
+ return Balance(
91
+ balance=self.balance + other.balance,
92
+ usd_value=self.usd_value + other.usd_value,
93
+ token=self.token,
94
+ block=self.block,
95
+ )
96
+ except Exception as e:
97
+ e.args = (f"Cannot add {self} and {other}: {e}", *e.args)
98
+ raise
99
+
100
+ def __radd__(self, other: Union["Balance", Literal[0]]) -> "Balance":
101
+ """
102
+ Supports the addition operation from the right side to enable use of `sum`.
103
+
104
+ Args:
105
+ other: Another :class:`~eth_portfolio.typing.Balance` object or zero.
106
+
107
+ Returns:
108
+ A new :class:`~eth_portfolio.typing.Balance` object with the summed values.
109
+
110
+ Raises:
111
+ TypeError: If the other object is not a :class:`~eth_portfolio.typing.Balance`.
112
+ Exception: If any other error occurs during addition.
113
+
114
+ Example:
115
+ >>> balance = Balance(Decimal('100'), Decimal('2000'))
116
+ >>> sum_balance = sum([balance, Balance()])
117
+ >>> sum_balance.balance
118
+ Decimal('100')
119
+ """
120
+ return self if other == 0 else self.__add__(other) # type: ignore
121
+
122
+ def __sub__(self, other: "Balance") -> "Balance":
123
+ """
124
+ Subtracts one :class:`~eth_portfolio.typing.Balance` object from another. It is the user's responsibility to ensure that
125
+ the two :class:`~eth_portfolio.typing.Balance` instances represent the same token.
126
+
127
+ Args:
128
+ other: Another :class:`~eth_portfolio.typing.Balance` object.
129
+
130
+ Returns:
131
+ A new :class:`~eth_portfolio.typing.Balance` object with the subtracted values.
132
+
133
+ Raises:
134
+ TypeError: If the other object is not a :class:`~eth_portfolio.typing.Balance`.
135
+ Exception: If any other error occurs during subtraction.
136
+
137
+ Example:
138
+ >>> balance1 = Balance(Decimal('100'), Decimal('2000'))
139
+ >>> balance2 = Balance(Decimal('50'), Decimal('1000'))
140
+ >>> result_balance = balance1 - balance2
141
+ >>> result_balance.balance
142
+ Decimal('50')
143
+ """
144
+ if not isinstance(other, Balance):
145
+ raise TypeError(f"{other} is not a `Balance` object.")
146
+ if self.token != other.token:
147
+ raise ValueError(
148
+ f"These Balance objects represent balances of different tokens ({self.token} and {other.token})"
149
+ )
150
+ if self.block != other.block:
151
+ raise ValueError(
152
+ f"These Balance objects represent balances from different blocks ({self.block} and {other.block})"
153
+ )
154
+ try:
155
+ return Balance(
156
+ balance=self.balance - other.balance,
157
+ usd_value=self.usd_value - other.usd_value,
158
+ token=self.token,
159
+ block=self.block,
160
+ )
161
+ except Exception as e:
162
+ raise e.__class__(f"Cannot subtract {self} and {other}: {e}") from e
163
+
164
+ def __bool__(self) -> bool:
165
+ """
166
+ Evaluates the truth value of the :class:`~eth_portfolio.typing.Balance` object.
167
+
168
+ Returns:
169
+ True if either the balance or the USD value is non-zero, otherwise False.
170
+
171
+ Example:
172
+ >>> balance = Balance(Decimal('0'), Decimal('0'))
173
+ >>> bool(balance)
174
+ False
175
+ """
176
+ return self.balance != 0 or self.usd_value != 0
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: eth_portfolio
3
+ Version: 0.5.2
4
+ Summary: eth-portfolio makes it easy to analyze your portfolio.
5
+ Home-page: https://github.com/BobTheBuidler/eth-portfolio
6
+ Author: BobTheBuidler
7
+ Author-email: bobthebuidlerdefi@gmail.com
8
+ Requires-Python: >=3.10,<3.14
9
+ Requires-Dist: checksum_dict>=2.1.7
10
+ Requires-Dist: dank_mids>=4.20.190
11
+ Requires-Dist: eth-brownie<1.23,>=1.22.0.dev0
12
+ Requires-Dist: eth_retry<1,>=0.3.4
13
+ Requires-Dist: evmspec>=0.4.1
14
+ Requires-Dist: ez-a-sync>=0.33.10
15
+ Requires-Dist: faster-async-lru==2.0.5.2
16
+ Requires-Dist: faster-eth-utils
17
+ Requires-Dist: numpy<3
18
+ Requires-Dist: pandas<3,>=1.4.3
19
+ Requires-Dist: typed-envs>=0.2.3
20
+ Requires-Dist: ypricemagic<5.2,>=5.1
21
+ Dynamic: author
22
+ Dynamic: author-email
23
+ Dynamic: home-page
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
@@ -0,0 +1,83 @@
1
+ eth_portfolio__mypyc.cpython-312-x86_64-linux-musl.so,sha256=drLgzV8UabAXTUEgKlRg_oacHGs4W9nkZJymZVdVnNs,902480
2
+ eth_portfolio/__init__.py,sha256=0sO4cSJaLYwJfnfVOJRFw7p5_Lzhsr95YuJ1aNQM83A,500
3
+ eth_portfolio/_argspec.cpython-312-x86_64-linux-musl.so,sha256=uftcQTVCHs_-0pAXyfTxRfJHwZ7MEMEytHysUv3Cm3w,17760
4
+ eth_portfolio/_argspec.py,sha256=VzUZkbDkmOSgNUZBGbGblqtxBfDcmBAB89dY2OX0j-U,1595
5
+ eth_portfolio/_cache.py,sha256=IOeMXvMgOlEEk01yHP0RARRZXyonuKXUNZbNLFM_KBU,4805
6
+ eth_portfolio/_config.cpython-312-x86_64-linux-musl.so,sha256=o2BnYmWW12LUqOSEGUAl5IP3d76IYRFLCFOFK7Rbe6k,17760
7
+ eth_portfolio/_config.py,sha256=mw-OA3M8rUA2hqy5wNt30AZRHkWFgR8K2sJg0o5Baxg,98
8
+ eth_portfolio/_decimal.py,sha256=tYS0miNoQYZguy0yd1bb3bf49l9F3YICyN8ov6r7VBs,4846
9
+ eth_portfolio/_decorators.py,sha256=_ZSurUFEIwZRiMFMhLcIXkD-Ey1CqfBqGaE24hLzOuA,2815
10
+ eth_portfolio/_exceptions.py,sha256=bw3IdXhqrWxeFqYLm7pJZqRHKZas_cCg8A5Ih1WQEqQ,2433
11
+ eth_portfolio/_shitcoins.cpython-312-x86_64-linux-musl.so,sha256=K7kG3CSmeuc-s_wgxu99GtEYSvvrl0RotZlFB3Ls2bg,17768
12
+ eth_portfolio/_shitcoins.py,sha256=oj-_bZmakXwAjWBJ3xBnDbriuX9nXyutbsoUrDLsbMg,17561
13
+ eth_portfolio/_stableish.cpython-312-x86_64-linux-musl.so,sha256=DAKsgeXLlXat8RuQUDHn1nhiZAE4ZEPf7j_msotm_Hs,17768
14
+ eth_portfolio/_stableish.py,sha256=VTv69Q91AHxbNbbY0LB4PFwKEseHdkE4_6fLPKH1uW0,2021
15
+ eth_portfolio/_submodules.py,sha256=J8ht9bAAvblUXqwOGN7UIOXUPxrTiq7m1RWiB0-ObaE,2190
16
+ eth_portfolio/_utils.py,sha256=8403ioVA6VX4XaF56CDI9IA4ilTZUf_TrdlQ78chXbQ,7661
17
+ eth_portfolio/address.py,sha256=LvBh4Vp2DBC3gQ0WD-TZ6jfe9s6FZbET1krYG9_KMAA,14139
18
+ eth_portfolio/buckets.py,sha256=-eG-F_Ke0meR_pdA8uYQQuO0lkVgbizTUG3Xhe8o5dE,7599
19
+ eth_portfolio/constants.cpython-312-x86_64-linux-musl.so,sha256=L3mFhzx2yaI9I9GFL5piDivsrO6JiUyU0FdQAmO34JI,17760
20
+ eth_portfolio/constants.py,sha256=tR2QKapbutcGYjXdxwB23FICQlwyDPvgua-dhltYyDc,3976
21
+ eth_portfolio/portfolio.py,sha256=MP_0Y6fXw8TNoyoFCPiu-MUA44jnMm0L_33gec6MjKU,24248
22
+ eth_portfolio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ eth_portfolio/_db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
+ eth_portfolio/_db/decorators.py,sha256=GXL6kqnARl0W1roITfrSZkPKoIi9jxJHEvaj9WH86RQ,5161
25
+ eth_portfolio/_db/entities.py,sha256=gjMIemMv7_SDzuEvag_-ZaTqlkOkvUMkj6Z93U9nHNo,10027
26
+ eth_portfolio/_db/utils.py,sha256=wRUlJLkh_pCut_88KQdX52c6QOhzY3Rel6WpI4kL8V0,21326
27
+ eth_portfolio/_ledgers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ eth_portfolio/_ledgers/address.py,sha256=2zBRCT8nsuOIOm7DPKmk6dXGe4Jm-q6yVkXaeJv5TOg,32911
29
+ eth_portfolio/_ledgers/portfolio.py,sha256=plqSPXji61ZL04XRD0bRuOAfh2X10YHp0tK7xEJAF0M,13127
30
+ eth_portfolio/_loaders/__init__.py,sha256=lb45_0ak32Z7N3-Nx1CAoRKiZ1_w-_YGbmSCNuunro8,1702
31
+ eth_portfolio/_loaders/_nonce.cpython-312-x86_64-linux-musl.so,sha256=wZS4abRRCJhUojZ1Xbv7rTr5amUWbHKdQE_9C-l1VQQ,17776
32
+ eth_portfolio/_loaders/_nonce.py,sha256=LZqNWnHGZH-3tuoRahvvprB15ZAgwWBgELidTyz0318,6285
33
+ eth_portfolio/_loaders/balances.cpython-312-x86_64-linux-musl.so,sha256=1INMUsfy45UxSyobdwpO9eJ31p2OzlnG2ocKtgAong0,17776
34
+ eth_portfolio/_loaders/balances.py,sha256=BTWfkJIoSraUMe94Wuj8NPyg5EO0OByIjbXu7j6PZEo,3132
35
+ eth_portfolio/_loaders/token_transfer.py,sha256=nFS8fJlfsHe3lgyM6X6oFT2B-ULJlig7QKGKai1uXx8,8531
36
+ eth_portfolio/_loaders/transaction.py,sha256=S7HkAxR_Iwvo2c8qEhlWYfgThcTf2MYGcX6RkL9HeEA,9180
37
+ eth_portfolio/_loaders/utils.cpython-312-x86_64-linux-musl.so,sha256=5HNxFOVp6ui9V4ludDfZJpZdVdg1zGUb4laX1vJHDhk,17760
38
+ eth_portfolio/_loaders/utils.py,sha256=aoGgWl9ra9F-qb0wA-sX3qelUNGI-fGvM90297L7xWM,2265
39
+ eth_portfolio/_ydb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ eth_portfolio/_ydb/token_transfers.py,sha256=KFsapzGfNWEv2eM-7qYMdIIA1aHs80CikQ-DPT4_un4,5179
41
+ eth_portfolio/protocols/__init__.py,sha256=H4_6JrXQ7sWdp8TKIPWrisMESYsY__6BiS3u6jR_PK4,2556
42
+ eth_portfolio/protocols/_base.py,sha256=2ztaUvIbgN27ss-mDOGYIS8ajpabQdCAaOLr6NEis44,3685
43
+ eth_portfolio/protocols/convex.py,sha256=uNbXxEmhcpXulNkbxoqWl9eAJTZjPJlzXFtrBGvRXLo,518
44
+ eth_portfolio/protocols/dsr.py,sha256=eGL0DK4IpZkv10CdNr-3OmlAYjqXJAtQHWL34HUBgpY,1755
45
+ eth_portfolio/protocols/liquity.py,sha256=sTUoVtFYj-OWUamwCnJyqna-eAa5Ww7-qGA0St1OTMQ,640
46
+ eth_portfolio/protocols/lending/README.md,sha256=OhZfsW8e-aD-q02g0maG9QGgW0IietkDRZc7PBakBvc,493
47
+ eth_portfolio/protocols/lending/__init__.py,sha256=BZtCOglz6R12wqETlECbCEITdtIT9J6bYzy61iDencI,1643
48
+ eth_portfolio/protocols/lending/_base.py,sha256=UBdJ5eV2baewEvppjES72eOJzKTK2XHGYnySQNBcack,2254
49
+ eth_portfolio/protocols/lending/compound.py,sha256=bqnIevm7NWhk6nMfkMZUKlQuVWr-tXnuntX-4De1YZM,7252
50
+ eth_portfolio/protocols/lending/liquity.py,sha256=N45LTa2VTcj3UDygn76iwaG_l0AYXOWh-9n5YBqkQNM,4184
51
+ eth_portfolio/protocols/lending/maker.py,sha256=myyz167mO3tX10JN_D5-dJrcPaHabeb0_Sf_AdXjK2k,4308
52
+ eth_portfolio/protocols/lending/unit.py,sha256=7oRvIkoKUm8IOnDv59pILSSJWFNNjwr4CR1gg2psW9M,1965
53
+ eth_portfolio/structs/__init__.py,sha256=3EmfKoJGszobO7fCkERLXSN50V6dX3nfhvbiKIvJUZI,1443
54
+ eth_portfolio/structs/modified.py,sha256=z75XDNXOfm3hDr7pj0PbmUvfPeQSFH9BJ9m0L2V_LFw,1784
55
+ eth_portfolio/structs/structs.py,sha256=gf9XaTL7Sgtc_Ywa1-fhgl9Z5V2j_nG5atpZxiPwjYU,19853
56
+ eth_portfolio/typing/__init__.py,sha256=bDFHKA8PH4i0l8OrEl5gvI1DUQateJWrdlwDwJkIw7s,57285
57
+ eth_portfolio/typing/balance/single.py,sha256=_HhJL21jOs4IPjRsYbjZVficsNWCS0fcpBryr3JFt7s,6325
58
+ eth_portfolio_scripts/__init__.py,sha256=TC5c4WZdzSHhTIBYuwzrAyzFuGzBmHiDX_g6ghO09jQ,261
59
+ eth_portfolio_scripts/_args.py,sha256=k6J6XkRe1VuN1DiyGuXLCR7NBSvzH5jnVChfzodKuB8,656
60
+ eth_portfolio_scripts/_logging.py,sha256=B_rQMYt_1PhpwCOLBRpkKK6M1ljcF0wAIgqfPIsFUGU,354
61
+ eth_portfolio_scripts/_portfolio.py,sha256=oNTXtxV4jYhQCk4DIc6hHLltZxC09OVoGlAE7COjGc4,7794
62
+ eth_portfolio_scripts/_utils.py,sha256=-JiZLpSa8P2_ZFXw1AfpVmTO6X65yPeVVdnrDpNFzNQ,3057
63
+ eth_portfolio_scripts/balances.cpython-312-x86_64-linux-musl.so,sha256=DT8Kff2Q2_XjwahqsdH882NYGe32NVOfuvLvoSXvCUM,17776
64
+ eth_portfolio_scripts/balances.py,sha256=1GEoGsGDj9gocBP1mQ2-maxJqLlA1YLZHcf90mRTWqc,1744
65
+ eth_portfolio_scripts/main.py,sha256=jc2o45OS-xzjwwNLgCOn9lwEzZJEhVFyAM4kesSwW6Q,3685
66
+ eth_portfolio_scripts/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
67
+ eth_portfolio_scripts/docker/__init__.cpython-312-x86_64-linux-musl.so,sha256=a1bQL6EXOw8WcxBXece-7IO0Pj_TLA6qpEMKr78jjII,17768
68
+ eth_portfolio_scripts/docker/__init__.py,sha256=ZXSIYcjp94c0O9o39BDGWju3YrCMLl4gtov7YChc9Ig,393
69
+ eth_portfolio_scripts/docker/check.cpython-312-x86_64-linux-musl.so,sha256=sMHUY7b_UpyUCkdN0-K8XGwltm-icdoEpuX2tcmDiXU,17776
70
+ eth_portfolio_scripts/docker/check.py,sha256=_UdwuLCwzJUHvpGFzDxk5GbYAafG-A-jL1YDaq4TU1E,1930
71
+ eth_portfolio_scripts/docker/docker-compose.yaml,sha256=K1iLHZcOVrnpb9Nb9gtcFaVosjjfjjfXGp6WkStBLQk,1809
72
+ eth_portfolio_scripts/docker/docker_compose.cpython-312-x86_64-linux-musl.so,sha256=-2G49YYfG-mNZYDzrMjcvIaZwgfMB0JH5uPg_PxqxHE,17816
73
+ eth_portfolio_scripts/docker/docker_compose.py,sha256=eIuiDkW21KQFpG-TOsLU_8aIfUEG_l_VhmX9vFUxD8Y,2832
74
+ eth_portfolio_scripts/docker/.grafana/dashboards/dashboards.yaml,sha256=MynNDOk69IihoYdd2bL7j8CnRb2Co4gdqW7T4m6AaEU,202
75
+ eth_portfolio_scripts/docker/.grafana/dashboards/Portfolio/Balances.json,sha256=dBmjogLJRuixCHWSs4ROE0_FXb-PUbqWBHEdLoP-1MU,68788
76
+ eth_portfolio_scripts/docker/.grafana/datasources/datasources.yml,sha256=pBE_0Nh_J7d9Fiy3Xu6vuac_HWCBcFsJJSV-ryjQR1Y,188
77
+ eth_portfolio_scripts/victoria/__init__.py,sha256=6rDSJ1OBup2feCuFmGbJt5F3ie3XKtdiVezldWB4PUE,1965
78
+ eth_portfolio_scripts/victoria/types.py,sha256=jsqWM5QxrhuTHbbxnfjd1PlwJIjybIbK-6gGwcNYiLY,707
79
+ eth_portfolio-0.5.2.dist-info/METADATA,sha256=yoar_nfWo9TRlq9myNVTyDgiAuZH7Viaq706lE-DDtk,809
80
+ eth_portfolio-0.5.2.dist-info/WHEEL,sha256=AwHYJA1Do1jwgPIoLQR4DiHSeYY_vU6Ht9Vljq5Yt_M,112
81
+ eth_portfolio-0.5.2.dist-info/entry_points.txt,sha256=yqoC6X3LU1NA_-oJ6mloEYEPNmS-0hPS9OtEwgIeDGU,66
82
+ eth_portfolio-0.5.2.dist-info/top_level.txt,sha256=4MlbY-Yj8oGBGL8piXiO4SOpk2gZFF9ZXVTObTZOzqM,57
83
+ eth_portfolio-0.5.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp312-cp312-musllinux_1_2_x86_64
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ eth-portfolio = eth_portfolio_scripts.main:main
@@ -0,0 +1,3 @@
1
+ eth_portfolio
2
+ eth_portfolio__mypyc
3
+ eth_portfolio_scripts
@@ -0,0 +1,20 @@
1
+ from os import environ
2
+
3
+
4
+ environ["DANKMIDS_GANACHE_FORK"] = "0"
5
+ environ["DANKMIDS_COLLECT_STATS"] = "0"
6
+
7
+
8
+ from dotenv import load_dotenv
9
+
10
+
11
+ load_dotenv()
12
+
13
+
14
+ from eth_portfolio_scripts._logging import logger, setup_logging
15
+
16
+
17
+ setup_logging()
18
+
19
+
20
+ __all__ = ["logger"]
@@ -0,0 +1,26 @@
1
+ from argparse import ArgumentParser
2
+
3
+
4
+ def get_arg_parser(description: str) -> ArgumentParser:
5
+ return ArgumentParser(description)
6
+
7
+
8
+ def add_infra_port_args(parser: ArgumentParser) -> None:
9
+ parser.add_argument(
10
+ "--grafana-port",
11
+ type=int,
12
+ help="The port that will be used by grafana",
13
+ default=3000,
14
+ )
15
+ parser.add_argument(
16
+ "--renderer-port",
17
+ type=int,
18
+ help="The port that will be used by grafana",
19
+ default=8091,
20
+ )
21
+ parser.add_argument(
22
+ "--victoria-port",
23
+ type=int,
24
+ help="The port that will be used by victoria metrics",
25
+ default=8428,
26
+ )
@@ -0,0 +1,15 @@
1
+ import warnings
2
+ from logging import INFO, basicConfig, getLogger
3
+
4
+ from brownie.exceptions import BrownieCompilerWarning, BrownieEnvironmentWarning
5
+
6
+
7
+ logger = getLogger(__name__)
8
+
9
+
10
+ def setup_logging() -> None:
11
+ basicConfig(level=INFO)
12
+
13
+
14
+ warnings.simplefilter("ignore", BrownieCompilerWarning)
15
+ warnings.simplefilter("ignore", BrownieEnvironmentWarning)
@@ -0,0 +1,209 @@
1
+ import asyncio
2
+ from datetime import datetime, timezone
3
+ from logging import getLogger
4
+ from math import floor
5
+ from typing import Awaitable, Callable, Final, Iterator, List, Optional, Tuple, Dict
6
+
7
+ import a_sync
8
+ import eth_retry
9
+ import y
10
+ from a_sync.functools import cached_property_unsafe as cached_property
11
+ from eth_typing import BlockNumber, ChecksumAddress
12
+ from msgspec import ValidationError, json
13
+ from y import ERC20, Network, NonStandardERC20
14
+ from y.constants import CHAINID
15
+ from y.time import NoBlockFound
16
+
17
+ from eth_portfolio import Portfolio
18
+ from eth_portfolio.buckets import get_token_bucket
19
+ from eth_portfolio.portfolio import _DEFAULT_LABEL
20
+ from eth_portfolio.typing import (
21
+ Addresses,
22
+ Balance,
23
+ RemoteTokenBalances,
24
+ PortfolioBalances,
25
+ TokenBalances,
26
+ )
27
+ from eth_portfolio_scripts import victoria
28
+
29
+
30
+ NETWORK_LABEL: Final = Network.label(CHAINID)
31
+
32
+ decode: Final = json.decode
33
+
34
+ logger: Final = getLogger("eth_portfolio")
35
+ log_debug: Final = logger.debug
36
+ log_error: Final = logger.error
37
+
38
+ _block_at_timestamp_semaphore: Final = a_sync.Semaphore(
39
+ 50, name="eth-portfolio get_block_at_timestamp"
40
+ )
41
+
42
+
43
+ async def get_block_at_timestamp(dt: datetime) -> BlockNumber:
44
+ async with _block_at_timestamp_semaphore:
45
+ while True:
46
+ try:
47
+ return await y.get_block_at_timestamp(dt, sync=False)
48
+ except NoBlockFound:
49
+ await asyncio.sleep(10)
50
+
51
+
52
+ class ExportablePortfolio(Portfolio):
53
+ """Adds methods to export full portoflio data."""
54
+
55
+ def __init__(
56
+ self,
57
+ addresses: Addresses,
58
+ *,
59
+ start_block: int = 0,
60
+ label: str = _DEFAULT_LABEL,
61
+ concurrency: int = 30,
62
+ load_prices: bool = True,
63
+ get_bucket: Callable[[ChecksumAddress], Awaitable[str]] = None,
64
+ num_workers_transactions: int = 1000,
65
+ asynchronous: bool = False,
66
+ custom_buckets: Optional[Dict[str, str]] = None,
67
+ ):
68
+ super().__init__(
69
+ addresses, start_block, label, load_prices, num_workers_transactions, asynchronous
70
+ )
71
+ self._semaphore = a_sync.Semaphore(concurrency)
72
+
73
+ # Lowercase all keys in custom_buckets if provided
74
+ self.custom_buckets = (
75
+ {k.lower(): v for k, v in custom_buckets.items()} if custom_buckets else None
76
+ )
77
+
78
+ # If get_bucket is not provided, use get_token_bucket with the lowercased mapping
79
+ if get_bucket is None:
80
+ self.get_bucket = lambda token: get_token_bucket(token, self.custom_buckets)
81
+ elif custom_buckets:
82
+ raise RuntimeError(
83
+ "You cannot pass in a custom get_bucket function AND a custom_buckets mapping, choose one."
84
+ )
85
+ else:
86
+ self.get_bucket = get_bucket
87
+
88
+ @cached_property
89
+ def _data_queries(self) -> Tuple[str, str]:
90
+ label = self.label.lower().replace(" ", "_")
91
+ return f"{label}_assets", f"{label}_debts"
92
+
93
+ @eth_retry.auto_retry
94
+ @a_sync.Semaphore(16)
95
+ async def data_exists(self, dt: datetime) -> bool:
96
+ # sourcery skip: use-contextlib-suppress
97
+ async for data in a_sync.as_completed(list(self.__get_data_exists_coros(dt)), aiter=True):
98
+ try:
99
+ result = decode(data, type=victoria.types.Response)
100
+ except ValidationError:
101
+ raise victoria.VictoriaMetricsError(data.decode()) from None
102
+ if result.status == "success" and len(result.data.result) > 0:
103
+ print(f"{dt} already loaded")
104
+ return True
105
+ return False
106
+
107
+ async def export_snapshot(self, dt: datetime) -> None:
108
+ log_debug("checking data at %s for %s", dt, self.label)
109
+ try:
110
+ if await self.data_exists(dt, sync=False):
111
+ return
112
+ block = await get_block_at_timestamp(dt)
113
+ log_debug("block at %s: %s", dt, block)
114
+ data = await self.get_data_for_export(block, dt, sync=False)
115
+ await victoria.post_data(data)
116
+ except Exception as e:
117
+ log_error("Error processing %s:", dt, exc_info=True)
118
+
119
+ async def get_data_for_export(self, block: BlockNumber, ts: datetime) -> List[victoria.Metric]:
120
+ async with self._semaphore:
121
+ print(f"exporting {ts} for {self.label}")
122
+ start = datetime.now(tz=timezone.utc)
123
+
124
+ metrics_to_export = []
125
+ data: PortfolioBalances = await self.describe(block, sync=False)
126
+
127
+ for wallet, wallet_data in dict.items(data):
128
+ for section, section_data in wallet_data.items():
129
+ if isinstance(section_data, TokenBalances):
130
+ for token, bals in dict.items(section_data):
131
+ metrics_to_export.extend(
132
+ await self.__process_token(ts, section, wallet, token, bals)
133
+ )
134
+ elif isinstance(section_data, RemoteTokenBalances):
135
+ if section == "external":
136
+ section = "assets"
137
+ for protocol, token_bals in section_data.items():
138
+ for token, bals in dict.items(token_bals):
139
+ metrics_to_export.extend(
140
+ await self.__process_token(
141
+ ts, section, wallet, token, bals, protocol=protocol
142
+ )
143
+ )
144
+ else:
145
+ raise NotImplementedError()
146
+
147
+ print(f"got data for {ts} in {datetime.now(tz=timezone.utc) - start}")
148
+ return metrics_to_export
149
+
150
+ def __get_data_exists_coros(self, dt: datetime) -> Iterator[str]:
151
+ for query in self._data_queries:
152
+ yield victoria.get(f"/api/v1/query?query={query}&time={int(dt.timestamp())}")
153
+
154
+ async def __process_token(
155
+ self,
156
+ ts: datetime,
157
+ section: str,
158
+ wallet: ChecksumAddress,
159
+ token: ChecksumAddress,
160
+ bal: Balance,
161
+ protocol: Optional[str] = None,
162
+ ) -> Tuple[victoria.types.PrometheusItem, victoria.types.PrometheusItem]:
163
+ # TODO wallet nicknames in grafana
164
+ # wallet = KNOWN_ADDRESSES[wallet] if wallet in KNOWN_ADDRESSES else wallet
165
+ if protocol is not None:
166
+ wallet = f"{protocol} | {wallet}"
167
+
168
+ label_and_section = f"{self.label}_{section}".lower().replace(" ", "_")
169
+ symbol = await _get_symbol(token)
170
+ bucket = await self.get_bucket(token)
171
+ ts_millis = floor(ts.timestamp()) * 1000
172
+
173
+ return (
174
+ victoria.types.PrometheusItem(
175
+ metric=victoria.Metric(
176
+ param="balance",
177
+ wallet=wallet,
178
+ token_address=token,
179
+ token=symbol,
180
+ bucket=bucket,
181
+ network=NETWORK_LABEL,
182
+ __name__=label_and_section,
183
+ ),
184
+ values=[float(bal.balance)],
185
+ timestamps=[ts_millis],
186
+ ),
187
+ victoria.types.PrometheusItem(
188
+ metric=victoria.Metric(
189
+ param="usd value",
190
+ wallet=wallet,
191
+ token_address=token,
192
+ token=symbol,
193
+ bucket=bucket,
194
+ network=NETWORK_LABEL,
195
+ __name__=label_and_section,
196
+ ),
197
+ values=[float(bal.usd)],
198
+ timestamps=[ts_millis],
199
+ ),
200
+ )
201
+
202
+
203
+ async def _get_symbol(token: str) -> str:
204
+ if token == "ETH":
205
+ return "ETH"
206
+ try:
207
+ return await ERC20(token, asynchronous=True).symbol
208
+ except NonStandardERC20:
209
+ return "<NonStandardERC20>"