Skip to content

Commit

Permalink
make summary bot, and looping every 30 urgent bot, update to use jeet…
Browse files Browse the repository at this point in the history
… for realm, etc (#16)
  • Loading branch information
ggnine-jito authored Jan 9, 2024
1 parent 13fbdc7 commit d928bf1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
17 changes: 17 additions & 0 deletions pages/api/gov-notifier-summary.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { withSentry } from '@sentry/nextjs'
import { runNotifier } from '../../scripts/governance-notifier'

async function handler(req, res) {
if (req?.headers?.authorization !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).send('Unauthorized')
}
try {
await runNotifier(true)
res.status(200).send('Summary notifier executed successfully')
} catch (error) {
console.error(error)
res.status(500).send('Error executing summary notifier')
}
}

export default withSentry(handler)
13 changes: 13 additions & 0 deletions public/realms/mainnet-beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2431,6 +2431,19 @@
"discord": "https://discord.com/invite/jito",
"github": "https://github.com/jito-foundation"
},
{
"symbol": "jeet",
"category": "defi",
"displayName": "jeet",
"programId": "GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw",
"realmId": "8vUkDSfizbM8gwKSefBeBz2LeZrFi9utebtauJuwzKe2",
"ogImage": "https://imgur.com/a/N3tf7e8",
"sortRank": 3,
"website": "https://dog.goblin.dog.doodad.dog.doodie/",
"twitter": "",
"discord": "https://dog.goblin.dog.doodad.dog.doodie",
"github": "https://dog.goblin.dog.doodad.dog.doodie"
},
{
"symbol": "Elusiv",
"category": "other",
Expand Down
35 changes: 16 additions & 19 deletions scripts/governance-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { accountsToPubkeyMap } from '@tools/sdk/accounts'
import { fmtTokenAmount } from '@utils/formatting'
import { formatNumber } from '@utils/formatNumber'

const fiveMinutesSeconds = 5 * 60
const thirtyMinutesSeconds = 30 * 60
const toleranceSeconds = 30

const maxRetries = 3
const maxRetries = 4
const retryDelay = 5000

async function sendWebhook(webhookUrl, data, retries = maxRetries) {
Expand Down Expand Up @@ -46,8 +46,9 @@ export function errorWrapper() {
})
}

export async function runNotifier() {
const REALM = 'Jito'
const REALM = 'jeet'

export async function runNotifier(summaryOnly = false) {
console.log('Starting governance notifier')
const connectionContext = getConnectionContext('mainnet')
const realmInfo = await getCertifiedRealmInfo(REALM, connectionContext)
Expand All @@ -62,7 +63,6 @@ export async function runNotifier() {
)

const governancesMap = accountsToPubkeyMap(governances)
let webhookTriggered = false

console.log(`- getting all proposals for all governances`)
const proposalsByGovernance = await Promise.all(
Expand Down Expand Up @@ -103,7 +103,7 @@ export async function runNotifier() {
) {
if (
nowInSeconds - proposal.account.votingCompletedAt.toNumber() <=
fiveMinutesSeconds + toleranceSeconds
thirtyMinutesSeconds + toleranceSeconds
) {
const votingTokenDecimals = 6
const yesVotes = fmtTokenAmount(
Expand Down Expand Up @@ -143,11 +143,10 @@ export async function runNotifier() {
)}/proposal/${proposal.pubkey.toBase58()}`

console.log(msg)
if (process.env.WEBHOOK_URL) {
sendWebhook(process.env.WEBHOOK_URL, {
if (!summaryOnly && process.env.WEBHOOK_URL) {
await sendWebhook(process.env.WEBHOOK_URL, {
content: msg,
})
webhookTriggered = true
}
}
countClosed++
Expand All @@ -165,7 +164,7 @@ export async function runNotifier() {
if (
// proposal opened in last 5 mins
nowInSeconds - proposal.account.votingAt.toNumber() <=
fiveMinutesSeconds + toleranceSeconds
thirtyMinutesSeconds + toleranceSeconds
// proposal opened in last 24 hrs - useful to notify when bot recently stopped working
// and missed the 5 min window
// (nowInSeconds - proposal.info.votingAt.toNumber())/(60 * 60) <=
Expand All @@ -180,11 +179,10 @@ export async function runNotifier() {
)}/proposal/${proposal.pubkey.toBase58()}`

console.log(msg)
if (process.env.WEBHOOK_URL) {
sendWebhook(process.env.WEBHOOK_URL, {
if (!summaryOnly && process.env.WEBHOOK_URL) {
await sendWebhook(process.env.WEBHOOK_URL, {
content: msg,
})
webhookTriggered = true
}
}
// note that these could also include those in finalizing state, but this is just for logging
Expand All @@ -211,7 +209,7 @@ export async function runNotifier() {
nowInSeconds
if (
remainingInSeconds > 86400 &&
remainingInSeconds < 86400 + fiveMinutesSeconds + toleranceSeconds
remainingInSeconds < 86400 + thirtyMinutesSeconds + toleranceSeconds
) {
const msg = `“${
proposal.account.name
Expand All @@ -220,21 +218,20 @@ export async function runNotifier() {
)}/proposal/${proposal.pubkey.toBase58()} in 24 hrs`

console.log(msg)
if (process.env.WEBHOOK_URL) {
sendWebhook(process.env.WEBHOOK_URL, {
if (!summaryOnly && process.env.WEBHOOK_URL) {
await sendWebhook(process.env.WEBHOOK_URL, {
content: msg,
})
webhookTriggered = true
}
}
}
}

const summary = `countOpenForVotingSinceSomeTime: ${countOpenForVotingSinceSomeTime}, countJustOpenedForVoting: ${countJustOpenedForVoting}, countVotingNotStartedYet: ${countVotingNotStartedYet}, countClosed: ${countClosed}, countCancelled: ${countCancelled}`

if (!webhookTriggered && process.env.WEBHOOK_URL) {
if (summaryOnly && process.env.WEBHOOK_URL) {
console.log('Nothing urgent to Report')
sendWebhook(process.env.WEBHOOK_URL, {
await sendWebhook(process.env.WEBHOOK_URL, {
content: 'Nothing urgent to Report: ' + summary,
})
}
Expand Down
6 changes: 5 additions & 1 deletion vercel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"crons": [
{
"path": "/api/gov-notifier-summary",
"schedule": "59 19 * * *"
},
{
"path": "/api/gov-notifier",
"schedule": "23 19 * * *"
"schedule": "*/30 * * * *"
}
]
}

0 comments on commit d928bf1

Please sign in to comment.