Skip to content

Commit

Permalink
Added Optimism Unidex Dex (#5040)
Browse files Browse the repository at this point in the history
* 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
3 people authored and 0xRobin committed Jan 4, 2024
1 parent 3646dea commit 1ab8789
Show file tree
Hide file tree
Showing 6 changed files with 234 additions and 1 deletion.
1 change: 1 addition & 0 deletions models/_sector/dex/trades/optimism/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ models:
- check_dex_base_trades_seed:
seed_file: ref('wardenswap_optimism_base_trades_seed')


- name: dodo_optimism_base_trades
meta:
blockchain: optimism
Expand Down
1 change: 1 addition & 0 deletions models/dex/dex_aggregator_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spells with issues, to be excluded in short term:
,ref('tokenlon_trades')
,ref('firebird_finance_optimism_trades')
,ref('oneinch_ar_trades')
,ref('unidex_optimism_trades')
] %}

{% for aggregator_model in dex_aggregator_models %}
Expand Down
99 changes: 99 additions & 0 deletions models/unidex/optimism/unidex_optimism_schema.yml
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: ""
11 changes: 11 additions & 0 deletions models/unidex/optimism/unidex_optimism_sources.yml
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
117 changes: 117 additions & 0 deletions models/unidex/optimism/unidex_optimism_trades.sql
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 %}
6 changes: 5 additions & 1 deletion seeds/dex/aggregator/dex_aggregator_seed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ optimism,1inch,AR v5,2022-11-07,0x65458306424f0f21248dcd1758dbf91decb41f853e52a4
polygon,1inch,AR v3,2021-05-12,0xfa3f410f0dc275ade43e009e1289e455b1ee16b4c50bccf52ddbabad0bf77474,-1,,0x8f3cf7ad23cd3cadbd9735aff958023239c6a063,0.011620135007290292,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee,
polygon,1inch,AR v4,2021-11-09,0x5c3f93d52361e3337a84493efd7a55ff669c1f754facf477f63fbdf427298052,-1,,0x8f3cf7ad23cd3cadbd9735aff958023239c6a063,1.8364855389353625,0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee,
polygon,1inch,AR v5,2022-11-04,0x3713f6bc4d359117f43a9358d14c8ee6067de1bb2451d821a046ec5736057c4c,-1,"3,1",0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270,5000.269483526215,0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270,5000
optimism,unidex,1,2023-05-17,0x999c03e122c3a671694e17af375b142f75b5460285b2dbb5ed4b50ad09b9f609,0,-1,0x5d47baba0d66083c52009271faf3f50dcc01023c,57.77841991515663,0x3c8b650257cfb5f272f799f5e2b4e65093a11a05,2824.9999999999995
optimism,unidex,1,2023-07-12,0x71f1999600cb55a470b9d3a4021156bb7e8682bcd668bb7939ec257a77b70d4b,7,-1,0x8700daec35af8ff88c16bdf0418774cb3d7599b4,49.50935975587508,0x7f5c764cbc14f9669b88837ca1490cca17c31607,100
optimism,unidex,1,2023-08-09,0xe24eb7479116e1418dd30e0ddd2d1e626ef957c6cf7df6721bfc1e3becc4da7a,73,-1,0xda10009cbd5d07dd0cecc66161fc93d7c9000da1,508.35012637873007,0x9560e827af36c94d2ac33a39bce1fe78631088db,4712.752
optimism,firebird_finance,1,2023-06-21,0xee6c8e576530a282dd8b6b0150690d2efc9bafcf535b994a9efdd95c68d6aaf0,31,-1,0x47536f17f4ff30e64a96a7555826b8f9e66ec468,18.109264993439986,0x7f5c764cbc14f9669b88837ca1490cca17c31607,28.088612
optimism,firebird_finance,1,2022-09-12,0x4b229101a53eda64d7205e8c67da5b69ac57b7030d7420777131dcebd1b6451c,18,-1,0x7f5c764cbc14f9669b88837ca1490cca17c31607,33.450938,0x4200000000000000000000000000000000000006,0.01913919808305519
optimism,firebird_finance,1,2022-09-27,0x77266a3fb99476be6859436eb0000ec1d0a0a78400149195317a65e2a70a5577,11,-1,0x4200000000000000000000000000000000000042,413.41739538888197,0x7f5c764cbc14f9669b88837ca1490cca17c31607,400
optimism,firebird_finance,1,2022-09-27,0x77266a3fb99476be6859436eb0000ec1d0a0a78400149195317a65e2a70a5577,11,-1,0x4200000000000000000000000000000000000042,413.41739538888197,0x7f5c764cbc14f9669b88837ca1490cca17c31607,400

0 comments on commit 1ab8789

Please sign in to comment.