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

Dex trades tama #7893

Draft
wants to merge 70 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
84f2521
added test file
sandeshsk12 Feb 28, 2025
57d02bc
Merge branch 'duneanalytics:main' into main
sandeshsk12 Feb 28, 2025
de8f82b
added ronin_tamadotmeme dex trades
sandeshsk12 Mar 3, 2025
43fb116
Merge branch 'duneanalytics:main' into main
sandeshsk12 Mar 3, 2025
b8cc01a
Merge branch 'main' into dex_trades_tama_meme
sandeshsk12 Mar 3, 2025
6f1b8d7
added table to dex_roin_base_trades.sql
sandeshsk12 Mar 3, 2025
f5ac888
added data to dex_ronin_base_trades.sql
sandeshsk12 Mar 3, 2025
636c01b
added seed file
sandeshsk12 Mar 4, 2025
6b72563
Merge branch 'duneanalytics:main' into main
sandeshsk12 Mar 4, 2025
8678f2e
added seed file
sandeshsk12 Mar 4, 2025
f788299
fixed typo
sandeshsk12 Mar 4, 2025
b2dfff1
added data to sources.yml
sandeshsk12 Mar 5, 2025
596ca4b
added source in source.yml
sandeshsk12 Mar 5, 2025
3def7d8
convert numbers to double
sandeshsk12 Mar 5, 2025
e15c6e1
convert numbers to double
sandeshsk12 Mar 5, 2025
f73fb4b
new seed file
sandeshsk12 Mar 5, 2025
cafa95c
Merge branch 'dex_trades_tama_meme'
sandeshsk12 Mar 5, 2025
82597d1
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
6dc99ee
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
4875e8c
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
eebb75d
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
151dc20
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
e43e1e9
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
0cb3f13
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
429ac4a
reduced decimals in seed file
sandeshsk12 Mar 5, 2025
07aa30c
fixed query
sandeshsk12 Mar 5, 2025
657a37a
fixed query
sandeshsk12 Mar 5, 2025
97dde4e
fixed query
sandeshsk12 Mar 5, 2025
a5523ec
fixed query
sandeshsk12 Mar 5, 2025
2881924
fixed query
sandeshsk12 Mar 5, 2025
e0c1450
filtered for successful calls
sandeshsk12 Mar 5, 2025
0821914
added data in schema_yml
sandeshsk12 Mar 5, 2025
11fc6ef
added data in schema_yml
sandeshsk12 Mar 5, 2025
c92f563
added data in schema_yml
sandeshsk12 Mar 5, 2025
4aa9902
fixed data in schema_yml
sandeshsk12 Mar 5, 2025
74ba99a
Merge branch 'main' into main
sandeshsk12 Mar 5, 2025
842030a
Merge branch 'duneanalytics:main' into main
sandeshsk12 Mar 13, 2025
bfe6893
Merge branch 'duneanalytics:main' into main
sandeshsk12 Mar 16, 2025
0bc1f9f
test case fixed
sandeshsk12 Mar 19, 2025
d33660f
fixed tests
sandeshsk12 Mar 19, 2025
5372139
fixed typo
sandeshsk12 Mar 19, 2025
2407711
fixed typo
sandeshsk12 Mar 19, 2025
a751c7c
initial commit
sandeshsk12 Mar 20, 2025
2d1a65f
Added name to dex_info.sql
sandeshsk12 Mar 20, 2025
f41a24a
add name to dex_info.sql
sandeshsk12 Mar 20, 2025
cb3f3fa
fixed wrong timestamp
sandeshsk12 Mar 20, 2025
01cabd1
fixed data types and typos
sandeshsk12 Mar 20, 2025
03ce0e1
added new seed file with data types defined in dune query
sandeshsk12 Mar 20, 2025
3e2abe1
changed data types of raw amounts in seed file schema
sandeshsk12 Mar 20, 2025
1bcd278
added new seed file with data types defined in dune query
sandeshsk12 Mar 20, 2025
e514639
changed data_type of amount_raw in dex_base_trades.sql
sandeshsk12 Mar 20, 2025
fbe671d
fixed seed file with names
sandeshsk12 Mar 20, 2025
0ade69c
fixed data types of block_date and block_month
sandeshsk12 Mar 21, 2025
f35e1e6
empty seed file
sandeshsk12 Mar 22, 2025
31ca28b
Merge branch 'main' into dex_trades_tama
sandeshsk12 Mar 22, 2025
ca584fa
add seed file data
sandeshsk12 Mar 23, 2025
4a394ff
version column in seed file has been converted to string
sandeshsk12 Mar 24, 2025
5e1d319
version column in SQL file has been converted to string
sandeshsk12 Mar 24, 2025
ce1fb01
seed file fixed
sandeshsk12 Mar 24, 2025
f74827d
Added comment
sandeshsk12 Mar 24, 2025
8bb2f91
version is now integer
sandeshsk12 Mar 24, 2025
57442c6
reduced unique combo to only tx_hash
sandeshsk12 Mar 24, 2025
5731b48
evt_index_tx_hash now the unique combination
sandeshsk12 Mar 24, 2025
7830ed0
fixed version varchar
sandeshsk12 Mar 24, 2025
e54d7ce
Merge branch 'main' into dex_trades_tama
sandeshsk12 Mar 24, 2025
b13d641
fixed name
sandeshsk12 Mar 24, 2025
531ce54
fixed name
sandeshsk12 Mar 24, 2025
b2880ec
varchar changed for version
sandeshsk12 Mar 24, 2025
0be9e97
Merge branch 'main' into dex_trades_tama
sandeshsk12 Mar 25, 2025
51183d5
varchar changed for version
sandeshsk12 Mar 25, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ logs/
!target/sources.json

