Skip to content

Commit

Permalink
Add Timeswap dex to trades (#7348)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Huang Geyang <[email protected]>
Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
4 people authored Jan 24, 2025
1 parent c7484cf commit ba26f64
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions dbt_subprojects/dex/models/dex_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
25 changes: 22 additions & 3 deletions dbt_subprojects/dex/models/trades/optimism/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -623,4 +642,4 @@ models:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('bridgers_optimism_base_trades_seed')
seed_file: ref('bridgers_optimism_base_trades_seed')
Original file line number Diff line number Diff line change
Expand Up @@ -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')
] %}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion dbt_subprojects/dex/seeds/trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -4803,4 +4818,4 @@ seeds:
token_sold_address: varbinary
token_bought_amount_raw: uint256
token_sold_amount_raw: uint256
block_date: timestamp
block_date: timestamp
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions sources/_sector/dex/trades/optimism/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba26f64

Please sign in to comment.