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

Notification message producer integrated with the platform MQ #1

Open
wants to merge 11 commits into
base: master
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
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ NOTIFICATION_KEY=123
LOGTAIL_SOURCE_TOKEN=123
PRIVATE_RPC_ENDPOINT_MAINNET=123

SIGNER_KEY=

BOT_TOKEN=123
NOTIFICATION_CHANNEL=-1001914742237
WEB_HOOK_URL=123
FUNCTION_SECRET=123
FUNCTION_SECRET=123

SUPABASE_ACCESS_TOKEN=
TEST_TG_USER_ID=
RPC_URL_ARB_GOERLI=https://rpc.goerli.arbitrum.gateway.fm
RPC_URL_MAINNET=https://rpc.ankr.com/eth
RPC_URL_GNOSIS=https://rpc.ankr.com/gnosis
RABBITMQ_URL=amqp://localhost
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ node_modules/*
.yarn/cache/
.yarn/install-state.gz

# subgraph

subgraph-court-v1/generated/*
subgraph-court-v1/build/*

# Local Netlify folder
.netlify
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ curl -s -X POST http://localhost:8888/.netlify/functions/update -H "Accept: appl

### Preparation

#### Retrieve your Telegram user chatId
1. Sending a message to your bot on Telegram
2. Visiting `https://api.telegram.org/bot${BOT_TOKEN}/getUpdates`, find the corresponding message and retrieve the chatId
#### Create a Notification Channel
1. Create a channel
2. Send a message to the channel and forward the message to the @userinfobot to retrieve the channel id.
3. Set the value to the environment variable `$NOTIFICATION_CHANNEL`

#### Bot Init
Expand Down
12 changes: 6 additions & 6 deletions codegen.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
overwrite: true
generates:
./generated/kleros-display-graphql.ts:
schema: "https://api.thegraph.com/subgraphs/name/andreimvp/kleros-display"
documents: "graphql/klerosdisplay/*.gql"
./generated/kleros-v1-notifications.ts:
schema: "https://api.thegraph.com/subgraphs/name/kleros/kleros-display-gnosis"
documents: "graphql/kleros-v1/*.gql"
plugins:
- "typescript"
- "typescript-operations"
- "typescript-graphql-request"
./generated/kleros-board-graphql.ts:
schema: "https://api.thegraph.com/subgraphs/name/klerosboard/klerosboard-mainnet"
documents: "graphql/klerosboard/*.gql"
./generated/kleros-v2-notifications.ts:
schema: "https://api.thegraph.com/subgraphs/name/kleros/kleros-v2-core-devnet"
documents: "graphql/kleros-v2/*.gql"
plugins:
- "typescript"
- "typescript-operations"
Expand Down
2 changes: 1 addition & 1 deletion config/botInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const initialize = async () => {

console.log("Setting multilang bot info . . .")
for (const lang in bot.names){
const name = bot.names[lang as keyof typeof bot.names] + " (v2)" // TODO: make the suffix a config variable?
const name = bot.names[lang as keyof typeof bot.names]
console.log('setting bot name ',lang,name)
try{
await axios.post(
Expand Down
278 changes: 237 additions & 41 deletions config/subgraph.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,258 @@
import { GraphQLClient } from "graphql-request";
import { gnosis, mainnet } from "viem/chains";
import { arbitrum, arbitrumGoerli, gnosis, mainnet } from "viem/chains";
import {
Sdk as KBSdk,
getSdk as getKBSdk,
} from "../generated/kleros-board-graphql";
NewDisputesQuery,
JurorsDrawnQuery,
Sdk,
getSdk,
JurorsPeriodQuery,
JurorsPeriodReminderQuery,
JurorsAppealQuery,
JurorsAppealReminderQuery,
Period
} from "../generated/kleros-v1-notifications";
import {
Sdk as KDSdk,
getSdk as getKDSdk,
} from "../generated/kleros-display-graphql";
NewDisputesV2Query,
JurorsDrawnV2Query,
Sdk as SdkV2,
getSdk as getSdkV2,
JurorsPeriodV2Query,
JurorsPeriodReminderV2Query,
JurorsAppealV2Query,
JurorsAppealReminderV2Query,
JurorsAppealFundedV2Query,
JurorsAppealFundedReminderV2Query,
Period as PeriodV2,
} from "../generated/kleros-v2-notifications";
import { Supported } from "../types";

const subgraphUrlKD = {
const subgraphUrlV1 = {
[mainnet.id]:
"https://api.thegraph.com/subgraphs/name/andreimvp/kleros-display-mainnet",
"https://api.thegraph.com/subgraphs/name/shotaronowhere/kleros-display-mainnet",
[gnosis.id]:
"https://api.thegraph.com/subgraphs/name/andreimvp/kleros-display",
"https://api.thegraph.com/subgraphs/name/shotaronowhere/kleros-display-gnosis",
} as const;

const subgraphUrlKB = {
[mainnet.id]:
"https://api.thegraph.com/subgraphs/name/klerosboard/klerosboard-mainnet",
[gnosis.id]:
"https://api.thegraph.com/subgraphs/name/klerosboard/klerosboard-gnosis",
const subgraphUrlV2 = {
[arbitrumGoerli.id]:
"https://api.thegraph.com/subgraphs/name/shotaronowhere/kleros-v2-core-devnet",
} as const;

export const KBsdks = Object.entries(subgraphUrlKB).reduce(
(acc, [chainId, url]) => ({
export const sdksV1 = Object.entries(subgraphUrlV1).reduce(
(acc, [chainId, url]) => {
return ({
...acc,
[+chainId]: getKBSdk(new GraphQLClient(url)),
}),
{} as Record<Supported<(keyof typeof subgraphUrlKB)[]>, KBSdk>
[+chainId]: getSdk(new GraphQLClient(url)),
})
},
{} as Record<Supported<(keyof typeof subgraphUrlV1)[]>, Sdk>
);

export const KDsdks = Object.entries(subgraphUrlKD).reduce(
(acc, [chainId, url]) => ({
export const sdksV2 = Object.entries(subgraphUrlV2).reduce(
(acc, [chainId, url]) => {
return ({
...acc,
[+chainId]: getKDSdk(new GraphQLClient(url)),
}),
{} as Record<Supported<(keyof typeof subgraphUrlKD)[]>, KDSdk>
[+chainId]: getSdkV2(new GraphQLClient(url)),
})
},
{} as Record<Supported<(keyof typeof subgraphUrlV2)[]>, SdkV2>
);

export const supportedChainIds = [
export const supportedChainIdsV1 = [
mainnet.id,
gnosis.id,
0 /* because the Supabase schema uses an int2 for now, should be arbitrumGoerli.id */,
];

