From 9d5cee9239e3f9d10a2c243611317b024e9b6093 Mon Sep 17 00:00:00 2001 From: Jakub Vins Date: Thu, 10 Sep 2026 16:41:09 +0200 Subject: [PATCH] Fix DeBank portfolio asset type mappings --- .../debank/test_debank_portfolio_parser.py | 45 +++++++++++++++++++ blockapi/v2/api/debank.py | 9 +++- blockapi/v2/api/debank_maps.py | 10 ++++- 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/blockapi/test/v2/api/debank/test_debank_portfolio_parser.py b/blockapi/test/v2/api/debank/test_debank_portfolio_parser.py index 90e9dab1..cd4b48a6 100644 --- a/blockapi/test/v2/api/debank/test_debank_portfolio_parser.py +++ b/blockapi/test/v2/api/debank/test_debank_portfolio_parser.py @@ -88,6 +88,51 @@ def test_parse_asset_type_liquidity_pool(portfolio_parser): ) +@pytest.mark.parametrize( + ('debank_type', 'asset_type'), + [ + ('Airdrop', AssetType.CLAIMABLE), + ('Leveraged Farming', AssetType.FARMING), + ('NFT Fraction', AssetType.LOCKED), + ('NFT Staked', AssetType.STAKED), + ], +) +def test_parse_debank_asset_type_aliases(portfolio_parser, debank_type, asset_type): + assert portfolio_parser._parse_asset_type(debank_type) == asset_type + + +def test_parse_leveraged_farming_borrow_as_debt(portfolio_parser, portfolio_response): + portfolio_item = portfolio_response['portfolio_item_list'][0] + portfolio_item['name'] = 'Leveraged Farming' + portfolio_item['detail_types'] = ['leveraged_farming'] + portfolio_response['portfolio_item_list'] = [portfolio_item] + + items = portfolio_parser.parse([portfolio_response])[0].items + + assert [item.asset_type for item in items] == [ + AssetType.FARMING, + AssetType.DEBT, + AssetType.DEBT, + AssetType.DEBT, + ] + + +def test_parse_nft_staked_rewards_as_rewards(portfolio_parser, portfolio_response): + portfolio_item = portfolio_response['portfolio_item_list'][0] + reward_token = portfolio_item['detail']['supply_token_list'][0] + portfolio_item['name'] = 'NFT Staked' + portfolio_item['detail_types'] = ['nft_common'] + portfolio_item['detail'] = { + 'reward_token_list': [reward_token], + 'supply_nft_list': [{'id': 'ignored-by-current-parser'}], + } + portfolio_response['portfolio_item_list'] = [portfolio_item] + + items = portfolio_parser.parse([portfolio_response])[0].items + + assert [item.asset_type for item in items] == [AssetType.REWARDS] + + def test_parse_unknown_asset_type_logs(portfolio_parser, caplog): expected_log = ["'dummy' is not a valid AssetType"] with caplog.at_level(level=logging.DEBUG): diff --git a/blockapi/v2/api/debank.py b/blockapi/v2/api/debank.py index fea68d16..548c5742 100644 --- a/blockapi/v2/api/debank.py +++ b/blockapi/v2/api/debank.py @@ -14,6 +14,7 @@ COINGECKO_IDS_BY_CONTRACTS, DEBANK_APP_CHAIN_MAP, DEBANK_ASSET_TYPES, + DEBANK_BORROW_ASSET_TYPES, NATIVE_COIN_MAP, REWARD_ASSET_TYPE_MAP, ) @@ -486,7 +487,7 @@ def _parse_portfolio_item( def _parse_balances(self, detail, item, pool_info) -> Iterable[BalanceItem]: asset_type = self._parse_asset_type(item.name) - borrow_type = self._get_borrow_asset_type(asset_type) + borrow_type = self._get_borrow_asset_type(item.name, asset_type) reward_type = self._get_reward_asset_type(asset_type) exclude = set() @@ -585,7 +586,11 @@ def _parse_asset_type(type_: str) -> Optional[AssetType]: return AssetType.LOCKED @staticmethod - def _get_borrow_asset_type(asset_type): + def _get_borrow_asset_type(debank_type: str, asset_type: AssetType): + mapped_type = DEBANK_BORROW_ASSET_TYPES.get(debank_type.lower()) + if mapped_type: + return mapped_type + if asset_type == AssetType.LENDING: return AssetType.LENDING_BORROW diff --git a/blockapi/v2/api/debank_maps.py b/blockapi/v2/api/debank_maps.py index 952e8e48..6fdf10d5 100644 --- a/blockapi/v2/api/debank_maps.py +++ b/blockapi/v2/api/debank_maps.py @@ -9,9 +9,17 @@ ) DEBANK_ASSET_TYPES = { + 'airdrop': AssetType.CLAIMABLE, 'deposit': AssetType.DEPOSITED, - 'vested': AssetType.VESTING, + 'leveraged farming': AssetType.FARMING, 'liquidity pool': AssetType.LIQUIDITY_POOL, + 'nft fraction': AssetType.LOCKED, + 'nft staked': AssetType.STAKED, + 'vested': AssetType.VESTING, +} + +DEBANK_BORROW_ASSET_TYPES = { + 'leveraged farming': AssetType.DEBT, } REWARD_ASSET_TYPE_MAP = {