From e3dd4e7c96ca60116af142015bd63a3f8a475505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Ribeiro?= Date: Tue, 20 Feb 2024 12:55:35 -0300 Subject: [PATCH] refactor core.constants --- cow_py/core/constants.py | 37 ++++++++++++++++++++------------- cow_py/subgraphs/base/client.py | 1 + tests/core/test_cow_error.py | 1 - 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/cow_py/core/constants.py b/cow_py/core/constants.py index f71d666..de7eb05 100644 --- a/cow_py/core/constants.py +++ b/cow_py/core/constants.py @@ -1,34 +1,41 @@ +from enum import Enum from typing import Dict from .chains import Chain +""" +This module contains constants and functions related to the CoW Protocol. It provides mappings of +the main CoW contract addresses to CoW's supported networks. +""" + BUY_ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" -VAULT_RELAYER = "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110" -COMPOSABLE_COW = "0xfdaFc9d1902f4e0b84f65F49f244b32b31013b74" -SETTLEMENT_CONTRACT = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41" -EXTENSIBLE_FALLBACK_HANDLER = "0x2f55e8b20D0B9FEFA187AA7d00B6Cbe563605bF5" + +class CowContractAddress(Enum): + VAULT_RELAYER = "0xC92E8bdf79f0507f65a392b0ab4667716BFE0110" + COMPOSABLE_COW = "0xfdaFc9d1902f4e0b84f65F49f244b32b31013b74" + SETTLEMENT_CONTRACT = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41" + EXTENSIBLE_FALLBACK_HANDLER = "0x2f55e8b20D0B9FEFA187AA7d00B6Cbe563605bF5" def map_address_to_supported_networks(address: str) -> Dict[Chain, str]: + """ + Maps a given address to all supported networks. + + :param address: The address to be mapped. + :return: A dictionary mapping the address to each supported chain. + """ return {chain_id: address for chain_id in Chain} -""" An object containing the addresses of the CoW Protocol settlement contracts for each supported chain. """ COW_PROTOCOL_SETTLEMENT_CONTRACT_CHAIN_ADDRESS_MAP = map_address_to_supported_networks( - SETTLEMENT_CONTRACT + CowContractAddress.SETTLEMENT_CONTRACT ) - -""" An object containing the addresses of the CoW Protocol Vault relayer contracts for each supported chain. """ COW_PROTOCOL_VAULT_RELAYER_CHAIN_ADDRESS_MAP = map_address_to_supported_networks( - VAULT_RELAYER + CowContractAddress.VAULT_RELAYER ) - -""" An object containing the addresses of the `ExtensibleFallbackHandler` contracts for each supported chain. """ EXTENSIBLE_FALLBACK_HANDLER_CONTRACT_CHAIN_ADDRESS_MAP = ( - map_address_to_supported_networks(EXTENSIBLE_FALLBACK_HANDLER) + map_address_to_supported_networks(CowContractAddress.EXTENSIBLE_FALLBACK_HANDLER) ) - -""" An object containing the addresses of the `ComposableCow` contracts for each supported chain. """ COMPOSABLE_COW_CONTRACT_CHAIN_ADDRESS_MAP = map_address_to_supported_networks( - COMPOSABLE_COW + CowContractAddress.COMPOSABLE_COW ) diff --git a/cow_py/subgraphs/base/client.py b/cow_py/subgraphs/base/client.py index 20dce3e..a9e82bf 100644 --- a/cow_py/subgraphs/base/client.py +++ b/cow_py/subgraphs/base/client.py @@ -7,6 +7,7 @@ import httpx + class GraphQLError(Exception): pass diff --git a/tests/core/test_cow_error.py b/tests/core/test_cow_error.py index d97e8ea..6f09344 100644 --- a/tests/core/test_cow_error.py +++ b/tests/core/test_cow_error.py @@ -1,4 +1,3 @@ -import pytest from cow_py.core.cow_error import ( CowError, ) # Adjust the import path according to your project structure