Skip to content

Commit

Permalink
Add clipper to dex.trades_beta (#5043)
Browse files Browse the repository at this point in the history
* macro and first test

* more chains

* update dex_ethereum_base_trades

---------

Co-authored-by: Huang Geyang <Sukebeta@outlook.com>
Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 3, 2024
1 parent 16d10f9 commit c4a200e
Show file tree
Hide file tree
Showing 21 changed files with 279 additions and 65 deletions.
52 changes: 52 additions & 0 deletions macros/models/_sector/dex/clipper_compatible_trades.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% macro clipper_compatible_trades(
blockchain = null,
project = null,
sources = []
)
%}

WITH dexs AS (
{% for src in sources %}
SELECT
'{{ src["version"] }}' as version,
t.evt_block_number AS block_number,
t.evt_block_time AS block_time,
t.recipient as taker,
CAST(NULL AS VARBINARY) AS maker,
t.inAmount as token_sold_amount_raw,
t.outAmount as token_bought_amount_raw,
t.inAsset as token_sold_address,
t.outAsset as token_bought_address,
t.contract_address AS project_contract_address,
t.evt_tx_hash AS tx_hash,
t.evt_index
FROM {{ source('clipper_' ~ blockchain, src["source"] )}} t
{% if is_incremental() %}
WHERE {{ incremental_predicate('evt_block_time') }}
{% endif %}
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
)

SELECT
'{{ blockchain }}' AS blockchain,
'{{ project }}' AS project,
dexs.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 %}
23 changes: 23 additions & 0 deletions models/_sector/dex/trades/arbitrum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,26 @@ models:
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('integral_arbitrum_base_trades_seed')

- name: clipper_arbitrum_base_trades
meta:
blockchain: arbitrum
sector: dex
project: clipper
contributors: 0xRob, amalashkevich, tomfutago
config:
tags: [ 'arbitrum', 'dex', 'trades', 'clipper' ]
description: "clipper 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('clipper_arbitrum_base_trades_seed')
filter:
version:
- coves1
- coves2
- 1
- 2
6 changes: 6 additions & 0 deletions models/_sector/dex/trades/arbitrum/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,9 @@ sources:
tables:
- name: TwapPair_evt_Swap
- name: TwapFactory_evt_PairCreated
- name: clipper_arbitrum
tables:
- name: ClipperCove_evt_CoveSwapped
- name: ClipperCove_v2_evt_CoveSwapped
- name: ClipperPackedVerifiedExchange_evt_Swapped
- name: ClipperPackedVerifiedExchange_v2_evt_Swapped
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
, ref('dodo_arbitrum_base_trades')
, ref('gmx_arbitrum_base_trades')
, ref('integral_arbitrum_base_trades')
, ref('clipper_arbitrum_base_trades')
] %}

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

{%
set config_sources = [
{'version': 'coves1', 'source': 'ClipperCove_evt_CoveSwapped'},
{'version': 'coves2', 'source': 'ClipperCove_v2_evt_CoveSwapped'},
{'version': '1', 'source': 'ClipperPackedVerifiedExchange_evt_Swapped'},
{'version': '2', 'source': 'ClipperPackedVerifiedExchange_v2_evt_Swapped'},
]
%}

{{
clipper_compatible_trades(
blockchain = 'arbitrum',
project = 'clipper',
sources = config_sources
)
}}
25 changes: 24 additions & 1 deletion models/_sector/dex/trades/ethereum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,29 @@ models:
- check_dex_base_trades_seed:
seed_file: ref('maverick_ethereum_base_trades_seed')

- name: clipper_ethereum_base_trades
meta:
blockchain: ethereum
sector: dex
project: clipper
contributors: 0xRob, amalashkevich, tomfutago
config:
tags: [ 'ethereum', 'dex', 'trades', 'clipper' ]
description: "clipper 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('clipper_ethereum_base_trades_seed')
filter:
version:
- 1
- 2
- 3
- 4

- name: mstable_ethereum_base_trades
meta:
blockchain: ethereum
Expand All @@ -449,4 +472,4 @@ models:
filter:
version:
- masset
- feederpool
- feederpool
6 changes: 6 additions & 0 deletions models/_sector/dex/trades/ethereum/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ sources:
tables:
- name: pool_evt_Swap
- name: factory_evt_PoolCreated
- name: clipper_ethereum
tables:
- name: ClipperExchangeInterface_evt_Swapped
- name: ClipperCaravelExchange_evt_Swapped
- name: ClipperVerifiedCaravelExchange_evt_Swapped
- name: ClipperApproximateCaravelExchange_evt_Swapped
- name: mstable_ethereum
tables:
- name: Masset_evt_Swapped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
, ref('dodo_ethereum_base_trades')
, ref('integral_ethereum_base_trades')
, ref('maverick_ethereum_base_trades')
, ref('clipper_ethereum_base_trades')
, ref('mstable_ethereum_base_trades')
] %}

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

