From 20bd39e3f1f3c17259673cd6c923bad3da10f239 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Tue, 3 Dec 2024 13:00:19 +0000
Subject: [PATCH 01/10] tmp: version generated file for future comparison
---
.../_projects/paraswap/paraswap_fees.sql | 669 ++++++++++++++++++
1 file changed, 669 insertions(+)
create mode 100644 dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
new file mode 100644
index 00000000000..4d59492e914
--- /dev/null
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -0,0 +1,669 @@
+--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
+
+with fee_claim_detail as (
+ select 'arbitrum' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
+ when _token = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from arbitrum.transactions t
+ join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'arbitrum' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from arbitrum.transactions tr
+ join arbitrum.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from avalanche_c.transactions t
+ join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 as token_address,
+ t.value as fee_raw
+ from avalanche_c.transactions tr
+ join avalanche_c.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'bnb' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'bnb' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from bnb.transactions t
+ join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'bnb' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c as token_address,
+ t.value as fee_raw
+ from bnb.transactions tr
+ join bnb.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'ethereum' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'ethereum' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from ethereum.transactions t
+ join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'ethereum' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
+ t.value as fee_raw
+ from ethereum.transactions tr
+ join ethereum.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'fantom' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'fantom' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from fantom.transactions t
+ join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'fantom' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 as token_address,
+ t.value as fee_raw
+ from fantom.transactions tr
+ join fantom.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'optimism' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x4200000000000000000000000000000000000006 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'optimism' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from optimism.transactions t
+ join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'optimism' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x4200000000000000000000000000000000000006 as token_address,
+ t.value as fee_raw
+ from optimism.transactions tr
+ join optimism.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
+
+ select 'polygon' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'polygon' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from polygon.transactions t
+ join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
+
+ union all
+
+ select 'polygon' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 as token_address,
+ t.value as fee_raw
+ from polygon.transactions tr
+ join polygon.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+),
+
+price_list as (
+ select date_trunc('day', minute) as block_date,
+ blockchain,
+ contract_address,
+ avg(price) as price
+ from prices.usd
+ where minute >= date('2021-04-01')
+ group by 1, 2, 3
+)
+
+select e.epoch_num as en,
+ f.blockchain as bc,
+ f.block_date as bd,
+ f.block_time as bt,
+ f.call_block_number as bn,
+ f.call_tx_hash as th,
+ f.user_address as ua,
+ f.token_address as ta,
+ k.symbol as erc20,
+ f.fee_raw,
+ mt.raw_price as rp,
+ p.price as p,
+ --f.fee_raw / power(10, k.decimals) * p.price as fa,
+ case when f.blockchain = 'polygon' and f.call_tx_hash in (0xc9d07af12ad163cb41b73209a30899c7e712e5ec02c0b7e01e8663c783623592) then 0 -- Skip tx for avoid price impact
+ when f.blockchain = 'bnb' and f.token_address in (
+ 0xf7659cfe53cf2c1135857a17bf491c945fa8b44d
+ ) then 0 -- Avoid price impact
+ when k.decimals is not null and coalesce(p.price, 0) > 0 then f.fee_raw / power(10, k.decimals) * p.price
+ when sc.decimals is not null then f.fee_raw / power(10, sc.decimals) * sc.price
+ when mt.raw_price > 0 then f.fee_raw * mt.raw_price
+ else f.fee_raw / power(10, usc.decimals) * usc.price end as fa
+from fee_claim_detail f
+inner join query_2634288 e on f.block_time >= e.epoch_start_date
+ and f.block_time <= e.epoch_end_date -- Epoch by timestamp
+left join tokens.erc20 k on f.blockchain = k.blockchain and f.token_address = k.contract_address
+left join price_list p on f.token_address = p.contract_address and f.blockchain = p.blockchain and f.block_date = p.block_date
+left join query_2742198 sc on f.token_address = sc.contract and f.blockchain = sc.blockchain -- stablecoins
+left join dune.sixdegree.result_para_token_price_on_dex mt on f.token_address = mt.token_address
+ and f.blockchain = mt.blockchain
+ and f.block_date = mt.block_date
+left join query_2743935 usc on f.token_address = usc.contract and f.blockchain = usc.blockchain -- unstable coins
\ No newline at end of file
From 31eac0f18a2900bb056aeb3b5081a92d9e93424c Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Tue, 3 Dec 2024 13:05:09 +0000
Subject: [PATCH 02/10] transfer changes implemented in other repo to this repo
---
.../_projects/paraswap/paraswap_fees.sql | 249 ++++++++++++++---
.../_projects/paraswap/paraswap_fees.sql | 250 +++++++++++++++---
2 files changed, 432 insertions(+), 67 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index b552eae3a79..203b8b17f49 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,6 +1,145 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
with fee_claim_detail as (
+ --
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ WITH parsed_fee_data AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data
+ ),
+ exploded_data AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ address,
+ _token,
+ fee
+ FROM
+ unpacked_fee_data
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ )
+ SELECT
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'arbitrum' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from arbitrum.transactions t
+ join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from arbitrum.transactions tr
+ join arbitrum.traces t on
+ t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join arbitrum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
select 'arbitrum' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -16,8 +155,9 @@ with fee_claim_detail as (
union all
- -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
select 'arbitrum' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -31,28 +171,34 @@ with fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ -- I think the below conditional was pointless
+ -- and not exists (
+ -- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ -- where call_tx_hash = erc.evt_tx_hash
+ -- and call_block_number = erc.evt_block_number
+ -- )
union all
+ -- v5: ETH Transfer to SmartVault directly
select 'arbitrum' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -61,38 +207,40 @@ with fee_claim_detail as (
0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
t.value as fee_raw
from arbitrum.transactions tr
- join arbitrum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
+ join arbitrum.traces t on
+ t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
+ left join arbitrum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t2.trace_address > t.trace_address
and t2.type = 'call'
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
+ left join arbitrum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
and t3.type = 'call'
and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
+ and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
+ --
union all
select 'avalanche_c' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -108,6 +256,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'avalanche_c' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -142,6 +291,7 @@ with fee_claim_detail as (
union all
select 'avalanche_c' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -182,6 +332,7 @@ with fee_claim_detail as (
union all
select 'bnb' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -197,6 +348,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'bnb' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -231,6 +383,7 @@ with fee_claim_detail as (
union all
select 'bnb' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -267,25 +420,33 @@ with fee_claim_detail as (
where call_tx_hash = t.tx_hash
and call_block_number = t.block_number
)
-
+
union all
-
+
+ --
+ -- all registerFee calls on v5 Fee Claimer
select 'ethereum' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
call_tx_hash,
_account as user_address,
+ -- FeeClaimer_call_registerFee -> normalize native token to wrapped token
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
_fee as fee_raw
+
+ -- Paraswap v5 Fee Claimer: https://etherscan.io/address/0xef13101c5bbd737cfb2bf00bbd38c626ad6952f7#code
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
union all
- -- Transfer to SmartVault directly
+ -- Transfer to SmartVault directly, (because some v5 methods don't call registerFee, and the fee is sent from within Augustus? TODO: confirm it)
+ -- sample txs: 0x3a9a1a32cfa1e703d2a8e1b965ee9c23c399ba26ced608a03a5dbf4193a4af18, 0xa70e19c1756634556f3ff5bae570b695aac85dff7d5de86faec9ddef2c0ea6de, 0x956f1de15ce6eb7e1dfee9e46be6d4d4a9d7c5903c45b4b3228881ac8108be39
select 'ethereum' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -296,18 +457,22 @@ with fee_claim_detail as (
from ethereum.transactions t
join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
@@ -319,28 +484,35 @@ with fee_claim_detail as (
union all
+ -- ETH transfers / from augustus v5 to SmartVault v5 (i.e. direct calls to v5 SmartVault)
+ -- sample 0x63e9dc15061218a7f80eec244807151ab727cd3d79247d55698194043da8da40 (seen amongst internal txs on the explorer)
select 'ethereum' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
+ -- normalize to WETH
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and t2.trace_address > t.trace_address
and t2.type = 'call'
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -348,6 +520,8 @@ with fee_claim_detail as (
and t3.type = 'call'
and t3.call_type = 'call'
and t3.value > cast(0 as uint256)
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
@@ -356,10 +530,11 @@ with fee_claim_detail as (
where call_tx_hash = t.tx_hash
and call_block_number = t.block_number
)
-
+ --
union all
select 'fantom' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -375,6 +550,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'fantom' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -409,6 +585,7 @@ with fee_claim_detail as (
union all
select 'fantom' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -449,6 +626,7 @@ with fee_claim_detail as (
union all
select 'optimism' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -464,6 +642,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'optimism' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -498,6 +677,7 @@ with fee_claim_detail as (
union all
select 'optimism' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -538,6 +718,7 @@ with fee_claim_detail as (
union all
select 'polygon' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -553,6 +734,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'polygon' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -587,6 +769,7 @@ with fee_claim_detail as (
union all
select 'polygon' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index 4d59492e914..5520ad7155c 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,7 +1,145 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
-
with fee_claim_detail as (
+ --
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ WITH parsed_fee_data AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data
+ ),
+ exploded_data AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ address,
+ _token,
+ fee
+ FROM
+ unpacked_fee_data
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ )
+ SELECT
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'arbitrum' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from arbitrum.transactions t
+ join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
select 'arbitrum' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from arbitrum.transactions tr
+ join arbitrum.traces t on
+ t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join arbitrum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'arbitrum' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -17,8 +155,9 @@ with fee_claim_detail as (
union all
- -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
select 'arbitrum' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -32,28 +171,34 @@ with fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ -- I think the below conditional was pointless
+ -- and not exists (
+ -- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ -- where call_tx_hash = erc.evt_tx_hash
+ -- and call_block_number = erc.evt_block_number
+ -- )
union all
+ -- v5: ETH Transfer to SmartVault directly
select 'arbitrum' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -62,38 +207,40 @@ with fee_claim_detail as (
0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
t.value as fee_raw
from arbitrum.transactions tr
- join arbitrum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
+ join arbitrum.traces t on
+ t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
+ left join arbitrum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t2.trace_address > t.trace_address
and t2.type = 'call'
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
+ left join arbitrum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
and t3.type = 'call'
and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
+ and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
+ --
union all
select 'avalanche_c' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -109,6 +256,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'avalanche_c' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -143,6 +291,7 @@ with fee_claim_detail as (
union all
select 'avalanche_c' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -183,6 +332,7 @@ with fee_claim_detail as (
union all
select 'bnb' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -198,6 +348,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'bnb' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -232,6 +383,7 @@ with fee_claim_detail as (
union all
select 'bnb' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -268,25 +420,33 @@ with fee_claim_detail as (
where call_tx_hash = t.tx_hash
and call_block_number = t.block_number
)
-
+
union all
-
+
+ --
+ -- all registerFee calls on v5 Fee Claimer
select 'ethereum' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
call_tx_hash,
_account as user_address,
+ -- FeeClaimer_call_registerFee -> normalize native token to wrapped token
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
_fee as fee_raw
+
+ -- Paraswap v5 Fee Claimer: https://etherscan.io/address/0xef13101c5bbd737cfb2bf00bbd38c626ad6952f7#code
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
union all
- -- Transfer to SmartVault directly
+ -- Transfer to SmartVault directly, (because some v5 methods don't call registerFee, and the fee is sent from within Augustus? TODO: confirm it)
+ -- sample txs: 0x3a9a1a32cfa1e703d2a8e1b965ee9c23c399ba26ced608a03a5dbf4193a4af18, 0xa70e19c1756634556f3ff5bae570b695aac85dff7d5de86faec9ddef2c0ea6de, 0x956f1de15ce6eb7e1dfee9e46be6d4d4a9d7c5903c45b4b3228881ac8108be39
select 'ethereum' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -297,18 +457,22 @@ with fee_claim_detail as (
from ethereum.transactions t
join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
@@ -320,28 +484,35 @@ with fee_claim_detail as (
union all
+ -- ETH transfers / from augustus v5 to SmartVault v5 (i.e. direct calls to v5 SmartVault)
+ -- sample 0x63e9dc15061218a7f80eec244807151ab727cd3d79247d55698194043da8da40 (seen amongst internal txs on the explorer)
select 'ethereum' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
+ -- normalize to WETH
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
and t2.trace_address > t.trace_address
and t2.type = 'call'
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -349,6 +520,8 @@ with fee_claim_detail as (
and t3.type = 'call'
and t3.call_type = 'call'
and t3.value > cast(0 as uint256)
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
@@ -357,10 +530,11 @@ with fee_claim_detail as (
where call_tx_hash = t.tx_hash
and call_block_number = t.block_number
)
-
+ --
union all
select 'fantom' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -376,6 +550,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'fantom' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -410,6 +585,7 @@ with fee_claim_detail as (
union all
select 'fantom' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -450,6 +626,7 @@ with fee_claim_detail as (
union all
select 'optimism' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -465,6 +642,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'optimism' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -499,6 +677,7 @@ with fee_claim_detail as (
union all
select 'optimism' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
@@ -539,6 +718,7 @@ with fee_claim_detail as (
union all
select 'polygon' as blockchain,
+ 'registerFee-v5' as source,
date_trunc('day', call_block_time) as block_date,
call_block_time as block_time,
call_block_number,
@@ -554,6 +734,7 @@ with fee_claim_detail as (
-- Transfer to SmartVault directly
select 'polygon' as blockchain,
+ 'erc20-v5' as source,
date_trunc('day', erc.evt_block_time) as block_date,
erc.evt_block_time as block_time,
erc.evt_block_number as call_block_number,
@@ -588,6 +769,7 @@ with fee_claim_detail as (
union all
select 'polygon' as blockchain,
+ 'eth-v5' as source,
date_trunc('day', t.block_time) as block_date,
t.block_time as block_time,
t.block_number as call_block_number,
From af60b1cee93e2a7c26c5dc907755d1fdd00ece3e Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Wed, 4 Dec 2024 09:38:00 +0000
Subject: [PATCH 03/10] achieved state: paraswap_fees template generates
exactly the same SQL as the original [hand to view diff against tmp branch
with raw query]
---
.../_projects/paraswap/paraswap_fees.sql | 1017 +++---------
.../_projects/paraswap/paraswap_fees.sql | 1405 +++++++----------
2 files changed, 825 insertions(+), 1597 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index 203b8b17f49..59bb06f3ff3 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,813 +1,220 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
+{{ config(
+ schema='paraswap',
+ alias = 'fees',
+ post_hook='{{ expose_spells(\'["avalanche_c","fantom","arbitrum","bnb","ethereum","optimism","polygon","base"]\',
+ "project",
+ "paraswap",
+ \'["eptighte"]\') }}'
+ )
+}}{%
+
+set blockchains = [
+ 'arbitrum',
+ 'avalanche_c',
+ 'bnb',
+ 'ethereum',
+ 'fantom',
+ 'optimism',
+ 'polygon',
+]
+%}{%
+set blockchain_dependencies = {
+ 'nativeToken': '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
+ 'ethereum': {
+ 'registerFeesV6': 'paraswap_v6_ethereum.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_ethereum.FeeClaimer_call_registerFee',
+ 'transactions': 'ethereum.transactions',
+ 'traces': 'ethereum.traces',
+ 'erc20EvtTransfer': 'erc20_ethereum.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
+ },
+ 'arbitrum': {
+ 'registerFeesV6': 'paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_arbitrum.FeeClaimer_call_registerFee',
+ 'transactions': 'arbitrum.transactions',
+ 'traces': 'arbitrum.traces',
+ 'erc20EvtTransfer': 'erc20_arbitrum.evt_Transfer',
+ 'tokensToReplace': [
+ ['0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8', '-- aArbWETH']
+ ],
+ 'wrappedNative': '0x82af49447d8a07e3bd95bd0d56f35241523fbab1'
+ },
+ 'avalanche_c': {
+ 'registerFeesV6': 'paraswap_v6_avalanche_c.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_avalanche_c.FeeClaimer_call_registerFee',
+ 'transactions': 'avalanche_c.transactions',
+ 'traces': 'avalanche_c.traces',
+ 'erc20EvtTransfer': 'erc20_avalanche_c.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7'
+ },
+ 'bnb': {
+ 'registerFeesV6': 'paraswap_v6_bnb.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_bnb.FeeClaimer_call_registerFee',
+ 'transactions': 'bnb.transactions',
+ 'traces': 'bnb.traces',
+ 'erc20EvtTransfer': 'erc20_bnb.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'
+ },
+ 'fantom': {
+ 'registerFeesV6': 'paraswap_v6_fantom.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_fantom.FeeClaimer_call_registerFee',
+ 'transactions': 'fantom.transactions',
+ 'traces': 'fantom.traces',
+ 'erc20EvtTransfer': 'erc20_fantom.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83'
+ },
+ 'optimism': {
+ 'registerFeesV6': 'paraswap_v6_optimism.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_optimism.FeeClaimer_call_registerFee',
+ 'transactions': 'optimism.transactions',
+ 'traces': 'optimism.traces',
+ 'erc20EvtTransfer': 'erc20_optimism.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0x4200000000000000000000000000000000000006'
+ },
+ 'polygon': {
+ 'registerFeesV6': 'paraswap_v6_polygon.AugustusFeeVault_call_registerFees',
+ 'registerFeesV5': 'paraswap_polygon.FeeClaimer_call_registerFee',
+ 'transactions': 'polygon.transactions',
+ 'traces': 'polygon.traces',
+ 'erc20EvtTransfer': 'erc20_polygon.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
+ },
+ 'base': {
+ 'registerFeesV6': 'paraswap_v6_base.AugustusFeeVault_call_registerFees',
+ 'transactions': 'base.transactions',
+ 'traces': 'base.traces',
+ 'erc20EvtTransfer': 'erc20_base.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0x4200000000000000000000000000000000000006'
+ },
+ 'zkevm': {
+ 'registerFeesV6': 'paraswap_v6_zkevm.AugustusFeeVault_call_registerFees',
+ 'transactions': 'zkevm.transactions',
+ 'traces': 'zkevm.traces',
+ 'erc20EvtTransfer': 'erc20_zkevm.evt_Transfer',
+ 'tokensToReplace': [],
+ 'wrappedNative': '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9'
+ },
+}
+%}
with fee_claim_detail as (
- --
- --
- -- all registerFee calls on v6 Fee Claimer
- WITH parsed_fee_data AS (
- SELECT
- contract_address,
- call_success,
- call_tx_hash,
- call_trace_address,
- call_block_time,
- call_block_number,
- CAST(json_parse(feeData) AS MAP) AS fee_json
- FROM
- paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
- WHERE
- call_success = true
- ),
- unpacked_fee_data as (
- SELECT
- contract_address,
- call_success,
- call_tx_hash,
- call_trace_address,
- call_block_time,
- call_block_number,
- CAST(fee_json['addresses'] AS ARRAY) AS addresses,
- from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
- CAST(fee_json['fees'] AS ARRAY) AS fees
- FROM
- parsed_fee_data
- ),
- exploded_data AS (
- SELECT
- call_block_time,
+ {% for blockchain in blockchains %}
+ select '{{ blockchain }}' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
call_block_number,
- call_tx_hash,
- address,
- _token,
- fee
- FROM
- unpacked_fee_data
- CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
- )
- SELECT
- 'registerFee-v6' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time,
- call_block_number,
- call_tx_hash,
- address as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
- fee as fee_raw
- FROM
- exploded_data
-
- union all
- -- ERC20 transfer to v6 Depositor
- select 'arbitrum' as blockchain,
- 'erc20-v6' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else erc.contract_address end) as token_address,
- erc.value as fee_raw
- from arbitrum.transactions t
- join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
- -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
- and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
- -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
- and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
- -- v6: ETH Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'eth-v6' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
- t.value as fee_raw
- from arbitrum.transactions tr
- join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- -- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t2.tx_hash -- Other income for Depositor v6
- and tr.block_number = t2.block_number
- -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- --
- union all
-
- -- v5 fee claimer.registerFee
- select 'arbitrum' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
- when _token = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else _token end) as token_address,
- _fee as fee_raw
- from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- v5: ERC20 Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else erc.contract_address end) as token_address,
- erc.value as fee_raw
- from arbitrum.transactions t
- join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- I think the below conditional was pointless
- -- and not exists (
- -- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- -- where call_tx_hash = erc.evt_tx_hash
- -- and call_block_number = erc.evt_block_number
- -- )
-
- union all
-
- -- v5: ETH Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
- t.value as fee_raw
- from arbitrum.transactions tr
- join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- --
- union all
-
- select 'avalanche_c' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'avalanche_c' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from avalanche_c.transactions t
- join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'avalanche_c' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 as token_address,
- t.value as fee_raw
- from avalanche_c.transactions tr
- join avalanche_c.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
-
- select 'bnb' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c else _token end) as token_address,
- _fee as fee_raw
- from paraswap_bnb.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'bnb' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from bnb.transactions t
- join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'bnb' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c as token_address,
- t.value as fee_raw
- from bnb.transactions tr
- join bnb.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
-
- --
- -- all registerFee calls on v5 Fee Claimer
- select 'ethereum' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- -- FeeClaimer_call_registerFee -> normalize native token to wrapped token
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
- _fee as fee_raw
-
- -- Paraswap v5 Fee Claimer: https://etherscan.io/address/0xef13101c5bbd737cfb2bf00bbd38c626ad6952f7#code
- from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly, (because some v5 methods don't call registerFee, and the fee is sent from within Augustus? TODO: confirm it)
- -- sample txs: 0x3a9a1a32cfa1e703d2a8e1b965ee9c23c399ba26ced608a03a5dbf4193a4af18, 0xa70e19c1756634556f3ff5bae570b695aac85dff7d5de86faec9ddef2c0ea6de, 0x956f1de15ce6eb7e1dfee9e46be6d4d4a9d7c5903c45b4b3228881ac8108be39
- select 'ethereum' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from ethereum.transactions t
- join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- -- ETH transfers / from augustus v5 to SmartVault v5 (i.e. direct calls to v5 SmartVault)
- -- sample 0x63e9dc15061218a7f80eec244807151ab727cd3d79247d55698194043da8da40 (seen amongst internal txs on the explorer)
- select 'ethereum' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- -- normalize to WETH
- 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
- t.value as fee_raw
- from ethereum.transactions tr
- join ethereum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
- --
- union all
-
- select 'fantom' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_fantom.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'fantom' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from fantom.transactions t
- join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'fantom' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 as token_address,
- t.value as fee_raw
- from fantom.transactions tr
- join fantom.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
-
- select 'optimism' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x4200000000000000000000000000000000000006 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_optimism.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'optimism' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from optimism.transactions t
- join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'optimism' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x4200000000000000000000000000000000000006 as token_address,
- t.value as fee_raw
- from optimism.transactions tr
- join optimism.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
-
- select 'polygon' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_polygon.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'polygon' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from polygon.transactions t
- join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = {{ blockchain_dependencies.get('nativeToken') }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }}{%
+ if blockchain_dependencies[blockchain].get('tokensToReplace')|length != 0 %}{%
+ for tokenToReplace in blockchain_dependencies[blockchain].get('tokensToReplace') %}
+ when _token = {{ tokenToReplace[0] }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }} {{ tokenToReplace[1] }}{%
+ endfor %}
+ {%
+ endif %} else _token end) as token_address,
+ _fee as fee_raw
+ from {{ blockchain_dependencies[blockchain].get('registerFeesV5') }}
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select '{{ blockchain }}' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,{%
+ if blockchain_dependencies[blockchain].get('tokensToReplace')|length == 0 %}
+ erc.contract_address as token_address,{%
+ else
+ %}
+ (case {%
+ for
+ tokenToReplace in blockchain_dependencies[blockchain].get('tokensToReplace')
+ %}when erc.contract_address = {{ tokenToReplace[0] }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }} {{ tokenToReplace[1] }}{%
+ endfor %}
+ else erc.contract_address end) as token_address,{%
+ endif %}
+ erc.value as fee_raw
+ from {{ blockchain_dependencies[blockchain].get('transactions') }} t
+ join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_{{blockchain}}.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- select 'polygon' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 as token_address,
- t.value as fee_raw
- from polygon.transactions tr
- join polygon.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ union all
+
+ select '{{ blockchain }}' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ {{ blockchain_dependencies[blockchain].get('wrappedNative')}} as token_address,
+ t.value as fee_raw
+ from {{ blockchain_dependencies[blockchain].get('transactions') }} tr
+ join {{ blockchain_dependencies[blockchain].get('traces') }} t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join {{ blockchain_dependencies[blockchain].get('traces') }} t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join {{ blockchain_dependencies[blockchain].get('traces') }} t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_{{blockchain}}.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+ {%
+ if not loop.last %}
+ union all{%
+ endif %}
+ {% endfor %}
),
-
+
price_list as (
select date_trunc('day', minute) as block_date,
blockchain,
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index 5520ad7155c..382d6aca145 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,813 +1,634 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
+
with fee_claim_detail as (
- --
- --
- -- all registerFee calls on v6 Fee Claimer
- WITH parsed_fee_data AS (
- SELECT
- contract_address,
- call_success,
- call_tx_hash,
- call_trace_address,
- call_block_time,
- call_block_number,
- CAST(json_parse(feeData) AS MAP) AS fee_json
- FROM
- paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
- WHERE
- call_success = true
- ),
- unpacked_fee_data as (
- SELECT
- contract_address,
- call_success,
- call_tx_hash,
- call_trace_address,
- call_block_time,
- call_block_number,
- CAST(fee_json['addresses'] AS ARRAY) AS addresses,
- from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
- CAST(fee_json['fees'] AS ARRAY) AS fees
- FROM
- parsed_fee_data
- ),
- exploded_data AS (
- SELECT
- call_block_time,
- call_block_number,
- call_tx_hash,
- address,
- _token,
- fee
- FROM
- unpacked_fee_data
- CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
- )
- SELECT
- 'registerFee-v6' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time,
- call_block_number,
- call_tx_hash,
- address as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
- fee as fee_raw
- FROM
- exploded_data
- union all
- -- ERC20 transfer to v6 Depositor
- select 'arbitrum' as blockchain,
- 'erc20-v6' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else erc.contract_address end) as token_address,
- erc.value as fee_raw
- from arbitrum.transactions t
- join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
- -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
- and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
- -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
- and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
- -- v6: ETH Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'eth-v6' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
- t.value as fee_raw
- from arbitrum.transactions tr
- join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- -- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t2.tx_hash -- Other income for Depositor v6
- and tr.block_number = t2.block_number
- -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ select 'arbitrum' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
+ when _token = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from arbitrum.transactions t
+ join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- --
- union all
-
- -- v5 fee claimer.registerFee
- select 'arbitrum' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
- when _token = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else _token end) as token_address,
- _fee as fee_raw
- from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
+ union all
+
+ select 'arbitrum' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from arbitrum.transactions tr
+ join arbitrum.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- -- v5: ERC20 Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
- else erc.contract_address end) as token_address,
- erc.value as fee_raw
- from arbitrum.transactions t
- join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- I think the below conditional was pointless
- -- and not exists (
- -- select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- -- where call_tx_hash = erc.evt_tx_hash
- -- and call_block_number = erc.evt_block_number
- -- )
-
- union all
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from avalanche_c.transactions t
+ join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- -- v5: ETH Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
- t.value as fee_raw
- from arbitrum.transactions tr
- join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- --
- union all
+ union all
+
+ select 'avalanche_c' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 as token_address,
+ t.value as fee_raw
+ from avalanche_c.transactions tr
+ join avalanche_c.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- select 'avalanche_c' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'avalanche_c' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from avalanche_c.transactions t
- join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
+ select 'bnb' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'bnb' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from bnb.transactions t
+ join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- select 'avalanche_c' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 as token_address,
- t.value as fee_raw
- from avalanche_c.transactions tr
- join avalanche_c.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
+ union all
+
+ select 'bnb' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c as token_address,
+ t.value as fee_raw
+ from bnb.transactions tr
+ join bnb.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_bnb.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- select 'bnb' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c else _token end) as token_address,
- _fee as fee_raw
- from paraswap_bnb.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'bnb' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from bnb.transactions t
- join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'bnb' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c as token_address,
- t.value as fee_raw
- from bnb.transactions tr
- join bnb.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
-
- --
- -- all registerFee calls on v5 Fee Claimer
- select 'ethereum' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- -- FeeClaimer_call_registerFee -> normalize native token to wrapped token
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
- _fee as fee_raw
+ select 'ethereum' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'ethereum' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from ethereum.transactions t
+ join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- -- Paraswap v5 Fee Claimer: https://etherscan.io/address/0xef13101c5bbd737cfb2bf00bbd38c626ad6952f7#code
- from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ union all
+
+ select 'ethereum' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
+ t.value as fee_raw
+ from ethereum.transactions tr
+ join ethereum.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- union all
-
- -- Transfer to SmartVault directly, (because some v5 methods don't call registerFee, and the fee is sent from within Augustus? TODO: confirm it)
- -- sample txs: 0x3a9a1a32cfa1e703d2a8e1b965ee9c23c399ba26ced608a03a5dbf4193a4af18, 0xa70e19c1756634556f3ff5bae570b695aac85dff7d5de86faec9ddef2c0ea6de, 0x956f1de15ce6eb7e1dfee9e46be6d4d4a9d7c5903c45b4b3228881ac8108be39
- select 'ethereum' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from ethereum.transactions t
- join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- -- ETH transfers / from augustus v5 to SmartVault v5 (i.e. direct calls to v5 SmartVault)
- -- sample 0x63e9dc15061218a7f80eec244807151ab727cd3d79247d55698194043da8da40 (seen amongst internal txs on the explorer)
- select 'ethereum' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- -- normalize to WETH
- 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
- t.value as fee_raw
- from ethereum.transactions tr
- join ethereum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and t.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- If following transfers have outgoing only, exclude this revenue.
- left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- v5 Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- v5 SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ select 'fantom' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'fantom' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from fantom.transactions t
+ join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- -- not sure about the conditional below. Shouldn't be (erc2.evt_tx_hash is not null AND erc3.evt_tx_hash is null) ?
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
- --
- union all
+ union all
+
+ select 'fantom' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 as token_address,
+ t.value as fee_raw
+ from fantom.transactions tr
+ join fantom.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_fantom.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- select 'fantom' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_fantom.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'fantom' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from fantom.transactions t
- join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
+ select 'optimism' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x4200000000000000000000000000000000000006 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'optimism' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from optimism.transactions t
+ join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- select 'fantom' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 as token_address,
- t.value as fee_raw
- from fantom.transactions tr
- join fantom.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
+ union all
+
+ select 'optimism' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x4200000000000000000000000000000000000006 as token_address,
+ t.value as fee_raw
+ from optimism.transactions tr
+ join optimism.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_optimism.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
+ union all
- select 'optimism' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x4200000000000000000000000000000000000006 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_optimism.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'optimism' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from optimism.transactions t
- join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
+ select 'polygon' as blockchain,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ _account as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 else _token end) as token_address,
+ _fee as fee_raw
+ from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_success = true
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+
+ union all
+
+ -- Transfer to SmartVault directly
+ select 'polygon' as blockchain,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ erc.contract_address as token_address,
+ erc.value as fee_raw
+ from polygon.transactions t
+ join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- select 'optimism' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x4200000000000000000000000000000000000006 as token_address,
- t.value as fee_raw
- from optimism.transactions tr
- join optimism.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
-
- union all
+ union all
+
+ select 'polygon' as blockchain,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 as token_address,
+ t.value as fee_raw
+ from polygon.transactions tr
+ join polygon.traces t on tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
+ and not exists (
+ select 1 from paraswap_polygon.FeeClaimer_call_registerFee
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
+
- select 'polygon' as blockchain,
- 'registerFee-v5' as source,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
- call_tx_hash,
- _account as user_address,
- (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 else _token end) as token_address,
- _fee as fee_raw
- from paraswap_polygon.FeeClaimer_call_registerFee
- where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'polygon' as blockchain,
- 'erc20-v5' as source,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
- erc.evt_tx_hash as call_tx_hash,
- erc.to as user_address,
- erc.contract_address as token_address,
- erc.value as fee_raw
- from polygon.transactions t
- join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
- left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
-
- union all
-
- select 'polygon' as blockchain,
- 'eth-v5' as source,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
- t.tx_hash as call_tx_hash,
- t.to as user_address,
- 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 as token_address,
- t.value as fee_raw
- from polygon.transactions tr
- join polygon.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
- left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
- select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
),
-
+
price_list as (
select date_trunc('day', minute) as block_date,
blockchain,
From edc7b042ce8b6c26d7ca652bf74c659689d67d29 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Wed, 4 Dec 2024 20:34:25 +0000
Subject: [PATCH 04/10] add many features: - cutoff_date optimization in all
queries - v6 fees queries similar to v5 (but sent to depositors, not smart
vault) - sources: whether it's v5 or v6; and whether it's a smart vault or
depositor, and whether it's ETH or ERC20
---
.../_projects/paraswap/paraswap_fees.sql | 295 ++-
.../_projects/paraswap/paraswap_fees.sql | 1944 +++++++++++++----
2 files changed, 1728 insertions(+), 511 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index 59bb06f3ff3..c1d628ceffa 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -7,7 +7,14 @@
"paraswap",
\'["eptighte"]\') }}'
)
-}}{%
+}}
+-- old date: '2024-07-08 12:00'
+{%
+
+
+set cutoff_date = '2024-11-30 00:00'
+
+%}{%
set blockchains = [
'arbitrum',
@@ -104,12 +111,155 @@ set blockchain_dependencies = {
},
}
%}
-with fee_claim_detail as (
- {% for blockchain in blockchains %}
- select '{{ blockchain }}' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
+with
+{% for blockchain in blockchains %}
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_{{ blockchain }} AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_{{ blockchain }}.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_{{ blockchain }} as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_{{ blockchain }}
+ ),
+ exploded_data_{{ blockchain }} AS (
+ SELECT
+ call_block_time,
call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_{{ blockchain }}
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+{% endfor %}
+fee_claim_detail as (
+ {% for blockchain in blockchains %}
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select '{{ blockchain }}' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_{{ blockchain }}
+ where call_block_time >= TIMESTAMP '{{ cutoff_date }}'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select '{{ blockchain }}' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from {{ blockchain }}.transactions t
+ join erc20_{{ blockchain }}.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_{{ blockchain }}.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ left join erc20_{{ blockchain }}.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '{{ cutoff_date }}'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select '{{ blockchain }}' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from {{ blockchain }}.transactions tr
+ join {{ blockchain }}.traces t on
+ t.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join {{ blockchain }}.traces t2 on
+ t2.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join {{ blockchain }}.traces t3 on
+ t3.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '{{ cutoff_date }}'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select '{{ blockchain }}' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = {{ blockchain_dependencies.get('nativeToken') }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }}{%
@@ -122,15 +272,17 @@ with fee_claim_detail as (
_fee as fee_raw
from {{ blockchain_dependencies[blockchain].get('registerFeesV5') }}
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select '{{ blockchain }}' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '{{ cutoff_date }}'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select '{{ blockchain }}' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,{%
if blockchain_dependencies[blockchain].get('tokensToReplace')|length == 0 %}
@@ -147,67 +299,74 @@ with fee_claim_detail as (
erc.value as fee_raw
from {{ blockchain_dependencies[blockchain].get('transactions') }} t
join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ -- If following transfers have outgoing only, exclude this revenue.
left join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
left join {{ blockchain_dependencies[blockchain].get('erc20EvtTransfer') }} erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and not exists (
select 1 from paraswap_{{blockchain}}.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select '{{ blockchain }}' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select '{{ blockchain }}' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
{{ blockchain_dependencies[blockchain].get('wrappedNative')}} as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from {{ blockchain_dependencies[blockchain].get('transactions') }} tr
join {{ blockchain_dependencies[blockchain].get('traces') }} t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join {{ blockchain_dependencies[blockchain].get('traces') }} t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join {{ blockchain_dependencies[blockchain].get('traces') }} t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join {{ blockchain_dependencies[blockchain].get('traces') }} t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '{{ cutoff_date }}'
+ and not exists (
select 1 from paraswap_{{blockchain}}.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
{%
if not loop.last %}
union all{%
@@ -221,11 +380,13 @@ price_list as (
contract_address,
avg(price) as price
from prices.usd
- where minute >= date('2021-04-01')
+ where minute >= TIMESTAMP '{{ cutoff_date }}'
group by 1, 2, 3
)
-select e.epoch_num as en,
+select
+ f.source as source,
+ e.epoch_num as en,
f.blockchain as bc,
f.block_date as bd,
f.block_time as bt,
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index 382d6aca145..35eb3d690ce 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,11 +1,408 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
-with fee_claim_detail as (
-
- select 'arbitrum' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
+-- old date: '2024-07-08 12:00'
+
+with
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_arbitrum AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_arbitrum as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_arbitrum
+ ),
+ exploded_data_arbitrum AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_arbitrum
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_avalanche_c AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_avalanche_c.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_avalanche_c as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_avalanche_c
+ ),
+ exploded_data_avalanche_c AS (
+ SELECT
+ call_block_time,
call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_avalanche_c
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_bnb AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_bnb.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_bnb as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_bnb
+ ),
+ exploded_data_bnb AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_bnb
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_ethereum AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_ethereum.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_ethereum as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_ethereum
+ ),
+ exploded_data_ethereum AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_ethereum
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_fantom AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_fantom.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_fantom as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_fantom
+ ),
+ exploded_data_fantom AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_fantom
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_optimism AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_optimism.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_optimism as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_optimism
+ ),
+ exploded_data_optimism AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_optimism
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+ -- all registerFee calls on v6 Fee Claimer
+ parsed_fee_data_polygon AS (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(json_parse(feeData) AS MAP) AS fee_json
+ FROM
+ paraswap_v6_polygon.AugustusFeeVault_call_registerFees
+ WHERE
+ call_success = true
+ ),
+ unpacked_fee_data_polygon as (
+ SELECT
+ contract_address,
+ call_success,
+ call_tx_hash,
+ call_trace_address,
+ call_block_time,
+ call_block_number,
+ CAST(fee_json['addresses'] AS ARRAY) AS addresses,
+ from_hex(CAST(fee_json['token'] AS VARCHAR)) AS _token,
+ CAST(fee_json['fees'] AS ARRAY) AS fees
+ FROM
+ parsed_fee_data_polygon
+ ),
+ exploded_data_polygon AS (
+ SELECT
+ call_block_time,
+ call_block_number,
+ call_tx_hash,
+ from_hex(address) as "address",
+ _token,
+ fee
+ FROM
+ unpacked_fee_data_polygon
+ CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
+ ),
+
+fee_claim_detail as (
+
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'arbitrum' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_arbitrum
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'arbitrum' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from arbitrum.transactions t
+ join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from arbitrum.transactions tr
+ join arbitrum.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join arbitrum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'arbitrum' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1
@@ -14,15 +411,17 @@ with fee_claim_detail as (
_fee as fee_raw
from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'arbitrum' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
(case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
@@ -30,601 +429,1256 @@ with fee_claim_detail as (
erc.value as fee_raw
from arbitrum.transactions t
join erc20_arbitrum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'arbitrum' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'arbitrum' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'avalanche_c' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'avalanche_c' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_avalanche_c
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'avalanche_c' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from avalanche_c.transactions t
+ join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'avalanche_c' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from avalanche_c.transactions tr
+ join avalanche_c.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join avalanche_c.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join avalanche_c.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'avalanche_c' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 else _token end) as token_address,
_fee as fee_raw
from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'avalanche_c' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'avalanche_c' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from avalanche_c.transactions t
join erc20_avalanche_c.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'avalanche_c' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'avalanche_c' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'bnb' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'bnb' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_bnb
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'bnb' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from bnb.transactions t
+ join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'bnb' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from bnb.transactions tr
+ join bnb.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join bnb.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join bnb.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'bnb' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c else _token end) as token_address,
_fee as fee_raw
from paraswap_bnb.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'bnb' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'bnb' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from bnb.transactions t
join erc20_bnb.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'bnb' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'bnb' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'ethereum' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'ethereum' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_ethereum
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'ethereum' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from ethereum.transactions t
+ join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'ethereum' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from ethereum.transactions tr
+ join ethereum.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join ethereum.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join ethereum.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'ethereum' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else _token end) as token_address,
_fee as fee_raw
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'ethereum' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'ethereum' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from ethereum.transactions t
join erc20_ethereum.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'ethereum' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'ethereum' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'fantom' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'fantom' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_fantom
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'fantom' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from fantom.transactions t
+ join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'fantom' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from fantom.transactions tr
+ join fantom.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join fantom.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join fantom.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'fantom' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 else _token end) as token_address,
_fee as fee_raw
from paraswap_fantom.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'fantom' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'fantom' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from fantom.transactions t
join erc20_fantom.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'fantom' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'fantom' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'optimism' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'optimism' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_optimism
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'optimism' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from optimism.transactions t
+ join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'optimism' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from optimism.transactions tr
+ join optimism.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join optimism.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join optimism.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'optimism' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x4200000000000000000000000000000000000006 else _token end) as token_address,
_fee as fee_raw
from paraswap_optimism.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'optimism' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'optimism' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from optimism.transactions t
join erc20_optimism.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'optimism' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'optimism' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0x4200000000000000000000000000000000000006 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
union all
- select 'polygon' as blockchain,
- date_trunc('day', call_block_time) as block_date,
- call_block_time as block_time,
- call_block_number,
+ --
+ -- all registerFee calls on v6 Fee Claimer
+ select 'polygon' as blockchain,
+ 'registerFee-v6' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
+ call_tx_hash,
+ address as user_address,
+ (case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 else _token end) as token_address,
+ fee as fee_raw
+ FROM
+ exploded_data_polygon
+ where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- ERC20 transfer to v6 Depositor
+ select 'polygon' as blockchain,
+ 'erc20-v6' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
+ erc.evt_tx_hash as call_tx_hash,
+ erc.to as user_address,
+ (case when erc.contract_address = 0xe50fa9b3c56ffb159cb0fca61f5c9d750e8128c8 then 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 -- aArbWETH
+ else erc.contract_address end) as token_address,
+ erc.value as fee_raw
+ from polygon.transactions t
+ join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
+ and t.block_number = erc.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
+ and t.block_number = erc2.evt_block_number
+ -- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3 -- no need to restrict then
+ -- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
+ and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+ -- v6: ETH Transfer to SmartVault directly
+ select 'polygon' as blockchain,
+ 'eth-v6' as source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
+ t.tx_hash as call_tx_hash,
+ t.to as user_address,
+ 0x82af49447d8a07e3bd95bd0d56f35241523fbab1 as token_address,
+ t.value as fee_raw
+ from polygon.transactions tr
+ join polygon.traces t on
+ t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t.tx_hash
+ and tr.block_number = t.block_number
+ -- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join polygon.traces t2 on
+ t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t2.tx_hash -- Other income for Depositor v6
+ and tr.block_number = t2.block_number
+ -- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
+ left join polygon.traces t3 on
+ t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.hash = t3.tx_hash -- Outgoing
+ and tr.block_number = t3.block_number
+ and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ --
+ union all
+
+ -- v5 fee claimer.registerFee
+ select 'polygon' as blockchain,
+ 'registerFee-v5' as source,
+ date_trunc('day', call_block_time) as block_date,
+ call_block_time as block_time,
+ call_block_number,
call_tx_hash,
_account as user_address,
(case when _token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 else _token end) as token_address,
_fee as fee_raw
from paraswap_polygon.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
-
- union all
-
- -- Transfer to SmartVault directly
- select 'polygon' as blockchain,
- date_trunc('day', erc.evt_block_time) as block_date,
- erc.evt_block_time as block_time,
- erc.evt_block_number as call_block_number,
+ and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+
+ union all
+
+ -- Transfer to SmartVault directly
+ -- v5: ERC20 Transfer to SmartVault directly
+ select 'polygon' as blockchain,
+ 'erc20-v5' as source,
+ date_trunc('day', erc.evt_block_time) as block_date,
+ erc.evt_block_time as block_time,
+ erc.evt_block_number as call_block_number,
erc.evt_tx_hash as call_tx_hash,
erc.to as user_address,
erc.contract_address as token_address,
erc.value as fee_raw
from polygon.transactions t
join erc20_polygon.evt_Transfer erc on t.hash = erc.evt_tx_hash
- and t.block_number = erc.evt_block_number
- and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
+ and t.block_number = erc.evt_block_number
+ and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ -- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
- and t.block_number = erc2.evt_block_number
- and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc2.evt_index > erc.evt_index
+ and t.block_number = erc2.evt_block_number
+ and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc2.evt_index > erc.evt_index
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
- and t.block_number = erc3.evt_block_number
- and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc3.evt_index > erc.evt_index
- where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
- and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t.block_number = erc3.evt_block_number
+ and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and erc3.evt_index > erc.evt_index
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
+ and t.success
+ and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = erc.evt_tx_hash
- and call_block_number = erc.evt_block_number
- )
+ where call_tx_hash = erc.evt_tx_hash
+ and call_block_number = erc.evt_block_number
+ )
- union all
-
- select 'polygon' as blockchain,
- date_trunc('day', t.block_time) as block_date,
- t.block_time as block_time,
- t.block_number as call_block_number,
+ union all
+ -- v5: ETH Transfer to SmartVault directly
+ select 'polygon' as blockchain,
+ 'eth-v5' AS source,
+ date_trunc('day', t.block_time) as block_date,
+ t.block_time as block_time,
+ t.block_number as call_block_number,
t.tx_hash as call_tx_hash,
t.to as user_address,
0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270 as token_address,
- t.value as fee_raw
+ t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on tr.hash = t.tx_hash
- and tr.block_number = t.block_number
- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- -- If following transfers have outgoing only, exclude this revenue.
- left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and tr.block_number = t2.block_number
- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
- and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t2.trace_address > t.trace_address
- and t2.type = 'call'
- and t2.call_type = 'call'
- and t2.value > cast(0 as uint256)
+ and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t.block_number
+ and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ -- If following transfers have outgoing only, exclude this revenue.
+ left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
+ and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t2.block_number
+ and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
+ and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t2.trace_address > t.trace_address
+ and t2.type = 'call'
+ and t2.call_type = 'call'
+ and t2.value > cast(0 as uint256)
left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and tr.block_number = t3.block_number
- and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and t3.trace_address > t.trace_address
- and t3.type = 'call'
- and t3.call_type = 'call'
- and t3.value > cast(0 as uint256)
- where (t2.tx_hash is not null or t3.tx_hash is null)
- and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00' -- Start from Epoch 20
- and not exists (
+ and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_number = t3.block_number
+ and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
+ and t3.trace_address > t.trace_address
+ and t3.type = 'call'
+ and t3.call_type = 'call'
+ and t3.value > cast(0 as uint256)
+ where (t2.tx_hash is not null or t3.tx_hash is null)
+ and tr.success
+ and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
- where call_tx_hash = t.tx_hash
- and call_block_number = t.block_number
- )
+ where call_tx_hash = t.tx_hash
+ and call_block_number = t.block_number
+ )
),
@@ -635,11 +1689,13 @@ price_list as (
contract_address,
avg(price) as price
from prices.usd
- where minute >= date('2021-04-01')
+ where minute >= TIMESTAMP '2024-11-30 00:00'
group by 1, 2, 3
)
-select e.epoch_num as en,
+select
+ f.source as source,
+ e.epoch_num as en,
f.blockchain as bc,
f.block_date as bd,
f.block_time as bt,
From 9fb84c85db2fb06a5ded90fb2d79fa8b96e97cd3 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Wed, 4 Dec 2024 20:40:12 +0000
Subject: [PATCH 05/10] cutoff date to epoch 20
---
.../_projects/paraswap/paraswap_fees.sql | 4 +-
.../_projects/paraswap/paraswap_fees.sql | 256 +++++++++---------
2 files changed, 130 insertions(+), 130 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index c1d628ceffa..76538c10b87 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -8,11 +8,11 @@
\'["eptighte"]\') }}'
)
}}
--- old date: '2024-07-08 12:00'
+-- old date: '2024-07-08 12:00' -- start of epoch 20
{%
-set cutoff_date = '2024-11-30 00:00'
+set cutoff_date = '2024-07-08 12:00'
%}{%
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index 35eb3d690ce..8fbd756b2c3 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -1,6 +1,6 @@
--para-fee-details-with-epoch-v3 https://dune.com/queries/4257927
--- old date: '2024-07-08 12:00'
+-- old date: '2024-07-08 12:00' -- start of epoch 20
with
@@ -313,7 +313,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_arbitrum
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -333,7 +333,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -341,16 +341,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -365,14 +365,14 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -382,7 +382,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -392,7 +392,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -411,7 +411,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -432,22 +432,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -467,13 +467,13 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -482,7 +482,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -491,7 +491,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -513,7 +513,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_avalanche_c
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -533,7 +533,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -541,16 +541,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -565,14 +565,14 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -582,7 +582,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -592,7 +592,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -609,7 +609,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -629,22 +629,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -664,13 +664,13 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -679,7 +679,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -688,7 +688,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -710,7 +710,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_bnb
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -730,7 +730,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -738,16 +738,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -762,14 +762,14 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -779,7 +779,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -789,7 +789,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -806,7 +806,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_bnb.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -826,22 +826,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -861,13 +861,13 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -876,7 +876,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -885,7 +885,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -907,7 +907,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_ethereum
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -927,7 +927,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -935,16 +935,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -959,14 +959,14 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -976,7 +976,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -986,7 +986,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1003,7 +1003,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1023,22 +1023,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1058,13 +1058,13 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1073,7 +1073,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1082,7 +1082,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1104,7 +1104,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_fantom
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1124,7 +1124,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1132,16 +1132,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1156,14 +1156,14 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1173,7 +1173,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1183,7 +1183,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1200,7 +1200,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_fantom.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1220,22 +1220,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1255,13 +1255,13 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1270,7 +1270,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1279,7 +1279,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1301,7 +1301,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_optimism
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1321,7 +1321,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1329,16 +1329,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1353,14 +1353,14 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1370,7 +1370,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1380,7 +1380,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1397,7 +1397,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_optimism.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1417,22 +1417,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1452,13 +1452,13 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1467,7 +1467,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1476,7 +1476,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1498,7 +1498,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_polygon
- where call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1518,7 +1518,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1526,16 +1526,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1550,14 +1550,14 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1567,7 +1567,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1577,7 +1577,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1594,7 +1594,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_polygon.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1614,22 +1614,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 00:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 00:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1649,13 +1649,13 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1664,7 +1664,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1673,7 +1673,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 00:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1689,7 +1689,7 @@ price_list as (
contract_address,
avg(price) as price
from prices.usd
- where minute >= TIMESTAMP '2024-11-30 00:00'
+ where minute >= TIMESTAMP '2024-07-08 12:00'
group by 1, 2, 3
)
From ade9718bc056ac8ef6ea8cfe6762387d6049f1d6 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Thu, 5 Dec 2024 06:25:56 +0000
Subject: [PATCH 06/10] include delta paraswap (protocol revenue only for now)
-- took 19 min to index with cutoff date = '2024-11-30 12:00'
---
.../_projects/paraswap/paraswap_fees.sql | 41 ++-
.../_projects/paraswap/paraswap_fees.sql | 279 ++++++++++--------
2 files changed, 189 insertions(+), 131 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index 76538c10b87..0418ab871a4 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -35,7 +35,8 @@ set blockchain_dependencies = {
'traces': 'ethereum.traces',
'erc20EvtTransfer': 'erc20_ethereum.evt_Transfer',
'tokensToReplace': [],
- 'wrappedNative': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
+ 'wrappedNative': '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
+ 'delta_v2': '0x0000000000bbF5c5Fd284e657F01Bd000933C96D'
},
'arbitrum': {
'registerFeesV6': 'paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees',
@@ -99,7 +100,8 @@ set blockchain_dependencies = {
'traces': 'base.traces',
'erc20EvtTransfer': 'erc20_base.evt_Transfer',
'tokensToReplace': [],
- 'wrappedNative': '0x4200000000000000000000000000000000000006'
+ 'wrappedNative': '0x4200000000000000000000000000000000000006',
+ 'delta_v2': '0x0000000000bbF5c5Fd284e657F01Bd000933C96D'
},
'zkevm': {
'registerFeesV6': 'paraswap_v6_zkevm.AugustusFeeVault_call_registerFees',
@@ -112,7 +114,24 @@ set blockchain_dependencies = {
}
%}
with
-{% for blockchain in blockchains %}
+{% for blockchain in blockchains %}{%
+ if blockchain_dependencies[blockchain].get('delta_v2') %}
+ deltav2_fees_balances_raw_{{ blockchain }} as (
+ select
+ evt_block_time,
+ evt_block_number,
+ evt_tx_hash,
+ destToken as fee_token,
+ protocolFee,
+ partnerFee
+ from
+ paraswapdelta_{{ blockchain }}.ParaswapDeltav2_evt_OrderSettled as evt
+ {% if is_incremental() %}
+ WHERE
+ {{ incremental_predicate('evt_block_time') }}
+ {% endif %}
+ ),{%
+ endif %}
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_{{ blockchain }} AS (
SELECT
@@ -156,7 +175,21 @@ with
),
{% endfor %}
fee_claim_detail as (
- {% for blockchain in blockchains %}
+ {% for blockchain in blockchains %}{%
+ if blockchain_dependencies[blockchain].get('delta_v2') %}
+ select '{{ blockchain }}' as blockchain,
+ 'delta-v2' as source,
+ date_trunc('day', evt_block_time) as block_date,
+ evt_block_time as block_time,
+ evt_block_number as call_block_number,
+ evt_tx_hash as call_tx_hash,
+ {{ blockchain_dependencies[blockchain].get('delta_v2') }} as user_address,
+ (case when fee_token = {{ blockchain_dependencies.get('nativeToken') }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }} else fee_token end) as token_address,
+ protocolFee as fee_raw
+ from deltav2_fees_balances_raw_{{ blockchain }}
+ where evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ union all
+ {% endif %}
--
-- all registerFee calls on v6 Fee Claimer
select '{{ blockchain }}' as blockchain,
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index 8fbd756b2c3..a1cf36ee71e 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -130,6 +130,18 @@ with
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
+ deltav2_fees_balances_raw_ethereum as (
+ select
+ evt_block_time,
+ evt_block_number,
+ evt_tx_hash,
+ destToken as fee_token,
+ protocolFee,
+ partnerFee
+ from
+ paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled as evt
+
+ ),
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_ethereum AS (
SELECT
@@ -313,7 +325,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_arbitrum
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -333,7 +345,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -341,16 +353,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -365,14 +377,14 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -382,7 +394,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -392,7 +404,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -411,7 +423,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -432,22 +444,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -467,13 +479,13 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -482,7 +494,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -491,7 +503,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -513,7 +525,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_avalanche_c
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -533,7 +545,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -541,16 +553,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -565,14 +577,14 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -582,7 +594,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -592,7 +604,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -609,7 +621,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -629,22 +641,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -664,13 +676,13 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -679,7 +691,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -688,7 +700,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -710,7 +722,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_bnb
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -730,7 +742,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -738,16 +750,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -762,14 +774,14 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -779,7 +791,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -789,7 +801,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -806,7 +818,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_bnb.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -826,22 +838,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -861,13 +873,13 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -876,7 +888,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -885,7 +897,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -894,6 +906,19 @@ fee_claim_detail as (
union all
+ select 'ethereum' as blockchain,
+ 'delta-v2' as source,
+ date_trunc('day', evt_block_time) as block_date,
+ evt_block_time as block_time,
+ evt_block_number as call_block_number,
+ evt_tx_hash as call_tx_hash,
+ 0x0000000000bbF5c5Fd284e657F01Bd000933C96D as user_address,
+ (case when fee_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else fee_token end) as token_address,
+ protocolFee as fee_raw
+ from deltav2_fees_balances_raw_ethereum
+ where evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ union all
+
--
-- all registerFee calls on v6 Fee Claimer
select 'ethereum' as blockchain,
@@ -907,7 +932,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_ethereum
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -927,7 +952,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -935,16 +960,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -959,14 +984,14 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -976,7 +1001,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -986,7 +1011,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -1003,7 +1028,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -1023,22 +1048,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1058,13 +1083,13 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1073,7 +1098,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1082,7 +1107,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1104,7 +1129,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_fantom
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1124,7 +1149,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1132,16 +1157,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1156,14 +1181,14 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1173,7 +1198,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1183,7 +1208,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -1200,7 +1225,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_fantom.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -1220,22 +1245,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1255,13 +1280,13 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1270,7 +1295,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1279,7 +1304,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1301,7 +1326,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_optimism
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1321,7 +1346,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1329,16 +1354,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1353,14 +1378,14 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1370,7 +1395,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1380,7 +1405,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -1397,7 +1422,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_optimism.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -1417,22 +1442,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1452,13 +1477,13 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1467,7 +1492,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1476,7 +1501,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1498,7 +1523,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_polygon
- where call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ where call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1518,7 +1543,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1526,16 +1551,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1550,14 +1575,14 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on
- t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on
- t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1567,7 +1592,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on
- t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1577,7 +1602,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
--
union all
@@ -1594,7 +1619,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_polygon.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
@@ -1614,22 +1639,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-07-08 12:00'
+ and block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1649,13 +1674,13 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1664,7 +1689,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1673,7 +1698,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
+ and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1689,7 +1714,7 @@ price_list as (
contract_address,
avg(price) as price
from prices.usd
- where minute >= TIMESTAMP '2024-07-08 12:00'
+ where minute >= TIMESTAMP '2024-11-30 12:00'
group by 1, 2, 3
)
From f038a62ba5708b0e9b6b69cb3897fc32bd1f9e14 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Thu, 5 Dec 2024 06:41:12 +0000
Subject: [PATCH 07/10] add delta v2 partner fees. (took 2 minutes to index
with cutoff_date = '2024-11-30 12:00')
---
.../_projects/paraswap/paraswap_fees.sql | 32 +++++++++++---
.../_projects/paraswap/paraswap_fees.sql | 43 +++++++++++++++----
2 files changed, 59 insertions(+), 16 deletions(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
index 0418ab871a4..0ee500e8b2b 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -114,8 +114,9 @@ set blockchain_dependencies = {
}
%}
with
-{% for blockchain in blockchains %}{%
+{% for blockchain in blockchains %}{%
if blockchain_dependencies[blockchain].get('delta_v2') %}
+ -- delta v2 protocol's and partners revenue src data
deltav2_fees_balances_raw_{{ blockchain }} as (
select
evt_block_time,
@@ -125,13 +126,14 @@ with
protocolFee,
partnerFee
from
- paraswapdelta_{{ blockchain }}.ParaswapDeltav2_evt_OrderSettled as evt
- {% if is_incremental() %}
- WHERE
- {{ incremental_predicate('evt_block_time') }}
- {% endif %}
+ paraswapdelta_{{ blockchain }}.ParaswapDeltav2_evt_OrderSettled as evt
+ where
+ {% if is_incremental() %}
+ {{ incremental_predicate('evt_block_time') }} AND
+ {% endif %}
+ evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
),{%
- endif %}
+ endif %}
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_{{ blockchain }} AS (
SELECT
@@ -146,6 +148,7 @@ with
paraswap_v6_{{ blockchain }}.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '{{ cutoff_date }}'
),
unpacked_fee_data_{{ blockchain }} as (
SELECT
@@ -177,6 +180,7 @@ with
fee_claim_detail as (
{% for blockchain in blockchains %}{%
if blockchain_dependencies[blockchain].get('delta_v2') %}
+ -- delta v2 protocol's revenue
select '{{ blockchain }}' as blockchain,
'delta-v2' as source,
date_trunc('day', evt_block_time) as block_date,
@@ -189,6 +193,20 @@ fee_claim_detail as (
from deltav2_fees_balances_raw_{{ blockchain }}
where evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
union all
+ -- delta v2 partners revenue
+ select '{{ blockchain }}' as blockchain,
+ 'delta-v2' as source,
+ date_trunc('day', evt_block_time) as block_date,
+ evt_block_time as block_time,
+ evt_block_number as call_block_number,
+ evt_tx_hash as call_tx_hash,
+ -- TODO: not easy to extract partner address here, may need to find a way
+ 0x0000000000000000000000000000000000000000 as user_address,
+ (case when fee_token = {{ blockchain_dependencies.get('nativeToken') }} then {{ blockchain_dependencies[blockchain].get('wrappedNative') }} else fee_token end) as token_address,
+ partnerFee as fee_raw
+ from deltav2_fees_balances_raw_{{ blockchain }}
+ where evt_block_time >= TIMESTAMP '{{ cutoff_date }}'
+ union all
{% endif %}
--
-- all registerFee calls on v6 Fee Claimer
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index a1cf36ee71e..bca8d6fb004 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -3,7 +3,7 @@
-- old date: '2024-07-08 12:00' -- start of epoch 20
with
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_arbitrum AS (
SELECT
@@ -18,6 +18,7 @@ with
paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_arbitrum as (
SELECT
@@ -45,7 +46,7 @@ with
unpacked_fee_data_arbitrum
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_avalanche_c AS (
SELECT
@@ -60,6 +61,7 @@ with
paraswap_v6_avalanche_c.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_avalanche_c as (
SELECT
@@ -87,7 +89,7 @@ with
unpacked_fee_data_avalanche_c
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_bnb AS (
SELECT
@@ -102,6 +104,7 @@ with
paraswap_v6_bnb.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_bnb as (
SELECT
@@ -130,6 +133,7 @@ with
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
+ -- delta v2 protocol's and partners revenue src data
deltav2_fees_balances_raw_ethereum as (
select
evt_block_time,
@@ -139,9 +143,11 @@ with
protocolFee,
partnerFee
from
- paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled as evt
-
- ),
+ paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled as evt
+ where
+
+ evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ ),
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_ethereum AS (
SELECT
@@ -156,6 +162,7 @@ with
paraswap_v6_ethereum.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_ethereum as (
SELECT
@@ -183,7 +190,7 @@ with
unpacked_fee_data_ethereum
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_fantom AS (
SELECT
@@ -198,6 +205,7 @@ with
paraswap_v6_fantom.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_fantom as (
SELECT
@@ -225,7 +233,7 @@ with
unpacked_fee_data_fantom
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_optimism AS (
SELECT
@@ -240,6 +248,7 @@ with
paraswap_v6_optimism.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_optimism as (
SELECT
@@ -267,7 +276,7 @@ with
unpacked_fee_data_optimism
CROSS JOIN UNNEST(addresses, fees) AS t(address, fee)
),
-
+
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_polygon AS (
SELECT
@@ -282,6 +291,7 @@ with
paraswap_v6_polygon.AugustusFeeVault_call_registerFees
WHERE
call_success = true
+ and call_block_time >= TIMESTAMP '2024-11-30 12:00'
),
unpacked_fee_data_polygon as (
SELECT
@@ -906,6 +916,7 @@ fee_claim_detail as (
union all
+ -- delta v2 protocol's revenue
select 'ethereum' as blockchain,
'delta-v2' as source,
date_trunc('day', evt_block_time) as block_date,
@@ -918,6 +929,20 @@ fee_claim_detail as (
from deltav2_fees_balances_raw_ethereum
where evt_block_time >= TIMESTAMP '2024-11-30 12:00'
union all
+ -- delta v2 partners revenue
+ select 'ethereum' as blockchain,
+ 'delta-v2' as source,
+ date_trunc('day', evt_block_time) as block_date,
+ evt_block_time as block_time,
+ evt_block_number as call_block_number,
+ evt_tx_hash as call_tx_hash,
+ -- TODO: not easy to extract partner address here, may need to find a way
+ 0x0000000000000000000000000000000000000000 as user_address,
+ (case when fee_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else fee_token end) as token_address,
+ partnerFee as fee_raw
+ from deltav2_fees_balances_raw_ethereum
+ where evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ union all
--
-- all registerFee calls on v6 Fee Claimer
From b42b5cc0ee0c8e305f9318c49a5971456779eb48 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Thu, 5 Dec 2024 07:02:08 +0000
Subject: [PATCH 08/10] fix cutoff date
---
.../_projects/paraswap/paraswap_fees.sql | 274 +++++++++---------
1 file changed, 137 insertions(+), 137 deletions(-)
diff --git a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
index bca8d6fb004..0af9b741e68 100644
--- a/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
+++ b/dbt_subprojects/dex/target/compiled/dex/models/_projects/paraswap/paraswap_fees.sql
@@ -18,7 +18,7 @@ with
paraswap_v6_arbitrum.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_arbitrum as (
SELECT
@@ -61,7 +61,7 @@ with
paraswap_v6_avalanche_c.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_avalanche_c as (
SELECT
@@ -104,7 +104,7 @@ with
paraswap_v6_bnb.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_bnb as (
SELECT
@@ -146,7 +146,7 @@ with
paraswapdelta_ethereum.ParaswapDeltav2_evt_OrderSettled as evt
where
- evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ evt_block_time >= TIMESTAMP '2024-07-08 12:00'
),
-- all registerFee calls on v6 Fee Claimer
parsed_fee_data_ethereum AS (
@@ -162,7 +162,7 @@ with
paraswap_v6_ethereum.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_ethereum as (
SELECT
@@ -205,7 +205,7 @@ with
paraswap_v6_fantom.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_fantom as (
SELECT
@@ -248,7 +248,7 @@ with
paraswap_v6_optimism.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_optimism as (
SELECT
@@ -291,7 +291,7 @@ with
paraswap_v6_polygon.AugustusFeeVault_call_registerFees
WHERE
call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
),
unpacked_fee_data_polygon as (
SELECT
@@ -335,7 +335,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_arbitrum
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -355,7 +355,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -363,16 +363,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -387,14 +387,14 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -404,7 +404,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -414,7 +414,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -433,7 +433,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -454,22 +454,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_arbitrum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_arbitrum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -489,13 +489,13 @@ fee_claim_detail as (
t.value as fee_raw
from arbitrum.transactions tr
join arbitrum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join arbitrum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -504,7 +504,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join arbitrum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -513,7 +513,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_arbitrum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -535,7 +535,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_avalanche_c
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -555,7 +555,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -563,16 +563,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -587,14 +587,14 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -604,7 +604,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -614,7 +614,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -631,7 +631,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -651,22 +651,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_avalanche_c.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_avalanche_c.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -686,13 +686,13 @@ fee_claim_detail as (
t.value as fee_raw
from avalanche_c.transactions tr
join avalanche_c.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join avalanche_c.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -701,7 +701,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join avalanche_c.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -710,7 +710,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_avalanche_c.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -732,7 +732,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_bnb
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -752,7 +752,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -760,16 +760,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -784,14 +784,14 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -801,7 +801,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -811,7 +811,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -828,7 +828,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_bnb.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -848,22 +848,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_bnb.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_bnb.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -883,13 +883,13 @@ fee_claim_detail as (
t.value as fee_raw
from bnb.transactions tr
join bnb.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join bnb.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -898,7 +898,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join bnb.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -907,7 +907,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_bnb.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -927,7 +927,7 @@ fee_claim_detail as (
(case when fee_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else fee_token end) as token_address,
protocolFee as fee_raw
from deltav2_fees_balances_raw_ethereum
- where evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where evt_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- delta v2 partners revenue
select 'ethereum' as blockchain,
@@ -941,7 +941,7 @@ fee_claim_detail as (
(case when fee_token = 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee then 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 else fee_token end) as token_address,
partnerFee as fee_raw
from deltav2_fees_balances_raw_ethereum
- where evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where evt_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
--
@@ -957,7 +957,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_ethereum
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -977,7 +977,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -985,16 +985,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1009,14 +1009,14 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1026,7 +1026,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1036,7 +1036,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1053,7 +1053,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_ethereum.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1073,22 +1073,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_ethereum.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_ethereum.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1108,13 +1108,13 @@ fee_claim_detail as (
t.value as fee_raw
from ethereum.transactions tr
join ethereum.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join ethereum.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1123,7 +1123,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join ethereum.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1132,7 +1132,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_ethereum.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1154,7 +1154,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_fantom
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1174,7 +1174,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1182,16 +1182,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1206,14 +1206,14 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1223,7 +1223,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1233,7 +1233,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1250,7 +1250,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_fantom.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1270,22 +1270,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_fantom.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_fantom.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1305,13 +1305,13 @@ fee_claim_detail as (
t.value as fee_raw
from fantom.transactions tr
join fantom.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join fantom.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1320,7 +1320,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join fantom.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1329,7 +1329,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_fantom.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1351,7 +1351,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_optimism
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1371,7 +1371,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1379,16 +1379,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1403,14 +1403,14 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1420,7 +1420,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1430,7 +1430,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1447,7 +1447,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_optimism.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1467,22 +1467,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_optimism.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_optimism.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1502,13 +1502,13 @@ fee_claim_detail as (
t.value as fee_raw
from optimism.transactions tr
join optimism.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join optimism.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1517,7 +1517,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join optimism.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1526,7 +1526,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_optimism.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1548,7 +1548,7 @@ fee_claim_detail as (
fee as fee_raw
FROM
exploded_data_polygon
- where call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ where call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- ERC20 transfer to v6 Depositor
@@ -1568,7 +1568,7 @@ fee_claim_detail as (
-- fees come from Augustus v6 but also from ParaSwapDebtSwapAdapterV3, ParaSwapRepayAdapter -- no need to restrict then
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
@@ -1576,16 +1576,16 @@ fee_claim_detail as (
-- and erc."from" = 0x6a000f20005980200259b80c5102003040001068 -- Augustus v6
and erc2.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- i don't understand this conditional. Don't count swaps? But then should omit txs that have ANY outgoing transfer of WETH / ETH, no?
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
union all
-- v6: ETH Transfer to SmartVault directly
@@ -1600,14 +1600,14 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on
- t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t.tx_hash
and tr.block_number = t.block_number
-- and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on
- t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t2.tx_hash -- Other income for Depositor v6
and tr.block_number = t2.block_number
-- and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
@@ -1617,7 +1617,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on
- t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.hash = t3.tx_hash -- Outgoing
and tr.block_number = t3.block_number
and t3."from" = 0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f -- Depositor v6
@@ -1627,7 +1627,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
--
union all
@@ -1644,7 +1644,7 @@ fee_claim_detail as (
_fee as fee_raw
from paraswap_polygon.FeeClaimer_call_registerFee
where call_success = true
- and call_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and call_block_time >= TIMESTAMP '2024-07-08 12:00'
union all
@@ -1664,22 +1664,22 @@ fee_claim_detail as (
and t.block_number = erc.evt_block_number
and erc."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
- and erc.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
-- If following transfers have outgoing only, exclude this revenue.
left join erc20_polygon.evt_Transfer erc2 on t.hash = erc2.evt_tx_hash
and t.block_number = erc2.evt_block_number
and erc2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and erc2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc2.evt_index > erc.evt_index
- and erc2.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc2.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
left join erc20_polygon.evt_Transfer erc3 on t.hash = erc3.evt_tx_hash
and t.block_number = erc3.evt_block_number
and erc3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and erc3.evt_index > erc.evt_index
- and erc3.evt_block_time >= TIMESTAMP '2024-11-30 12:00'
+ and erc3.evt_block_time >= TIMESTAMP '2024-07-08 12:00'
where (erc2.evt_tx_hash is not null or erc3.evt_tx_hash is null)
and t.success
- and block_time >= TIMESTAMP '2024-11-30 12:00'
+ and block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = erc.evt_tx_hash
@@ -1699,13 +1699,13 @@ fee_claim_detail as (
t.value as fee_raw
from polygon.transactions tr
join polygon.traces t on tr.hash = t.tx_hash
- and t.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t.block_number
and t."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
-- If following transfers have outgoing only, exclude this revenue.
left join polygon.traces t2 on tr.hash = t2.tx_hash -- Other income for SmartVault
- and t2.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t2.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t2.block_number
and t2."from" = 0xdef171fe48cf0115b1d80b88dc8eab59176fee57 -- Router
and t2.to = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
@@ -1714,7 +1714,7 @@ fee_claim_detail as (
and t2.call_type = 'call'
and t2.value > cast(0 as uint256)
left join polygon.traces t3 on tr.hash = t3.tx_hash -- Outgoing
- and t3.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and t3.block_time >= TIMESTAMP '2024-07-08 12:00'
and tr.block_number = t3.block_number
and t3."from" = 0xd5b927956057075377263aab7f8afc12f85100db -- SmartVault
and t3.trace_address > t.trace_address
@@ -1723,7 +1723,7 @@ fee_claim_detail as (
and t3.value > cast(0 as uint256)
where (t2.tx_hash is not null or t3.tx_hash is null)
and tr.success
- and tr.block_time >= TIMESTAMP '2024-11-30 12:00'
+ and tr.block_time >= TIMESTAMP '2024-07-08 12:00'
and not exists (
select 1 from paraswap_polygon.FeeClaimer_call_registerFee
where call_tx_hash = t.tx_hash
@@ -1739,7 +1739,7 @@ price_list as (
contract_address,
avg(price) as price
from prices.usd
- where minute >= TIMESTAMP '2024-11-30 12:00'
+ where minute >= TIMESTAMP '2024-07-08 12:00'
group by 1, 2, 3
)
From c86fb925bc6a0a95722120b937af39d12be3e9a3 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Thu, 5 Dec 2024 07:14:27 +0000
Subject: [PATCH 09/10] add annotation to old query, else checked hits - some
of the mappings seem redundant
---
.../paraswap/paraswap_fees_by_epoch.sql | 99 +++++++++++++++++++
1 file changed, 99 insertions(+)
create mode 100644 dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
new file mode 100644
index 00000000000..a757bb63a10
--- /dev/null
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
@@ -0,0 +1,99 @@
+-- https://dune.com/queries/4252179
+-- para-fee-detail-v4-materialized-view
+
+with paraswap_fee_address(blockchain, address) as (
+ values
+ ('ethereum',0xb1720612d0131839dc489fcf20398ea925282fca ), -- no hits since epoch 20
+ ('ethereum',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('ethereum',0x619bbf92fd6ba59893327676b2685a3762a49a33 ), -- no hits since epoch 20
+ ('arbitrum',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('arbitrum',0xb9eeb869d6dbfc5988d5adf3f63cd6b77ac9d9fd ),
+ ('arbitrum',0x7dA82E75BE36Ab9625B1dd40A5aE5181b43473f3 ),
+ ('bnb',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('bnb',0xcbb65ad3e64f404b5411486e15561bfb645ce642 ),
+ ('bnb',0x8c1a1D0b6286F35d47a676aB78482f1cf3D749dC ),
+ ('avalanche_c',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('avalanche_c',0x1bf4c97384e7bdc609017305edb23fd28c13e76a ),
+ ('avalanche_c',0xAFFdeC0FE0B5BBfd725642D87D14c465d25F8dE8 ),
+ ('fantom',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('fantom',0xced122f9b99d224675eeda13f0c14639c5633f91 ),
+ ('fantom',0x5487683dc3216655D0C8AA31255e2e313b99B477 ),
+ ('optimism',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('optimism',0x3b28a6f6291f7e8277751f2911ac49c585d049f6 ),
+ ('optimism',0xf93A7F819F83DBfDbC307d4D4f0FE5a208C50318 ),
+ ('polygon',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
+ ('polygon',0x0c84cd406b8a4e07df9a1b15ef348023a1dcd075 ),
+ ('polygon',0xABF832105D7D19E5DEC28D014d5a12579dfa1097 )
+),
+
+revenue_detail as (
+ select f.en as epoch_num,
+ bc as blockchain,
+ f.bd as block_date,
+ f.bt as block_time,
+ (case when a.address is null then 'Partner Fees' else 'ParaSwap Revenue' end) as fee_type,
+ case when f.bc = 'arbitrum' and f.th in (0x6a5f7a06a96b738f30b8cb2ab3d4bd9cf9342dd374121a9c6ae9532794d4ab42, 0xbfb570699ee9a033312a9df5c44070273c63703df7eb2b4c60541db36b2b5f00) then 0
+ when f.bc = 'bnb' and f.th in (0x3cff5cb1447dc8de854758af9cc60fc45b85aebebed59865e813886f3ba0b308) then 0
+ when f.bc = 'ethereum' and f.th in (0x454464d6e1552249f597a73fe301d1a180d533d6b8b29e9cd4c6cd2df46e916a,0x053033102a6099e3ba0c641096a2321986ea48e218a5a4fec847198b2889ba41,0x52d2d525c65e2cf4361d382c3bd9977544055bc4a69235f727ead393a6830672) then 0
+ when f.bc = 'polygon' and f.ta in (
+ 0xf06443e106af722c557634ac48ec52ad76733e1c,
+ 0xc91c06db0f7bffba61e2a5645cc15686f0a8c828,
+ 0xcf66eb3d546f0415b368d98a95eaf56ded7aa752,
+ 0x4fd86e5c455e1b34a835484fdd627fe92ec400ae,
+ 0x8563cfb8809f0de89ab89b0f884358cffeafd28a,
+ 0x116cf39a540ae5b5073a89929abc8f0e689f21a3
+ ) then 0
+ when f.p is null and f.fa >= 100000 then 0 -- Drop price if there is no token price in dune and amount_usd > $100k
+ when f.fa >= 1000000 then 0 -- Drop price if amount_usd > $1M
+ else f.fa end as fee_amount
+ --sum(fa) filter (where bd >= current_date - interval '1' day and bd < current_date) as fee_amount_24_hour,
+ --sum(fa) filter (where bd >= current_date - interval '90' day and bd < current_date) as fee_amount_90_day,
+ --sum(fa) filter (where bd >= date_trunc('year', now())) as fee_amount_ytd
+ from dune.paraswap.result_para_fee_details_with_epoch_v_4 f
+ left join paraswap_fee_address a on f.bc = a.blockchain and f.ua = a.address
+
+ union all
+
+ select f.epoch as epoch_num,
+ f.blockchain,
+ date_trunc('day', f.block_time)as block_date,
+ f.block_time,
+ 'ParaSwap Revenue' as fee_type,
+ f.paraswap_revenue as fee_amount
+ --sum(fa) filter (where bd >= current_date - interval '1' day and bd < current_date) as fee_amount_24_hour,
+ --sum(fa) filter (where bd >= current_date - interval '90' day and bd < current_date) as fee_amount_90_day,
+ --sum(fa) filter (where bd >= date_trunc('year', now())) as fee_amount_ytd
+ from dune.paraswap.result_paraswap_metamask_swaps_v_4 f
+
+ union all
+
+ select f.epoch as epoch_num,
+ f.blockchain,
+ date_trunc('day', f.block_time)as block_date,
+ f.block_time,
+ 'Partner Fees' as fee_type,
+ f.partner_fee as fee_amount
+ --sum(fa) filter (where bd >= current_date - interval '1' day and bd < current_date) as fee_amount_24_hour,
+ --sum(fa) filter (where bd >= current_date - interval '90' day and bd < current_date) as fee_amount_90_day,
+ --sum(fa) filter (where bd >= date_trunc('year', now())) as fee_amount_ytd
+ from dune.paraswap.result_paraswap_metamask_swaps_v_4 f
+)
+
+select f.epoch_num
+,f.blockchain
+,f.fee_type
+,case when f.epoch_num = 15 and f.blockchain = 'polygon' and f.fee_type = 'ParaSwap Revenue' then cast('123000' as double)
+ else f.fee_amount end as fee_amount
+from (
+ select epoch_num
+ ,blockchain
+ ,fee_type
+ ,sum(fee_amount) as fee_amount
+ from revenue_detail
+ group by 1,2,3
+) f
+
+union all
+
+select *
+from dune.paraswap.dataset_para_fee_detail_before_epoch20
\ No newline at end of file
From e9a5d3f961f11dbfff873f9a177203a8490e03c6 Mon Sep 17 00:00:00 2001
From: alexshchur <60445720+alexshchur@users.noreply.github.com>
Date: Thu, 5 Dec 2024 08:45:34 +0000
Subject: [PATCH 10/10] connect v6 and delta volume to "paraswap fees by epoch"
aggregated view
---
.../_projects/paraswap/paraswap_fees_by_epoch.sql | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
index a757bb63a10..4db13a74e21 100644
--- a/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
+++ b/dbt_subprojects/dex/models/_projects/paraswap/paraswap_fees_by_epoch.sql
@@ -6,24 +6,32 @@ with paraswap_fee_address(blockchain, address) as (
('ethereum',0xb1720612d0131839dc489fcf20398ea925282fca ), -- no hits since epoch 20
('ethereum',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('ethereum',0x619bbf92fd6ba59893327676b2685a3762a49a33 ), -- no hits since epoch 20
+ ('ethereum',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
+ ('ethereum',0x0000000000bbf5c5fd284e657f01bd000933c96d ), -- delta v2, accumulates all fees on itself
('arbitrum',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('arbitrum',0xb9eeb869d6dbfc5988d5adf3f63cd6b77ac9d9fd ),
('arbitrum',0x7dA82E75BE36Ab9625B1dd40A5aE5181b43473f3 ),
+ ('arbitrum',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
('bnb',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('bnb',0xcbb65ad3e64f404b5411486e15561bfb645ce642 ),
('bnb',0x8c1a1D0b6286F35d47a676aB78482f1cf3D749dC ),
+ ('bnb',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
('avalanche_c',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('avalanche_c',0x1bf4c97384e7bdc609017305edb23fd28c13e76a ),
('avalanche_c',0xAFFdeC0FE0B5BBfd725642D87D14c465d25F8dE8 ),
+ ('avalanche_c',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
('fantom',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('fantom',0xced122f9b99d224675eeda13f0c14639c5633f91 ),
('fantom',0x5487683dc3216655D0C8AA31255e2e313b99B477 ),
+ ('fantom',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
('optimism',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('optimism',0x3b28a6f6291f7e8277751f2911ac49c585d049f6 ),
('optimism',0xf93A7F819F83DBfDbC307d4D4f0FE5a208C50318 ),
+ ('optimism',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ), -- depositor v6 augustus -- accumulates fees from augustus v6
('polygon',0xd5b927956057075377263aab7f8afc12f85100db ), -- v5 smart vault
('polygon',0x0c84cd406b8a4e07df9a1b15ef348023a1dcd075 ),
- ('polygon',0xABF832105D7D19E5DEC28D014d5a12579dfa1097 )
+ ('polygon',0xABF832105D7D19E5DEC28D014d5a12579dfa1097 ),
+ ('polygon',0x4d5401b9e9dcd7c9097e1df036c3afafc35d604f ) -- depositor v6 augustus -- accumulates fees from augustus v6
),
revenue_detail as (