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.

Files changed (83) hide show
  1. eth_portfolio/__init__.py +24 -0
  2. eth_portfolio/_argspec.cpython-311-x86_64-linux-musl.so +0 -0
  3. eth_portfolio/_argspec.py +43 -0
  4. eth_portfolio/_cache.py +119 -0
  5. eth_portfolio/_config.cpython-311-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 +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.cpython-311-x86_64-linux-musl.so +0 -0
  19. eth_portfolio/_loaders/_nonce.py +193 -0
  20. eth_portfolio/_loaders/balances.cpython-311-x86_64-linux-musl.so +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.cpython-311-x86_64-linux-musl.so +0 -0
  25. eth_portfolio/_loaders/utils.py +67 -0
  26. eth_portfolio/_shitcoins.cpython-311-x86_64-linux-musl.so +0 -0
  27. eth_portfolio/_shitcoins.py +342 -0
  28. eth_portfolio/_stableish.cpython-311-x86_64-linux-musl.so +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.cpython-311-x86_64-linux-musl.so +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.cpython-311-x86_64-linux-musl.so +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.cpython-311-x86_64-linux-musl.so +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__.cpython-311-x86_64-linux-musl.so +0 -0
  74. eth_portfolio_scripts/docker/__init__.py +16 -0
  75. eth_portfolio_scripts/docker/check.cpython-311-x86_64-linux-musl.so +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.cpython-311-x86_64-linux-musl.so +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,176 @@
