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

lido action tx notification #32

Merged
merged 3 commits into from
Sep 27, 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
5 changes: 5 additions & 0 deletions lido-actions/actions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependency directories
node_modules/

# Ignore tsc output
out/**/*
86 changes: 86 additions & 0 deletions lido-actions/actions/lidoEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Context, TransactionEvent } from "@tenderly/actions";

import axios from "axios";

const subscribeLidoImportantEventsFn = async (
context: Context,
transactionEvent: TransactionEvent,
) => {
const txHash = transactionEvent.hash;
const network = transactionEvent.network;

const bearerToken = await context.secrets.get("BEARER");
const botToken = await context.secrets.get("BOT-TOKEN");
const channelId = await context.secrets.get("CHANNEL-ID");

const url = `https://api.tenderly.co/api/v1/public-contract/${network}/trace/${txHash}`;

const tdlyTx = `https://www.tdly.co/tx/${network}/${txHash}`;

const response = await axios.get(url, {
headers: {
authorization: `${bearerToken}`,
},
});

const result = response.data;

const validatorExitRequestLog = result.logs.find(
(log: any) => log.name === "ValidatorExitRequest",
);

if (validatorExitRequestLog) {
const stakingModuleId = validatorExitRequestLog.inputs.find(
(input: any) => input.soltype.name === "stakingModuleId",
)?.value;
const nodeOperatorId = validatorExitRequestLog.inputs.find(
(input: any) => input.soltype.name === "nodeOperatorId",
)?.value;
const timestamp = validatorExitRequestLog.inputs.find(
(input: any) => input.soltype.name === "timestamp",
)?.value;
const validatorPubkey = validatorExitRequestLog.inputs.find(
(input: any) => input.soltype.name === "validatorPubkey",
)?.value;

const rawTimestamp = Number(timestamp);
const convertedTime = new Date(rawTimestamp * 1000); // Convert to milliseconds

if (stakingModuleId == 1 && nodeOperatorId == 14) {
console.log(
`Condition met: stakingModuleId: ${stakingModuleId}, nodeOperatorId: ${nodeOperatorId}, validatorPubkey: ${validatorPubkey}, timestamp: ${convertedTime.toUTCString()}`,
);

const message = `*Condition met*

*stakingModuleId*: ${stakingModuleId}
*nodeOperatorId*: ${nodeOperatorId}
*validatorPubkey*: ${validatorPubkey}
*timestamp*: ${convertedTime.toUTCString()}
*transaction*: [txHash](${tdlyTx})
`;

const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;
const payload = {
chat_id: channelId,
text: message,
parse_mode: "markdown",
};

try {
await axios.post(telegramApiUrl, payload);
console.log("Message sent successfully.");
} catch (error) {
console.error("Error sending message:", error);
}
} else {
console.log(
`Condition not met: stakingModuleId: ${stakingModuleId}, nodeOperatorId: ${nodeOperatorId}, validatorPubkey: ${validatorPubkey}`,
);
}
} else {
console.log("No ValidatorExitRequest log found");
}
};

module.exports = { subscribeLidoImportantEventsFn };
151 changes: 151 additions & 0 deletions lido-actions/actions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions lido-actions/actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "actions",
"scripts": {
"build": "node_modules/.bin/tsc"
},
"devDependencies": {
"typescript": "^4.9.5"
},
"dependencies": {
"@tenderly/actions": "^0.2.16",
"@types/node": "^20.8.10",
"axios": "^1.6.0"
}
}
19 changes: 19 additions & 0 deletions lido-actions/actions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compileOnSave": true,
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "out",
"rootDir": "",
"sourceMap": true,
"strict": true,
"target": "es2020"
},
"exclude": [
"**/*.spec.ts"
],
"include": [
"**/*"
]
}
22 changes: 22 additions & 0 deletions lido-actions/tenderly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
account_id: ""
actions:
account_slug/project_slug:
runtime: v2
sources: actions
specs:
action_name:
description: Get a notification when condition matches on Lido tx
function: lidoEvents:subscribeToLidoValidatorExitRequestFn
execution_type: parallel
trigger:
type: transaction
transaction:
status:
- mined
filters:
- network: 1
eventEmitted:
contract:
address: 0x0de4ea0184c2ad0baca7183356aea5b8d5bf5c6e
name: ValidatorExitRequest
project_slug: ""