Skip to content

add both github action cron job and vercel cron job for governance no… #5

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

Merged
merged 5 commits into from
Jan 8, 2024
Merged
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
27 changes: 27 additions & 0 deletions .github/workflows/check-governance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Check Gov Notifications

on:
schedule:
- cron: '0 10 * * *' # Runs at 10:00 UTC every day (6:00 AM ET)
workflow_dispatch:

jobs:
run-notifier:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install dependencies
run: yarn install

- name: Run the governance notifier script
run: npx ts-node scripts/governance-notifier.ts
env:
CLUSTER_URL: https://api.metaplex.solana.com/
WEBHOOK_URL: https://webhook.site/b48b863e-d364-433a-b55b-bbc86db7d1ed
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"dependencies": {
"@blockworks-foundation/mango-mints-redemption": "0.0.10",
"@blockworks-foundation/mango-v4": "0.20.3",
"@jup-ag/referral-sdk": "0.1.5",
"@blockworks-foundation/mango-v4-settings": "0.2.19",
"@blockworks-foundation/mangolana": "0.0.1-beta.15",
"@bonfida/spl-name-service": "0.1.47",
Expand All @@ -55,6 +54,7 @@
"@heroicons/react": "1.0.6",
"@hookform/resolvers": "2.8.10",
"@identity.com/sol-did-client": "3.1.4",
"@jup-ag/referral-sdk": "0.1.5",
"@marinade.finance/marinade-ts-sdk": "2.0.9",
"@mean-dao/payment-streaming": "4.0.3",
"@metaplex-foundation/js": "0.19.4",
Expand Down
17 changes: 17 additions & 0 deletions pages/api/governance-notifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { runNotifier } from '../../scripts/governance-notifier'

export default async function (req, res) {
console.log('req?.headers?.authorization')
console.log(req?.headers?.authorization)
if (req?.headers?.authorization !== `Bearer ${process.env.CRON_SECRET}`) {
return res.status(401).send('Unauthorized')
}

try {
await runNotifier()
res.status(200).send('Notifier executed successfully')
} catch (error) {
console.error(error)
res.status(500).send('Error executing notifier')
}
}
19 changes: 6 additions & 13 deletions scripts/governance-notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@ import { formatNumber } from '@utils/formatNumber'
const fiveMinutesSeconds = 5 * 60
const toleranceSeconds = 30

if (!process.env.CLUSTER_URL) {
console.error('Please set CLUSTER_URL to a rpc node of choice!')
if (!process.env.MAINNET_RPC) {
console.error('Please set MAINNET_RPC to a rpc node of choice!')
process.exit(1)
}

function errorWrapper() {
export function errorWrapper() {
runNotifier().catch((error) => {
console.error(error)
})
}

// run every 5 mins, checks if a governance proposal just opened in the last 5 mins
// and notifies on WEBHOOK_URL
async function runNotifier() {
const REALM = process.env.REALM || 'MNGO'
export async function runNotifier() {
const REALM = 'Jito'
const connectionContext = getConnectionContext('mainnet')
const realmInfo = await getCertifiedRealmInfo(REALM, connectionContext)

const connection = new Connection(process.env.CLUSTER_URL!)
const connection = new Connection(process.env.MAINNET_RPC!)
console.log(`- getting all governance accounts for ${REALM}`)
const governances = await getGovernanceAccounts(
connection,
Expand Down Expand Up @@ -205,8 +203,3 @@ async function runNotifier() {
`-- countOpenForVotingSinceSomeTime: ${countOpenForVotingSinceSomeTime}, countJustOpenedForVoting: ${countJustOpenedForVoting}, countVotingNotStartedYet: ${countVotingNotStartedYet}, countClosed: ${countClosed}, countCancelled: ${countCancelled}`
)
}

// start notifier immediately
errorWrapper()

setInterval(errorWrapper, fiveMinutesSeconds * 1000)
8 changes: 8 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"crons": [
{
"path": "/api/governance-notifier",
"schedule": "*/10 * * * *"
}
]
}