From 18abbb9fbe125fc408bea2d499f7953c2c055fbb Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 20 Mar 2024 20:10:27 +0100
Subject: [PATCH 01/17] feat: uniV3 basic lp info

---
 .../_sector/dex/uniswap_compatible_lp.sql     | 135 ++++++++++++++++++
 models/_sector/dex/lps/_schema.yml            | 133 +++++++++++++++++
 models/_sector/dex/lps/dex_base_lps.sql       |  60 ++++++++
 models/_sector/dex/lps/ethereum/_schema.yml   |  25 ++++
 .../lps/ethereum/dex_ethereum_base_trades.sql |  47 ++++++
 .../uniswap_v3_ethereum_base_lps.sql          |  25 ++++
 6 files changed, 425 insertions(+)
 create mode 100644 macros/models/_sector/dex/uniswap_compatible_lp.sql
 create mode 100644 models/_sector/dex/lps/_schema.yml
 create mode 100644 models/_sector/dex/lps/dex_base_lps.sql
 create mode 100644 models/_sector/dex/lps/ethereum/_schema.yml
 create mode 100644 models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql
 create mode 100644 models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
new file mode 100644
index 00000000000..d696ff4c056
--- /dev/null
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -0,0 +1,135 @@
+{% macro uniswap_compatible_v3_lp(
+    blockchain = null
+    , project = null
+    , version = null
+    , Pair_evt_Mint = null
+    , Pair_evt_Burn = null
+    , Factory_evt_PoolCreated = null
+    , NonfungibleTokenPositionManager_evt_Transfer = null
+    , NonfungibleTokenPositionManager_evt_IncreaseLiquidity = null
+    , NonfungibleTokenPositionManager_evt_DecreaseLiquidity = null
+    , position_manager_addr = null
+    )
+%}
+WITH id_to_lp AS
+(
+    SELECT
+        distinct t.tokenId
+        ,t.to AS lp_address
+    FROM
+        {{ NonfungibleTokenPositionManager_evt_Transfer }}
+    WHERE
+        t."from" = 0x0000000000000000000000000000000000000000
+)
+
+, mints AS
+(
+    SELECT
+        'mint' AS event_type
+        ,m.evt_block_number AS block_number
+        ,m.evt_block_time AS block_time
+        ,m.evt_tx_hash AS tx_hash
+        ,m.evt_index
+        , {% if position_manager_addr %}
+                id.lp_address
+            {% else %}
+                m.owner
+            {% endif %} AS lp_address
+        , {% if position_manager_addr %}
+                cast(pm.tokenId AS double)
+            {% else %}
+                0
+            {% endif %} AS position_id
+        , m.tickLower AS tick_lower
+        , m.tickUpper AS tick_upper
+        , m.amount AS liquidity
+        , m.amount0 AS amount0
+        , m.amount1 AS amount1
+        , f.token0 AS token0_address
+        , f.token1 AS token1_address
+        , m.contract_address AS pool_address
+    FROM
+        {{ Pair_evt_Mint }} m
+    INNER JOIN
+        {{ Factory_evt_PoolCreated }} f
+        ON f.pool = m.contract_address
+    LEFT JOIN
+        {{ NonfungibleTokenPositionManager_evt_IncreaseLiquidity }} pm
+        ON m.owner = pm.contract_address and m.evt_tx_hash = pm.evt_tx_hash
+    LEFT JOIN id_to_lp AS id
+        ON pm.tokenId = id.tokenId
+    {% if is_incremental() %}
+    WHERE
+        {{ incremental_predicate('m.evt_block_time') }}
+    {% endif %}
+)
+
+, burns AS
+(
+    SELECT
+        'burn' AS event_type
+        ,b.evt_block_number AS block_number
+        ,b.evt_block_time AS block_time
+        ,b.evt_tx_hash AS tx_hash
+        ,b.evt_index
+        , {% if position_manager_addr %}
+                id.lp_address
+            {% else %}
+                b.owner
+            {% endif %} AS lp_address
+        , {% if position_manager_addr %}
+                cast(pm.tokenId AS double)
+            {% else %}
+                0
+            {% endif %} AS position_id
+        , b.tickLower AS tick_lower
+        , b.tickUpper AS tick_upper
+        , b.amount AS liquidity
+        , b.amount0
+        , b.amount1
+        , f.token0 AS token0_address
+        , f.token1 AS token1_address
+        , m.contract_address AS pool_address
+    FROM
+        {{ Pair_evt_Burn }} b
+    INNER JOIN
+        {{ Factory_evt_PoolCreated }} f
+        ON f.pool = b.contract_address
+    LEFT JOIN
+        {{ NonfungibleTokenPositionManager_evt_IncreaseLiquidity }} pm
+        ON b.owner = pm.contract_address and b.evt_tx_hash = pm.evt_tx_hash
+    LEFT JOIN id_to_lp AS id
+        ON pm.tokenId = id.tokenId
+    {% if is_incremental() %}
+    WHERE
+        {{ incremental_predicate('b.evt_block_time') }}
+    {% endif %}
+)
+
+SELECT
+    '{{ blockchain }}' AS blockchain
+    , '{{ project }}' AS project
+    , '{{ version }}' AS version
+    , lp_data.event_type
+    , lp_data.block_number
+    , lp_data.block_time
+    , date_trunc('MONTH', lp_data.block_time) AS block_month
+    , lp_data.tx_hash
+    , lp_data.evt_index
+    , lp_data.lp_address
+    , lp_data.position_id
+    , lp.tick_lower
+    , lp.tick_upper
+    , CAST(lp_data.liquidity AS UINT256) AS liquidity_raw
+    , CAST(lp_data.amount0 AS UINT256) AS amount0_raw
+    , CAST(lp_data.amount1 AS UINT256) AS amount1_raw
+    , lp_data.token0_address
+    , lp_data.token1_address
+    , lp_data.pool_address
+FROM
+    (
+        select * from mints
+        union all
+        select * from burns
+    ) lp_data
+{% endmacro %}
\ No newline at end of file
diff --git a/models/_sector/dex/lps/_schema.yml b/models/_sector/dex/lps/_schema.yml
new file mode 100644
index 00000000000..e8a51182864
--- /dev/null
+++ b/models/_sector/dex/lps/_schema.yml
@@ -0,0 +1,133 @@
+version: 1
+
+models:
+  # - name: dex_lps
+  #   meta:
+  #     blockchain: ethereum
+  #     sector: dex
+  #     contributors: 0xrusowsky
+  #   config:
+  #     tags: [ 'dex', 'lps' ]
+  #   tests:
+  #     - dbt_utils.unique_combination_of_columns:
+  #         combination_of_columns:
+  #           - blockchain
+  #           - project
+  #           - version
+  #           - tx_hash
+  #           - evt_index
+  #   columns:
+  #     - &blockchain
+  #       name: blockchain
+  #       description: "Blockchain where the DEX is deployed"
+  #     - &project
+  #       name: project
+  #       description: "Project name of the DEX"
+  #       tests:
+  #         - relationships:
+  #             to: ref('dex_info')
+  #             field: project
+  #     - &version
+  #       name: version
+  #       description: "Version of the contract built and deployed by the DEX project"
+  #     - &block_month
+  #       name: block_month
+  #       description: "Month of the event block time"
+  #     - &block_time
+  #       name: block_time
+  #       description: "UTC event block time of each DEX trade"
+  #     - &block_number
+  #       name: block_number
+  #       description: "Block number of each DEX trade"
+  #     - &token0_symbol
+  #       name: token0_symbol
+  #       description: "Token symbol for token bought in the trade"
+  #     - &token1_symbol
+  #       name: token1_symbol
+  #       description: "Token symbol for token sold in the trade"
+  #     - &token_pair
+  #       name: token_pair
+  #       description: "Token symbol pair for each token involved in the trade"
+  #     - &token0_amount_raw
+  #       name: token0_amount_raw
+  #       description: "Raw amount of token0"
+  #     - &token1_amount_raw
+  #       name: token1_amount_raw
+  #       description: "Raw amount of token1"
+  #     - &liquidity_amount_raw
+  #       name: liquidity_amount_raw
+  #       description: "Raw amount of liquidity provided"
+  #     - &token0_amount_usd
+  #       name: token0_amount_usd
+  #       description: "USD value of amount token0 provided at time of execution"
+  #     - &token1_amount_usd
+  #       name: token1_amount_usd
+  #       description: "USD value of amount token1 provided at time of execution"
+  #     - &liquidity_usd
+  #       name: liquidity_usd
+  #       description: "USD value of the liquidity provided at time of execution"
+  #       tests:
+  #         - dbt_utils.accepted_range:
+  #             max_value: 1000000000 # $1b is an arbitrary number, intended to flag outlier amounts early
+  #     - &token0_address
+  #       name: token0_address
+  #       description: "Contract address of the token bought"
+  #     - &token1_address
+  #       name: token1_address
+  #       description: "Contract address of the token sold"
+  #     - &pool_address
+  #       name: pool_address
+  #       description: "Project contract address which executed the trade on the blockchain"
+  #     - &liquidity_provider
+  #       name: liquidity_provider
+  #       description: "Address of the liquidity provider (LP)"
+  #     - &position_id
+  #       name: position_id
+  #       description: "ID of the NFT that represents the liquidity position. Zero if they didn't use the NFTPositionManager."
+  #     - &tick_lower
+  #       name: tick_lower
+  #       description: "Lower tick of the position."
+  #     - &tick_upper
+  #       name: tick_upper
+  #       description: "Upper tick of the position."
+  #     - &tx_hash
+  #       name: tx_hash
+  #       description: "Unique transaction hash value tied to each transaction on the DEX"
+  #     - &evt_index
+  #       name: evt_index
+  #       description: "Index of the corresponding trade event"
+
+  - name: dex_base_lps
+    meta:
+      blockchain: ethereum
+      sector: dex
+      contributors: 0xrusowsky
+    config:
+      tags: [ 'dex' ]
+    tests:
+      - dbt_utils.unique_combination_of_columns:
+          combination_of_columns:
+            - blockchain
+            - project
+            - version
+            - tx_hash
+            - evt_index
+    columns:
+      - *blockchain
+      - *project
+      - *version
+      - *block_time
+      - *block_month
+      - *block_number
+      - *token0_amount_raw
+      - *token1_amount_raw
+      - *liquidity_amount_raw
+      - *token0_address
+      - *token1_address
+      - *pool_address
+      - *liquidity_provider
+      - *position_id
+      - *tick_lower
+      - *tick_upper
+      - *tx_hash
+      - *evt_index
\ No newline at end of file
diff --git a/models/_sector/dex/lps/dex_base_lps.sql b/models/_sector/dex/lps/dex_base_lps.sql
new file mode 100644
index 00000000000..30a14c1ea1b
--- /dev/null
+++ b/models/_sector/dex/lps/dex_base_lps.sql
@@ -0,0 +1,60 @@
+{{ config(
+    schema = 'dex'
+    , alias = 'base_lps'
+    , partition_by = ['block_month', 'blockchain', 'project']
+    , materialized = 'incremental'
+    , file_format = 'delta'
+    , incremental_strategy = 'merge'
+    , unique_key = ['blockchain', 'project', 'version', 'tx_hash', 'evt_index']
+    , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
+    )
+}}
+
+{% set models = [
+    ref('dex_ethereum_base_ls')
+] %}
+
+with base_union as (
+    SELECT *
+    FROM
+    (
+        {% for model in models %}
+        SELECT
+            blockchain
+            , project
+            , version
+            , block_time
+            , block_month
+            , block_number
+            , token0_amount_raw
+            , token1_amount_raw
+            , liquidity_amount_raw
+            , token0_address
+            , token1_address
+            , pool_address
+            , liquidity_provider
+            , position_id
+            , tick_lower
+            , tick_upper
+            , tx_hash
+            , evt_index
+            , row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank
+        FROM
+            {{ model }}
+        {% if is_incremental() %}
+        WHERE
+            {{ incremental_predicate('block_time') }}
+        {% endif %}
+        {% if not loop.last %}
+        UNION ALL
+        {% endif %}
+        {% endfor %}
+    )
+    WHERE
+        duplicates_rank = 1
+)
+
+select
+    *
+from
+    base_union
diff --git a/models/_sector/dex/lps/ethereum/_schema.yml b/models/_sector/dex/lps/ethereum/_schema.yml
new file mode 100644
index 00000000000..7340bb1c892
--- /dev/null
+++ b/models/_sector/dex/lps/ethereum/_schema.yml
@@ -0,0 +1,25 @@
+version: 2
+
+models:
+  - name: dex_ethereum_base_lps
+    tests:
+      - check_dex_info_relationship
+
+  - name: uniswap_v3_ethereum_base_trades
+    meta:
+      blockchain: ethereum
+      sector: dex
+      project: uniswap
+      contributors: 0xrusowsky
+    config:
+      tags: [ 'ethereum', 'dex', 'lps', 'uniswap', 'v3' ]
+    description: "uniswap ethereum v3 base lps"
+    tests:
+      - dbt_utils.unique_combination_of_columns:
+          combination_of_columns:
+            - tx_hash
+            - evt_index
+      # - check_dex_base_lps_seed:
+      #     seed_file: ref('uniswap_ethereum_base_lps_seed')
+      #     filter:
+      #       version: 3
\ No newline at end of file
diff --git a/models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql b/models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql
new file mode 100644
index 00000000000..05f71d8bac4
--- /dev/null
+++ b/models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql
@@ -0,0 +1,47 @@
+{{ config(
+    schema = 'dex_ethereum'
+    , alias = 'base_lps'
+    , materialized = 'view'
+    )
+}}
+
+{% set base_models = [
+    ref('uniswap_v3_ethereum_base_lps')
+] %}
+
+WITH base_union AS (
+    SELECT *
+    FROM (
+        {% for base_model in base_models %}
+        SELECT
+            blockchain
+            , project
+            , version
+            , block_time
+            , block_month
+            , block_number
+            , token0_amount_raw
+            , token1_amount_raw
+            , liquidity_amount_raw
+            , token0_address
+            , token1_address
+            , pool_address
+            , liquidity_provider
+            , position_id
+            , tick_lower
+            , tick_upper
+            , tx_hash
+            , evt_index
+        FROM 
+            {{ base_model }}
+        {% if not loop.last %}
+        UNION ALL
+        {% endif %}
+        {% endfor %}
+    )
+)
+
+select
+    *
+from
+    base_union
\ No newline at end of file
diff --git a/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql b/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql
new file mode 100644
index 00000000000..4a0ee0c02d0
--- /dev/null
+++ b/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql
@@ -0,0 +1,25 @@
+{{ config(
+    schema = 'uniswap_v3_ethereum'
+    , alias = 'base_trades'
+    , materialized = 'incremental'
+    , file_format = 'delta'
+    , incremental_strategy = 'merge'
+    , unique_key = ['tx_hash', 'evt_index']
+    , incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
+    )
+}}
+
+{{
+    uniswap_compatible_v3_trades(
+        blockchain = 'ethereum'
+        , project = 'uniswap'
+        , version = '3'
+        , Pair_evt_Mint = source('uniswap_v3_ethereum', 'Pair_evt_Mint')
+        , Pair_evt_Burn = source('uniswap_v3_ethereum', 'Pair_evt_Burn')
+        , Factory_evt_PoolCreated = source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated')
+        , NonfungibleTokenPositionManager_evt_Transfer = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_Transfer')
+        , NonfungibleTokenPositionManager_evt_IncreaseLiquidity = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_IncreaseLiquidity')
+        , NonfungibleTokenPositionManager_evt_DecreaseLiquidity = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_DecreaseLiquidity')
+        , position_manager_addr = 0xc36442b4a4522e871399cd717abdd847ab11fe88
+    )
+}}
\ No newline at end of file