export const getKDSubgraphData = async (
chainId: Supported<typeof supportedChainIds>,
key: keyof KDSdk,
id: string
) => await KDsdks[chainId as keyof typeof subgraphUrlKD][key]({ id });

export const getKBSubgraphData = async (
chainId: Supported<typeof supportedChainIds>,
key: keyof KBSdk,
params: any
) =>
await KBsdks[chainId as Supported<(keyof typeof subgraphUrlKB)[]>][key](
params
);
export const supportedChainIdsV2 = [
arbitrumGoerli.id,
];

require('dotenv').config()
const { RPC_URL_GNOSIS, RPC_URL_MAINNET, RPC_URL_ARB_GOERLI } = process.env

export const rpcUrl = {
[mainnet.id]: RPC_URL_MAINNET,
[gnosis.id]: RPC_URL_GNOSIS,
[arbitrumGoerli.id]: RPC_URL_ARB_GOERLI,
};

export const getAppealableDisputes = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { reminderDeadline: any; blockHeight: number; indexLast: any; }
) => {
let appealableDisputes: JurorsAppealQuery | undefined = undefined;
try {
appealableDisputes = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["JurorsAppeal"](
params
);
} catch (e) {
console.error(e);
}
return appealableDisputes;
}

export const getAppealableDisputesV2 = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { reminderDeadline: any; blockHeight: number; indexLast: any; }
) => {
let appealableDisputes: JurorsAppealV2Query | undefined = undefined;
try {
appealableDisputes = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["JurorsAppealV2"](
params
);
} catch (e) {
console.error(e);
}
return appealableDisputes;
}

