Skip to content

feat: add Tempo DEXs#9506

Open
jeff-dude wants to merge 13 commits intomainfrom
cursor/CUR2-1693-tempo-exchange-base-trades-bf73
Open

feat: add Tempo DEXs#9506
jeff-dude wants to merge 13 commits intomainfrom
cursor/CUR2-1693-tempo-exchange-base-trades-bf73

Conversation

@jeff-dude
Copy link
Copy Markdown
Member

@jeff-dude jeff-dude commented Mar 30, 2026

Thank you for contributing to Spellbook 🪄

Description:

Adds DEX trading support for the Tempo blockchain, wiring four protocols into the full dex.trades lineage.

Tempo Exchange (tempo_exchange_tempo_base_trades.sql):

  • Standalone inline SQL model sourcing from two decoded call tables:
    • tempoexchange_tempo.stablecoindex_call_swapexactamountin — exact input swaps
    • tempoexchange_tempo.stablecoindex_call_swapexactamountout — exact output swaps
  • Unions both swap types, mapping tokenIn/tokenOut and actual amounts to the standard base trades schema
  • Filters on call_success = true; uses incremental_predicate for incremental runs

Uniswap V2 (uniswap_v2_tempo_base_trades.sql):

  • Uses the shared uniswap_compatible_v2_trades macro with pair_evt_swap and uniswapv2factory_evt_paircreated sources

Uniswap V3 (uniswap_v3_tempo_base_trades.sql):

  • Uses the shared uniswap_compatible_v3_trades macro with uniswapv3pool_evt_swap and uniswapv3factory_evt_poolcreated sources

Uniswap V4 (uniswap_v4_tempo_base_trades.sql):

  • Uses the shared uniswap_compatible_v4_trades macro with PoolManager_call_Swap source

Chain-level models (new tempo/ directory):

  • dex_tempo_base_trades.sql — unions all four platform base trades with add_tx_columns
  • dex_tempo_trades.sql — enriches with token metadata and USD pricing via enrich_dex_trades
  • dex_tempo_token_volumes_daily.sql — daily token volume aggregation

Infrastructure:

  • Sources YAML at sources/_sector/dex/trades/tempo/_sources.yml declaring decoded tables for all protocols
  • Uniswap-specific sources at sources/uniswap/tempo/uniswap_tempo_sources.yml
  • Schema YAML with uniqueness tests and seed test references for all platforms
  • Seed CSVs with column types registered in seeds/trades/_schema.yml
  • 'tempo' added to the chains list in dex_trades.sql
  • Temporary 14-day non-incremental filter in dex_trades.sql to expedite CI (to be reverted before merge)

All models compile successfully via dbt compile.


quick links for more information:

Linear Issue: CUR2-1693

Open in Web Open in Cursor 

cursoragent and others added 2 commits March 30, 2026 21:36
- Add platform model: uniswap_v4_tempo_base_trades.sql
- Add chain-level union: dex_tempo_base_trades.sql
- Add chain-level enriched trades: dex_tempo_trades.sql
- Add token volumes daily: dex_tempo_token_volumes_daily.sql
- Add 'tempo' to cross-chain dex_trades.sql, dex_token_volumes_daily.sql, dex_trades_view_test.sql
- Add source definitions for uniswap_v4_tempo (PoolManager events + calls)
- Add schema, seed CSV, and seed schema entry

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
- Add tempo_exchange_tempo_base_trades.sql platform model using
  swapExactAmountIn and swapExactAmountOut call tables
- Add chain-level models: dex_tempo_base_trades, dex_tempo_trades,
  dex_tempo_token_volumes_daily
- Add sources YAML for tempoexchange_tempo decoded tables
- Add schema, seed CSV, and seed schema for tempo_exchange
- Wire tempo into dex_trades cross-chain union

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@github-actions github-actions bot added WIP work in progress dbt: dex covers the DEX dbt subproject labels Mar 30, 2026
…ap-v4-7a59' into cursor/CUR2-1693-tempo-exchange-base-trades-bf73

# Conflicts:
#	dbt_subprojects/dex/models/trades/tempo/_schema.yml
#	dbt_subprojects/dex/models/trades/tempo/dex_tempo_base_trades.sql
#	dbt_subprojects/dex/seeds/trades/_schema.yml
#	sources/_sector/dex/trades/tempo/_sources.yml

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude jeff-dude changed the title feat: add Tempo Exchange DEX base trades for tempo chain feat: add Tempo DEXs Mar 30, 2026
@jeff-dude
Copy link
Copy Markdown
Member Author

@cursor push a temp commit in dex_trades model to filter non-incremental runs to last 14 days to expedite CI runs

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 30, 2026

