diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24f3add --- /dev/null +++ b/.gitignore @@ -0,0 +1,126 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# setuptools-scm +version.py + +# Ape stuff +.build/ + +**/.DS_Store +*.swp +*.swo + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..735751e --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2021 ApeWorX Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index e69de29..505cfb0 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,44 @@ +# Python EVM Chains Metadata + +Provides general metadata on EVM-compatible chains organized by Ape-style ecosystem and network. + +Original soure data: https://github.com/ethereum-lists/chains + +## Quick Start + +## Dependencies + +- [python3](https://www.python.org/downloads) version 3.8 up to 3.11. + +## Installation + +### via `pip` + +You can install the latest release via [`pip`](https://pypi.org/project/pip/): + +```bash +pip install evmchains +``` + +### via `setuptools` + +You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version: + +```bash +git clone https://github.com/ApeWorX/evmchains.git +cd evmchains +python3 setup.py install +``` + +## Quick Usage + +``` +from evmchains import get_chain_meta +chain = get_chain_meta("ethereum", "mainnet") +assert chain.chainId == 1 +``` + +## Development + +Please see the [contributing guide](CONTRIBUTING.md) to learn more how to contribute to this project. +Comments, questions, criticisms and pull requests are welcomed. diff --git a/evmchains/__init__.py b/evmchains/__init__.py new file mode 100644 index 0000000..bae2fde --- /dev/null +++ b/evmchains/__init__.py @@ -0,0 +1,16 @@ +from evmchains.chains import PUBLIC_CHAIN_RPCS +from evmchains.types import Chain + + +def get_chain_meta(ecosystem: str, network: str) -> Chain: + """Return a Chain instance with metadata for an EVM chain""" + if ( + ecosystem not in PUBLIC_CHAIN_RPCS + or network not in PUBLIC_CHAIN_RPCS[ecosystem] + ): + raise KeyError(f"Unknown ecosystem:network: {ecosystem}:{network}") + + return Chain(**PUBLIC_CHAIN_RPCS[ecosystem][network]) + + +__all__ = ["PUBLIC_CHAIN_RPCS", "Chain", "get_chain_meta"] diff --git a/evmchains/_meta.py b/evmchains/_meta.py new file mode 100644 index 0000000..b6dd2a8 --- /dev/null +++ b/evmchains/_meta.py @@ -0,0 +1,16 @@ +# file generated by setuptools_scm +# don't change, don't track in version control +TYPE_CHECKING = False +if TYPE_CHECKING: + from typing import Tuple, Union + VERSION_TUPLE = Tuple[Union[int, str], ...] +else: + VERSION_TUPLE = object + +version: str +__version__: str +__version_tuple__: VERSION_TUPLE +version_tuple: VERSION_TUPLE + +__version__ = version = '0.0.1a1' +__version_tuple__ = version_tuple = (0, 0, 1) diff --git a/evmchains/chains.py b/evmchains/chains.py new file mode 100644 index 0000000..ed59d0f --- /dev/null +++ b/evmchains/chains.py @@ -0,0 +1,743 @@ +# This file is auto-generated by scripts/update_rpc.py +# 2024-01-23 02:47:29.050302 +# Do not edit this file directly. +from typing import Any, Dict, List + +PUBLIC_CHAIN_RPCS: Dict[str, Dict[str, Dict[str, Any]]] = { + "arbitrum": { + "mainnet": { + "chain": "ETH", + "chainId": 42161, + "ens": None, + "explorers": [ + { + "name": "Arbiscan", + "standard": "EIP3091", + "url": "https://arbiscan.io", + }, + { + "name": "Arbitrum Explorer", + "standard": "EIP3091", + "url": "https://explorer.arbitrum.io", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://arbitrum.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://arbitrum.io", + "name": "Arbitrum One", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 42161, + "rpc": [ + "https://arbitrum-mainnet.infura.io/v3/${INFURA_API_KEY}", + "https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}", + "https://arb1.arbitrum.io/rpc", + "https://arbitrum-one.publicnode.com", + ], + "shortName": "arb1", + "slip44": None, + }, + "goerli": { + "chain": "ETH", + "chainId": 421613, + "ens": None, + "explorers": [ + { + "name": "Arbitrum Goerli Arbiscan", + "standard": "EIP3091", + "url": "https://goerli.arbiscan.io", + } + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://arbitrum.io/", + "name": "Arbitrum Goerli", + "nativeCurrency": { + "decimals": 18, + "name": "Arbitrum Goerli Ether", + "symbol": "AGOR", + }, + "networkId": 421613, + "rpc": [ + "https://goerli-rollup.arbitrum.io/rpc", + "https://arbitrum-goerli.publicnode.com", + ], + "shortName": "arb-goerli", + "slip44": 1, + }, + "sepolia": { + "chain": "ETH", + "chainId": 421614, + "ens": None, + "explorers": [ + { + "name": "Arbitrum Sepolia Rollup Testnet Explorer", + "standard": "EIP3091", + "url": "https://sepolia-explorer.arbitrum.io", + } + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://arbitrum.io", + "name": "Arbitrum Sepolia", + "nativeCurrency": { + "decimals": 18, + "name": "Sepolia Ether", + "symbol": "ETH", + }, + "networkId": 421614, + "rpc": [ + "https://sepolia-rollup.arbitrum.io/rpc", + "https://arbitrum-sepolia.infura.io/v3/${INFURA_API_KEY}", + ], + "shortName": "arb-sep", + "slip44": 1, + }, + }, + "avalanche": { + "mainnet": { + "chain": "AVAX", + "chainId": 43114, + "ens": None, + "explorers": [ + { + "name": "snowtrace", + "standard": "EIP3091", + "url": "https://snowtrace.io", + } + ], + "faucets": [], + "features": [{"name": "EIP1559"}], + "icon": "avax", + "infoURL": "https://www.avax.network/", + "name": "Avalanche C-Chain", + "nativeCurrency": {"decimals": 18, "name": "Avalanche", "symbol": "AVAX"}, + "networkId": 43114, + "rpc": [ + "https://api.avax.network/ext/bc/C/rpc", + "https://avalanche-c-chain.publicnode.com", + ], + "shortName": "avax", + "slip44": 9005, + }, + "fuji": { + "chain": "AVAX", + "chainId": 43113, + "ens": None, + "explorers": [ + { + "name": "snowtrace", + "standard": "EIP3091", + "url": "https://testnet.snowtrace.io", + } + ], + "faucets": ["https://faucet.avax-test.network/"], + "features": None, + "icon": "avax", + "infoURL": "https://cchain.explorer.avax-test.network", + "name": "Avalanche Fuji Testnet", + "nativeCurrency": {"decimals": 18, "name": "Avalanche", "symbol": "AVAX"}, + "networkId": 1, + "rpc": [ + "https://api.avax-test.network/ext/bc/C/rpc", + "https://avalanche-fuji-c-chain.publicnode.com", + ], + "shortName": "Fuji", + "slip44": 1, + }, + }, + "base": { + "mainnet": { + "chain": "ETH", + "chainId": 8453, + "ens": None, + "explorers": [ + {"name": "basescan", "standard": "none", "url": "https://basescan.org"}, + { + "icon": "blockscout", + "name": "basescout", + "standard": "EIP3091", + "url": "https://base.blockscout.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://base.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": "base", + "infoURL": "https://base.org", + "name": "Base", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 8453, + "rpc": [ + "https://mainnet.base.org/", + "https://developer-access-mainnet.base.org/", + "https://base.gateway.tenderly.co", + "https://base.publicnode.com", + ], + "shortName": "base", + "slip44": None, + }, + "sepolia": { + "chain": "ETH", + "chainId": 84532, + "ens": None, + "explorers": [ + { + "icon": "blockscout", + "name": "basescout", + "standard": "EIP3091", + "url": "https://base-sepolia.blockscout.com", + } + ], + "faucets": [], + "features": None, + "icon": "baseTestnet", + "infoURL": "https://base.org", + "name": "Base Sepolia Testnet", + "nativeCurrency": { + "decimals": 18, + "name": "Sepolia Ether", + "symbol": "ETH", + }, + "networkId": 84532, + "rpc": ["https://sepolia.base.org"], + "shortName": "basesep", + "slip44": 1, + }, + }, + "bsc": { + "mainnet": { + "chain": "BSC", + "chainId": 56, + "ens": None, + "explorers": [ + { + "name": "bscscan", + "standard": "EIP3091", + "url": "https://bscscan.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://bnb.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://www.bnbchain.org/en", + "name": "BNB Smart Chain Mainnet", + "nativeCurrency": { + "decimals": 18, + "name": "BNB Chain Native Token", + "symbol": "BNB", + }, + "networkId": 56, + "rpc": [ + "https://bsc-dataseed1.bnbchain.org", + "https://bsc-dataseed2.bnbchain.org", + "https://bsc-dataseed3.bnbchain.org", + "https://bsc-dataseed4.bnbchain.org", + "https://bsc-dataseed1.defibit.io", + "https://bsc-dataseed2.defibit.io", + "https://bsc-dataseed3.defibit.io", + "https://bsc-dataseed4.defibit.io", + "https://bsc-dataseed1.ninicoin.io", + "https://bsc-dataseed2.ninicoin.io", + "https://bsc-dataseed3.ninicoin.io", + "https://bsc-dataseed4.ninicoin.io", + "https://bsc.publicnode.com", + ], + "shortName": "bnb", + "slip44": 714, + }, + "testnet": { + "chain": "BSC", + "chainId": 97, + "ens": None, + "explorers": [ + { + "name": "bscscan-testnet", + "standard": "EIP3091", + "url": "https://testnet.bscscan.com", + } + ], + "faucets": ["https://testnet.bnbchain.org/faucet-smart"], + "features": None, + "icon": None, + "infoURL": "https://www.bnbchain.org/en", + "name": "BNB Smart Chain Testnet", + "nativeCurrency": { + "decimals": 18, + "name": "BNB Chain Native Token", + "symbol": "tBNB", + }, + "networkId": 97, + "rpc": [ + "https://data-seed-prebsc-1-s1.bnbchain.org:8545", + "https://data-seed-prebsc-2-s1.bnbchain.org:8545", + "https://data-seed-prebsc-1-s2.bnbchain.org:8545", + "https://data-seed-prebsc-2-s2.bnbchain.org:8545", + "https://data-seed-prebsc-1-s3.bnbchain.org:8545", + "https://data-seed-prebsc-2-s3.bnbchain.org:8545", + "https://bsc-testnet.publicnode.com", + ], + "shortName": "bnbt", + "slip44": 1, + }, + }, + "ethereum": { + "mainnet": { + "chain": "ETH", + "chainId": 1, + "ens": {"registry": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"}, + "explorers": [ + { + "name": "etherscan", + "standard": "EIP3091", + "url": "https://etherscan.io", + }, + { + "icon": "blockscout", + "name": "blockscout", + "standard": "EIP3091", + "url": "https://eth.blockscout.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://ethereum.dex.guru", + }, + ], + "faucets": [], + "features": [{"name": "EIP155"}, {"name": "EIP1559"}], + "icon": "ethereum", + "infoURL": "https://ethereum.org", + "name": "Ethereum Mainnet", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 1, + "rpc": [ + "https://mainnet.infura.io/v3/${INFURA_API_KEY}", + "https://api.mycryptoapi.com/eth", + "https://cloudflare-eth.com", + "https://ethereum.publicnode.com", + "https://mainnet.gateway.tenderly.co", + "https://rpc.flashbots.net", + "https://rpc.flashbots.net/fast", + "https://rpc.mevblocker.io", + "https://rpc.mevblocker.io/fast", + "https://rpc.mevblocker.io/noreverts", + "https://rpc.mevblocker.io/fullprivacy", + ], + "shortName": "eth", + "slip44": 60, + }, + "goerli": { + "chain": "ETH", + "chainId": 5, + "ens": {"registry": "0x112234455c3a32fd11230c42e7bccd4a84e02010"}, + "explorers": [ + { + "name": "etherscan-goerli", + "standard": "EIP3091", + "url": "https://goerli.etherscan.io", + }, + { + "icon": "blockscout", + "name": "blockscout-goerli", + "standard": "EIP3091", + "url": "https://eth-goerli.blockscout.com", + }, + ], + "faucets": [ + "http://fauceth.komputing.org?chain=5&address=${ADDRESS}", + "https://goerli-faucet.slock.it?address=${ADDRESS}", + "https://faucet.goerli.mudit.blog", + ], + "features": None, + "icon": None, + "infoURL": "https://goerli.net/#about", + "name": "Goerli", + "nativeCurrency": {"decimals": 18, "name": "Goerli Ether", "symbol": "ETH"}, + "networkId": 5, + "rpc": [ + "https://goerli.infura.io/v3/${INFURA_API_KEY}", + "https://rpc.goerli.mudit.blog/", + "https://ethereum-goerli.publicnode.com", + "https://goerli.gateway.tenderly.co", + ], + "shortName": "gor", + "slip44": 1, + }, + "sepolia": { + "chain": "ETH", + "chainId": 11155111, + "ens": None, + "explorers": [ + { + "name": "etherscan-sepolia", + "standard": "EIP3091", + "url": "https://sepolia.etherscan.io", + }, + { + "name": "otterscan-sepolia", + "standard": "EIP3091", + "url": "https://sepolia.otterscan.io", + }, + ], + "faucets": [ + "http://fauceth.komputing.org?chain=11155111&address=${ADDRESS}" + ], + "features": None, + "icon": None, + "infoURL": "https://sepolia.otterscan.io", + "name": "Sepolia", + "nativeCurrency": { + "decimals": 18, + "name": "Sepolia Ether", + "symbol": "ETH", + }, + "networkId": 11155111, + "rpc": [ + "https://rpc.sepolia.org", + "https://rpc2.sepolia.org", + "https://rpc-sepolia.rockx.com", + "https://rpc.sepolia.ethpandaops.io", + "https://sepolia.infura.io/v3/${INFURA_API_KEY}", + "https://sepolia.gateway.tenderly.co", + "https://ethereum-sepolia.publicnode.com", + ], + "shortName": "sep", + "slip44": 1, + }, + }, + "fantom": { + "mainnet": { + "chain": "FTM", + "chainId": 250, + "ens": None, + "explorers": [ + { + "icon": "ftmscan", + "name": "ftmscan", + "standard": "EIP3091", + "url": "https://ftmscan.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://fantom.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": "fantom", + "infoURL": "https://fantom.foundation", + "name": "Fantom Opera", + "nativeCurrency": {"decimals": 18, "name": "Fantom", "symbol": "FTM"}, + "networkId": 250, + "rpc": ["https://rpc.ftm.tools", "https://fantom.publicnode.com"], + "shortName": "ftm", + "slip44": None, + }, + "testnet": { + "chain": "FTM", + "chainId": 4002, + "ens": None, + "explorers": [ + { + "icon": "ftmscan", + "name": "ftmscan", + "standard": "EIP3091", + "url": "https://testnet.ftmscan.com", + } + ], + "faucets": ["https://faucet.fantom.network"], + "features": None, + "icon": "fantom", + "infoURL": "https://docs.fantom.foundation/quick-start/short-guide#fantom-testnet", + "name": "Fantom Testnet", + "nativeCurrency": {"decimals": 18, "name": "Fantom", "symbol": "FTM"}, + "networkId": 4002, + "rpc": [ + "https://rpc.testnet.fantom.network", + "https://fantom-testnet.publicnode.com", + ], + "shortName": "tftm", + "slip44": 1, + }, + }, + "gnosis": { + "mainnet": { + "chain": "GNO", + "chainId": 100, + "ens": None, + "explorers": [ + { + "name": "gnosisscan", + "standard": "EIP3091", + "url": "https://gnosisscan.io", + }, + { + "icon": "blockscout", + "name": "blockscout", + "standard": "EIP3091", + "url": "https://gnosis.blockscout.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://gnosis.dex.guru", + }, + ], + "faucets": [ + "https://gnosisfaucet.com", + "https://stakely.io/faucet/gnosis-chain-xdai", + "https://faucet.prussia.dev/xdai", + ], + "features": None, + "icon": "gnosis", + "infoURL": "https://docs.gnosischain.com", + "name": "Gnosis", + "nativeCurrency": {"decimals": 18, "name": "xDAI", "symbol": "XDAI"}, + "networkId": 100, + "rpc": [ + "https://rpc.gnosischain.com", + "https://rpc.gnosis.gateway.fm", + "https://rpc.ankr.com/gnosis", + "https://gnosischain-rpc.gateway.pokt.network", + "https://gnosis-mainnet.public.blastapi.io", + "https://gnosis.api.onfinality.io/public", + "https://gnosis.blockpi.network/v1/rpc/public", + "https://web3endpoints.com/gnosischain-mainnet", + "https://gnosis.oat.farm", + "https://gnosis.publicnode.com", + ], + "shortName": "gno", + "slip44": 700, + }, + }, + "optimism": { + "mainnet": { + "chain": "ETH", + "chainId": 10, + "ens": None, + "explorers": [ + { + "name": "etherscan", + "standard": "EIP3091", + "url": "https://optimistic.etherscan.io", + }, + { + "icon": "blockscout", + "name": "blockscout", + "standard": "EIP3091", + "url": "https://optimism.blockscout.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://optimism.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://optimism.io", + "name": "OP Mainnet", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 10, + "rpc": [ + "https://mainnet.optimism.io", + "https://optimism.publicnode.com", + "https://optimism.gateway.tenderly.co", + ], + "shortName": "oeth", + "slip44": None, + }, + "goerli": { + "chain": "ETH", + "chainId": 420, + "ens": None, + "explorers": [ + { + "icon": "blockscout", + "name": "blockscout", + "standard": "EIP3091", + "url": "https://optimism-goerli.blockscout.com", + } + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://optimism.io", + "name": "Optimism Goerli Testnet", + "nativeCurrency": {"decimals": 18, "name": "Goerli Ether", "symbol": "ETH"}, + "networkId": 420, + "rpc": [ + "https://goerli.optimism.io", + "https://optimism-goerli.publicnode.com", + "https://optimism-goerli.gateway.tenderly.co", + ], + "shortName": "ogor", + "slip44": 1, + }, + "sepolia": { + "chain": "ETH", + "chainId": 11155420, + "ens": None, + "explorers": [ + { + "icon": "blockscout", + "name": "opscout", + "standard": "EIP3091", + "url": "https://optimism-sepolia.blockscout.com", + } + ], + "faucets": ["https://app.optimism.io/faucet"], + "features": None, + "icon": None, + "infoURL": "https://optimism.io", + "name": "OP Sepolia Testnet", + "nativeCurrency": { + "decimals": 18, + "name": "Sepolia Ether", + "symbol": "ETH", + }, + "networkId": 11155420, + "rpc": ["https://sepolia.optimism.io"], + "shortName": "opsep", + "slip44": 1, + }, + }, + "polygon": { + "mainnet": { + "chain": "Polygon", + "chainId": 137, + "ens": None, + "explorers": [ + { + "name": "polygonscan", + "standard": "EIP3091", + "url": "https://polygonscan.com", + }, + { + "icon": "dexguru", + "name": "dexguru", + "standard": "EIP3091", + "url": "https://polygon.dex.guru", + }, + ], + "faucets": [], + "features": None, + "icon": "polygon", + "infoURL": "https://polygon.technology/", + "name": "Polygon Mainnet", + "nativeCurrency": {"decimals": 18, "name": "MATIC", "symbol": "MATIC"}, + "networkId": 137, + "rpc": [ + "https://polygon-rpc.com/", + "https://rpc-mainnet.matic.network", + "https://matic-mainnet.chainstacklabs.com", + "https://rpc-mainnet.maticvigil.com", + "https://rpc-mainnet.matic.quiknode.pro", + "https://matic-mainnet-full-rpc.bwarelabs.com", + "https://polygon-bor.publicnode.com", + "https://polygon.gateway.tenderly.co", + ], + "shortName": "matic", + "slip44": 966, + }, + "mumbai": { + "chain": "Polygon", + "chainId": 80001, + "ens": None, + "explorers": [ + { + "name": "polygonscan", + "standard": "EIP3091", + "url": "https://mumbai.polygonscan.com", + } + ], + "faucets": ["https://faucet.polygon.technology/"], + "features": None, + "icon": "polygon", + "infoURL": "https://polygon.technology/", + "name": "Mumbai", + "nativeCurrency": {"decimals": 18, "name": "MATIC", "symbol": "MATIC"}, + "networkId": 80001, + "rpc": [ + "https://rpc-mumbai.maticvigil.com", + "https://polygon-mumbai-bor.publicnode.com", + "https://polygon-mumbai.gateway.tenderly.co", + ], + "shortName": "maticmum", + "slip44": 1, + }, + }, + "polygon-zkevm": { + "mainnet": { + "chain": "Polygon", + "chainId": 1101, + "ens": None, + "explorers": [ + { + "icon": "zkevm", + "name": "blockscout", + "standard": "EIP3091", + "url": "https://zkevm.polygonscan.com", + } + ], + "faucets": [], + "features": None, + "icon": "zkevm", + "infoURL": "https://polygon.technology/polygon-zkevm", + "name": "Polygon zkEVM", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 1101, + "rpc": ["https://zkevm-rpc.com"], + "shortName": "zkevm", + "slip44": None, + }, + "testnet": { + "chain": "Polygon", + "chainId": 1442, + "ens": None, + "explorers": [ + { + "name": "Polygon zkEVM explorer", + "standard": "EIP3091", + "url": "https://explorer.public.zkevm-test.net", + } + ], + "faucets": [], + "features": None, + "icon": None, + "infoURL": "https://polygon.technology/solutions/polygon-zkevm/", + "name": "Polygon zkEVM Testnet", + "nativeCurrency": {"decimals": 18, "name": "Ether", "symbol": "ETH"}, + "networkId": 1442, + "rpc": ["https://rpc.public.zkevm-test.net"], + "shortName": "testnet-zkEVM-mango", + "slip44": 1, + }, + }, +} diff --git a/evmchains/types.py b/evmchains/types.py new file mode 100644 index 0000000..5db8de2 --- /dev/null +++ b/evmchains/types.py @@ -0,0 +1,20 @@ +from typing import Any, Dict, List, Optional + +from pydantic import BaseModel + + +class Chain(BaseModel): + chainId: int + networkId: int + name: str + shortName: str + chain: str + infoURL: str + rpc: List[str] + faucets: List[str] + nativeCurrency: Dict[str, Any] + explorers: List[Dict[str, str]] + icon: Optional[str] = None + features: Optional[List[Dict[str, str]]] = None + slip44: Optional[int] = None + ens: Optional[Dict[str, str]] = None diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf52c47 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,65 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel", "setuptools_scm[toml]>=5.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "evmchains" +description = "Packaged metadata on Ethereum Virtual Machine (EVM) chains" +urls = {source = "https://github.com/ApeWorx/evmchains"} +readme = "README.md" +requires-python = ">=3.8" +keywords = ["ethereum", "evm", "blockchain"] +license = {file = "LICENSE"} +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "Intended Audience :: End Users/Desktop", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: MacOS", + "Operating System :: POSIX", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", +] +dependencies = [ + "pydantic~=2.5.3", +] +dynamic = ["version"] + +[project.optional-dependencies] +dev = [ + "black~=23.12.1", + "isort~=5.13.2", + "mypy~=1.8.0", + "pytest~=7.4.4", + "requests-2.31.0", + "setuptools-scm-8.0.4", +] + +[tool.mypy] +exclude = "build/" + +[tool.setuptools_scm] +write_to = "evmchains/_meta.py" + +# NOTE: you have to use single-quoted strings in TOML for regular expressions. +# It's the equivalent of r-strings in Python. Multiline strings are treated as +# verbose regular expressions by Black. Use [ ] to denote a significant space +# character. + +[tool.black] +target-version = ['py38', 'py39', 'py310', 'py311'] +include = '\.pyi?$' + +[tool.pytest.ini_options] +python_files = "test_*.py" +testpaths = "tests" + +[tool.isort] +force_grid_wrap = 0 +include_trailing_comma = true +multi_line_output = 3 +use_parentheses = true diff --git a/scripts/update.py b/scripts/update.py new file mode 100644 index 0000000..0da3995 --- /dev/null +++ b/scripts/update.py @@ -0,0 +1,157 @@ +import logging +from datetime import datetime +from pathlib import Path +from pprint import PrettyPrinter +from typing import Any, Dict, List, Optional +from urllib.parse import urljoin + +import black +import requests + +from evmchains.types import Chain + +INCLUDE_PROTOCOLS = ["http", "https"] +SOURCE_URL = ( + "https://raw.githubusercontent.com/ethereum-lists/chains/master/_data/chains/" +) +CHAIN_CONST_FILE = Path(__file__).parent.parent / "evmchains" / "chains.py" +BLACKLIST_STRINGS = [ + # 2024-01-19: Node appears to be broken. Returning errors on simple requests. + "rpc.blocknative.com" +] + +# Mapping of Ape ecosystem:network to chain IDs. These are the chains that we will be fetching. +CHAIN_IDS = { + "arbitrum": { + "mainnet": 42161, + "goerli": 421613, + "sepolia": 421614, + }, + "avalanche": { + "mainnet": 43114, + "fuji": 43113, + }, + "base": { + "mainnet": 8453, + "sepolia": 84532, + }, + "bsc": { + "mainnet": 56, + "testnet": 97, + }, + "ethereum": { + "mainnet": 1, + "goerli": 5, + "sepolia": 11155111, + }, + "fantom": { + "mainnet": 250, + "testnet": 4002, + }, + "gnosis": { + "mainnet": 100, + }, + "optimism": { + "mainnet": 10, + "goerli": 420, + "sepolia": 11155420, + }, + "polygon": { + "mainnet": 137, + "mumbai": 80001, + }, + "polygon-zkevm": { + "mainnet": 1101, + "testnet": 1442, + }, +} + +pp = PrettyPrinter(indent=4) +logger = logging.getLogger("update") +logger.setLevel(logging.DEBUG) + + +def stamp() -> str: + """UTC timestamp for file header""" + return str(datetime.utcnow()) + + +def ensure_dict(d: Dict[str, Any], key: str): + if key in d and isinstance(d[key], dict): + return + d[key] = dict() + + +def is_uri_blacklisted(uri: str) -> bool: + """Check if a URI is blacklisted.""" + for blacklisted in BLACKLIST_STRINGS: + if blacklisted in uri: + return True + return False + + +def fetch_chain(chain_id: int) -> Chain: + """Fetch a chain from the ethereum-lists repo.""" + url = urljoin(SOURCE_URL, f"eip155-{chain_id}.json") + + logger.info(f"GET {url}") + r = requests.get(url) + r.raise_for_status() + + chain = Chain.model_validate_json(r.text) + + # Filter out blacklised URIs + chain.rpc = list(filter(lambda rpc: not is_uri_blacklisted(rpc), chain.rpc)) + + # Filter out unwanted protocols (e.g. websocket) + chain.rpc = list( + filter(lambda rpc: rpc.split(":")[0] in INCLUDE_PROTOCOLS, chain.rpc) + ) + + return chain + + +def fetch_chains() -> Dict[str, Dict[str, Chain]]: + """Fetch all chains from the ethereum-lists repo.""" + chains: Dict[str, Dict[str, Chain]] = {} + for ecosystem in CHAIN_IDS.keys(): + for network, chain_id in CHAIN_IDS[ecosystem].items(): + logger.info(f"Fetching chain {ecosystem}:{network} ({chain_id})") + ensure_dict(chains, ecosystem) + chains[ecosystem][network] = fetch_chain(chain_id) + return chains + + +def write_chain_const(chains: Dict[str, Dict[str, Chain]]): + """Write the file with Python constant""" + file_str = "# This file is auto-generated by scripts/update_rpc.py\n" + file_str += f"# {stamp()}\n" + file_str += "# Do not edit this file directly.\n" + file_str += "from typing import Any, Dict, List\n\n" + file_str += "PUBLIC_CHAIN_RPCS: Dict[str, Dict[str, Dict[str, Any]]] = {\n" + + for ecosystem in chains.keys(): + file_str += f' "{ecosystem}": {{\n' + for network, chain in chains[ecosystem].items(): + # pprint to make a somewhat pythonic string output + file_str += f' "{network}": {pp.pformat(chain.model_dump())},\n' + file_str += " },\n" + file_str += "}\n" + + # black to make it actually readable + file_str = black.format_file_contents(file_str, fast=False, mode=black.FileMode()) + + with CHAIN_CONST_FILE.open("w") as const_file: + const_file.write(file_str) + + +def main(): + logger.info("Fetching chain data...") + logger.info(f" Source: {SOURCE_URL}") + logger.info(f" Dest: {CHAIN_CONST_FILE}") + chains = fetch_chains() + write_chain_const(chains) + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6068493 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup() diff --git a/tests/test_func.py b/tests/test_func.py new file mode 100644 index 0000000..71de8fb --- /dev/null +++ b/tests/test_func.py @@ -0,0 +1,28 @@ +from evmchains import PUBLIC_CHAIN_RPCS, Chain, get_chain_meta + + +def test_chain_structure(): + assert "ethereum" in PUBLIC_CHAIN_RPCS + assert "mainnet" in PUBLIC_CHAIN_RPCS["ethereum"] + + chain = PUBLIC_CHAIN_RPCS["ethereum"]["mainnet"] + assert isinstance(chain, dict) + assert len(chain["rpc"]) > 0 + assert chain["chainId"] == 1 + assert chain["networkId"] == 1 + assert chain["shortName"] == "eth" + assert chain["name"] == "Ethereum Mainnet" + assert chain["nativeCurrency"]["symbol"] == "ETH" + assert len(chain["explorers"]) > 0 + + +def test_get_chain_meta(): + chain = get_chain_meta("arbitrum", "mainnet") + assert isinstance(chain, Chain) + assert len(chain.rpc) > 0 + assert chain.chainId == 42161 + assert chain.networkId == 42161 + assert chain.shortName == "arb1" + assert chain.name == "Arbitrum One" + assert chain.nativeCurrency["symbol"] == "ETH" + assert len(chain.explorers) > 0