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

Add arbswap to dex.trades_beta #4869

Merged
merged 5 commits into from
Nov 30, 2023

Conversation

tomfutago
Copy link
Contributor

@tomfutago tomfutago commented Nov 23, 2023

linked to #4759

@dune-eng
Copy link

Workflow run id 6972573753 approved.

@dune-eng
Copy link

Workflow run id 6972574012 approved.

@tomfutago tomfutago marked this pull request as ready for review November 23, 2023 17:12
@Hosuke Hosuke self-assigned this Nov 25, 2023
@Hosuke Hosuke added the dbt: dex covers the DEX dbt subproject label Nov 25, 2023
Copy link
Collaborator

@Hosuke Hosuke left a comment

Choose a reason for hiding this comment

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

@jeff-dude jeff-dude added question Further information is requested in review Assignee is currently reviewing the PR and removed ready-for-final-review labels Nov 27, 2023
@dune-eng
Copy link

Workflow run id 7017377274 approved.

@dune-eng
Copy link

Workflow run id 7017377186 approved.

Comment on lines 33 to 36
{% endif %}

UNION ALL

Copy link
Collaborator

Choose a reason for hiding this comment

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

We may start trying to replace the part before UNION ALL with the macro.

@dune-eng
Copy link

Workflow run id 7018126055 approved.

@dune-eng
Copy link

Workflow run id 7018126165 approved.

@tomfutago
Copy link
Contributor Author

tomfutago commented Nov 28, 2023

Combo of macro + straight select applied, but as macro already contains cte (and already returns final list of columns) - it can't be a direct replacement of current select, but needs to go as a separate nested cte and then union outputs together.

If there's better way to go about it - lmk.

@tomfutago tomfutago requested a review from Hosuke November 28, 2023 11:54
@Hosuke
Copy link
Collaborator

Hosuke commented Nov 29, 2023

I just checked the compiled code of arbswap_arbitrum_base_trades.sql, and it looks good:



WITH 

dexs_macro AS (
    -- Arbswap AMM
    
WITH dexs AS
(
    SELECT
        t.evt_block_number AS block_number
        , t.evt_block_time AS block_time
        , t.to AS taker
        , t.contract_address AS maker
        , CASE WHEN amount0Out = UINT256 '0' THEN amount1Out ELSE amount0Out END AS token_bought_amount_raw
        , CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN amount1In ELSE amount0In END AS token_sold_amount_raw
        , CASE WHEN amount0Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_bought_address
        , CASE WHEN amount0In = UINT256 '0' OR amount1Out = UINT256 '0' THEN f.token1 ELSE f.token0 END AS token_sold_address
        , t.contract_address AS project_contract_address
        , t.evt_tx_hash AS tx_hash
        , t.evt_index AS evt_index
    FROM
        delta_prod.arbswap_arbitrum.SwapPair_evt_Swap t
    INNER JOIN
        delta_prod.arbswap_arbitrum.SwapFactory_evt_PairCreated f
        ON f.pair = t.contract_address
    
)

SELECT
    'arbitrum' AS blockchain
    , 'arbswap' AS project
    , '1' AS 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 AS (
    -- Arbswap Stableswap
    SELECT
        t.evt_block_number AS block_number,
        t.evt_block_time AS block_time,
        t.buyer AS taker,
        CAST(NULL AS VARBINARY) AS maker,
        tokens_bought AS token_bought_amount_raw,
        tokens_sold AS token_sold_amount_raw,
        CASE WHEN bought_id = UINT256 '0' THEN f.tokenA ELSE f.tokenB END AS token_bought_address,
        CASE WHEN sold_id = UINT256 '0' THEN f.tokenA ELSE f.tokenB END AS token_sold_address,
        t.contract_address AS project_contract_address,
        t.evt_tx_hash AS tx_hash,
        t.evt_index
    FROM
        delta_prod.arbswap_arbitrum.ArbswapStableSwapTwoPool_evt_TokenExchange t
    INNER JOIN delta_prod.arbswap_arbitrum.ArbswapStableSwapFactory_evt_NewStableSwapPair f
        ON f.swapContract = t.contract_address
    
)

SELECT
    dexs_macro.blockchain,
    dexs_macro.project,
    dexs_macro.version,
    dexs_macro.block_month,
    dexs_macro.block_date,
    dexs_macro.block_time,
    dexs_macro.block_number,
    dexs_macro.token_bought_amount_raw,
    dexs_macro.token_sold_amount_raw,
    dexs_macro.token_bought_address,
    dexs_macro.token_sold_address,
    dexs_macro.taker,
    dexs_macro.maker,
    dexs_macro.project_contract_address,
    dexs_macro.tx_hash,
    dexs_macro.evt_index
FROM dexs_macro
UNION ALL
SELECT
    'arbitrum' AS blockchain,
    'arbswap' AS project,
    '1' AS 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

Copy link
Collaborator

@Hosuke Hosuke left a comment

Choose a reason for hiding this comment

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

LGTM.✅ for the macro-hybrid spell
Sample macro-hybrid arbswap_arbitrum_base_trades

Copy link
Member

@jeff-dude jeff-dude left a comment

Choose a reason for hiding this comment

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

i'm good with this approach -- thank you for finding a solution!

@Hosuke let's keep in mind for other projects moving forward.

@jeff-dude jeff-dude removed the question Further information is requested label Nov 30, 2023
@jeff-dude jeff-dude removed the in review Assignee is currently reviewing the PR label Nov 30, 2023
@jeff-dude jeff-dude merged commit 8a9e296 into duneanalytics:main Nov 30, 2023
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dbt: dex covers the DEX dbt subproject
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants