From a3213a8ecd08bd267591f19fe4510a67b78521dc Mon Sep 17 00:00:00 2001 From: bram-vdberg Date: Thu, 16 Jan 2025 12:40:04 +0100 Subject: [PATCH] Add a flag to send dry-run results to slack (#492) This PR adds a flag to send the results from the dry-run to a slack channel. --- src/fetch/transfer_file.py | 35 ++++++++++++++++++++++++++++++++++- src/utils/script_args.py | 7 +++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/fetch/transfer_file.py b/src/fetch/transfer_file.py index 0260dc93..e6efbd67 100644 --- a/src/fetch/transfer_file.py +++ b/src/fetch/transfer_file.py @@ -59,10 +59,13 @@ def dashboard_url(period: AccountingPeriod, config: AccountingConfig) -> str: return base + urllib.parse.quote_plus(slug + query, safe="=&?") -def manual_propose( +def manual_propose( # pylint: disable=too-many-arguments, too-many-positional-arguments transfers: list[Transfer], period: AccountingPeriod, config: AccountingConfig, + send_to_slack: bool = False, + slack_client: WebClient | None = None, + log_saver_obj: PrintStore | None = None, ) -> None: """ Entry point to manual creation of rewards payout transaction. @@ -76,6 +79,20 @@ def manual_propose( print(Transfer.summarize(transfers)) print("Please cross check these results with the dashboard linked above.\n") + if send_to_slack: + slack_channel = config.io_config.slack_channel + assert slack_channel is not None + + post_to_slack( + slack_client, # type: ignore + channel=slack_channel, + message=( + f"""Solver Rewards dry-run results for network {config.dune_config.dune_blockchain} + More details in thread""" + ), + sub_messages=log_saver_obj.get_values(), # type: ignore + ) + def auto_propose( transfers: list[Transfer], @@ -195,6 +212,22 @@ def main() -> None: dry_run=args.dry_run, config=config, ) + elif args.send_to_slack: + ssl_context = ssl.create_default_context(cafile=certifi.where()) + ssl_context.verify_mode = ssl.CERT_REQUIRED + slack_client = WebClient( + token=config.io_config.slack_token, + # https://stackoverflow.com/questions/59808346/python-3-slack-client-ssl-sslcertverificationerror + ssl=ssl_context, + ) + manual_propose( + transfers=payout_transfers, + period=dune.period, + config=config, + send_to_slack=args.send_to_slack, + slack_client=slack_client, + log_saver_obj=log_saver, + ) else: manual_propose(transfers=payout_transfers, period=dune.period, config=config) diff --git a/src/utils/script_args.py b/src/utils/script_args.py index 5e791403..39cd1df1 100644 --- a/src/utils/script_args.py +++ b/src/utils/script_args.py @@ -13,6 +13,7 @@ class ScriptArgs: post_tx: bool dry_run: bool ignore_slippage: bool + send_to_slack: bool def generic_script_init(description: str) -> ScriptArgs: @@ -44,10 +45,16 @@ def generic_script_init(description: str) -> ScriptArgs: action="store_true", help="Flag for ignoring slippage computations", ) + parser.add_argument( + "--send-to-slack", + action="store_true", + help="Flag indicating whether or not the script should send the results to a slack channel", + ) args = parser.parse_args() return ScriptArgs( start=args.start, post_tx=args.post_tx, dry_run=args.dry_run, ignore_slippage=args.ignore_slippage, + send_to_slack=args.send_to_slack, )