Skip to content

Commit

Permalink
monitoring uniswapv3
Browse files Browse the repository at this point in the history
  • Loading branch information
dzekicb committed Apr 23, 2024
1 parent 6f89d42 commit c439da4
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
5 changes: 5 additions & 0 deletions uniswap-factory-pool-monitoring/actions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dependency directories
node_modules/

# Ignore tsc output
out/**/*
47 changes: 47 additions & 0 deletions uniswap-factory-pool-monitoring/actions/example.ts
Original file line number Diff line number Diff line change
@@ -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 };
50 changes: 50 additions & 0 deletions uniswap-factory-pool-monitoring/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 uniswap-factory-pool-monitoring/actions/package.json
Original file line number Diff line number Diff line change
@@ -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
}
19 changes: 19 additions & 0 deletions uniswap-factory-pool-monitoring/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": [
"**/*"
]
}
14 changes: 14 additions & 0 deletions uniswap-factory-pool-monitoring/tenderly.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit c439da4

Please sign in to comment.