> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tenderly.co/llms.txt
> Use this file to discover all available pages before exploring further.

# UniswapV3 Pool Creation की निगरानी करें

> UniswapV3Factory में नए pool creations की निगरानी करने और स्वचालित actions करने के लिए Tenderly Web3 Actions का उपयोग करना सीखें।

इस tutorial में, हम आपको दिखाएंगे कि कैसे **UniswapV3Factory contract में नए pool creations की निगरानी करने के लिए Tenderly Web3 Action सेट अप करें** और स्वचालित actions करें। यह project प्रदर्शित करता है कि smart contracts के साथ interact करने के लिए Web3 Actions और custom monitoring system बनाने के लिए Tenderly के features का उपयोग कैसे करें।

<Card title="UniswapV3Factory monitoring Web3 Action template" href="" />

## Project अवलोकन

इस project का उद्देश्य एक system सेट अप करना है जो UniswapV3Factory contract में नए pool creations की निगरानी करता है और विशिष्ट शर्तें पूरी होने पर स्वचालित actions करता है। यहाँ project के flow का एक quick breakdown है:

1. Web3 Action Ethereum mainnet पर UniswapV3Factory contract से `PoolCreated` events के लिए listen करता है।
2. जब कोई event detect होता है, तो यह event data से नए pool का address extract करता है।
3. action नए pool contract को आपके Tenderly project में जोड़ता है और आसान प्रबंधन के लिए इसे tag करता है।

## पूर्वापेक्षाएँ

शुरू करने से पहले, सुनिश्चित करें कि आपके पास निम्नलिखित है:

* [Tenderly CLI](https://github.com/Tenderly/tenderly-cli) स्थापित
* [Node.js](https://nodejs.org/) (v20 वर्तमान में समर्थित)
* [npm](https://www.npmjs.com/)
* एक Tenderly account और project

## Setup

आइए अपने `UniswapV3Factory` Monitoring system को सेट अप करने के चरणों से गुज़रें:

<Steps>
  ### एक नया Tenderly Project बनाएँ

  यदि आपने पहले से नहीं किया है, तो अपने Tenderly dashboard में एक नया project बनाएँ या एक मौजूदा का उपयोग करें।

  ### Tenderly में एक Alert बनाएँ

  1. अपने Tenderly Dashboard में Log इन करें
  2. अपने project पर navigate करें
  3. **Alerts** tab पर जाएँ और **New Alert** पर क्लिक करें
  4. Alert Type को **Event Emitted** पर सेट करें
  5. alert कॉन्फ़िगर करें:
     * **Contract Address:** `0x1f98431c8ad98523631ae4a59f267346ea31f984` (UniswapV3Factory contract)
     * **Event Signature:** `PoolCreated(address,address,uint24,int24,address)`
     * आसान reference के लिए अपने alert को उचित नाम दें
  6. alert सहेजें और बाद में उपयोग के लिए alert का `id` नोट करें

  ### Web3 Action Project को Initialize करें

  एक terminal खोलें और एक नया Web3 Actions project initialize करने के लिए निम्न command चलाएँ:

  ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  tenderly actions init
  ```

  prompt होने पर अपना Tenderly project चुनें और अपनी actions के लिए एक directory नाम चुनें।

  ### tenderly.yaml कॉन्फ़िगर करें

  निम्न configuration के साथ `tenderly.yaml` file update करें:

  ```yaml theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  account_id: "<YOUR_ACCOUNT_ID>"
  actions:
    <YOUR_ACCOUNT_ID>/<YOUR_PROJECT_SLUG>:
      runtime: v2
      sources: actions
      specs:
        uniswapV3:
          description: "Monitoring UniswapV3 Factory Contract and adding Child/Pool to Contracts page with proper tag"
          function: uniswapV3Monitoring:actionFn
          trigger:
            type: alert
            alert: { <ALERT_ID> }
          execution_type: parallel
  project_slug: "<YOUR_PROJECT_SLUG>"
  ```

  `<YOUR_ACCOUNT_ID>`, `<YOUR_PROJECT_SLUG>`, और `<ALERT_ID>` को अपने वास्तविक Tenderly `Account Name`, `Project Slug`, और आपके द्वारा नोट किए गए `Alert ID` से बदलें।

  ### Secrets सेट अप करें

  अपने Tenderly project settings में निम्न secret जोड़ें:

  * `ACCESS-KEY`: आपकी Tenderly [API access key](/platform/account/projects/api-tokens)

  secrets जोड़ने के लिए, अपनी Tenderly project settings पर जाएँ और "Secrets" अनुभाग पर navigate करें।

  ### Web3 Action को Implement करें

  अपनी actions directory में `uniswapV3Monitoring.ts` नामक एक नई file बनाएँ और अपने Web3 Action logic को इस प्रकार implement करें:

  ```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  const ethers = require('ethers');

  const actionFn = async (context: Context, alertEvent: AlertEvent) => {
    const key = await context.secrets.get('ACCESS-KEY');

    const accountSlug = '<YOUR_ACCOUNT_ID>';
    const projectSlug = '<YOUR_PROJECT_SLUG>';
    const tagName = 'pool';

    const tenderly = new Tenderly({
      accountName: accountSlug,
      projectName: projectSlug,
      accessKey: key,
      network: Number(alertEvent.network),
    });

    const poolCreatedSignature = ethers.utils.id("PoolCreated(address,address,uint24,int24,address)");

    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;
      }
    }

    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);
    }
  };

  module.exports = { actionFn };
  ```

  `<YOUR_ACCOUNT_ID>` और `<YOUR_PROJECT_SLUG>` को अपने वास्तविक Tenderly `Account Name` और `Project Slug` से बदलना सुनिश्चित करें।

  ### Deployment

  अपनी Web3 Action deploy करने के लिए, Tenderly CLI का उपयोग करें:

  ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  tenderly actions deploy
  ```

  यह command आपकी `tenderly.yaml` file में परिभाषित action को deploy करेगा।
