From d4dac28cb03cca2fb20d11a3e98f509d606757e4 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 15 Aug 2024 16:44:15 +0100 Subject: [PATCH] Add duration calculation when using a subscription --- scripts/initiate_ritual.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/scripts/initiate_ritual.py b/scripts/initiate_ritual.py index 7b08678f..8d6d1bcd 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", @@ -110,6 +111,23 @@ def cli( 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: + click.echo( + "Subscription has already started. Subtracting the elapsed time from the duration." + ) + now = chain.blocks.head.timestamp + 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)