export const getNewDisputes = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { blockHeight: number, disputeID: number;}
) => {
let res: NewDisputesQuery | undefined = undefined;
try {
res = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["NewDisputes"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getNewDisputesV2 = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { blockHeight: number, disputeID: number;}
) => {
let res: NewDisputesV2Query | undefined = undefined;
try {
res = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["NewDisputesV2"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getDraws = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { blockHeight: number; indexLast: any; }
) => {
let res: JurorsDrawnQuery | undefined = undefined;
try {
res = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["JurorsDrawn"](
params
);
} catch (e) {
console.error(e);
}
return res;
}


export const getDrawsV2 = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { blockHeight: number; indexLast: any; }
) => {
let res: JurorsDrawnV2Query | undefined = undefined;
try {
res = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["JurorsDrawnV2"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getPeriods = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { period: Period, reminderDeadline: any; blockHeight: number; indexLast: any; }
) => {
let res: JurorsPeriodQuery | undefined = undefined;
try {
res = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["JurorsPeriod"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getPeriodReminders = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { period: Period, reminderDeadline: any; timeNow: any; blockHeight: number; idLast: string; blockLast: any; }
) => {
let res: JurorsPeriodReminderQuery | undefined = undefined;
try {
res = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["JurorsPeriodReminder"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getPeriodsV2 = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { period: PeriodV2, reminderDeadline: any; blockHeight: number; indexLast: any; }
) => {
let res: JurorsPeriodV2Query | undefined = undefined;
try {
res = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["JurorsPeriodV2"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getPeriodV2Reminders = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { period: PeriodV2, reminderDeadline: any; timeNow: any; blockHeight: number; idLast: string; blockLast: any; }
) => {
let res: JurorsPeriodReminderV2Query | undefined = undefined;
try {
res = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["JurorsPeriodReminderV2"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getAppealReminders = async (
chainId: Supported<typeof supportedChainIdsV1>,
params: { reminderDeadline: any; timeNow: any; blockHeight: number; idLast: string; blockLast: any; }
) => {
let res: JurorsAppealReminderQuery | undefined = undefined;
try {
res = await sdksV1[chainId as Supported<(keyof typeof subgraphUrlV1)[]>]["JurorsAppealReminder"](
params
);
} catch (e) {
console.error(e);
}
return res;
}

export const getAppealRemindersV2 = async (
chainId: Supported<typeof supportedChainIdsV2>,
params: { reminderDeadline: any; timeNow: any; blockHeight: number; idLast: string; blockLast: any; }
) => {
let res: JurorsAppealReminderV2Query | undefined = undefined;
try {
res = await sdksV2[chainId as Supported<(keyof typeof subgraphUrlV2)[]>]["JurorsAppealReminderV2"](
params
);
} catch (e) {
console.error(e);
}
return res;
}
6 changes: 5 additions & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ declare global {
BOT_TOKEN: string;
WEB_HOOK_URL: string;
LOGTAIL_SOURCE_TOKEN: string;
PRIVATE_RPC_ENDPOINT_MAINNET: string;
RABBITMQ_URL: string;
SIGNER_KEY: string;
TEST_TG_USER_ID: number | undefined;
RPC_URL_MAINNET: string;
RPC_URL_GNOSIS: string;
NOTIFICATION_CHANNEL: string;
FUNCTION_SECRET: string;
}
Expand Down
Loading