-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dependency directories | ||
node_modules/ | ||
|
||
# Ignore tsc output | ||
out/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
"**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: "" |