Skip to content

Commit

Permalink
Merge branch 'main' into macro-2
Browse files Browse the repository at this point in the history
  • Loading branch information
RantumBits authored Jan 27, 2025
2 parents 09e56c0 + 9fbf0df commit 0b24f08
Show file tree
Hide file tree
Showing 113 changed files with 1,777 additions and 662 deletions.
8 changes: 4 additions & 4 deletions dbt_macros/shared/balancer/balancer_bpt_prices_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ WITH pool_labels AS (
GROUP BY 1, 2, 3
),

erc4626_prices AS(
erc4626_prices AS (
SELECT
date_trunc('day', minute) AS day,
DATE_TRUNC('day', minute) AS day,
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
GROUP BY 1, 2, 3
),

swaps_changes AS (
Expand Down
20 changes: 8 additions & 12 deletions dbt_macros/shared/balancer/balancer_liquidity_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -339,10 +337,8 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -387,16 +383,16 @@ WITH pool_labels AS (
GROUP BY 1
),

erc4626_prices AS(
erc4626_prices AS (
SELECT
date_trunc('day', minute) AS day,
DATE_TRUNC('day', minute) AS day,
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
GROUP BY 1, 2, 3
),

swaps_changes AS (
Expand Down
20 changes: 8 additions & 12 deletions dbt_macros/shared/balancer/balancer_protocol_fee_macro.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -221,10 +219,8 @@ WITH pool_labels AS (
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
GROUP BY 1, 2
HAVING sum(sample_size) > 3
),
Expand Down Expand Up @@ -272,16 +268,16 @@ WITH pool_labels AS (
FROM bpt_prices_1
),

erc4626_prices AS(
erc4626_prices AS (
SELECT
date_trunc('day', minute) AS day,
DATE_TRUNC('day', minute) AS day,
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
GROUP BY 1, 2, 3
),

daily_protocol_fee_collected AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ WITH
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
{% if is_incremental() %}
AND {{ incremental_predicate('hour') }}
{% endif %}
Expand Down Expand Up @@ -216,10 +214,8 @@ WITH
approx_percentile(median_price, 0.5) AS price,
sum(sample_size) AS sample_size
FROM {{ source('dex', 'prices') }}
WHERE
(('{{blockchain}}' = 'sonic' AND contract_address != 0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38)
OR ('{{blockchain}}' = 'fantom' AND contract_address NOT IN (0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)))
AND blockchain = '{{blockchain}}'
WHERE blockchain = '{{blockchain}}'
AND contract_address NOT IN (0x039e2fb66102314ce7b64ce5ce3e5183bc94ad38, 0xde1e704dae0b4051e80dabb26ab6ad6c12262da0, 0x5ddb92a5340fd0ead3987d3661afcd6104c3b757)
{% if is_incremental() %}
AND {{ incremental_predicate('hour') }}
{% endif %}
Expand Down Expand Up @@ -272,16 +268,16 @@ WITH
GROUP BY 1
),

erc4626_prices AS(
erc4626_prices AS (
SELECT
date_trunc('day', minute) AS day,
DATE_TRUNC('day', minute) AS day,
wrapped_token AS token,
decimals,
APPROX_PERCENTILE(median_price, 0.5) AS price,
DATE_TRUNC ('day', next_change) AS next_change
LEAD(DATE_TRUNC('day', minute), 1, CURRENT_DATE + INTERVAL '1' day) OVER (PARTITION BY wrapped_token ORDER BY date_trunc('day', minute)) AS next_change
FROM {{ source('balancer_v3' , 'erc4626_token_prices') }}
WHERE blockchain = '{{blockchain}}'
GROUP BY 1, 2, 3, 5
GROUP BY 1, 2, 3
),

daily_balance AS (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ FROM (VALUES
,('Project', 0x850a146D7478dAAa98Fc26Fd85e6A24e50846A9d, 'viaPrize', 'Season 4')
,('Project', 0x4ABa01FB8E1f6BFE80c56Deb367f19F35Df0f4aE, 'Beefy - Universal Zap', 'Season 4')
,('Project', 0xB646C68578835F44d7C5b3F44ed51174FD1A89DE, 'DRPC - a more affordable, cost-efficient, and scalable RPC solution for Optimism', 'Season 4')
-- ,('Project', TBD , 'Immunefi Bug Bounty Program for Protocols building on Optimism', 'Season 4')
,('Project', 0x2501c477d0a35545a387aa4a3eee4292a9a8b3f0, 'Immunefi Bug Bounty Program for Protocols building on Optimism', 'Season 4')
,('Project', 0x82d2242257115351899894eF384f779b5ba8c695, 'Kwenta Referral Program', 'Season 4')
,('Project', 0xBBEa9BA18e457303D666b6bd27AdE10221E3635f, 'Lemon Cash Grant Proposal', 'Season 4')
,('Project', 0xD4C00FE7657791C2A43025dE483F05E49A5f76A6, 'LYRA V2', 'Season 4')
Expand All @@ -261,7 +261,7 @@ FROM (VALUES
,('Project', 0x707f310DD0325f48Fe06e1D44Cb5fdb522EDf723, 'MultiBaas historical data', 'Season 4')
,('Project', 0x811Cc10d5a80B037dCcbC467C33736Ce7e6690fB, 'seal: UI for smart contracts', 'Season 4')
,('Project', 0x5A973117Dd273676bf4D14313b80562DC8973ba9, '[RFG-3] Sherlock Audits', 'Season 4')
-- ,('Project', TBD , '[RFG-3] Trail of Bits Security Reviews', 'Season 4')
,('Project', 0x5A973117Dd273676bf4D14313b80562DC8973ba9, '[RFG-3] Trail of Bits Security Reviews', 'Season 4')
,('Project', 0xB6B9E9e56AB5a4AF927faa802ac93786352f3af9, 'Cantina.xyx and Spearbit Labs: RFG-3', 'Season 4')
,('Project', 0x697008C9CcA249eB5AbE9583f041A18A850453A4, 'LlamaNodes | High-Performant & Cost-Effective RPCs', 'Season 4')
,('Project', 0x4a364125054B47b669af9D16cc65dCE6C6Fbd573, 'FHE x OP', 'Season 4')
Expand Down
4 changes: 2 additions & 2 deletions dbt_subprojects/daily_spellbook/models/evms/evms_info.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
]\',
"sector",
"evms",
\'["hildobby", "hosuke", "jeff-dude"]\') }}')
\'["hildobby", "hosuke", "jeff-dude", "agaperste"]\') }}')
}}

SELECT chain_id
Expand Down Expand Up @@ -90,7 +90,7 @@ FROM (
, (11155111, 'sepolia', 'Sepolia', 'Testnet', 'Testnet', 'tETH', 0x7b79995e5f793a07bc00c21412e50ecae098e7f9, 'https://sepolia.etherscan.io/', timestamp '2015-07-30 15:26:13', NULL, NULL, NULL, true)
, (167000, 'taiko', 'Taiko', 'Layer 2', 'Optimistic Rollup', 'ETH', 0xa51894664a773981c6c112c43ce576f315d5b1b6, 'https://taikoscan.network/', timestamp '2024-03-29 07:39:12', 'OP Stack', 'Ethereum Blobs', 'Ethereum', false)
, (1329, 'sei', 'Sei Network', 'Layer 1', NULL, 'SEI', 0xE30feDd158A2e3b13e9badaeABaFc5516e95e8C7, 'https://seitrace.com/?chain=pacific-1', timestamp '2024-05-27 13:14', NULL, NULL, NULL, true)
, (480, 'worldchain', 'World Chain', 'Layer 2', 'Optimistic Rollup', 'WLD', 0x2cFc85d8E48F8EAB294be644d9E25C3030863003, 'https://worldchain-mainnet.explorer.alchemy.com/', timestamp '2024-06-25 17:14', 'OP Stack', 'Ethereum Blobs', 'Ethereum', true)
, (480, 'worldchain', 'World Chain', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x4200000000000000000000000000000000000006, 'https://worldchain-mainnet.explorer.alchemy.com/', timestamp '2024-06-25 17:14', 'OP Stack', 'Ethereum Blobs', 'Ethereum', true)
, (728126428, 'tron', 'TRON', 'Layer 1', null, 'TRX', from_tron_address('TNUC9Qb1rRpS5CbWLmNMxXBjyFoydXjWFR'), 'https://tronscan.org/', timestamp '2024-06-25 17:14', NULL, NULL, NULL, true)
, (1101001, 'b3', 'B3', 'Layer 2', 'Optimistic Rollup', 'ETH', 0x4200000000000000000000000000000000000006, 'https://explorer.b3.fun/', timestamp '2024-03-14 12:00', 'OP Stack', 'Ethereum Blobs', 'Ethereum', true)
, (5000, 'mantle', 'Mantle', 'Layer 2', 'Optimistic Rollup', 'MNT', 0x78c1b0c915c4faa5fffa6cabf0219da63d7f4cb8, 'https://mantlescan.xyz/', timestamp '2023-07-02 18:21', 'Optimistic Virtual Machine', 'Ethereum', 'Ethereum', true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ with
transfer_combined as (
select * from {{ ref('nexusmutual_ethereum_capital_pool_transfers') }}
where block_time >= timestamp '2019-05-23'
and 1=1 -- dummy condition to trigger re-run
),

lido_oracle as (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ nexusmutual_contracts (contract_address) as (
(0x7cbe5682be6b648cc1100c76d4f6c96997f753d6), --Pool2, deployed: May-23-2019
(0xcafea8321b5109d22c53ac019d7a449c947701fb), --MCR, deployed: May-25-2021
(0xcafea92739e411a4D95bbc2275CA61dE6993C9a7), --MCR, deployed: Nov-21-2023
(0x51ad1265C8702c9e96Ea61Fe4088C2e22eD4418e) --Advisory Board multisig
(0x51ad1265C8702c9e96Ea61Fe4088C2e22eD4418e), --Advisory Board multisig
(0xcafeaed98d7Fce8F355C03c9F3507B90a974f37e) --SwapOperator
),

transfer_in as (
Expand Down Expand Up @@ -122,4 +123,3 @@ from transfer_nxmty_in
union all
select block_time, block_number, block_date, transfer_type, symbol, amount, contract_address, unique_key, tx_hash
from transfer_nxmty_out
where 1=1 -- dummy condition to trigger re-run
1 change: 1 addition & 0 deletions dbt_subprojects/dex/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ vars:
DBT_ENV_CUSTOM_ENV_S3_BUCKET: "{{ env_var('DBT_ENV_CUSTOM_ENV_S3_BUCKET', 'local') }}"
DBT_ENV_INCREMENTAL_TIME: "{{ env_var('DBT_ENV_INCREMENTAL_TIME', '1') }}"
DBT_ENV_INCREMENTAL_TIME_UNIT: "{{ env_var('DBT_ENV_INCREMENTAL_TIME_UNIT', 'day') }}"
ETH_ERC20_ADDRESS: '0x0000000000000000000000000000000000000000'

# These configurations specify where dbt should look for different types of files.
# You don't need to change these!
Expand Down
2 changes: 1 addition & 1 deletion dbt_subprojects/dex/macros/add_amount_usd.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WITH trusted_tokens AS (
, minute
, price
FROM
{{ source('prices','usd') }}
{{ source('prices','usd_with_native') }}
{% if is_incremental() %}
WHERE
{{ incremental_predicate('minute') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,87 @@ SELECT
, dexs.evt_index
FROM
dexs
{% endmacro %}

{% macro uniswap_compatible_v4_trades(
blockchain = null
, project = 'uniswap'
, version = '4'
, PoolManager_evt_Swap = null
, PoolManager_evt_Initialize = null
, taker_column_name = null
, maker_column_name = 'id'
, swap_optional_columns = ['fee']
, initialize_optional_columns = ['hooks']
, pair_column_name = 'id'
)
%}
WITH dexs AS
(
SELECT
t.evt_block_number AS block_number
, t.evt_block_time AS block_time
, {% if taker_column_name -%} t.{{ taker_column_name }} {% else -%} cast(null as varbinary) {% endif -%} as taker
-- In v4, the maker (i.e. what sold the token) is the pool's virtual address. We also pass the pool ID, making it easier to join with Initialize() and retrieve hooked pool metrics.
, {% if maker_column_name -%} t.{{ maker_column_name }} {% else -%} cast(null as varbinary) {% endif -%} as maker
-- in v4, when amount is negative, then user are selling the token (so things are done from the perspective of the user instead of the pool)
, CASE WHEN t.amount0 < INT256 '0' THEN abs(t.amount1) ELSE abs(t.amount0) END AS token_bought_amount_raw
, CASE WHEN t.amount0 < INT256 '0' THEN abs(t.amount0) ELSE abs(t.amount1) END AS token_sold_amount_raw
, CASE WHEN t.amount0 < INT256 '0' THEN f.currency1 ELSE f.currency0 END AS token_bought_address
, CASE WHEN t.amount0 < INT256 '0' THEN f.currency0 ELSE f.currency1 END AS token_sold_address
, t.contract_address as project_contract_address
, t.sender
, t.evt_tx_hash AS tx_hash
, t.evt_index
{%- if swap_optional_columns %}
{%- for optional_column in swap_optional_columns %}
, t.{{ optional_column }}
{%- endfor %}
{%- endif %}
{%- if initialize_optional_columns %}
{%- for optional_column in initialize_optional_columns %}
, f.{{ optional_column }}
{%- endfor %}
{%- endif %}
FROM
{{ PoolManager_evt_Swap }} t
INNER JOIN
{{ PoolManager_evt_Initialize }} f
ON f.{{ pair_column_name }} = t.id
{%- if is_incremental() %}
WHERE
{{ incremental_predicate('t.evt_block_time') }}
{%- endif %}
)

SELECT
{% if blockchain -%} '{{ blockchain }}' {% else -%} 'Unassigned' {% endif -%} as blockchain
, '{{ project }}' AS project
, '{{ version }}' 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
, CAST(dexs.token_bought_amount_raw AS UINT256) AS token_bought_amount_raw
, CAST(dexs.token_sold_amount_raw AS UINT256) AS token_sold_amount_raw
, dexs.token_bought_address
, dexs.token_sold_address
, dexs.sender as router
, dexs.taker
, dexs.maker
, dexs.project_contract_address
, dexs.tx_hash
, dexs.evt_index
{%- if swap_optional_columns %}
{%- for optional_column in swap_optional_columns %}
, dexs.{{ optional_column }}
{%- endfor %}
{%- endif %}
{%- if initialize_optional_columns %}
{%- for optional_column in initialize_optional_columns %}
, dexs.{{ optional_column }}
{%- endfor %}
{%- endif %}
FROM
dexs
{% endmacro %}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ WITH base_trades as (
{{ incremental_predicate('block_time') }}
{% endif %}
)
, tokens_metadata as (
--erc20 tokens
select
blockchain
, contract_address
, symbol
, decimals
from
{{ tokens_erc20_model }}
union all
--native tokens
select
blockchain
, {{var('ETH_ERC20_ADDRESS')}} as contract_address -- 0x00..00
, native_token_symbol as symbol
, 18 as decimals
from {{ source('evms','info') }}
)
, enrichments AS (
SELECT
base_trades.blockchain
Expand Down Expand Up @@ -48,11 +66,11 @@ WITH base_trades as (
FROM
base_trades
LEFT JOIN
{{ tokens_erc20_model }} as erc20_bought
tokens_metadata as erc20_bought
ON erc20_bought.contract_address = base_trades.token_bought_address
AND erc20_bought.blockchain = base_trades.blockchain
LEFT JOIN
{{ tokens_erc20_model }} as erc20_sold
tokens_metadata as erc20_sold
ON erc20_sold.contract_address = base_trades.token_sold_address
AND erc20_sold.blockchain = base_trades.blockchain
)
Expand Down
Loading

0 comments on commit 0b24f08

Please sign in to comment.