Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord propose #221

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions assistant/rewards/rewards_assistant.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from helpers.discord import send_message_to_discord
from assistant.subgraph.client import fetch_wallet_balances
import json
from brownie import *
Expand Down Expand Up @@ -305,6 +306,18 @@ def rootUpdater(badger, startBlock, endBlock, pastRewards, saveLocalFile, test=F
upload(
rewards_data["contentFileName"], rewards_data["merkleTree"], publish=False
)
send_message_to_discord(
"**CYCLE PROPOSED AND UPLOADED**",
f'Badger Cycle {rewards_data["merkleTree"]["cycle"]} Proposed',
[
{
"name": "Block Info",
"value": f'Start: {rewards_data["merkleTree"]["startBlock"]}\nEnd: {rewards_data["merkleTree"]["endBlock"]}',
"inline": True,
}
],
"Badger Cycle Proposer",
)

return rewards_data

Expand Down Expand Up @@ -352,6 +365,19 @@ def guardian(
)
upload(rewards_data["contentFileName"], rewards_data["merkleTree"]),

send_message_to_discord(
"**CYCLE APPROVED AND UPLOADED**",
f'Badger Cycle {rewards_data["merkleTree"]["cycle"]} Complete',
[
{
"name": "Block Info",
"value": f'Start: {rewards_data["merkleTree"]["startBlock"]}\nEnd: {rewards_data["merkleTree"]["endBlock"]}',
"inline": True,
}
],
"Badger Cycle Approver",
)


def run_action(badger, args, test, saveLocalFile=True):
if args["action"] == "rootUpdater":
Expand Down
8 changes: 8 additions & 0 deletions config/env_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def __init__(self):
)
self.graph_api_key = decouple.config("GRAPH_API_KEY")
self.debug = debug
self.test_webhook_url = decouple.config("TEST_WEBHOOK_URL")
self.discord_webhook_url = decouple.config("DISCORD_WEBHOOK_URL")

def get_webhook_url(self):
if self.debug:
return self.test_webhook_url
else:
return self.discord_webhook_url


env_config = EnvConfig()
19 changes: 19 additions & 0 deletions helpers/discord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from discord import Webhook, RequestsWebhookAdapter, Embed
from config.env_config import env_config


def send_message_to_discord(title: str, description: str, fields: list, username: str):

webhook = Webhook.from_url(
env_config.get_webhook_url(),
adapter=RequestsWebhookAdapter(),
)

embed = Embed(title=title, description=description)

for field in fields:
embed.add_field(
name=field.get("name"), value=field.get("value"), inline=field.get("inline")
)

webhook.send(embed=embed, username=username)
6 changes: 6 additions & 0 deletions scripts/rewards/auto/approve_root_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from helpers.gas_utils import gas_strategies

from assistant.rewards.rewards_assistant import fetch_current_rewards_tree, run_action
from helpers.discord import send_message_to_discord

console = Console()

Expand Down Expand Up @@ -41,5 +42,10 @@ def main():
approve_root(badger)
except Exception as e:
console.print("[red]Error[/red]", e)
send_message_to_discord(
"**ERROR APPROVING ROOT**",
"approve_root_auto.py has encountered an error",
[{"name": "Error", "value": e, "inline": True}],
)
finally:
time.sleep(10 * 60)
6 changes: 6 additions & 0 deletions scripts/rewards/auto/propose_root_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from scripts.systems.badger_system import BadgerSystem, connect_badger
from scripts.rewards.propose_root import propose_root
from assistant.rewards.rewards_assistant import fetch_current_rewards_tree, run_action
from helpers.discord import send_message_to_discord

console = Console()

Expand All @@ -21,5 +22,10 @@ def main():
propose_root(badger)
except Exception as e:
console.print("[red]Error[/red]", e)
send_message_to_discord(
"**ERROR PROPOSING ROOT**",
"propose_root_auto.py has encountered an error",
[{"name": "Error", "value": e, "inline": True}],
)
finally:
time.sleep(10 * 60)