Skip to content

Commit

Permalink
Merge pull request #32 from Tenderly/bdz/lido-w3a
Browse files Browse the repository at this point in the history
lido action tx notification
  • Loading branch information
dzekicb authored Sep 27, 2024
2 parents a6c9de9 + f97650c commit 40c7f3f
Show file tree
Hide file tree
Showing 6 changed files with 297 additions and 0 deletions.
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: ""

0 comments on commit 40c7f3f

Please sign in to comment.