def __init__( self, ethereum_manager: 'EthereumManager', msg_aggregator: MessagesAggregator, ) -> None: self.ethereum = ethereum_manager self.zerion_sdk = ZerionSDK(ethereum_manager, msg_aggregator)
def test_query_all_protocol_balances_for_account( ethereum_manager, function_scope_messages_aggregator, inquirer, # pylint: disable=unused-argument ): """Simple test that we can get balances for various defi protocols via zerion At the moment we are using random accounts that at some point have balances in a protocol. So the test just checks that some balance is queried. No specific. TODO: Perhaps create a small rotki tests account on the mainnet that keeps a certain balance in a few DeFi protocols and does not change them. This way we can have something stable to check again. """ zerion = ZerionSDK(ethereum_manager, function_scope_messages_aggregator) balances = zerion.all_balances_for_account( '0xf753beFE986e8Be8EBE7598C9d2b6297D9DD6662') if len(balances) == 0: test_warnings.warn( UserWarning('Test account for DeFi balances has no balances')) return assert len(balances) > 0 errors = function_scope_messages_aggregator.consume_errors() assert len(errors) == 0 warnings = function_scope_messages_aggregator.consume_warnings() assert len(warnings) == 0
def test_protocol_names_are_known( ethereum_manager, function_scope_messages_aggregator, inquirer, # pylint: disable=unused-argument ): zerion = ZerionSDK(ethereum_manager, function_scope_messages_aggregator) protocol_names = zerion.contract.call( ethereum=zerion.ethereum, method_name='getProtocolNames', arguments=[], ) # Make sure that none of the already known names has changed. If it has changed. # If it has that may cause trouble as we saw in: https://github.com/rotki/rotki/issues/1803 for expected_name in KNOWN_ZERION_PROTOCOL_NAMES: msg = f'Could not find "{expected_name}" in the zerion protocol names' assert expected_name in protocol_names, msg # informative pass with some warnings if a protocol is added by zerion we don't know about # We should check those warnings from time to time and add them to the known # protocols and add an icon for them among other things for name in protocol_names: if name not in KNOWN_ZERION_PROTOCOL_NAMES: test_warnings.warn( UserWarning( f'Unknown protocol "{name}" seen in Zerion protocol names' ), )
class DefiChad(): """An aggregator for many things ethereum DeFi""" def __init__( self, ethereum_manager: 'EthereumManager', msg_aggregator: MessagesAggregator, ) -> None: self.ethereum = ethereum_manager self.zerion_sdk = ZerionSDK(ethereum_manager, msg_aggregator) def query_defi_balances( self, addresses: List[ChecksumEthAddress], ) -> Dict[ChecksumEthAddress, List[DefiProtocolBalances]]: defi_balances = defaultdict(list) for account in addresses: balances = self.zerion_sdk.all_balances_for_account(account) if len(balances) != 0: defi_balances[account] = balances # and also query balances of tokens that are not detected by zerion adapter contract result = multicall_specific( ethereum=self.ethereum, contract=VOTE_ESCROWED_CRV, method_name='locked', arguments=[[x] for x in addresses], ) crv_price = Price(ZERO) if any(x[0] != 0 for x in result): crv_price = Inquirer().find_usd_price(A_CRV) for idx, address in enumerate(addresses): balance = result[idx][0] if balance == 0: continue # else the address has vote escrowed CRV amount = token_normalized_value_decimals(token_amount=balance, token_decimals=18) protocol_balance = DefiProtocolBalances( protocol=DefiProtocol( name='Curve • Vesting', description='Curve vesting or locked in escrow for voting', url='https://www.curve.fi/', version=1, ), balance_type='Asset', base_balance=DefiBalance( token_address=VOTE_ESCROWED_CRV.address, token_name='Vote-escrowed CRV', token_symbol='veCRV', balance=Balance( amount=amount, usd_value=amount * crv_price, ), ), underlying_balances=[], ) defi_balances[address].append(protocol_balance) return defi_balances
class DefiChad(): """An aggregator for many things ethereum DeFi""" def __init__( self, ethereum_manager: 'EthereumManager', msg_aggregator: MessagesAggregator, ) -> None: self.ethereum = ethereum_manager self.zerion_sdk = ZerionSDK(ethereum_manager, msg_aggregator) def query_defi_balances( self, addresses: List[ChecksumEthAddress], ) -> Dict[ChecksumEthAddress, List[DefiProtocolBalances]]: defi_balances = defaultdict(list) for account in addresses: balances = self.zerion_sdk.all_balances_for_account(account) if len(balances) != 0: defi_balances[account] = balances return defi_balances