1
+ from typing import Literal, 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: ChecksumAddress | None = None
39
+ """
40
+ The token the balance is of, if known.
41
+ """
42
+
43
+ block: BlockNumber | None = 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)
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,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: eth_portfolio
3
+ Version: 0.5.8
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.192
11
+ Requires-Dist: eth-brownie<1.23,>=1.22.0.dev2
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.3
16
+ Requires-Dist: faster-eth-utils
17
+ Requires-Dist: numpy<3
18
+ Requires-Dist: pandas<3,>=1.4.3
19
+ Requires-Dist: pandas-stubs<3,>=1.4.3
20
+ Requires-Dist: typed-envs>=0.2.3
21
+ Requires-Dist: types-tqdm
22
+ Requires-Dist: ypricemagic<5.2,>=5.1.5
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: home-page
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
@@ -0,0 +1,83 @@
1
+ eth_portfolio__mypyc.cpython-311-x86_64-linux-musl.so,sha256=yro_HLC6MYaq3mgtgXi-hxVh-0Rwis_cu6Ckc0ypMi4,806872
2
+ eth_portfolio/__init__.py,sha256=6LVvIubKt5md1EdMVTxHubZQqYZhYaA64v_UMrn-gTI,499
3
+ eth_portfolio/_argspec.cpython-311-x86_64-linux-musl.so,sha256=NGQ-v_R3axHZlqApo5JB41uc2k7BrsWbNeuCwUN4LkY,17624
4
+ eth_portfolio/_argspec.py,sha256=1hMCiTGt6BBiWkR9b1eFWxTNyEKXF_bgb4yOoH8Mitk,1603
5
+ eth_portfolio/_cache.py,sha256=D0xI--BOsr37XAqqGCgcYN296X5RtQqBC_J6vJoNtTw,4728
6
+ eth_portfolio/_config.cpython-311-x86_64-linux-musl.so,sha256=Lfhkma_f1sWGUyUSnb3-2gYLr8MCnhO05DvN2ubRa-M,17624
7
+ eth_portfolio/_config.py,sha256=mw-OA3M8rUA2hqy5wNt30AZRHkWFgR8K2sJg0o5Baxg,98
8
+ eth_portfolio/_decimal.py,sha256=8lCXpmzaAs2WGb4mzewHvGkVo50fZpXwdZeXpzYaSJU,4814
9
+ eth_portfolio/_decorators.py,sha256=yC2jMj9KwcfYnKky54Sp-s2G3-SJffGIjpcEP5lCsFQ,2791
10
+ eth_portfolio/_exceptions.py,sha256=pk4XFeTelD1-77iXAdIDlH6VzjfvsFBwmmEBkrHGsbI,2423
11
+ eth_portfolio/_shitcoins.cpython-311-x86_64-linux-musl.so,sha256=3nmUKrqKdYZMxsDjH9DXk5NZEA0Mj_x6Skj0Ivcq3-8,17632
12
+ eth_portfolio/_shitcoins.py,sha256=vMlyBMdhpvU7xocXVfK1zSqNo4K3AzzUgO-LcM2plLA,17664
13
+ eth_portfolio/_stableish.cpython-311-x86_64-linux-musl.so,sha256=Jwngfv5kdpQx0Z0zaC7peIU4m9rpTUO3fHj8rcuKFHI,17632
14
+ eth_portfolio/_stableish.py,sha256=kYnsk6aCA9RGQKcDPLML6LAPyc__YTsK5vJLzNxkh2g,2016
15
+ eth_portfolio/_submodules.py,sha256=sGrgpcE0iQjsifbyG6_-cL5VSU_L9oZ8SDkQWfAwCjU,2161
16
+ eth_portfolio/_utils.py,sha256=ci7y6GIJ3458eOgCowQ859EtpSWK89DifogV6dgh_YU,7935
17
+ eth_portfolio/address.py,sha256=HLKXt36kEQ-vKCJjmaUdZMBcJsPDZ800eLeRYzqWojA,14085
18
+ eth_portfolio/buckets.py,sha256=wIRM6YXwNVtsA5-p9HYr45FNJkl11x1uUjm92_SVpLU,7547
19
+ eth_portfolio/constants.cpython-311-x86_64-linux-musl.so,sha256=VrIG6qkOZSgkU3ZF08idW-7t8rweAKrIaw2uhwFmF1M,17624
20
+ eth_portfolio/constants.py,sha256=tR2QKapbutcGYjXdxwB23FICQlwyDPvgua-dhltYyDc,3976
21
+ eth_portfolio/portfolio.py,sha256=qByA7pzFUHLi9wTdu3AgQNglubjquYw5KVWB0vEOvCg,24249
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=lRRr6S43b4LQ-HQ-BbANpEl3D0DaaN421Zbk0KUKfv4,5187
25
+ eth_portfolio/_db/entities.py,sha256=KjcMoJs9AcaIBDsb9XMBahB4iaxbvVELDU133V86DLw,10015
26
+ eth_portfolio/_db/utils.py,sha256=r5wRnaPQ3-6pUSoBeTbyedl-tNt9eAvhHWRH0vfh4bk,21722
27
+ eth_portfolio/_ledgers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ eth_portfolio/_ledgers/address.py,sha256=p-_15b07TgZU12LMN0NIusDGSJ0O7ESqjhhkNArY5XY,32592
29
+ eth_portfolio/_ledgers/portfolio.py,sha256=5CMrPLIUCBo0xihEEz3wd6tCctbjRMQ1YZfLWCCnDUY,13067
30
+ eth_portfolio/_loaders/__init__.py,sha256=_7WwCsSCJH-muqXzUQL152fptzUlShgRkG6Gr0o-kmo,1702
31
+ eth_portfolio/_loaders/_nonce.cpython-311-x86_64-linux-musl.so,sha256=bJHshOGQNa4u_ij7rvveyKPZoVN6lUTGiID2BIKFoiY,17640
32
+ eth_portfolio/_loaders/_nonce.py,sha256=OgfAOgf95L775rSEGNJrmMGptT8CYBUNmFxV-fF-3AQ,6213
33
+ eth_portfolio/_loaders/balances.cpython-311-x86_64-linux-musl.so,sha256=uNws78yBTRvUWaOY58MCm6IGzHc5VxGMCjFOtMzQoDc,17640
34
+ eth_portfolio/_loaders/balances.py,sha256=qPo_-DjA0UfRnhyDJaelklZwrmjxQIgbJ-06cZ8pu1I,3364
35
+ eth_portfolio/_loaders/token_transfer.py,sha256=jApqFEhjGOzIz9qqf-UjEnuy5XgSiTBcs7j7sHoZiss,8492
36
+ eth_portfolio/_loaders/transaction.py,sha256=jgYg_vetemNeVwxjvkn7a-wVzoT65pOnj_ABLb4lj9M,9202
37
+ eth_portfolio/_loaders/utils.cpython-311-x86_64-linux-musl.so,sha256=jprgMNFir9B0SmmDLk-FSuc7eIYADctTX2FZ1VGCvIQ,17624
38
+ eth_portfolio/_loaders/utils.py,sha256=SLgU1UW6yiix4IZksqD421Yik5mUifH5jefmDVmDRSk,2264
39
+ eth_portfolio/_ydb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ eth_portfolio/_ydb/token_transfers.py,sha256=oLhoumwgKJcLwpJuYrpLPhADai2YOrNA06irC5pE9QE,5205
41
+ eth_portfolio/protocols/__init__.py,sha256=SK7-lE3h_0rpGFxPv7qgLh06n5LicxwJ-UEDBR3IkVE,2517
42
+ eth_portfolio/protocols/_base.py,sha256=6wPaGNSvoYruYmyrGAF4K-XMvGNK0Gt7BnlemqpAQsI,3585
43
+ eth_portfolio/protocols/convex.py,sha256=uNbXxEmhcpXulNkbxoqWl9eAJTZjPJlzXFtrBGvRXLo,518
44
+ eth_portfolio/protocols/dsr.py,sha256=dpakgHDhcVvvthspQWiXRlb88CvWVqyfA2T1QlawOZE,1738
45
+ eth_portfolio/protocols/liquity.py,sha256=i8auPyQC5chB1Q_jrMPnKOXqHoJitrZwWyYv5yXZL3M,641
46
+ eth_portfolio/protocols/lending/README.md,sha256=OhZfsW8e-aD-q02g0maG9QGgW0IietkDRZc7PBakBvc,493
47
+ eth_portfolio/protocols/lending/__init__.py,sha256=u5WITxFG1gsh1A2jG_kNKTNI58pQPmZ2-9zDVlkq03Q,1631
48
+ eth_portfolio/protocols/lending/_base.py,sha256=NG3-LbDjHWjD7yF1H95kyJHNYgnDLiqaDlWrNem6kFI,2204
49
+ eth_portfolio/protocols/lending/compound.py,sha256=r16i7Y8pq1XvNZya71GfhWzpZn8j-6MRJNAKrPxbHqA,7206
50
+ eth_portfolio/protocols/lending/liquity.py,sha256=IC-Fky4A2fQH9sHnad6SKhMZZrRx6bNNRAhxkXLvoew,4149
51
+ eth_portfolio/protocols/lending/maker.py,sha256=zIQyD3SDGPbD_yHqEfV4SKe1i05a8j2GjWZra283Wik,4282
52
+ eth_portfolio/protocols/lending/unit.py,sha256=ozzqV_pciKgZCmbDIL8721j7M_r5nXIuWlnSW0hUOU0,1930
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=c4aAKTReZ1-_eWyzUm17rZzTbgFYbXN3V9JM-MSZ-qQ,19746
56
+ eth_portfolio/typing/__init__.py,sha256=Lqp2_Qst0kPggjBJlDp9YOlaM2dNCdYpW601VuQ22gs,57118
57
+ eth_portfolio/typing/balance/single.py,sha256=jBul4zMTJT8U_cP5DKxALBKMRGXIjQFx_WIesceSPl4,6293
58
+ eth_portfolio_scripts/__init__.py,sha256=6Fc2KtR3RXEKp8aJos2EOtrtkgmn5-8XvVd8zzPzxzw,258
59
+ eth_portfolio_scripts/_args.py,sha256=k6J6XkRe1VuN1DiyGuXLCR7NBSvzH5jnVChfzodKuB8,656
60
+ eth_portfolio_scripts/_logging.py,sha256=We2lHgSbubNS-pac3Y_K0CU5JvJmsF37W4QeW4NPwyQ,353
61
+ eth_portfolio_scripts/_portfolio.py,sha256=d3DSeaNdE2Fg3erRXqf1X73e6z3_R07qcwDgzet4E4E,7785
62
+ eth_portfolio_scripts/_utils.py,sha256=EgJph58R9Rguj4r_lYeFuS8gScHFhtpTeoxPiXtL6f4,3058
63
+ eth_portfolio_scripts/balances.cpython-311-x86_64-linux-musl.so,sha256=xjLbakQWm08p3losDaIX8zzf57caokn-zDW9ahci1EI,17640
64
+ eth_portfolio_scripts/balances.py,sha256=LYqD4YPxlUIWdqiXAmtbp_MgVf1oWbDSskMtvz5T0jA,1724
65
+ eth_portfolio_scripts/main.py,sha256=zlgeH2HYTmJ9F2GbB6l0I9QLOJy1z7Xe71bOHrAsYJs,3676
66
+ eth_portfolio_scripts/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
67
+ eth_portfolio_scripts/docker/__init__.cpython-311-x86_64-linux-musl.so,sha256=V1G9iUfQ_VxAL86M-cY7ja_ZQr6JastV-MJb7LEVgkM,17632
68
+ eth_portfolio_scripts/docker/__init__.py,sha256=7bRbWsRTk0OJgZChUVIV2a9313TQQv_8iCJCi0uRSBw,393
69
+ eth_portfolio_scripts/docker/check.cpython-311-x86_64-linux-musl.so,sha256=DbQD0A7xHFDBY7HjEZwZG7B6zRMpV2yRSUqpogTHFjU,17640
70
+ eth_portfolio_scripts/docker/check.py,sha256=3iqkx-_ftWpteYDVcO2kyJLY---gPWGO2o2HH2OarpM,1906
71
+ eth_portfolio_scripts/docker/docker-compose.yaml,sha256=9detffYIxkgUg4h2_tOJx__Hrl8_xrIPlfEsYoH8RHc,1809
72
+ eth_portfolio_scripts/docker/docker_compose.cpython-311-x86_64-linux-musl.so,sha256=qNax1x0Gr3ouQJU4N1Ytk65tMVOOyaXeECXKF7L23VM,17680
73
+ eth_portfolio_scripts/docker/docker_compose.py,sha256=PvBBuUo-1wMaCC3KoBsWV_-AdET1bXbXGc0ngVa9Cgo,2788
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=6DfZfwW46gmClj1pUq6GwmumyL4XMMsOPUni8QHahEs,1964
78
+ eth_portfolio_scripts/victoria/types.py,sha256=oIwswuWU1KWWM_CyUmGf2WVPzPai_JCN2mA9gEbb8uk,694
79
+ eth_portfolio-0.5.8.dist-info/METADATA,sha256=neh_nI8wDret0cmjgMBtijOWoBZ65_tMjQev4Li34Io,875
80
+ eth_portfolio-0.5.8.dist-info/WHEEL,sha256=J_Ko_zS6o8JXUfI9CaFd6O2wkMIFNryhqfb69cs30HY,113
81
+ eth_portfolio-0.5.8.dist-info/entry_points.txt,sha256=yqoC6X3LU1NA_-oJ6mloEYEPNmS-0hPS9OtEwgIeDGU,66
82
+ eth_portfolio-0.5.8.dist-info/top_level.txt,sha256=4MlbY-Yj8oGBGL8piXiO4SOpk2gZFF9ZXVTObTZOzqM,57
83
+ eth_portfolio-0.5.8.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp311-cp311-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,17 @@
1
+ from os import environ
2
+
3
+ environ["DANKMIDS_GANACHE_FORK"] = "0"
4
+ environ["DANKMIDS_COLLECT_STATS"] = "0"
5
+
6
+
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+
12
+ from eth_portfolio_scripts._logging import logger, setup_logging
13
+
14
+ setup_logging()
15
+
16
+
17
+ __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,14 @@
1
+ import warnings
2
+ from logging import INFO, basicConfig, getLogger
3
+
4
+ from brownie.exceptions import BrownieCompilerWarning, BrownieEnvironmentWarning
5
+
6
+ logger = getLogger(__name__)
7
+
8
+
9
+ def setup_logging() -> None:
10
+ basicConfig(level=INFO)
11
+
12
+
13
+ warnings.simplefilter("ignore", BrownieCompilerWarning)
14
+ warnings.simplefilter("ignore", BrownieEnvironmentWarning)
@@ -0,0 +1,209 @@
1
+ import asyncio
2
+ from collections.abc import Awaitable, Callable, Iterator
3
+ from datetime import datetime, timezone
4
+ from logging import getLogger
5
+ from math import floor
6
+ from typing import Final
7
+
8
+ import a_sync
9
+ import eth_retry
10
+ import y
11
+ from a_sync.functools import cached_property_unsafe as cached_property
12
+ from eth_typing import BlockNumber, ChecksumAddress
13
+ from msgspec import ValidationError, json
14
+ from y import ERC20, Network, NonStandardERC20
15
+ from y.constants import CHAINID
16
+ from y.time import NoBlockFound
17
+
18
+ from eth_portfolio import Portfolio
19
+ from eth_portfolio.buckets import get_token_bucket
20
+ from eth_portfolio.portfolio import _DEFAULT_LABEL
21
+ from eth_portfolio.typing import (
22
+ Addresses,
23
+ Balance,
24
+ PortfolioBalances,
25
+ RemoteTokenBalances,
26
+ TokenBalances,
27
+ )
28
+ from eth_portfolio_scripts import victoria
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: dict[str, str] | None = 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: str | None = 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>"