Skip to content

Commit

Permalink
additional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dzekicb committed May 3, 2024
1 parent f2f449f commit f24fa21
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 78 deletions.
49 changes: 23 additions & 26 deletions uniswap-factory-pool-monitoring/actions/example.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
import { Network as ActionsNetwork, Context, AlertEvent } from '@tenderly/actions';
import { Network as SDKNetwork, Tenderly } from '@tenderly/sdk';
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 provider = new ethers.providers.JsonRpcProvider(context.gateways.getGateway(ActionsNetwork.MAINNET));
const key = await context.secrets.get('ACCESS-KEY')
const networkId = "1";
const tagName = "pool";

const accountSlug = '';
const projectSlug = '';
const tagName = 'pool';

const tenderly = new Tenderly({
accountName: accountSlug,
projectName: projectSlug,
accessKey: key,
network: SDKNetwork.MAINNET, // Replace with the appropriate network
});

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}`]
}

async function addContract(childContractAddress: string) {
try {
await axiosInstance.post(`account/me/project/monitoring/address`, contractData);
await axiosInstance.post(`account/me/project/monitoring/tag`, tagData);
await tenderly.contracts.add(childContractAddress, {
displayName: 'Pool'
});
await tenderly.contracts.update(childContractAddress, { appendTags: [tagName] });
console.log(`Pool contract is: ${childContractAddress}, and has been added with tag ${tagName}`);
} catch (error) {
console.error("Error calling Tenderly API:", error);
}
catch (error) {
console.error('Error adding contract:', error);
}
}

await callYourApi(poolAddress);
await addContract(poolAddress);
};

// Do not change this.
Expand Down
50 changes: 0 additions & 50 deletions uniswap-factory-pool-monitoring/actions/package-lock.json

This file was deleted.

3 changes: 2 additions & 1 deletion uniswap-factory-pool-monitoring/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"typescript": "^4.3.5"
},
"dependencies": {
"@tenderly/actions": "^0.2.0"
"@tenderly/actions": "^0.2.0",
"@tenderly/sdk": "^0.2.5"
},
"private": true
}
2 changes: 1 addition & 1 deletion uniswap-factory-pool-monitoring/actions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"rootDir": "",
"sourceMap": true,
"strict": true,
"target": "es2020"
"target": "es2020",
},
"exclude": [
"**/*.spec.ts"
Expand Down

0 comments on commit f24fa21

Please sign in to comment.