39
39
convert_list_to_models ,
40
40
convert_to_model ,
41
41
)
42
+ from .svm import SVMTokenAPI
42
43
from .types import (
43
44
Interval ,
44
45
NetworkId ,
55
56
class NFTWrapper :
56
57
"""NFT-specific methods wrapper for EVM chains."""
57
58
58
- def __init__ (self , api_instance ) :
59
+ def __init__ (self , api_instance : "TokenAPI" ) -> None :
59
60
self ._api = api_instance
60
61
61
62
async def ownerships (
@@ -90,13 +91,11 @@ async def activities(
90
91
91
92
async def item (self , contract : str , token_id : str , network : NetworkId | str | None = None ) -> list [dict [str , Any ]]:
92
93
"""Get specific NFT item metadata by contract and token ID."""
93
- data = await self ._api ._evm_nft_item (contract = contract , token_id = token_id , network = network )
94
- return data .get ("items" , []) if data else []
94
+ return await self ._api ._evm_nft_item (contract = contract , token_id = token_id , network = network )
95
95
96
96
async def holders (self , contract : str , network : NetworkId | str | None = None ) -> list [dict [str , Any ]]:
97
97
"""Get NFT holders for a contract."""
98
- data = await self ._api ._evm_nft_holders (contract = contract , network = network )
99
- return data .get ("holders" , []) if data else []
98
+ return await self ._api ._evm_nft_holders (contract = contract , network = network )
100
99
101
100
async def sales (
102
101
self ,
@@ -106,14 +105,13 @@ async def sales(
106
105
network : NetworkId | str | None = None ,
107
106
) -> list [dict [str , Any ]]:
108
107
"""Get NFT marketplace sales."""
109
- data = await self ._api ._evm_nft_sales (contract = contract , token_id = token_id , limit = limit , network = network )
110
- return data .get ("sales" , []) if data else []
108
+ return await self ._api ._evm_nft_sales (contract = contract , token_id = token_id , limit = limit , network = network )
111
109
112
110
113
111
class EVMWrapper :
114
112
"""EVM-specific methods wrapper."""
115
113
116
- def __init__ (self , api_instance ) :
114
+ def __init__ (self , api_instance : "TokenAPI" ) -> None :
117
115
self ._api = api_instance
118
116
119
117
# Initialize nested NFT wrapper
@@ -135,10 +133,9 @@ async def historical_balances(
135
133
network : NetworkId | str | None = None ,
136
134
) -> list [dict [str , Any ]]:
137
135
"""Get historical balance data for EVM addresses."""
138
- data = await self ._api ._evm_historical_balances (
136
+ return await self ._api ._evm_historical_balances (
139
137
address = address , contracts = contracts , interval = interval , limit = limit , network = network
140
138
)
141
- return data .get ("balances" , []) if data else []
142
139
143
140
async def token_info (self , contract : str , network : NetworkId | str | None = None ) -> Token | None :
144
141
"""Get EVM token contract information."""
@@ -251,7 +248,7 @@ async def token_holders(
251
248
class SVMWrapper :
252
249
"""SVM-specific methods wrapper."""
253
250
254
- def __init__ (self , api_instance ) :
251
+ def __init__ (self , api_instance : "TokenAPI" ) -> None :
255
252
self ._api = api_instance
256
253
257
254
async def swaps (
@@ -354,7 +351,7 @@ async def get_sol_price(
354
351
print(f"Price: ${stats['price']:.2f} (confidence: {stats['confidence']:.0%})")
355
352
```
356
353
"""
357
- return await self ._api ._svm_get_sol_price (include_stats = include_stats , network = network ) # type: ignore[no-any-return]
354
+ return await self ._api ._svm_get_sol_price (include_stats = include_stats , network = network )
358
355
359
356
360
357
class TokenAPI :
@@ -421,7 +418,7 @@ def __init__(
421
418
self .evm = EVMWrapper (self )
422
419
self .svm = SVMWrapper (self )
423
420
424
- def _extract_data (self , response ) -> list [dict [Any , Any ]]:
421
+ def _extract_data (self , response : Any ) -> list [dict [str , Any ]]:
425
422
"""Extract clean data from API response."""
426
423
if hasattr (response , "data" ) and isinstance (response .data , dict ):
427
424
data = response .data .get ("data" , [])
@@ -430,7 +427,7 @@ def _extract_data(self, response) -> list[dict[Any, Any]]:
430
427
431
428
async def _call_evm_method (
432
429
self , method_name : str , network : NetworkId | str | None = None , ** kwargs : Any
433
- ) -> list [dict ]:
430
+ ) -> list [dict [ str , Any ] ]:
434
431
"""Generic EVM method delegation helper."""
435
432
net = str (network ) if network else self ._default_network
436
433
async with self ._api .evm (net ) as client :
@@ -440,14 +437,14 @@ async def _call_evm_method(
440
437
441
438
async def _call_evm_method_single (
442
439
self , method_name : str , network : NetworkId | str | None = None , ** kwargs : Any
443
- ) -> dict | None :
440
+ ) -> dict [ str , Any ] | None :
444
441
"""Generic EVM method delegation helper that returns single result."""
445
442
data = await self ._call_evm_method (method_name , network , ** kwargs )
446
443
return data [0 ] if data else None
447
444
448
445
async def _call_svm_method (
449
446
self , method_name : str , network : SolanaNetworkId | str = SolanaNetworkId .SOLANA , ** kwargs : Any
450
- ) -> list [dict ]:
447
+ ) -> list [dict [ str , Any ] ]:
451
448
"""Generic SVM method delegation helper."""
452
449
async with self ._api .svm (str (network )) as client :
453
450
method = getattr (client , method_name )
@@ -471,7 +468,7 @@ async def _call_svm_method_direct(
471
468
472
469
async def _evm_balances (
473
470
self , address : str , contract : str | None = None , limit : int = 10 , network : NetworkId | str | None = None
474
- ) -> list [dict ]:
471
+ ) -> list [dict [ str , Any ] ]:
475
472
"""Internal EVM balances implementation."""
476
473
return await self ._call_evm_method ("get_balances" , network , address = address , contract = contract , limit = limit )
477
474
@@ -481,13 +478,13 @@ async def _evm_nfts(
481
478
token_standard : TokenStandard | str | None = None ,
482
479
limit : int = 10 ,
483
480
network : NetworkId | str | None = None ,
484
- ) -> list [dict ]:
481
+ ) -> list [dict [ str , Any ] ]:
485
482
"""Internal EVM NFTs implementation."""
486
483
return await self ._call_evm_method (
487
484
"get_nft_ownerships" , network , address = address , token_standard = token_standard , limit = limit
488
485
)
489
486
490
- async def _evm_token_info (self , contract : str , network : NetworkId | str | None = None ) -> dict | None :
487
+ async def _evm_token_info (self , contract : str , network : NetworkId | str | None = None ) -> dict [ str , Any ] | None :
491
488
"""Internal EVM token info implementation."""
492
489
return await self ._call_evm_method_single ("get_token" , network , contract = contract )
493
490
@@ -498,7 +495,7 @@ async def _evm_transfers(
498
495
contract : str | None = None ,
499
496
limit : int = 10 ,
500
497
network : NetworkId | str | None = None ,
501
- ) -> list [dict ]:
498
+ ) -> list [dict [ str , Any ] ]:
502
499
"""Internal EVM transfers implementation."""
503
500
return await self ._call_evm_method (
504
501
"get_transfers" , network , from_address = from_address , to_address = to_address , contract = contract , limit = limit
@@ -510,7 +507,7 @@ async def _evm_swaps(
510
507
protocol : Protocol | str | None = None ,
511
508
limit : int = 10 ,
512
509
network : NetworkId | str | None = None ,
513
- ) -> list [dict ]:
510
+ ) -> list [dict [ str , Any ] ]:
514
511
"""Internal EVM swaps implementation."""
515
512
return await self ._call_evm_method ("get_swaps" , network , pool = pool , protocol = protocol , limit = limit )
516
513
@@ -528,7 +525,7 @@ async def _evm_swaps_advanced(
528
525
order_direction : OrderDirection | str = OrderDirection .DESC ,
529
526
limit : int = 10 ,
530
527
network : NetworkId | str | None = None ,
531
- ) -> list [dict ]:
528
+ ) -> list [dict [ str , Any ] ]:
532
529
"""Internal EVM advanced swaps implementation."""
533
530
return await self ._call_evm_method (
534
531
"get_swaps" ,
@@ -546,7 +543,7 @@ async def _evm_swaps_advanced(
546
543
limit = limit ,
547
544
)
548
545
549
- async def _evm_nft_collection (self , contract : str , network : NetworkId | str | None = None ) -> dict | None :
546
+ async def _evm_nft_collection (self , contract : str , network : NetworkId | str | None = None ) -> dict [ str , Any ] | None :
550
547
"""Internal EVM NFT collection implementation."""
551
548
return await self ._call_evm_method_single ("get_nft_collection" , network , contract = contract )
552
549
@@ -557,7 +554,7 @@ async def _evm_nft_activities(
557
554
to_address : str | None = None ,
558
555
limit : int = 10 ,
559
556
network : NetworkId | str | None = None ,
560
- ) -> list [dict ]:
557
+ ) -> list [dict [ str , Any ] ]:
561
558
"""Internal EVM NFT activities implementation."""
562
559
return await self ._call_evm_method (
563
560
"get_nft_activities" ,
@@ -570,7 +567,7 @@ async def _evm_nft_activities(
570
567
571
568
async def _evm_nft_item (
572
569
self , contract : str , token_id : str , network : NetworkId | str | None = None
573
- ) -> list [dict [Any , Any ]]:
570
+ ) -> list [dict [str , Any ]]:
574
571
"""Internal EVM NFT item implementation."""
575
572
return await self ._call_evm_method ("get_nft_item" , network , contract = contract , token_id = token_id )
576
573
@@ -584,7 +581,7 @@ async def _evm_nft_sales(
584
581
token_id : str | None = None ,
585
582
limit : int = 10 ,
586
583
network : NetworkId | str | None = None ,
587
- ) -> list [dict [Any , Any ]]:
584
+ ) -> list [dict [str , Any ]]:
588
585
"""Internal EVM NFT sales implementation."""
589
586
return await self ._call_evm_method ("get_nft_sales" , network , contract = contract , token_id = token_id , limit = limit )
590
587
@@ -595,7 +592,7 @@ async def _evm_historical_balances(
595
592
interval : Interval | str = Interval .ONE_DAY ,
596
593
limit : int = 10 ,
597
594
network : NetworkId | str | None = None ,
598
- ) -> list [dict [Any , Any ]]:
595
+ ) -> list [dict [str , Any ]]:
599
596
"""Internal EVM historical balances implementation."""
600
597
return await self ._call_evm_method (
601
598
"get_historical_balances" , network , address = address , contracts = contracts , interval = interval , limit = limit
@@ -608,7 +605,7 @@ async def _evm_pools(
608
605
protocol : Protocol | str | None = None ,
609
606
limit : int = 10 ,
610
607
network : NetworkId | str | None = None ,
611
- ) -> list [dict ]:
608
+ ) -> list [dict [ str , Any ] ]:
612
609
"""Internal EVM pools implementation."""
613
610
return await self ._call_evm_method ("get_pools" , network , pool = pool , token = token , protocol = protocol , limit = limit )
614
611
@@ -619,7 +616,7 @@ async def _evm_price_history(
619
616
days : int = 1 ,
620
617
limit : int = 24 ,
621
618
network : NetworkId | str | None = None ,
622
- ) -> list [dict ]:
619
+ ) -> list [dict [ str , Any ] ]:
623
620
"""Internal EVM price history implementation."""
624
621
start_time = int ((datetime .now () - timedelta (days = days )).timestamp ())
625
622
return await self ._call_evm_method (
@@ -633,7 +630,7 @@ async def _evm_pool_history(
633
630
days : int = 1 ,
634
631
limit : int = 24 ,
635
632
network : NetworkId | str | None = None ,
636
- ) -> list [dict ]:
633
+ ) -> list [dict [ str , Any ] ]:
637
634
"""Internal EVM pool history implementation."""
638
635
start_time = int ((datetime .now () - timedelta (days = days )).timestamp ())
639
636
return await self ._call_evm_method (
@@ -642,7 +639,7 @@ async def _evm_pool_history(
642
639
643
640
async def _evm_token_holders (
644
641
self , contract : str , limit : int = 10 , network : NetworkId | str | None = None
645
- ) -> list [dict ]:
642
+ ) -> list [dict [ str , Any ] ]:
646
643
"""Internal EVM token holders implementation."""
647
644
return await self ._call_evm_method ("get_token_holders" , network , contract = contract , limit = limit )
648
645
@@ -655,7 +652,7 @@ async def _svm_balances(
655
652
program_id : SolanaPrograms | str | None = None ,
656
653
limit : int = 10 ,
657
654
network : SolanaNetworkId | str = SolanaNetworkId .SOLANA ,
658
- ) -> list [dict ]:
655
+ ) -> list [dict [ str , Any ] ]:
659
656
"""Internal SVM balances implementation."""
660
657
return await self ._call_svm_method (
661
658
"get_balances" , network , token_account = token_account , mint = mint , program_id = program_id , limit = limit
@@ -671,7 +668,7 @@ async def _svm_transfers(
671
668
destination : str | None = None ,
672
669
limit : int = 10 ,
673
670
network : SolanaNetworkId | str = SolanaNetworkId .SOLANA ,
674
- ) -> list [dict ]:
671
+ ) -> list [dict [ str , Any ] ]:
675
672
"""Internal SVM transfers implementation."""
676
673
return await self ._call_svm_method (
677
674
"get_transfers" ,
@@ -698,7 +695,7 @@ async def _svm_swaps(
698
695
end_time : int | None = None ,
699
696
limit : int = 10 ,
700
697
network : SolanaNetworkId | str = SolanaNetworkId .SOLANA ,
701
- ) -> list [dict ]:
698
+ ) -> list [dict [ str , Any ] ]:
702
699
"""Internal SVM swaps implementation."""
703
700
return await self ._call_svm_method (
704
701
"get_swaps" ,
@@ -721,7 +718,9 @@ async def _svm_get_sol_price(
721
718
network : SolanaNetworkId | str = SolanaNetworkId .SOLANA ,
722
719
) -> float | dict [str , Any ] | None :
723
720
"""Internal SVM SOL price implementation."""
724
- return await self ._call_svm_method_direct ("get_sol_price" , network , include_stats = include_stats ) # type: ignore[no-any-return]
721
+ # Direct API call to avoid circular dependency
722
+ async with SVMTokenAPI (self ._api .api_key or "" , str (network ), self ._api .base_url ) as client :
723
+ return await client ._get_sol_price_internal (include_stats = include_stats ) # type: ignore[no-any-return,attr-defined]
725
724
726
725
# ===== Utility Methods =====
727
726
0 commit comments