</Steps>

## यह कैसे काम करता है

आपके द्वारा सेट अप की गई Web3 Action `UniswapV3Factory` contract द्वारा `PoolCreated` event के emit होने पर स्वचालित रूप से trigger होगी। यहाँ `actionFn` function का breakdown है:

1. Tenderly context से `ACCESS-KEY` secret retrieve करें।
2. अपने account और project विवरण के साथ एक नए Tenderly SDK instance को initialize करें।
3. ethers.js का उपयोग करके `PoolCreated` event signature परिभाषित करें।
4. `PoolCreated` event खोजने और नए pool का address extract करने के लिए event logs के माध्यम से Loop करें।
5. Tenderly SDK का उपयोग करके, नए pool contract को अपने Tenderly project में `Pool` display name के साथ जोड़ें।
6. आसान प्रबंधन के लिए नए pool contract को `pool` tag से tag करें।
7. pool address और tagging प्रक्रिया की पुष्टि log करें।

<Note>
  यह implementation स्वचालित रूप से नए Uniswap V3 pools को आपके Tenderly project में जोड़ता है और उन्हें tag करता है, जिससे इन contracts की निगरानी और प्रबंधन करना आसान हो जाता है।
</Note>

## Customization

अपनी Web3 Action के व्यवहार को modify करने के लिए:

1. `uniswapV3Monitoring.ts` file में `actionFn` को edit करें।
2. आप pools के लिए एक अलग tag का उपयोग करने के लिए `tagName` variable को बदल सकते हैं।
3. event से अधिक जानकारी process करने या Tenderly SDK के साथ अन्य actions करने के लिए अतिरिक्त logic जोड़ें।

उदाहरण के लिए, अधिक विस्तृत logging जोड़ने के लिए:

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
console.log(`New pool created: ${poolAddress}`);
console.log(`Network: ${alertEvent.network}`);
console.log(`Transaction hash: ${alertEvent.hash}`);
```

## Monitoring और Troubleshooting

यह सुनिश्चित करने के लिए कि आपकी Web3 Action सही तरीके से काम कर रही है:

* Tenderly dashboard में अपनी Web3 Action executions की निगरानी करें
* किसी भी error संदेशों या execution विवरण के लिए Tenderly logs की जाँच करें
* transaction विवरण और contract interactions का निरीक्षण करने के लिए Tenderly के debugging tools का उपयोग करें
* नए जोड़े गए और tag किए गए pool contracts देखने के लिए अपने Tenderly project के Contracts पेज की जाँच करें

<Warning>
  यह setup विशेष रूप से Ethereum mainnet पर `UniswapV3Factory` contract की निगरानी के लिए designed है।
</Warning>

## निष्कर्ष

आपने अब `UniswapV3Factory` contract में नए pool creations को track करने के लिए Tenderly Web3 Actions का उपयोग करके एक custom monitoring system सेट अप कर लिया है। यह project प्रदर्शित करता है कि smart contracts के साथ कैसे interact करें, Tenderly के SDK का उपयोग करें, और विशिष्ट blockchain events की निगरानी और प्रतिक्रिया के लिए एक स्वचालित system कैसे बनाएँ।

Uniswap V3 और इसके contracts के बारे में अधिक जानकारी के लिए, [Uniswap V3 दस्तावेज़](https://developers.uniswap.org/protocol/reference/core/UniswapV3Factory) देखें।
