-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
227 lines (202 loc) · 9.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import os
import requests
import time
import discord
from discord.ext import tasks, commands
TOKEN = os.getenv("TOKEN")
CHANNEL_PUBLIC = 954047687202836540 # multisig-monitor
CHANNELS_PRIVATE = {
"dev": 1159524009390641276, # Badger_dev
"techops": 1159212671770566757, # badger_tech_ops
"treasury_vault": 1159212813034737704, # treasury_vault
"treasury_ops": 1159523577830322287, # treasury_ops
"treasury_voter": 1159523642464542801, # treasury_voter
"ibbtc": 1159523577830322287, # treasury_ops
}
API_CALL_LOOP_PERIOD = 30
SAFES = {
"0xB65cef03b9B89f99517643226d76e286ee999e77": ["dev", "Mainnet", 3],
"0xb364bAb258ad35dd83c7dd4E8AC78676b7aa1e9F": ["dev", "Arbitrum", 3],
"0x329543f0F4BB134A3f7a826DC32532398B38a3fA": ["dev", "Binance Smart Chain", 2],
"0x4977110Ed3CD5eC5598e88c8965951a47dd4e738": ["dev", "Polygon", 3],
# "0x4c56ee3295042f8A5dfC83e770a21c707CB46f5b": ["dev", "Fantom", 3],
"0x0D5eDB3ECbB15EF4EaD105c018fEd4e1d173B335": ["dev", "Optimism", 3],
"0x86cbD0ce0c087b482782c181dA8d191De18C8275": ["techops", "Mainnet", 3],
"0x292549E6bd5a41aE4521Bb8679aDA59631B9eD4C": ["techops", "Arbitrum", 3],
"0xeb7341c89ba46CC7945f75Bd5dD7a04f8FA16327": ["techops", "Polygon", 3],
# "0x781E82D5D49042baB750efac91858cB65C6b0582": ["techops", "Fantom", 3],
"0x8D05c5DA2a3Cb4BeB4C5EB500EE9e3Aa71670733": ["techops", "Optimism", 2],
"0xD0A7A8B98957b9CD3cFB9c0425AbE44551158e9e": ["treasury_vault", "Mainnet", 5],
# "0x45b798384c236ef0d78311D98AcAEc222f8c6F54": ["treasury_vault", "Fantom", 3],
"0x042B32Ac6b453485e357938bdC38e0340d4b9276": ["treasury_ops", "Mainnet", 3],
# "0xf109c50684EFa12d4dfBF501eD4858F25A4300B3": ["treasury_ops", "Fantom", 3],
"0xA9ed98B5Fb8428d68664f3C5027c62A10d45826b": ["treasury_voter", "Mainnet", 5],
"0xB76782B51BFf9C27bA69C77027e20Abd92Bcf3a8": ["ibbtc", "Mainnet", 3],
}
GNOSIS_URLS = {
"Mainnet": "https://safe-transaction-mainnet.safe.global/",
"Binance Smart Chain": "https://safe-transaction-bsc.safe.global/",
"Polygon": "https://safe-transaction-polygon.safe.global/",
"Arbitrum": "https://safe-transaction-arbitrum.safe.global/",
"Optimism": "https://safe-transaction-optimism.safe.global/",
# "Fantom": "https://safe-txservice.fantom.network",
}
GNOSIS_SLUGS = {
"Mainnet": "eth",
"Arbitrum": "arb1",
"Binance Smart Chain": "bnb",
"Polygon": "matic",
"Optimism": "oeth",
}
EXPLORER_URLS = {
"Mainnet": "https://etherscan.io/tx/",
"Binance Smart Chain": "https://bscscan.com/tx/",
"Polygon": "https://polygonscan.com/tx/",
"Arbitrum": "https://arbiscan.io/tx/",
# "Fantom": "https://ftmscan.com/tx/",
"Optimism": "https://optimistic.etherscan.io/tx/",
}
MENTIONS = {
"dev": "<@766785323110891580>", # DAPP
"techops": "<@&1015337028495360040>", # TECH_OPS_MULTISIG
"treasury_vault": "<@&1015338392487202887>", # TREASURY_MULTISIG
"treasury_ops": "<@&1015338392487202887>", # TREASURY_MULTISIG
"treasury_voter": "<@&1015338392487202887>", # TREASURY_MULTISIG
"ibbtc": "<@&1015338392487202887>", # TREASURY_MULTISIG
}
HEADERS = {"accept": "application/json"}
BOT = commands.Bot(command_prefix=["."])
def fetch_thresholds(address):
try:
url = f"{GNOSIS_URLS[SAFES[address][1]]}/api/v1/safes/{address}/"
r = requests.get(url, headers=HEADERS).json()
return r["threshold"]
except Exception as e:
print("fetch thresholds error:", str(e))
return -1
def gnosis_api_call(address):
try:
url = f"{GNOSIS_URLS[SAFES[address][1]]}/api/v1/safes/{address}/multisig-transactions/?limit=5"
r = requests.get(url, headers=HEADERS).json()
return r["results"]
except Exception as e:
print("api call error", str(e))
@BOT.event
async def on_ready():
await BOT.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="Badger DAO's Gnosis Safes",
status=discord.Status.online,
)
)
@tasks.loop(seconds=API_CALL_LOOP_PERIOD)
async def get_data():
global first_run
try:
for address in SAFES:
for safe_tx in gnosis_api_call(address):
try:
creation_date = (
safe_tx["submissionDate"].split(".")[0].replace("T", " ")
)
modified_date = safe_tx["modified"].split(".")[0].replace("T", " ")
safe_tx_hash = safe_tx["safeTxHash"]
is_executed = safe_tx["isExecuted"]
if [safe_tx_hash, modified_date, is_executed] in prev_safe_tx_hash:
continue
prev_safe_tx_hash.append([safe_tx_hash, modified_date, is_executed])
if first_run:
continue
nonce = safe_tx["nonce"]
chain = SAFES[address][1]
if chain == "Fantom":
gnosis_url = f"https://safe.fantom.network/#/safes/{address}/transactions"
else:
gnosis_url = f"https://app.safe.global/{GNOSIS_SLUGS[chain]}:{address}/transactions/tx?id=multisig_{address}_{safe_tx_hash}"
if safe_tx["transactionHash"] is None:
tx_hash = "n/a"
tx_url = "n/a"
else:
tx_hash = safe_tx["transactionHash"]
tx_url = EXPLORER_URLS[chain] + tx_hash
confirmations = safe_tx["confirmations"]
confirmations_required = SAFES[address][2]
if safe_tx["isSuccessful"] is None:
is_successful = "n/a"
elif safe_tx["isSuccessful"] == True:
is_successful = "Success"
else:
is_successful = "Fail"
description = f"""
safe: **`{address}`**
nonce: **{nonce}**
safe_tx_hash: [`{safe_tx_hash}`]({gnosis_url})
tx_hash: [`{tx_hash}`]({tx_url})
signatures: **{len(confirmations)}/{confirmations_required}**
executed: **{is_executed}**
tx status: **{is_successful}**
'ready to sign' issue board: [https://github.com/orgs/Badger-Finance/projects/25/views/16](https://github.com/orgs/Badger-Finance/projects/25/views/16)
(modified {modified_date}, created {creation_date})
"""
title_suffix = f"{SAFES[address][0]} ({chain})"
if is_executed == False and is_successful != "n/a":
# some weird false positive
continue
elif is_executed == True:
tag = "[TX EXECUTED]"
public = True
private = True
mention = False
elif len(confirmations) == confirmations_required:
tag = "[READY FOR EXEC]"
public = True
private = False
mention = False
elif len(confirmations) == 0:
tag = "[NEW TX]"
public = True
private = True
mention = True
else:
continue
embed = discord.Embed(
title=f"{tag} {title_suffix}",
description=description,
color=0x00FF00,
)
if public:
channel = BOT.get_channel(CHANNEL_PUBLIC)
await channel.send(embed=embed)
if private:
channel = BOT.get_channel(CHANNELS_PRIVATE[SAFES[address][0]])
await channel.send(embed=embed)
if mention:
await channel.send(MENTIONS[SAFES[address][0]])
except Exception as e:
print("parse error", str(e))
if first_run:
first_run = False
# give sign of life to show bot is healthy and back online
channel = BOT.get_channel(CHANNEL_PUBLIC)
await channel.send("\U0001F916")
print("\U0001F916")
except Exception as e:
print("main func error:", str(e))
@get_data.before_loop
async def before_name_change():
await BOT.wait_until_ready()
if __name__ == "__main__":
try:
# overwrite (default) signing threshold with actual data from api
for safe in SAFES:
threshold = fetch_thresholds(safe)
if threshold != -1:
SAFES[safe][2] = threshold
time.sleep(0.2)
except Exception as e:
print("update thresholds error:", str(e))
first_run = True
prev_safe_tx_hash = []
get_data.start()
BOT.run(TOKEN)