-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmodels.py
More file actions
1408 lines (1283 loc) · 38.5 KB
/
models.py
File metadata and controls
1408 lines (1283 loc) · 38.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
from datetime import datetime
from decimal import Decimal
from enum import Enum
from typing import Dict, List, Literal, Optional, Union
import attr
from pydantic import BaseModel, Field
from blockapi.utils.datetime import parse_dt
from blockapi.utils.num import raw_to_decimals, to_decimal, to_int
UNKNOWN = 'unknown'
NFT_STANDARDS = frozenset(
{
'NFT',
'V1_NFT',
'V2_NFT',
'ProgrammableNFT',
'MplCoreAsset',
'MplCoreCollection',
}
)
class Blockchain(str, Enum):
ABSTRACT = 'abstract'
ACALA = 'acala'
AELF = 'aelf'
AI_LAYER = 'ai-layer'
AKASH = 'akash'
ALEPHIUM = 'alephium'
ALEPH_ZERO = 'aleph-zero'
ALGORAND = 'algorand'
ALIEN_X = 'alienx'
ANCIENT8 = 'ancient8'
APE = 'ape'
APECHAIN = 'apechain'
APTOS = 'aptos'
ARBITRUM = 'arbitrum'
ARBITRUM_NOVA = 'arbitrum-nova'
ARBITRUM_ONE = 'arbitrum-one'
ARCHWAY = 'archway'
ARDOR = 'ardor'
AREON = 'areon'
ASTAR = 'astar'
ASTAR_ZKEVM = 'astar-zk-evm'
AURA = 'aura'
AURA_NETWORK = 'aura-network'
AURORA = 'aurora'
AVALANCHE = 'avalanche'
AVAX_C = 'avax-c'
AXIE = 'axie'
B2 = 'b2'
BAHAMUT = 'bahamut'
BASE = 'base'
BEAM = 'beam'
BERACHAIN = 'berachain'
BEVM = 'bevm'
BIFROST = 'bifrost'
BINANCECOIN = 'binancecoin'
BINANCE_SMART_CHAIN = 'binance-smart-chain'
BITCANNA = 'bitcanna'
BITCICHAIN = 'bitcichain'
BITCOIN = 'bitcoin'
BITCOIN_CASH = 'bitcoin-cash'
BITGERT = 'bitgert'
BITKUB_CHAIN = 'bitkub-chain'
BITROCK = 'bitrock'
BITSHARES = 'bitshares'
BIT_LAYER = 'bit-layer'
BIT_TORRENT = 'bit-torrent'
BLAST = 'blast'
BLOCKNET = 'blocknet'
BNB_BEACON_CHAIN = 'bnb-beacon-chain'
BOB = 'bob'
BOBA = 'boba'
BOS = 'bos'
BOUNCE_BIT = 'bounce-bit'
CALLISTO = 'callisto'
CANTO = 'canto'
CARDANO = 'cardano'
CASPER = 'casper'
CELER_NETWORK = 'celer-network'
CELESTIA = 'celestia'
CELO = 'celo'
CHIA = 'chia'
CHIHUAHUA = 'chihuahua'
CHILIZ = 'chiliz'
CLOVER = 'clover'
CLV_PARACHAIN = 'clv-parachain'
CMP = 'cmp'
COINEX_SMART_CHAIN = 'coinex-smart-chain'
COLOSSUSXT = 'colossusxt'
COMBO = 'combo'
COMDEX = 'comdex'
CONFLUX = 'conflux'
COREUM = 'coreum'
CORE_CHAIN = 'core-chain'
COSMOS = 'cosmos'
COUNTERPARTY = 'counterparty'
CRESCENT = 'crescent'
CRONOS = 'cronos'
CRONOS_ZKEVM = 'cronos-zkevm'
CRYPTO_ORG = 'crypto-org'
CUBE = 'cube'
CYBER = 'cyber'
DARWINIA_CRAB_NETWORK = 'darwinia-crab-network'
DASH = 'dash'
DBK = 'dbk'
DEFI = 'defi'
DEFICHAIN_EVM = 'defichain-evm'
DEFIVERSE = 'defiverse'
DEFI_KINGDOMS = 'defi-kingdoms'
DEGEN = 'degen'
DERIVE = 'derive'
DEX_ALOT = 'dexalot'
DFK_CHAIN = 'dfk-chain'
DITHEREUM = 'dithereum'
DOGECHAIN = 'dogechain'
DRC_20 = 'drc-20'
DXCHAIN = 'dxchain'
DYDX = 'dydx'
DYMENSION = 'dymension'
ECHELON = 'echelon'
ELASTOS = 'elastos'
ELA_DID_SIDECHAIN = 'ela-did-sidechain'
ELROND = 'elrond'
ELYSIUM = 'elysium'
EMERALD_PARATIME = 'emerald-paratime'
EMPIRE = 'empire'
ENDURANCE = 'endurance'
ENERGI = 'energi'
ENQ_ENECUUM = 'enq-enecuum'
EOS = 'eos'
ERGO = 'ergo'
ETHEREUM = 'ethereum'
ETHEREUMPOW = 'ethereumpow'
ETHEREUM_CLASSIC = 'ethereum-classic'
ETHERLINK = 'etherlink'
EVERSCALE = 'everscale'
EVMOS = 'evmos'
EXOSAMA = 'exosama'
EXPANSE_NETWORK = 'expanse-network'
FACTOM = 'factom'
FANTOM = 'fantom'
FILECOIN = 'filecoin'
FINDORA = 'findora'
FLARE = 'flare'
FLOW = 'flow'
FON_CHAIN = 'fon-chain'
FRAXTAL = 'fraxtal'
FUNCTION_X = 'function-x'
FUSE = 'fuse'
FUSION_NETWORK = 'fusion-network'
GALA = 'gala'
GATEVM = 'gatevm'
GENESIS_L1 = 'genesis-l1'
GENESYS = 'genesys'
GNOSIS = 'gnosis'
GOCHAIN = 'gochain'
GODWOKEN = 'godwoken'
GRAPHLINQ_CHAIN = 'graphlinq-chain'
GRAVITY = 'gravity'
GRAVITY_ALPHA = 'gravity-alpha'
GRAVITY_BRIDGE = 'gravity-bridge'
HAQQ_NETWORK = 'haqq-network'
HARMONY = 'harmony'
HECO = 'heco'
HEDERA_HASHGRAPH = 'hedera-hashgraph'
HOO_SMART_CHAIN = 'hoo-smart-chain'
HORIZEN_EON = 'horizen-eon'
HUBBLE = 'hubble'
HUMANODE = 'humanode'
HUOBI_TOKEN = 'huobi-token'
HYDRA = 'hydra'
HYPEREVM = 'hyperevm'
HYPERLIQUID = 'hyperliquid'
HYPRA_NETWORK = 'hypra-network'
ICON = 'icon'
IMMUTABLE = 'immutable'
INEVM = 'inevm'
INJECTIVE = 'injective'
INTERNET_COMPUTER = 'internet-computer'
IOTA_EVM = 'iota-evm'
IOTEX = 'iotex'
IRIS = 'iris'
JUNO = 'juno'
KADENA = 'kadena'
KARAK = 'karak'
KARDIACHAIN = 'kardiachain'
KARURA = 'karura'
KASPLEX = 'kasplex'
KAVA = 'kava'
KCC = 'kcc'
KI_CHAIN = 'ki-chain'
KLAYTN_CYPRESS = 'klaytn-cypress'
KLAY_TOKEN = 'klay-token'
KOMODO = 'komodo'
KROMA = 'kroma'
KUCOIN = 'kucoin'
KUJIRA = 'kujira'
KUSAMA = 'kusama'
LAIKACHAIN = 'laikachain'
LENS = 'lens'
LIGHTLINK = 'lightlink'
LINEA = 'linea'
LISK = 'lisk'
LITECOIN = 'litecoin'
LOOT = 'loot'
LUKSO = 'lukso'
MAINNETZ = 'mainnetz'
MANTA_PACIFIC = 'manta-pacific'
MANTLE = 'mantle'
MAP_PROTOCOL = 'map-protocol'
MASSA = 'massa'
MEGAETH = 'megaeth'
MELD = 'meld'
MERLIN_CHAIN = 'merlin-chain'
METAL_L2 = 'metal-l2'
METAVERSE_ETP = 'metaverse-etp'
METER = 'meter'
METIS_ANDROMEDA = 'metis-andromeda'
MIGALOO = 'migaloo'
MILKOMEDA_C1 = 'milkomeda-c1'
MILKOMEDA_CARDANO = 'milkomeda-cardano'
MINT = 'mint'
MIXIN_NETWORK = 'mixin-network'
MODE = 'mode'
MOLTEN = 'molten'
MOONBEAM = 'moonbeam'
MOONRIVER = 'moonriver'
MORPH = 'morph'
NEAR_PROTOCOL = 'near-protocol'
NEM = 'nem'
NEO = 'neo'
NEON_EVM = 'neon-evm'
NEUTRON = 'neutron'
NOBLE = 'noble'
NULS = 'nuls'
NXT = 'nxt'
OASIS_CHAIN = 'oasis-chain'
OASIS_EMERALD = 'oasis-emerald'
OASIS_SAPPHIRE = 'oasis-sapphire'
OASYS = 'oasys'
OCTA_SPACE = 'octa-space'
OKEX_CHAIN = 'okex-chain'
OKT = 'okt'
OMAX = 'omax'
OMNI = 'omni'
OMNIFLIX = 'omniflix'
ONCHAIN = 'onchain'
ONTOLOGY = 'ontology'
ONUS_CHAIN = 'onus-chain'
OPENLEDGER = 'openledger'
OPEN_NETWORK = 'open-network'
OPTIMISM = 'optimism'
OPTIMISTIC_BNB = 'optimistic-bnb'
OPTIMISTIC_ETHEREUM = 'optimistic-ethereum'
ORAI = 'orai'
ORDERLY = 'orderly'
ORDINALS = 'ordinals'
ORENIUM = 'orenium'
OSMOSIS = 'osmosis'
PALM = 'palm'
PEGO = 'pego'
PERSISTENCE = 'persistence'
PICASSO = 'picasso'
PLAT_ON = 'plat-on'
PLASMA = 'plasma'
POLIS_CHAIN = 'polis-chain'
POLKADOT = 'polkadot'
POLYGON = 'polygon'
POLYGON_ZK_EVM = 'polygon-zkevm'
PROOF_OF_MEMES = 'proof-of-memes'
PROOF_OF_PLAY_APEX = 'proof-of-play-apex'
PULSE = 'pulse'
QL1 = 'ql1'
QTUM = 'qtum'
QUICKSILVER = 'quicksilver'
Q_MAINNET = 'q-mainnet'
RADIX = 'radix'
RAILS = 'rails'
RARI = 'rari'
REAL = 'real'
REGEN = 'regen'
REI_NETWORK = 'rei-network'
REYA = 'reya'
ROLLUX = 'rollux'
RONIN = 'ronin'
ROOTSTOCK = 'rootstock'
RSK = 'rsk'
RSS3_VSL = 'rss3-vsl'
SAAKURU = 'saakuru'
SAGA = 'saga'
SAITA = 'saita'
SANKO = 'sanko'
SATOSHI_VM_ALPHA = 'satoshi-vm-alpha'
SCROLL = 'scroll'
SECRET = 'secret'
SEED_COIN_NETWORK = 'seed-coin-network'
SEI = 'sei'
SEI_NETWORK = 'sei-network'
SEI_V2 = 'sei-v2'
SENTINEL = 'sentinel'
SGE = 'sge'
SHAPE = 'shape'
SHIBARIUM = 'shibarium'
SHIBA_CHAIN = 'shiba-chain'
SHIDEN_NETWORK = 'shiden-network'
SHIMMER_EVM = 'shimmer_evm'
SIFCHAIN = 'sifchain'
SKALE = 'skale'
SMART_BITCOIN_CASH = 'smart-bitcoin-cash'
SOLANA = 'solana'
SONGBIRD = 'songbird'
SONGBIRD_CANARY = 'songbird-canary'
SONIC = 'sonic'
SORA = 'sora'
STACKS = 'stacks'
STARKNET = 'starknet'
STELLAR = 'stellar'
STEP_NETWORK = 'step-network'
STORY = 'story'
STRATIS = 'stratis'
SUI = 'sui'
SUPER_LUMIO = 'super-lumio'
SUPER_ZERO = 'super-zero'
SWELL = 'swell'
SX_NETWORK = 'sx-network'
SYSCOIN = 'syscoin'
TAIKO = 'taiko'
TBWG_CHAIN = 'tbwg-chain'
TDVV_SIDECHAIN = 'tdvv-sidechain'
TELOS = 'telos'
TENET = 'tenet'
TERRA = 'terra'
TERRA_2 = 'terra-2'
TEZOS = 'tezos'
THAI_CHAIN = 'thai-chain'
THAI_CHAIN_2_THAI_FI = 'thai-chain-2-thai-fi'
THETA = 'theta'
THOR = 'thor'
THUNDERCORE = 'thundercore'
TOMBCHAIN = 'tombchain'
TOMOCHAIN = 'tomochain'
TRON = 'tron'
TRUSTLESS_COMPUTER = 'trustless-computer'
UBIQ = 'ubiq'
ULTRON = 'ultron'
UNICHAIN = 'unichain'
VALOBIT = 'valobit'
VALORBIT = 'valorbit'
VECHAIN = 'vechain'
VELAS = 'velas'
VENOM = 'venom'
VITE = 'vite'
WANCHAIN = 'wanchain'
WAVES = 'waves'
WAX = 'wax'
WEMIX_NETWORK = 'wemix-network'
WORLD_CHAIN = 'world-chain'
WYZTH = 'wyzth'
XAI = 'xai'
XDAI = 'xdai'
XDC_NETWORK = 'xdc-network'
XPLA = 'xpla'
XRP = 'xrp'
X_LAYER = 'x-layer'
YOCOIN = 'yocoin'
ZEDXION = 'zedxion'
ZERO = 'zero'
ZCASH = 'zcash'
ZETA_CHAIN = 'zetachain'
ZILLIQA = 'zilliqa'
ZIRCUIT = 'zircuit'
ZKFAIR = 'zkfair'
ZKLINK_NOVA = 'zklink-nova'
ZKSYNC_ERA = 'zksync-era'
ZORA = 'zora'
class AssetType(str, Enum):
AVAILABLE = 'available'
CLAIMABLE = 'claimable'
COLLATERAL = 'collateral'
COMMON = 'common'
DEBT = 'debt'
DEPOSITED = 'deposited'
FARMING = 'farming'
ILLIQUID = 'illiquid'
INVESTMENT = 'investment'
LENDING = 'lending'
LENDING_BORROW = 'lending_borrow'
LENDING_REWARDS = 'lending_reward'
LIQUIDATION_REWARDS = 'liquidation_rewards'
LIQUIDITY_POOL = 'liquidity_pool'
LIQUIDITY_POOL_PRINCIPAL = 'liquidity_pool_principal'
LOCKED = 'locked'
NFT = 'nft'
PENDING_TRANSACTION = 'pending_transaction'
PREDICTION = 'prediction'
PRICED_VESTING = 'priced_vesting'
REWARDS = 'rewards'
STAKED = 'staked'
VESTING = 'vesting'
YIELD = 'yield'
# DEPRECATED
ASSET = 'asset'
class OperationType(str, Enum):
UNKNOWN = 'unknown'
INFLATION = 'inflation'
TRANSACTION = 'transaction'
COLLECT_TX_FEE = 'collect-tx-fee'
class OperationDirection(str, Enum):
OUTGOING = 'outgoing'
INCOMING = 'incoming'
class TransactionStatus(str, Enum):
CONFIRMED = 'confirmed'
PENDING = 'pending'
class CoingeckoId(str, Enum):
ASTAR = 'astar'
AURORA = 'aurora-near'
AVALANCHE = 'avalanche-2'
BINANCE = 'binancecoin'
BITCOIN = 'bitcoin'
BIT_TORRENT = 'bittorrent'
BOBA = 'boba-network'
CANTO = 'canto'
CELO = 'celo'
CELESTIA = 'celestia'
COSMOS = 'cosmos'
CRONOS = 'crypto-com-chain'
DAI = 'dai'
DYDX = 'dydx'
DOGECOIN = 'dogecoin'
ETHEREUM = 'ethereum'
EVMOS = 'evmos'
FANTOM = 'fantom'
FUSE = 'fuse-network-token'
HARMONY = 'harmony'
HUOBI = 'huobi-token'
IOTEX = 'iotex'
KLAY = 'klaytn'
KUCOIN = 'kucoin-shares'
KUSAMA = 'kusama'
LITECOIN = 'litecoin'
LUNA = 'terra-luna'
MATIC = 'matic-network'
METIS = 'metis-token'
MOONBEAM = 'moonbeam'
MOONBEAM_MOONRIVER = 'moonriver'
OKT = 'oec-token'
OPTIMISM = 'optimism'
OSMOSIS = 'osmosis'
PERPETUAL = 'perpetual-protocol'
POLKADOT = 'polkadot'
PRIME = 'echelon-prime'
RONIN = 'ronin'
RSK = 'rootstock'
SHIDEN = 'shiden'
SOLANA = 'solana'
SONGBIRD = 'songbird'
SUI = 'sui'
SYNTHETIX = 'havven'
TELOS = 'telos'
USDC = 'usd-coin'
WANCHAIN = 'wanchain'
WETH = 'weth'
XDAI = 'xdai'
ZCASH = 'zcash'
class NftOfferDirection(str, Enum):
OFFER = 'offer'
LISTING = 'listing'
class OfferItemType(str, Enum):
NATIVE = 'native'
ERC20 = 'erc-20'
ERC721 = 'erc-721'
ERC1155 = 'erc-1155'
ERC721_WITH_CRITERIA = 'erc-721-limited'
ERC1155_WITH_CRITERIA = 'erc-1155-limited'
class BtcNftType(str, Enum):
"""Type of NFT of BTC chain"""
BRC20 = "brc20"
DOMAIN = "domain"
COLLECTION = "collection"
ARC20 = "arc20"
RUNES = "runes"
@attr.s(auto_attribs=True, slots=True)
class ApiOptions:
blockchain: Blockchain
base_url: Optional[str]
rate_limit: float = 0.0
testnet: bool = False
start_offset: Optional[int] = attr.ib(default=None)
max_items_per_page: Optional[int] = attr.ib(default=None)
page_offset_step: Optional[int] = attr.ib(default=None)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class CoinInfo:
tags: List[str] = attr.ib(default=None)
total_supply: Optional[Decimal] = attr.ib(default=None)
logo_url: Optional[str] = attr.ib(default=None)
coingecko_id: Optional[CoingeckoId] = attr.ib(default=None)
website: Optional[str] = attr.ib(default=None)
@classmethod
def from_api(
cls,
tags: Optional[List[str]] = None,
total_supply: Optional[Union[int, float, str]] = None,
logo_url: Optional[str] = None,
coingecko_id: Optional[str] = None,
website: Optional[str] = None,
) -> 'CoinInfo':
return cls(
tags=tags,
total_supply=(
to_decimal(total_supply) if total_supply is not None else None
),
logo_url=logo_url,
coingecko_id=coingecko_id,
website=website,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class CoinContract:
blockchain: Blockchain
contract: str
decimals: int
@classmethod
def from_api(cls, *, blockchain: Blockchain, contract: str, decimals: int):
return cls(blockchain=blockchain, contract=contract, decimals=decimals)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class Coin:
symbol: str
name: str
decimals: int
blockchain: Blockchain
address: Optional[str] = attr.ib(default=None)
standards: Optional[List[str]] = attr.ib(default=None)
protocol_id: Optional[str] = attr.ib(default=None)
info: Optional[CoinInfo] = attr.ib(default=None)
@property
def is_nft(self) -> bool:
if not self.standards:
return False
return bool(set(self.standards) & NFT_STANDARDS)
@classmethod
def from_api(
cls,
blockchain: Blockchain,
decimals: Union[int, str],
symbol: Optional[str] = None,
name: Optional[str] = None,
address: Optional[str] = None,
standards: Optional[List[str]] = None,
protocol_id: Optional[str] = None,
info: Optional[CoinInfo] = None,
) -> 'Coin':
return cls(
symbol=symbol if symbol else UNKNOWN,
name=name if name else UNKNOWN,
decimals=to_int(decimals) if decimals else 0,
blockchain=blockchain,
address=address,
standards=standards,
protocol_id=protocol_id,
info=info,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class CoingeckoMapping:
symbol: str
coingecko_id: CoingeckoId
contracts: set[str]
@attr.s(auto_attribs=True, slots=True, frozen=True)
class Protocol:
protocol_id: str
chain: Blockchain
name: str
user_deposit: Decimal
site_url: Optional[str] = attr.ib(default=None)
logo_url: Optional[str] = attr.ib(default=None)
has_supported_portfolio: bool = attr.ib(default=False)
@classmethod
def from_api(
cls,
*,
protocol_id: str,
chain: Blockchain,
name: str,
user_deposit: Union[str, float, int],
site_url: Optional[str] = None,
logo_url: Optional[str] = None,
has_supported_portfolio: Optional[bool] = False,
) -> 'Protocol':
return cls(
protocol_id=protocol_id,
chain=chain,
name=name,
user_deposit=to_decimal(user_deposit),
site_url=site_url,
logo_url=logo_url,
has_supported_portfolio=has_supported_portfolio,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class PoolInfo:
pool_id: str
project_id: str
name: Optional[str] = attr.ib(default=None)
adapter_id: Optional[str] = attr.ib(default=None)
controller: Optional[str] = attr.ib(default=None)
position_index: Optional[str] = attr.ib(default=None)
tokens: Optional[list[str]] = attr.ib(default=None)
@classmethod
def from_api(
cls,
*,
pool_id: str,
project_id: str,
name: Optional[str] = None,
adapter_id: Optional[str] = None,
controller: Optional[str] = None,
position_index: Optional[str] = None,
tokens: Optional[list[str]] = None,
) -> 'PoolInfo':
return cls(
pool_id=pool_id,
project_id=project_id,
name=name,
adapter_id=adapter_id,
controller=controller,
position_index=position_index,
tokens=tokens,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class BalanceItem:
balance: Decimal
balance_raw: Decimal
raw: Dict
coin: Optional[Coin] = attr.ib(default=None)
coin_contract: Optional[CoinContract] = attr.ib(default=None)
asset_type: AssetType = AssetType.AVAILABLE
last_updated: Optional[datetime] = attr.ib(default=None)
protocol: Optional[Protocol] = attr.ib(default=None)
is_wallet: bool = True
pool_info: Optional[PoolInfo] = attr.ib(default=None)
@classmethod
def from_api(
cls,
*,
balance_raw: Union[int, float, str, Decimal] = None,
coin: Optional[Coin] = None,
coin_contract: Optional[CoinContract] = None,
asset_type: AssetType = AssetType.AVAILABLE,
raw: Union[Dict, List[Dict]],
last_updated: Optional[Union[int, str]] = None,
protocol: Optional[Protocol] = None,
is_wallet: bool = True,
pool_info: Optional[PoolInfo] = None,
balance: Optional[Decimal] = None,
) -> 'BalanceItem':
if coin is None and coin_contract is None:
raise ValueError('Either coin or coin_contract must be set')
raw_balance = to_decimal(balance_raw) if balance_raw else None
balance = (
balance
if balance
else raw_to_decimals(
balance_raw, coin.decimals if coin else coin_contract.decimals
)
)
return cls(
balance_raw=raw_balance,
balance=balance,
coin=coin,
coin_contract=coin_contract,
asset_type=asset_type,
raw=raw,
last_updated=(parse_dt(last_updated) if last_updated is not None else None),
protocol=protocol,
is_wallet=is_wallet,
pool_info=pool_info,
)
def __add__(self, other: 'BalanceItem') -> 'BalanceItem':
"""
Warning: Adding items of different coins leads to wrong results.
"""
return BalanceItem(
balance_raw=self.balance_raw + other.balance_raw,
balance=self.balance + other.balance,
coin=self.coin,
coin_contract=self.coin_contract,
asset_type=self.asset_type,
raw=self._add_raw(other),
last_updated=self.last_updated,
protocol=self.protocol,
is_wallet=self.is_wallet,
)
def _add_raw(self, other):
"""
Used to skip wrapping of "merged" into "merged" key over and over again.
"""
if self.raw.get("merged") and isinstance(self.raw.get("merged"), list):
return {"merged": self.raw.get("merged") + [other.raw]}
else:
return {"merged": [self.raw, other.raw]}
@attr.s(auto_attribs=True, slots=True, frozen=True)
class NftToken:
ident: str
collection: str
collection_name: Optional[str]
contract: str
standard: str
name: str
description: Optional[str]
amount: Optional[int]
image_url: str
metadata_url: Optional[str]
metadata: Optional[dict]
updated_time: Optional[datetime]
is_disabled: bool
is_nsfw: bool
asset_type: AssetType
blockchain: Blockchain
market_url: str
@classmethod
def from_api(
cls,
*,
ident: str,
collection: str,
contract: str,
standard: Literal['erc721', 'erc1155', 'ordinals', 'rune'],
name: str,
description: Optional[str],
amount: int,
image_url: str,
metadata_url: Optional[str],
updated_time: Optional[Union[str, datetime]],
is_disabled: bool,
is_nsfw: bool,
blockchain: Blockchain,
asset_type: AssetType = AssetType.AVAILABLE,
collection_name: Optional[str] = None,
market_url: Optional[str] = None,
) -> 'NftToken':
return cls(
ident=ident,
collection=collection,
contract=contract,
standard=standard,
name=name,
description=description,
amount=int(amount) if amount else 1,
image_url=image_url,
metadata_url=metadata_url,
metadata=None,
updated_time=(
parse_dt(updated_time)
if updated_time and updated_time.strip()
else None
),
is_disabled=is_disabled,
is_nsfw=is_nsfw,
blockchain=blockchain,
asset_type=asset_type,
collection_name=collection_name,
market_url=market_url,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class NftOffer:
offer_key: str
direction: NftOfferDirection
collection: str
contract: str
blockchain: Blockchain
offerer: str
start_time: datetime
end_time: Optional[datetime]
offer_coin: Optional[Coin]
offer_contract: Optional[str]
offer_ident: Optional[str]
offer_amount: Decimal
pay_coin: Optional[Coin]
pay_contract: Optional[str]
pay_ident: Optional[str]
pay_amount: Decimal
@classmethod
def from_api(
cls,
*,
offer_key: str,
direction: NftOfferDirection,
collection: str,
contract: str,
blockchain: Blockchain,
offerer: str,
start_time: Optional[str],
end_time: Optional[str],
offer_coin: Optional[Coin],
offer_contract: Optional[str],
offer_ident: Optional[str],
offer_amount: str,
pay_coin: Optional[Coin],
pay_contract: Optional[str],
pay_ident: Optional[str],
pay_amount: str,
) -> 'NftOffer':
return cls(
offer_key=offer_key,
direction=direction,
collection=collection,
contract=contract,
blockchain=blockchain,
offerer=offerer,
start_time=parse_dt(start_time) if start_time else datetime.utcnow(),
end_time=parse_dt(end_time) if end_time else None,
offer_coin=offer_coin,
offer_contract=offer_contract.lower() if offer_contract else None,
offer_ident=offer_ident,
offer_amount=(
raw_to_decimals(offer_amount, offer_coin.decimals)
if offer_coin
else to_decimal(offer_amount)
),
pay_coin=pay_coin,
pay_contract=pay_contract.lower() if pay_contract else None,
pay_ident=pay_ident,
pay_amount=(
raw_to_decimals(pay_amount, pay_coin.decimals)
if pay_coin
else to_decimal(pay_amount)
),
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class NftCollectionIntervalStats:
volume: Decimal
volume_diff: Decimal
volume_percent_change: Decimal
sales_count: int
sales_diff: int
average_price: Decimal
@classmethod
def from_api(
cls,
*,
volume: str,
volume_diff: str,
volume_percent_change: str,
sales_count: str,
sales_diff: str,
average_price: str,
) -> 'NftCollectionIntervalStats':
return cls(
volume=Decimal(volume),
volume_diff=Decimal(volume_diff),
volume_percent_change=Decimal(volume_percent_change),
sales_count=int(sales_count) if sales_count else 0,
sales_diff=int(Decimal(sales_diff)) if sales_diff else 0,
average_price=Decimal(average_price),
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class NftCollectionTotalStats:
volume: Decimal
sales_count: int
owners_count: int
market_cap: Decimal
floor_price: Decimal
coin: Coin
average_price: Decimal
@classmethod
def from_api(
cls,
*,
volume: str,
sales_count: str,
owners_count: str,
market_cap: str,
floor_price: str,
average_price: str,
coin: Coin,
) -> 'NftCollectionTotalStats':
return cls(
volume=Decimal(volume) if volume else Decimal('0'),
sales_count=int(sales_count) if sales_count else 0,
owners_count=int(owners_count) if owners_count else 0,
market_cap=Decimal(market_cap) if market_cap else Decimal('0'),
floor_price=Decimal(floor_price) if floor_price else Decimal('0'),
average_price=Decimal(average_price) if average_price else Decimal('0'),
coin=coin,
)
@classmethod
def from_api_convert_decimals(
cls,
*,
volume: str,
sales_count: str,
owners_count: str,
market_cap: str,
floor_price: str,
average_price: str,
coin: Coin,
) -> 'NftCollectionTotalStats':
return cls(
volume=raw_to_decimals(volume, coin.decimals) if volume else Decimal('0'),
sales_count=int(sales_count) if sales_count else 0,
owners_count=int(owners_count) if owners_count else 0,
market_cap=(
raw_to_decimals(market_cap, coin.decimals)
if market_cap
else Decimal('0')
),
floor_price=(
raw_to_decimals(floor_price, coin.decimals)
if floor_price
else Decimal('0')
),
average_price=(
raw_to_decimals(average_price, coin.decimals)
if average_price
else Decimal('0')
),
coin=coin,
)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class ContractInfo:
blockchain: Blockchain
address: str
@classmethod
def from_api(cls, *, blockchain: Blockchain, address: str):
return cls(blockchain=blockchain, address=address)
@attr.s(auto_attribs=True, slots=True, frozen=True)
class NftPrice:
coin: Coin
amount: Decimal
@classmethod
def from_api(cls, *, coin: Coin, amount_raw: Union[int, str]):