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
5 changes: 5 additions & 0 deletions blockapi/test/v2/api/debank/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def mist_response() -> List:
return read_json_file("debank/data/mist_response.json")


@pytest.fixture
def unknown_chain_response() -> dict:
return read_json_file('debank/data/unknown_chain_response.json')


@pytest.fixture
def debank_usage_response() -> dict:
return read_json_file('debank/data/usage_response.json')
Expand Down
51 changes: 51 additions & 0 deletions blockapi/test/v2/api/debank/data/unknown_chain_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": "avax_traderjoexyz_lending",
"chain": "this-chain-will-never-exist",
"name": "Trader Joe Lending",
"site_url": "https://www.traderjoexyz.com",
"logo_url": "https://static.debank.com/image/project/logo_url/avax_traderjoexyz_lending/eab9fd6fb47852d3b7766515bfefe366.png",
"has_supported_portfolio": true,
"tvl": 162476998.75607753,
"portfolio_item_list": [
{
"stats": {
"asset_usd_value": 547045.4515305705,
"debt_usd_value": 0,
"net_usd_value": 547045.4515305705
},
"update_at": 1650963061.376993,
"name": "Lending",
"pool_id": "0xdc13687554205e5b89ac783db14bb5bba4a1edac",
"detail_types": [
"lending"
],
"detail": {
"supply_token_list": [
{
"id": "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7",
"chain": "avax",
"name": "Wrapped AVAX",
"symbol": "WAVAX",
"display_symbol": "WAVAX",
"optimized_symbol": "WAVAX",
"decimals": 18,
"logo_url": "https://static.debank.com/image/avax_token/logo_url/0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7/753d82f0137617110f8dec56309b4065.png",
"protocol_id": "avax_gmx",
"price": 72.17,
"is_verified": true,
"is_core": true,
"is_wallet": true,
"time_at": 1607728259,
"amount": 7579.956374263135,
"is_collateral": false
}
],
"borrow_token_list": [],
"health_rate": null
},
"proxy_detail": {}
}
]
}
]
5 changes: 5 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 @@ -140,3 +140,8 @@ def test_require_pool_or_pool_id():
DebankModelPortfolioItem(
name='portfolio', detail=detail, pool=None, pool_id=None
)


def test_portfolio_with_unknown_chain(portfolio_parser, unknown_chain_response):
parsed = portfolio_parser.parse(unknown_chain_response)
assert parsed == []
5 changes: 4 additions & 1 deletion blockapi/v2/api/debank.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def parse(self, response: List) -> Dict[str, Protocol]:
def parse_item(item: DebankModelProtocol) -> Optional[Protocol]:
blockchain = get_blockchain_from_debank_chain(item.chain)
if not blockchain:
logger.warning(f'No blockchain found for protocol {item.id}')
logger.warning(f'No blockchain found for protocol {item.id}. Skipping.')
return None

return Protocol.from_api(
Expand Down Expand Up @@ -349,6 +349,9 @@ def parse(self, response: List) -> List[Pool]:

def parse_items(self, raw_portfolio: DebankModelPortfolio) -> List[Pool]:
root_protocol = self._protocol_parser.parse_item(raw_portfolio)
if not root_protocol:
return []

pools = self._parse_portfolio_item_list(
raw_portfolio.portfolio_item_list or [], root_protocol
)
Expand Down