Skip to content

Commit

Permalink
style: rename ChainType to ChainIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Aug 2, 2024
1 parent 982f8a7 commit b25aa1e
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 69 deletions.
12 changes: 6 additions & 6 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from operate.constants import KEY, KEYS, OPERATE, SERVICES
from operate.ledger import get_ledger_type_from_chain_type
from operate.services.health_checker import HealthChecker
from operate.types import ChainType, DeploymentStatus
from operate.types import ChainIdentifier, DeploymentStatus
from operate.wallet.master import MasterWalletManager


Expand Down Expand Up @@ -349,7 +349,7 @@ async def _get_wallets(request: Request) -> t.List[t.Dict]:
async def _get_wallet_by_chain(request: Request) -> t.List[t.Dict]:
"""Create wallet safe"""
ledger_type = get_ledger_type_from_chain_type(
chain=ChainType[request.path_params["chain"].upper()]
chain=ChainIdentifier[request.path_params["chain"].upper()]
)
manager = operate.wallet_manager
if not manager.exists(ledger_type=ledger_type):
Expand Down Expand Up @@ -378,7 +378,7 @@ async def _create_wallet(request: Request) -> t.List[t.Dict]:
)

data = await request.json()
chain_type = ChainType(data["chain_type"])
chain_type = ChainIdentifier(data["chain_type"])
ledger_type = get_ledger_type_from_chain_type(chain=chain_type)
manager = operate.wallet_manager
if manager.exists(ledger_type=ledger_type):
Expand All @@ -405,7 +405,7 @@ async def _get_safes(request: Request) -> t.List[t.Dict]:
async def _get_safe(request: Request) -> t.List[t.Dict]:
"""Create wallet safe"""
ledger_type = get_ledger_type_from_chain_type(
chain=ChainType[request.path_params["chain"].upper()]
chain=ChainIdentifier[request.path_params["chain"].upper()]
)
manager = operate.wallet_manager
if not manager.exists(ledger_type=ledger_type):
Expand Down Expand Up @@ -436,7 +436,7 @@ async def _create_safe(request: Request) -> t.List[t.Dict]:
)

data = await request.json()
chain_type = ChainType(data["chain_type"])
chain_type = ChainIdentifier(data["chain_type"])
ledger_type = get_ledger_type_from_chain_type(chain=chain_type)
manager = operate.wallet_manager
if not manager.exists(ledger_type=ledger_type):
Expand Down Expand Up @@ -478,7 +478,7 @@ async def _update_safe(request: Request) -> t.List[t.Dict]:
)

data = await request.json()
chain_type = ChainType(data["chain_type"])
chain_type = ChainIdentifier(data["chain_type"])
ledger_type = get_ledger_type_from_chain_type(chain=chain_type)
manager = operate.wallet_manager
if not manager.exists(ledger_type=ledger_type):
Expand Down
48 changes: 24 additions & 24 deletions operate/ledger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from operate.ledger.base import LedgerHelper
from operate.ledger.ethereum import Ethereum
from operate.ledger.solana import Solana
from operate.types import ChainType, LedgerType
from operate.types import ChainIdentifier, LedgerType


ETHEREUM_PUBLIC_RPC = os.environ.get("DEV_RPC", "https://ethereum.publicnode.com")
Expand All @@ -39,24 +39,24 @@
SOLANA_RPC = os.environ.get("DEV_RPC", "https://api.mainnet-beta.solana.com")

PUBLIC_RPCS = {
ChainType.ETHEREUM: ETHEREUM_PUBLIC_RPC,
ChainType.GNOSIS: GNOSIS_PUBLIC_RPC,
ChainType.GOERLI: GOERLI_PUBLIC_RPC,
ChainType.SOLANA: SOLANA_PUBLIC_RPC,
ChainIdentifier.ETHEREUM: ETHEREUM_PUBLIC_RPC,
ChainIdentifier.GNOSIS: GNOSIS_PUBLIC_RPC,
ChainIdentifier.GOERLI: GOERLI_PUBLIC_RPC,
ChainIdentifier.SOLANA: SOLANA_PUBLIC_RPC,
}

DEFAULT_RPCS = {
ChainType.ETHEREUM: ETHEREUM_RPC,
ChainType.GNOSIS: GNOSIS_RPC,
ChainType.GOERLI: GOERLI_RPC,
ChainType.SOLANA: SOLANA_RPC,
ChainIdentifier.ETHEREUM: ETHEREUM_RPC,
ChainIdentifier.GNOSIS: GNOSIS_RPC,
ChainIdentifier.GOERLI: GOERLI_RPC,
ChainIdentifier.SOLANA: SOLANA_RPC,
}

CHAIN_HELPERS: t.Dict[ChainType, t.Type[LedgerHelper]] = {
ChainType.ETHEREUM: Ethereum,
ChainType.GNOSIS: Ethereum,
ChainType.GOERLI: Ethereum,
ChainType.SOLANA: Solana,
CHAIN_HELPERS: t.Dict[ChainIdentifier, t.Type[LedgerHelper]] = {
ChainIdentifier.ETHEREUM: Ethereum,
ChainIdentifier.GNOSIS: Ethereum,
ChainIdentifier.GOERLI: Ethereum,
ChainIdentifier.SOLANA: Solana,
}

LEDGER_HELPERS: t.Dict[LedgerType, t.Type[LedgerHelper]] = {
Expand All @@ -65,26 +65,26 @@
}

CURRENCY_DENOMS = {
ChainType.ETHEREUM: "Wei",
ChainType.GNOSIS: "xDai",
ChainType.GOERLI: "GWei",
ChainType.SOLANA: "Lamp",
ChainIdentifier.ETHEREUM: "Wei",
ChainIdentifier.GNOSIS: "xDai",
ChainIdentifier.GOERLI: "GWei",
ChainIdentifier.SOLANA: "Lamp",
}


def get_default_rpc(chain: ChainType) -> str:
def get_default_rpc(chain: ChainIdentifier) -> str:
"""Get default RPC chain type."""
return DEFAULT_RPCS.get(chain, ETHEREUM_RPC)


def get_ledger_type_from_chain_type(chain: ChainType) -> LedgerType:
"""Get LedgerType from ChainType."""
if chain in (ChainType.ETHEREUM, ChainType.GOERLI, ChainType.GNOSIS):
def get_ledger_type_from_chain_type(chain: ChainIdentifier) -> LedgerType:
"""Get LedgerType from ChainIdentifier."""
if chain in (ChainIdentifier.ETHEREUM, ChainIdentifier.GOERLI, ChainIdentifier.GNOSIS):
return LedgerType.ETHEREUM
return LedgerType.SOLANA


def get_ledger_helper_by_chain(rpc: str, chain: ChainType) -> LedgerHelper:
def get_ledger_helper_by_chain(rpc: str, chain: ChainIdentifier) -> LedgerHelper:
"""Get ledger helper by chain type."""
return CHAIN_HELPERS.get(chain, Ethereum)(rpc=rpc)

Expand All @@ -94,6 +94,6 @@ def get_ledger_helper_by_ledger(rpc: str, ledger: LedgerHelper) -> LedgerHelper:
return LEDGER_HELPERS.get(ledger, Ethereum)(rpc=rpc) # type: ignore


def get_currency_denom(chain: ChainType) -> str:
def get_currency_denom(chain: ChainIdentifier) -> str:
"""Get currency denom by chain type."""
return CURRENCY_DENOMS.get(chain, "Wei")
34 changes: 17 additions & 17 deletions operate/ledger/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

"""Chain profiles."""

from operate.types import ChainType, ContractAddresses
from operate.types import ChainIdentifier, ContractAddresses


CONTRACTS = {
# TODO: autogenerate this when autonomy is bumped to the latest version.
# Cannot be done with the given version.
# The addresses have been manually copied from:
# https://github.com/valory-xyz/open-autonomy/blob/v0.15.1/autonomy/chain/constants.py
ChainType.GNOSIS: ContractAddresses(
ChainIdentifier.GNOSIS: ContractAddresses(
{
"service_manager": "0x04b0007b2aFb398015B76e5f22993a1fddF83644",
"service_registry": "0x9338b5153AE39BB89f50468E608eD9d764B755fD",
Expand All @@ -37,7 +37,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.ETHEREUM: ContractAddresses(
ChainIdentifier.ETHEREUM: ContractAddresses(
{
"service_registry": "0x48b6af7B12C71f09e2fC8aF4855De4Ff54e775cA",
"service_registry_token_utility": "0x3Fb926116D454b95c669B6Bf2E7c3bad8d19affA",
Expand All @@ -47,7 +47,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.GOERLI: ContractAddresses(
ChainIdentifier.GOERLI: ContractAddresses(
{
"service_registry": "0x1cEe30D08943EB58EFF84DD1AB44a6ee6FEff63a",
"service_registry_token_utility": "0x6d9b08701Af43D68D991c074A27E4d90Af7f2276",
Expand All @@ -57,7 +57,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.POLYGON: ContractAddresses(
ChainIdentifier.POLYGON: ContractAddresses(
{
"service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
"service_registry_token_utility": "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8",
Expand All @@ -67,7 +67,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.POLYGON_MUMBAI: ContractAddresses(
ChainIdentifier.POLYGON_MUMBAI: ContractAddresses(
{
"service_registry": "0xf805DfF246CC208CD2F08ffaD242b7C32bc93623",
"service_registry_token_utility": "0x131b5551c81e9B3E89E9ACE30A5B3D45144E3e42",
Expand All @@ -77,7 +77,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.CHIADO: ContractAddresses(
ChainIdentifier.CHIADO: ContractAddresses(
{
"service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855",
"service_registry_token_utility": "0xc2c7E40674f1C7Bb99eFe5680Efd79842502bED4",
Expand All @@ -87,7 +87,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.ARBITRUM_ONE: ContractAddresses(
ChainIdentifier.ARBITRUM_ONE: ContractAddresses(
{
"service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
"service_registry_token_utility": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44",
Expand All @@ -97,7 +97,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.ARBITRUM_SEPOLIA: ContractAddresses(
ChainIdentifier.ARBITRUM_SEPOLIA: ContractAddresses(
{
"service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855",
"service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994",
Expand All @@ -107,7 +107,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.OPTIMISTIC: ContractAddresses(
ChainIdentifier.OPTIMISTIC: ContractAddresses(
{
"service_registry": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44",
"service_registry_token_utility": "0xBb7e1D6Cb6F243D6bdE81CE92a9f2aFF7Fbe7eac",
Expand All @@ -117,7 +117,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.OPTIMISTIC_SEPOLIA: ContractAddresses(
ChainIdentifier.OPTIMISTIC_SEPOLIA: ContractAddresses(
{
"service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855",
"service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994",
Expand All @@ -127,7 +127,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.BASE: ContractAddresses(
ChainIdentifier.BASE: ContractAddresses(
{
"service_registry": "0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE",
"service_registry_token_utility": "0x34C895f302D0b5cf52ec0Edd3945321EB0f83dd5",
Expand All @@ -137,7 +137,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.BASE_SEPOLIA: ContractAddresses(
ChainIdentifier.BASE_SEPOLIA: ContractAddresses(
{
"service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855",
"service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994",
Expand All @@ -147,7 +147,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.CELO: ContractAddresses(
ChainIdentifier.CELO: ContractAddresses(
{
"service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50",
"service_registry_token_utility": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44",
Expand All @@ -157,7 +157,7 @@
"multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D",
}
),
ChainType.CELO_ALFAJORES: ContractAddresses(
ChainIdentifier.CELO_ALFAJORES: ContractAddresses(
{
"service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855",
"service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994",
Expand All @@ -170,9 +170,9 @@
}

STAKING = {
ChainType.GNOSIS: "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A",
ChainIdentifier.GNOSIS: "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A",
}

OLAS = {
ChainType.GNOSIS: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f",
ChainIdentifier.GNOSIS: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f",
}
4 changes: 2 additions & 2 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
from operate.services.deployment_runner import run_host_deployment, stop_host_deployment
from operate.services.utils import tendermint
from operate.types import (
ChainType,
ChainIdentifier,
DeployedNodes,
DeploymentConfig,
DeploymentStatus,
Expand Down Expand Up @@ -244,7 +244,7 @@ def ledger_config(self) -> "LedgerConfig":
(_, config), *_ = override["config"]["ledger_apis"].items()
return LedgerConfig(
rpc=config["address"],
chain=ChainType(config["chain_id"]),
chain=ChainIdentifier(config["chain_id"]),
type=LedgerType.ETHEREUM,
)
raise ValueError("No ledger config found.")
Expand Down
4 changes: 2 additions & 2 deletions operate/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def key_file(self) -> str:
return f"{self.name.lower()}.txt"


class ChainType(enum.IntEnum):
class ChainIdentifier(enum.IntEnum):
"""Chain type enum."""

ETHEREUM = 1
Expand Down Expand Up @@ -138,7 +138,7 @@ class LedgerConfig(LocalResource):

rpc: str
type: LedgerType
chain: ChainType
chain: ChainIdentifier


LedgerConfigs = t.List[LedgerConfig]
Expand Down
Loading

0 comments on commit b25aa1e

Please sign in to comment.