Skip to content

Commit

Permalink
add chains to swaap_v2 dex (#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
borelien authored Jul 8, 2024
1 parent 34e5ef4 commit 4ceb30d
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 57 deletions.
49 changes: 49 additions & 0 deletions dex/macros/models/_project/swaap_compatible_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% macro swaap_v2_compatible_trades(
blockchain = null,
project = null,
version = null
)
%}

WITH dexs AS
(
SELECT
t.evt_block_number AS block_number
, t.evt_block_time AS block_time
, CAST(null AS VARBINARY) AS taker
, t.contract_address AS maker
, CASE WHEN amountIn < INT256 '0' THEN abs(amountIn) ELSE abs(amountOut) END AS token_bought_amount_raw -- when amountIn is negative it means trader_a is buying tokenIn from the pool
, CASE WHEN amountIn < INT256 '0' THEN abs(amountOut) ELSE abs(amountIn) END AS token_sold_amount_raw
, CASE WHEN amountIn < INT256 '0' THEN t.tokenIn ELSE t.tokenOut END AS token_bought_address
, CASE WHEN amountIn < INT256 '0' THEN t.tokenOut ELSE t.tokenIn 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
FROM {{ source(project ~ '_v' ~ version ~ '_' ~ blockchain, 'Vault_evt_Swap' )}} t
{% if is_incremental() %}
WHERE
{{ incremental_predicate('t.evt_block_time') }}
{% endif %}
)

SELECT
'{{ blockchain }}' AS blockchain
, '{{ project }}' AS project
, '{{ version }}' 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
FROM
dexs

{% endmacro %}
11 changes: 6 additions & 5 deletions dex/models/trades/arbitrum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,20 @@ models:
meta:
blockchain: arbitrum
sector: dex
project: swaap_v2
project: swaap
contributors: LLDAO
config:
tags: [ 'arbitrum', 'dex', 'trades', 'swaap_v2']
description: "swaap_v2 Arbitrum base trades"
tags: [ 'arbitrum', 'dex', 'trades', 'swaap', 'v2']
description: "swaap v2 arbitrum base trades"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('swaap_v2_arbitrum_base_trades_seed')
seed_file: ref('swaap_arbitrum_base_trades_seed')
filter:
version: 2

- name: apeswap_arbitrum_base_trades
meta:
Expand Down Expand Up @@ -735,4 +737,3 @@ models:
seed_file: ref('dackieswap_v2_arbitrum_base_trades_seed')
filter:
version: 2

Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,10 @@
)
}}

WITH dexs AS
(
SELECT
t.evt_block_number AS block_number
, t.evt_block_time AS block_time
, CAST(null AS VARBINARY) AS taker
, t.contract_address AS maker
, CASE WHEN amountIn < INT256 '0' THEN abs(amountIn) ELSE abs(amountOut) END AS token_bought_amount_raw -- when amountIn is negative it means trader_a is buying tokenIn from the pool
, CASE WHEN amountIn < INT256 '0' THEN abs(amountOut) ELSE abs(amountIn) END AS token_sold_amount_raw
, CASE WHEN amountIn < INT256 '0' THEN t.tokenIn ELSE t.tokenOut END AS token_bought_address
, CASE WHEN amountIn < INT256 '0' THEN t.tokenOut ELSE t.tokenIn 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
FROM {{ source('swaap_v2_arbitrum', 'Vault_evt_Swap') }} t
{% if is_incremental() %}
WHERE
{{ incremental_predicate('t.evt_block_time') }}
{% endif %}
)

SELECT
'arbitrum' AS blockchain
, 'swaap' 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
FROM
dexs

{{
swaap_v2_compatible_trades(
blockchain = 'arbitrum',
project = 'swaap',
version = '2'
)
}}
18 changes: 18 additions & 0 deletions dex/models/trades/base/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -920,3 +920,21 @@ models:
version:
- 1

