diff --git a/models/_sector/dex/trades/optimism/_schema.yml b/models/_sector/dex/trades/optimism/_schema.yml index 1c733329555..94bb7149b7f 100644 --- a/models/_sector/dex/trades/optimism/_schema.yml +++ b/models/_sector/dex/trades/optimism/_schema.yml @@ -1,6 +1,8 @@ version: 2 models: + - name: dex_optimism_base_trades + - name: uniswap_v3_optimism_base_trades meta: blockchain: optimism @@ -112,4 +114,29 @@ models: - token_bought_amount_raw - token_sold_amount_raw - - name: dex_optimism_base_trades + - name: mummy_finance_optimism_base_trades + meta: + blockchain: optimism + sector: dex + project: mummy_finance + contributors: ARDev097 + config: + tags: [ 'optimism', 'dex', 'trades', 'mummy_finance' ] + description: > + mummy_finance base trades on optimism. + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - tx_hash + - evt_index + - check_seed: + seed_file: ref('mummy_finance_optimism_base_trades_seed') + match_columns: + - tx_hash + - evt_index + check_columns: + - block_number + - token_bought_address + - token_sold_address + - token_bought_amount_raw + - token_sold_amount_raw \ No newline at end of file diff --git a/models/_sector/dex/trades/optimism/dex_optimism_base_trades.sql b/models/_sector/dex/trades/optimism/dex_optimism_base_trades.sql index 1af305bb79c..633df557e91 100644 --- a/models/_sector/dex/trades/optimism/dex_optimism_base_trades.sql +++ b/models/_sector/dex/trades/optimism/dex_optimism_base_trades.sql @@ -8,6 +8,7 @@ {% set base_models = [ ref('uniswap_v3_optimism_base_trades') , ref('woofi_optimism_base_trades') + , ref('mummy_finance_optimism_base_trades') , ref('sushiswap_v1_optimism_base_trades') , ref('sushiswap_v2_optimism_base_trades') ] %} diff --git a/models/_sector/dex/trades/optimism/platforms/mummy_finance_optimism_base_trades.sql b/models/_sector/dex/trades/optimism/platforms/mummy_finance_optimism_base_trades.sql new file mode 100644 index 00000000000..00bff9db38f --- /dev/null +++ b/models/_sector/dex/trades/optimism/platforms/mummy_finance_optimism_base_trades.sql @@ -0,0 +1,60 @@ +{{ config( + schema = 'mummy_finance_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 mummy_finance_optimism_evt_trade_tables = [ + source('mummy_finance_optimism', 'Router_evt_Swap') +] %} + +with dexs AS ( + {% for evt_trade_table in mummy_finance_optimism_evt_trade_tables %} + SELECT + evt_block_time AS block_time, + account AS taker, + CAST(NULL as VARBINARY) AS maker, + amountIn AS token_bought_amount_raw, + amountOut AS token_sold_amount_raw, + CAST(NULL AS double) AS amount_usd, + tokenIn AS token_bought_address, + tokenOut AS token_sold_address, + contract_address AS project_contract_address, + evt_tx_hash AS tx_hash, + evt_block_number AS block_number, + evt_index + FROM {{ evt_trade_table }} + {% if is_incremental() %} + WHERE {{incremental_predicate('evt_block_time')}} + {% endif %} + + {% if not loop.last %} + UNION ALL + {% endif %} + + {% endfor %} +) + +SELECT + 'optimism' AS blockchain, + 'mummy_finance' AS project, + '1' AS version, + CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date, + CAST(date_trunc('MONTH', dexs.block_time) AS date) AS block_month, + 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 diff --git a/models/dex/dex_trades.sql b/models/dex/dex_trades.sql index e2436099820..c7dca5a72eb 100644 --- a/models/dex/dex_trades.sql +++ b/models/dex/dex_trades.sql @@ -77,6 +77,7 @@ ,ref('openocean_optimism_trades') ,ref('woofi_optimism_trades') ,ref('oneinch_lop_own_trades') +,ref('mummy_finance_optimism_trades') ] %} diff --git a/models/mummy_finance/optimism/mummy_finance_optimism_schema.yml b/models/mummy_finance/optimism/mummy_finance_optimism_schema.yml new file mode 100644 index 00000000000..78174130006 --- /dev/null +++ b/models/mummy_finance/optimism/mummy_finance_optimism_schema.yml @@ -0,0 +1,96 @@ +version: 2 + +models: + - name: mummy_finance_optimism_trades + meta: + blockchain: optimism + sector: dex + project: mummy_finance + contributors: ARDev097 + config: + tags: ['optimism', 'trades', 'mummy_finance', 'dex'] + description: > + Mummy Finance contract trades on optimism + tests: + - dbt_utils.unique_combination_of_columns: + combination_of_columns: + - block_date + - blockchain + - project + - version + - tx_hash + - evt_index + - check_dex_seed: + blockchain: optimism + project: mummy_finance + 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 the time of execution in the original currency" + - &token_sold_amount + name: token_sold_amount + description: "Value of the token sold at the time of execution in the original currency" + - &token_bought_amount_raw + name: token_bought_amount_raw + description: "Raw value of the token bought at the time of execution in the original currency" + - &token_sold_amount_raw + name: token_sold_amount_raw + description: "Raw value of the token sold at the time of execution in the original currency" + - &amount_usd + name: amount_usd + description: "USD value of the trade at the 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 the trader who purchased a token" + - &maker + name: maker + description: "Address of the 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: "" diff --git a/models/mummy_finance/optimism/mummy_finance_optimism_sources.yml b/models/mummy_finance/optimism/mummy_finance_optimism_sources.yml new file mode 100644 index 00000000000..d0b76dd897b --- /dev/null +++ b/models/mummy_finance/optimism/mummy_finance_optimism_sources.yml @@ -0,0 +1,11 @@ +version: 2 + +sources: + - name: mummy_finance_optimism + freshness: + warn_after: { count: 12, period: hour } + description: > + Decoded event table for swaps on mummy_finance + tables: + - name: Router_evt_Swap + loaded_at_field: evt_block_time \ No newline at end of file diff --git a/models/mummy_finance/optimism/mummy_finance_optimism_trades.sql b/models/mummy_finance/optimism/mummy_finance_optimism_trades.sql new file mode 100644 index 00000000000..0269d8c67c3 --- /dev/null +++ b/models/mummy_finance/optimism/mummy_finance_optimism_trades.sql @@ -0,0 +1,116 @@ +{{ config( + alias = 'trades' + ,schema = 'mummy_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", + "mummy_finance", + \'["ARDev097"]\') }}' + ) +}} + + +{% set project_start_date = '2023-03-04' %} +{% set mummy_finance_optimism_evt_trade_tables = [ + source('mummy_finance_optimism', 'Router_evt_Swap') +] %} + +with dexs AS ( + {% for evt_trade_table in mummy_finance_optimism_evt_trade_tables %} + SELECT + evt_block_time AS block_time, + account AS taker, + CAST(NULL as VARBINARY) AS maker, + amountIn AS token_bought_amount_raw, + amountOut AS token_sold_amount_raw, + CAST(NULL AS double) AS amount_usd, + tokenIn AS token_bought_address, + tokenOut AS token_sold_address, + contract_address AS project_contract_address, + evt_tx_hash AS tx_hash, + 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, + 'mummy_finance' AS project, + '1' AS version, + CAST(date_trunc('DAY', dexs.block_time) AS date) AS block_date, + 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, p_bought.decimals)) * p_bought.price + , (dexs.token_sold_amount_raw / power(10, p_sold.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 +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 %} \ No newline at end of file diff --git a/seeds/_sector/dex/_schema.yml b/seeds/_sector/dex/_schema.yml index b5dabfe116d..57a79b5b5f5 100644 --- a/seeds/_sector/dex/_schema.yml +++ b/seeds/_sector/dex/_schema.yml @@ -1919,3 +1919,18 @@ seeds: token_bought_amount_raw: uint256 token_sold_amount_raw: uint256 block_date: timestamp + + - name: mummy_finance_optimism_base_trades_seed + config: + column_types: + blockchain: varchar + project: varchar + version: varchar + tx_hash: varbinary + evt_index: uint256 + block_number: uint256 + token_bought_address: varbinary + token_sold_address: varbinary + token_bought_amount_raw: uint256 + token_sold_amount_raw: uint256 + block_date: timestamp \ No newline at end of file diff --git a/seeds/_sector/dex/mummy_finance_optimism_base_trades_seed.csv b/seeds/_sector/dex/mummy_finance_optimism_base_trades_seed.csv new file mode 100644 index 00000000000..a645824e74d --- /dev/null +++ b/seeds/_sector/dex/mummy_finance_optimism_base_trades_seed.csv @@ -0,0 +1,4 @@ +blockchain,project,version,block_date,tx_hash,evt_index,token_bought_address,token_sold_address,token_bought_amount_raw,token_sold_amount_raw,block_number +optimism,mummy_finance,1,2023-06-20,0xcb520a60a0eae0a5a7b9e5658345151a370ef9c236072db32d9b3212ee24a496,36,0x4200000000000000000000000000000000000042,0x7f5c764cbc14f9669b88837ca1490cca17c31607,793611235228965919821,1048751532,105845939 +optimism,mummy_finance,1,2023-06-30,0x671265ebe5dd61134633adf575ba80faec6be090271351ad79fed7c0f5468d50,65,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000042,376164519929816238,525204782676043586106,106272130 +optimism,mummy_finance,1,2023-06-09,0xd7cadb14f39a79bf0ca3ea0ebf9aa85caa1465da154010294ee502942a8de5d4,21,0x4200000000000000000000000000000000000006,0x4200000000000000000000000000000000000042,1530834771081590982,2097160814236567037100,105370626 \ No newline at end of file diff --git a/seeds/dex/trades/dex_trades_seed.csv b/seeds/dex/trades/dex_trades_seed.csv index 82eac113223..2bfa68ea588 100644 --- a/seeds/dex/trades/dex_trades_seed.csv +++ b/seeds/dex/trades/dex_trades_seed.csv @@ -527,3 +527,6 @@ avalanche_c,uniswap,3,2023-11-11,0x31e1a422f13f742ba7ad4c5b2b33bf2cc6c05777cfff4 avalanche_c,uniswap,3,2023-11-11,0x79cc2e2b8543ae7b5215f9f389069106061efc619fa23437b5662d81fac2d8dc,2,0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e,661.400762,0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7,46 avalanche_c,uniswap,3,2023-11-11,0x31e1a422f13f742ba7ad4c5b2b33bf2cc6c05777cfff4062f8e9667dc0eab524,16,0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab,0.6729956329,0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7,95.79678643 avalanche_c,uniswap,3,2023-11-11,0x41b6ec0e3ba96f6c72bab7954353152ba44904bd61232f91e824c9a74495b1e4,2,0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7,600.415091,0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7,41.78982883 +optimism,mummy_finance,1,2023-06-20,0xcb520a60a0eae0a5a7b9e5658345151a370ef9c236072db32d9b3212ee24a496,36,0x4200000000000000000000000000000000000042,793.6112352289659,0x7f5c764cbc14f9669b88837ca1490cca17c31607,1048.751532 +optimism,mummy_finance,1,2023-06-30,0x671265ebe5dd61134633adf575ba80faec6be090271351ad79fed7c0f5468d50,65,0x4200000000000000000000000000000000000006,0.37616451992981625,0x4200000000000000000000000000000000000042,525.2047826760436 +optimism,mummy_finance,1,2023-06-09,0xd7cadb14f39a79bf0ca3ea0ebf9aa85caa1465da154010294ee502942a8de5d4,21,0x4200000000000000000000000000000000000006,1.530834771081591,0x4200000000000000000000000000000000000042,2097.160814236567 \ No newline at end of file