Ejemplo n.º 1
0
    def _parse_liquidations(
        self,
        liquidations: List[Dict[str, Any]],
        from_ts: Timestamp,
        to_ts: Timestamp,
    ) -> List[AaveLiquidationEvent]:
        events = []
        for entry in liquidations:
            common = _parse_common_event_data(entry, from_ts, to_ts)
            if common is None:
                continue  # either timestamp out of range or error (logged in the function above)
            timestamp, tx_hash, index = common
            result = self._get_asset_and_balance(
                entry=entry,
                timestamp=timestamp,
                reserve_key='collateralReserve',
                amount_key='collateralAmount',
                location='aave liquidation from graph query',
            )
            if result is None:
                continue  # problem parsing, error already logged
            collateral_asset, collateral_balance = result

            result = self._get_asset_and_balance(
                entry=entry,
                timestamp=timestamp,
                reserve_key='principalReserve',
                amount_key='principalAmount',
                location='aave liquidation from graph query',
            )
            if result is None:
                continue  # problem parsing, error already logged
            principal_asset, principal_balance = result
            events.append(
                AaveLiquidationEvent(
                    event_type='liquidation',
                    collateral_asset=collateral_asset,
                    collateral_balance=collateral_balance,
                    principal_asset=principal_asset,
                    principal_balance=principal_balance,
                    block_number=0,  # can't get from graph query
                    timestamp=timestamp,
                    tx_hash=tx_hash,
                    log_index=
                    index,  # not really the log index, but should also be unique
                ))

        return events
Ejemplo n.º 2
0
def test_add_and_get_aave_events(data_dir, username):
    """Test that get aave events works fine and returns only events for what we need"""
    msg_aggregator = MessagesAggregator()
    data = DataHandler(data_dir, msg_aggregator)
    data.unlock(username, '123', create_new=True)

    addr1 = make_ethereum_address()
    addr1_events = [AaveSimpleEvent(
        event_type='deposit',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=1,
        timestamp=Timestamp(1),
        tx_hash='0x01653e88600a6492ad6e9ae2af415c990e623479057e4e93b163e65cfb2d4436',
        log_index=1,
    ), AaveSimpleEvent(
        event_type='withdrawal',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=2,
        timestamp=Timestamp(2),
        tx_hash='0x4147da3e5d3c0565a99192ce0b32182ab30b8e1067921d9b2a8ef3bd60b7e2ce',
        log_index=2,
    )]
    data.db.add_aave_events(address=addr1, events=addr1_events)

    addr2 = make_ethereum_address()
    addr2_events = [AaveSimpleEvent(
        event_type='deposit',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=1,
        timestamp=Timestamp(1),
        tx_hash='0x8c094d58f33e8dedcd348cb33b58f3bd447602f1fecb99e51b1c2868029eab55',
        log_index=1,
    ), AaveSimpleEvent(
        event_type='withdrawal',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=2,
        timestamp=Timestamp(2),
        tx_hash='0x58c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        log_index=2,
    )]
    data.db.add_aave_events(address=addr2, events=addr2_events)

    # addr3 has all types of aave events so we test serialization/deserialization
    addr3 = make_ethereum_address()
    addr3_events = [AaveSimpleEvent(
        event_type='deposit',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=1,
        timestamp=Timestamp(1),
        tx_hash='0x9e394d58f33e8dedcd348cb33b58f3bd447602f1fecb99e51b1c2868029eab55',
        log_index=1,
    ), AaveSimpleEvent(
        event_type='withdrawal',
        asset=A_DAI,
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=2,
        timestamp=Timestamp(2),
        tx_hash='0x4c167445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        log_index=2,
    ), AaveSimpleEvent(
        event_type='interest',
        asset=Asset('WBTC'),
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=4,
        timestamp=Timestamp(4),
        tx_hash='0x49c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        log_index=4,
    ), AaveBorrowEvent(
        event_type='borrow',
        asset=Asset('ETH'),
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=5,
        timestamp=Timestamp(5),
        tx_hash='0x19c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        log_index=5,
        borrow_rate_mode='stable',
        borrow_rate=FVal('0.05233232323423432'),
        accrued_borrow_interest=FVal('5.112234'),
    ), AaveRepayEvent(
        event_type='repay',
        asset=Asset('MANA'),
        value=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=6,
        timestamp=Timestamp(6),
        tx_hash='0x29c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        log_index=6,
        fee=Balance(amount=FVal('0.1'), usd_value=FVal('0.1')),
    ), AaveLiquidationEvent(
        event_type='liquidation',
        collateral_asset=Asset('ETH'),
        collateral_balance=Balance(amount=FVal(1), usd_value=FVal(1)),
        principal_asset=Asset('ETH'),
        principal_balance=Balance(amount=FVal(1), usd_value=FVal(1)),
        block_number=7,
        log_index=7,
        timestamp=Timestamp(7),
        tx_hash='0x39c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
    )]
    data.db.add_aave_events(address=addr3, events=addr3_events)

    events = data.db.get_aave_events(address=addr1, atoken=EthereumToken('aDAI'))
    assert events == addr1_events
    events = data.db.get_aave_events(address=addr2, atoken=EthereumToken('aDAI'))
    assert events == addr2_events
    events = data.db.get_aave_events(address=addr3)
    assert events == addr3_events

    # check that all aave events are properly hashable (aka can go in a set)
    test_set = set()
    for event in addr3_events:
        test_set.add(event)
    assert len(test_set) == len(addr3_events)
Ejemplo n.º 3
0
Archivo: aave.py Proyecto: rotki/rotki
     block_number=0,
     timestamp=Timestamp(1598800092),
     tx_hash='0x819cdd20760ab68bc7bf9343cb2e5552ab512dcf071afe1c3995a07a379f0961',
     log_index=2,
     borrow_rate_mode='variable',
     borrow_rate=FVal('0.018558721449222331635565398'),
     accrued_borrow_interest=ZERO,
 ), AaveLiquidationEvent(
     event_type='liquidation',
     collateral_asset=A_WBTC,
     collateral_balance=Balance(
         amount=FVal('0.41590034'),
         usd_value=FVal('0.41590034'),
     ),
     principal_asset=A_ETH,
     principal_balance=Balance(
         amount=FVal('9.251070299427409111'),
         usd_value=FVal('9.251070299427409111'),
     ),
     block_number=0,
     timestamp=Timestamp(1598941756),
     tx_hash='0x00eea6359d247c9433d32620358555a0fd3265378ff146b9511b7cff1ecb7829',
     log_index=8,
 ), AaveRepayEvent(
     event_type='repay',
     asset=A_ETH,
     value=Balance(
         amount=FVal('3.665850591343088034'),
         usd_value=FVal('3.665850591343088034'),
     ),
     fee=Balance(amount=ZERO, usd_value=ZERO),