Skip to content

Commit 3a9c865

Browse files
[OPENSEA] add OS in-app swaps / token trading (#9044)
1 parent 3643de2 commit 3a9c865

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{{
2+
config(
3+
schema = 'opensea',
4+
alias = 'evm_token_trades',
5+
materialized = 'incremental',
6+
file_format = 'delta',
7+
incremental_strategy = 'merge',
8+
unique_key = ['tx_hash', 'generatedIndex', 'blockchain'],
9+
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
10+
)
11+
}}
12+
13+
WITH opensea_evm_hashs AS (
14+
SELECT
15+
blockchain
16+
, hash
17+
FROM {{ source('evms', 'transactions') }}
18+
WHERE SUBSTR("data", varbinary_length("data") - 3, 4) = 0x865d8597
19+
AND block_time > TRY_CAST('2025-03-12 23:42' AS TIMESTAMP)
20+
AND blockchain IN (
21+
'ethereum'
22+
, 'abstract'
23+
, 'apechain'
24+
, 'arbitrum'
25+
, 'avalanche_c'
26+
, 'b3'
27+
, 'base'
28+
, 'berachain'
29+
, 'blast'
30+
, 'flow'
31+
, 'optimism'
32+
, 'polygon'
33+
, 'unichain'
34+
, 'ronin'
35+
, 'sei'
36+
, 'shape'
37+
, 'zora'
38+
)
39+
{% if is_incremental() %}
40+
AND {{ incremental_predicate('block_time') }}
41+
{% endif %}
42+
)
43+
44+
SELECT
45+
det.blockchain
46+
, det.project
47+
, det."version"
48+
, det.project_contract_address
49+
, det.tx_from
50+
, det.block_time
51+
, det.token_bought_symbol
52+
, det.token_bought_address
53+
, det.token_sold_symbol
54+
, det.token_sold_address
55+
, det.token_sold_amount
56+
, det.amount_usd
57+
, det.tx_hash
58+
, det.block_number * POW(10,5) + evt_index AS generatedIndex
59+
FROM dex.trades det
60+
INNER JOIN opensea_evm_hashs oeh
61+
ON det.tx_hash = oeh.hash
62+
AND det.blockchain = oeh.blockchain
63+
WHERE det.block_time > TRY_CAST('2025-03-12 23:42' AS TIMESTAMP)
64+
{% if is_incremental() %}
65+
AND {{ incremental_predicate('det.block_time') }}
66+
{% endif %}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{
2+
config(
3+
schema = 'opensea',
4+
alias = 'solana_token_trades',
5+
materialized = 'incremental',
6+
file_format = 'delta',
7+
incremental_strategy = 'merge',
8+
unique_key = ['blockchain', 'project', 'trader_id', 'block_time', 'token_bought_symbol', 'token_bought_mint_address', 'token_sold_symbol', 'token_sold_mint_address', 'token_sold_amount', 'amount_usd', 'tx_id'],
9+
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
10+
)
11+
}}
12+
13+
WITH opensea_tx_ids AS (
14+
SELECT DISTINCT(tx_id) AS tx_id
15+
FROM {{ source('solana', 'instruction_calls') }}
16+
WHERE CONTAINS(log_messages, 'Program log: Memo (len 8): "865d8597"')
17+
AND executing_account = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
18+
AND block_time > TRY_CAST('2025-05-26 00:00' AS TIMESTAMP)
19+
{% if is_incremental() %}
20+
AND {{ incremental_predicate('block_time') }}
21+
{% endif %}
22+
)
23+
24+
SELECT
25+
dst.blockchain
26+
, dst.project
27+
, dst.trader_id
28+
, dst.block_time
29+
, dst.token_bought_symbol
30+
, dst.token_bought_mint_address
31+
, dst.token_sold_symbol
32+
, dst.token_sold_mint_address
33+
, dst.token_sold_amount
34+
, dst.amount_usd
35+
, dst.tx_id
36+
FROM {{ source('dex_solana', 'trades') }} dst
37+
INNER JOIN opensea_tx_ids oti
38+
ON dst.tx_id = oti.tx_id
39+
WHERE dst.block_time > TRY_CAST('2025-05-26 00:00' AS TIMESTAMP)
40+
{% if is_incremental() %}
41+
AND {{ incremental_predicate('dst.block_time') }}
42+
{% endif %}

0 commit comments

Comments
 (0)