{%
set config_sources = [
{'version': '1', 'source': 'ClipperExchangeInterface_evt_Swapped'},
{'version': '2', 'source': 'ClipperCaravelExchange_evt_Swapped'},
{'version': '3', 'source': 'ClipperVerifiedCaravelExchange_evt_Swapped'},
{'version': '4', 'source': 'ClipperApproximateCaravelExchange_evt_Swapped'},
]
%}

{{
clipper_compatible_trades(
blockchain = 'ethereum',
project = 'clipper',
sources = config_sources
)
}}
22 changes: 22 additions & 0 deletions models/_sector/dex/trades/optimism/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,25 @@ models:
- 2_dvm
- 2_dpp
- 2_dsp

- name: clipper_optimism_base_trades
meta:
blockchain: optimism
sector: dex
project: clipper
contributors: 0xRob, amalashkevich, tomfutago
config:
tags: [ 'optimism', 'dex', 'trades', 'clipper' ]
description: "clipper 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('clipper_optimism_base_trades_seed')
filter:
version:
- coves1
- 1
- 2
5 changes: 5 additions & 0 deletions models/_sector/dex/trades/optimism/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ sources:
- name: DVM_evt_DODOSwap
- name: DPP_evt_DODOSwap
- name: DSP_evt_DODOSwap
- name: clipper_optimism
tables:
- name: ClipperPackedExchange_evt_Swapped
- name: ClipperPackedVerifiedExchange_evt_Swapped
- name: ClipperCove_evt_CoveSwapped
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
, ref('balancer_v2_optimism_base_trades')
, ref('wardenswap_optimism_base_trades')
, ref('dodo_optimism_base_trades')
, ref('clipper_optimism_base_trades')
] %}

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

{%
set config_sources = [
{'version': 'coves1', 'source': 'ClipperCove_evt_CoveSwapped'},
{'version': '1', 'source': 'ClipperPackedExchange_evt_Swapped'},
{'version': '2', 'source': 'ClipperPackedVerifiedExchange_evt_Swapped'},
]
%}

{{
clipper_compatible_trades(
blockchain = 'optimism',
project = 'clipper',
sources = config_sources
)
}}
22 changes: 22 additions & 0 deletions models/_sector/dex/trades/polygon/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,25 @@ models:
- 2_dvm
- 2_dpp
- 2_dsp

- name: clipper_polygon_base_trades
meta:
blockchain: polygon
sector: dex
project: clipper
contributors: 0xRob, amalashkevich, tomfutago
config:
tags: [ 'polygon', 'dex', 'trades', 'clipper' ]
description: "clipper 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('clipper_polygon_base_trades_seed')
filter:
version:
- coves1
- 1
- 2
5 changes: 5 additions & 0 deletions models/_sector/dex/trades/polygon/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ sources:
- name: DPPAdvanced_evt_DODOSwap
- name: DPPOracle_evt_DODOSwap
- name: DSP_evt_DODOSwap
- name: clipper_polygon
tables:
- name: ClipperDirectExchange_evt_Swapped
- name: ClipperVerifiedExchange_evt_Swapped
- name: ClipperCove_evt_CoveSwapped
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
, ref('balancer_v2_polygon_base_trades')
, ref('fraxswap_polygon_base_trades')
, ref('dodo_polygon_base_trades')
, ref('clipper_polygon_base_trades')
] %}

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

{%
set config_sources = [
{'version': 'coves1', 'source': 'ClipperCove_evt_CoveSwapped'},
{'version': '1', 'source': 'ClipperDirectExchange_evt_Swapped'},
{'version': '2', 'source': 'ClipperVerifiedExchange_evt_Swapped'},
]
%}

{{
clipper_compatible_trades(
blockchain = 'polygon',
project = 'clipper',
sources = config_sources
)
}}
17 changes: 0 additions & 17 deletions models/clipper/arbitrum/clipper_arbitrum_sources.yml

This file was deleted.

17 changes: 0 additions & 17 deletions models/clipper/ethereum/clipper_ethereum_sources.yml

This file was deleted.

Loading

0 comments on commit c4a200e

Please sign in to comment.