Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mummy_finance optimism trades #4861

Merged
merged 83 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
769ddc8
add openxswap trades
ARDev097 Oct 7, 2023
94fa2d1
Merge branch 'main' into main
ARDev097 Oct 7, 2023
6016d6b
add legacy file for openxswap trades
ARDev097 Oct 7, 2023
5ac28b1
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 7, 2023
7930509
update legacy file for openxswap trades
ARDev097 Oct 7, 2023
1117163
Add seeds records for openxswap
ARDev097 Oct 9, 2023
cee2755
Add uniqueness and check_dex_seed tests
Hosuke Oct 9, 2023
ede1f32
updated seeds records for openxswap
ARDev097 Oct 9, 2023
52d4018
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 9, 2023
f45d1a4
Merge branch 'main' into main
Hosuke Oct 9, 2023
a672611
added openocean dex
ARDev097 Oct 18, 2023
b055157
Added seed data for openocean dex
ARDev097 Oct 18, 2023
69db76e
Added seed data for openocean dex
ARDev097 Oct 19, 2023
f8a31db
Merge branch 'main' into main
ARDev097 Oct 19, 2023
b111fc7
Updated dex_trades_assert_freshness file
ARDev097 Oct 19, 2023
31f685e
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 19, 2023
ef1ddde
Updated trades.sql file
ARDev097 Oct 20, 2023
b566e57
Updated trades.sql file
ARDev097 Oct 20, 2023
40319ca
Merge branch 'main' into main
ARDev097 Oct 20, 2023
4c16a37
Modified schema file
ARDev097 Oct 20, 2023
398df12
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 20, 2023
e83ba26
Merge branch 'main' into main
ARDev097 Oct 20, 2023
8b00d70
Modified schema file
ARDev097 Oct 20, 2023
d038792
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 20, 2023
252ca47
Modified schema file
ARDev097 Oct 20, 2023
b392a25
Modified schema file
ARDev097 Oct 21, 2023
17305c2
Modified schema file
ARDev097 Oct 21, 2023
c65b9ab
Modified schema file
ARDev097 Oct 21, 2023
30d2ffe
Modified seeds file
ARDev097 Oct 21, 2023
6fcab01
Merge branch 'main' into main
ARDev097 Oct 21, 2023
f25d65d
Update models/openocean/optimism/openocean_optimism_trades.sql
Hosuke Oct 21, 2023
637729c
modified trades file
ARDev097 Oct 22, 2023
28f209c
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Oct 22, 2023
c446a43
Update models/openocean/optimism/openocean_optimism_trades.sql
Hosuke Oct 23, 2023
b990856
Update models/openocean/optimism/openocean_optimism_schema.yml
Hosuke Oct 23, 2023
a75e5f5
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
aad807f
Merge branch 'main' into main
ARDev097 Nov 8, 2023
8f308ac
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
fb5ddee
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Nov 8, 2023
cd97b84
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
b2e550d
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
d7dccfc
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
129440d
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
4e1eb3e
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
ebb51d9
Added Odos Optimism Dex Trades Data
ARDev097 Nov 8, 2023
b5c8ddf
Added Odos Optimism Dex Trades Data
ARDev097 Nov 9, 2023
6d6de0f
added sepll for woofi dex on optimism
ARDev097 Nov 11, 2023
53d58a8
added sepll for woofi dex on optimism
ARDev097 Nov 11, 2023
5223d25
added sepll for woofi dex on optimism
ARDev097 Nov 11, 2023
7874ce3
added sepll for woofi dex on optimism
ARDev097 Nov 11, 2023
501af15
Removed tag from trades.sql file
ARDev097 Nov 13, 2023
18805a9
Merge branch 'main' into main
ARDev097 Nov 13, 2023
f7b795d
Implement woofi_optimism_base_trades
Hosuke Nov 13, 2023
bca546f
Add block_number
Hosuke Nov 13, 2023
c8f3d19
Merge branch 'main' into main
ARDev097 Nov 15, 2023
fa6b207
Merge branch 'main' into main
ARDev097 Nov 16, 2023
de0446f
Update dex_trades_seed.csv (Removing zksync line which might be added…
ARDev097 Nov 16, 2023
801d126
Add woofi_optimism_base_trades_seed
Hosuke Nov 16, 2023
48c6971
Add check_seed test to woofi_optimism_base_trades
Hosuke Nov 16, 2023
9b50086
Merge branch 'main' into main
Hosuke Nov 20, 2023
568b04b
Remove dunesql tag
Hosuke Nov 20, 2023
f5bc3a7
Remove duped seed definition
Hosuke Nov 20, 2023
80d7882
Merge branch 'main' into main
Hosuke Nov 21, 2023
85a3875
Merge branch 'main' into main
Hosuke Nov 21, 2023
680eb6b
Merge branch 'main' into main
jeff-dude Nov 21, 2023
0586323
Merge branch 'main' into main
ARDev097 Nov 22, 2023
e358237
Added mummy_finance dex trade's
ARDev097 Nov 23, 2023
36d823b
Merge branch 'main' into main
ARDev097 Nov 23, 2023
91059d4
Removed trace_address column
ARDev097 Nov 23, 2023
6dca0ca
Merge branch 'main' of https://github.com/ARDev097/spellbook
ARDev097 Nov 23, 2023
fbdc83e
Implemented macro approach in mummy_finance dex trades
ARDev097 Nov 24, 2023
cc5b0da
Implemented macro approach in mummy_finance dex trades
ARDev097 Nov 24, 2023
ca00975
Implemented macro approach in mummy_finance dex trades
ARDev097 Nov 24, 2023
53f9472
Make changes in dex_trades_assert_freshness file
ARDev097 Nov 24, 2023
c63b02e
Updated seed file record
ARDev097 Nov 24, 2023
6718d4d
Updated seed file record
ARDev097 Nov 24, 2023
63340bf
Updated dex_trades_asser_freshness file
ARDev097 Nov 24, 2023
eaf41d4
Updated base_trades file
ARDev097 Nov 27, 2023
ff558b2
Updated base_trades file
ARDev097 Nov 27, 2023
16ea5b8
Recover tests/dex/dex_trades_assert_freshness.sql
Hosuke Nov 27, 2023
b72502e
Merge branch 'main' into main
Hosuke Nov 29, 2023
5e8d72b
Merge branch 'main' into main
Hosuke Nov 29, 2023
d62cc18
Merge branch 'main' into main
ARDev097 Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion models/_sector/dex/trades/optimism/_schema.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 2

models:
- name: dex_optimism_base_trades

- name: uniswap_v3_optimism_base_trades
meta:
blockchain: optimism
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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')
] %}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions models/dex/dex_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
,ref('openocean_optimism_trades')
,ref('woofi_optimism_trades')
,ref('oneinch_lop_own_trades')
,ref('mummy_finance_optimism_trades')
] %}


Expand Down
96 changes: 96 additions & 0 deletions models/mummy_finance/optimism/mummy_finance_optimism_schema.yml
Original file line number Diff line number Diff line change
@@ -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: ""
11 changes: 11 additions & 0 deletions models/mummy_finance/optimism/mummy_finance_optimism_sources.yml
Original file line number Diff line number Diff line change
@@ -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
116 changes: 116 additions & 0 deletions models/mummy_finance/optimism/mummy_finance_optimism_trades.sql
Original file line number Diff line number Diff line change
@@ -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 %}
15 changes: 15 additions & 0 deletions seeds/_sector/dex/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions seeds/_sector/dex/mummy_finance_optimism_base_trades_seed.csv
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions seeds/dex/trades/dex_trades_seed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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