forked from viaprotocol/tokenlists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
97 lines (84 loc) · 2.21 KB
/
common.py
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
from typing import NewType, Optional, TypedDict
from pydantic import BaseModel, Field, validator
from web3 import Web3
CHAIN_NAMES_BY_ID = {
'1': 'ethereum',
'10': 'optimism',
'100': 'gnosis',
'10000': 'smartbch',
'-1': 'solana',
'-2': 'near',
'1024': 'clover',
'11297108109': 'palm',
'122': 'fuse',
'128': 'heco',
'1284': 'moonbeam',
'1285': 'moonriver',
'1287': 'moonbase',
'1313161554': 'aurora',
'137': 'polygon',
'1666600000': 'harmony',
'1666700000': 'harmony-testnet',
'20': 'elastos',
'25': 'cronos',
'250': 'ftm',
'256': 'heco-testnet',
'288': 'boba',
'3': 'ropsten',
'321': 'kcc',
'361': 'theta',
'4': 'rinkeby',
'40': 'telos',
'4002': 'ftmtest',
'42': 'kovan',
'42161': 'arbitrum',
'42220': 'celo',
'43113': 'fuji',
'43114': 'avax',
'4689': 'iotex',
'592': 'astar',
'5': 'goerli',
'56': 'bsc',
'1818': 'cube',
'65': 'okex-testnet',
'66': 'okex',
'70': 'hoo',
'80001': 'mumbai',
'82': 'meter',
'88': 'tomochain',
'97': 'bsc-testnet',
'9001': 'evmos',
}
Address = NewType('Address', str)
ChainId = NewType('ChainId', int)
class Token(BaseModel):
symbol: str
name: str
address: Address
decimals: int = Field(..., alias="tokenDecimal")
chainId: ChainId
logoURI: Optional[str]
coingeckoId: Optional[str]
listedIn: list[str] = []
class Config:
allow_population_by_field_name = True
def __init__(self, **data):
super().__init__(
logoURI=(
data.pop("logoURI", None) or data.pop("logo", None) or data.pop("icon", None) or data.pop("image", None)
),
**data,
)
# if logo.startswith('//'):
# logo = 'ht
@validator("address")
def addr_checksum(cls, v: str):
v = v.strip()
if Web3.isAddress(v):
if "#" in v:
v = v.split("#")[0]
return Web3.toChecksumAddress(v)
return v
NATIVE_ADDR_0xe = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
NATIVE_ADDR_0x0 = Address("0x0000000000000000000000000000000000000000")
NATIVE_MATIC_ADDR = "0x0000000000000000000000000000000000001010"