mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 14:11:55 +00:00
AN-6328/update-compv3-asset-details (#451)
* update compv3 * fix blockchain name
This commit is contained in:
parent
3ad4cfde89
commit
752033468e
@ -1,14 +1,114 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
tags = ['silver','defi','lending','curated']
|
||||
materialized = 'incremental',
|
||||
unique_key = "compound_market_address",
|
||||
tags = ['silver','defi','lending','curated','asset_details']
|
||||
) }}
|
||||
|
||||
WITH contracts_dim AS (
|
||||
SELECT
|
||||
address,
|
||||
name,
|
||||
symbol,
|
||||
decimals
|
||||
FROM
|
||||
{{ ref('core__dim_contracts') }}
|
||||
),
|
||||
|
||||
comp_v3_base AS (
|
||||
SELECT
|
||||
contract_address,
|
||||
block_number,
|
||||
live.udf_api(
|
||||
'POST',
|
||||
'{URL}',
|
||||
OBJECT_CONSTRUCT(
|
||||
'Content-Type', 'application/json',
|
||||
'fsc-quantum-state', 'livequery'
|
||||
),
|
||||
utils.udf_json_rpc_call(
|
||||
'eth_call',
|
||||
[
|
||||
{
|
||||
'to': contract_address,
|
||||
'from': null,
|
||||
'data': RPAD('0xc55dae63', 64, '0')
|
||||
},
|
||||
utils.udf_int_to_hex(block_number)
|
||||
],
|
||||
concat_ws('-', contract_address, '0xc55dae63', block_number)
|
||||
),
|
||||
'Vault/prod/evm/quicknode/polygon/mainnet'
|
||||
) AS api_response
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
WHERE
|
||||
topic_0 = '0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b'
|
||||
AND origin_from_address IN (
|
||||
LOWER('0x6103DB328d4864dc16BD2F0eE1B9A92e3F87f915'),
|
||||
LOWER('0x2501713A67a3dEdde090E42759088A7eF37D4EAb')
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND modified_timestamp >= (
|
||||
SELECT MAX(modified_timestamp) - INTERVAL '12 hours' FROM {{ this }}
|
||||
)
|
||||
AND modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
|
||||
QUALIFY ROW_NUMBER() OVER (
|
||||
PARTITION BY contract_address
|
||||
ORDER BY block_number ASC
|
||||
) = 1
|
||||
),
|
||||
|
||||
comp_v3_data AS (
|
||||
SELECT
|
||||
l.contract_address AS ctoken_address,
|
||||
c1.symbol AS ctoken_symbol,
|
||||
c1.name AS ctoken_name,
|
||||
c1.decimals AS ctoken_decimals,
|
||||
LOWER(
|
||||
CONCAT(
|
||||
'0x',
|
||||
SUBSTR(
|
||||
l.api_response:data:result :: STRING,
|
||||
-40
|
||||
)
|
||||
)
|
||||
) AS underlying_address,
|
||||
c2.name AS underlying_name,
|
||||
c2.symbol AS underlying_symbol,
|
||||
c2.decimals AS underlying_decimals,
|
||||
l.block_number AS created_block,
|
||||
'Compound V3' AS compound_version
|
||||
FROM comp_v3_base l
|
||||
LEFT JOIN contracts_dim c1 ON l.contract_address = c1.address
|
||||
LEFT JOIN contracts_dim c2 ON LOWER(
|
||||
CONCAT(
|
||||
'0x',
|
||||
SUBSTR(
|
||||
l.api_response:data:result :: STRING,
|
||||
-40
|
||||
)
|
||||
)
|
||||
) = c2.address
|
||||
WHERE c1.name IS NOT NULL
|
||||
)
|
||||
|
||||
SELECT
|
||||
LOWER('0xF25212E676D1F7F89Cd72fFEe66158f541246445') AS compound_market_address,
|
||||
'Compound USDC' AS compound_market_name,
|
||||
'cUSDCv3' AS compound_market_symbol,
|
||||
6 AS compound_market_decimals,
|
||||
LOWER('0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359') AS underlying_asset_address,
|
||||
'USDC' AS underlying_asset_name,
|
||||
'USDC' AS underlying_asset_symbol,
|
||||
6 AS underlying_asset_decimals
|
||||
ctoken_address AS compound_market_address,
|
||||
ctoken_symbol AS compound_market_symbol,
|
||||
ctoken_name AS compound_market_name,
|
||||
ctoken_decimals AS compound_market_decimals,
|
||||
underlying_address AS underlying_asset_address,
|
||||
underlying_name AS underlying_asset_name,
|
||||
underlying_symbol AS underlying_asset_symbol,
|
||||
underlying_decimals AS underlying_asset_decimals,
|
||||
created_block AS created_block_number,
|
||||
compound_version,
|
||||
{{ dbt_utils.generate_surrogate_key(['compound_market_address']) }} AS comp_asset_details_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
comp_v3_data
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
WITH comp_assets AS (
|
||||
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
@ -21,7 +21,6 @@ comp_assets as (
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
borrow AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -59,17 +58,22 @@ borrow AS (
|
||||
ON asset = C.compound_market_address
|
||||
WHERE
|
||||
topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl
|
||||
AND l.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(compound_market_address)
|
||||
FROM
|
||||
comp_assets
|
||||
)
|
||||
AND tx_succeeded
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
WITH comp_assets AS (
|
||||
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
@ -20,9 +20,7 @@ comp_assets as (
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
|
||||
supply AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -58,8 +56,14 @@ supply AS (
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral
|
||||
AND l.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(compound_market_address)
|
||||
FROM
|
||||
comp_assets
|
||||
)
|
||||
AND tx_succeeded
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
|
||||
@ -60,13 +60,13 @@ liquidations AS (
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral
|
||||
AND tx_succeeded
|
||||
AND l.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(compound_market_address)
|
||||
FROM
|
||||
comp_assets
|
||||
)
|
||||
AND tx_succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
WITH comp_assets AS (
|
||||
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
@ -21,7 +21,6 @@ comp_assets as (
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
repayments AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -54,7 +53,7 @@ repayments AS (
|
||||
'-',
|
||||
event_index :: STRING
|
||||
) AS _log_id,
|
||||
modified_timestamp AS _inserted_timestamp
|
||||
l.modified_timestamp AS _inserted_timestamp
|
||||
FROM
|
||||
{{ ref('core__fact_event_logs') }}
|
||||
l
|
||||
@ -62,17 +61,22 @@ repayments AS (
|
||||
ON contract_address = C.compound_market_address
|
||||
WHERE
|
||||
topics [0] = '0xd1cf3d156d5f8f0d50f6c122ed609cec09d35c9b9fb3fff6ea0959134dae424e' --Supply
|
||||
AND l.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(compound_market_address)
|
||||
FROM
|
||||
comp_assets
|
||||
)
|
||||
AND tx_succeeded
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
AND l.modified_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
AND _inserted_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
AND l.modified_timestamp >= SYSDATE() - INTERVAL '7 day'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
|
||||
@ -6,9 +6,8 @@
|
||||
tags = ['silver','defi','lending','curated']
|
||||
) }}
|
||||
|
||||
WITH comp_assets AS (
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
@ -22,7 +21,6 @@ comp_assets as (
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
withdraw AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
@ -57,8 +55,13 @@ withdraw AS (
|
||||
ON token_address = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral
|
||||
AND l.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(compound_market_address)
|
||||
FROM
|
||||
comp_assets
|
||||
)
|
||||
AND tx_succeeded
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l.modified_timestamp >= (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user