- name: swaap_v2_base_base_trades
meta:
blockchain: base
sector: dex
project: swaap
contributors: borelien
config:
tags: [ 'base', 'dex', 'trades', 'swaap', 'v2']
description: "swaap v2 base base trades"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('swaap_base_base_trades_seed')
filter:
version: 2
1 change: 1 addition & 0 deletions dex/models/trades/base/dex_base_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
, ref('swapbased_base_base_trades')
, ref('clipper_base_base_trades')
, ref('solidly_v3_base_base_trades')
, ref('swaap_v2_base_base_trades')
] %}

WITH base_union AS (
Expand Down
19 changes: 19 additions & 0 deletions dex/models/trades/base/platforms/swaap_v2_base_base_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
schema = 'swaap_v2_base',
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')]
)
}}

{{
swaap_v2_compatible_trades(
blockchain = 'base',
project = 'swaap',
version = '2'
)
}}
2 changes: 1 addition & 1 deletion dex/models/trades/bnb/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,4 +519,4 @@ models:
- check_dex_base_trades_seed:
seed_file: ref('uniswap_bnb_base_trades_seed')
filter:
version: 2
version: 2
18 changes: 18 additions & 0 deletions dex/models/trades/ethereum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,21 @@ models:
- check_dex_base_trades_seed:
seed_file: ref('solidly_v3_ethereum_base_trades_seed')

- name: swaap_v2_ethereum_base_trades
meta:
blockchain: ethereum
sector: dex
project: swaap
contributors: borelien
config:
tags: [ 'ethereum', 'dex', 'trades', 'swaap', 'v2']
description: "swaap v2 ethereum base trades"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('swaap_ethereum_base_trades_seed')
filter:
version: 2
1 change: 1 addition & 0 deletions dex/models/trades/ethereum/dex_ethereum_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
, ref('xchange_ethereum_base_trades')
, ref('curvefi_ethereum_base_trades')
, ref('solidly_v3_ethereum_base_trades')
, ref('swaap_v2_ethereum_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
schema = 'swaap_v2_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')]
)
}}

{{
swaap_v2_compatible_trades(
blockchain = 'ethereum',
project = 'swaap',
version = '2'
)
}}
21 changes: 20 additions & 1 deletion dex/models/trades/optimism/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,23 @@ models:
- check_dex_base_trades_seed:
seed_file: ref('fraxswap_optimism_base_trades_seed')
filter:
version: 1
version: 1

- name: swaap_v2_optimism_base_trades
meta:
blockchain: optimism
sector: dex
project: swaap
contributors: borelien
config:
tags: [ 'optimism', 'dex', 'trades', 'swaap', 'v2']
description: "swaap v2 optimism base trades"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('swaap_optimism_base_trades_seed')
filter:
version: 2
1 change: 1 addition & 0 deletions dex/models/trades/optimism/dex_optimism_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
, ref('uniswap_v2_optimism_base_trades')
, ref('elk_finance_optimism_base_trades')
, ref('fraxswap_optimism_base_trades')
, ref('swaap_v2_optimism_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
schema = 'swaap_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')]
)
}}

{{
swaap_v2_compatible_trades(
blockchain = 'optimism',
project = 'swaap',
version = '2'
)
}}
19 changes: 19 additions & 0 deletions dex/models/trades/polygon/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,22 @@ models:
seed_file: ref('gridex_polygon_base_trades_seed')
filter:
version: 1

- name: swaap_v2_polygon_base_trades
meta:
blockchain: polygon
sector: dex
project: swaap
contributors: borelien
config:
tags: [ 'polygon', 'dex', 'trades', 'swaap', 'v2']
description: "swaap v2 polygon base trades"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('swaap_polygon_base_trades_seed')
filter:
version: 2
1 change: 1 addition & 0 deletions dex/models/trades/polygon/dex_polygon_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
, ref('uniswap_v2_polygon_base_trades')
, ref('smardex_polygon_base_trades')
, ref('gridex_polygon_base_trades')
, ref('swaap_v2_polygon_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{
config(
schema = 'swaap_v2_polygon',
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')]
)
}}

{{
swaap_v2_compatible_trades(
blockchain = 'polygon',
project = 'swaap',
version = '2'
)
}}
Loading

0 comments on commit 4ceb30d

Please sign in to comment.