dbt_subprojects/dex/spellbook-env/

# dbt creds
spellbook/dbt_subprojects/dex/dbt_project.yml
2 changes: 2 additions & 0 deletions dbt_subprojects/dex/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: "dex"
version: "1.0.0"
config-version: 2
require-dbt-version: ">=1.8.0"
# dbt-cloud:
# project-id: 70471823438801

quoting:
database: false
Expand Down
1 change: 1 addition & 0 deletions dbt_subprojects/dex/models/dex_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,5 @@ FROM (VALUES
, ('beraswap', 'BeraSwap', 'Direct', 'BeraSwap')
, ('burrbear', 'BurrBear', 'Direct', 'moneygoesburr')
, ('reservoir_swap', 'Reservoir Swap', 'Direct', 'reservoir0x')
, ('tamadotmeme', 'tamadotmeme', 'Direct', 'tamadotmeme')
) AS temp_table (project, name, marketplace_type, x_username)
4 changes: 2 additions & 2 deletions dbt_subprojects/dex/models/trades/dex_base_trades.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ with base_union as (
, block_date
, block_time
, block_number
, cast(token_bought_amount_raw as uint256) as token_bought_amount_raw
, cast(token_sold_amount_raw as uint256) as token_sold_amount_raw
, cast(token_bought_amount_raw as double) as token_bought_amount_raw
, cast(token_sold_amount_raw as double) as token_sold_amount_raw
, token_bought_address
, token_sold_address
, taker
Expand Down
18 changes: 18 additions & 0 deletions dbt_subprojects/dex/models/trades/ronin/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,21 @@ models:
seed_file: ref('katana_ronin_base_trades_seed')
filter:
version: 3

- name: tamadotmeme_v1_ronin_base_trades
meta:
blockchain: ronin
sector: dex
project: tamadotmeme
contributors: 0xsandeshk
config:
tags: ["ronin", "dex", "trades", "tamadotmeme"]
description: "tamadotmeme ronin base trades"
data_tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- tx_hash
- evt_index
- check_dex_base_trades_seed:
seed_file: ref('tamadotmeme_ronin_base_trades_seed')

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% set base_models = [
ref('katana_v2_ronin_base_trades')
, ref('katana_v3_ronin_base_trades')
, ref('tamadotmeme_v1_ronin_base_trades')
] %}

