Skip to content

Commit

Permalink
Merge pull request #14 from ackness/v0.1.8-dev
Browse files Browse the repository at this point in the history
support ide autocomplete, fix some path error on windows platform
  • Loading branch information
ackness authored Aug 1, 2023
2 parents 5eb2224 + 6ace422 commit 4a98fd7
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Many Abis

![Version](https://img.shields.io/badge/many--abis-v0.1.7-green)
![Version](https://img.shields.io/badge/many--abis-v0.1.8-green)
![Pypi](https://img.shields.io/pypi/dm/many-abis)

![GitHub Org's stars](https://img.shields.io/github/stars/ackness/many_abis?style=social)
Expand Down
6 changes: 3 additions & 3 deletions many_abis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .utils import *
from .chains import *
from .abis import *
from ._base import *
from .abis import *
from .chains import *
from .constants import *
from .utils import *
16 changes: 11 additions & 5 deletions many_abis/abis.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from .utils import load_all_abis
from addict import Dict
from pathlib import PurePath

import requests
from addict import Dict

from .meta import ABIMetaData
from .utils import load_all_abis


# __all__ = ["ABIS"]

def all_abis():
def all_abis() -> tuple[list[str], ABIMetaData]:
all_abis = load_all_abis()
names = []
all_abis_rename = {}
for k, v in all_abis.items():
ns = k.split('/')[2:]
ns = list(PurePath(k).parts)[2:]
# ns = k.split('/')[2:] # only for linux or mac
name = '_'.join(ns).upper()
names.append(name)
all_abis_rename[name] = v
return names, Dict(all_abis_rename)


ALL_ABIS_NAME, ABIS = all_abis()
globals().update(ABIS)


def get_abi_from_address(address: str, api_key: str, chain_api: str):
Expand Down
24 changes: 14 additions & 10 deletions many_abis/chains.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from .utils import load_chains
from addict import Dict
from functools import reduce
from typing import Union

from addict import Dict

from .meta import WethMetaData, ChainMetaData, SingleDexMetaData, ChainsMetaData
from .utils import load_chains

CHAINS = Dict(load_chains())
SUPPORTED_CHAINS = list(CHAINS.keys())
CHAINS: ChainsMetaData = Dict(load_chains())
SUPPORTED_CHAINS: list[str] = list(CHAINS.keys())


def all_chains():
def all_chains() -> list[str]:
return SUPPORTED_CHAINS


def get_chain_by_name(name: str):
def get_chain_by_name(name: str) -> ChainMetaData:
assert name in SUPPORTED_CHAINS, f"Chain {name} not supported"
return CHAINS[name]


def get_chain_by_id(chain_id: int):
def get_chain_by_id(chain_id: int) -> ChainMetaData:
for name, info in CHAINS.items():
if "chain_id" not in info:
raise ValueError(f"Chain {name} does not have chain_id")
Expand All @@ -24,7 +28,7 @@ def get_chain_by_id(chain_id: int):
raise ValueError(f"Chain id {chain_id} not supported")


def get_chain(name=None, chain_id=None):
def get_chain(name=None, chain_id=None) -> ChainMetaData:
assert name or chain_id, "Must provide either name or chain_id"
if name:
name = name.lower()
Expand All @@ -34,11 +38,11 @@ def get_chain(name=None, chain_id=None):
return get_chain_by_id(chain_id)


def chain(*args, **kwargs):
def chain(*args, **kwargs) -> ChainMetaData:
return get_chain(*args, **kwargs)


def get(*keys):
def get(*keys) -> Union[ChainMetaData, SingleDexMetaData, WethMetaData, ChainsMetaData]:
try:
return reduce(lambda d, key: d[key], keys, CHAINS)
except KeyError as e:
Expand Down
1 change: 1 addition & 0 deletions many_abis/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CHAIN_SCAN_API:
CRONOS: str = 'https://api.cronoscan.com/api'
OPT: str = 'https://api-optimistic.etherscan.io/api'


@dataclass(frozen=True)
class CHAIN_CONTRACT_API:
ETH: str = 'https://api.etherscan.io/api?module=contract&action=getabi&address={contract_address}&apikey={api_key}'
Expand Down
91 changes: 91 additions & 0 deletions many_abis/meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from typing import Iterable, Mapping, Sequence


class WethMetaData:
address: str
name: str
symbol: str


class SingleDexMetaData:
factory_address: str
router_address: str
name: str
website: str


class ChainMetaData:
chain_id: int
charts: Mapping[str, str]
dex: Mapping[str, SingleDexMetaData]
explorer: str
name: str
rpc: Sequence[str]
stable_coins: Mapping[str, str]
weth: WethMetaData


class ChainsMetaData:
eth: ChainMetaData
bsc: ChainMetaData
polygon: ChainMetaData
heco: ChainMetaData
fantom: ChainMetaData
arbitrum: ChainMetaData
cronos: ChainMetaData
avalanche: ChainMetaData
kcc: ChainMetaData
moonriver: ChainMetaData
okx: ChainMetaData
bsc_test: ChainMetaData
optimism: ChainMetaData


class ABIMetaData(Iterable):
AAVE_V1_ATOKEN: Sequence[Mapping]
AAVE_V1_LENDING_POOL: Sequence[Mapping]
AAVE_V1_LENDING_POOL_ADDRESSES_PROVIDER: Sequence[Mapping]
AAVE_V1_LENDING_POOL_CORE: Sequence[Mapping]
AAVE_V2_COLLECTOR: Sequence[Mapping]
AAVE_V2_INCENTIVES_CONTROLLER: Sequence[Mapping]
AAVE_V2_LENDING_POOL: Sequence[Mapping]
AAVE_V2_LENDING_POOL_ADDRESSES_PROVIDER: Sequence[Mapping]
AAVE_V2_LENDING_POOL_ADDRESSES_PROVIDER_REGISTRY: Sequence[Mapping]
AAVE_V2_LENDING_POOL_COLLATERAL_MANAGER: Sequence[Mapping]
AAVE_V2_LENDING_POOL_CONFIGURATOR: Sequence[Mapping]
AAVE_V2_LENDING_RATE_ORACLE: Sequence[Mapping]
AAVE_V2_POOL_ADMIN: Sequence[Mapping]
AAVE_V2_PRICE_ORACLE: Sequence[Mapping]
AAVE_V2_PROTOCAL_DATA_PROVIDER: Sequence[Mapping]
AAVE_V2_UI_INCENTIVE_DATA_PROVIDER: Sequence[Mapping]
AAVE_V2_UI_POOL_DATA_PROVIDER: Sequence[Mapping]
AAVE_V2_WETH_GATEWAY: Sequence[Mapping]
JOE_V2_FACTORY: Sequence[Mapping]
JOE_V2_PAIR: Sequence[Mapping]
JOE_V2_ROUTER: Sequence[Mapping]
PANCAKE_V3_IPERIPHERY_PAYMENTS_WITH_FEE: Sequence[Mapping]
PANCAKE_V3_MASTER_CHEF_V3: Sequence[Mapping]
PANCAKE_V3_NON_FUNGIBLE_POSITION_MANAGER: Sequence[Mapping]
PANCAKE_V3_POOL_V3: Sequence[Mapping]
PANCAKE_V3_QUOTER: Sequence[Mapping]
PANCAKE_V3_QUOTER_V2: Sequence[Mapping]
PANCAKE_V3_ROUTER_V3: Sequence[Mapping]
PANCAKE_V3_SELF_PERMIT: Sequence[Mapping]
PANCAKE_V3_STAKER: Sequence[Mapping]
UNISWAP_BSC_ROUTER: Sequence[Mapping]
UNISWAP_V1_EXCHANGE: Sequence[Mapping]
UNISWAP_V1_FACTORY: Sequence[Mapping]
UNISWAP_V2_FACTORY: Sequence[Mapping]
UNISWAP_V2_PAIR: Sequence[Mapping]
UNISWAP_V2_ROUTER: Sequence[Mapping]
UNISWAP_V3_FACTORY: Sequence[Mapping]
UNISWAP_V3_MULTICALL: Sequence[Mapping]
UNISWAP_V3_NON_FUNGIBLE_POSITION_MANAGE: Sequence[Mapping]
UNISWAP_V3_POOL: Sequence[Mapping]
UNISWAP_V3_QUOTER: Sequence[Mapping]
UNISWAP_V3_ROUTER: Sequence[Mapping]
ERC1155: Sequence[Mapping]
ERC20: Sequence[Mapping]
ERC721: Sequence[Mapping]
ERC777: Sequence[Mapping]
WETH9: Sequence[Mapping]
17 changes: 8 additions & 9 deletions many_abis/utils.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import glob
import json
import os
import glob
from types import SimpleNamespace
from typing import Any

root_path = f"{os.path.dirname(os.path.abspath(__file__))}/assets"
root_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")


def _load_json_file(fp):
def _load_json_file(fp) -> Any:
with open(fp) as f:
abi = json.load(f)
return abi


def load_abi(name: str):
def load_abi(name: str) -> dict[str, str]:
with open(os.path.abspath(os.path.join(root_path, f'{name}.abi'))) as f:
abi = json.load(f)
return abi


def load_all_abis():
def load_all_abis() -> dict[str, dict[str, str]]:
all_abis_fp = list(glob.iglob(f"{root_path}/**/*.abi", recursive=True))
return {f'{p[len(root_path):][:-4]}': _load_json_file(p) for p in all_abis_fp}


def load_chains():
def load_chains() -> dict[str, Any]:
fp = os.path.join(root_path, "utils", "chains.json")
return _load_json_file(fp)

Expand All @@ -36,7 +36,6 @@ def print_all_dex():
print(f" - [{j + 1}] [{dex.name}]({dex.website})")


def supported_abis():
def supported_abis() -> list[str]:
from .abis import ALL_ABIS_NAME
# print(ALL_ABIS_NAME)
return ALL_ABIS_NAME
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

with open('README.md', 'r', encoding='utf-8') as fh:
long_description = fh.read()
# print(find_packages())

setup(
name='many_abis',
packages=['many_abis'],
# packages=['many_abis'],
packages=find_packages(where="many_abis"),
package_dir={'many_abis': 'many_abis'},
package_data={'': [
'**/*.abi', '**/*.json']},
version='0.1.7',
package_data={'': ["assets/*"]},
version='0.1.8',
license='MIT',
description='A simple way to get different DEXs abis for block chains.',
long_description=long_description,
Expand All @@ -24,5 +24,6 @@
"eth_utils",
"addict"
],
python_requires='>=3.8',

)

0 comments on commit 4a98fd7

Please sign in to comment.