Skip to content

Commit

Permalink
If can't find usd_value of base_balance, sum up all underlying ones
Browse files Browse the repository at this point in the history
  • Loading branch information
LefterisJP committed Jul 6, 2020
1 parent d56bb0d commit a30b180
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 9 additions & 2 deletions rotkehlchen/chain/ethereum/zerion.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def all_balances_for_account(self, account: ChecksumEthAddress) -> List[DefiProt
defi_balance = self._get_single_balance(balance)
underlying_balances.append(defi_balance)

if base_balance.balance.usd_value == ZERO:
# This can happen. We can't find a price for some assets
# such as combined pool assets. But we can instead use
# the sum of the usd_value of the underlying_balances
usd_sum = sum(x.balance.usd_value for x in underlying_balances)
base_balance.balance.usd_value = usd_sum # type: ignore

protocol_balances.append(DefiProtocolBalances(
protocol=protocol,
balance_type=balance_type,
Expand All @@ -111,18 +118,18 @@ def _get_single_balance(self, entry: Tuple[Tuple[str, str, str, int], int]) -> D
decimals = metadata[3]
normalized_value = token_normalized_value(balance_value, decimals)
token_symbol = metadata[2]

try:
asset = Asset(token_symbol)
usd_price = Inquirer().find_usd_price(asset)
except (UnknownAsset, UnsupportedAsset):
if '+' not in token_symbol: # ignore the curve fi "pool" combined base asset
if '+' not in token_symbol: # ignore the curvefinance pool combined base asset
self.msg_aggregator.add_error(
f'Unsupported asset {token_symbol} encountered during DeFi protocol queries',
)
usd_price = Price(ZERO)

usd_value = normalized_value * usd_price

defi_balance = DefiBalance(
token_address=to_checksum_address(metadata[0]),
token_name=metadata[1],
Expand Down
3 changes: 1 addition & 2 deletions rotkehlchen/tests/api/test_defi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def test_query_defi_balances(rotkehlchen_api_server, ethereum_accounts): # pyli
result = assert_proper_response_with_result(response)

assert len(result) == 1

# Since we can't really be sure of latest balance of a non-test accont just check
# Since we can't really be sure of latest balance of a non-test account just check
# for correctness of result if there is any balance
if len(result['0x2B888954421b424C5D3D9Ce9bB67c9bD47537d12']) != 0:
first_entry = result['0x2B888954421b424C5D3D9Ce9bB67c9bD47537d12'][0]
Expand Down

0 comments on commit a30b180

Please sign in to comment.