Skip to content

Commit

Permalink
Since Zerion doesnt detect Aave LEND balance add special query for it
Browse files Browse the repository at this point in the history
  • Loading branch information
LefterisJP committed Jul 11, 2020
1 parent 7e46d85 commit e68cac8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions rotkehlchen/chain/ethereum/aave.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
}
ATOKENS_LIST = [EthereumToken(x) for x in ATOKEN_TO_DEPLOYED_BLOCK]

A_LEND = EthereumToken('LEND')


class AaveEvent(NamedTuple):
"""An event related to an Aave aToken
Expand Down Expand Up @@ -175,8 +177,43 @@ def get_balances(
else: # 'Debt'
borrowing_map[asset.token_symbol] = AaveBorrowingBalance(
balance=asset.balance,
variable_apr=FVal(reserve_data[4] / RAY),
stable_apr=FVal(reserve_data[4] / RAY),
variable_apr=FVal(reserve_data[5] / RAY),
stable_apr=FVal(reserve_data[6] / RAY),
)

lend_reserve_data = reserve_cache.get(reserve_address, None)
if lend_reserve_data is None:
lend_reserve_data = self.ethereum.call_contract(
contract_address=AAVE_LENDING_POOL.address,
abi=AAVE_LENDING_POOL.abi,
method_name='getReserveData',
arguments=[A_LEND.ethereum_address],
)
reserve_cache['LEND'] = lend_reserve_data

user_lend_data = self.ethereum.call_contract(
contract_address=AAVE_LENDING_POOL.address,
abi=AAVE_LENDING_POOL.abi,
method_name='getUserReserveData',
arguments=[A_LEND.ethereum_address, account],
)
if user_lend_data[0] != 0 or user_lend_data[1] != 0:
lend_usd_price = Inquirer().find_usd_price(A_LEND)

if user_lend_data[0] != 0:
amount = FVal(user_lend_data[0] / (10 ** A_LEND.decimals))
balance = Balance(amount=amount, usd_value=amount * lend_usd_price)
lending_map['LEND'] = AaveLendingBalance(
balance=balance,
apy=FVal(lend_reserve_data[4] / RAY),
)
if user_lend_data[1] != 0:
amount = FVal(user_lend_data[1] / (10 ** A_LEND.decimals))
balance = Balance(amount=amount, usd_value=amount * lend_usd_price)
borrowing_map['LEND'] = AaveBorrowingBalance(
balance=balance,
variable_apr=FVal(lend_reserve_data[5] / RAY),
stable_apr=FVal(lend_reserve_data[6] / RAY),
)

if lending_map == {} and borrowing_map == {}:
Expand Down
2 changes: 1 addition & 1 deletion rotkehlchen/chain/ethereum/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _call_contract_etherscan(
if result == '0x':
raise BlockchainQueryError(
f'Error doing call on contract {contract_address} via etherscan.'
f' Returned 0x result'
f' Returned 0x result',
)

fn_abi = contract._find_matching_fn_abi(
Expand Down

0 comments on commit e68cac8

Please sign in to comment.