示例#1
0
def test_get_logs(ethereum_manager, call_order,
                  ethereum_manager_connect_at_start):
    wait_until_all_nodes_connected(
        ethereum_manager_connect_at_start=ethereum_manager_connect_at_start,
        ethereum=ethereum_manager,
    )

    argument_filters = {
        'from': '0x7780E86699e941254c8f4D9b7eB08FF7e96BBE10',
        'to': YEARN_YCRV_VAULT.address,
    }
    events = ethereum_manager.get_logs(
        contract_address='0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8',
        abi=ERC20TOKEN_ABI,
        event_name='Transfer',
        argument_filters=argument_filters,
        from_block=10712531,
        to_block=10712753,
        call_order=call_order,
    )
    assert len(events) == 1
    expected_event = {
        'address':
        '0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8',
        'blockNumber':
        10712731,
        'data':
        '0x0000000000000000000000000000000000000000000001e3f60028423cff0000',
        'gasPrice':
        72000000000,
        'gasUsed':
        93339,
        'logIndex':
        157,
        'topics': [
            '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
            '0x0000000000000000000000007780e86699e941254c8f4d9b7eb08ff7e96bbe10',
            '0x0000000000000000000000005dbcf33d8c2e976c6b560249878e6f1491bca25c',
        ],
        'transactionHash':
        '0xca33e56e1e529dacc9aa1261c8ba9230927329eb609fbe252e5bd3c2f5f3bcc9',
        'transactionIndex':
        85,
    }
    assert_serialized_dicts_equal(
        events[0],
        expected_event,
        same_key_length=False,
        ignore_keys=[
            'timeStamp',  # returned from etherscan
            'blockHash',  # returned from web3
            'removed',  # returned from web3
        ],
    )
示例#2
0
def test_two_vaults_same_account_same_collateral(rotkehlchen_api_server,
                                                 ethereum_accounts):
    """Check that no events are duplicated between vaults for same collateral by same account

    Test for vaults side of https://github.com/rotki/rotki/issues/1032
    """
    rotki = rotkehlchen_api_server.rest_api.rotkehlchen
    proxies_mapping = {
        # proxy for 8632 and 8543
        ethereum_accounts[0]:
        '0xAe9996b76bdAa003ace6D66328A6942565f5768d',
    }
    mock_proxies(rotki, proxies_mapping, 'makerdao_vaults')

    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultsresource",
        ))
    vaults = assert_proper_response_with_result(response)
    vault_8543 = {
        'identifier': 8543,
        'owner': ethereum_accounts[0],
        'collateral_type': 'ETH-A',
        'collateral_asset': 'ETH',
        'collateral': {
            'amount': '0',
            'usd_value': '0',
        },
        'debt': {
            'amount': '0',
            'usd_value': '0',
        },
        'collateralization_ratio': None,
        'liquidation_ratio': '150.00%',
        'liquidation_price': None,
        'stability_fee': '0.00%',
    }
    vault_8632 = {
        'identifier': 8632,
        'owner': ethereum_accounts[0],
        'collateral_type': 'ETH-A',
        'collateral_asset': 'ETH',
        'collateral': {
            'amount': '0',
            'usd_value': '0',
        },
        'debt': {
            'amount': '0',
            'usd_value': '0',
        },
        'collateralization_ratio': None,
        'liquidation_ratio': '150.00%',
        'liquidation_price': None,
        'stability_fee': '0.00%',
    }
    assert len(vaults) == 2
    assert_serialized_dicts_equal(vaults[0],
                                  vault_8543,
                                  ignore_keys=['stability_fee'])
    assert_serialized_dicts_equal(vaults[1],
                                  vault_8632,
                                  ignore_keys=VAULT_IGNORE_KEYS)
    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultdetailsresource",
        ))
    vault_8543_details = {
        'identifier':
        8543,
        'collateral_asset':
        'ETH',
        'creation_ts':
        1587910979,
        'total_interest_owed':
        '0',
        'total_liquidated': {
            'amount': '0',
            'usd_value': '0',
        },
        'events': [{
            'event_type':
            'deposit',
            'value': {
                'amount': '1',
                'usd_value': '197.78',
            },
            'timestamp':
            1587910979,
            'tx_hash':
            '0xf59858df4e42cdc2aecfebdcf38e1df841866c6a9eb3adb6bde9a844564a3bb6',
        }, {
            'event_type':
            'generate',
            'value': {
                'amount': '80',
                'usd_value': '81.2',
            },
            'timestamp':
            1587910979,
            'tx_hash':
            '0xf59858df4e42cdc2aecfebdcf38e1df841866c6a9eb3adb6bde9a844564a3bb6',
        }, {
            'event_type':
            'payback',
            'value': {
                'amount': '80',
                'usd_value': '80.24',
            },
            'timestamp':
            1589989097,
            'tx_hash':
            '0x52396f7d20db54e2e9e716698b643a39815ff149a6cccbe9c7597dc9e06bb9d3',
        }, {
            'event_type':
            'deposit',
            'value': {
                'amount': '3.5',
                'usd_value': '734.475',
            },
            'timestamp':
            1589993538,
            'tx_hash':
            '0x3c3942dc40fe68303098d91e765ceecaed4664bba0ef8f8e684b6f0e61968c6c',
        }, {
            'event_type':
            'withdraw',
            'value': {
                'amount': '4.5',
                'usd_value': '893.52',
            },
            'timestamp':
            1590043499,
            'tx_hash':
            '0xbcd4158f0089404f6ab5378517762cddc13d21c9d2fcf3fd45cf1cf4b656242c',
        }],
    }
    vault_8632_details = {
        'identifier':
        8632,
        'collateral_asset':
        'ETH',
        'creation_ts':
        1588174425,
        'total_interest_owed':
        '0',
        'total_liquidated': {
            'amount': '0',
            'usd_value': '0',
        },
        'events': [{
            'event_type':
            'deposit',
            'value': {
                'amount': '2.4',
                'usd_value': '517.32',
            },
            'timestamp':
            1588174425,
            'tx_hash':
            '0xdb677a4257b5bdb305c278102d7b2460408bb7a3981414b994f4dd80a737ac2a',
        }, {
            'event_type':
            'generate',
            'value': {
                'amount': '192',
                'usd_value': '194.688',
            },
            'timestamp':
            1588174425,
            'tx_hash':
            '0xdb677a4257b5bdb305c278102d7b2460408bb7a3981414b994f4dd80a737ac2a',
        }, {
            'event_type':
            'payback',
            'value': {
                'amount': '192',
                'usd_value': '192.192',
            },
            'timestamp':
            1590042891,
            'tx_hash':
            '0x488a937677030cc810d0062001c08c944ecf6329b24a45ae9480bada8147bf75',
        }, {
            'event_type':
            'deposit',
            'value': {
                'amount': '4.4',
                'usd_value': '873.664',
            },
            'timestamp':
            1590043699,
            'tx_hash':
            '0x712ddb654b878bcb30c5344d7c18f7f796fe94abd6e5b8a22b2da0a6c99bb425',
        }, {
            'event_type':
            'generate',
            'value': {
                'amount': '429.79',
                'usd_value': '430.21979',
            },
            'timestamp':
            1590044118,
            'tx_hash':
            '0x36bfa27e157c03393a8816f6c1e3e990474f8f7473413810d87e2f4981d58044',
        }],
    }
    details = assert_proper_response_with_result(response)
    assert len(details) == 2
    assert_serialized_dicts_equal(details[0],
                                  vault_8543_details,
                                  ignore_keys=['stability_fee'])
    assert_serialized_dicts_equal(
        details[1],
        vault_8632_details,
        ignore_keys=[
            'total_interest_owed',
            'total_liquidated_amount',
            'total_liquidated_usd',
            'stability_fee',
        ],
        # Checking only the first 5 events, since that's how many we had when the test was written
        length_list_keymap={'events': 5},
    )
示例#3
0
def test_query_vaults_details_liquidation(rotkehlchen_api_server,
                                          ethereum_accounts):
    """Check vault details of a vault with liquidations

    Also use three accounts, two of which have vaults associated with them to test
    that vaults for multiple accounts get detected
    """
    rotki = rotkehlchen_api_server.rest_api.rotkehlchen
    proxies_mapping = {
        ethereum_accounts[0]: '0x689D4C2229717f877A644A0aAd742D67E5D0a2FB',
        ethereum_accounts[2]: '0x420F88De6dadA0a77Db7b9EdBe3A0C614346031E',
    }
    mock_proxies(rotki, proxies_mapping, 'makerdao_vaults')
    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultsresource",
        ))
    vaults = assert_proper_response_with_result(response)
    vault_6021 = {
        'identifier': 6021,
        'owner': ethereum_accounts[2],
        'collateral_type': 'ETH-A',
        'collateral_asset': 'ETH',
        'collateral': {
            'amount': ZERO,
            'usd_value': ZERO,
        },
        'debt': {
            'amount': ZERO,
            'usd_value': ZERO,
        },
        'collateralization_ratio': None,
        'liquidation_ratio': '150.00%',
        'liquidation_price': None,
        'stability_fee': '0.00%',
    }
    vault_8015_with_owner = VAULT_8015.copy()
    vault_8015_with_owner['owner'] = ethereum_accounts[0]
    assert_serialized_dicts_equal(vault_6021,
                                  vaults[0],
                                  ignore_keys=['stability_fee'])
    assert_serialized_dicts_equal(
        vault_8015_with_owner,
        vaults[1],
        ignore_keys=VAULT_IGNORE_KEYS,
    )
    assert len(vaults) == 2

    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultdetailsresource",
        ))
    vault_6021_details = {
        'identifier':
        6021,
        'collateral_asset':
        'ETH',
        'creation_ts':
        1582699808,
        'total_interest_owed':
        '-11078.655097848869',
        'total_liquidated': {
            'amount': '141.7',
            'usd_value': '19191.848',
        },
        'events': [{
            'event_type':
            'deposit',
            'value': {
                'amount': '140',
                'usd_value': '31322.2',
            },
            'timestamp':
            1582699808,
            'tx_hash':
            '0x3246ef91fd3d6e1f7c5766de4fa1f0991ba67d92e518447ba8207fe98569c309',
        }, {
            'event_type':
            'generate',
            'value': {
                'amount': '14000',
                'usd_value': '14028',
            },
            'timestamp':
            1582699808,
            'tx_hash':
            '0x3246ef91fd3d6e1f7c5766de4fa1f0991ba67d92e518447ba8207fe98569c309',
        }, {
            'event_type':
            'deposit',
            'value': {
                'amount': '1.7',
                'usd_value': '331.262',
            },
            'timestamp':
            1583958747,
            'tx_hash':
            '0x65ac798cb9f22068e43fd9ef8303a31e436989062ae87e25650cc44c7788ab62',
        }, {
            'event_type':
            'payback',
            'value': {
                'amount': '2921.344902',
                'usd_value': '2927.187591',
            },
            'timestamp':
            1584024065,
            'tx_hash':
            '0x6e44d22d6898ee012369787cd75ea6fb9ace6f995cd157675f370e8ba4a7b9ad',
        }, {
            'event_type':
            'liquidation',
            'value': {
                'amount': '50',
                'usd_value': '6772',
            },
            'timestamp':
            1584061534,
            'tx_hash':
            '0xb02050d914ab40f59a9e07eb4f8161ce36eb97cea9c189b027eb1ceeac83a516',
        }, {
            'event_type':
            'liquidation',
            'value': {
                'amount': '50',
                'usd_value': '6772',
            },
            'timestamp':
            1584061897,
            'tx_hash':
            '0x678f31d49dd70d76c0ce441343c0060dc600f4c8dbb4cee2b08c6b451b6097cd',
        }, {
            'event_type':
            'liquidation',
            'value': {
                'amount': '41.7',
                'usd_value': '5647.848',
            },
            'timestamp':
            1584061977,
            'tx_hash':
            '0xded0f9de641087692555d92a7fa94fa9fa7abf22744b2d16c20a66c5e48a8edf',
        }],
    }
    details = assert_proper_response_with_result(response)
    assert len(details) == 2
    assert_serialized_dicts_equal(vault_6021_details,
                                  details[0],
                                  ignore_keys=['stability_fee'])
    assert_serialized_dicts_equal(
        VAULT_8015_DETAILS,
        details[1],
        length_list_keymap={'events': 7},
        ignore_keys=['total_interest_owed'],
    )
    assert FVal(details[1]['total_interest_owed']) >= FVal(
        VAULT_8015_DETAILS['total_interest_owed'], )
示例#4
0
def test_query_vaults_wbtc(rotkehlchen_api_server, ethereum_accounts):
    """Check vault info and details for a vault with WBTC as collateral"""
    rotki = rotkehlchen_api_server.rest_api.rotkehlchen
    proxies_mapping = {
        ethereum_accounts[0]:
        '0x9684e6C1c7B79868839b27F88bA6d5A176367075',  # 8913
    }

    mock_proxies(rotki, proxies_mapping, 'makerdao_vaults')
    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultsresource",
        ))
    # That proxy has 3 vaults. We only want to test 8913, which is closed/repaid so just keep that
    vaults = [
        x for x in assert_proper_response_with_result(response)
        if x['identifier'] == 8913
    ]
    vault_8913 = MakerdaoVault(
        identifier=8913,
        owner=ethereum_accounts[0],
        collateral_type='WBTC-A',
        urn='0x37f7B3C82A9Edc13FdCcE66E7d500b3698A13294',
        collateral_asset=A_WBTC,
        collateral=Balance(ZERO, ZERO),
        debt=Balance(ZERO, ZERO),
        collateralization_ratio=None,
        liquidation_ratio=FVal(1.5),
        liquidation_price=None,
        stability_fee=FVal(0.02),
    )
    expected_vaults = [vault_8913.serialize()]
    assert_serialized_lists_equal(expected_vaults,
                                  vaults,
                                  ignore_keys=['stability_fee'])
    # And also make sure that the internal mapping will only query details of 8913
    makerdao_vaults = rotki.chain_manager.get_module('makerdao_vaults')
    makerdao_vaults.vault_mappings = {ethereum_accounts[0]: [vault_8913]}

    response = requests.get(
        api_url_for(
            rotkehlchen_api_server,
            "makerdaovaultdetailsresource",
        ))
    vault_8913_details = {
        'identifier':
        8913,
        'collateral_asset':
        'WBTC',
        'creation_ts':
        1588664698,
        'total_interest_owed':
        '0.1903819198',
        'total_liquidated': {
            'amount': '0',
            'usd_value': '0',
        },
        'events': [{
            'event_type':
            'deposit',
            'value': {
                'amount': '0.011',
                'usd_value': '87.06599',
            },
            'timestamp':
            1588664698,
            'tx_hash':
            '0x9ba4a6187fa2c49ba327e7c923846a08a1e972017ec41d3f9f66ef524f7dde59',
        }, {
            'event_type':
            'generate',
            'value': {
                'amount': '25',
                'usd_value': '25.15',
            },
            'timestamp':
            1588664698,
            'tx_hash':
            '0x9ba4a6187fa2c49ba327e7c923846a08a1e972017ec41d3f9f66ef524f7dde59',
        }, {
            'event_type':
            'payback',
            'value': {
                'amount': '25.000248996',
                'usd_value': '25.15025',
            },
            'timestamp':
            1588696496,
            'tx_hash':
            '0x8bd960e7eb8b9e2b81d2446d1844dd63f94636c7800ea5e3b4d926ea0244c66c',
        }, {
            'event_type':
            'deposit',
            'value': {
                'amount': '0.0113',
                'usd_value': '89.440517',
            },
            'timestamp':
            1588720248,
            'tx_hash':
            '0x678c4da562173c102473f1904ff293a767ebac9ec6c7d728ef2fd41acf00a13a',
        }],  # way too many events in the vault, so no need to check them all
    }
    details = assert_proper_response_with_result(response)
    assert len(details) == 1
    assert_serialized_dicts_equal(
        details[0],
        vault_8913_details,
        # Checking only the first 4 events
        length_list_keymap={'events': 4},
    )
示例#5
0
def test_defi_event_zero_amount(accountant):
    """Test that if a Defi Event with a zero amount obtained
    comes in we don't raise an error

    Regression test for a division by zero error a user reported
    """
    defi_events = [
        DefiEvent(
            timestamp=1467279735,
            wrapped_event=AaveInterestEvent(
                event_type='interest',
                asset=A_WBTC,
                value=Balance(amount=FVal(0), usd_value=FVal(0)),
                block_number=4,
                timestamp=Timestamp(1467279735),
                tx_hash=
                '0x49c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
                log_index=4,
            ),
            event_type=DefiEventType.AAVE_EVENT,
            got_asset=A_WBTC,
            got_balance=Balance(amount=FVal(0), usd_value=FVal(0)),
            spent_asset=A_WBTC,
            spent_balance=Balance(amount=FVal(0), usd_value=FVal(0)),
            pnl=[
                AssetBalance(asset=A_WBTC,
                             balance=Balance(amount=FVal(0),
                                             usd_value=FVal(0)))
            ],
            count_spent_got_cost_basis=True,
            tx_hash=
            '0x49c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',
        )
    ]
    _, events = accounting_history_process(
        accountant=accountant,
        start_ts=1466979735,
        end_ts=1519693374,
        history_list=[],
        defi_events_list=defi_events,
    )
    assert_serialized_dicts_equal(
        events[0],
        {
            'cost_basis': None,
            'is_virtual': False,
            'location': 'blockchain',
            'net_profit_or_loss': ZERO,
            'paid_asset': '_ceth_0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599',
            'paid_in_asset': ZERO,
            'paid_in_profit_currency': ZERO,
            'received_asset': '',
            'received_in_asset': ZERO,
            'taxable_amount': ZERO,
            'taxable_bought_cost_in_profit_currency': ZERO,
            'taxable_received_in_profit_currency': ZERO,
            'time': 1467279735,
            'type': 'defi_event',
            'link':
            'https://etherscan.io/tx/0x49c67445d26679623f9b7d56a8be260a275cb6744a1c1ae5a8d6883a5a5c03de',  # noqa: E501
            'notes': '',
        })