Skip to content

Commit

Permalink
lido action tx notification
Browse files Browse the repository at this point in the history
  • Loading branch information
dzekicb committed Aug 27, 2024
1 parent edd3ee5 commit 4e58b6f
Show file tree
Hide file tree
Showing 6 changed files with 290 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/**/*
79 changes: 79 additions & 0 deletions lido-actions/actions/lidoEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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}`;

try {
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');
}

} catch (error) {
console.error('Error:', error);
}
}

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:subscribeLidoImportantEventsFn
execution_type: parallel
trigger:
type: transaction
transaction:
status:
- mined
filters:
- network: 1
eventEmitted:
contract:
address: 0x0de4ea0184c2ad0baca7183356aea5b8d5bf5c6e
name: ValidatorExitRequest
project_slug: ""

0 comments on commit 4e58b6f

Please sign in to comment.