From 1766717c9653af78f456a1ead6f347a4e3e9d3e9 Mon Sep 17 00:00:00 2001 From: dzekicb Date: Wed, 8 May 2024 16:58:52 +0200 Subject: [PATCH] additional changes on the provided comments --- .../actions/example.ts | 50 +++++++++---------- uniswap-factory-pool-monitoring/tenderly.yaml | 2 +- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/uniswap-factory-pool-monitoring/actions/example.ts b/uniswap-factory-pool-monitoring/actions/example.ts index a65fb0f..6da0fa9 100755 --- a/uniswap-factory-pool-monitoring/actions/example.ts +++ b/uniswap-factory-pool-monitoring/actions/example.ts @@ -1,44 +1,42 @@ -import { Network as ActionsNetwork, Context, AlertEvent } from '@tenderly/actions'; -import { Network as SDKNetwork, Tenderly } from '@tenderly/sdk'; +import { Context, AlertEvent } from '@tenderly/actions'; +import { Tenderly } from '@tenderly/sdk'; const ethers = require('ethers'); -// Do not change function name. const actionFn = async (context: Context, alertEvent: AlertEvent) => { + const key = await context.secrets.get('ACCESS-KEY'); - const provider = new ethers.providers.JsonRpcProvider(context.gateways.getGateway(ActionsNetwork.MAINNET)); - const key = await context.secrets.get('ACCESS-KEY') - - const accountSlug = ''; - const projectSlug = ''; + const accountSlug = '{account_id}'; + const projectSlug = '{project_slug}'; const tagName = 'pool'; const tenderly = new Tenderly({ accountName: accountSlug, projectName: projectSlug, accessKey: key, - network: SDKNetwork.MAINNET, // Replace with the appropriate network + network: Number(alertEvent.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; + const poolCreatedSignature = ethers.utils.id("PoolCreated(address,address,uint24,int24,address)"); - async function addContract(childContractAddress: string) { - try { - 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 adding contract:', error); + let poolAddress = ""; + for (const log of alertEvent.logs) { + if (log.topics[0] === poolCreatedSignature) { + const data = log.data; + const addressHex = data.substring(data.length - 40); + poolAddress = ethers.utils.getAddress('0x' + addressHex).toLowerCase(); + break; } } - await addContract(poolAddress); + try { + await tenderly.contracts.add(poolAddress, { + displayName: 'Pool' + }); + await tenderly.contracts.update(poolAddress, { appendTags: [tagName] }); + console.log(`Pool contract is: ${poolAddress}, and has been added with tag ${tagName}`); + } catch (error) { + console.error('Error adding contract:', error); + } }; -// Do not change this. -module.exports = { actionFn }; \ No newline at end of file +module.exports = { actionFn }; diff --git a/uniswap-factory-pool-monitoring/tenderly.yaml b/uniswap-factory-pool-monitoring/tenderly.yaml index 12d705c..5c4600a 100644 --- a/uniswap-factory-pool-monitoring/tenderly.yaml +++ b/uniswap-factory-pool-monitoring/tenderly.yaml @@ -1,6 +1,6 @@ account_id: "" actions: - account_id/project_slug: + account_id/project_slug: # these will need to be changed according to the actual account_id/project_slug runtime: v2 sources: actions specs: