-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add openxswap trades * add legacy file for openxswap trades * update legacy file for openxswap trades * Add seeds records for openxswap * Add uniqueness and check_dex_seed tests * updated seeds records for openxswap * added openocean dex * Added seed data for openocean dex * Added seed data for openocean dex * Updated dex_trades_assert_freshness file * Updated trades.sql file * Updated trades.sql file * Modified schema file * Modified schema file * Modified schema file * Modified schema file * Modified schema file * Modified schema file * Modified seeds file * Update models/openocean/optimism/openocean_optimism_trades.sql * modified trades file * Update models/openocean/optimism/openocean_optimism_trades.sql * Update models/openocean/optimism/openocean_optimism_schema.yml * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * Added Odos Optimism Dex Trades Data * added sepll for woofi dex on optimism * added sepll for woofi dex on optimism * added sepll for woofi dex on optimism * added sepll for woofi dex on optimism * Removed tag from trades.sql file * Implement woofi_optimism_base_trades * Add block_number * Update dex_trades_seed.csv (Removing zksync line which might be added mistakenly during resolving commits) * Add woofi_optimism_base_trades_seed * Add check_seed test to woofi_optimism_base_trades * Remove dunesql tag * Remove duped seed definition * Added mummy_finance dex trade's * Removed trace_address column * Implemented macro approach in mummy_finance dex trades * Implemented macro approach in mummy_finance dex trades * Implemented macro approach in mummy_finance dex trades * Make changes in dex_trades_assert_freshness file * Updated seed file record * Updated seed file record * Updated dex_trades_asser_freshness file * Updated base_trades file * Updated base_trades file * Recover tests/dex/dex_trades_assert_freshness.sql * Added spell for hashflow dex using macro approach * Fix _schema.yml * Update models/dex/dex_info.sql * Updated crosschain_trade file for resolving syntax error * Fix incremental filters * Add hashflow_optimism_crosschain_trades to roll-up table and fix alias * Added Spell For Unidex Dex(Trades Data) * Make the requested chnages in trade.sql file --------- Co-authored-by: Huang Geyang <Sukebeta@outlook.com> Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
234 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: unidex_optimism_trades | ||
meta: | ||
blockchain: optimism | ||
sector: dex | ||
project: unidex | ||
contributors: ARDev097 | ||
config: | ||
tags: ['optimism','trades', 'unidex','dex'] | ||
description: > | ||
unidex dex trades on optimism | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- block_date | ||
- blockchain | ||
- project | ||
- version | ||
- tx_hash | ||
- evt_index | ||
- check_dex_aggregator_seed: | ||
blockchain: optimism | ||
project: unidex | ||
version: 1 | ||
columns: | ||
- &blockchain | ||
name: blockchain | ||
description: "Blockchain on which the DEX is deployed" | ||
- &project | ||
name: project | ||
description: "Project name of the DEX" | ||
- &version | ||
name: version | ||
description: "Version of the contract built and deployed by the DEX project" | ||
- &block_month | ||
name: block_month | ||
description: "UTC event block month of each DEX trade" | ||
- &block_date | ||
name: block_date | ||
description: "UTC event block date of each DEX trade" | ||
- &block_time | ||
name: block_time | ||
description: "UTC event block time of each DEX trade" | ||
- &token_bought_symbol | ||
name: token_bought_symbol | ||
description: "Token symbol for token bought in the transaction" | ||
- &token_sold_symbol | ||
name: token_sold_symbol | ||
description: "Token symbol for token sold in the transaction" | ||
- &token_pair | ||
name: token_pair | ||
description: "Token symbol pair for each token involved in the transaction" | ||
- &token_bought_amount | ||
name: token_bought_amount | ||
description: "Value of the token bought at time of execution in the original currency" | ||
- &token_sold_amount | ||
name: token_sold_amount | ||
description: "Value of the token sold at time of execution in the original currency" | ||
- &token_bought_amount_raw | ||
name: token_bought_amount_raw | ||
description: "Raw value of the token bought at time of execution in the original currency" | ||
- &token_sold_amount_raw | ||
name: token_sold_amount_raw | ||
description: "Raw value of the token sold at time of execution in the original currency" | ||
- &amount_usd | ||
name: amount_usd | ||
description: "USD value of the trade at time of execution" | ||
- &token_bought_address | ||
name: token_bought_address | ||
description: "Contract address of the token bought" | ||
- &token_sold_address | ||
name: token_sold_address | ||
description: "Contract address of the token sold" | ||
- &taker | ||
name: taker | ||
description: "Address of trader who purchased a token" | ||
- &maker | ||
name: maker | ||
description: "Address of trader who sold a token" | ||
- &project_contract_address | ||
name: project_contract_address | ||
description: "Project contract address which executed the trade on the blockchain" | ||
- &tx_hash | ||
name: tx_hash | ||
description: "Unique transaction hash value tied to each transaction on the DEX" | ||
- &tx_from | ||
name: tx_from | ||
description: "Address which initiated the transaction" | ||
- &tx_to | ||
name: tx_to | ||
description: "Address which received the transaction" | ||
- &evt_index | ||
name: evt_index | ||
description: "" | ||
- &trace_address | ||
name: trace_address | ||
description: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: unidex_optimism | ||
freshness: | ||
warn_after: { count: 12, period: hour } | ||
description: > | ||
Decoded event table for swaps on unidex dex aggregator | ||
tables: | ||
- name: metaaggregator_settlement_evt_Trade | ||
loaded_at_field: evt_block_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
{{ config( | ||
alias='trades', | ||
schema='unidex_optimism', | ||
partition_by=['block_month'], | ||
materialized='incremental', | ||
file_format='delta', | ||
incremental_strategy='merge', | ||
unique_key=['block_date', 'blockchain', 'project', 'version', 'tx_hash', 'evt_index'], | ||
post_hook='{{ expose_spells(\'["optimism"]\', | ||
"project", | ||
"unidex", | ||
\'["ARDev097"]\') }}' | ||
) | ||
}} | ||
|
||
{% set project_start_date = '2023-03-08' %} | ||
{% set unidex_optimism_evt_trade_tables = [ | ||
source('unidex_optimism', 'metaaggregator_settlement_evt_Trade') | ||
] %} | ||
|
||
with dexs as ( | ||
{% for evt_trade_table in unidex_optimism_evt_trade_tables %} | ||
SELECT | ||
evt_block_time AS block_time, | ||
owner AS taker, | ||
CAST(NULL as VARBINARY) AS maker, | ||
buyAmount AS token_bought_amount_raw, | ||
sellAmount AS token_sold_amount_raw, | ||
CAST(NULL AS double) AS amount_usd, | ||
buyToken AS token_bought_address, | ||
sellToken AS token_sold_address, | ||
contract_address AS project_contract_address, | ||
evt_tx_hash AS tx_hash, | ||
array[-1] AS trace_address, | ||
evt_index | ||
FROM {{ evt_trade_table }} | ||
{% if is_incremental() %} | ||
WHERE evt_block_time >= date_trunc('day', now() - interval '7' day) | ||
{% else %} | ||
WHERE evt_block_time >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
|
||
{% if not loop.last %} | ||
UNION ALL | ||
{% endif %} | ||
|
||
{% endfor %} | ||
) | ||
|
||
SELECT | ||
'optimism' AS blockchain, | ||
'unidex' AS project, | ||
'1' AS version, | ||
TRY_CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date, | ||
TRY_CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month, | ||
dexs.block_time, | ||
erc20a.symbol AS token_bought_symbol, | ||
erc20b.symbol AS token_sold_symbol, | ||
CASE | ||
WHEN lower(erc20a.symbol) > lower(erc20b.symbol) | ||
THEN concat(erc20b.symbol, '-', erc20a.symbol) | ||
ELSE concat(erc20a.symbol, '-', erc20b.symbol) | ||
END AS token_pair, | ||
dexs.token_bought_amount_raw / power(10, erc20a.decimals) AS token_bought_amount, | ||
dexs.token_sold_amount_raw / power(10, erc20b.decimals) AS token_sold_amount, | ||
dexs.token_bought_amount_raw AS token_bought_amount_raw, | ||
dexs.token_sold_amount_raw AS token_sold_amount_raw, | ||
COALESCE( | ||
dexs.amount_usd, | ||
(dexs.token_bought_amount_raw / power(10, erc20a.decimals)) * p_bought.price, | ||
(dexs.token_sold_amount_raw / power(10, erc20b.decimals)) * p_sold.price | ||
) AS amount_usd, | ||
dexs.token_bought_address, | ||
dexs.token_sold_address, | ||
COALESCE(dexs.taker, tx."from") AS taker, | ||
dexs.maker, | ||
dexs.project_contract_address, | ||
dexs.tx_hash, | ||
tx."from" AS tx_from, | ||
tx.to AS tx_to, | ||
dexs.evt_index, | ||
dexs.trace_address | ||
FROM dexs | ||
INNER JOIN {{ source('optimism', 'transactions') }} tx | ||
ON dexs.tx_hash = tx.hash | ||
{% if not is_incremental() %} | ||
AND tx.block_time >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
{% if is_incremental() %} | ||
AND tx.block_time >= date_trunc('day', now() - interval '7' day) | ||
{% endif %} | ||
LEFT JOIN {{ ref('tokens_erc20') }} erc20a | ||
ON erc20a.contract_address = dexs.token_bought_address | ||
AND erc20a.blockchain = 'optimism' | ||
LEFT JOIN {{ ref('tokens_erc20') }} erc20b | ||
ON erc20b.contract_address = dexs.token_sold_address | ||
AND erc20b.blockchain = 'optimism' | ||
LEFT JOIN {{ source('prices', 'usd') }} p_bought | ||
ON p_bought.minute = date_trunc('minute', dexs.block_time) | ||
AND p_bought.contract_address = dexs.token_bought_address | ||
AND p_bought.blockchain = 'optimism' | ||
{% if not is_incremental() %} | ||
AND p_bought.minute >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
{% if is_incremental() %} | ||
AND p_bought.minute >= date_trunc('day', now() - interval '7' day) | ||
{% endif %} | ||
LEFT JOIN {{ source('prices', 'usd') }} p_sold | ||
ON p_sold.minute = date_trunc('minute', dexs.block_time) | ||
AND p_sold.contract_address = dexs.token_sold_address | ||
AND p_sold.blockchain = 'optimism' | ||
{% if not is_incremental() %} | ||
AND p_sold.minute >= TIMESTAMP '{{project_start_date}}' | ||
{% endif %} | ||
{% if is_incremental() %} | ||
AND p_sold.minute >= date_trunc('day', now() - interval '7' day) | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters