-
Notifications
You must be signed in to change notification settings - Fork 16
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
14 changed files
with
303 additions
and
54 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
102 changes: 102 additions & 0 deletions
102
...uniswap_v2_ethereum_mainnet/analytics__protocol_uniswap_v2_ethereum_mainnet__deposits.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,102 @@ | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
alias = 'DEPOSITS', | ||
unique_key='ID', | ||
) | ||
}} | ||
|
||
WITH pools as ( | ||
SELECT | ||
pair AS id | ||
, '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f' AS protocol__id | ||
, token0 | ||
, token1 | ||
FROM factory_pair_created | ||
) | ||
|
||
, mint_evts AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, evt_address as contract_address | ||
, pools.protocol__id | ||
, pools.token0 | ||
, pools.token1 | ||
, sender | ||
, amount0 | ||
, amount1 | ||
, evt_block_number as block_number | ||
, evt_block_time as block_timestamp | ||
, DATE_TRUNC('hour', evt_block_time) AS HOUR | ||
FROM pools_mint mint | ||
INNER JOIN pools ON mint.evt_address = pools.id | ||
) | ||
|
||
, sync AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, reserve0 | ||
, reserve1 | ||
FROM pools_sync sync | ||
) | ||
|
||
, mint_transfers AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, "to" | ||
, value as liquidity | ||
FROM pools_transfer t | ||
WHERE "from" = '0000000000000000000000000000000000000000' | ||
) | ||
|
||
, most_cols AS ( | ||
SELECT | ||
'DEPOSIT-' || m.transaction_hash || '-' || m.log_index AS id | ||
, m.transaction_hash as hash | ||
, m.log_index | ||
, p.protocol__id | ||
, t."to" as "to" | ||
, sender AS "from" | ||
, m.block_number | ||
, m.block_timestamp AS timestamp | ||
, m.contract_address AS pool__id | ||
, ARRAY[p.token0, p.token1] AS input_tokens | ||
, m.contract_address as output_token__id | ||
, ARRAY[amount0, amount1] AS input_token_amounts | ||
, t.liquidity AS output_token_amount | ||
, ARRAY[s.reserve0, s.reserve1] as reserve_amounts | ||
|
||
-- TODO: | ||
, 0 AS _amount0_usd | ||
, 0 AS _amount1_usd | ||
, 0 AS amount_usd | ||
FROM mint_evts m | ||
INNER JOIN pools p ON m.contract_address = p.id | ||
LEFT JOIN sync s ON m.transaction_hash = s.transaction_hash AND m.log_index = s.log_index + 1 | ||
LEFT JOIN mint_transfers t ON m.transaction_hash = t.transaction_hash AND m.log_index = t.log_index + 2 | ||
) | ||
|
||
, final AS ( | ||
SELECT | ||
id | ||
, hash | ||
, log_index | ||
, protocol__id | ||
, "to" | ||
, "from" | ||
, block_number | ||
, timestamp | ||
, input_tokens | ||
, output_token__id | ||
, input_token_amounts | ||
, output_token_amount | ||
, reserve_amounts | ||
, amount_usd | ||
, pool__id | ||
FROM most_cols | ||
) | ||
|
||
SELECT * FROM final |
86 changes: 86 additions & 0 deletions
86
...ol_uniswap_v2_ethereum_mainnet/analytics__protocol_uniswap_v2_ethereum_mainnet__swaps.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,86 @@ | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
alias = 'SWAPS', | ||
unique_key='ID', | ||
) | ||
}} | ||
|
||
WITH pools as ( | ||
SELECT | ||
pair AS id | ||
, '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f' AS protocol__id | ||
, token0 | ||
, token1 | ||
FROM factory_pair_created | ||
) | ||
|
||
, swap_evts AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, evt_address as contract_address | ||
, pools.protocol__id | ||
, pools.token0 | ||
, pools.token1 | ||
, "to" | ||
, sender | ||
, amount0_in | ||
, amount0_out | ||
, amount1_in | ||
, amount1_out | ||
, evt_block_number as block_number | ||
, evt_block_time as block_timestamp | ||
, DATE_TRUNC('hour', evt_block_time) AS HOUR | ||
FROM pools_swap swap | ||
INNER JOIN pools ON swap.evt_address = pools.id | ||
) | ||
|
||
, sync AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, reserve0 | ||
, reserve1 | ||
FROM pools_sync sync | ||
) | ||
|
||
, final AS ( | ||
SELECT | ||
'SWAP-' || s.transaction_hash || '-' || s.log_index AS id | ||
, s.transaction_hash as hash | ||
, s.log_index | ||
, p.protocol__id | ||
, s."to" AS "to" | ||
, sender AS "from" | ||
, s.block_number | ||
, s.block_timestamp AS timestamp | ||
|
||
, CASE | ||
WHEN amount0_in > 0 THEN p.token0 | ||
ELSE p.token1 | ||
END AS token_in__id | ||
, CASE | ||
WHEN amount0_in > 0 THEN amount0_in | ||
ELSE amount1_in | ||
END AS amount_in | ||
, 0 AS amount_in_usd | ||
|
||
, CASE | ||
WHEN amount0_in > 0 THEN p.token1 | ||
ELSE p.token0 | ||
END AS token_out__id | ||
, CASE | ||
WHEN amount0_in > 0 THEN amount1_out | ||
ELSE amount0_out | ||
END AS amount_out | ||
, 0 AS amount_out_usd | ||
|
||
, ARRAY[sync.reserve0, sync.reserve1] as reserve_amounts | ||
, s.contract_address AS pool__id | ||
FROM swap_evts s | ||
INNER JOIN pools p ON s.contract_address = p.id | ||
LEFT JOIN sync ON s.transaction_hash = sync.transaction_hash AND s.log_index = sync.log_index + 1 | ||
) | ||
|
||
SELECT * FROM final |
115 changes: 115 additions & 0 deletions
115
...niswap_v2_ethereum_mainnet/analytics__protocol_uniswap_v2_ethereum_mainnet__withdraws.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,115 @@ | ||
{{ | ||
config( | ||
materialized = 'incremental', | ||
alias = 'WITHDRAWS', | ||
unique_key='ID', | ||
) | ||
}} | ||
|
||
WITH pools as ( | ||
SELECT | ||
pair AS id | ||
, '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f' AS protocol__id | ||
, token0 | ||
, token1 | ||
FROM factory_pair_created | ||
) | ||
|
||
, burn_evts AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, evt_address as contract_address | ||
, pools.protocol__id | ||
, pools.token0 | ||
, pools.token1 | ||
, sender | ||
, amount0 | ||
, amount1 | ||
, evt_block_number as block_number | ||
, evt_block_time as block_timestamp | ||
, DATE_TRUNC('hour', evt_block_time) AS HOUR | ||
FROM pools_burn burn | ||
INNER JOIN pools ON burn.evt_address = pools.id | ||
) | ||
|
||
, sync AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, reserve0 | ||
, reserve1 | ||
FROM pools_sync sync | ||
) | ||
|
||
, transfers AS ( | ||
SELECT | ||
evt_tx_hash as transaction_hash | ||
, evt_index as log_index | ||
, evt_address as contract_address | ||
, "from" | ||
, value as liquidity | ||
FROM pools_transfer t | ||
WHERE "to" = '0000000000000000000000000000000000000000' | ||
) | ||
|
||
, burn_transfer AS ( | ||
SELECT | ||
b.transaction_hash, | ||
b.log_index, | ||
t.liquidity | ||
FROM burn_evts b | ||
INNER JOIN transfers t | ||
ON b.transaction_hash = t.transaction_hash | ||
AND b.log_index > t.log_index | ||
AND b.contract_address = t.contract_address | ||
) | ||
|
||
, most_cols AS ( | ||
SELECT | ||
'WITHDRAW-' || b.transaction_hash || '-' || b.log_index AS id | ||
, b.transaction_hash as hash | ||
, b.log_index | ||
, p.protocol__id | ||
, b.sender AS "to" | ||
, b.contract_address as "from" | ||
, b.block_number | ||
, b.block_timestamp AS timestamp | ||
, b.contract_address AS pool__id | ||
, ARRAY[p.token0, p.token1] AS input_tokens | ||
, b.contract_address as output_token__id | ||
, ARRAY[amount0, amount1] AS input_token_amounts | ||
, t.liquidity AS output_token_amount | ||
, ARRAY[s.reserve0, s.reserve1] as reserve_amounts | ||
|
||
-- TODO: | ||
, 0 AS _amount0_usd | ||
, 0 AS _amount1_usd | ||
, 0 AS amount_usd | ||
FROM burn_evts b | ||
INNER JOIN pools p ON b.contract_address = p.id | ||
LEFT JOIN sync s ON b.transaction_hash = s.transaction_hash AND b.log_index = s.log_index + 1 | ||
LEFT JOIN burn_transfer t ON b.transaction_hash = t.transaction_hash AND b.log_index = t.log_index | ||
) | ||
|
||
, final AS ( | ||
SELECT | ||
id | ||
, hash | ||
, log_index | ||
, protocol__id | ||
, "to" | ||
, "from" | ||
, block_number | ||
, timestamp | ||
, input_tokens | ||
, output_token__id | ||
, input_token_amounts | ||
, output_token_amount | ||
, reserve_amounts | ||
, amount_usd | ||
, pool__id | ||
FROM most_cols | ||
) | ||
|
||
SELECT * FROM final |
27 changes: 0 additions & 27 deletions
27
sql/dbt/projects/protocol_uniswap_v2_ethereum_mainnet/models/example/my_first_dbt_model.sql
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
sql/dbt/projects/protocol_uniswap_v2_ethereum_mainnet/models/example/my_second_dbt_model.sql
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
sql/dbt/projects/protocol_uniswap_v2_ethereum_mainnet/models/example/schema.yml
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.