eth-portfolio 0.5.0__cp312-cp312-win32.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.cp312-win32.pyd +0 -0
  3. eth_portfolio/_argspec.py +42 -0
  4. eth_portfolio/_cache.py +121 -0
  5. eth_portfolio/_config.cp312-win32.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 +604 -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 +938 -0
  16. eth_portfolio/_ledgers/portfolio.py +327 -0
  17. eth_portfolio/_loaders/__init__.py +33 -0
  18. eth_portfolio/_loaders/_nonce.cp312-win32.pyd +0 -0
  19. eth_portfolio/_loaders/_nonce.py +196 -0
  20. eth_portfolio/_loaders/balances.cp312-win32.pyd +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 +240 -0
  24. eth_portfolio/_loaders/utils.cp312-win32.pyd +0 -0
  25. eth_portfolio/_loaders/utils.py +68 -0
  26. eth_portfolio/_shitcoins.cp312-win32.pyd +0 -0
  27. eth_portfolio/_shitcoins.py +340 -0
  28. eth_portfolio/_stableish.cp312-win32.pyd +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 +145 -0
  34. eth_portfolio/address.py +397 -0
  35. eth_portfolio/buckets.py +212 -0
  36. eth_portfolio/constants.cp312-win32.pyd +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 +1447 -0
  56. eth_portfolio/typing/balance/single.py +176 -0
  57. eth_portfolio-0.5.0.dist-info/METADATA +26 -0
  58. eth_portfolio-0.5.0.dist-info/RECORD +83 -0
  59. eth_portfolio-0.5.0.dist-info/WHEEL +5 -0
  60. eth_portfolio-0.5.0.dist-info/entry_points.txt +2 -0
  61. eth_portfolio-0.5.0.dist-info/top_level.txt +3 -0
  62. eth_portfolio__mypyc.cp312-win32.pyd +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.cp312-win32.pyd +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__.cp312-win32.pyd +0 -0
  74. eth_portfolio_scripts/docker/__init__.py +16 -0
  75. eth_portfolio_scripts/docker/check.cp312-win32.pyd +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.cp312-win32.pyd +0 -0
  79. eth_portfolio_scripts/docker/docker_compose.py +98 -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.0
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.154
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.6
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.0.9
20
+ Requires-Dist: ypricemagic<5.1,>=5
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.cp312-win32.pyd,sha256=Ebtqi-lAmKXX6TYyqMSckyXD_Gq4PIwfR81QXpCcra0,267776
2
+ eth_portfolio/__init__.py,sha256=5GmHYzhUX2gOC4MScgXnqS8x2MawbpWOuWPmqlvCotA,525
3
+ eth_portfolio/_argspec.cp312-win32.pyd,sha256=Ww3JS1u5fCLffXVdSJbdGLCNH-fom0kBcIPebh39GJI,9216
4
+ eth_portfolio/_argspec.py,sha256=au8ycJ56-7UzbQVzYUOoMX9sToH0QNi2tS1O820xB3A,1637
5
+ eth_portfolio/_cache.py,sha256=OntwbiDOrBV5JzHHDzJlxcEVrmKK5GG0uXeLeoDDbpA,4926
6
+ eth_portfolio/_config.cp312-win32.pyd,sha256=H_UEB92WJ6V7OGRx0r-zPamOPawTvSOP0a8I5DstIT4,9216
7
+ eth_portfolio/_config.py,sha256=BSOvFS4D0oqgVTtBbtW2g2kpL8Mk6xiP0PipfXs_91A,102
8
+ eth_portfolio/_decimal.py,sha256=DwLUg8pzeTIREG2sHgRK48hoWmjelWNvpEKj10Ra7to,5002
9
+ eth_portfolio/_decorators.py,sha256=AvB-q69MvaFe0Ykh1os6hSewcUujURQ9onqobMaONOM,2899
10
+ eth_portfolio/_exceptions.py,sha256=xb5VmCtBtXy9WXu_1ofoG4j9BJsMQXMVydCJNUulrNY,2500
11
+ eth_portfolio/_shitcoins.cp312-win32.pyd,sha256=_Z6fv0mLcmSCZlrny6a5Rb1BuC36Hp-5aayYdqSJY2k,9216
12
+ eth_portfolio/_shitcoins.py,sha256=TRK7b5bYj5rVUPn5QClDa5cnJxcx0zvEP8A3e8HvMSQ,17901
13
+ eth_portfolio/_stableish.cp312-win32.pyd,sha256=TmlgeL4cgnublxxx0Iq4Z0WcK3xExQibhDFRNexMRxo,9216
14
+ eth_portfolio/_stableish.py,sha256=8pdlYe2YcZ8rTzdCzg-ihRQLPtSFXBNDjtnvuTgPRcQ,2063
15
+ eth_portfolio/_submodules.py,sha256=zne-2YyVFoKHwkLuHx8cdz5lpcwwSDw1edJ9v8G4c1A,2263
16
+ eth_portfolio/_utils.py,sha256=iGck5SKUwpfnuZvLnKDR1A00obZNKx622Y9GY_TYiZA,7886
17
+ eth_portfolio/address.py,sha256=RrFIWSx6jSITwh16Hqs6W6S9fz1KEaebQEk1vqL3HwI,14536
18
+ eth_portfolio/buckets.py,sha256=n8FdgC_mf4DZPFkEu3v3LOamN1Kani8CIrhaLyg_6jY,7811
19
+ eth_portfolio/constants.cp312-win32.pyd,sha256=Bruk66blVI9T41HAqjY0_AlEGgLW5h8ii1yyk1wFVMA,9216
20
+ eth_portfolio/constants.py,sha256=IKMVKXjoQ74RRnpK3sEtqbbGmwKlYg0pXzuGVO0R0B8,4063
21
+ eth_portfolio/portfolio.py,sha256=FSJ1_FG120dN5vWSPyhbHfyuFHdmFqTHJ5_Ci-4Rts4,24909
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=RS-RiuOAgbrMKQpCwwAtP3lPRs8vKM6aPhh9LP4SwtI,5308
25
+ eth_portfolio/_db/entities.py,sha256=1Z1AsR400SJYzDrDGxUJt1HuSKB3ErvxIytFtju7UHU,10345
26
+ eth_portfolio/_db/utils.py,sha256=3P4EVQ5cHLbDrAnBESAIKhoDpJLXLS8IDJNnsh7T2Sc,21586
27
+ eth_portfolio/_ledgers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
+ eth_portfolio/_ledgers/address.py,sha256=wght92UXf6UIO9GNRzdMy3H43Em7kUk9ArtBsRF-xjw,33830
29
+ eth_portfolio/_ledgers/portfolio.py,sha256=rAr5S1tksgLPUOK1J1FbIWgvTQNzTqrRp8oukiP2BTo,13427
30
+ eth_portfolio/_loaders/__init__.py,sha256=YrBeRuA48cN2Bg2R2nXiNt1CsUIG_7N6ENIpY6aISPo,1735
31
+ eth_portfolio/_loaders/_nonce.cp312-win32.pyd,sha256=HLxQnMsPf9yAsAWAUAXI8WCKzVPcilO5mrv4JhI-r1Y,9216
32
+ eth_portfolio/_loaders/_nonce.py,sha256=bA-5fZG8ALuADgQGrnoxt6p6j7QEwI6vIGnZRF1Zx7M,6481
33
+ eth_portfolio/_loaders/balances.cp312-win32.pyd,sha256=bosDMyqaaNuzC_NLXRLz4Zs54yefLWFrxvK7gO7TKKs,9216
34
+ eth_portfolio/_loaders/balances.py,sha256=_v-x1M3lzDHPt8svHmCcpxZKw0BaGHfZimhkwgphY8A,3226
35
+ eth_portfolio/_loaders/token_transfer.py,sha256=itaWVDyotG0EYPb4o94UOpxYvTdE6YIuUR2pzpXAnwI,8748
36
+ eth_portfolio/_loaders/transaction.py,sha256=oOG3cFdLAa10k2hpN17GO7Wtq-rpUJ1oo7hLAKDjbDc,9393
37
+ eth_portfolio/_loaders/utils.cp312-win32.pyd,sha256=Ym7DE_kmDTGaadrOkkIE370pbWe8HZvrV2dtCGOohSs,9216
38
+ eth_portfolio/_loaders/utils.py,sha256=gJvIikinjCPj-elQVep55VTya9slSARApx-FJKYwnkE,2333
39
+ eth_portfolio/_ydb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ eth_portfolio/_ydb/token_transfers.py,sha256=HUTeWShcQD4IzocTHmBOreml0jbVttLcaed1fNiJ2qg,5297
41
+ eth_portfolio/protocols/__init__.py,sha256=k1e4MI8KPALIg7awaVA9LbBuEjqxWZF7uGgxysQ4y90,2623
42
+ eth_portfolio/protocols/_base.py,sha256=nuMnnltg4HZ0Z5Nl83ofwAsTE3A9jLYhDZFkRhAKIIY,3793
43
+ eth_portfolio/protocols/convex.py,sha256=az8FhxLtXf0WKo25Ke0IDRGF8x1yMlffoCRz9aG2fGE,535
44
+ eth_portfolio/protocols/dsr.py,sha256=jn_4niDINXQxqu9Tfb77vsfbhv4oIRRFKsKvnMgEO4I,1806
45
+ eth_portfolio/protocols/liquity.py,sha256=Ptiem5zd1op6qmZj2d6PmcgSqrKCLhlTw3CmIwII1Dc,656
46
+ eth_portfolio/protocols/lending/README.md,sha256=0C941RnyfQwT1DE9bvxwLP-gBTHlQcQysF-75FXHINo,498
47
+ eth_portfolio/protocols/lending/__init__.py,sha256=4jKDPx3sb7Iyi9kOdJRpM6LJy_GhUpviLIbpV_6noYU,1693
48
+ eth_portfolio/protocols/lending/_base.py,sha256=_1zXroYHlliLP685xiRfw8I_tQOoZyaPlnxA_gzLytU,2311
49
+ eth_portfolio/protocols/lending/compound.py,sha256=1aoksFSvIIsk-cNDs2-Kdwl-RtIdTzh3QgpksXG1kEs,7439
50
+ eth_portfolio/protocols/lending/liquity.py,sha256=bJ5TKD-WTVn3S1tlbSGGVFCoKFvgStHVOzKBM2LbsRY,4294
51
+ eth_portfolio/protocols/lending/maker.py,sha256=zXDeD9qS0hP1thEraQ_NlDkBOW5B-Lb2q3RcVWPzV80,4419
52
+ eth_portfolio/protocols/lending/unit.py,sha256=OQGDZWdsTOUL4jOKJ1xef6wXhWLHnsRFJjAzn0XSBmM,2011
53
+ eth_portfolio/structs/__init__.py,sha256=x-9CdKe8XMukp8Kjr_lD49ohrSd0iGEvvsMAHtAPrLI,1486
54
+ eth_portfolio/structs/modified.py,sha256=QIuFh-u5VTHe0oborn3oHAiAGD0wqhUQW7XFJVZu2KI,1853
55
+ eth_portfolio/structs/structs.py,sha256=TDJ4u3E_H8uG7iX-C1Pux8TesY2zXRhQUJxmN7cp4cc,20490
56
+ eth_portfolio/typing/__init__.py,sha256=v_KbOgqTKcR4y-05Bel_mg6uAV-IsGurGR-jDW46SMg,58763
57
+ eth_portfolio/typing/balance/single.py,sha256=NmtWXqCWMIkaoyvfL67Rh0wWurLf55fVaDkyUxZ27oY,6501
58
+ eth_portfolio_scripts/__init__.py,sha256=DIBnQmjmhmNL1lO9Lq4QptrZmC7u6_N3p9zRjcZ9vbY,281
59
+ eth_portfolio_scripts/_args.py,sha256=M33vPkja62XEJeCZAqacNSBCqbzse07wepwyBOtkvVo,682
60
+ eth_portfolio_scripts/_logging.py,sha256=EgW8ozQZLAgt_cUgqe5BYZLMVQwB6X-0gq0T-BvqlTY,369
61
+ eth_portfolio_scripts/_portfolio.py,sha256=b9TPX2c4Tg5FJLFEsaG45Ks4XYn0G--v746vpJdWnjU,8003
62
+ eth_portfolio_scripts/_utils.py,sha256=lj2B79G8YX21ATNp_v-onsU_kNFZF3unBclCVp3AIn8,3163
63
+ eth_portfolio_scripts/balances.cp312-win32.pyd,sha256=rzObhWlNFu7b5is0Ue2N91HJ858UyIRswUIg6opqi_A,9216
64
+ eth_portfolio_scripts/balances.py,sha256=ttU2OlxIZY4cou7D_yLmIKd8vjdHLtddq2-PXCR7N0U,1801
65
+ eth_portfolio_scripts/main.py,sha256=ToEwL5_bLEwZLasTV7FroQInjLe28l7J7FGzYdxZ8mY,3804
66
+ eth_portfolio_scripts/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
67
+ eth_portfolio_scripts/docker/__init__.cp312-win32.pyd,sha256=ocquzT4zi7piXSkbTakT2-VoskU4nSAiw1L0BbKz-3U,9216
68
+ eth_portfolio_scripts/docker/__init__.py,sha256=R27uZPLUEK2--fb9IrxrDUk6R5_IVFJSv7s_ia7p5Xk,409
69
+ eth_portfolio_scripts/docker/check.cp312-win32.pyd,sha256=Ekx5hWwQefBewBnGlFCPmMt21vIQVgaIYBn0bO-Y_Og,9216
70
+ eth_portfolio_scripts/docker/check.py,sha256=mf853kj0_M2iI3d2KuWuwsXtSieP9qWhvTJdrqX8iU8,1997
71
+ eth_portfolio_scripts/docker/docker-compose.yaml,sha256=WecmD-VvS_78ay3waRjsH8Vch9gHXriaAYD34wFFWB0,1870
72
+ eth_portfolio_scripts/docker/docker_compose.cp312-win32.pyd,sha256=0z5wpiq_Adqx-NYOscPUY6npvV0pHFdlAJP6mjTkyiE,9216
73
+ eth_portfolio_scripts/docker/docker_compose.py,sha256=w1Z4XfSCC1vVLnss74XbkHUBVb0P2-zOIkMyidkZh38,2903
74
+ eth_portfolio_scripts/docker/.grafana/dashboards/dashboards.yaml,sha256=wktTI-OAdF_khhbciZFo4Gt2V9bUjbe7GLqwdzTKf0U,212
75
+ eth_portfolio_scripts/docker/.grafana/dashboards/Portfolio/Balances.json,sha256=XGMV8e4tDak53e9bmymwAB4uqZmAIcU5JlRT3OiwTeU,70750
76
+ eth_portfolio_scripts/docker/.grafana/datasources/datasources.yml,sha256=8PPH_QDhfbRRh3IidskW46rifJejloa1a9I1KCw2FTk,199
77
+ eth_portfolio_scripts/victoria/__init__.py,sha256=R0VvKiAC0e57zZNihcCptVkFO5CBHIbp2trFYuyY01M,2038
78
+ eth_portfolio_scripts/victoria/types.py,sha256=KNq8aIiNXeiDnCKL7xycmouo0YeKI-sbQkIcTymcSYk,745
79
+ eth_portfolio-0.5.0.dist-info/METADATA,sha256=K8pzlsm0OQ5wiUDNOtV2nwMtiZQzJm_EdrewQwHyLeI,832
80
+ eth_portfolio-0.5.0.dist-info/WHEEL,sha256=LwxTQZ0gyDP_uaeNCLm-ZIktY9hv6x0e22Q-hgFd-po,97
81
+ eth_portfolio-0.5.0.dist-info/entry_points.txt,sha256=yqoC6X3LU1NA_-oJ6mloEYEPNmS-0hPS9OtEwgIeDGU,66
82
+ eth_portfolio-0.5.0.dist-info/top_level.txt,sha256=4MlbY-Yj8oGBGL8piXiO4SOpk2gZFF9ZXVTObTZOzqM,57
83
+ eth_portfolio-0.5.0.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-win32
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
Binary file
@@ -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>"