From 5a03af6d759b339c9d049ec396bb0be7eafd14ab Mon Sep 17 00:00:00 2001 From: ARDev097 <147229733+ARDev097@users.noreply.github.com> Date: Fri, 22 Dec 2023 20:18:07 +0530 Subject: [PATCH] Added firebird_finance dex (#4907) * 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 trades for firebird_finance dex with macro approach * Added trades for firebird_finance dex with macro approach * Added trades for firebird_finance dex with macro approach * Updated seed file for adding block_number * Added mummy_finance and firebird_finance dex info in dex_info sql file * Added mummy_finance and firebird_finance dex info in dex_info sql file * Added mummy_finance and firebird_finance dex info in dex_info sql file * Make the required changes and added the firebird dex info in dex_aggregator_trades.sql file * Make the required changes and added the firebird dex info in dex_aggregator_trades.sql file * Moved seed content to dex_aggregator_seed.csv file and removed ref from base_trades.sql file * Solved error in _schema.yml file which occures due to resolving conflicts * Added seeds record in dex_aggregator_seed.csv file * Added seeds record in dex_aggregator_seed.csv file * Added seeds record in dex_aggregator_seed.csv file * Added seeds record in dex_aggregator_seed.csv file * Added seeds record in dex_aggregator_seed.csv file * Added seeds record in dex_aggregator_seed.csv file * Updated fireboird_finance_optimism_tades sql file to add trace address field * Updated fireboird_finance_optimism_tades sql file to add trace address field * Updated fireboird_finance_optimism_tades sql file to add trace address field * Remove firebird_finance_optimism_base_trades from dex.base_trades * Update check_dex_aggregator_seed test * Updated seeds record * Updated seeds record * Updated seeds record * Fix alias --------- Co-authored-by: Huang Geyang Co-authored-by: jeff-dude <102681548+jeff-dude@users.noreply.github.com> --- models/dex/dex_aggregator_trades.sql | 1 + .../firebird_finance_optimism_schema.yml | 99 +++++++++++++++ .../firebird_finance_optimism_sources.yml | 11 ++ .../firebird_finance_optimism_trades.sql | 118 ++++++++++++++++++ seeds/dex/aggregator/dex_aggregator_seed.csv | 3 + 5 files changed, 232 insertions(+) create mode 100644 models/firebird_finance/optimism/firebird_finance_optimism_schema.yml create mode 100644 models/firebird_finance/optimism/firebird_finance_optimism_sources.yml create mode 100644 models/firebird_finance/optimism/firebird_finance_optimism_trades.sql diff --git a/models/dex/dex_aggregator_trades.sql b/models/dex/dex_aggregator_trades.sql index 8561b9c1786..d6ab2f4c221 100644 --- a/models/dex/dex_aggregator_trades.sql +++ b/models/dex/dex_aggregator_trades.sql @@ -31,6 +31,7 @@ spells with issues, to be excluded in short term: ,ref('zeroex_trades') ,ref('kyberswap_aggregator_trades') ,ref('tokenlon_trades') + ,ref('firebird_finance_optimism_trades') ,ref('oneinch_ar_trades') ] %} diff --git a/models/firebird_finance/optimism/firebird_finance_optimism_schema.yml b/models/firebird_finance/optimism/firebird_finance_optimism_schema.yml new file mode 100644 index 00000000000..d28e89bb0e1 --- /dev/null +++ b/models/firebird_finance/optimism/firebird_finance_optimism_schema.yml @@ -0,0 +1,99 @@ +version: 2 + +models: + - name: firebird_finance_optimism_trades + meta: + blockchain: optimism + sector: dex + project: firebird_finance + contributors: ARDev097 + config: + tags: ['optimism','trades', 'firebird_finance','dex'] + description: > + firebird_finance 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: firebird_finance + version: 1 + columns: + - &blockchain + name: blockchain + description: "Blockchain 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: "" \ No newline at end of file diff --git a/models/firebird_finance/optimism/firebird_finance_optimism_sources.yml b/models/firebird_finance/optimism/firebird_finance_optimism_sources.yml new file mode 100644 index 00000000000..3661d299161 --- /dev/null +++ b/models/firebird_finance/optimism/firebird_finance_optimism_sources.yml @@ -0,0 +1,11 @@ +version: 2 + +sources: + - name: firebird_finance_optimism + freshness: + warn_after: { count: 12, period: hour } + description: > + Decoded event table for swaps on firebird_finance + tables: + - name: FireBirdRouter_evt_Swapped + loaded_at_field: evt_block_time diff --git a/models/firebird_finance/optimism/firebird_finance_optimism_trades.sql b/models/firebird_finance/optimism/firebird_finance_optimism_trades.sql new file mode 100644 index 00000000000..458ea3efba2 --- /dev/null +++ b/models/firebird_finance/optimism/firebird_finance_optimism_trades.sql @@ -0,0 +1,118 @@ +{{ config( + alias='trades', + schema='firebird_finance_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", + "firebird_finance", + \'["ARDev097"]\') }}' + ) +}} + +{% set project_start_date = '2022-07-11' %} +{% set firebird_finance_optimism_evt_trade_tables = [ + source('firebird_finance_optimism', 'FireBirdRouter_evt_Swapped') +] %} + +with dexs as ( + {% for evt_trade_table in firebird_finance_optimism_evt_trade_tables %} + SELECT + evt_block_time AS block_time, + sender AS taker, + CAST(NULL as VARBINARY) AS maker, + returnAmount AS token_bought_amount_raw, + spentAmount AS token_sold_amount_raw, + CAST(NULL AS double) AS amount_usd, + dstToken AS token_bought_address, + srcToken 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, + 'firebird_finance' 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 %} + diff --git a/seeds/dex/aggregator/dex_aggregator_seed.csv b/seeds/dex/aggregator/dex_aggregator_seed.csv index d205034f618..62fad45ce26 100644 --- a/seeds/dex/aggregator/dex_aggregator_seed.csv +++ b/seeds/dex/aggregator/dex_aggregator_seed.csv @@ -117,3 +117,6 @@ 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,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 \ No newline at end of file