Beispiel #1
0
def _handle_pooltogether(normalized_balance: FVal,
                         token_name: str) -> Optional[DefiBalance]:
    """Special handling for pooltogether

    https://github.com/rotki/rotki/issues/1429
    """
    if 'DAI' in token_name:
        dai_price = Inquirer.find_usd_price(A_DAI)
        return DefiBalance(
            token_address=to_checksum_address(
                '0x49d716DFe60b37379010A75329ae09428f17118d'),
            token_name='Pool Together DAI token',
            token_symbol='plDAI',
            balance=Balance(
                amount=normalized_balance,
                usd_value=normalized_balance * dai_price,
            ),
        )
    if 'USDC' in token_name:
        usdc_price = Inquirer.find_usd_price(A_USDC)
        return DefiBalance(
            token_address=to_checksum_address(
                '0xBD87447F48ad729C5c4b8bcb503e1395F62e8B98'),
            token_name='Pool Together USDC token',
            token_symbol='plUSDC',
            balance=Balance(
                amount=normalized_balance,
                usd_value=normalized_balance * usdc_price,
            ),
        )
    # else
    return None
Beispiel #2
0
def get_usd_price_zero_if_error(
    asset: Asset,
    time: Timestamp,
    location: str,
    msg_aggregator: MessagesAggregator,
) -> Price:
    """A special version of query_usd_price_zero_if_error using current price instead
    of historical token price for some assets.

    Since these assets are not supported by our price oracles we derive current
    price from the chain but without an archive node can't query old prices.

    TODO: MAke an issue about this
    This can be solved when we have an archive node.
    """
    inquirer = Inquirer()
    if asset in inquirer.special_tokens:
        return inquirer.find_usd_price(asset)

    return query_usd_price_zero_if_error(
        asset=asset,
        time=time,
        location=location,
        msg_aggregator=msg_aggregator,
    )
Beispiel #3
0
def create_inquirer(data_directory, should_mock_current_price_queries,
                    mocked_prices) -> Inquirer:
    # Since this is a singleton and we want it initialized everytime the fixture
    # is called make sure its instance is always starting from scratch
    Inquirer._Inquirer__instance = None  # type: ignore
    # Get a cryptocompare without a DB since invoking DB fixture here causes problems
    # of existing user for some tests
    cryptocompare = Cryptocompare(data_directory=data_directory, database=None)
    gecko = Coingecko(data_directory=data_directory)
    inquirer = Inquirer(data_dir=data_directory,
                        cryptocompare=cryptocompare,
                        coingecko=gecko)
    if not should_mock_current_price_queries:
        return inquirer

    def mock_find_usd_price(asset):  # pylint: disable=unused-argument
        return mocked_prices.get(asset, FVal('1.5'))

    inquirer.find_usd_price = mock_find_usd_price  # type: ignore

    def mock_query_fiat_pair(base, quote):  # pylint: disable=unused-argument
        return FVal(1)

    inquirer.query_fiat_pair = mock_query_fiat_pair  # type: ignore

    return inquirer
Beispiel #4
0
    def get_account_nfts(self, account: ChecksumEthAddress) -> List[NFT]:
        """May raise RemoteError"""
        offset = 0
        options = {'order_direction': 'desc', 'offset': offset, 'limit': ASSETS_MAX_LIMIT, 'owner': account}  # noqa: E501
        eth_usd_price = Inquirer.find_usd_price(A_ETH)

        raw_result = []
        while True:
            result = self._query(endpoint='assets', options=options)
            raw_result.extend(result['assets'])  # pylint: disable=unsubscriptable-object
            if len(result['assets']) != ASSETS_MAX_LIMIT:  # pylint: disable=unsubscriptable-object
                break

            # else continue by paginating
            offset += ASSETS_MAX_LIMIT
            options['offset'] = offset

        nfts = []
        for entry in raw_result:
            try:
                nfts.append(self._deserialize_nft(
                    entry=entry,
                    owner_address=account,
                    eth_usd_price=eth_usd_price,
                ))
            except (UnknownAsset, DeserializationError) as e:
                self.msg_aggregator.add_warning(
                    f'Skipping detected NFT for {account} due to {str(e)}. '
                    f'Check out logs for more details',
                )
                log.warning(
                    f'Skipping detected NFT for {account} due to {str(e)}. '
                    f'Problematic entry: {entry} ',
                )

        return nfts
Beispiel #5
0
def create_inquirer(
    data_directory,
    should_mock_current_price_queries,
    mocked_prices,
    current_price_oracles_order,
    ethereum_manager,
    ignore_mocked_prices_for=None,
) -> Inquirer:
    # Since this is a singleton and we want it initialized everytime the fixture
    # is called make sure its instance is always starting from scratch
    Inquirer._Inquirer__instance = None  # type: ignore
    # Get a cryptocompare without a DB since invoking DB fixture here causes problems
    # of existing user for some tests
    cryptocompare = Cryptocompare(data_directory=data_directory, database=None)
    gecko = Coingecko()
    inquirer = Inquirer(
        data_dir=data_directory,
        cryptocompare=cryptocompare,
        coingecko=gecko,
    )
    if ethereum_manager is not None:
        inquirer.inject_ethereum(ethereum_manager)
        uniswap_v2_oracle = UniswapV2Oracle(ethereum_manager)
        uniswap_v3_oracle = UniswapV3Oracle(ethereum_manager)
        saddle_oracle = SaddleOracle(ethereum_manager)
        Inquirer().add_defi_oracles(
            uniswap_v2=uniswap_v2_oracle,
            uniswap_v3=uniswap_v3_oracle,
            saddle=saddle_oracle,
        )
    inquirer.set_oracles_order(current_price_oracles_order)

    if not should_mock_current_price_queries:
        return inquirer

    def mock_find_price(
            from_asset,
            to_asset,
            ignore_cache: bool = False,  # pylint: disable=unused-argument
    ):
        return mocked_prices.get((from_asset, to_asset), FVal('1.5'))

    def mock_find_usd_price(asset, ignore_cache: bool = False):  # pylint: disable=unused-argument
        return mocked_prices.get(asset, FVal('1.5'))

    if ignore_mocked_prices_for is None:
        inquirer.find_price = mock_find_price  # type: ignore
        inquirer.find_usd_price = mock_find_usd_price  # type: ignore
    else:

        def mock_some_prices(from_asset, to_asset, ignore_cache=False):
            if from_asset.symbol in ignore_mocked_prices_for:
                return inquirer.find_price_old(from_asset, to_asset,
                                               ignore_cache)
            return mock_find_price(from_asset, to_asset, ignore_cache)

        def mock_some_usd_prices(asset, ignore_cache=False):
            if asset.symbol in ignore_mocked_prices_for:
                return inquirer.find_usd_price_old(asset, ignore_cache)
            return mock_find_usd_price(asset, ignore_cache)

        inquirer.find_price_old = inquirer.find_price  # type: ignore
        inquirer.find_usd_price_old = inquirer.find_usd_price  # type: ignore
        inquirer.find_price = mock_some_prices  # type: ignore
        inquirer.find_usd_price = mock_some_usd_prices  # type: ignore

    def mock_query_fiat_pair(base, quote):  # pylint: disable=unused-argument
        return FVal(1)

    inquirer._query_fiat_pair = mock_query_fiat_pair  # type: ignore

    return inquirer