예제 #1
0
파일: events.py 프로젝트: yakkomajuri/rotki
    def add_defi_event(self, event: DefiEvent) -> None:
        log.debug(
            'Accounting for DeFi event',
            sensitive_log=True,
            event=event,
        )
        rate = self.get_rate_in_profit_currency(event.asset, event.timestamp)
        profit_loss = event.amount * rate
        if not event.is_profitable():
            profit_loss *= -1

        self.defi_profit_loss += profit_loss
        self.csv_exporter.add_defi_event(
            event=event, profit_loss_in_profit_currency=profit_loss)
예제 #2
0
    def add_defi_event(self, event: DefiEvent,
                       profit_loss_in_profit_currency: FVal) -> None:
        if not self.create_csv:
            return

        self.defi_events_csv.append({
            'time':
            self.timestamp_to_date(event.timestamp),
            'type':
            str(event.event_type),
            'asset':
            str(event.asset),
            'amount':
            str(event.amount),
            f'profit_loss_in_{self.profit_currency.identifier}':
            profit_loss_in_profit_currency,
            'tx_hashes':
            event.serialize_tx_hashes(),
            'notes':
            event.notes,
        })

        paid_asset: Union[EmptyStr, Asset]
        received_asset: Union[EmptyStr, Asset]
        if event.is_profitable():
            paid_in_profit_currency = ZERO
            paid_in_asset = ZERO
            paid_asset = S_EMPTYSTR
            received_asset = event.asset
            received_in_asset = event.amount
            received_in_profit_currency = profit_loss_in_profit_currency
        else:
            paid_in_profit_currency = -1 * profit_loss_in_profit_currency
            paid_in_asset = event.amount
            paid_asset = event.asset
            received_asset = S_EMPTYSTR
            received_in_asset = ZERO
            received_in_profit_currency = ZERO

        self.add_to_allevents(
            event_type=EV_DEFI,
            location=Location.BLOCKCHAIN,
            paid_in_profit_currency=paid_in_profit_currency,
            paid_asset=paid_asset,
            paid_in_asset=paid_in_asset,
            received_asset=received_asset,
            received_in_asset=received_in_asset,
            taxable_received_in_profit_currency=received_in_profit_currency,
            timestamp=event.timestamp,
        )