From c439da4640700f7d9bd19914ff08eb5305026990 Mon Sep 17 00:00:00 2001 From: dzekicb Date: Tue, 23 Apr 2024 15:26:47 +0200 Subject: [PATCH] monitoring uniswapv3 --- .../actions/.gitignore | 5 ++ .../actions/example.ts | 47 +++++++++++++++++ .../actions/package-lock.json | 50 +++++++++++++++++++ .../actions/package.json | 14 ++++++ .../actions/tsconfig.json | 19 +++++++ uniswap-factory-pool-monitoring/tenderly.yaml | 14 ++++++ 6 files changed, 149 insertions(+) create mode 100755 uniswap-factory-pool-monitoring/actions/.gitignore create mode 100755 uniswap-factory-pool-monitoring/actions/example.ts create mode 100644 uniswap-factory-pool-monitoring/actions/package-lock.json create mode 100755 uniswap-factory-pool-monitoring/actions/package.json create mode 100755 uniswap-factory-pool-monitoring/actions/tsconfig.json create mode 100644 uniswap-factory-pool-monitoring/tenderly.yaml diff --git a/uniswap-factory-pool-monitoring/actions/.gitignore b/uniswap-factory-pool-monitoring/actions/.gitignore new file mode 100755 index 0000000..2f5b2a0 --- /dev/null +++ b/uniswap-factory-pool-monitoring/actions/.gitignore @@ -0,0 +1,5 @@ +# Dependency directories +node_modules/ + +# Ignore tsc output +out/**/* diff --git a/uniswap-factory-pool-monitoring/actions/example.ts b/uniswap-factory-pool-monitoring/actions/example.ts new file mode 100755 index 0000000..12c4f75 --- /dev/null +++ b/uniswap-factory-pool-monitoring/actions/example.ts @@ -0,0 +1,47 @@ +const ethers = require('ethers'); +import { Network, Context, AlertEvent } from '@tenderly/actions'; +const axios = require('axios'); + +// Do not change function name. +const actionFn = async (context: Context, alertEvent: AlertEvent) => { + + const provider = new ethers.providers.JsonRpcProvider(context.gateways.getGateway(Network.MAINNET)); + const key = await context.secrets.get('ACCESS-KEY') + const networkId = "1"; + const tagName = "child"; + + const resp = await provider.send("tenderly_traceTransaction", [`${alertEvent.hash}`]); + const poolCreatedLogs = resp.logs.filter((log: { name: string; }) => log.name === 'PoolCreated'); + const poolInput = poolCreatedLogs[0].inputs.find((input: { name: string; }) => input.name === 'pool'); + const poolAddress = poolInput.value; + + async function callYourApi(childContractAddress: any) { + const axiosInstance = axios.create({ + baseURL: 'https://api.tenderly.co/api/v1' + }); + axiosInstance.defaults.headers.common['X-Access-Key'] = key; + + const contractData = { + "network_id": `${networkId}`, + "address": `${childContractAddress}` + }; + + const tagData = { + "tag":`${tagName}`, + "contract_ids":[`eth:${networkId}:${childContractAddress}`] + } + + try { + await axiosInstance.post(`account/me/project/monitoring/address`, contractData); + await axiosInstance.post(`account/me/project/monitoring/tag`, tagData); + console.log(`Pool contract is: ${childContractAddress}, and has been added with tag ${tagName}`); + } catch (error) { + console.error("Error calling Tenderly API:", error); + } + } + + await callYourApi(poolAddress); +}; + +// Do not change this. +module.exports = { actionFn }; \ No newline at end of file diff --git a/uniswap-factory-pool-monitoring/actions/package-lock.json b/uniswap-factory-pool-monitoring/actions/package-lock.json new file mode 100644 index 0000000..a574d3d --- /dev/null +++ b/uniswap-factory-pool-monitoring/actions/package-lock.json @@ -0,0 +1,50 @@ +{ + "name": "actions", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "actions", + "dependencies": { + "@tenderly/actions": "^0.2.0" + }, + "devDependencies": { + "@types/node": "^20.12.7", + "typescript": "^4.3.5" + } + }, + "node_modules/@tenderly/actions": { + "version": "0.2.48", + "resolved": "https://registry.npmjs.org/@tenderly/actions/-/actions-0.2.48.tgz", + "integrity": "sha512-+AVDTTgdyRnUglo/ftbuERrVbm1Th79jWwuVdWL6wO2MSbfBj3BchCurLrMDcK3tEYI20yXcrmS872VOT5u3cg==" + }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + } + } +} diff --git a/uniswap-factory-pool-monitoring/actions/package.json b/uniswap-factory-pool-monitoring/actions/package.json new file mode 100755 index 0000000..7338437 --- /dev/null +++ b/uniswap-factory-pool-monitoring/actions/package.json @@ -0,0 +1,14 @@ +{ + "name": "actions", + "scripts": { + "build": "tsc" + }, + "devDependencies": { + "@types/node": "^20.12.7", + "typescript": "^4.3.5" + }, + "dependencies": { + "@tenderly/actions": "^0.2.0" + }, + "private": true +} diff --git a/uniswap-factory-pool-monitoring/actions/tsconfig.json b/uniswap-factory-pool-monitoring/actions/tsconfig.json new file mode 100755 index 0000000..3dd096e --- /dev/null +++ b/uniswap-factory-pool-monitoring/actions/tsconfig.json @@ -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": [ + "**/*" + ] +} \ No newline at end of file diff --git a/uniswap-factory-pool-monitoring/tenderly.yaml b/uniswap-factory-pool-monitoring/tenderly.yaml new file mode 100644 index 0000000..fe9ecdf --- /dev/null +++ b/uniswap-factory-pool-monitoring/tenderly.yaml @@ -0,0 +1,14 @@ +account_id: "dzeka" +actions: + dzeka/monitoring: + runtime: v2 + sources: actions + specs: + uniswapV3: + description: Monitoring UniswapV3 Factory Contract and adding Child/Pool to Contracts page with proper tag + function: example:actionFn + trigger: + type: alert + alert: {2391be3d-15ae-46d6-8d8d-eb629589d1c0} + execution_type: parallel +project_slug: "monitoring" \ No newline at end of file