-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathchains.py
More file actions
41 lines (32 loc) · 1.23 KB
/
chains.py
File metadata and controls
41 lines (32 loc) · 1.23 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
from dexguru_sdk import DexGuru
from pydantic import HttpUrl
from meta_aggregation_api.models.chain import ChainModel
class ChainsConfig:
"""
All supported chains are defined here.
Chain object contains name, chain_id, description and native_token.
Native token is an object with address, name, symbol and decimals.
Models defined in models/chain.py
Usage:
chain = chains.eth
chain.chain_id
# 1
"""
chains = {}
def __init__(self, api_key: str, domain: HttpUrl):
self.dex_guru_sdk = DexGuru(api_key=api_key, domain=domain)
async def set_chains(self):
chains_ = await self.dex_guru_sdk.get_chains()
for chain in chains_.data:
self.chains[chain.name.lower()] = ChainModel.parse_obj(chain.dict())
def __contains__(self, item: str | int):
return item in self.chains.keys() or item in [
chain.chain_id for chain in self.__dict__.values()
]
def get_chain_by_id(self, chain_id: int):
for chain in self.chains.values():
if chain.chain_id == chain_id:
return chain
raise ValueError(f'Chain id {chain_id} not found')
def __getattr__(self, item):
return self.chains[item]