Ejemplo n.º 1
0
 def _process_vault_dai_payback(
         self,
         pot: 'AccountingPot',  # pylint: disable=unused-argument
         event: HistoryBaseEntry,
         other_events: List[HistoryBaseEntry],  # pylint: disable=unused-argument
 ) -> None:
     cdp_id = event.extra_data[
         'cdp_id']  # type: ignore  # this event should have extra_data
     self.vault_balances[cdp_id] -= event.balance.amount
     if self.vault_balances[cdp_id] < ZERO:
         loss = -1 * self.vault_balances[cdp_id]
         pot.add_spend(
             event_type=AccountingEventType.TRANSACTION_EVENT,
             notes=f'Lost {loss} DAI as debt during payback to CDP {cdp_id}',
             location=event.location,
             timestamp=event.get_timestamp_in_sec(),
             asset=A_DAI,
             amount=loss,
             taxable=True,
             extra_data={'tx_hash': event.event_identifier},
         )
         self.vault_balances[cdp_id] = ZERO
Ejemplo n.º 2
0
 def _process_dsr_withdraw(
         self,
         pot: 'AccountingPot',  # pylint: disable=unused-argument
         event: HistoryBaseEntry,
         other_events: List[HistoryBaseEntry],  # pylint: disable=unused-argument
 ) -> None:
     address = cast(ChecksumEthAddress,
                    event.location_label)  # should always exist
     self.dsr_balances[address] -= event.balance.amount
     if self.dsr_balances[address] < ZERO:
         profit = -1 * self.dsr_balances[address]
         pot.add_acquisition(
             event_type=AccountingEventType.TRANSACTION_EVENT,
             notes=f'Gained {profit} DAI from Makerdao DSR',
             location=event.location,
             timestamp=event.get_timestamp_in_sec(),
             asset=A_DAI,
             amount=profit,
             taxable=True,
             extra_data={'tx_hash': event.event_identifier},
         )
         self.dsr_balances[address] = ZERO
Ejemplo n.º 3
0
    def process(
        self,
        event: HistoryBaseEntry,
        events_iterator: Iterator[AccountingEventMixin],
    ) -> int:
        """Process a transaction event and return amount of actions consumed from the iterator"""
        timestamp = event.get_timestamp_in_sec()
        type_identifier = event.get_type_identifier()
        event_settings = self.tx_event_settings.get(type_identifier, None)
        if event_settings is None:
            log.debug(
                f'During transaction accounting found transaction event {event} '
                f'with no mapped event settings. Skipping...', )
            return 1

        notes = event.notes if event.notes else ''
        counter = 1
        other_events: List[HistoryBaseEntry] = []
        while counter < event_settings.take:
            next_event = next(events_iterator, None)
            if next_event is None:
                log.debug(
                    f'At accounting for tx_event {notes} we expected to take '
                    f'{event_settings.take} additional events but found no more',
                )
                return counter
            if not isinstance(next_event, HistoryBaseEntry):
                log.debug(
                    f'At accounting for tx_event {notes} we expected to take '
                    f'{event_settings.take} additional events but found a '
                    f'non history base entry event', )
                return counter
            other_events.append(next_event)
            counter += 1

        # if there is any module specific accountant functionality call it
        if event_settings.accountant_cb is not None:
            event_settings.accountant_cb(
                pot=self.pot,
                event=event,
                other_events=other_events,
            )

        if event_settings.multitake_treatment == TxMultitakeTreatment.SWAP:  # noqa: E501
            return self._process_tx_swap(
                timestamp=timestamp,
                out_event=event,
                in_event=other_events[0],
                event_settings=event_settings,
            )

        self.pot.add_asset_change_event(
            method=event_settings.method,
            event_type=AccountingEventType.TRANSACTION_EVENT,
            notes=event.notes if event.notes else '',
            location=event.location,
            timestamp=timestamp,
            asset=event.asset,
            amount=event.balance.amount,
            taxable=event_settings.taxable,
            count_entire_amount_spend=event_settings.count_entire_amount_spend,
            count_cost_basis_pnl=event_settings.count_cost_basis_pnl,
            extra_data={'tx_hash': event.event_identifier},
        )
        return 1