Skip to content

Commit

Permalink
Merge pull request #306 from theref/duration
Browse files Browse the repository at this point in the history
Add duration calculation for subscription based rituals
  • Loading branch information
cygnusv authored Aug 21, 2024
2 parents 9e115b6 + 2619079 commit 0067b74
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions 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 @@ -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)
Expand All @@ -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,
)


Expand Down

0 comments on commit 0067b74

Please sign in to comment.