From 880928f8d5851b6f5dcc7d8d2e09ffea1c332fdb Mon Sep 17 00:00:00 2001 From: fubuloubu <3859395+fubuloubu@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:47:26 -0400 Subject: [PATCH] feat(CLI): add support for viewing and modifying delegates --- ape_safe/_cli/__init__.py | 2 ++ ape_safe/_cli/delegates.py | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 ape_safe/_cli/delegates.py diff --git a/ape_safe/_cli/__init__.py b/ape_safe/_cli/__init__.py index 58cd73a..4d9529f 100644 --- a/ape_safe/_cli/__init__.py +++ b/ape_safe/_cli/__init__.py @@ -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 @@ -17,3 +18,4 @@ def cli(): cli.add_command(remove) cli.add_command(all_txns) cli.add_command(pending) +cli.add_command(delegates) diff --git a/ape_safe/_cli/delegates.py b/ape_safe/_cli/delegates.py new file mode 100644 index 0000000..1a77cc9 --- /dev/null +++ b/ape_safe/_cli/delegates.py @@ -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)