diff --git a/operate/cli.py b/operate/cli.py index b6388f9b2..e2d396772 100644 --- a/operate/cli.py +++ b/operate/cli.py @@ -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 @@ -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): @@ -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): @@ -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): @@ -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): @@ -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): diff --git a/operate/ledger/__init__.py b/operate/ledger/__init__.py index 078a93d1e..55c1fd2a4 100644 --- a/operate/ledger/__init__.py +++ b/operate/ledger/__init__.py @@ -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") @@ -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]] = { @@ -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) @@ -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") diff --git a/operate/ledger/profiles.py b/operate/ledger/profiles.py index 9292c8ece..ed66a60e6 100644 --- a/operate/ledger/profiles.py +++ b/operate/ledger/profiles.py @@ -19,7 +19,7 @@ """Chain profiles.""" -from operate.types import ChainType, ContractAddresses +from operate.types import ChainIdentifier, ContractAddresses CONTRACTS = { @@ -27,7 +27,7 @@ # 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", @@ -37,7 +37,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.ETHEREUM: ContractAddresses( + ChainIdentifier.ETHEREUM: ContractAddresses( { "service_registry": "0x48b6af7B12C71f09e2fC8aF4855De4Ff54e775cA", "service_registry_token_utility": "0x3Fb926116D454b95c669B6Bf2E7c3bad8d19affA", @@ -47,7 +47,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.GOERLI: ContractAddresses( + ChainIdentifier.GOERLI: ContractAddresses( { "service_registry": "0x1cEe30D08943EB58EFF84DD1AB44a6ee6FEff63a", "service_registry_token_utility": "0x6d9b08701Af43D68D991c074A27E4d90Af7f2276", @@ -57,7 +57,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.POLYGON: ContractAddresses( + ChainIdentifier.POLYGON: ContractAddresses( { "service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50", "service_registry_token_utility": "0xa45E64d13A30a51b91ae0eb182e88a40e9b18eD8", @@ -67,7 +67,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.POLYGON_MUMBAI: ContractAddresses( + ChainIdentifier.POLYGON_MUMBAI: ContractAddresses( { "service_registry": "0xf805DfF246CC208CD2F08ffaD242b7C32bc93623", "service_registry_token_utility": "0x131b5551c81e9B3E89E9ACE30A5B3D45144E3e42", @@ -77,7 +77,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.CHIADO: ContractAddresses( + ChainIdentifier.CHIADO: ContractAddresses( { "service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855", "service_registry_token_utility": "0xc2c7E40674f1C7Bb99eFe5680Efd79842502bED4", @@ -87,7 +87,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.ARBITRUM_ONE: ContractAddresses( + ChainIdentifier.ARBITRUM_ONE: ContractAddresses( { "service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50", "service_registry_token_utility": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44", @@ -97,7 +97,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.ARBITRUM_SEPOLIA: ContractAddresses( + ChainIdentifier.ARBITRUM_SEPOLIA: ContractAddresses( { "service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855", "service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994", @@ -107,7 +107,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.OPTIMISTIC: ContractAddresses( + ChainIdentifier.OPTIMISTIC: ContractAddresses( { "service_registry": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44", "service_registry_token_utility": "0xBb7e1D6Cb6F243D6bdE81CE92a9f2aFF7Fbe7eac", @@ -117,7 +117,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.OPTIMISTIC_SEPOLIA: ContractAddresses( + ChainIdentifier.OPTIMISTIC_SEPOLIA: ContractAddresses( { "service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855", "service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994", @@ -127,7 +127,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.BASE: ContractAddresses( + ChainIdentifier.BASE: ContractAddresses( { "service_registry": "0x3C1fF68f5aa342D296d4DEe4Bb1cACCA912D95fE", "service_registry_token_utility": "0x34C895f302D0b5cf52ec0Edd3945321EB0f83dd5", @@ -137,7 +137,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.BASE_SEPOLIA: ContractAddresses( + ChainIdentifier.BASE_SEPOLIA: ContractAddresses( { "service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855", "service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994", @@ -147,7 +147,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.CELO: ContractAddresses( + ChainIdentifier.CELO: ContractAddresses( { "service_registry": "0xE3607b00E75f6405248323A9417ff6b39B244b50", "service_registry_token_utility": "0x3d77596beb0f130a4415df3D2D8232B3d3D31e44", @@ -157,7 +157,7 @@ "multisend": "0x40A2aCCbd92BCA938b02010E17A5b8929b49130D", } ), - ChainType.CELO_ALFAJORES: ContractAddresses( + ChainIdentifier.CELO_ALFAJORES: ContractAddresses( { "service_registry": "0x31D3202d8744B16A120117A053459DDFAE93c855", "service_registry_token_utility": "0xeB49bE5DF00F74bd240DE4535DDe6Bc89CEfb994", @@ -170,9 +170,9 @@ } STAKING = { - ChainType.GNOSIS: "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A", + ChainIdentifier.GNOSIS: "0xEE9F19b5DF06c7E8Bfc7B28745dcf944C504198A", } OLAS = { - ChainType.GNOSIS: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f", + ChainIdentifier.GNOSIS: "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f", } diff --git a/operate/services/service.py b/operate/services/service.py index afec1d2ca..c49854725 100644 --- a/operate/services/service.py +++ b/operate/services/service.py @@ -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, @@ -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.") diff --git a/operate/types.py b/operate/types.py index cc7d9616f..04ce310f6 100644 --- a/operate/types.py +++ b/operate/types.py @@ -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 @@ -138,7 +138,7 @@ class LedgerConfig(LocalResource): rpc: str type: LedgerType - chain: ChainType + chain: ChainIdentifier LedgerConfigs = t.List[LedgerConfig] diff --git a/operate/wallet/master.py b/operate/wallet/master.py index d4d64bc6c..16fa6307e 100644 --- a/operate/wallet/master.py +++ b/operate/wallet/master.py @@ -38,7 +38,7 @@ ) from operate.ledger import get_default_rpc from operate.resource import LocalResource -from operate.types import ChainType, LedgerType +from operate.types import ChainIdentifier, LedgerType from operate.utils.gnosis import add_owner from operate.utils.gnosis import create_safe as create_gnosis_safe from operate.utils.gnosis import get_owners, swap_owner @@ -83,7 +83,7 @@ def key_path(self) -> Path: def ledger_api( self, - chain_type: ChainType, + chain_type: ChainIdentifier, rpc: t.Optional[str] = None, ) -> LedgerApi: """Get ledger api object.""" @@ -97,7 +97,7 @@ def transfer( self, to: str, amount: int, - chain_type: ChainType, + chain_type: ChainIdentifier, from_safe: bool = True, ) -> None: """Transfer funds to the given account.""" @@ -110,7 +110,7 @@ def new(password: str, path: Path) -> t.Tuple["MasterWallet", t.List[str]]: def create_safe( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: t.Optional[str] = None, rpc: t.Optional[str] = None, ) -> None: @@ -119,7 +119,7 @@ def create_safe( def add_backup_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: str, rpc: t.Optional[str] = None, ) -> None: @@ -128,7 +128,7 @@ def add_backup_owner( def swap_backup_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, old_owner: str, new_owner: str, rpc: t.Optional[str] = None, @@ -138,7 +138,7 @@ def swap_backup_owner( def add_or_swap_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: str, rpc: t.Optional[str] = None, ) -> None: @@ -152,7 +152,7 @@ class EthereumMasterWallet(MasterWallet): path: Path address: str - safe_chains: t.List[ChainType] # For cross-chain support + safe_chains: t.List[ChainIdentifier] # For cross-chain support ledger_type: LedgerType = LedgerType.ETHEREUM safe: t.Optional[str] = None @@ -162,7 +162,7 @@ class EthereumMasterWallet(MasterWallet): _key = ledger_type.key_file _crypto_cls = EthereumCrypto - def _transfer_from_eoa(self, to: str, amount: int, chain_type: ChainType) -> None: + def _transfer_from_eoa(self, to: str, amount: int, chain_type: ChainIdentifier) -> None: """Transfer funds from EOA wallet.""" ledger_api = t.cast(EthereumApi, self.ledger_api(chain_type=chain_type)) tx_helper = TxSettler( @@ -195,7 +195,7 @@ def _build_tx( # pylint: disable=unused-argument setattr(tx_helper, "build", _build_tx) # noqa: B010 tx_helper.transact(lambda x: x, "", kwargs={}) - def _transfer_from_safe(self, to: str, amount: int, chain_type: ChainType) -> None: + def _transfer_from_safe(self, to: str, amount: int, chain_type: ChainIdentifier) -> None: """Transfer funds from safe wallet.""" transfer_from_safe( ledger_api=self.ledger_api(chain_type=chain_type), @@ -209,7 +209,7 @@ def transfer( self, to: str, amount: int, - chain_type: ChainType, + chain_type: ChainIdentifier, from_safe: bool = True, ) -> None: """Transfer funds to the given account.""" @@ -253,7 +253,7 @@ def new( def create_safe( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: t.Optional[str] = None, rpc: t.Optional[str] = None, ) -> None: @@ -271,7 +271,7 @@ def create_safe( def add_backup_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: str, rpc: t.Optional[str] = None, ) -> None: @@ -288,7 +288,7 @@ def add_backup_owner( def swap_backup_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, old_owner: str, new_owner: str, rpc: t.Optional[str] = None, @@ -307,7 +307,7 @@ def swap_backup_owner( def add_or_swap_owner( self, - chain_type: ChainType, + chain_type: ChainIdentifier, owner: str, rpc: t.Optional[str] = None, ) -> None: diff --git a/scripts/setup_wallet.py b/scripts/setup_wallet.py index f17dbdcb6..524356ed8 100644 --- a/scripts/setup_wallet.py +++ b/scripts/setup_wallet.py @@ -21,7 +21,7 @@ import requests -from operate.types import ChainType +from operate.types import ChainIdentifier from scripts.fund import fund @@ -48,7 +48,7 @@ wallet = requests.post( "http://localhost:8000/api/wallet", json={ - "chain_type": ChainType.GNOSIS, + "chain_type": ChainIdentifier.GNOSIS, }, ).json() print("Setting up wallet") @@ -61,7 +61,7 @@ requests.post( "http://localhost:8000/api/wallet/safe", json={ - "chain_type": ChainType.GNOSIS, + "chain_type": ChainIdentifier.GNOSIS, "owner": "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC", # Backup owner }, ).json()