Skip to content

Commit

Permalink
Add duration calculation when using a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
theref committed Aug 15, 2024
1 parent 6b12617 commit d4dac28
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion scripts/initiate_ritual.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d4dac28

Please sign in to comment.