Skip to content

Commit

Permalink
feat(CLI): add support for viewing and modifying delegates
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Mar 12, 2024
1 parent 4beb16c commit 880928f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ape_safe/_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click

from ape_safe._cli.delegates import delegates
from ape_safe._cli.pending import pending
from ape_safe._cli.safe_mgmt import _list, add, all_txns, remove

Expand All @@ -17,3 +18,4 @@ def cli():
cli.add_command(remove)
cli.add_command(all_txns)
cli.add_command(pending)
cli.add_command(delegates)
57 changes: 57 additions & 0 deletions ape_safe/_cli/delegates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import click
from ape.cli import ConnectedProviderCommand
from ape.types import AddressType
from eth_typing import ChecksumAddress

from ape_safe._cli.click_ext import callback_factory, safe_argument, safe_cli_ctx, safe_option


@click.group()
def delegates():
"""
Commands for viewing and configuring delegates thru the configured Safe API
"""


@delegates.command("list", cls=ConnectedProviderCommand)
@safe_cli_ctx()
@safe_argument
def _list(cli_ctx, safe):
"""
Show delegates for signers in a Safe
"""
if delegates := safe.client.get_delegates():
cli_ctx.logger.success(f"Found delegates for {safe.address} ({safe.alias})")
for delegator in delegates:
click.echo(f"\nSigner {delegator}:")
click.echo("- " + "\n- ".join(delegates[delegator]))

else:
cli_ctx.logger.error(f"No delegates for {safe.address} ({safe.alias})")


@delegates.command(cls=ConnectedProviderCommand)
@safe_cli_ctx()
@safe_option
@click.argument("delegate", type=ChecksumAddress)
@click.argument("label")
@click.argument("signer", callback=callback_factory.submitter_callback)
def add(cli_ctx, safe, delegate, label, signer):
"""
Add a delegate for a specific signer in a Safe
"""
delegate = cli_ctx.conversion_manager.convert(delegate, AddressType)
safe.client.add_delegate(delegate, label, signer)


@delegates.command(cls=ConnectedProviderCommand)
@safe_cli_ctx()
@safe_option
@click.argument("delegate", type=ChecksumAddress)
@click.argument("signer", callback=callback_factory.submitter_callback)
def remove(cli_ctx, safe, delegate, signer):
"""
Remove a delegate for a specific signer in a Safe
"""
delegate = cli_ctx.conversion_manager.convert(delegate, AddressType)
safe.client.remove_delegate(delegate, signer)

0 comments on commit 880928f

Please sign in to comment.