-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Added support for fetchin apps from debank #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vinsho
wants to merge
2
commits into
master
Choose a base branch
from
feat/debank-polymarket-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "python.testing.pytestEnabled": true | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| from decimal import Decimal | ||
|
|
||
| import pytest | ||
|
|
||
| from blockapi.v2.api.debank import ( | ||
| DebankApp, | ||
| DebankAppDeposit, | ||
| DebankPrediction, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def polymarket_response(): | ||
| """Sample response from get_complex_app_list for Polymarket.""" | ||
| return [ | ||
| { | ||
| "id": "polymarket", | ||
| "name": "Polymarket", | ||
| "site_url": "https://polymarket.com/", | ||
| "logo_url": "https://static.debank.com/image/project/logo_url/app_polymarket/265aca8cef9212e094ef24c71a01c175.png", | ||
| "has_supported_portfolio": True, | ||
| "portfolio_item_list": [ | ||
| { | ||
| "stats": { | ||
| "asset_usd_value": 290915.13432776055, | ||
| "debt_usd_value": 0, | ||
| "net_usd_value": 290915.13432776055, | ||
| }, | ||
| "asset_dict": {"be0eecf639f4e6a57e375123e46ed7b4": 290595.12768}, | ||
| "asset_token_list": [ | ||
| { | ||
| "id": "be0eecf639f4e6a57e375123e46ed7b4", | ||
| "name": "USDC", | ||
| "symbol": "USDC", | ||
| "decimals": 6, | ||
| "logo_url": "https://static.debank.com/image/app_token/logo_url/polymarket/fc98c076b66fa798bcd8755cd859032e.png", | ||
| "app_id": "polymarket", | ||
| "price": 1.0011012113324658, | ||
| "amount": 290595.12768, | ||
| } | ||
| ], | ||
| "update_at": 1768998504.1334498, | ||
| "name": "Deposit", | ||
| "detail_types": ["common"], | ||
| "detail": { | ||
| "supply_token_list": [ | ||
| { | ||
| "id": "be0eecf639f4e6a57e375123e46ed7b4", | ||
| "name": "USDC", | ||
| "symbol": "USDC", | ||
| "decimals": 6, | ||
| "logo_url": "https://static.debank.com/image/app_token/logo_url/polymarket/fc98c076b66fa798bcd8755cd859032e.png", | ||
| "app_id": "polymarket", | ||
| "price": 1.0011012113324658, | ||
| "amount": 290595.12768, | ||
| } | ||
| ] | ||
| }, | ||
| "proxy_detail": {}, | ||
| "position_index": "cash_0x5c23dead9ecf271448411096f349133e0bb9c465", | ||
| }, | ||
| { | ||
| "stats": { | ||
| "asset_usd_value": 27068.1993, | ||
| "debt_usd_value": 0, | ||
| "net_usd_value": 27068.1993, | ||
| }, | ||
| "asset_dict": {}, | ||
| "asset_token_list": [], | ||
| "update_at": 1768998504.1336002, | ||
| "name": "Prediction", | ||
| "detail_types": ["prediction"], | ||
| "detail": { | ||
| "name": "Lighter market cap (FDV) >$1B one day after launch?", | ||
| "side": "Yes", | ||
| "amount": 27068.1993, | ||
| "price": 1, | ||
| "claimable": True, | ||
| "event_end_at": None, | ||
| "is_market_closed": False, | ||
| }, | ||
| "proxy_detail": {}, | ||
| "position_index": "0x5c23dead9ecf271448411096f349133e0bb9c465_108054592060808479303370270554306028883916458239782628449790057811735078958789", | ||
| }, | ||
| { | ||
| "stats": { | ||
| "asset_usd_value": 5099.9924519999995, | ||
| "debt_usd_value": 0, | ||
| "net_usd_value": 5099.9924519999995, | ||
| }, | ||
| "asset_dict": {}, | ||
| "asset_token_list": [], | ||
| "update_at": 1768998504.1336374, | ||
| "name": "Prediction", | ||
| "detail_types": ["prediction"], | ||
| "detail": { | ||
| "name": "Gensyn FDV above $600M one day after launch?", | ||
| "side": "Yes", | ||
| "amount": 19999.9704, | ||
| "price": 0.255, | ||
| "claimable": False, | ||
| "event_end_at": None, | ||
| "is_market_closed": False, | ||
| }, | ||
| "proxy_detail": {}, | ||
| "position_index": "0x5c23dead9ecf271448411096f349133e0bb9c465_101101625858935510994152869873088213062714890530116131353411379193297614599911", | ||
| }, | ||
| ], | ||
| } | ||
| ] | ||
|
|
||
|
|
||
| def test_empty_response(app_parser): | ||
| parsed_apps = app_parser.parse([]) | ||
| assert parsed_apps == [] | ||
|
|
||
|
|
||
| def test_parse_polymarket_app(app_parser, polymarket_response): | ||
| parsed_apps = app_parser.parse(polymarket_response) | ||
| assert len(parsed_apps) == 1 | ||
|
|
||
| app = parsed_apps[0] | ||
| assert isinstance(app, DebankApp) | ||
| assert app.app_id == "polymarket" | ||
| assert app.name == "Polymarket" | ||
| assert app.site_url == "https://polymarket.com/" | ||
| assert app.has_supported_portfolio is True | ||
|
|
||
|
|
||
| def test_parse_polymarket_deposits(app_parser, polymarket_response): | ||
| """Deposits should be parsed as DebankAppDeposit objects.""" | ||
| parsed_apps = app_parser.parse(polymarket_response) | ||
| app = parsed_apps[0] | ||
|
|
||
| # Should have 1 deposit | ||
| assert len(app.deposits) == 1 | ||
| deposit = app.deposits[0] | ||
|
|
||
| assert isinstance(deposit, DebankAppDeposit) | ||
| assert deposit.name == "Deposit" | ||
| assert deposit.asset_usd_value == Decimal("290915.13432776055") | ||
| assert deposit.debt_usd_value == Decimal("0") | ||
| assert deposit.net_usd_value == Decimal("290915.13432776055") | ||
| assert deposit.position_index == "cash_0x5c23dead9ecf271448411096f349133e0bb9c465" | ||
|
|
||
| # Should have 1 token (USDC) | ||
| assert len(deposit.tokens) == 1 | ||
| assert deposit.tokens[0]["symbol"] == "USDC" | ||
| assert deposit.token_symbols == ["USDC"] | ||
|
|
||
|
|
||
| def test_parse_polymarket_predictions(app_parser, polymarket_response): | ||
| """Predictions should be parsed as DebankPrediction objects.""" | ||
| parsed_apps = app_parser.parse(polymarket_response) | ||
| app = parsed_apps[0] | ||
|
|
||
| # Should have 2 predictions | ||
| assert len(app.predictions) == 2 | ||
|
|
||
| pred1 = app.predictions[0] | ||
| assert isinstance(pred1, DebankPrediction) | ||
| assert ( | ||
| pred1.prediction_name == "Lighter market cap (FDV) >$1B one day after launch?" | ||
| ) | ||
| assert pred1.side == "Yes" | ||
| assert pred1.amount == Decimal("27068.1993") | ||
| assert pred1.price == Decimal("1") | ||
| assert pred1.usd_value == Decimal("27068.1993") | ||
| assert pred1.claimable is True | ||
| assert pred1.is_market_closed is False | ||
|
|
||
| pred2 = app.predictions[1] | ||
| assert pred2.prediction_name == "Gensyn FDV above $600M one day after launch?" | ||
| assert pred2.side == "Yes" | ||
| assert pred2.amount == Decimal("19999.9704") | ||
| assert pred2.price == Decimal("0.255") | ||
| assert pred2.claimable is False | ||
|
|
||
|
|
||
| def test_parse_multiple_apps(app_parser): | ||
| """Test parsing multiple apps.""" | ||
| response = [ | ||
| { | ||
| "id": "app1", | ||
| "name": "App 1", | ||
| "has_supported_portfolio": True, | ||
| "portfolio_item_list": [ | ||
| { | ||
| "stats": { | ||
| "asset_usd_value": 100, | ||
| "debt_usd_value": 0, | ||
| "net_usd_value": 100, | ||
| }, | ||
| "name": "Prediction", | ||
| "detail_types": ["prediction"], | ||
| "detail": { | ||
| "name": "Test prediction", | ||
| "side": "Yes", | ||
| "amount": 100, | ||
| "price": 0.5, | ||
| "claimable": False, | ||
| "is_market_closed": False, | ||
| }, | ||
| "position_index": "test_position_index", | ||
| } | ||
| ], | ||
| }, | ||
| { | ||
| "id": "app2", | ||
| "name": "App 2", | ||
| "has_supported_portfolio": False, | ||
| "portfolio_item_list": [], | ||
| }, | ||
| ] | ||
|
|
||
| parsed_apps = app_parser.parse(response) | ||
| assert len(parsed_apps) == 2 | ||
| assert parsed_apps[0].app_id == "app1" | ||
| assert parsed_apps[1].app_id == "app2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.