Skip to content

Commit

Permalink
Add a flag to send dry-run results to slack (#492)
Browse files Browse the repository at this point in the history
This PR adds a flag to send the results from the dry-run to a slack
channel.
  • Loading branch information
bram-vdberg authored Jan 16, 2025
1 parent ac16615 commit a3213a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/fetch/transfer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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],
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions src/utils/script_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
)

0 comments on commit a3213a8

Please sign in to comment.