WITH base_union AS (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{{ config(
schema = 'tamadotmeme_v1_ronin',
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')]
) }}

-- Retrieve hourly Ronin prices for the WRON token.
WITH ronin_price AS (
SELECT
hour,
median_price AS ron_price
FROM {{ source('dex', 'prices') }}
WHERE contract_address = 0xe514d9deb7966c8be0ca922de8a064264ea6bcd4
),

-- Process "buy" transactions:
-- - Normalizes token amounts (dividing by 10^18).
-- - Joins on token creation events to get a readable token symbol.
-- - Computes the USD value using the hourly Ronin price.
-- - Filters out events before the Tama Trade protocol launch.
buy AS (
SELECT
'ronin' AS blockchain,
'tamadotmeme' AS project,
'1' AS version,
DATE_TRUNC('month', bet.call_block_time) AS block_month,
DATE_TRUNC('day', bet.call_block_time) AS block_date,
bet.call_block_time AS block_time,
bet.call_block_number AS block_number,
tc.symbol AS token_bought_symbol, -- Readable token symbol from creation event.
'WRON' AS token_sold_symbol, -- WRON represents the wrapped RONIN token.
concat(tc.symbol, '-', 'WRON') AS token_pair,
cast(bet.output_amountOut as double) / POWER(10, 18) AS token_bought_amount,
cast(bet.amountIn as double) / POWER(10, 18) AS token_sold_amount,
cast(bet.output_amountOut as double) AS token_bought_amount_raw,
cast(bet.amountIn as double) AS token_sold_amount_raw,
cast(bet.amountIn as double) / POWER(10, 18) * rp.ron_price AS amount_usd, -- USD value
bet.token AS token_bought_address,
0xe514d9deb7966c8be0ca922de8a064264ea6bcd4 AS token_sold_address, -- All tokens on tamadot meme are bought using RONIN
bet.call_tx_from AS taker,
bet.contract_address AS maker,
bet.contract_address AS project_contract_address,
bet.call_tx_hash AS tx_hash,
bet.call_tx_from AS tx_from,
bet.call_tx_to AS tx_to,
bet.call_tx_index AS evt_index,
row_number() over(partition by bet.call_tx_hash order by bet.call_trace_address asc) as rn

FROM {{ source('tamadotmeme_ronin', 'maincontract_call_buytokenswitheth') }} AS bet
LEFT JOIN {{ source('tamadotmeme_ronin', 'maincontract_evt_tokencreated') }} AS tc
ON bet.token = tc.token
LEFT JOIN ronin_price AS rp
ON DATE_TRUNC('hour', bet.call_block_time) = rp.hour
WHERE call_block_time >= TRY_CAST('2025-01-21 14:07' AS TIMESTAMP)
and call_success
),

-- Process "sell" transactions:
-- Similar to the "buy" section, this CTE normalizes amounts, adds token symbol info,
-- computes USD value, and applies the same protocol launch filter.
sell AS (
SELECT
'ronin' AS blockchain,
'tamadotmeme' AS project,
'1' AS version,
DATE_TRUNC('month', ste.call_block_time) AS block_month,
DATE_TRUNC('day', ste.call_block_time) AS block_date,
ste.call_block_time AS block_time,
ste.call_block_number AS block_number,
'WRON' AS token_bought_symbol,
tc.symbol AS token_sold_symbol, -- Readable token symbol from creation event.
concat(tc.symbol, '-', 'WRON') AS token_pair,
cast(ste.output_amountOut as double) / POWER(10, 18) AS token_bought_amount,
cast(ste.amountIn as double) / POWER(10, 18) AS token_sold_amount,
cast(ste.output_amountOut as double) AS token_bought_amount_raw,
cast(ste.amountIn as double) AS token_sold_amount_raw,
cast(ste.output_amountOut as double) / POWER(10, 18) * rp.ron_price AS amount_usd,
0xe514d9deb7966c8be0ca922de8a064264ea6bcd4 AS token_bought_address, -- All tokens on tamadot meme are sold for RONIN
ste.token AS token_sold_address,
ste.call_tx_from AS taker,
ste.call_tx_to AS maker,
ste.contract_address AS project_contract_address,
ste.call_tx_hash AS tx_hash,
ste.call_tx_from AS tx_from,
ste.call_tx_to AS tx_to,
ste.call_tx_index AS evt_index,
row_number() over(partition by ste.call_tx_hash order by ste.call_trace_address asc) as rn

FROM {{ source('tamadotmeme_ronin', 'maincontract_call_selltokensforeth') }} AS ste
LEFT JOIN {{ source('tamadotmeme_ronin', 'maincontract_evt_tokencreated') }} AS tc
ON ste.token = tc.token
LEFT JOIN ronin_price AS rp
ON DATE_TRUNC('hour', ste.call_block_time) = rp.hour
WHERE call_block_time >= TRY_CAST('2025-01-21 14:07' AS TIMESTAMP)
and call_success
)

,combined as
(
(SELECT * FROM buy where rn=1)
UNION ALL
(SELECT * FROM sell where rn=1)
)
select
cast (blockchain as varchar) as blockchain
, cast (project as varchar) as project
, cast (version as varchar) as version
, cast (block_month as date) as block_month
, cast (block_date as date) as block_date
, cast (block_time as timestamp) as block_time
, cast (block_number as uint256) as block_number
, cast (token_bought_symbol as varchar) as token_bought_symbol
, cast (token_sold_symbol as varchar) as token_sold_symbol
, cast (token_pair as varchar) as token_pair
, cast (token_bought_amount as uint256) as token_bought_amount
, cast (token_sold_amount as uint256) as token_sold_amount
, cast (token_bought_amount_raw as double) as token_bought_amount_raw
, cast (token_sold_amount_raw as double) as token_sold_amount_raw
, cast (amount_usd as uint256) as amount_usd
, cast (token_bought_address as varbinary) as token_bought_address
, cast (token_sold_address as varbinary) as token_sold_address
, cast (taker as varbinary) as taker
, cast (maker as varbinary) as maker
, cast (project_contract_address as varbinary) as project_contract_address
, cast (tx_hash as varbinary) as tx_hash
, cast (tx_from as varbinary) as tx_from
, cast (tx_to as varbinary) as tx_to
, cast (evt_index as uint256) as evt_index
from combined
14 changes: 14 additions & 0 deletions dbt_subprojects/dex/seeds/trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4968,4 +4968,18 @@ seeds:
token_sold_address: varbinary
token_bought_amount_raw: uint256
token_sold_amount_raw: uint256
block_date: timestamp
- name: tamadotmeme_ronin_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: double
token_sold_amount_raw: double
block_date: timestamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blockchain,project,version,block_month,block_date,block_time,block_number,token_bought_symbol,token_sold_symbol,token_pair,token_bought_amount,token_sold_amount,token_bought_amount_raw,token_sold_amount_raw,amount_usd,token_bought_address,token_sold_address,taker,maker,project_contract_address,tx_hash,tx_from,tx_to,evt_index
ronin,tamadotmeme,1,2025-03-01 00:00:00,2025-03-05 00:00:00,2025-03-05 03:48:53,43098037,WRON,CATA,CATA-WRON,55,2449126,55057648837407490000,2449126284014839500000000,49,0xe514d9deb7966c8be0ca922de8a064264ea6bcd4,0xdd3d4e4014fcdc7f0f68d7a7f6d27554bcc75e22,0xd48c2d71b9bc18308f68cec3ebc30d24fd8e15f2,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0xd8d1bab27279b54fb4285576c6cd876d8c9a6dc456fafb0c56a7e4a1eb393c03,0xd48c2d71b9bc18308f68cec3ebc30d24fd8e15f2,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0
ronin,tamadotmeme,1,2025-03-01 00:00:00,2025-03-06 00:00:00,2025-03-06 21:54:33,43148546,WRON,ALT,ALT-WRON,59,9344862,59020062936203125000,9344862084910370000000000,54,0xe514d9deb7966c8be0ca922de8a064264ea6bcd4,0x176bacdbf7dd4f3e598e0cf53a86eeca727ea80c,0xd3dbce32839a0c319f6c5553678017a90dc227d8,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0xd50b7e9b79420e68be998e7a7973eda2a8150f1b15d581eb5fc8416a30440436,0xd3dbce32839a0c319f6c5553678017a90dc227d8,0xa54b0184d12349cf65281c6f965a74828ddd9e8f,0
5 changes: 5 additions & 0 deletions sources/_sector/dex/trades/ronin/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ sources:
- name: KatanaFactory_evt_PairCreated
- name: KatanaV3Pool_evt_Swap
- name: KatanaV3Factory_evt_PoolCreated
- name: tamadotmeme_ronin
tables:
- name: maincontract_call_buytokenswitheth
- name: maincontract_evt_tokencreated
- name: maincontract_call_selltokensforeth
Loading