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,110 @@
1
+ from asyncio import gather
2
+ from typing import Final
3
+
4
+ from a_sync import igather
5
+ from brownie import ZERO_ADDRESS
6
+ from dank_mids.exceptions import Revert
7
+ from eth_typing import HexStr
8
+ from faster_async_lru import alru_cache
9
+ from faster_eth_abi import encode
10
+ from y import Contract, Network, contract_creation_block_async, get_price
11
+ from y._decorators import stuck_coro_debugger
12
+ from y.constants import dai
13
+ from y.datatypes import Address, Block
14
+
15
+ from eth_portfolio._utils import Decimal
16
+ from eth_portfolio.protocols.lending._base import LendingProtocolWithLockedCollateral
17
+ from eth_portfolio.typing import Balance, TokenBalances
18
+
19
+ yfi: Final = "0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e"
20
+ dai: Contract
21
+ _1e18: Final = Decimal(10**18)
22
+ _1e45: Final = Decimal(10**45)
23
+
24
+
25
+ def encode_bytes(bytestring: str) -> bytes:
26
+ return encode(["bytes32"], [bytestring])
27
+
28
+
29
+ class Maker(LendingProtocolWithLockedCollateral):
30
+ networks = [Network.Mainnet]
31
+
32
+ def __init__(self) -> None:
33
+ self.proxy_registry = Contract("0x4678f0a6958e4D2Bc4F1BAF7Bc52E8F3564f3fE4")
34
+ self.cdp_manager = Contract("0x5ef30b9986345249bc32d8928B7ee64DE9435E39")
35
+ self.ilk_registry = Contract("0x5a464C28D19848f44199D003BeF5ecc87d090F87")
36
+ self.vat = Contract("0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B")
37
+
38
+ @stuck_coro_debugger
39
+ async def _balances(self, address: Address, block: Block | None = None) -> TokenBalances:
40
+ if block is not None and block <= await contract_creation_block_async(self.ilk_registry):
41
+ return TokenBalances(block=block)
42
+
43
+ # `self._urn` is cached after the first call so we will await these without gather
44
+ urn = await self._urn(address)
45
+ ilks = await self.get_ilks(block)
46
+
47
+ gem_coros = igather(map(self.get_gem, map(str, ilks)))
48
+ ink_coros = igather(
49
+ self.vat.urns.coroutine(ilk, urn, block_identifier=block) for ilk in ilks
50
+ )
51
+
52
+ gems, ink_data = await gather(gem_coros, ink_coros)
53
+
54
+ balances: TokenBalances = TokenBalances(block=block)
55
+ for token, data in zip(gems, ink_data):
56
+ if token != ZERO_ADDRESS and (ink := data.dict()["ink"]):
57
+ balance = ink / _1e18
58
+ value = round(balance * Decimal(await get_price(token, block, sync=False)), 18)
59
+ balances[token] = Balance(balance, value, token=token, block=block)
60
+ return balances
61
+
62
+ @stuck_coro_debugger
63
+ async def _debt(self, address: Address, block: int | None = None) -> TokenBalances:
64
+ if block is not None and block <= await contract_creation_block_async(self.ilk_registry):
65
+ return TokenBalances(block=block)
66
+
67
+ # `self._urn` is cached after the first call so we will await these without gather
68
+ urn = await self._urn(address)
69
+ ilks = await self.get_ilks(block)
70
+
71
+ data = await igather(
72
+ gather(
73
+ self.vat.urns.coroutine(ilk, urn, block_identifier=block),
74
+ self.vat.ilks.coroutine(ilk, block_identifier=block),
75
+ )
76
+ for ilk in ilks
77
+ )
78
+
79
+ balances: TokenBalances = TokenBalances(block=block)
80
+ for urns, ilk_info in data:
81
+ art = urns.dict()["art"]
82
+ rate = ilk_info.dict()["rate"]
83
+ debt = art * rate / _1e45
84
+ balances[dai.address] += Balance(debt, debt, token=dai, block=block)
85
+ return balances
86
+
87
+ async def get_ilks(self, block: int | None) -> list[HexStr]:
88
+ """List all ilks (cdp keys of sorts) for MakerDAO"""
89
+ try:
90
+ return await self.ilk_registry.list.coroutine(block_identifier=block)
91
+ except Revert:
92
+ return []
93
+
94
+ @alru_cache
95
+ async def get_gem(self, ilk: bytes) -> str:
96
+ return await self.ilk_registry.gem.coroutine(ilk)
97
+
98
+ @alru_cache
99
+ async def _proxy(self, address: Address) -> Address:
100
+ return await self.proxy_registry.proxies.coroutine(address)
101
+
102
+ @alru_cache
103
+ async def _cdp(self, address: Address) -> Address:
104
+ proxy = await self._proxy(address)
105
+ return await self.cdp_manager.first.coroutine(proxy)
106
+
107
+ @alru_cache
108
+ async def _urn(self, address: Address) -> Address:
109
+ cdp = await self._cdp(address)
110
+ return await self.cdp_manager.urns.coroutine(cdp)
@@ -0,0 +1,44 @@
1
+ from y import Contract, Network
2
+ from y._decorators import stuck_coro_debugger
3
+ from y.datatypes import Address, Block
4
+
5
+ from eth_portfolio._decimal import Decimal
6
+ from eth_portfolio._utils import _get_price
7
+ from eth_portfolio.protocols.lending._base import LendingProtocolWithLockedCollateral
8
+ from eth_portfolio.typing import Balance, TokenBalances
9
+
10
+ # NOTE: This only works for YFI collateral, must extend before using for other collaterals
11
+ yfi = "0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e"
12
+ usdp = "0x1456688345527bE1f37E9e627DA0837D6f08C925"
13
+
14
+
15
+ class UnitXyz(LendingProtocolWithLockedCollateral):
16
+ networks = [Network.Mainnet]
17
+
18
+ def __init__(self) -> None:
19
+ self.unitVault = Contract("0xb1cff81b9305166ff1efc49a129ad2afcd7bcf19")
20
+ self.start_block = 11315910
21
+
22
+ @stuck_coro_debugger
23
+ async def _balances(self, address: Address, block: Block | None = None) -> TokenBalances:
24
+ balances: TokenBalances = TokenBalances(block=block)
25
+ if block and block < self.start_block:
26
+ return balances
27
+ bal: int = await self.unitVault.collaterals.coroutine(yfi, address, block_identifier=block)
28
+ if bal:
29
+ bal = Decimal(bal) / 10**18
30
+ balances[yfi] = Balance(bal, bal * await _get_price(yfi, block), token=yfi, block=block)
31
+ return balances
32
+
33
+ @stuck_coro_debugger
34
+ async def _debt(self, address: Address, block: Block | None = None) -> TokenBalances:
35
+ balances: TokenBalances = TokenBalances(block=block)
36
+ if block and block < self.start_block:
37
+ return balances
38
+ # NOTE: This only works for YFI based debt, must extend before using for other collaterals
39
+ if debt := await self.unitVault.getTotalDebt.coroutine(
40
+ yfi, address, block_identifier=block
41
+ ):
42
+ debt = Decimal(debt) / 10**18
43
+ balances[usdp] = Balance(debt, debt, token=usdp, block=block)
44
+ return balances
@@ -0,0 +1,17 @@
1
+ from y import ERC20, Network
2
+
3
+ from eth_portfolio.protocols._base import SingleTokenStakingPoolABC
4
+
5
+
6
+ class LqtyStakingPool(SingleTokenStakingPoolABC):
7
+ networks = [Network.Mainnet]
8
+ contract_address = "0x4f9Fbb3f1E99B56e0Fe2892e623Ed36A76Fc605d"
9
+ balance_method_name = "stakes"
10
+ token = ERC20("0x6DEA81C8171D0bA574754EF6F8b412F2Ed88c54D") # LQTY
11
+
12
+
13
+ class LiquityStabilityPool(SingleTokenStakingPoolABC):
14
+ networks = [Network.Mainnet]
15
+ contract_address = "0x66017D22b0f8556afDd19FC67041899Eb65a21bb"
16
+ balance_method_name = "getCompoundedLUSDDeposit"
17
+ token = ERC20("0x5f98805A4E8be255a32880FDeC7F6728C6568bA0") # LUSD
eth_portfolio/py.typed ADDED
File without changes
@@ -0,0 +1,43 @@
1
+ """
2
+ This module provides the primary union type and specific ledger entry types used in the `eth_portfolio` package.
3
+
4
+ The `__all__` list defines the public API for this module, which includes the main union type `LedgerEntry` and its specific types: `Transaction`, `InternalTransfer`, `TokenTransfer`, and `TransactionRLP`.
5
+
6
+ Examples:
7
+ Importing the main union type and specific ledger entry types:
8
+
9
+ >>> from eth_portfolio.structs import LedgerEntry, Transaction, InternalTransfer, TokenTransfer, TransactionRLP
10
+
11
+ Using the `LedgerEntry` union type to annotate a variable that can hold any ledger entry type:
12
+
13
+ >>> entry: LedgerEntry = Transaction(...)
14
+ >>> entry = InternalTransfer(...)
15
+ >>> entry = TokenTransfer(...)
16
+ >>> entry = TransactionRLP(...)
17
+
18
+ See Also:
19
+ - :class:`~eth_portfolio.structs.structs.LedgerEntry`
20
+ - :class:`~eth_portfolio.structs.structs.Transaction`
21
+ - :class:`~eth_portfolio.structs.structs.InternalTransfer`
22
+ - :class:`~eth_portfolio.structs.structs.TokenTransfer`
23
+ - :class:`~eth_portfolio.structs.structs.TransactionRLP`
24
+ """
25
+
26
+ from eth_portfolio.structs.structs import (
27
+ InternalTransfer,
28
+ LedgerEntry,
29
+ TokenTransfer,
30
+ Transaction,
31
+ TransactionRLP,
32
+ )
33
+
34
+ __all__ = [
35
+ # main union type
36
+ "LedgerEntry",
37
+ # LedgerEntry types
38
+ "Transaction",
39
+ "InternalTransfer",
40
+ "TokenTransfer",
41
+ # TODO figure out how to get rid of this
42
+ "TransactionRLP",
43
+ ]
@@ -0,0 +1,69 @@
1
+ from typing import Union
2
+
3
+ from evmspec.structs.trace import call, create, reward, suicide
4
+
5
+
6
+ class CallTrace(
7
+ call.Trace,
8
+ frozen=True,
9
+ kw_only=True,
10
+ array_like=True,
11
+ forbid_unknown_fields=True,
12
+ omit_defaults=True,
13
+ repr_omit_defaults=True,
14
+ ): # type: ignore [call-arg]
15
+ """
16
+ It works just like a :class:`evmspec.trace.call.Trace` but it encodes to a tuple instead of a dict to save space since keys are known.
17
+ """
18
+
19
+
20
+ class CreateTrace(
21
+ create.Trace,
22
+ frozen=True,
23
+ kw_only=True,
24
+ array_like=True,
25
+ forbid_unknown_fields=True,
26
+ omit_defaults=True,
27
+ repr_omit_defaults=True,
28
+ ): # type: ignore [call-arg]
29
+ """
30
+ It works just like a :class:`evmspec.trace.create.Trace` but it encodes to a tuple instead of a dict to save space since keys are known.
31
+ """
32
+
33
+
34
+ class RewardTrace(
35
+ reward.Trace,
36
+ frozen=True,
37
+ kw_only=True,
38
+ array_like=True,
39
+ forbid_unknown_fields=True,
40
+ omit_defaults=True,
41
+ repr_omit_defaults=True,
42
+ ): # type: ignore [call-arg]
43
+ """
44
+ It works just like a :class:`evmspec.trace.reward.Trace` but it encodes to a tuple instead of a dict to save space since keys are known.
45
+ """
46
+
47
+
48
+ class SuicideTrace(
49
+ suicide.Trace,
50
+ frozen=True,
51
+ kw_only=True,
52
+ array_like=True,
53
+ forbid_unknown_fields=True,
54
+ omit_defaults=True,
55
+ repr_omit_defaults=True,
56
+ ): # type: ignore [call-arg]
57
+ """
58
+ It works just like a :class:`evmspec.trace.suicide.Trace` but it encodes to a tuple instead of a dict to save space since keys are known.
59
+ """
60
+
61
+
62
+ _modified_trace_type_map = {
63
+ call.Trace: CallTrace,
64
+ create.Trace: CreateTrace,
65
+ reward.Trace: RewardTrace,
66
+ suicide.Trace: SuicideTrace,
67
+ }
68
+
69
+ ModifiedTrace = Union[CallTrace, CreateTrace, RewardTrace, SuicideTrace]