Skip to content

Commit

Permalink
Script that lists all the active rituals that a specified staking pro…
Browse files Browse the repository at this point in the history
…vider is participating in.
  • Loading branch information
derekpierre committed Aug 15, 2024
1 parent 76daac1 commit 788f98c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions scripts/ritual_membership.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import click
from ape import networks, project
from ape.cli import ConnectedProviderCommand, network_option
from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address

from deployment.constants import SUPPORTED_TACO_DOMAINS
from deployment.registry import contracts_from_registry
from deployment.utils import registry_filepath_from_domain


@click.command(cls=ConnectedProviderCommand)
@network_option(required=True)
@click.option(
"--domain",
"-d",
help="TACo domain",
type=click.Choice(SUPPORTED_TACO_DOMAINS),
required=True,
)
@click.option(
"--staking-provider-address",
"-p",
help="Staking provider address to check",
type=ChecksumAddress,
required=True,
)
def cli(network, domain, staking_provider_address):
"""Lists all the active rituals that a staking provider is participating in."""
registry_filepath = registry_filepath_from_domain(domain=domain)
contracts = contracts_from_registry(
registry_filepath, chain_id=networks.active_provider.chain_id
)

provider_checksum_address = to_checksum_address(staking_provider_address)
# lower used for comparing against sorted list
provider_checksum_address_lower = provider_checksum_address.lower()

coordinator = project.Coordinator.at(contracts["Coordinator"].address)
num_rituals = coordinator.numberOfRituals()

ritual_memberships = []

for ritual_id in range(0, num_rituals):
if not coordinator.isRitualActive(ritual_id):
continue

participants = coordinator.getParticipants(ritual_id)
for participant in participants:
provider = participant.provider
if provider == provider_checksum_address:
ritual_memberships.append(ritual_id)
break
if provider_checksum_address_lower < provider:
# list of participants is sorted so stop early if already passed
break

if not ritual_memberships:
print(f"\nStaking provider {provider_checksum_address} is not part of any rituals")
return

print("\nActive Ritual Memberships:")
for ritual_id in ritual_memberships:
print(f"\t- ID: #{ritual_id}")

0 comments on commit 788f98c

Please sign in to comment.