mirror of
https://github.com/FlipsideCrypto/blast-models.git
synced 2026-02-06 14:11:55 +00:00
tidy + incrementals
This commit is contained in:
parent
a03beb9993
commit
307928ce9a
@ -14,6 +14,15 @@ WITH blast_contracts AS (
|
||||
{{ ref('silver__contracts') }}
|
||||
WHERE
|
||||
token_name LIKE 'INIT%'
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp > (
|
||||
SELECT
|
||||
max(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
underlying AS (
|
||||
SELECT
|
||||
@ -23,7 +32,7 @@ underlying AS (
|
||||
from_address AS token_address,
|
||||
to_address AS underlying_asset_address
|
||||
FROM
|
||||
blast.core.fact_traces
|
||||
{{ ref('core__fact_traces') }}
|
||||
WHERE
|
||||
identifier = 'CALL_0_1'
|
||||
AND LEFT(
|
||||
@ -43,7 +52,7 @@ unwrapped AS (
|
||||
from_address AS underlying_asset_address,
|
||||
to_address AS underlying_unwrap_address
|
||||
FROM
|
||||
blast.core.fact_traces
|
||||
{{ ref('core__fact_traces') }}
|
||||
WHERE
|
||||
identifier = 'CALL_0_0'
|
||||
AND LEFT(
|
||||
|
||||
@ -47,7 +47,7 @@ init_borrows AS (
|
||||
-- receipt token
|
||||
contract_address AS token,
|
||||
'INIT Capital' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
@ -55,6 +55,15 @@ init_borrows AS (
|
||||
contract_address = '0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x49dd87b26edb1c92c93f83b092bd5a425c6bf7a562c0fed02f2576c49f477ba4'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
token_transfer AS (
|
||||
-- token transfer checks for withdrawal/deposits in usdb/weth(for hooks leveraging)/blast
|
||||
@ -71,8 +80,7 @@ token_transfer AS (
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
LEFT JOIN {{ ref('silver__contracts') }} USING(contract_address)
|
||||
WHERE
|
||||
1 = 1
|
||||
AND contract_address IN (
|
||||
contract_address IN (
|
||||
'0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad',
|
||||
'0x4300000000000000000000000000000000000003',
|
||||
'0x4300000000000000000000000000000000000004'
|
||||
@ -162,7 +170,7 @@ init_combine AS (
|
||||
C.token_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
init_borrows b
|
||||
LEFT JOIN asset_details C
|
||||
@ -198,9 +206,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS underlyingAmount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
init_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -47,9 +47,8 @@ init_deposits AS (
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS minttokens_raw,
|
||||
-- receipt token
|
||||
'INIT Capital' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
@ -57,6 +56,15 @@ init_deposits AS (
|
||||
contract_address = '0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x722732c12c1c1ba3942aef8ee6e0357b01908558e142501c5f85b356c4dcadf8'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
token_transfer1 AS (
|
||||
SELECT
|
||||
@ -70,9 +78,7 @@ token_transfer1 AS (
|
||||
t3.token_name,
|
||||
t2.from_address AS from_address2,
|
||||
t2.to_address AS to_address2,
|
||||
t2.raw_amount AS base_amount,
|
||||
--t4.token_decimals as base_decimals, t4.token_symbol as base_symbol, t4.token_name as base_name
|
||||
-- consolidate names, decimal, symbol, amount
|
||||
t2.raw_amount AS base_amount
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
t1
|
||||
@ -84,8 +90,7 @@ token_transfer1 AS (
|
||||
t3
|
||||
ON t2.contract_address = t3.contract_address
|
||||
WHERE
|
||||
1 = 1
|
||||
AND t1.contract_address IN (
|
||||
t1.contract_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
@ -104,7 +109,7 @@ token_transfer1 AS (
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
) -- for Blast
|
||||
)
|
||||
AND t2.contract_address IN (
|
||||
SELECT
|
||||
underlying_unwrap_address
|
||||
@ -118,7 +123,7 @@ token_transfer1 AS (
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
) -- to get USDB from WUSDB
|
||||
)
|
||||
),
|
||||
token_transfer2 AS (
|
||||
SELECT
|
||||
@ -169,7 +174,7 @@ token_transfer2 AS (
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
) -- for Blast
|
||||
)
|
||||
),
|
||||
token_transfer AS (
|
||||
SELECT
|
||||
@ -182,7 +187,7 @@ token_transfer AS (
|
||||
base_amount,
|
||||
raw_amount
|
||||
) AS raw_amount,
|
||||
to_address --coalesce(from_address2, from_address) as from_address
|
||||
to_address
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
@ -222,7 +227,7 @@ native_transfer AS (
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
WHERE
|
||||
to_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21') -- hard code wweth contract here
|
||||
to_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21')
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
@ -250,7 +255,6 @@ init_combine AS (
|
||||
eth_value,
|
||||
raw_amount
|
||||
) AS mintAmount_raw,
|
||||
-- actual out
|
||||
COALESCE(
|
||||
eth_decimals,
|
||||
d.token_decimals
|
||||
@ -268,7 +272,7 @@ init_combine AS (
|
||||
C.token_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
init_deposits b
|
||||
LEFT JOIN asset_details C
|
||||
@ -302,9 +306,9 @@ SELECT
|
||||
supplied_symbol,
|
||||
supplier,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
init_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -49,10 +49,9 @@ init_liquidations AS (
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: FLOAT AS sharesamt,
|
||||
-- receipt token
|
||||
contract_address AS token,
|
||||
'INIT Capital' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
@ -60,6 +59,15 @@ init_liquidations AS (
|
||||
contract_address = '0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x6df71caf4cddb1620bcf376243248e0077da98913d65a7e9315bc9984e5fff72'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
token_transfer AS (
|
||||
SELECT
|
||||
@ -72,7 +80,7 @@ token_transfer AS (
|
||||
token_symbol,
|
||||
token_name
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
{{ ref('core__fact_token_transfers') }} a
|
||||
LEFT JOIN {{ ref('silver__contracts') }} USING(contract_address)
|
||||
WHERE
|
||||
1 = 1
|
||||
@ -95,14 +103,14 @@ token_transfer AS (
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
) -- for Blast
|
||||
)
|
||||
OR from_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
) -- to get USDB from WUSDB
|
||||
)
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
@ -130,7 +138,6 @@ SELECT
|
||||
10,
|
||||
C.token_decimals
|
||||
) AS tokens_seized,
|
||||
-- in tokens
|
||||
underlying_amount_raw / pow(
|
||||
10,
|
||||
d.token_decimals
|
||||
@ -139,7 +146,7 @@ SELECT
|
||||
C.underlying_asset_address AS liquidation_contract_address,
|
||||
C.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.platform,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
init_liquidations l
|
||||
|
||||
@ -45,14 +45,12 @@ init_repayments AS (
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS sharesAmt,
|
||||
-- receipt token
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: FLOAT AS amtToRepay,
|
||||
-- receipt token
|
||||
contract_address AS token,
|
||||
'INIT Capital' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
@ -60,6 +58,15 @@ init_repayments AS (
|
||||
contract_address = '0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x77673b670822baca14a7caf6f8038f811649ab73e4c06083b0e58a53389bece7'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
native_transfer AS (
|
||||
SELECT
|
||||
@ -73,7 +80,7 @@ native_transfer AS (
|
||||
FROM
|
||||
{{ ref('core__fact_traces') }}
|
||||
WHERE
|
||||
to_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21') -- hard code wweth contract here
|
||||
to_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21')
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
@ -95,7 +102,7 @@ token_transfer AS (
|
||||
token_symbol,
|
||||
token_name
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
{{ ref('core__fact_token_transfers') }} a
|
||||
LEFT JOIN {{ ref('silver__contracts') }} USING(contract_address)
|
||||
WHERE
|
||||
1 = 1
|
||||
@ -110,14 +117,14 @@ token_transfer AS (
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
) -- for Blast
|
||||
)
|
||||
OR to_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
) -- to get USDB from WUSDB
|
||||
)
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
@ -167,7 +174,7 @@ init_combine AS (
|
||||
) AS underlying_asset_address,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
init_repayments b
|
||||
LEFT JOIN asset_details C
|
||||
@ -200,9 +207,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
init_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -8,161 +8,287 @@
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
tx_hash,
|
||||
token_address,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
underlying_unwrap_address,
|
||||
underlying_unwrap_name,
|
||||
underlying_unwrap_symbol,
|
||||
underlying_unwrap_decimals,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__init_asset_details') }}
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_number,
|
||||
tx_hash,
|
||||
token_address,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_name,
|
||||
underlying_symbol,
|
||||
underlying_decimals,
|
||||
underlying_unwrap_address,
|
||||
underlying_unwrap_name,
|
||||
underlying_unwrap_symbol,
|
||||
underlying_unwrap_decimals,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__init_asset_details') }}
|
||||
),
|
||||
init_redemption AS (
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
contract_address AS token_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
utils.udf_hex_to_int( topics[1] :: STRING ) :: FLOAT as posId,
|
||||
concat('0x', substr(topics[2] :: string, 27, 40)) as pool,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS redeemed_token_raw, -- receipt token
|
||||
'INIT Capital' AS platform,
|
||||
inserted_timestamp as _inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address ='0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x09c2e7b3728acfd99b3f71e4c1a55bcd48019bcc0e45c741f7c2f3393f49ea91'
|
||||
AND tx_status = 'SUCCESS'
|
||||
),
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
contract_address AS token_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
utils.udf_hex_to_int(
|
||||
topics [1] :: STRING
|
||||
) :: FLOAT AS posId,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS pool,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: FLOAT AS redeemed_token_raw,
|
||||
'INIT Capital' AS platform,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address = '0xa7d36f2106b5a5d528a7e2e7a3f436d703113a10'
|
||||
AND topics [0] :: STRING = '0x09c2e7b3728acfd99b3f71e4c1a55bcd48019bcc0e45c741f7c2f3393f49ea91'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
token_transfer1 AS (
|
||||
SELECT
|
||||
t1.tx_hash, t2.contract_address, t1.from_address, t1.to_address, t1.raw_amount,
|
||||
t3.token_symbol, t3.token_decimals, t3.token_name,
|
||||
t2.from_address as from_address2, t2.to_address as to_address2, t2.raw_amount as base_amount,
|
||||
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }} t1
|
||||
left join
|
||||
{{ ref('core__fact_token_transfers') }} t2 on t1.tx_hash=t2.tx_hash and t1.contract_address = t2.from_address
|
||||
left join
|
||||
{{ ref('silver__contracts') }} t3 on t2.contract_address = t3.contract_address
|
||||
WHERE
|
||||
1=1
|
||||
AND t1.contract_address in (select underlying_asset_address from asset_details where underlying_unwrap_address is not null)
|
||||
AND t1.tx_hash IN (select tx_hash from init_redemption)
|
||||
|
||||
AND t1.from_address in (SELECT token_address FROM ASSET_DETAILS) -- for Blast
|
||||
AND t2.contract_address IN (select underlying_unwrap_address from asset_details)
|
||||
AND (t2.from_address in (SELECT underlying_asset_address FROM asset_details)) -- to get USDB from WUSDB
|
||||
),
|
||||
|
||||
token_transfer2 as (
|
||||
SELECT
|
||||
t1.tx_hash, t1.contract_address, t1.from_address, t1.to_address, t1.raw_amount,
|
||||
t3.token_symbol, t3.token_decimals, t3.token_name,
|
||||
null as from_address2, null as to_address2, null as base_amount, null as base_decimals, null as base_symbol, null as base_name
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }} t1
|
||||
left join
|
||||
{{ ref('silver__contracts') }} t3 on t1.contract_address = t3.contract_address
|
||||
WHERE
|
||||
1=1
|
||||
AND t1.contract_address in (select underlying_asset_address from asset_details where underlying_unwrap_address is null)
|
||||
AND t1.tx_hash IN (select tx_hash from init_redemption)
|
||||
AND t1.tx_hash not in (select tx_hash from token_transfer1)
|
||||
|
||||
AND t1.from_address in (SELECT token_address FROM ASSET_DETAILS) -- for Blast
|
||||
|
||||
),
|
||||
token_transfer as (
|
||||
select
|
||||
tx_hash,
|
||||
contract_address,
|
||||
token_decimals,
|
||||
token_symbol,
|
||||
token_name,
|
||||
coalesce(base_amount, raw_amount) as raw_amount,
|
||||
from_address
|
||||
from (
|
||||
select tx_hash, contract_address, base_amount, raw_amount, from_address2, from_address, token_name, token_symbol, token_decimals from token_transfer1
|
||||
union all
|
||||
select tx_hash, contract_address, base_amount, raw_amount, from_address2, from_address, token_name, token_symbol, token_decimals from token_transfer2
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
MAX(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
token_transfer1 AS (
|
||||
SELECT
|
||||
t1.tx_hash,
|
||||
t2.contract_address,
|
||||
t1.from_address,
|
||||
t1.to_address,
|
||||
t1.raw_amount,
|
||||
t3.token_symbol,
|
||||
t3.token_decimals,
|
||||
t3.token_name,
|
||||
t2.from_address AS from_address2,
|
||||
t2.to_address AS to_address2,
|
||||
t2.raw_amount AS base_amount
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
t1
|
||||
LEFT JOIN {{ ref('core__fact_token_transfers') }}
|
||||
t2
|
||||
ON t1.tx_hash = t2.tx_hash
|
||||
AND t1.contract_address = t2.from_address
|
||||
LEFT JOIN {{ ref('silver__contracts') }}
|
||||
t3
|
||||
ON t2.contract_address = t3.contract_address
|
||||
WHERE
|
||||
1 = 1
|
||||
AND t1.contract_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
underlying_unwrap_address IS NOT NULL
|
||||
)
|
||||
AND t1.tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
init_redemption
|
||||
)
|
||||
AND t1.from_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND t2.contract_address IN (
|
||||
SELECT
|
||||
underlying_unwrap_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
AND (
|
||||
t2.from_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
)
|
||||
),
|
||||
token_transfer2 AS (
|
||||
SELECT
|
||||
t1.tx_hash,
|
||||
t1.contract_address,
|
||||
t1.from_address,
|
||||
t1.to_address,
|
||||
t1.raw_amount,
|
||||
t3.token_symbol,
|
||||
t3.token_decimals,
|
||||
t3.token_name,
|
||||
NULL AS from_address2,
|
||||
NULL AS to_address2,
|
||||
NULL AS base_amount,
|
||||
NULL AS base_decimals,
|
||||
NULL AS base_symbol,
|
||||
NULL AS base_name
|
||||
FROM
|
||||
{{ ref('core__fact_token_transfers') }}
|
||||
t1
|
||||
LEFT JOIN {{ ref('silver__contracts') }}
|
||||
t3
|
||||
ON t1.contract_address = t3.contract_address
|
||||
WHERE
|
||||
1 = 1
|
||||
AND t1.contract_address IN (
|
||||
SELECT
|
||||
underlying_asset_address
|
||||
FROM
|
||||
asset_details
|
||||
WHERE
|
||||
underlying_unwrap_address IS NULL
|
||||
)
|
||||
AND t1.tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
init_redemption
|
||||
)
|
||||
AND t1.tx_hash NOT IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
token_transfer1
|
||||
)
|
||||
AND t1.from_address IN (
|
||||
SELECT
|
||||
token_address
|
||||
FROM
|
||||
asset_details
|
||||
)
|
||||
),
|
||||
token_transfer AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
contract_address,
|
||||
token_decimals,
|
||||
token_symbol,
|
||||
token_name,
|
||||
COALESCE(
|
||||
base_amount,
|
||||
raw_amount
|
||||
) AS raw_amount,
|
||||
from_address
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
tx_hash,
|
||||
contract_address,
|
||||
base_amount,
|
||||
raw_amount,
|
||||
from_address2,
|
||||
from_address,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals
|
||||
FROM
|
||||
token_transfer1
|
||||
UNION ALL
|
||||
SELECT
|
||||
tx_hash,
|
||||
contract_address,
|
||||
base_amount,
|
||||
raw_amount,
|
||||
from_address2,
|
||||
from_address,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals
|
||||
FROM
|
||||
token_transfer2
|
||||
)
|
||||
),
|
||||
|
||||
native_transfer AS (
|
||||
SELECT
|
||||
tx_hash, from_address as wrapped_address, to_address, value_precise_raw as eth_value, 'WETH' as eth_symbol, 18 as eth_decimals, '0x4300000000000000000000000000000000000004' as eth_address
|
||||
FROM
|
||||
blast.core.fact_traces
|
||||
WHERE
|
||||
from_address in ('0xf683ce59521aa464066783d78e40cd9412f33d21') -- hard code wweth contract here
|
||||
AND tx_hash IN (SELECT tx_hash FROM init_redemption)
|
||||
AND type = 'CALL'
|
||||
AND trace_status='SUCCESS'
|
||||
and input='0x'
|
||||
SELECT
|
||||
tx_hash,
|
||||
from_address AS wrapped_address,
|
||||
to_address,
|
||||
value_precise_raw AS eth_value,
|
||||
'WETH' AS eth_symbol,
|
||||
18 AS eth_decimals,
|
||||
'0x4300000000000000000000000000000000000004' AS eth_address
|
||||
FROM
|
||||
blast.core.fact_traces
|
||||
WHERE
|
||||
from_address IN ('0xf683ce59521aa464066783d78e40cd9412f33d21')
|
||||
AND tx_hash IN (
|
||||
SELECT
|
||||
tx_hash
|
||||
FROM
|
||||
init_redemption
|
||||
)
|
||||
AND TYPE = 'CALL'
|
||||
AND trace_status = 'SUCCESS'
|
||||
AND input = '0x'
|
||||
),
|
||||
|
||||
init_combine AS (
|
||||
SELECT
|
||||
b.block_number,
|
||||
b.block_timestamp,
|
||||
b.tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_to_address as redeemer,
|
||||
origin_function_signature,
|
||||
b.contract_address,
|
||||
pool,
|
||||
|
||||
coalesce(eth_value, raw_amount) as received_amount_raw, -- actual out
|
||||
coalesce(eth_decimals, d.token_decimals) as received_decimals,
|
||||
coalesce(eth_symbol, d.token_symbol) as received_symbol,
|
||||
coalesce(eth_address, d.contract_address) AS received_contract_address,
|
||||
|
||||
redeemed_token_raw, -- receipt burnt
|
||||
C.token_address,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
C.token_address AS redeemed_contract_address,
|
||||
C.token_symbol AS redeemed_symbol,
|
||||
C.token_decimals AS redeemed_decimals,
|
||||
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
init_redemption b
|
||||
LEFT JOIN asset_details c
|
||||
ON b.pool = C.token_address
|
||||
LEFT JOIN token_transfer d
|
||||
ON b.tx_hash = d.tx_hash AND b.pool = d.from_address
|
||||
LEFT JOIN native_transfer e
|
||||
on b.tx_hash = e.tx_hash
|
||||
SELECT
|
||||
b.block_number,
|
||||
b.block_timestamp,
|
||||
b.tx_hash,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_to_address AS redeemer,
|
||||
origin_function_signature,
|
||||
b.contract_address,
|
||||
pool,
|
||||
COALESCE(
|
||||
eth_value,
|
||||
raw_amount
|
||||
) AS received_amount_raw,
|
||||
COALESCE(
|
||||
eth_decimals,
|
||||
d.token_decimals
|
||||
) AS received_decimals,
|
||||
COALESCE(
|
||||
eth_symbol,
|
||||
d.token_symbol
|
||||
) AS received_symbol,
|
||||
COALESCE(
|
||||
eth_address,
|
||||
d.contract_address
|
||||
) AS received_contract_address,
|
||||
redeemed_token_raw,
|
||||
C.token_address,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
C.token_address AS redeemed_contract_address,
|
||||
C.token_symbol AS redeemed_symbol,
|
||||
C.token_decimals AS redeemed_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
init_redemption b
|
||||
LEFT JOIN asset_details C
|
||||
ON b.pool = C.token_address
|
||||
LEFT JOIN token_transfer d
|
||||
ON b.tx_hash = d.tx_hash
|
||||
AND b.pool = d.from_address
|
||||
LEFT JOIN native_transfer e
|
||||
ON b.tx_hash = e.tx_hash
|
||||
)
|
||||
SELECT
|
||||
block_number,
|
||||
@ -188,10 +314,9 @@ SELECT
|
||||
redeemed_decimals
|
||||
) AS redeemed_tokens,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
init_combine ee
|
||||
qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
init_combine ee qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -7,18 +7,17 @@
|
||||
) }}
|
||||
|
||||
WITH asset_list AS (
|
||||
|
||||
SELECT
|
||||
'0x44f33bc796f7d3df55040cd3c631628b560715c2' AS pool_address -- weth lending pool
|
||||
'0x44f33bc796f7d3df55040cd3c631628b560715c2' AS pool_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x4a1d9220e11a47d8ab22ccd82da616740cf0920a' AS pool_address -- usdb lending pool
|
||||
'0x4a1d9220e11a47d8ab22ccd82da616740cf0920a' AS pool_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x788654040d7e9a8bb583d7d8ccea1ebf1ae4ac06' AS pool_address -- usdb pro lending pool
|
||||
'0x788654040d7e9a8bb583d7d8ccea1ebf1ae4ac06' AS pool_address
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x60ed5493b35f833189406dfec0b631a6b5b57f66' AS pool_address -- weth pro lending pool
|
||||
'0x60ed5493b35f833189406dfec0b631a6b5b57f66' AS pool_address
|
||||
),
|
||||
contracts AS (
|
||||
SELECT
|
||||
@ -37,34 +36,33 @@ juice_contracts AS (
|
||||
collateral_tokens AS (
|
||||
SELECT
|
||||
'0x1d37383447ceceeedb7c92372d6993821d3d7b40' AS contract_address,
|
||||
'0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' AS underlying_asset -- sUSDE
|
||||
'0x211cc4dd073734da055fbf44a2b4667d5e5fe5d2' AS underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x7e4afebe294345d72de6bb8405c871d7bb6c53d1' AS contract_address,
|
||||
'0x04c0599ae5a44757c0af6f9ec3b93da8976c150a' AS underlying_asset -- weWETH
|
||||
'0x04c0599ae5a44757c0af6f9ec3b93da8976c150a' AS underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x295e17672f1290b66dd064ec6b7fdaf280b33cea' AS contract_address,
|
||||
'0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' AS underlying_asset -- USDE
|
||||
'0x5d3a1ff2b6bab83b63cd9ad0787074081a52ef34' AS underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x0246937acacabe4e1b6045de9b68113d72966be2' AS contract_address,
|
||||
'0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad' AS underlying_asset -- BLAST
|
||||
'0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad' AS underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0x2b1c36a733b1bab31f05ac8866d330e29c604b8f' AS contract_address,
|
||||
'0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad' AS underlying_asset -- BLAST
|
||||
'0xb1a5700fa2358173fe465e6ea4ff52e36e88e2ad' AS underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
'0xc81a630806d1af3fd7509187e1afc501fd46e818' AS contract_address,
|
||||
'0x2416092f143378750bb29b79ed961ab195cceea5' AS underlying_asset -- ezETH
|
||||
'0x2416092f143378750bb29b79ed961ab195cceea5' AS underlying_asset
|
||||
),
|
||||
-- identify creation txs for pools
|
||||
tx_pull AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
blast.core.fact_event_logs
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
origin_from_address = '0x0ee09b204ffebf9a1f14c99e242830a09958ba34'
|
||||
AND origin_to_address = '0x4e59b44847b379578588920ca78fbf26c0b4956c'
|
||||
@ -74,6 +72,15 @@ tx_pull AS (
|
||||
FROM
|
||||
asset_list
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
trace_pull AS (
|
||||
SELECT
|
||||
@ -91,8 +98,16 @@ trace_pull AS (
|
||||
'CREATE_0_5',
|
||||
'CREATE_0_4'
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
-- get debt token
|
||||
debt_token AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
@ -102,7 +117,8 @@ debt_token AS (
|
||||
to_address AS debt_address,
|
||||
NAME AS debt_name,
|
||||
decimals AS debt_decimals,
|
||||
symbol AS debt_symbol
|
||||
symbol AS debt_symbol,
|
||||
l.modified_timestamp
|
||||
FROM
|
||||
trace_pull l
|
||||
LEFT JOIN contracts
|
||||
@ -110,7 +126,6 @@ debt_token AS (
|
||||
WHERE
|
||||
identifier = 'CREATE_0_4'
|
||||
),
|
||||
-- get liquidity token
|
||||
token AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
@ -118,9 +133,10 @@ token AS (
|
||||
to_address AS token_address,
|
||||
NAME AS token_name,
|
||||
decimals AS token_decimals,
|
||||
symbol AS token_symbol
|
||||
symbol AS token_symbol,
|
||||
a.modified_timestamp
|
||||
FROM
|
||||
trace_pull
|
||||
trace_pull a
|
||||
LEFT JOIN contracts
|
||||
ON address = token_address
|
||||
WHERE
|
||||
@ -128,9 +144,9 @@ token AS (
|
||||
),
|
||||
underlying AS (
|
||||
SELECT
|
||||
*
|
||||
*,
|
||||
FROM
|
||||
blast.core.fact_event_logs
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
@ -138,6 +154,15 @@ underlying AS (
|
||||
FROM
|
||||
tx_pull
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
underlying_asset AS (
|
||||
SELECT
|
||||
@ -147,7 +172,7 @@ underlying_asset AS (
|
||||
NAME AS underlying_name,
|
||||
decimals AS underlying_decimals,
|
||||
symbol AS underlying_symbol,
|
||||
t1.inserted_timestamp,
|
||||
t1.modified_timestamp,
|
||||
t1._log_id
|
||||
FROM
|
||||
underlying t1
|
||||
@ -158,14 +183,14 @@ underlying_asset AS (
|
||||
topics [1] IS NOT NULL
|
||||
AND t2.contract_address != '0x2536fe9ab3f511540f2f9e2ec2a805005c3dd800'
|
||||
),
|
||||
-- collateral tokens
|
||||
logs_pull AS (
|
||||
SELECT
|
||||
*,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0], 25, 40)) AS contract_address
|
||||
CONCAT('0x', SUBSTR(segmented_data [0], 25, 40)) AS contract_address,
|
||||
modified_timestamp
|
||||
FROM
|
||||
blast.core.fact_event_logs
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address = LOWER('0x2536FE9ab3F511540F2f9e2eC2A805005C3Dd800')
|
||||
AND topics [0] = '0x2da9afcf2ffbfd720263cc579aa9f8dfce34b31d447b0ba6d0bfefc40f713c84'
|
||||
@ -175,12 +200,21 @@ logs_pull AS (
|
||||
FROM
|
||||
juice_contracts
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
get_underlying AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
blast.core.fact_event_logs
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
@ -189,6 +223,15 @@ get_underlying AS (
|
||||
logs_pull
|
||||
)
|
||||
AND topics [0] = '0xcaa97ab28bae75adcb5a02786c64b44d0d3139aa521bf831cdfbe280ef246e36'
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
collateral_base AS (
|
||||
SELECT
|
||||
@ -197,7 +240,7 @@ collateral_base AS (
|
||||
block_number,
|
||||
t1.contract_address,
|
||||
t2.contract_address AS underlying_asset,
|
||||
inserted_timestamp,
|
||||
t1.modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
logs_pull t1
|
||||
@ -219,7 +262,7 @@ collateral_list AS (
|
||||
d.name AS underlying_name,
|
||||
d.symbol AS underlying_symbol,
|
||||
d.decimals AS underlying_decimals,
|
||||
A.inserted_timestamp,
|
||||
A.modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
collateral_base A
|
||||
@ -229,7 +272,6 @@ collateral_list AS (
|
||||
LEFT JOIN contracts d
|
||||
ON underlying_asset_address = d.address
|
||||
),
|
||||
-- combine pool + collateral
|
||||
combine_asset AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
@ -248,7 +290,7 @@ combine_asset AS (
|
||||
debt_name,
|
||||
debt_decimals,
|
||||
debt_symbol,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
underlying_asset
|
||||
@ -272,7 +314,7 @@ combine_asset AS (
|
||||
NULL AS debt_name,
|
||||
NULL AS debt_decimals,
|
||||
NULL AS debt_symbol,
|
||||
inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
collateral_list
|
||||
|
||||
@ -40,17 +40,26 @@ juice_borrows AS (
|
||||
utils.udf_hex_to_int (segmented_data[0]) as loan_amount_raw,
|
||||
contract_address AS pool_address,
|
||||
'Juice' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
LEFT JOIN
|
||||
{{ ref('core__fact_event_logs') }} a
|
||||
LEFT JOIN
|
||||
asset_details on contract_address=pool_address
|
||||
WHERE
|
||||
contract_address IN (select pool_address from asset_details)
|
||||
AND topics [0] :: STRING = '0xcbc04eca7e9da35cb1393a6135a199ca52e450d5e9251cbd99f7847d33a36750'
|
||||
AND tx_status = 'SUCCESS'
|
||||
),
|
||||
{% if is_incremental() %}
|
||||
AND a.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND a.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
juice_combine AS (
|
||||
SELECT
|
||||
@ -75,7 +84,7 @@ juice_combine AS (
|
||||
debt_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
juice_borrows b
|
||||
LEFT JOIN asset_details C
|
||||
@ -103,9 +112,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
juice_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -45,10 +45,10 @@ juice_deposits AS (
|
||||
) :: INTEGER AS mintAmount_raw,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }} a
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -58,15 +58,15 @@ juice_deposits AS (
|
||||
)
|
||||
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
{% if is_incremental() %}
|
||||
AND a.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND a.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
juice_combine AS (
|
||||
SELECT
|
||||
@ -89,7 +89,7 @@ juice_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
juice_deposits b
|
||||
LEFT JOIN asset_details C
|
||||
@ -120,9 +120,9 @@ SELECT
|
||||
supplied_symbol,
|
||||
supplier,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
juice_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -37,30 +37,35 @@ juice_liquidations AS (
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(l.data, 3, len(l.data)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS borrower,
|
||||
-- account
|
||||
l.contract_address AS token,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS repayAmount_raw,
|
||||
-- collateral_amount inclusive of fees
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER AS bonuscollateral_raw,
|
||||
-- liquidation fee
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER AS debtamountneeded_raw,
|
||||
-- debt repaid
|
||||
'Juice' AS platform,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }} l
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
INNER JOIN asset_details ad
|
||||
ON l.contract_address = ad.pool_address
|
||||
WHERE
|
||||
l.topics [0] :: STRING = '0xe32ec3ea3154879f27d5367898ab3a5ac6b68bf921d7cc610720f417c5cb243c'
|
||||
AND l.tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
token_transfer AS (
|
||||
SELECT
|
||||
@ -75,7 +80,7 @@ token_transfer AS (
|
||||
event_index ASC
|
||||
)
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }} a
|
||||
WHERE
|
||||
1 = 1
|
||||
AND contract_address IN (
|
||||
@ -92,7 +97,17 @@ token_transfer AS (
|
||||
FROM
|
||||
juice_liquidations
|
||||
)
|
||||
AND tx_status = 'SUCCESS' qualify(ROW_NUMBER() over(PARTITION BY tx_hash
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND a.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND a.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
qualify(ROW_NUMBER() over(PARTITION BY tx_hash
|
||||
ORDER BY
|
||||
event_index ASC)) = 1
|
||||
),
|
||||
@ -124,7 +139,7 @@ liquidation_union AS (
|
||||
asd1.underlying_asset_address AS liquidation_contract_address,
|
||||
asd1.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.platform,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
juice_liquidations l
|
||||
@ -137,4 +152,4 @@ SELECT
|
||||
FROM
|
||||
liquidation_union qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -42,10 +42,10 @@ juice_repayments AS (
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repayed_amount_raw,
|
||||
'Juice' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }} a
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -55,6 +55,15 @@ juice_repayments AS (
|
||||
)
|
||||
AND topics [0] :: STRING = '0x5c16de4f8b59bd9caf0f49a545f25819a895ed223294290b408242e72a594231'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND a.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND a.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
juice_combine AS (
|
||||
@ -76,7 +85,7 @@ juice_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
juice_repayments b
|
||||
LEFT JOIN asset_details C
|
||||
@ -103,9 +112,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
juice_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -38,10 +38,10 @@ withdraw_logs AS (
|
||||
DATA,
|
||||
topics,
|
||||
tx_status,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }} a
|
||||
WHERE
|
||||
(
|
||||
contract_address IN (
|
||||
@ -58,10 +58,19 @@ withdraw_logs AS (
|
||||
)
|
||||
)
|
||||
AND topics [0] :: STRING IN (
|
||||
'0x884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364' -- pool redeem,
|
||||
'0x0b260cc77140cab3405675836fc971314e656137208b77414be51fafd58ae34b' -- collateral redeem,
|
||||
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' -- transfer
|
||||
'0x884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364',
|
||||
'0x0b260cc77140cab3405675836fc971314e656137208b77414be51fafd58ae34b',
|
||||
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND a.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND a.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
juice_redemption AS (
|
||||
SELECT
|
||||
@ -80,7 +89,7 @@ juice_redemption AS (
|
||||
) :: INTEGER AS received_amount_raw,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS redeemer,
|
||||
'Juice' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
withdraw_logs
|
||||
@ -111,7 +120,7 @@ juice_collateralredeems AS (
|
||||
) :: INTEGER AS received_amount_raw,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS redeemer,
|
||||
'Juice' AS platform,
|
||||
inserted_timestamp AS _inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
withdraw_logs
|
||||
@ -175,7 +184,7 @@ juice_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
juice_redemption b
|
||||
LEFT JOIN token_transfer USING(tx_hash)
|
||||
@ -201,7 +210,7 @@ juice_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
juice_collateralredeems b
|
||||
LEFT JOIN token_transfer d USING(tx_hash)
|
||||
@ -217,7 +226,6 @@ SELECT
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
--token as token_address,
|
||||
token_symbol,
|
||||
received_amount_raw AS amount_unadj,
|
||||
received_amount_raw / pow(
|
||||
@ -232,9 +240,9 @@ SELECT
|
||||
) AS redeemed_tokens,
|
||||
redeemer,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
juice_combine ee qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
) }}
|
||||
|
||||
WITH contracts AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
@ -22,34 +21,31 @@ log_pull AS (
|
||||
C.token_name,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
{{ ref('core__fact_event_logs') }} l
|
||||
LEFT JOIN contracts C
|
||||
ON C.contract_address = l.contract_address
|
||||
WHERE
|
||||
topics [0] :: STRING = '0x7ac369dbd14fa5ea3f473ed67cc9d598964a77501540ba6751eb0b3decf5870d'
|
||||
and origin_from_address='0x6315f65843e7582508e4f0aac20a7203e7b09f02'
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l._inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND origin_from_address='0x6315f65843e7582508e4f0aac20a7203e7b09f02'
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
|
||||
traces_pull AS (
|
||||
SELECT
|
||||
t.from_address AS token_address,
|
||||
t.to_address AS underlying_asset
|
||||
FROM
|
||||
{{ ref('silver__traces') }}
|
||||
t
|
||||
{{ ref('core__fact_traces') }} t
|
||||
WHERE
|
||||
tx_hash IN (
|
||||
SELECT
|
||||
@ -57,8 +53,17 @@ traces_pull AS (
|
||||
FROM
|
||||
log_pull
|
||||
)
|
||||
and input = '0x18160ddd'
|
||||
and type = 'STATICCALL'
|
||||
AND input = '0x18160ddd'
|
||||
AND type = 'STATICCALL'
|
||||
{% if is_incremental() %}
|
||||
AND t.modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND t.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
underlying_details AS (
|
||||
SELECT
|
||||
@ -69,21 +74,19 @@ underlying_details AS (
|
||||
l.token_name,
|
||||
l.token_symbol,
|
||||
l.token_decimals,
|
||||
case when t.underlying_asset is null then '0x4300000000000000000000000000000000000004' -- native eth as weth
|
||||
else t.underlying_asset
|
||||
end as underlying_asset,
|
||||
l._inserted_timestamp,
|
||||
CASE WHEN t.underlying_asset IS NULL THEN '0x4300000000000000000000000000000000000004'
|
||||
ELSE t.underlying_asset
|
||||
END AS underlying_asset,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
log_pull l
|
||||
LEFT JOIN traces_pull t
|
||||
ON l.contract_address = t.token_address
|
||||
qualify(ROW_NUMBER() over(PARTITION BY l.contract_address
|
||||
QUALIFY(ROW_NUMBER() OVER(PARTITION BY l.contract_address
|
||||
ORDER BY
|
||||
block_timestamp ASC)) = 1
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
SELECT
|
||||
l.tx_hash,
|
||||
l.block_number,
|
||||
@ -96,7 +99,7 @@ SELECT
|
||||
C.token_name AS underlying_name,
|
||||
C.token_symbol AS underlying_symbol,
|
||||
C.token_decimals AS underlying_decimals,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
underlying_details l
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_name,
|
||||
token_name,
|
||||
token_symbol,
|
||||
token_decimals,
|
||||
underlying_asset_address,
|
||||
@ -43,10 +42,10 @@ orbit_borrows AS (
|
||||
) :: INTEGER AS totalBorrows,
|
||||
contract_address AS token,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -56,16 +55,15 @@ orbit_borrows AS (
|
||||
)
|
||||
AND topics [0] :: STRING = '0x13ed6866d4e1ee6da46f845c46d7e54120883d75c5ea9a2dacc1c4ca8984ab80'
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
orbit_combine AS (
|
||||
SELECT
|
||||
@ -86,7 +84,7 @@ orbit_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
orbit_borrows b
|
||||
LEFT JOIN asset_details C
|
||||
@ -112,9 +110,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
orbit_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -39,10 +39,10 @@ orbit_deposits AS (
|
||||
) :: INTEGER AS mintAmount_raw,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS supplier,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -52,15 +52,15 @@ orbit_deposits AS (
|
||||
)
|
||||
AND topics [0] :: STRING = '0x4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
orbit_combine AS (
|
||||
SELECT
|
||||
@ -83,7 +83,7 @@ orbit_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
orbit_deposits b
|
||||
LEFT JOIN asset_details C
|
||||
@ -114,9 +114,9 @@ SELECT
|
||||
supplied_symbol,
|
||||
supplier,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
orbit_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -7,7 +7,6 @@
|
||||
) }}
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_name,
|
||||
@ -42,10 +41,10 @@ orbit_liquidations AS (
|
||||
) :: INTEGER AS repayAmount_raw,
|
||||
CONCAT('0x', SUBSTR(segmented_data [3] :: STRING, 25, 40)) AS tokenCollateral,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -57,13 +56,13 @@ orbit_liquidations AS (
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union AS (
|
||||
@ -99,7 +98,7 @@ liquidation_union AS (
|
||||
asd1.underlying_asset_address AS liquidation_contract_address,
|
||||
asd1.underlying_symbol AS liquidation_contract_symbol,
|
||||
l.platform,
|
||||
l._inserted_timestamp,
|
||||
l.modified_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
orbit_liquidations l
|
||||
@ -113,4 +112,4 @@ SELECT
|
||||
FROM
|
||||
liquidation_union qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
@ -37,10 +37,10 @@ orbit_repayments AS (
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER AS repayed_amount_raw,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -51,14 +51,14 @@ orbit_repayments AS (
|
||||
AND topics [0] :: STRING = '0x1a2a22cb034d26d1854bdc6666a5b91fe25efbbb5dcad3b0355478d6f5c362a1'
|
||||
AND tx_status = 'SUCCESS'
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
orbit_combine AS (
|
||||
SELECT
|
||||
@ -80,7 +80,7 @@ orbit_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
orbit_repayments b
|
||||
LEFT JOIN asset_details C
|
||||
@ -108,9 +108,9 @@ SELECT
|
||||
underlying_decimals
|
||||
) AS amount,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
orbit_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
@ -7,7 +7,6 @@
|
||||
) }}
|
||||
|
||||
WITH asset_details AS (
|
||||
|
||||
SELECT
|
||||
token_address,
|
||||
token_name,
|
||||
@ -40,10 +39,10 @@ orbit_redemptions AS (
|
||||
) :: INTEGER AS redeemed_token_raw,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS redeemer,
|
||||
'Orbit' AS platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
contract_address IN (
|
||||
SELECT
|
||||
@ -55,13 +54,13 @@ orbit_redemptions AS (
|
||||
AND tx_status = 'SUCCESS'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
AND modified_timestamp > (
|
||||
SELECT
|
||||
max(modified_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
),
|
||||
orbit_combine AS (
|
||||
@ -85,7 +84,7 @@ orbit_combine AS (
|
||||
C.underlying_decimals,
|
||||
b.platform,
|
||||
b._log_id,
|
||||
b._inserted_timestamp
|
||||
b.modified_timestamp
|
||||
FROM
|
||||
orbit_redemptions b
|
||||
LEFT JOIN asset_details C
|
||||
@ -115,9 +114,9 @@ SELECT
|
||||
) AS redeemed_tokens,
|
||||
redeemer,
|
||||
platform,
|
||||
_inserted_timestamp,
|
||||
modified_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
orbit_combine ee qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
orbit_combine qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
modified_timestamp DESC)) = 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user