Skip to content

Commit

Permalink
feat: add remaining networks
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Nov 25, 2024
1 parent a39aa3b commit 74ca075
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ This plugin supports the following ecosystems:

- Arbitrum
- Avalanche
- Base
- Blast
- BSC
- Celo
- Ethereum
- ~~Linea~~ (awaiting ape-linea update)
- Linea
- Mantle
- Optimism
- Palm
- Polygon
- Scroll
- Starknet
- Unichain
- zkSync

## Dependencies

Expand Down
22 changes: 15 additions & 7 deletions ape_infura/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID", "WEB3_INFURA_API_KEY")
# NOTE: https://docs.infura.io/learn/websockets#supported-networks
_WEBSOCKET_CAPABLE_ECOSYSTEMS = {
"ethereum",
"arbitrum",
"optimism",
"polygon",
"linea",
_WEBSOCKET_CAPABLE_NETWORKS = {
"arbitrum": ("mainnet", "sepolia"),
"avalanche": ("fuji", "mainnet"),
"base": ("mainnet", "sepolia"),
"blast": ("mainnet",),
"bsc": ("mainnet", "opbnb"),
"ethereum": ("holesky", "mainnet", "sepolia"),
"linea": ("mainnet", "sepolia"),
"mainnet": ("mainnet",),
"optimism": ("mainnet", "sepolia"),
"polygon": ("amoy", "mainnet"),
"scroll": ("mainnet",),
}


Expand Down Expand Up @@ -83,7 +89,9 @@ def http_uri(self) -> str:
@property
def ws_uri(self) -> Optional[str]:
# NOTE: Overriding `Web3Provider.ws_uri` implementation
if self.network.ecosystem.name not in _WEBSOCKET_CAPABLE_ECOSYSTEMS:
ecosystem_name = self.network.ecosystem.name
network_name = self.network.name
if network_name not in _WEBSOCKET_CAPABLE_NETWORKS.get(ecosystem_name, []):
return None

# Remove `http` in default URI w/ `ws`, also infura adds `/ws` to URI
Expand Down
40 changes: 35 additions & 5 deletions ape_infura/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,54 @@
"fuji",
"mainnet",
],
"base": [
"mainnet",
"sepolia",
],
"blast": [
"mainnet",
"sepolia",
],
"bsc": ["mainnet", "opbnb", "opbnb-testnet", "testnet"],
"celo": [
"alfajores",
"mainnet",
],
"ethereum": [
"holesky",
"mainnet",
"sepolia",
],
"linea": [
"mainnet",
"sepolia",
],
"mantle": [
"mainnet",
"sepolia",
],
# TODO: Comment out after ape-linea supports 0.7
# "linea": [
# "mainnet",
# ],
"optimism": [
"mainnet",
"sepolia",
],
"polygon": [
"palm": [
"mainnet",
"testnet",
],
"polygon": [
"amoy",
"mainnet",
],
"scroll": ["mainnet", "sepolia"],
"starknet": [
"mainnet",
"sepolia",
],
"unichain": [
"sepolia",
],
"zksync": [
"mainnet",
"sepolia",
],
}
2 changes: 1 addition & 1 deletion tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import websocket # type: ignore
from ape.utils import ZERO_ADDRESS

from ape_infura.provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS, Infura
from ape_infura.provider import _WEBSOCKET_CAPABLE_NETWORKS, Infura


def test_infura_http(provider):
Expand Down

0 comments on commit 74ca075

Please sign in to comment.