-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,649 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...projects/dex/models/_projects/balancer/pools/arbitrum/balancer_v3_arbitrum_pools_fees.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ | ||
config( | ||
schema = 'balancer_v3_arbitrum', | ||
alias = 'pools_fees', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], | ||
unique_key = ['block_number', 'tx_hash', 'index'] | ||
) | ||
}} | ||
|
||
SELECT | ||
'arbitrum' AS blockchain, | ||
'3' AS version, | ||
pool AS contract_address, | ||
evt_tx_hash AS tx_hash, | ||
evt_index AS tx_index, | ||
evt_index AS index, | ||
evt_block_time AS block_time, | ||
evt_block_number AS block_number, | ||
swapFeePercentage AS swap_fee_percentage | ||
FROM {{ source ('balancer_v3_arbitrum', 'Vault_evt_SwapFeePercentageChanged') }} | ||
WHERE 1 = 1 | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('evt_block_time') }} | ||
{% endif %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dbt_subprojects/dex/models/_projects/balancer/pools/base/balancer_v3_base_pools_fees.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{ | ||
config( | ||
schema = 'balancer_v3_base', | ||
alias = 'pools_fees', | ||
materialized = 'incremental', | ||
file_format = 'delta', | ||
incremental_strategy = 'merge', | ||
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')], | ||
unique_key = ['block_number', 'tx_hash', 'index'] | ||
) | ||
}} | ||
|
||
SELECT | ||
'base' AS blockchain, | ||
'3' AS version, | ||
pool AS contract_address, | ||
evt_tx_hash AS tx_hash, | ||
evt_index AS tx_index, | ||
evt_index AS index, | ||
evt_block_time AS block_time, | ||
evt_block_number AS block_number, | ||
swapFeePercentage AS swap_fee_percentage | ||
FROM {{ source ('balancer_v3_base', 'Vault_evt_SwapFeePercentageChanged') }} | ||
WHERE 1 = 1 | ||
{% if is_incremental() %} | ||
AND {{ incremental_predicate('evt_block_time') }} | ||
{% endif %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
...subprojects/dex/models/_projects/balancer/trades/arbitrum/balancer_v3_arbitrum_trades.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
{{ | ||
config( | ||
schema = 'balancer_v3_arbitrum', | ||
alias = 'trades', | ||
materialized = 'view', | ||
post_hook = '{{ expose_spells(\'["arbitrum"]\', | ||
spell_type = "project", | ||
spell_name = "balancer", | ||
contributors = \'["viniabussafi"]\') }}' | ||
) | ||
}} | ||
|
||
WITH | ||
dexs_arbitrum AS ( | ||
SELECT | ||
tx_hash, | ||
evt_index, | ||
pool_id, | ||
swap_fee, | ||
pool_symbol, | ||
pool_type | ||
FROM {{ ref('balancer_v3_arbitrum_base_trades') }} | ||
), | ||
|
||
dexs AS ( | ||
SELECT | ||
dexs.blockchain, | ||
dexs.project, | ||
dexs.version, | ||
dexs.block_month, | ||
dexs.block_date, | ||
dexs.block_time, | ||
dexs.block_number, | ||
dexs.token_bought_symbol, | ||
dexs.token_sold_symbol, | ||
dexs.token_pair, | ||
dexs.token_bought_amount, | ||
dexs.token_sold_amount, | ||
dexs.token_bought_amount_raw, | ||
dexs.token_sold_amount_raw, | ||
dexs.amount_usd, | ||
dexs.token_bought_address, | ||
dexs.token_sold_address, | ||
dexs.taker, | ||
dexs.maker, | ||
dexs.project_contract_address, | ||
dexs.tx_hash, | ||
dexs.tx_from, | ||
dexs.tx_to, | ||
dexs.evt_index, | ||
dexs_arbitrum.pool_id, | ||
dexs_arbitrum.swap_fee, | ||
dexs_arbitrum.pool_symbol, | ||
dexs_arbitrum.pool_type | ||
FROM {{ ref('dex_trades') }} dexs | ||
INNER JOIN dexs_arbitrum | ||
ON dexs.tx_hash = dexs_arbitrum.tx_hash | ||
AND dexs.evt_index = dexs_arbitrum.evt_index | ||
WHERE dexs.blockchain = 'arbitrum' | ||
AND dexs.project = 'balancer' | ||
AND dexs.version = '3' | ||
), | ||
|
||
bpa AS ( | ||
SELECT | ||
dexs.block_number, | ||
dexs.tx_hash, | ||
dexs.evt_index, | ||
bpt_prices.contract_address, | ||
dexs.block_time, | ||
MAX(bpt_prices.day) AS bpa_max_block_date | ||
FROM dexs | ||
LEFT JOIN {{ source('balancer', 'bpt_prices') }} bpt_prices | ||
ON bpt_prices.contract_address = dexs.token_bought_address | ||
AND bpt_prices.day <= DATE_TRUNC('day', dexs.block_time) | ||
AND bpt_prices.blockchain = 'arbitrum' | ||
GROUP BY 1, 2, 3, 4, 5 | ||
), | ||
|
||
bpb AS ( | ||
SELECT | ||
dexs.block_number, | ||
dexs.tx_hash, | ||
dexs.evt_index, | ||
bpt_prices.contract_address, | ||
dexs.block_time, | ||
MAX(bpt_prices.day) AS bpb_max_block_date | ||
FROM dexs | ||
LEFT JOIN {{ source('balancer', 'bpt_prices') }} bpt_prices | ||
ON bpt_prices.contract_address = dexs.token_sold_address | ||
AND bpt_prices.day <= DATE_TRUNC('day', dexs.block_time) | ||
AND bpt_prices.blockchain = 'arbitrum' | ||
GROUP BY 1, 2, 3, 4, 5 | ||
), | ||
|
||
erc4626_prices AS( | ||
SELECT | ||
minute, | ||
wrapped_token, | ||
decimals, | ||
APPROX_PERCENTILE(median_price, 0.5) AS price, | ||
LEAD(minute, 1, NOW()) OVER (PARTITION BY wrapped_token ORDER BY minute) AS time_of_next_change | ||
FROM {{ source('balancer_v3', 'erc4626_token_prices') }} | ||
WHERE blockchain = 'arbitrum' | ||
GROUP BY 1, 2, 3 | ||
) | ||
|
||
SELECT | ||
dexs.blockchain, | ||
dexs.project, | ||
dexs.version, | ||
dexs.block_date, | ||
dexs.block_number, | ||
dexs.block_month, | ||
dexs.block_time, | ||
dexs.token_bought_symbol, | ||
dexs.token_sold_symbol, | ||
dexs.token_pair, | ||
dexs.token_bought_amount, | ||
dexs.token_sold_amount, | ||
dexs.token_bought_amount_raw, | ||
dexs.token_sold_amount_raw, | ||
COALESCE( | ||
dexs.amount_usd, | ||
dexs.token_bought_amount_raw / POWER(10, COALESCE(erc20a.decimals, erc4626a.decimals, 18)) * COALESCE(bpa_bpt_prices.bpt_price, erc4626a.price), | ||
dexs.token_sold_amount_raw / POWER(10, COALESCE(erc20b.decimals, erc4626b.decimals, 18)) * COALESCE(bpb_bpt_prices.bpt_price, erc4626b.price) | ||
) AS amount_usd, | ||
dexs.token_bought_address, | ||
dexs.token_sold_address, | ||
dexs.taker, | ||
dexs.maker, | ||
dexs.project_contract_address, | ||
dexs.pool_id, | ||
dexs.swap_fee, | ||
dexs.pool_symbol, | ||
dexs.pool_type, | ||
dexs.tx_hash, | ||
dexs.tx_from, | ||
dexs.tx_to, | ||
dexs.evt_index | ||
FROM dexs | ||
LEFT JOIN {{ source('tokens', 'erc20') }} erc20a | ||
ON erc20a.contract_address = dexs.token_bought_address | ||
AND erc20a.blockchain = dexs.blockchain | ||
LEFT JOIN {{ source('tokens', 'erc20') }} erc20b | ||
ON erc20b.contract_address = dexs.token_sold_address | ||
AND erc20b.blockchain = dexs.blockchain | ||
INNER JOIN bpa | ||
ON bpa.block_number = dexs.block_number | ||
AND bpa.tx_hash = dexs.tx_hash | ||
AND bpa.evt_index = dexs.evt_index | ||
LEFT JOIN {{ source('balancer', 'bpt_prices') }} bpa_bpt_prices | ||
ON bpa_bpt_prices.contract_address = bpa.contract_address | ||
AND bpa_bpt_prices.day = bpa.bpa_max_block_date | ||
AND bpa_bpt_prices.blockchain = 'arbitrum' | ||
INNER JOIN bpb | ||
ON bpb.block_number = dexs.block_number | ||
AND bpb.tx_hash = dexs.tx_hash | ||
AND bpb.evt_index = dexs.evt_index | ||
LEFT JOIN {{ source('balancer', 'bpt_prices') }} bpb_bpt_prices | ||
ON bpb_bpt_prices.contract_address = bpb.contract_address | ||
AND bpb_bpt_prices.day = bpb.bpb_max_block_date | ||
AND bpb_bpt_prices.blockchain = 'arbitrum' | ||
LEFT JOIN erc4626_prices erc4626a | ||
ON erc4626a.wrapped_token = dexs.token_bought_address | ||
AND erc4626a.minute <= dexs.block_time | ||
AND dexs.block_time < erc4626a.time_of_next_change | ||
LEFT JOIN erc4626_prices erc4626b | ||
ON erc4626b.wrapped_token = dexs.token_sold_address | ||
AND erc4626b.minute <= dexs.block_time | ||
AND dexs.block_time < erc4626b.time_of_next_change |
Oops, something went wrong.