Added a temporary 14-day filter on non-incremental runs in dex_trades.sql — both the chain_trades and as_is_dexs CTEs now include WHERE block_time >= now() - interval '14' day on full-refresh paths. This will limit the data scanned during CI. Committed and pushed with a reminder that it must be reverted before merge.

Open in Web Open in Cursor 

…dite CI

This is a temporary commit to speed up CI runs. Must be reverted before merge.

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude
Copy link
Copy Markdown
Member Author

@cursor apply above suggest changes in comment

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 31, 2026

Applied all four review suggestions from @jeff-dude to tempo_exchange_tempo_base_trades.sql:

  • Removed unnecessary CAST(... AS uint256) on amount columns (amountIn, output_amountOut, output_amountIn, amountOut)
  • Changed ROW_NUMBER() ordering from call_block_time to call_trace_address
  • Added call_block_date AS block_date to both CTEs and used dexs.block_date directly instead of CAST(date_trunc('day', ...) AS date)
  • Replaced CAST(NULL AS VARBINARY) AS taker with call_tx_from AS taker sourced from the CTEs
Open in Web Open in Cursor 

- Remove unnecessary CAST on amount columns
- Use call_trace_address for ROW_NUMBER ordering
- Add call_block_date to CTEs and use directly
- Use call_tx_from as taker instead of NULL

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude
Copy link
Copy Markdown
Member Author

@cursor can you add the uniswap v2 and v3 models for tempo too? similar to v4, there are existing macros we can use. here are tables:

uniswap_v2_tempo.uniswapv2factory_evt_paircreated
uniswap_v2_tempo.pair_evt_swap
uniswap_v3_tempo.uniswapv3factory_evt_poolcreated
uniswap_v3_tempo.uniswapv3pool_evt_swap

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 31, 2026

Added Uniswap V2 and V3 models for the Tempo chain:

  • uniswap_v2_tempo_base_trades.sql — uses the uniswap_compatible_v2_trades macro with pair_evt_swap and uniswapv2factory_evt_paircreated sources
  • uniswap_v3_tempo_base_trades.sql — uses the uniswap_compatible_v3_trades macro with uniswapv3pool_evt_swap and uniswapv3factory_evt_poolcreated sources
  • Added V2/V3 source declarations in _sources.yml, schema entries with seed tests (shared uniswap_tempo_base_trades_seed, filtered by version 2/3), and wired both into dex_tempo_base_trades union (now 4 platforms total)

All models compile successfully.

Open in Web Open in Cursor 

- Add uniswap_v2_tempo_base_trades using uniswap_compatible_v2_trades macro
- Add uniswap_v3_tempo_base_trades using uniswap_compatible_v3_trades macro
- Add V2/V3 source declarations for decoded tables
- Add schema entries with seed tests (shared uniswap_tempo seed, filtered by version)
- Wire V2/V3 into dex_tempo_base_trades union (now 4 platforms)

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude
Copy link
Copy Markdown
Member Author

jeff-dude commented Mar 31, 2026

todo:

  • - wait for v2/3 decoded tables to have data backfilled
  • - rerun CI
  • - remove temp commit to dex trades

@jeff-dude jeff-dude marked this pull request as ready for review March 31, 2026 19:41
@github-actions github-actions bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Mar 31, 2026
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for all 3 issues found in the latest run.

  • ✅ Fixed: Temporary CI window limits production history
    • Removed the WHERE block_time >= now() - interval '14' day filter from both the chain_trades and as_is_dexs non-incremental paths in dex_trades.sql, restoring full-refresh behavior.
  • ✅ Fixed: Event index collisions across swap types
    • Moved ROW_NUMBER() computation from individual swap CTEs to after the UNION ALL in the final SELECT, so evt_index is assigned globally per tx_hash across both swap types.
  • ✅ Fixed: Synthetic event indexes drop cross-protocol trades
    • Added project to the dedup partition in dex_tempo_base_trades.sql so that synthetic evt_index values from tempo_exchange cannot collide with real evt_index values from other protocols in the same transaction.

Create PR

Or push these changes by commenting:

@cursor push 9a274a5a2a
Preview (9a274a5a2a)
diff --git a/dbt_subprojects/dex/models/trades/dex_trades.sql b/dbt_subprojects/dex/models/trades/dex_trades.sql
--- a/dbt_subprojects/dex/models/trades/dex_trades.sql
+++ b/dbt_subprojects/dex/models/trades/dex_trades.sql
@@ -110,8 +110,6 @@
     {%- else -%}
     {% if is_incremental() %}
     WHERE {{ incremental_predicate('block_time') }}
-    {% else %}
-    WHERE block_time >= now() - interval '14' day -- temp CI filter, revert before merge
     {% endif %}
     {%- endif %}
     {% if not loop.last %}
