-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor external protocols (#82)
- Loading branch information
1 parent
1b18559
commit f01f7f2
Showing
4 changed files
with
47 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
|
||
import asyncio | ||
from typing import List, Optional | ||
|
||
import a_sync | ||
from y.datatypes import Address, Block | ||
|
||
from eth_portfolio._utils import (_get_protocols_for_submodule, | ||
_import_submodules) | ||
from eth_portfolio.protocols import lending | ||
from eth_portfolio.protocols._base import StakingPoolABC | ||
from eth_portfolio.typing import RemoteTokenBalances | ||
|
||
_import_submodules() | ||
|
||
protocols: List[StakingPoolABC] = _get_protocols_for_submodule() # type: ignore [assignment] | ||
|
||
class ExternalBalances: | ||
protocols: List[StakingPoolABC] = _get_protocols_for_submodule() # type: ignore | ||
|
||
@a_sync.future | ||
async def balances(self, address: Address, block: Optional[Block] = None) -> RemoteTokenBalances: | ||
if not self.protocols: | ||
return RemoteTokenBalances() | ||
return RemoteTokenBalances({ | ||
type(protocol).__name__: protocol_balances | ||
async for protocol, protocol_balances | ||
in a_sync.map(lambda p: p.balances(address, block), self.protocols) | ||
if protocol_balances is not None | ||
}) | ||
|
||
_external = ExternalBalances() | ||
@a_sync.future | ||
async def balances(address: Address, block: Optional[Block] = None) -> RemoteTokenBalances: | ||
if not protocols: | ||
return RemoteTokenBalances() | ||
return RemoteTokenBalances({ | ||
type(protocol).__name__: protocol_balances | ||
async for protocol, protocol_balances | ||
in a_sync.map(lambda p: p.balances(address, block), protocols) | ||
if protocol_balances is not None | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters