diff --git a/scripts/initiate_ritual.py b/scripts/initiate_ritual.py index 323d327c..1908c402 100644 --- a/scripts/initiate_ritual.py +++ b/scripts/initiate_ritual.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import click +from ape import chain from ape.cli import ConnectedProviderCommand, account_option, network_option from deployment import registry @@ -25,7 +26,7 @@ "-t", help="Duration of the ritual in seconds. Must be at least 24h.", type=MinInt(86400), - required=True, + required=False, ) @click.option( "--access-controller", @@ -105,6 +106,31 @@ def cli( message="Cannot specify --min-version when using --handpicked.", ) + # Get the contracts from the registry + coordinator_contract = registry.get_contract(domain=domain, contract_name="Coordinator") + access_controller_contract = registry.get_contract(domain=domain, contract_name=access_controller) + fee_model_contract = registry.get_contract(domain=domain, contract_name=fee_model) + + # if using a subcription, duration needs to be calculated + if fee_model == "BqETHSubscription": + start_of_subscription = fee_model_contract.startOfSubscription() + duration = ( + fee_model_contract.subscriptionPeriodDuration() + + fee_model_contract.yellowPeriodDuration() + + fee_model_contract.redPeriodDuration() + ) + if start_of_subscription > 0: + end_of_subscription = fee_model_contract.getEndOfSubscription() + now = chain.blocks.head.timestamp + if now > end_of_subscription: + raise ValueError("Subscription has already ended.") + click.echo( + "Subscription has already started. Subtracting the elapsed time from the duration." + ) + elapsed = now - start_of_subscription + 100 + duration -= elapsed + + # Get the staking providers in the ritual cohort if handpicked: providers = sorted(line.lower() for line in handpicked) @@ -115,20 +141,16 @@ def cli( domain=domain, num_nodes=num_nodes, duration=duration, random_seed=random_seed, min_version=min_version ) - # Get the contracts from the registry - coordinator = registry.get_contract(domain=domain, contract_name="Coordinator") - access_controller = registry.get_contract(domain=domain, contract_name=access_controller) - fee_model = registry.get_contract(domain=domain, contract_name=fee_model) # Initiate the ritual transactor = Transactor(account=account) transactor.transact( - coordinator.initiateRitual, - fee_model.address, + coordinator_contract.initiateRitual, + fee_model_contract.address, providers, authority, duration, - access_controller.address, + access_controller_contract.address, )