Skip to content

Commit

Permalink
add zeroex_v2_mode trades (#7167)
Browse files Browse the repository at this point in the history
* add seed

* add files

* upset settler_address cte in macro

* add mode to cross-chain

* update schema

* v2_mode_trades

* fix fills_count_ cte

* update macro for fills_within on mode

* trade_details name, update eth + polygon

* fills_within

* update eth model for fills_within cte

---------

Co-authored-by: jeff-dude <[email protected]>
  • Loading branch information
RantumBits and jeff-dude authored Nov 25, 2024
1 parent 51d47e4 commit 241e6a3
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
version: 2

models:
- name: zeroex_v2_mode_trades
meta:
blockchain: mode
project: zeroex
contributors: rantum
config:
tags: ['mode','0x','dex_aggregator','dex','aggregator']
description: >
0x API erc20 trades through 0x v2 contracts. No fills, only deduped transactions.
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_month
- block_date
- tx_hash
- evt_index
- check_seed:
seed_file: ref('zeroex_v2_mode_trades_sample')
match_columns:
- tx_hash
check_columns:
- taker
- maker_token
- taker_token
columns:
- &blockchain
name: blockchain
description: "Blockchain which the aggregator project is deployed"
- &block_date
name: block_date
description: "UTC event block date of each trade"
- &block_month
name: block_month
description: "UTC event block month of each trade"
- &block_time
name: block_time
description: "UTC event block time of each trade"
- &taker_symbol
name: taker_symbol
description: "Symbol of the token taker sells"
- &maker_symbol
name: maker_symbol
description: "Symbol of the token taker buys"
- &token_pair
name: token_pair
description: "Token pair traded"
- &taker_token_amount
name: taker_token_amount
description: "The after-decimal amount of the token taker sells"
- &taker_token_amount_raw
name: taker_token_amount_raw
description: "The raw amount of the token taker sells"
- &maker_token_amount
name: maker_token_amount
description: "The after-decimal amount of the token taker buys"
- &maker_token_amount_raw
name: maker_token_amount_raw
description: "The raw amount of the token taker buys"
- &volume_usd
name: volume_usd
description: "Trading volume measured in USD value"
- &taker_token
name: taker_token
description: "Contract address of the token taker sells"
- &maker_token
name: maker_token
description: "Contract address of the token taker buys"
- &maker
name: maker
description: "buyer of the trade"
- &taker
name: taker
description: "seller of the trade"
- &affiliate_address
name: affiliate_address
description: "The recipient address of the affiliate, or the applications that is using 0x API, for receiving affiliate fee"
- &tx_hash
name: tx_hash
description: "Transaction hash of the fill"
- &tx_from
name: tx_from
description: "Address which initiated the trade"
- &tx_to
name: tx_to
description: "Address which received the trade"
- &evt_index
name: evt_index
description: "Index of the corresponding order filled event"
- &type
name: type
description: "The liquidity route the order went thru"
- &swap_flag
name: swap_flag
description: "If the swap was filled/consumed thru 0x API"
- &contract_address
name: contract_address
desctiption: "The address of the contract which fired the fill/swap event"
- &fills_within
name: fills_within
description: "fills in then multihop, if present"








Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{ config(
schema = 'zeroex_v2_mode',
alias = 'trades',
materialized='incremental',
partition_by = ['block_month'],
unique_key = ['block_month', 'block_date', 'tx_hash', 'evt_index'],
on_schema_change='sync_all_columns',
file_format ='delta',
incremental_strategy='merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')]
)}}

{% set zeroex_settler_start_date = '2024-07-15' %}
{% set blockchain = 'mode' %}

WITH zeroex_tx AS (
{{
zeroex_settler_txs_cte(
blockchain = blockchain,
start_date = zeroex_settler_start_date
)
}}
),
zeroex_v2_trades_direct AS (
{{
zeroex_v2_trades_direct(
blockchain = blockchain,
start_date = zeroex_settler_start_date

)
}}
),
zeroex_v2_trades_indirect AS (
{{
zeroex_v2_trades_indirect(
blockchain = blockchain,
start_date = zeroex_settler_start_date

)
}}
),
tbl_trades AS (
SELECT *
FROM zeroex_v2_trades_direct
UNION ALL
SELECT *
FROM zeroex_v2_trades_indirect
),
trade_details as (
{{
zeroex_v2_trades_detail(
blockchain = blockchain,
start_date = zeroex_settler_start_date

)
}}

)
select
*
from trade_details
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ config(
schema = 'zeroex'
, alias = 'api_fills_deduped'
, post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle"]\',
, post_hook='{{ expose_spells(\'["arbitrum", "avalanche_c", "base", "bnb", "celo", "ethereum", "fantom", "optimism", "polygon","scroll", "linea","blast","mantle","mode"]\',
"project",
"zeroex",
\'["rantum","bakabhai993"]\') }}'
Expand Down Expand Up @@ -31,6 +31,7 @@
,ref('zeroex_v2_arbitrum_trades')
,ref('zeroex_scroll_settler_trades')
,ref('zeroex_linea_settler_trades')
,ref('zeroex_v2_mode_trades')
,ref('zeroex_v2_blast_trades')
,ref('zeroex_v2_mantle_trades')
] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ models:

- name: zeroex_api_fills_deduped
meta:
blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle
blockchain: ethereum, optimism, polygon, arbitrum, fantom, avalanche, bnb, base, scroll, linea, blast, mantle, mode
sector: dex
project: zeroex
contributors: rantum, bakabhai993
Expand Down
11 changes: 11 additions & 0 deletions dbt_subprojects/dex/seeds/_project/zeroex/mode/_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2

seeds:
- name: zeroex_v2_mode_trades_sample
config:
column_types:
tx_hash: varbinary
taker: varbinary
taker_token: varbinary
maker_token: varbinary
taker_token_amount: double
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tx_hash,taker,taker_token,maker_token,taker_token_amount
0xd7ace13835ceb119b071c508e8ee262fcecb5a0f2a1bfdd1b9b1f04afa73d94d,0x44c20316a06371ca5acb975974c18abfa7a14a5a,0xf0f161fda2712db8b566946122a5af183995e2ed,0x4200000000000000000000000000000000000006,
0xd10163ac93593667d3922a05c09580856b1b4c1dc015738c67968912a42c46dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,0x2416092f143378750bb29b79ed961ab195cceea5,238973
0xd84a08f6d48b5c34cde908452602088cdb42beceef29074b8a8d5c7e45f2a3dc,0x8a6bfcae15e729fd1440574108437dea281a9b3e,0x4200000000000000000000000000000000000006,0x6a660e56fa3b630a786cc4ae98859f8532d03de9,

0 comments on commit 241e6a3

Please sign in to comment.