diff --git a/price-pusher/poetry.lock b/price-pusher/poetry.lock index 3cadf5f4..4d98526a 100644 --- a/price-pusher/poetry.lock +++ b/price-pusher/poetry.lock @@ -2248,4 +2248,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "7d4b7ec95a03290d536c949f466fe3e815d2cee650d8a0e99c7672ebc1c7d8bf" +content-hash = "5c63d1e724ae5c30ac58f6c44f83638f4bf4a8bd879702f2e81be7f0ee8dc32f" diff --git a/price-pusher/pyproject.toml b/price-pusher/pyproject.toml index c094980d..c6148b6a 100644 --- a/price-pusher/pyproject.toml +++ b/price-pusher/pyproject.toml @@ -24,8 +24,6 @@ pragma-sdk = { path = "../pragma-sdk", develop = true } pragma-utils = { path = "../pragma-utils", develop = true } click = "^8.1.0" pydantic = "^2.7.4" -boto3 = "^1.28.61" -moto = { extras = ["s3", "secretsmanager"], version = "^4.2.5" } [tool.poetry.group.dev.dependencies] poethepoet = "^0.26.1" diff --git a/vrf-listener/poetry.lock b/vrf-listener/poetry.lock index 3cadf5f4..6b7e92e0 100644 --- a/vrf-listener/poetry.lock +++ b/vrf-listener/poetry.lock @@ -2248,4 +2248,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "7d4b7ec95a03290d536c949f466fe3e815d2cee650d8a0e99c7672ebc1c7d8bf" +content-hash = "3891187df1af7e222b915f26b036597fd6bfc53141d2e8e1f0eb3ba7047eff48" diff --git a/vrf-listener/pyproject.toml b/vrf-listener/pyproject.toml index e1c17ce9..ed41ea7f 100644 --- a/vrf-listener/pyproject.toml +++ b/vrf-listener/pyproject.toml @@ -23,9 +23,6 @@ python = ">=3.10,<3.13" pragma-sdk = { path = "../pragma-sdk", develop = true } pragma-utils = { path = "../pragma-utils", develop = true } click = "^8.1.0" -pydantic = "^2.7.4" -boto3 = "^1.28.61" -moto = { extras = ["s3", "secretsmanager"], version = "^4.2.5" } [tool.poetry.group.dev.dependencies] poethepoet = "^0.26.1" @@ -102,7 +99,7 @@ exclude = [] generate-setup-file = true [tool.coverage.run] -source = ["price-pusher"] +source = ["vrf-listener"] [tool.coverage.report] omit = ["*_test.py", "tests/*"] diff --git a/vrf-listener/vrf_listener/main.py b/vrf-listener/vrf_listener/main.py index 5bd95657..cf9f76d8 100644 --- a/vrf-listener/vrf_listener/main.py +++ b/vrf-listener/vrf_listener/main.py @@ -7,26 +7,35 @@ from pragma_utils.logger import setup_logging from pragma_utils.cli import load_private_key_from_cli_arg +from pragma_sdk.onchain.client import PragmaOnChainClient + logger = logging.getLogger(__name__) -async def main(): - pass - # client = PragmaOnChainClient( - # network=RPC_URL, - # account_private_key=admin_private_key, - # account_contract_address=ADMIN_CONTRACT_ADDRESS, - # chain_name=NETWORK, - # ) - # client.init_randomness_contract(VRF_CONTRACT_ADDRESS) +async def main( + network: str, + rpc_url: Optional[str], + vrf_address: str, + admin_address: str, + private_key: str, + start_block: int, + update_time_interval: int, +) -> None: + client = PragmaOnChainClient( + network=rpc_url, + account_contract_address=admin_address, + account_private_key=private_key, + chain_name=network, + ) + client.init_randomness_contract(vrf_address) - # while True: - # logger.info("Checking for randomness requests...") - # try: - # await client.handle_random(admin_private_key, START_BLOCK) - # except Exception as e: - # logger.error("Error handling randomness requests: %s", e) - # await asyncio.sleep(VRF_UPDATE_TIME_SECONDS) + while True: + logger.info("Checking for randomness requests...") + try: + await client.handle_random(private_key, start_block) + except Exception as e: + logger.error("Error handling randomness requests: %s", e) + await asyncio.sleep(update_time_interval) @click.command() @@ -39,9 +48,10 @@ async def main(): @click.option( "-n", "--network", - required=True, + required=False, + default="sepolia", type=click.Choice(["sepolia", "mainnet"], case_sensitive=False), - help="At which network the price corresponds.", + help="Which network to listen. Defaults to SEPOLIA.", ) @click.option( "--rpc-url", @@ -50,14 +60,12 @@ async def main(): help="RPC url used by the onchain client.", ) @click.option( - "-v", "--vrf-address", type=click.STRING, required=True, help="Address of the VRF contract", ) @click.option( - "-a", "--admin-address", type=click.STRING, required=True, @@ -71,12 +79,19 @@ async def main(): help="Secret key of the signer. Format: aws:secret_name, plain:secret_key, or env:ENV_VAR_NAME", ) @click.option( - "--start-block", + "-b" "--start-block", type=click.INT, required=False, default=0, help="At which block to start listening for VRF requests. Defaults to 0.", ) +@click.option( + "-t" "--update-time-interval", + type=click.INT, + required=False, + default=10, + help="Delay in seconds between VRF checks. Defaults to 10 seconds.", +) def cli_entrypoint( log_level: str, network: str, @@ -85,6 +100,7 @@ def cli_entrypoint( admin_address: str, private_key: str, start_block: int, + update_time_interval: int, ) -> None: """ Click does not support async functions. @@ -95,7 +111,17 @@ def cli_entrypoint( setup_logging(logger, log_level) private_key = load_private_key_from_cli_arg(private_key) - asyncio.run(main()) + asyncio.run( + main( + network, + rpc_url, + vrf_address, + admin_address, + private_key, + start_block, + update_time_interval, + ) + ) if __name__ == "__main__":