From ba26f64b801ae4fb2d16de09dca24a8fd141504f Mon Sep 17 00:00:00 2001 From: archie17277 <160746411+archie17277@users.noreply.github.com> Date: Sat, 25 Jan 2025 03:32:40 +0530 Subject: [PATCH] Add Timeswap dex to trades (#7348) * Added timeswap dex * Added timeswap dex * Update sql file * Update _schema.yml * update sql file * Update timeswap_v2_optimism_base_trades.sql * update sql file * Update _schema.yml * update schema file * update schema file * Fix saddle finance test * Remove duped saddle_finance_optimism_base_trades --------- Co-authored-by: 0xRob <83790096+0xRobin@users.noreply.github.com> Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- dbt_subprojects/dex/models/dex_info.sql | 1 + .../dex/models/trades/optimism/_schema.yml | 25 +++++++- .../optimism/dex_optimism_base_trades.sql | 1 + .../timeswap_v2_optimism_base_trades.sql | 57 +++++++++++++++++++ dbt_subprojects/dex/seeds/trades/_schema.yml | 17 +++++- .../timeswap_v2_optimism_base_trades_seed.csv | 3 + .../_sector/dex/trades/optimism/_sources.yml | 3 + 7 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 dbt_subprojects/dex/models/trades/optimism/platforms/timeswap_v2_optimism_base_trades.sql create mode 100644 dbt_subprojects/dex/seeds/trades/timeswap_v2_optimism_base_trades_seed.csv diff --git a/dbt_subprojects/dex/models/dex_info.sql b/dbt_subprojects/dex/models/dex_info.sql index 173aea33710..85adf56b98a 100644 --- a/dbt_subprojects/dex/models/dex_info.sql +++ b/dbt_subprojects/dex/models/dex_info.sql @@ -186,6 +186,7 @@ FROM (VALUES , ('kaia_swap', 'KaiaSwap', 'Direct', 'KaiaSwap') , ('defi_kingdoms', 'DeFi Kingdoms', 'Direct', 'DeFiKingdoms') , ('hyperjump', 'HyperJump', 'Direct', 'Hyperjump_fi') + , ('timeswap', 'Timeswap', 'Direct', 'TimeswapLabs') , ('infusion', 'Infusion', 'Direct', 'infusionfinance') , ('stablebase', 'StableBase', 'Direct', 'stablebasefi') , ('flashliquidity', 'Flashliquidity', 'Direct', 'flashliquidity') diff --git a/dbt_subprojects/dex/models/trades/optimism/_schema.yml b/dbt_subprojects/dex/models/trades/optimism/_schema.yml index f7ea645d2a5..26c121ce00f 100644 --- a/dbt_subprojects/dex/models/trades/optimism/_schema.yml +++ b/dbt_subprojects/dex/models/trades/optimism/_schema.yml @@ -591,6 +591,25 @@ models: filter: version: 2 + - name: timeswap_v2_optimism_base_trades + meta: + blockchain: optimism + sector: dex + project: timeswap_v2 + contributors: archie + config: + tags: [ 'optimism', 'dex', 'trades', 'timeswap', 'v2'] + description: "timeswap v2 optimism base trades" + data_tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_dex_base_trades_seed: + seed_file: ref('timeswap_v2_optimism_base_trades_seed') + filter: + version: 2 + - name: saddle_finance_optimism_base_trades meta: blockchain: optimism @@ -606,8 +625,8 @@ models: - tx_hash - evt_index - check_dex_base_trades_seed: - seed_file: ref('saddle_finance_optimism_base_trades_seed') - + seed_file: ref('saddle_finance_optimism_base_trades_seed') + - name: bridgers_optimism_base_trades meta: blockchain: optimism @@ -623,4 +642,4 @@ models: - tx_hash - evt_index - check_dex_base_trades_seed: - seed_file: ref('bridgers_optimism_base_trades_seed') \ No newline at end of file + seed_file: ref('bridgers_optimism_base_trades_seed') diff --git a/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql b/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql index 8f7399fa326..3c6b10c0a09 100644 --- a/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql +++ b/dbt_subprojects/dex/models/trades/optimism/dex_optimism_base_trades.sql @@ -36,6 +36,7 @@ , ref('elk_finance_optimism_base_trades') , ref('fraxswap_optimism_base_trades') , ref('swaap_v2_optimism_base_trades') + , ref('timeswap_v2_optimism_base_trades') , ref('bridgers_optimism_base_trades') , ref('saddle_finance_optimism_base_trades') ] %} diff --git a/dbt_subprojects/dex/models/trades/optimism/platforms/timeswap_v2_optimism_base_trades.sql b/dbt_subprojects/dex/models/trades/optimism/platforms/timeswap_v2_optimism_base_trades.sql new file mode 100644 index 00000000000..abb21123144 --- /dev/null +++ b/dbt_subprojects/dex/models/trades/optimism/platforms/timeswap_v2_optimism_base_trades.sql @@ -0,0 +1,57 @@ +{{ + config( + schema = 'timeswap_v2_optimism', + 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')] + ) +}} + +WITH dexs AS +( + SELECT + t.evt_block_number AS block_number + -- , t.evt_block_date AS block_date + , t.evt_block_time AS block_time + , CAST(null AS VARBINARY) AS taker + , t.contract_address AS maker + , CASE WHEN t.token0AndLong0Amount < INT256 '0' THEN abs(t.token0AndLong0Amount) ELSE abs(t.token1AndLong1Amount) END AS token_bought_amount_raw + , CASE WHEN t.token0AndLong0Amount < INT256 '0' THEN abs(t.token1AndLong1Amount) ELSE abs(t.token0AndLong0Amount) END AS token_sold_amount_raw + , CASE WHEN t.token0AndLong0Amount < INT256 '0' THEN t.tokenTo ELSE t.longTo END AS token_bought_address + , CASE WHEN t.token0AndLong0Amount < INT256 '0' THEN t.longTo ELSE t.tokenTo END AS token_sold_address + , t.contract_address AS project_contract_address + , t.evt_tx_hash AS tx_hash + , t.evt_index AS evt_index + , t.evt_tx_from AS tx_from + , t.evt_tx_to AS tx_to + FROM {{ source('timeswap_v2_optimism', 'TimeswapV2Option_evt_Swap') }} t + {% if is_incremental() %} + WHERE + {{ incremental_predicate('t.evt_block_time') }} + {% endif %} +) + +SELECT + 'optimism' AS blockchain + , 'timeswap' AS project + , '2' AS version + , CAST(date_trunc('month', dexs.block_time) AS date) AS block_month + , CAST(date_trunc('day', dexs.block_time) AS date) AS block_date + , dexs.block_time + , dexs.block_number + , dexs.token_bought_amount_raw + , dexs.token_sold_amount_raw + , dexs.token_bought_address + , dexs.token_sold_address + , dexs.taker + , dexs.maker + , dexs.project_contract_address + , dexs.tx_hash + , dexs.evt_index + , dexs.tx_from + , dexs.tx_to +FROM + dexs diff --git a/dbt_subprojects/dex/seeds/trades/_schema.yml b/dbt_subprojects/dex/seeds/trades/_schema.yml index 8b5028d8b0a..83450755817 100644 --- a/dbt_subprojects/dex/seeds/trades/_schema.yml +++ b/dbt_subprojects/dex/seeds/trades/_schema.yml @@ -4470,6 +4470,21 @@ seeds: token_sold_amount_raw: uint256 block_date: timestamp + - name: timeswap_v2_optimism_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp + - name: infusion_base_base_trades_seed config: column_types: @@ -4803,4 +4818,4 @@ seeds: token_sold_address: varbinary token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 - block_date: timestamp \ No newline at end of file + block_date: timestamp diff --git a/dbt_subprojects/dex/seeds/trades/timeswap_v2_optimism_base_trades_seed.csv b/dbt_subprojects/dex/seeds/trades/timeswap_v2_optimism_base_trades_seed.csv new file mode 100644 index 00000000000..564e9e1d0ad --- /dev/null +++ b/dbt_subprojects/dex/seeds/trades/timeswap_v2_optimism_base_trades_seed.csv @@ -0,0 +1,3 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,block_number,token_bought_amount_raw,token_sold_amount_raw +optimism,timeswap,2,2024-02-08,0x90d645b281c3ed4426635085f55624e7d2a199616bb2629002d49b7e0f5e3016,15,0xee486841a813504c3466e0006167a57c073b6c4d,0xd6cb50081a0087be91066723211b50ee3753f0da,115891534,12828,3947076923076924 +optimism,timeswap,2,2023-12-22,0xf70eac3e9afe21e0c2c8f676d55be49d8100f9234b964a2068f799ea5f0bcca6,36,0xee486841a813504c3466e0006167a57c073b6c4d,0xb3d1e41f84acd0e77f83473aa62fc8560c2a3c0c,113841782,219912892,157080637142857142857 \ No newline at end of file diff --git a/sources/_sector/dex/trades/optimism/_sources.yml b/sources/_sector/dex/trades/optimism/_sources.yml index 92c1a7d2d65..ef43f0bf45a 100644 --- a/sources/_sector/dex/trades/optimism/_sources.yml +++ b/sources/_sector/dex/trades/optimism/_sources.yml @@ -101,6 +101,9 @@ sources: - name: swaap_v2_optimism tables: - name: Vault_evt_Swap + - name: timeswap_v2_optimism + tables: + - name: TimeswapV2Option_evt_Swap - name: saddle_finance_optimism tables: - name: SwapFlashLoan_evt_TokenSwap