mirror of
https://github.com/FlipsideCrypto/near-models.git
synced 2026-02-06 11:26:52 +00:00
add chainlist api pull, simplify json parsing, upd doc
This commit is contained in:
parent
376fb6b288
commit
28ad82275e
@ -1,7 +1,7 @@
|
||||
{% docs defi__fact_intents %}
|
||||
|
||||
## Description
|
||||
This table contains all intent-based transactions on the NEAR Protocol blockchain, capturing user intents for token transfers, swaps, and other DeFi operations through the intents.near protocol. The data includes both NEP-245 and DIP-4 standard intents, providing comprehensive tracking of intent creation, execution, and fulfillment. This table enables analysis of intent-based trading patterns, MEV protection mechanisms, and user behavior in intent-driven DeFi protocols.
|
||||
This table contains all intent-based transactions on the NEAR Protocol blockchain, capturing user intents for token transfers, swaps, and other DeFi operations through the intents.near protocol. The data includes both NEP-245 and DIP-4 standard intents, providing comprehensive tracking of intent creation, execution, and fulfillment. This table enables analysis of intent-based trading patterns, MEV protection mechanisms, and user behavior in intent-driven DeFi protocols. This table includes all intent execution within a transaction, which may include several intermediate steps interacting with solvers.
|
||||
|
||||
## Key Use Cases
|
||||
- Intent-based trading analysis and pattern recognition
|
||||
|
||||
@ -74,9 +74,9 @@ logs_base AS(
|
||||
predecessor_id,
|
||||
signer_id,
|
||||
gas_burnt,
|
||||
clean_log,
|
||||
TRY_PARSE_JSON(clean_log) :event :: STRING AS log_event,
|
||||
TRY_PARSE_JSON(clean_log) :data :: ARRAY AS log_data,
|
||||
TRY_PARSE_JSON(clean_log) AS log_json,
|
||||
log_json :event :: STRING AS log_event,
|
||||
log_json :data :: ARRAY AS log_data,
|
||||
ARRAY_SIZE(log_data) AS log_data_len,
|
||||
receipt_succeeded,
|
||||
modified_timestamp
|
||||
@ -102,7 +102,7 @@ nep245_logs AS (
|
||||
FROM
|
||||
logs_base lb
|
||||
WHERE
|
||||
TRY_PARSE_JSON(lb.clean_log) :standard :: STRING = 'nep245'
|
||||
lb.log_json :standard :: STRING = 'nep245'
|
||||
|
||||
{% if is_incremental() and not var("MANUAL_FIX") %}
|
||||
AND
|
||||
@ -112,13 +112,13 @@ nep245_logs AS (
|
||||
dip4_logs AS (
|
||||
SELECT
|
||||
lb.*,
|
||||
try_parse_json(lb.clean_log):data[0]:referral::string as referral,
|
||||
try_parse_json(lb.clean_log):data[0]:fees_collected as fees_collected_raw,
|
||||
try_parse_json(lb.clean_log):version :: string as version
|
||||
lb.log_json:data[0]:referral::string as referral,
|
||||
lb.log_json:data[0]:fees_collected as fees_collected_raw,
|
||||
lb.log_json:version :: string as version
|
||||
FROM
|
||||
logs_base lb
|
||||
WHERE
|
||||
TRY_PARSE_JSON(lb.clean_log) :standard :: STRING = 'dip4'
|
||||
lb.log_json :standard :: STRING = 'dip4'
|
||||
{% if is_incremental() and not var("MANUAL_FIX") %}
|
||||
AND
|
||||
COALESCE(lb.modified_timestamp, '1970-01-01') >= '{{max_mod}}'
|
||||
|
||||
38
models/silver/labels/external/silver__chainlist_ids.sql
vendored
Normal file
38
models/silver/labels/external/silver__chainlist_ids.sql
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = 'chainlist_id',
|
||||
incremental_strategy = 'merge',
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
tags = ['scheduled_non_core']
|
||||
) }}
|
||||
|
||||
WITH api_call AS (
|
||||
|
||||
SELECT
|
||||
response
|
||||
FROM
|
||||
{{ ref('streamline__chainlist_ids_realtime') }}
|
||||
),
|
||||
flattened AS (
|
||||
SELECT
|
||||
VALUE :chain ::STRING AS chain,
|
||||
VALUE :chainId :: INT AS chain_id,
|
||||
VALUE :name :: STRING AS chain_name
|
||||
FROM
|
||||
api_call,
|
||||
LATERAL FLATTEN(
|
||||
input => response :data :: ARRAY
|
||||
)
|
||||
)
|
||||
SELECT
|
||||
chain,
|
||||
chain_id,
|
||||
chain_name,
|
||||
{{ dbt_utils.generate_surrogate_key(['chain_id']) }} AS chainlist_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
flattened
|
||||
|
||||
qualify(row_number() over (partition by chain_id order by inserted_timestamp asc)) = 1
|
||||
@ -15,7 +15,6 @@ WITH api_call AS (
|
||||
),
|
||||
flattened AS (
|
||||
SELECT
|
||||
TRY_PARSE_JSON(VALUE) AS token_metadata,
|
||||
VALUE :defuse_asset_identifier :: STRING AS defuse_asset_identifier,
|
||||
VALUE :intents_token_id :: STRING AS intents_token_id,
|
||||
VALUE :standard :: STRING AS standard,
|
||||
@ -33,16 +32,12 @@ FROM
|
||||
),
|
||||
chain_mapping AS (
|
||||
-- Map EVM chain IDs to blockchain names
|
||||
SELECT '1' AS chain_id, 'eth' AS blockchain_name UNION ALL
|
||||
SELECT '10', 'op' UNION ALL
|
||||
SELECT '56', 'bsc' UNION ALL
|
||||
SELECT '100', 'gnosis' UNION ALL
|
||||
SELECT '137', 'pol' UNION ALL
|
||||
SELECT '8453', 'base' UNION ALL
|
||||
SELECT '42161', 'arb' UNION ALL
|
||||
SELECT '43114', 'avax' UNION ALL
|
||||
SELECT '80094', 'bera' UNION ALL
|
||||
SELECT '196', 'okx'
|
||||
SELECT
|
||||
chain_id :: STRING AS chain_id,
|
||||
LOWER(chain) AS blockchain_name
|
||||
FROM
|
||||
{{ ref('silver__chainlist_ids') }}
|
||||
|
||||
),
|
||||
parsed AS (
|
||||
SELECT
|
||||
@ -95,9 +90,7 @@ parsed AS (
|
||||
END
|
||||
ELSE
|
||||
SPLIT_PART(defuse_asset_identifier, ':', ARRAY_SIZE(SPLIT(defuse_asset_identifier, ':')))
|
||||
END AS crosschain_token_contract,
|
||||
-- Extract chain_id for mapping (second part of defuse_asset_identifier)
|
||||
SPLIT_PART(defuse_asset_identifier, ':', 2) AS chain_id_for_mapping
|
||||
END AS crosschain_token_contract
|
||||
FROM
|
||||
flattened
|
||||
LEFT JOIN chain_mapping cm
|
||||
|
||||
30
models/streamline/external/token_metadata/chainlist/streamline__chainlist_ids_realtime.sql
vendored
Normal file
30
models/streamline/external/token_metadata/chainlist/streamline__chainlist_ids_realtime.sql
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
{{ config (
|
||||
materialized = "view",
|
||||
tags = ['streamline_non_core']
|
||||
) }}
|
||||
|
||||
WITH api_call AS (
|
||||
|
||||
SELECT
|
||||
{{ target.database }}.live.udf_api(
|
||||
'GET',
|
||||
'https://chainlist.org/rpcs.json',
|
||||
OBJECT_CONSTRUCT(
|
||||
'Content-Type',
|
||||
'application/json',
|
||||
'fsc-quantum-state',
|
||||
'livequery'
|
||||
),
|
||||
{}
|
||||
) :: variant AS response
|
||||
)
|
||||
SELECT
|
||||
response
|
||||
FROM
|
||||
api_call
|
||||
WHERE
|
||||
response IS NOT NULL
|
||||
AND response :status_code :: INT IN (
|
||||
200,
|
||||
201
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user