def test_case_does_not_matter_for_asset_constructor(): """Test that whatever case we give to asset constructor result is the same""" a1 = Asset('bTc') a2 = Asset('BTC') assert a1 == a2 assert a1.identifier == 'BTC' assert a2.identifier == 'BTC' a3 = symbol_to_ethereum_token('UsDt') a4 = symbol_to_ethereum_token('usdt') assert a3.identifier == a4.identifier == ethaddress_to_identifier('0xdAC17F958D2ee523a2206206994597C13D831ec7') # noqa: E501
def _compound_symbol_to_token(symbol: str, timestamp: Timestamp) -> EthereumToken: """ Turns a compound symbol to an ethereum token. May raise UnknownAsset """ if symbol == 'cWBTC': if timestamp >= Timestamp(1615751087): return EthereumToken('0xccF4429DB6322D5C611ee964527D42E5d685DD6a') # else return EthereumToken('0xC11b1268C1A384e55C48c2391d8d480264A3A7F4') # else return symbol_to_ethereum_token(symbol)
def get_balances( self, given_defi_balances: GIVEN_DEFI_BALANCES, ) -> Dict[ChecksumEthAddress, Dict[str, Dict[Asset, CompoundBalance]]]: compound_balances = {} if isinstance(given_defi_balances, dict): defi_balances = given_defi_balances else: defi_balances = given_defi_balances() for account, balance_entries in defi_balances.items(): lending_map = {} borrowing_map = {} rewards_map = {} for balance_entry in balance_entries: if balance_entry.protocol.name not in ('Compound Governance', 'Compound'): continue entry = balance_entry.base_balance if entry.token_address == '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': asset = A_ETH # hacky way to specify ETH in compound else: try: asset = EthereumToken(entry.token_address) except UnknownAsset: log.error( f'Encountered unknown asset {entry.token_symbol} with address ' f'{entry.token_address} in compound. Skipping', ) continue unclaimed_comp_rewards = ( entry.token_address == A_COMP.ethereum_address and balance_entry.protocol.name == 'Compound Governance') if unclaimed_comp_rewards: rewards_map[A_COMP] = CompoundBalance( balance_type=BalanceType.ASSET, balance=entry.balance, apy=None, ) continue if balance_entry.balance_type == 'Asset': # Get the underlying balance underlying_token_address = balance_entry.underlying_balances[ 0].token_address try: underlying_asset = EthereumToken( underlying_token_address) except UnknownAsset: log.error( f'Encountered unknown token with address ' f'{underlying_token_address} in compound. Skipping', ) continue lending_map[underlying_asset] = CompoundBalance( balance_type=BalanceType.ASSET, balance=balance_entry.underlying_balances[0].balance, apy=self._get_apy(entry.token_address, supply=True), ) else: # 'Debt' try: ctoken = symbol_to_ethereum_token('c' + entry.token_symbol) except UnknownAsset: log.error( f'Encountered unknown asset {entry.token_symbol} in ' f'compound while figuring out cToken. Skipping', ) continue borrowing_map[asset] = CompoundBalance( balance_type=BalanceType.LIABILITY, balance=entry.balance, apy=self._get_apy(ctoken.ethereum_address, supply=False), ) if lending_map == {} and borrowing_map == {} and rewards_map == {}: # no balances for the account continue compound_balances[account] = { 'rewards': rewards_map, 'lending': lending_map, 'borrowing': borrowing_map, } return compound_balances # type: ignore