From a08e5c49ff5efa63ff7101d77905afabf77f37b7 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 20 Mar 2024 20:45:16 +0100
Subject: [PATCH 02/17] fix: compilation errors

---
 .../_sector/dex/uniswap_compatible_lp.sql     |  2 +-
 models/_sector/dex/lps/_schema.yml            | 38 +++++++++----------
 models/_sector/dex/lps/dex_base_lps.sql       |  2 +-
 models/_sector/dex/lps/ethereum/_schema.yml   |  2 +-
 ...e_trades.sql => dex_ethereum_base_lps.sql} |  0
 .../uniswap_v3_ethereum_base_lps.sql          |  6 +--
 .../ethereum/uniswap_ethereum_sources.yml     | 36 +++++++++++++++++-
 7 files changed, 60 insertions(+), 26 deletions(-)
 rename models/_sector/dex/lps/ethereum/{dex_ethereum_base_trades.sql => dex_ethereum_base_lps.sql} (100%)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index d696ff4c056..c31f8b409fd 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -1,4 +1,4 @@
-{% macro uniswap_compatible_v3_lp(
+{% macro uniswap_compatible_v3_lps(
     blockchain = null
     , project = null
     , version = null
diff --git a/models/_sector/dex/lps/_schema.yml b/models/_sector/dex/lps/_schema.yml
index e8a51182864..28bd12d4c5e 100644
--- a/models/_sector/dex/lps/_schema.yml
+++ b/models/_sector/dex/lps/_schema.yml
@@ -112,22 +112,22 @@ models:
             - version
             - tx_hash
             - evt_index
-    columns:
-      - *blockchain
-      - *project
-      - *version
-      - *block_time
-      - *block_month
-      - *block_number
-      - *token0_amount_raw
-      - *token1_amount_raw
-      - *liquidity_amount_raw
-      - *token0_address
-      - *token1_address
-      - *pool_address
-      - *liquidity_provider
-      - *position_id
-      - *tick_lower
-      - *tick_upper
-      - *tx_hash
-      - *evt_index
\ No newline at end of file
+    # columns:
+    #   - blockchain
+    #   - project
+    #   - version
+    #   - block_time
+    #   - block_month
+    #   - block_number
+    #   - amount0_raw
+    #   - amount1_raw
+    #   - liquidity_amount_raw
+    #   - token0_address
+    #   - token1_address
+    #   - pool_address
+    #   - liquidity_provider
+    #   - position_id
+    #   - tick_lower
+    #   - tick_upper
+    #   - tx_hash
+    #   - evt_index
\ No newline at end of file
diff --git a/models/_sector/dex/lps/dex_base_lps.sql b/models/_sector/dex/lps/dex_base_lps.sql
index 30a14c1ea1b..6f924a5c53a 100644
--- a/models/_sector/dex/lps/dex_base_lps.sql
+++ b/models/_sector/dex/lps/dex_base_lps.sql
@@ -11,7 +11,7 @@
 }}
 
 {% set models = [
-    ref('dex_ethereum_base_ls')
+    ref('dex_ethereum_base_lps')
 ] %}
 
 with base_union as (
diff --git a/models/_sector/dex/lps/ethereum/_schema.yml b/models/_sector/dex/lps/ethereum/_schema.yml
index 7340bb1c892..51809bc2c26 100644
--- a/models/_sector/dex/lps/ethereum/_schema.yml
+++ b/models/_sector/dex/lps/ethereum/_schema.yml
@@ -5,7 +5,7 @@ models:
     tests:
       - check_dex_info_relationship
 
-  - name: uniswap_v3_ethereum_base_trades
+  - name: uniswap_v3_ethereum_base_lps
     meta:
       blockchain: ethereum
       sector: dex
diff --git a/models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql b/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
similarity index 100%
rename from models/_sector/dex/lps/ethereum/dex_ethereum_base_trades.sql
rename to models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
diff --git a/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql b/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql
index 4a0ee0c02d0..517457d2d79 100644
--- a/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql
+++ b/models/_sector/dex/lps/ethereum/platforms/uniswap_v3_ethereum_base_lps.sql
@@ -1,6 +1,6 @@
 {{ config(
     schema = 'uniswap_v3_ethereum'
-    , alias = 'base_trades'
+    , alias = 'base_lps'
     , materialized = 'incremental'
     , file_format = 'delta'
     , incremental_strategy = 'merge'
@@ -10,16 +10,16 @@
 }}
 
 {{
-    uniswap_compatible_v3_trades(
+    uniswap_compatible_v3_lps(
         blockchain = 'ethereum'
         , project = 'uniswap'
         , version = '3'
         , Pair_evt_Mint = source('uniswap_v3_ethereum', 'Pair_evt_Mint')
         , Pair_evt_Burn = source('uniswap_v3_ethereum', 'Pair_evt_Burn')
         , Factory_evt_PoolCreated = source('uniswap_v3_ethereum', 'Factory_evt_PoolCreated')
-        , NonfungibleTokenPositionManager_evt_Transfer = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_Transfer')
         , NonfungibleTokenPositionManager_evt_IncreaseLiquidity = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_IncreaseLiquidity')
         , NonfungibleTokenPositionManager_evt_DecreaseLiquidity = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_DecreaseLiquidity')
         , position_manager_addr = 0xc36442b4a4522e871399cd717abdd847ab11fe88
+        , NonfungibleTokenPositionManager_evt_Transfer = source('uniswap_v3_ethereum', 'NonfungibleTokenPositionManager_evt_Transfer')
     )
 }}
\ No newline at end of file
diff --git a/sources/uniswap/ethereum/uniswap_ethereum_sources.yml b/sources/uniswap/ethereum/uniswap_ethereum_sources.yml
index b54b69da10a..1eca3b84761 100644
--- a/sources/uniswap/ethereum/uniswap_ethereum_sources.yml
+++ b/sources/uniswap/ethereum/uniswap_ethereum_sources.yml
@@ -246,4 +246,38 @@ sources:
           - *id
 
       - name: Pair_evt_Flash
-        loaded_at_field: evt_block_time
\ No newline at end of file
+        loaded_at_field: evt_block_time
+
+      - name: NonfungibleTokenPositionManager_evt_IncreaseLiquidity
+        loaded_at_field: evt_block_time
+        columns:
+          - *contract_address
+          - *evt_block_number
+          - *evt_block_time
+          - *evt_index
+          - *evt_tx_hash
+          - &tokenId
+            name: tokenId
+
+      - name: NonfungibleTokenPositionManager_evt_DecreaseLiquidity
+        loaded_at_field: evt_block_time
+        columns:
+          - *contract_address
+          - *evt_block_number
+          - *evt_block_time
+          - *evt_index
+          - *evt_tx_hash
+          - *tokenId
+
+      - name: NonfungibleTokenPositionManager_evt_Transfer
+        loaded_at_field: evt_block_time
+        columns:
+          - *contract_address
+          - *evt_block_number
+          - *evt_block_time
+          - *evt_index
+          - *evt_tx_hash
+          - *tokenId
+          - &from
+            name: from
+          - *to
\ No newline at end of file

From f5522f54525c5176cfe24b73fdefb30a72ddf5f5 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 20 Mar 2024 21:11:28 +0100
Subject: [PATCH 03/17] fix: missing alias

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index c31f8b409fd..cf5acb50a51 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -17,7 +17,7 @@ WITH id_to_lp AS
         distinct t.tokenId
         ,t.to AS lp_address
     FROM
-        {{ NonfungibleTokenPositionManager_evt_Transfer }}
+        {{ NonfungibleTokenPositionManager_evt_Transfer }} t
     WHERE
         t."from" = 0x0000000000000000000000000000000000000000
 )

From 35082a63d4bd80121548fc7d0caff7e96a2cdb38 Mon Sep 17 00:00:00 2001
From: Huang Geyang <Sukebeta@outlook.com>
Date: Fri, 22 Mar 2024 15:41:45 +0800
Subject: [PATCH 04/17] Fix mismatched alias

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index cf5acb50a51..8bb6a17ab67 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -89,7 +89,7 @@ WITH id_to_lp AS
         , b.amount1
         , f.token0 AS token0_address
         , f.token1 AS token1_address
-        , m.contract_address AS pool_address
+        , b.contract_address AS pool_address
     FROM
         {{ Pair_evt_Burn }} b
     INNER JOIN

From d38780017647130e63c9dbaac8091aaea9f3dcc4 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 10:49:38 +0100
Subject: [PATCH 05/17] fix: alias typo

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 8bb6a17ab67..1b147f43e6c 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -118,8 +118,8 @@ SELECT
     , lp_data.evt_index
     , lp_data.lp_address
     , lp_data.position_id
-    , lp.tick_lower
-    , lp.tick_upper
+    , lp_data.tick_lower
+    , lp_data.tick_upper
     , CAST(lp_data.liquidity AS UINT256) AS liquidity_raw
     , CAST(lp_data.amount0 AS UINT256) AS amount0_raw
     , CAST(lp_data.amount1 AS UINT256) AS amount1_raw

From 6b933991a1febabc23ce0c97720da64d972cfb15 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 11:02:20 +0100
Subject: [PATCH 06/17] fix: aslias mismatch

---
 models/_sector/dex/lps/dex_base_lps.sql                   | 6 +++---
 models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/models/_sector/dex/lps/dex_base_lps.sql b/models/_sector/dex/lps/dex_base_lps.sql
index 6f924a5c53a..707adb4007e 100644
--- a/models/_sector/dex/lps/dex_base_lps.sql
+++ b/models/_sector/dex/lps/dex_base_lps.sql
@@ -26,9 +26,9 @@ with base_union as (
             , block_time
             , block_month
             , block_number
-            , token0_amount_raw
-            , token1_amount_raw
-            , liquidity_amount_raw
+            , amount0_raw
+            , amount1_raw
+            , liquidity_raw
             , token0_address
             , token1_address
             , pool_address
diff --git a/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql b/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
index 05f71d8bac4..96456c8c332 100644
--- a/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
+++ b/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
@@ -20,9 +20,9 @@ WITH base_union AS (
             , block_time
             , block_month
             , block_number
-            , token0_amount_raw
-            , token1_amount_raw
-            , liquidity_amount_raw
+            , amount0_raw
+            , amount1_raw
+            , liquidity_raw
             , token0_address
             , token1_address
             , pool_address

From 98a591e70c6aed62c3ecae6e43c4c3a2aee6e33f Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 11:03:03 +0100
Subject: [PATCH 07/17] fix: missing alias

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 1b147f43e6c..b0bdd0f794d 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -116,7 +116,7 @@ SELECT
     , date_trunc('MONTH', lp_data.block_time) AS block_month
     , lp_data.tx_hash
     , lp_data.evt_index
-    , lp_data.lp_address
+    , lp_data.lp_address as liquidity_provider
     , lp_data.position_id
     , lp_data.tick_lower
     , lp_data.tick_upper

From bddfe41f6421b63d624d891216fbda0abdd61993 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 11:27:08 +0100
Subject: [PATCH 08/17] fix: remove duplicates

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql       | 4 ++--
 models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index b0bdd0f794d..5799522b09c 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -114,8 +114,6 @@ SELECT
     , lp_data.block_number
     , lp_data.block_time
     , date_trunc('MONTH', lp_data.block_time) AS block_month
-    , lp_data.tx_hash
-    , lp_data.evt_index
     , lp_data.lp_address as liquidity_provider
     , lp_data.position_id
     , lp_data.tick_lower
@@ -126,6 +124,8 @@ SELECT
     , lp_data.token0_address
     , lp_data.token1_address
     , lp_data.pool_address
+    , lp_data.tx_hash
+    , lp_data.evt_index
 FROM
     (
         select * from mints
diff --git a/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql b/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
index 96456c8c332..3747c9d8e3a 100644
--- a/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
+++ b/models/_sector/dex/lps/ethereum/dex_ethereum_base_lps.sql
@@ -32,13 +32,20 @@ WITH base_union AS (
             , tick_upper
             , tx_hash
             , evt_index
+            , row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank
         FROM 
             {{ base_model }}
+        {% if is_incremental() %}
+        WHERE
+            {{ incremental_predicate('block_time') }}
+        {% endif %}
         {% if not loop.last %}
         UNION ALL
         {% endif %}
         {% endfor %}
     )
+    WHERE
+        duplicates_rank = 1
 )
 
 select

From 60ee493a1f0acbb535e2a9e0a743787605a1e2f5 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 11:39:41 +0100
Subject: [PATCH 09/17] fix: remove duplicates

---
 .../_sector/dex/uniswap_compatible_lp.sql     | 58 ++++++++++---------
 1 file changed, 32 insertions(+), 26 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 5799522b09c..a6d7cb0154f 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -106,30 +106,36 @@ WITH id_to_lp AS
     {% endif %}
 )
 
-SELECT
-    '{{ blockchain }}' AS blockchain
-    , '{{ project }}' AS project
-    , '{{ version }}' AS version
-    , lp_data.event_type
-    , lp_data.block_number
-    , lp_data.block_time
-    , date_trunc('MONTH', lp_data.block_time) AS block_month
-    , lp_data.lp_address as liquidity_provider
-    , lp_data.position_id
-    , lp_data.tick_lower
-    , lp_data.tick_upper
-    , CAST(lp_data.liquidity AS UINT256) AS liquidity_raw
-    , CAST(lp_data.amount0 AS UINT256) AS amount0_raw
-    , CAST(lp_data.amount1 AS UINT256) AS amount1_raw
-    , lp_data.token0_address
-    , lp_data.token1_address
-    , lp_data.pool_address
-    , lp_data.tx_hash
-    , lp_data.evt_index
-FROM
-    (
-        select * from mints
-        union all
-        select * from burns
-    ) lp_data
+SELECT *
+FROM (
+    SELECT
+        '{{ blockchain }}' AS blockchain
+        , '{{ project }}' AS project
+        , '{{ version }}' AS version
+        , event_type
+        , block_number
+        , block_time
+        , date_trunc('MONTH', block_time) AS block_month
+        , lp_address as liquidity_provider
+        , position_id
+        , tick_lower
+        , tick_upper
+        , CAST(liquidity AS UINT256) AS liquidity_raw
+        , CAST(amount0 AS UINT256) AS amount0_raw
+        , CAST(amount1 AS UINT256) AS amount1_raw
+        , token0_address
+        , token1_address
+        , pool_address
+        , tx_hash
+        , evt_index
+        , row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank
+    FROM
+        (
+            select * from mints
+            union all
+            select * from burns
+        ) lp_data
+) lp_data
+WHERE
+    duplicates_rank = 1
 {% endmacro %}
\ No newline at end of file

From f2eab4ded5367076e826159b4782ba49b3c5ec8b Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:04:09 +0100
Subject: [PATCH 10/17] fix: position manager ids

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index a6d7cb0154f..d7d929f8fcd 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -30,12 +30,12 @@ WITH id_to_lp AS
         ,m.evt_block_time AS block_time
         ,m.evt_tx_hash AS tx_hash
         ,m.evt_index
-        , {% if position_manager_addr %}
+        , {% if m.owner = position_manager_addr %}
                 id.lp_address
             {% else %}
                 m.owner
             {% endif %} AS lp_address
-        , {% if position_manager_addr %}
+        , {% if m.owner = position_manager_addr %}
                 cast(pm.tokenId AS double)
             {% else %}
                 0

From b297d223ade3913a8ea29ed534a7308508ab850a Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:09:51 +0100
Subject: [PATCH 11/17] fix: position mannager join

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index d7d929f8fcd..b35dd57fd63 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -30,12 +30,12 @@ WITH id_to_lp AS
         ,m.evt_block_time AS block_time
         ,m.evt_tx_hash AS tx_hash
         ,m.evt_index
-        , {% if m.owner = position_manager_addr %}
+        , {% if id.lp_address %}
                 id.lp_address
             {% else %}
                 m.owner
             {% endif %} AS lp_address
-        , {% if m.owner = position_manager_addr %}
+        , {% if id.lp_address %}
                 cast(pm.tokenId AS double)
             {% else %}
                 0

From 15cf3969805f25c7cd12432cadbefcdbbd47a3c2 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:14:29 +0100
Subject: [PATCH 12/17] fix: position manager id

---
 .../_sector/dex/uniswap_compatible_lp.sql     | 20 ++++++-------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index b35dd57fd63..0e7f8589794 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -26,20 +26,12 @@ WITH id_to_lp AS
 (
     SELECT
         'mint' AS event_type
-        ,m.evt_block_number AS block_number
-        ,m.evt_block_time AS block_time
-        ,m.evt_tx_hash AS tx_hash
-        ,m.evt_index
-        , {% if id.lp_address %}
-                id.lp_address
-            {% else %}
-                m.owner
-            {% endif %} AS lp_address
-        , {% if id.lp_address %}
-                cast(pm.tokenId AS double)
-            {% else %}
-                0
-            {% endif %} AS position_id
+        , m.evt_block_number AS block_number
+        , m.evt_block_time AS block_time
+        , m.evt_tx_hash AS tx_hash
+        , m.evt_index
+        , CASE WHEN m.owner = position_manager_addr THEN id.lp_address ELSE m.owner END AS lp_address
+        , CASE WHEN m.owner = position_manager_addr THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
         , m.tickLower AS tick_lower
         , m.tickUpper AS tick_upper
         , m.amount AS liquidity

From 8045149c6aaedd57800274b366c62c02a0a390ba Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:22:04 +0100
Subject: [PATCH 13/17] fix: use variable properly

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 0e7f8589794..7a62d4cf5be 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -30,8 +30,8 @@ WITH id_to_lp AS
         , m.evt_block_time AS block_time
         , m.evt_tx_hash AS tx_hash
         , m.evt_index
-        , CASE WHEN m.owner = position_manager_addr THEN id.lp_address ELSE m.owner END AS lp_address
-        , CASE WHEN m.owner = position_manager_addr THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
+        , CASE WHEN m.owner = {{ position_manager_addr }} THEN id.lp_address ELSE m.owner END AS lp_address
+        , CASE WHEN m.owner = {{ position_manager_addr }} THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
         , m.tickLower AS tick_lower
         , m.tickUpper AS tick_upper
         , m.amount AS liquidity

From 8ddaf97feb414d7d50ac2141d0c5052f65ecb3bd Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:32:09 +0100
Subject: [PATCH 14/17] fix: cast input address

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 7a62d4cf5be..6b93178ef7a 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -30,8 +30,8 @@ WITH id_to_lp AS
         , m.evt_block_time AS block_time
         , m.evt_tx_hash AS tx_hash
         , m.evt_index
-        , CASE WHEN m.owner = {{ position_manager_addr }} THEN id.lp_address ELSE m.owner END AS lp_address
-        , CASE WHEN m.owner = {{ position_manager_addr }} THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
+        , CASE WHEN m.owner = CAST({{ position_manager_addr }} AS varbinary) THEN id.lp_address ELSE m.owner END AS lp_address
+        , CASE WHEN m.owner = CAST({{ position_manager_addr }} AS varbinary) THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
         , m.tickLower AS tick_lower
         , m.tickUpper AS tick_upper
         , m.amount AS liquidity

From a276d4eb54c19d7983f88d13c4985c3db33b6f61 Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:45:14 +0100
Subject: [PATCH 15/17] hardcode position manager address

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 6b93178ef7a..94152b7ea1f 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -30,8 +30,8 @@ WITH id_to_lp AS
         , m.evt_block_time AS block_time
         , m.evt_tx_hash AS tx_hash
         , m.evt_index
-        , CASE WHEN m.owner = CAST({{ position_manager_addr }} AS varbinary) THEN id.lp_address ELSE m.owner END AS lp_address
-        , CASE WHEN m.owner = CAST({{ position_manager_addr }} AS varbinary) THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
+        , CASE WHEN m.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN id.lp_address ELSE m.owner END AS lp_address
+        , CASE WHEN m.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
         , m.tickLower AS tick_lower
         , m.tickUpper AS tick_upper
         , m.amount AS liquidity

From bd4757a251b76dce7e1374cc80d9d93832432c0a Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 12:57:48 +0100
Subject: [PATCH 16/17] fix: burns

---
 .../models/_sector/dex/uniswap_compatible_lp.sql   | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 94152b7ea1f..29a18cd6b47 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -31,7 +31,7 @@ WITH id_to_lp AS
         , m.evt_tx_hash AS tx_hash
         , m.evt_index
         , CASE WHEN m.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN id.lp_address ELSE m.owner END AS lp_address
-        , CASE WHEN m.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN cast(pm.tokenId AS double) ELSE 0 END AS position_id
+        , CASE WHEN m.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN cast(pm.tokenId AS double) END AS position_id
         , m.tickLower AS tick_lower
         , m.tickUpper AS tick_upper
         , m.amount AS liquidity
@@ -64,16 +64,8 @@ WITH id_to_lp AS
         ,b.evt_block_time AS block_time
         ,b.evt_tx_hash AS tx_hash
         ,b.evt_index
-        , {% if position_manager_addr %}
-                id.lp_address
-            {% else %}
-                b.owner
-            {% endif %} AS lp_address
-        , {% if position_manager_addr %}
-                cast(pm.tokenId AS double)
-            {% else %}
-                0
-            {% endif %} AS position_id
+        , CASE WHEN b.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN id.lp_address ELSE b.owner END AS lp_address
+        , CASE WHEN b.owner = 0xc36442b4a4522e871399cd717abdd847ab11fe88 THEN cast(pm.tokenId AS double) END AS position_id
         , b.tickLower AS tick_lower
         , b.tickUpper AS tick_upper
         , b.amount AS liquidity

From 2001e4b895c79643013e8a0303a1f785ee87587a Mon Sep 17 00:00:00 2001
From: 0xrusowsky <0xrusowsky@proton.me>
Date: Wed, 27 Mar 2024 15:17:13 +0100
Subject: [PATCH 17/17] fix: wrong table

---
 macros/models/_sector/dex/uniswap_compatible_lp.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/macros/models/_sector/dex/uniswap_compatible_lp.sql b/macros/models/_sector/dex/uniswap_compatible_lp.sql
index 29a18cd6b47..7d9d5aabe90 100644
--- a/macros/models/_sector/dex/uniswap_compatible_lp.sql
+++ b/macros/models/_sector/dex/uniswap_compatible_lp.sql
@@ -80,7 +80,7 @@ WITH id_to_lp AS
         {{ Factory_evt_PoolCreated }} f
         ON f.pool = b.contract_address
     LEFT JOIN
-        {{ NonfungibleTokenPositionManager_evt_IncreaseLiquidity }} pm
+        {{ NonfungibleTokenPositionManager_evt_DecreaseLiquidity }} pm
         ON b.owner = pm.contract_address and b.evt_tx_hash = pm.evt_tx_hash
     LEFT JOIN id_to_lp AS id
         ON pm.tokenId = id.tokenId