Skip to content

Commit

Permalink
Conversion tool: added parser for Zerion explorer
Browse files Browse the repository at this point in the history
New parser for the Zerion wallet/explorer, this is an easy way to import your Ethereum DeFi transactions.

This change also fixes the convert_currency method of DataParser to handle if the currency is not fiat.
  • Loading branch information
nanonano committed Jun 23, 2021
1 parent 0550142 commit d2f755d
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data_source_fiat:
- Conversion tool: added parser for BscScan explorer.
- Conversion tool: specify the local currency of the "Value" headers.
- Conversion tool: added parser for Exodus wallet.
- Conversion tool: added parser for Zerion explorer.
### Changed
- Conversion tool: UnknownAddressError exception changed to generic DataFilenameError.
- Binance parser: use filename to determine if deposits or withdrawals.
Expand Down
3 changes: 3 additions & 0 deletions bittytax/conv/dataparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def parse_timestamp(cls, timestamp_str, tzinfos=None, tz=None, dayfirst=False, f

@classmethod
def convert_currency(cls, value, from_currency, timestamp):
if from_currency not in config.fiat_list:
return None

if not value or value is None:
return None

Expand Down
1 change: 1 addition & 0 deletions bittytax/conv/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
from . import trezor
from . import uphold
from . import wirex
from . import zerion
102 changes: 102 additions & 0 deletions bittytax/conv/parsers/zerion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
# (c) Nano Nano Ltd 2021

from ..out_record import TransactionOutRecord
from ..dataparser import DataParser
from ..exceptions import UnexpectedTypeError

WALLET = "Ethereum"

def parse_zerion(data_row, parser, **_kwargs):
row_dict = data_row.row_dict
data_row.timestamp = DataParser.parse_timestamp(row_dict['Date'] + ' ' + row_dict['Time'])

# We have to strip carriage returns from fields, this is a bug in the Zerion exporter
if row_dict['Buy Amount']:
buy_quantity = row_dict['Buy Amount'].split('\n')[0]
buy_asset = row_dict['Buy Currency'].split('\n')[0]
buy_value = DataParser.convert_currency(row_dict['Buy Fiat Amount'].split('\n')[0],
row_dict['Buy Fiat Currency'].split('\n')[0],
data_row.timestamp)
else:
buy_quantity = None
buy_asset = ''
buy_value = None

if row_dict['Sell Amount']:
sell_quantity = row_dict['Sell Amount'].split('\n')[0]
sell_asset = row_dict['Sell Currency'].split('\n')[0]
sell_value = DataParser.convert_currency(row_dict['Sell Fiat Amount'].split('\n')[0],
row_dict['Sell Fiat Currency'].split('\n')[0],
data_row.timestamp)
else:
sell_quantity = None
sell_asset = ''
sell_value = None

if row_dict['Fee Amount']:
fee_quantity = row_dict['Fee Amount'].split('\n')[0]
fee_asset = row_dict['Fee Currency'].split('\n')[0]
fee_value = DataParser.convert_currency(row_dict['Fee Fiat Amount'].split('\n')[0],
row_dict['Fee Fiat Currency'].split('\n')[0],
data_row.timestamp)
else:
fee_quantity = None
fee_asset = ''
fee_value = None

if row_dict['Accounting Type'] == "Income":
data_row.t_record = TransactionOutRecord(TransactionOutRecord.TYPE_DEPOSIT,
data_row.timestamp,
buy_quantity=buy_quantity,
buy_asset=buy_asset,
buy_value=buy_value,
fee_quantity=fee_quantity,
fee_asset=fee_asset,
fee_value=fee_value,
wallet=WALLET)
elif row_dict['Accounting Type'] == "Spend":
if sell_quantity is None and fee_quantity is None:
return

# If a Spend only contains fees, we must include a sell of zero
if sell_quantity is None:
sell_quantity = 0
sell_asset = fee_asset

data_row.t_record = TransactionOutRecord(TransactionOutRecord.TYPE_WITHDRAWAL,
data_row.timestamp,
sell_quantity=sell_quantity,
sell_asset=sell_asset,
sell_value=sell_value,
fee_quantity=fee_quantity,
fee_asset=fee_asset,
fee_value=fee_value,
wallet=WALLET)
elif row_dict['Accounting Type'] == "Trade":
data_row.t_record = TransactionOutRecord(TransactionOutRecord.TYPE_TRADE,
data_row.timestamp,
buy_quantity=buy_quantity,
buy_asset=buy_asset,
buy_value=buy_value,
sell_quantity=sell_quantity,
sell_asset=sell_asset,
sell_value=sell_value,
fee_quantity=fee_quantity,
fee_asset=fee_asset,
fee_value=fee_value,
wallet=WALLET)
else:
raise UnexpectedTypeError(parser.in_header.index('Accounting Type'), 'Accounting Type',
row_dict['Accounting Type'])

DataParser(DataParser.TYPE_EXPLORER,
"Zerion (ETH Transactions)",
['Date', 'Time', 'Transaction Type', 'Status', 'Application', 'Accounting Type',
'Buy Amount', 'Buy Currency', 'Buy Currency Address', 'Buy Fiat Amount',
'Buy Fiat Currency', 'Sell Amount', 'Sell Currency', 'Sell Currency Address',
'Sell Fiat Amount', 'Sell Fiat Currency', 'Fee Amount', 'Fee Currency',
'Fee Fiat Amount', 'Fee Fiat Currency', 'Sender', 'Receiver', 'Tx Hash', 'Link',
'Timestamp', 'Changes JSON'],
worksheet_name="Zerion",
row_handler=parse_zerion)

0 comments on commit d2f755d

Please sign in to comment.