Skip to content

Commit

Permalink
Update lidoEvents.ts
Browse files Browse the repository at this point in the history
remove try/catch
  • Loading branch information
dzekicb authored Sep 27, 2024
1 parent b8f3397 commit f97650c
Showing 1 changed file with 64 additions and 57 deletions.
121 changes: 64 additions & 57 deletions lido-actions/actions/lidoEvents.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
import {
Context,
TransactionEvent
} from '@tenderly/actions';
import { Context, TransactionEvent } from "@tenderly/actions";

import axios from 'axios';
import axios from "axios";

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

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 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 url = `https://api.tenderly.co/api/v1/public-contract/${network}/trace/${txHash}`;
const tdlyTx = `https://www.tdly.co/tx/${network}/${txHash}`;

const tdlyTx = `https://www.tdly.co/tx/${network}/${txHash}`;
const response = await axios.get(url, {
headers: {
authorization: `${bearerToken}`,
},
});

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

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

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;

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

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()}`,
);

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

const message = `*Condition met*
const message = `*Condition met*
*stakingModuleId*: ${stakingModuleId}
*nodeOperatorId*: ${nodeOperatorId}
Expand All @@ -50,30 +60,27 @@ const subscribeLidoImportantEventsFn = async (context: Context, transactionEvent
*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);
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};
module.exports = { subscribeLidoImportantEventsFn };

0 comments on commit f97650c

Please sign in to comment.