Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions blockapi/test/v2/api/debank/test_debank_portfolio_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions blockapi/v2/api/debank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion blockapi/v2/api/debank_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading