Skip to content

added tama_meme_dex #8002

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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ logs/
!target/sources.json

dbt_subprojects/dex/spellbook-env/
dbt_subprojects/dex/dbt_cloud.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to recover this file.

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 @@ -213,4 +213,5 @@ FROM (VALUES
, ('inkyswap', 'InkySwap', 'Direct', 'inkyswap')
, ('squidswap', 'SquidSwap', 'Direct', 'squidswap_ink')
, ('swanswap', 'SwanSwap', 'Direct', 'swan_swap')
, ('tamadotmeme', 'tamadotmeme', 'Direct', 'tamadotmeme')
) AS temp_table (project, name, marketplace_type, x_username)
17 changes: 17 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,20 @@ 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,150 @@
{{ config(
schema = 'tamadotmeme_v1_ronin',
alias = 'base_trades',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['tx_hash', 'evt_index']
) }}

-- 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
),
Comment on lines +11 to +17
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be the correct approach to implement a base_trades spell,
please read the document first:
https://github.com/duneanalytics/spellbook/blob/main/dbt_subprojects/dex/models/trades/readme.md


-- Process "buy" transactions:
-- This CTE identifies and transforms "buy" transactions from the tamadotmeme protocol on Ronin.
-- It normalizes token amounts, joins on token creation events to get a readable token symbol,
-- computes the USD value using the hourly Ronin price, and applies a protocol launch filter.

-- While we could use the simple marcos table for trade pairs, some of the tokens might not have data, so we instead use contracts data
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant date and addresses can be introduced as jinja vars.

{% if is_incremental() %}
AND
{{ incremental_predicate('bet.call_block_time') }}
{% endif %}
and call_tx_to!=0x9b0a1d03ea99a8b3cf9b7e73e0aa1b805ce45c54 -- edge case where the tx is both a buy and a sell and coincentally the same token has the same event indiex in respective table
and call_success
),

-- Process "sell" transactions:
-- This CTE identifies and transforms "sell" transactions from the tamadotmeme protocol on Ronin.
-- It mirrors the "buy" CTE, but extracts data from the "sell" transaction events.
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('WRON' , '-', tc.symbol) 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)
{% if is_incremental() %}
AND
{{ incremental_predicate('ste.call_block_time') }}
{% endif %}
and call_tx_to!=0x9b0a1d03ea99a8b3cf9b7e73e0aa1b805ce45c54 -- edge case where the tx is both a buy and a sell and coincentally the same token has the same event indiex in respective table
and call_success
)

-- Combine buy and sell transactions:
-- This CTE combines the results from the "buy" and "sell" CTEs into a single dataset.
-- while also ensuring the last row of each transaction is selected
,combined as (

(SELECT * FROM buy where rn=1)
UNION ALL
(SELECT * FROM sell where rn=1)

)

-- Select and cast the final output:
-- This SELECT statement casts the columns to the appropriate data types for the final model.
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 double) as token_bought_amount
, cast (token_sold_amount as double) as token_sold_amount
, 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 (amount_usd as double) 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
15 changes: 15 additions & 0 deletions dbt_subprojects/dex/seeds/trades/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5059,3 +5059,18 @@ seeds:
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: uint256
token_sold_amount_raw: uint256
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