Repository: rotki/rotki

Issue:
BlockFi Issue when Importing
## Problem Definition

When I try to import an All transactions CSV that I downloaded from BlockFi on May 29th, 2022, the records cannot be imported and in Notifications I get the error:

"Unsuported entry Crypto Transfer. Data: {'Cryptocurrency': 'USDC', 'Amount': '3597.48627700', 'Transaction Type': 'Crypto Transfer', 'Confirmed At': '2021-01-27 07:57:38'}"

I assume this is happening with all records since nothing is ultimately imported.




Discussion:
Hey @skazzaks thank you for the issue!

Unfortunately CSV imports are very easy to break since all these services such as blockfi alter the format however and whenever they want.

To address this we would need you to provide us with an example file you need to import to see how it looks like now. Can you do that?
Thanks for getting back to me! I am able to reproduce with this:
[trade_report_all2.csv](https://github.com/rotki/rotki/files/8793371/trade_report_all2.csv)


Looks like the offender is of type "Crypto Transfer" and the others in my dataset aren't, so that could be it.
Hey @skazzaks thanks. We will have a look using the csv you provided.
Hey @skazzaks
In a bid to resolve your issue, what does `Crypto Transfer` represent? A crypto deposit or withdrawal?
I looked into it and I am not sure, but I suspect transferring crypto in or
out of BlockFi. I do that very rarely so maybe that was it.

On Mon, 30 May 2022 at 15:42, Isaac Adewumi ***@***.***>
wrote:

> Hey @skazzaks <https://github.com/skazzaks>
> In a bid to resolve your issue, what does Crypto Transfer represent? A
> crypto deposit or withdrawal?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/rotki/rotki/issues/4386#issuecomment-1141175811>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAFJZAGGWEZNF5H2D7YT5FLVMTATDANCNFSM5XIDLIUQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


Resolving patch:
diff --git a/rotkehlchen/data/importer.py b/rotkehlchen/data/importer.py
--- a/rotkehlchen/data/importer.py
+++ b/rotkehlchen/data/importer.py
@@ -871,6 +871,24 @@ def _consume_blockfi_entry(self, csv_row: Dict[str, Any], **kwargs: Any) -> None
                 notes=f'{entry_type} from BlockFi',
             )
             self.db_ledger.add_ledger_action(action)
+        elif entry_type == 'Crypto Transfer':
+            category = (
+                AssetMovementCategory.WITHDRAWAL if FVal(csv_row['Amount']) < ZERO
+                else AssetMovementCategory.DEPOSIT
+            )
+            asset_movement = AssetMovement(
+                location=Location.BLOCKFI,
+                category=category,
+                address=None,
+                transaction_id=None,
+                timestamp=timestamp,
+                asset=asset,
+                amount=amount,
+                fee=fee,
+                fee_asset=fee_asset,
+                link='',
+            )
+            self.db.add_asset_movements([asset_movement])
         elif entry_type == 'Trade':
             pass
         else:


Test patch:
diff --git a/rotkehlchen/tests/data/blockfi-transactions.csv b/rotkehlchen/tests/data/blockfi-transactions.csv
--- a/rotkehlchen/tests/data/blockfi-transactions.csv
+++ b/rotkehlchen/tests/data/blockfi-transactions.csv
@@ -5,4 +5,6 @@ ETH,0.56469042,Interest Payment,2021-01-30 23:59:59
 BTC,0.00052383,Referral Bonus,2020-12-02 23:59:59
 ETH,-3,Withdrawal,2020-11-21 16:59:31
 ETH,0.48385358,Bonus Payment,2020-09-16 21:59:59
-BTC,1.11415058,Deposit,2020-07-20 12:10:55
\ No newline at end of file
+BTC,1.11415058,Deposit,2020-07-20 12:10:55
+USDC,3597.48627700,Crypto Transfer,2021-01-27 07:57:38
+BTC,-2.11415058,Crypto Transfer,2021-01-28 07:57:38
\ No newline at end of file
diff --git a/rotkehlchen/tests/utils/dataimport.py b/rotkehlchen/tests/utils/dataimport.py
--- a/rotkehlchen/tests/utils/dataimport.py
+++ b/rotkehlchen/tests/utils/dataimport.py
@@ -619,6 +619,28 @@ def assert_blockfi_transactions_import_results(rotki: Rotkehlchen):
         fee_asset=A_USD,
         fee=Fee(ZERO),
         link='',
+    ), AssetMovement(
+        location=Location.BLOCKFI,
+        category=AssetMovementCategory.DEPOSIT,
+        address=None,
+        transaction_id=None,
+        timestamp=Timestamp(1611734258),
+        asset=A_USDC,
+        amount=AssetAmount(FVal('3597.48627700')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='',
+    ), AssetMovement(
+        location=Location.BLOCKFI,
+        category=AssetMovementCategory.WITHDRAWAL,
+        address=None,
+        transaction_id=None,
+        timestamp=Timestamp(1611820658),
+        asset=A_BTC,
+        amount=AssetAmount(FVal('2.11415058')),
+        fee_asset=A_USD,
+        fee=Fee(ZERO),
+        link='',
     )]
     assert expected_movements == asset_movements