forked from nucypher/nucypher-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script that lists all the active rituals that a specified staking pro…
…vider is participating in.
- Loading branch information
1 parent
76daac1
commit 788f98c
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |