Skip to content

Commit

Permalink
Add pcsx on arb to dex trades (duneanalytics#7465)
Browse files Browse the repository at this point in the history
* add pcsx to arb vs seed file

* add example output into pcs arb base trade seed csv

* add a ExclusiveDutchOrderReactor_evt_Fill table in the arb _sources yml file

* modify the sql code to include pcsx arb

* modified the sql to fix a bug

* fix bug in sql
  • Loading branch information
ChefButterBeer authored Jan 20, 2025
1 parent 1704dd7 commit c4c4123
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 21 deletions.
3 changes: 2 additions & 1 deletion dbt_subprojects/dex/models/trades/arbitrum/_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ models:
blockchain: arbitrum
sector: dex
project: pancakeswap
contributors: chef_seaweed, tomfutago
contributors: chef_butterbeer, chef_seaweed, tomfutago
config:
tags: ["arbitrum", "dex", "trades", "pancakeswap", "uniswap", "v2"]
description: "Pancakeswap Arbitrum v2 base trades"
Expand All @@ -230,6 +230,7 @@ models:
version:
- 2
- stableswap
- pcsx

- name: balancer_v2_arbitrum_base_trades
meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dexs_macro AS (
}}
),

dexs AS (
dexs_ss AS (
-- PancakeSwap v2 stableswap
SELECT
'stableswap' AS version,
Expand All @@ -46,6 +46,51 @@ dexs AS (
{% if is_incremental() %}
WHERE {{ incremental_predicate('t.evt_block_time') }}
{% endif %}
),

transfer as (
select
tx_hash,
"from",
to,
contract_address,
sum(amount_raw) as amount_raw
from {{ source('tokens', 'transfers') }}
where blockchain = 'arbitrum'
and block_date >= date '2024-08-01'
and tx_hash in (select evt_tx_hash from {{ source('pancakeswap_arbitrum', 'ExclusiveDutchOrderReactor_evt_Fill') }})
{% if is_incremental() %}
and {{ incremental_predicate('block_time') }}
{% endif %}
group by 1,2,3,4
),

dexs_pcsx AS (
-- PancakeSwapX
SELECT
'pcsx' AS version,
a.evt_block_number AS block_number,
a.evt_block_time AS block_time,
a.swapper AS taker,
a.filler AS maker,
receive.amount_raw AS token_bought_amount_raw,
send.amount_raw AS token_sold_amount_raw,
receive.contract_address AS token_bought_address,
send.contract_address AS token_sold_address,
a.contract_address AS project_contract_address,
a.evt_tx_hash AS tx_hash,
a.evt_index

FROM {{ source('pancakeswap_arbitrum', 'ExclusiveDutchOrderReactor_evt_Fill') }} a

LEFT JOIN transfer AS send
ON a.evt_tx_hash = send.tx_hash AND a.swapper = send."from"

LEFT JOIN transfer AS receive
on a.evt_tx_hash = receive.tx_hash AND a.swapper = receive."to"
{% if is_incremental() %}
WHERE {{ incremental_predicate('a.evt_block_time') }}
{% endif %}
)

SELECT
Expand All @@ -70,18 +115,40 @@ UNION ALL
SELECT
'arbitrum' AS blockchain,
'pancakeswap' AS project,
dexs.version,
CAST(date_trunc('month', dexs.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs.block_time) AS date) AS block_date,
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
dexs_ss.version,
CAST(date_trunc('month', dexs_ss.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs_ss.block_time) AS date) AS block_date,
dexs_ss.block_time,
dexs_ss.block_number,
dexs_ss.token_bought_amount_raw,
dexs_ss.token_sold_amount_raw,
dexs_ss.token_bought_address,
dexs_ss.token_sold_address,
dexs_ss.taker,
dexs_ss.maker,
dexs_ss.project_contract_address,
dexs_ss.tx_hash,
dexs_ss.evt_index
FROM dexs_ss
UNION ALL
SELECT
'arbitrum' AS blockchain,
'pancakeswap' AS project,
dexs_pcsx.version,
CAST(date_trunc('month', dexs_pcsx.block_time) AS date) AS block_month,
CAST(date_trunc('day', dexs_pcsx.block_time) AS date) AS block_date,
dexs_pcsx.block_time,
dexs_pcsx.block_number,
dexs_pcsx.token_bought_amount_raw,
dexs_pcsx.token_sold_amount_raw,
dexs_pcsx.token_bought_address,
dexs_pcsx.token_sold_address,
dexs_pcsx.taker,
dexs_pcsx.maker,
dexs_pcsx.project_contract_address,
dexs_pcsx.tx_hash,
dexs_pcsx.evt_index
FROM dexs_pcsx
WHERE token_sold_amount_raw > 0
AND token_bought_amount_raw > 0
AND token_bought_address is not NULL
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ arbitrum,pancakeswap,2,2023-08-10,0x1958fe5d2b768dff806749c4d029be07fd5a0e182d4d
arbitrum,pancakeswap,2,2023-08-10,0xb9cda996210e763e0edaa5489a276e96f4db35161b15b95407f95cfd4a8e2c79,10,0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9,0x82af49447d8a07e3bd95bd0d56f35241523fbab1,120059612,221946,125732913697032
arbitrum,pancakeswap,stableswap,2024-04-01,0x2cf8caf24b570525f082d3654ea210877f7900abb1ec86c463ae70983b6aaee5,26,0xb688ba096b7bb75d7841e47163cd12d18b36a5bf,0x0c880f6761f1af8d9aa9c466984b80dab9a8c9e8,196473076,406168916530447950398,296449467065124408277
arbitrum,pancakeswap,stableswap,2024-04-02,0xbf75e0478b82c5748c534f9f2269016bd818d0b404324cb0a03a5f12f61230cb,12,0xb688ba096b7bb75d7841e47163cd12d18b36a5bf,0x0c880f6761f1af8d9aa9c466984b80dab9a8c9e8,196871367,401013690539420465823,288005566501605715147
arbitrum,pancakeswap,pcsx,2025-01-13,0x4b740e957457a80213ec5650991d025441ecef3305dfbe3b77d1c14232ce1c9d,7,0x82af49447d8a07e3bd95bd0d56f35241523fbab1,0x912ce59144191c1204e64559fe8253a0e49e6548,294915549,1270358560945986962,5825398783795375785546
arbitrum,pancakeswap,pcsx,2025-01-13,0xb96773ceea967f9099c585a2d9ff1a2308018291a2c19035ad062e29f285f100,12,0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9,0xaf88d065e77c8cc2239327c5edb3a432268e5831,294910647,200809512,200954754
arbitrum,pancakeswap,pcsx,2025-01-13,0x93026efe07954361d10336be40c64cd430420472faae447d3aee3568d4e13f76,22,0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9,0xaf88d065e77c8cc2239327c5edb3a432268e5831,294940634,367841716,367794365
9 changes: 5 additions & 4 deletions sources/_sector/dex/trades/arbitrum/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ sources:
- name: LBFactory_evt_LBPairCreated
- name: trader_joe_v2_1_arbitrum
- name: trader_joe_arbitrum
- name: pancakeswap_arbitrum
tables:
- name: ExclusiveDutchOrderReactor_evt_Fill
- name: pancakeswap_v2_arbitrum
tables:
- name: PancakePair_evt_Swap
- name: PancakeFactory_evt_PairCreated
- name: PancakeStableSwapTwoPool_evt_TokenExchange
- name: PancakeStableSwapFactory_evt_NewStableSwapPair
- name: pancakeswap_v3_arbitrum
tables:
- name: PancakeV3Pool_evt_Swap
- name: PancakeV3Factory_evt_PoolCreated
- name: pancakeswap_v2_arbitrum
tables:
- name: PancakeStableSwapTwoPool_evt_TokenExchange
- name: PancakeStableSwapFactory_evt_NewStableSwapPair
- name: balancer_v2_arbitrum
tables:
- name: Vault_evt_Swap
Expand Down

0 comments on commit c4c4123

Please sign in to comment.