@@ -154,8 +152,6 @@
     {%- else -%}
     {% if is_incremental() %}
     WHERE {{ incremental_predicate('block_time') }}
-    {% else %}
-    WHERE block_time >= now() - interval '14' day -- temp CI filter, revert before merge
     {% endif %}
     {%- endif %}
     {% if not loop.last %}

diff --git a/dbt_subprojects/dex/models/trades/tempo/dex_tempo_base_trades.sql b/dbt_subprojects/dex/models/trades/tempo/dex_tempo_base_trades.sql
--- a/dbt_subprojects/dex/models/trades/tempo/dex_tempo_base_trades.sql
+++ b/dbt_subprojects/dex/models/trades/tempo/dex_tempo_base_trades.sql
@@ -64,7 +64,7 @@
 , final as (
     select
         *
-        , row_number() over (partition by tx_hash, evt_index order by tx_hash) as duplicates_rank
+        , row_number() over (partition by tx_hash, evt_index, project order by tx_hash) as duplicates_rank
     from
         add_tx_columns
 )

diff --git a/dbt_subprojects/dex/models/trades/tempo/platforms/tempo_exchange_tempo_base_trades.sql b/dbt_subprojects/dex/models/trades/tempo/platforms/tempo_exchange_tempo_base_trades.sql
--- a/dbt_subprojects/dex/models/trades/tempo/platforms/tempo_exchange_tempo_base_trades.sql
+++ b/dbt_subprojects/dex/models/trades/tempo/platforms/tempo_exchange_tempo_base_trades.sql
@@ -22,7 +22,7 @@
         , contract_address AS project_contract_address
         , call_tx_hash AS tx_hash
         , call_tx_from AS taker
-        , ROW_NUMBER() OVER (PARTITION BY call_tx_hash ORDER BY call_trace_address) AS row_num
+        , call_trace_address
     FROM {{ source('tempoexchange_tempo', 'stablecoindex_call_swapexactamountin') }}
     WHERE call_success = true
     {% if is_incremental() -%}
@@ -42,7 +42,7 @@
         , contract_address AS project_contract_address
         , call_tx_hash AS tx_hash
         , call_tx_from AS taker
-        , ROW_NUMBER() OVER (PARTITION BY call_tx_hash ORDER BY call_trace_address) AS row_num
+        , call_trace_address
     FROM {{ source('tempoexchange_tempo', 'stablecoindex_call_swapexactamountout') }}
     WHERE call_success = true
     {% if is_incremental() -%}
@@ -72,5 +72,5 @@
     , CAST(NULL AS VARBINARY) AS maker
     , dexs.project_contract_address
     , dexs.tx_hash
-    , dexs.row_num AS evt_index
+    , ROW_NUMBER() OVER (PARTITION BY dexs.tx_hash ORDER BY dexs.call_trace_address) AS evt_index
 FROM dexs

You can send follow-ups to this agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

@jeff-dude
Copy link
Copy Markdown
Member Author

@cursor can you remove the seed files, seed schema additions and seed tests?

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 31, 2026

Removed all seed-related artifacts for tempo DEXs:

  • Deleted both seed CSV files (tempo_exchange_tempo_base_trades_seed.csv and uniswap_tempo_base_trades_seed.csv)
  • Removed both seed schema entries from seeds/trades/_schema.yml
  • Removed all four check_dex_base_trades_seed test blocks from the model _schema.yml (tempo_exchange, uniswap v2, v3, v4)

All models still compile cleanly.

Open in Web Open in Cursor 

…po DEXs

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
cursoragent and others added 2 commits March 31, 2026 20:08
Merge uniswap_v4_tempo evt tables (PoolManager_evt_Swap,
PoolManager_evt_Initialize) into sources/_sector/dex/trades/tempo/_sources.yml
and delete the separate sources/uniswap/tempo/uniswap_tempo_sources.yml.

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude
Copy link
Copy Markdown
Member Author

@cursor revert temp commit which hardcoded time filter on dex_trades model

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 1, 2026

Reverted the temporary 14-day non-incremental filter from dex_trades.sql. Both the chain_trades and as_is_dexs CTEs are now back to the original behavior where non-incremental runs have no time restriction.

Open in Web Open in Cursor 

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude jeff-dude requested a review from a team April 1, 2026 14:21
Copy link
Copy Markdown
Contributor

@tomfutago tomfutago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just seeds missing and entry in dex_info (if that's still a thing)

Co-authored-by: jeff-dude <jeff-dude@users.noreply.github.com>
@jeff-dude jeff-dude added ready-for-merging and removed ready-for-review this PR development is complete, please review labels Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dbt: dex covers the DEX dbt subproject ready-for-merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants