Repository: rotki/rotki

Issue:
Investigate compound events for 0xA3d7553397352eFB84a0bc217a464E9E114207d6
## Problem Definition

In our tests we checked compound for [`0xA3d7553397352eFB84a0bc217a464E9E114207d6`](https://etherscan.io/address/0xA3d7553397352eFB84a0bc217a464E9E114207d6).

In the borrowing section it seems to have event for borrowing ETH but no repayment, or liquidation events and no outstanding debt.

![2020-09-15_10-38](https://user-images.githubusercontent.com/1658405/93188659-87b5e080-f741-11ea-9e58-9dddbe0d331a.png)


This does not add up. Something is missing. Either a problem with the sugraph query or a bug in our code.

## Task

Investigate



Discussion:

Resolving patch:
diff --git a/rotkehlchen/chain/ethereum/compound.py b/rotkehlchen/chain/ethereum/compound.py
--- a/rotkehlchen/chain/ethereum/compound.py
+++ b/rotkehlchen/chain/ethereum/compound.py
@@ -278,9 +278,6 @@ def _get_borrow_events(
 
         events = []
         for entry in result[graph_event_name]:
-            if event_type == 'repay' and entry['borrower'] != entry['payer']:
-                continue  # skip repay event. It's actually a liquidation
-
             underlying_symbol = entry['underlyingSymbol']
             try:
                 underlying_asset = Asset(underlying_symbol)
@@ -658,8 +655,19 @@ def get_history(
             user_events = self._get_lend_events('mint', address, from_timestamp, to_timestamp)
             user_events.extend(self._get_lend_events('redeem', address, from_timestamp, to_timestamp))  # noqa: E501
             user_events.extend(self._get_borrow_events('borrow', address, from_timestamp, to_timestamp))  # noqa: E501
-            user_events.extend(self._get_borrow_events('repay', address, from_timestamp, to_timestamp))  # noqa: E501
-            user_events.extend(self._get_liquidation_events(address, from_timestamp, to_timestamp))
+            repay_events = self._get_borrow_events('repay', address, from_timestamp, to_timestamp)
+            liquidation_events = self._get_liquidation_events(address, from_timestamp, to_timestamp)  # noqa: E501
+            indices_to_remove = []
+            for levent in liquidation_events:
+                for ridx, revent in enumerate(repay_events):
+                    if levent.tx_hash == revent.tx_hash:
+                        indices_to_remove.append(ridx)
+
+            for i in sorted(indices_to_remove, reverse=True):
+                del repay_events[i]
+
+            user_events.extend(repay_events)
+            user_events.extend(liquidation_events)
             if len(user_events) != 0:
                 # query comp events only if any other event has happened
                 user_events.extend(self._get_comp_events(address, from_timestamp, to_timestamp))


Test patch:
diff --git a/rotkehlchen/tests/api/test_makerdao_vaults.py b/rotkehlchen/tests/api/test_makerdao_vaults.py
--- a/rotkehlchen/tests/api/test_makerdao_vaults.py
+++ b/rotkehlchen/tests/api/test_makerdao_vaults.py
@@ -564,9 +564,9 @@ def test_query_vaults_usdc(rotkehlchen_api_server, ethereum_accounts):
         collateral=Balance(ZERO, ZERO),
         debt=Balance(ZERO, ZERO),
         collateralization_ratio=None,
-        liquidation_ratio=FVal(1.1),
+        liquidation_ratio=FVal('1.03'),
         liquidation_price=None,
-        stability_fee=FVal(0.04),
+        stability_fee=FVal('0.04'),
     )
     expected_vaults = [vault_7588.serialize()]
     assert_serialized_lists_equal(expected_vaults, vaults, ignore_keys=['stability_fee'])
@@ -626,7 +626,7 @@ def test_query_vaults_usdc(rotkehlchen_api_server, ethereum_accounts):
     }
     details = assert_proper_response_with_result(response)
     expected_details = [vault_7588_details]
-    assert_serialized_lists_equal(expected_details, details)
+    assert_serialized_lists_equal(expected_details, details, ignore_keys=['liquidation_ratio'])
 
 
 @pytest.mark.parametrize('number_of_eth_accounts', [1])
diff --git a/rotkehlchen/tests/utils/checks.py b/rotkehlchen/tests/utils/checks.py
--- a/rotkehlchen/tests/utils/checks.py
+++ b/rotkehlchen/tests/utils/checks.py
@@ -60,6 +60,9 @@ def assert_serialized_dicts_equal(
             if a_val == b[a_key]:
                 continue
 
+            if '%' in a_val:
+                raise AssertionError(f'{a_val} != {b[a_key]}')
+
             # if strings are not equal, try to turn them to Fvals
             try:
                 afval = FVal(a_val)