Merge pull request #67 from FlipsideCrypto/an-6498/lending

An 6498/lending
This commit is contained in:
tarikceric 2025-09-09 08:19:38 -07:00 committed by GitHub
commit d3d6348ac2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 2260 additions and 0 deletions

View File

@ -0,0 +1,10 @@
reserve,token
0xf8d3506b42a6879680974fc745526c9cbd48b0b0816079aa59f65fc865bdfbf6,0x1::aptos_coin::aptosCoin
0xc2315bdb8f7789e1817ac423e80748075fa68b7e33949bde8c2769a46fdb212,0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC
0x66cca033c185547a88494a9c71baa0dd2185212cfe5e79ec2ec0c4040b5c35c0,0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT
0x2760ca0d7ed74fec37f1c539fd752b5c684fa011c539a79def7a6c67717ebace,0x4e1854f6d332c9525e258fb6e66f84b6af8aba687bbcb832a24768c4e175feec::abtc::ABTC
0xd03ef5ba3d8742597f3d2ad2707e8800eb6888517ae5563de22b7822e3cf6603,0x81214a80d82035a190fcb76b6ff3c0145161c3a9f33d137f2bbaee4cfec8a387
0x77d97d473f0be79c6b55c7577f92fff6e27cde3e39c473247b76d411dd63a344,0x8a7403ae3d95f181761cf36742680442c698b49e047350b77a8906ec5168bdae
0xb993e4c6f53e1e40d4bd9ae6033fe0c07fcd7e385e9cd9ab6fb54ae4f8eb55b1,0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
0xc9699e980dace9ecd74ef411db855cd532ea7be73ac84c47aaccbb6f82f47a57,0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b
0x633786a0316f24a3d79a56571c7970e3465f673962fae42b2e55b95482470efb,0xaef6a8c3182e076db72d64324617114cacf9a52f28325edc10b483f7f05da0e7
1 reserve token
2 0xf8d3506b42a6879680974fc745526c9cbd48b0b0816079aa59f65fc865bdfbf6 0x1::aptos_coin::aptosCoin
3 0xc2315bdb8f7789e1817ac423e80748075fa68b7e33949bde8c2769a46fdb212 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC
4 0x66cca033c185547a88494a9c71baa0dd2185212cfe5e79ec2ec0c4040b5c35c0 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT
5 0x2760ca0d7ed74fec37f1c539fd752b5c684fa011c539a79def7a6c67717ebace 0x4e1854f6d332c9525e258fb6e66f84b6af8aba687bbcb832a24768c4e175feec::abtc::ABTC
6 0xd03ef5ba3d8742597f3d2ad2707e8800eb6888517ae5563de22b7822e3cf6603 0x81214a80d82035a190fcb76b6ff3c0145161c3a9f33d137f2bbaee4cfec8a387
7 0x77d97d473f0be79c6b55c7577f92fff6e27cde3e39c473247b76d411dd63a344 0x8a7403ae3d95f181761cf36742680442c698b49e047350b77a8906ec5168bdae
8 0xb993e4c6f53e1e40d4bd9ae6033fe0c07fcd7e385e9cd9ab6fb54ae4f8eb55b1 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
9 0xc9699e980dace9ecd74ef411db855cd532ea7be73ac84c47aaccbb6f82f47a57 0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b
10 0x633786a0316f24a3d79a56571c7970e3465f673962fae42b2e55b95482470efb 0xaef6a8c3182e076db72d64324617114cacf9a52f28325edc10b483f7f05da0e7

View File

@ -0,0 +1,132 @@
{% docs lending_platform %}
The name of the lending platform where the activity occurred (e.g., 'echelon', 'echo'). Used to identify which specific lending protocol handled the transaction.
**Data type:** String
**Example:**
- echelon
- echo
**Business Context:**
- Enables filtering and analysis by specific lending platforms
- Supports cross-protocol comparisons and platform performance metrics
- Essential for multi-protocol lending analytics and protocol adoption tracking
{% enddocs %}
{% docs lending_protocol %}
The protocol name for the lending platform, typically matching the platform name. Used for protocol identification and categorization in analytics.
**Data type:** String
**Example:**
- echelon
- echo
**Business Context:**
- Provides consistent protocol naming across different data sources
- Enables protocol-specific analysis and reporting
- Supports protocol comparison and market share analysis
{% enddocs %}
{% docs lending_version %}
The version of the lending protocol being used (e.g., 'v1', 'v2'). Indicates which iteration of the protocol's smart contracts handled the transaction.
**Data type:** String
**Example:**
- v1
- v2
**Business Context:**
- Tracks protocol upgrades and version adoption
- Enables analysis of protocol evolution and feature usage
- Important for understanding protocol maturity and stability
{% enddocs %}
{% docs lending_liquidator %}
The address of the account that initiated the liquidation of a borrower's position. Liquidators are incentivized to liquidate undercollateralized positions to maintain protocol health.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies who is performing liquidations and earning liquidation rewards
- Enables analysis of liquidator behavior and profitability
- Important for understanding liquidation market dynamics and risk management
{% enddocs %}
{% docs lending_borrower %}
The address of the account that borrowed assets from the lending protocol. Borrowers must provide collateral to secure their loans.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Core field for user behavior analysis and risk assessment
- Enables tracking of borrowing patterns and credit risk
- Essential for understanding user engagement and protocol utilization
{% enddocs %}
{% docs lending_depositor %}
The address of the account that deposited assets into the lending protocol to earn interest or provide liquidity.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies users providing liquidity to the protocol
- Enables analysis of deposit patterns and user retention
- Important for understanding TVL growth and user engagement
{% enddocs %}
{% docs lending_collateral_token %}
The token address of the collateral asset used in a lending transaction. In liquidations, this represents the asset being liquidated from the borrower's position.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies which assets are being used as collateral
- Enables analysis of collateral composition and risk
- Important for understanding asset utilization and market dynamics
{% enddocs %}
{% docs lending_debt_token %}
The token address of the debt asset in a lending transaction. In liquidations, this represents the asset that was borrowed and is being repaid.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies which assets are being borrowed
- Enables analysis of borrowing demand and asset utilization
- Important for understanding lending market dynamics and risk exposure
{% enddocs %}
{% docs lending_payer %}
The address of the account that paid for a repayment transaction. This can be the borrower themselves or a third party (e.g., a liquidator or helper service).
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies who is making repayments (self vs. third-party)
- Enables analysis of repayment patterns and user behavior
- Important for understanding debt management and protocol health
{% enddocs %}
{% docs lending_withdrawer %}
The address of the account that withdrew previously deposited assets from the lending protocol.
**Data type:** String
**Example:**
- 0x1234567890abcdef1234567890abcdef12345678
**Business Context:**
- Identifies users removing liquidity and realizing yield or reallocating collateral
- Enables analysis of withdrawal behavior, retention, and liquidity outflows
- Useful for tracking user lifecycle (deposit → borrow/repay → withdraw)
{% enddocs %}

View File

@ -0,0 +1,26 @@
{% docs defi__ez_lending_borrows %}
## Description
This table tracks all lending borrows across multiple DeFi lending protocols on Aptos, combining data from Echelon and Echo protocols. It captures when users borrow assets from lending markets using their deposited collateral, including complete transaction context, token metadata, and USD pricing information.
## Key Use Cases
- Lending protocol borrowing analysis and leverage tracking
- DeFi risk assessment and collateralization ratio monitoring
- User borrowing behavior analysis and credit risk evaluation
- Protocol lending capacity and utilization metrics
- Cross-protocol borrowing pattern analysis
## Important Relationships
- Utilizes token price data from `price.ez_prices_hourly` for USD calculations
- References token metadata from `core.dim_tokens` for decimal precision
- Complements `defi.ez_lending_deposits` and `defi.ez_lending_repayments` for complete lending activity analysis
## Commonly-used Fields
- `tx_hash`: Essential for linking to transaction details and verification
- `borrower`: Core field for user behavior analysis and wallet tracking
- `token_address` and `token_symbol`: Key for filtering by specific tokens and DeFi analysis
- `amount_raw` and `amount_usd`: Critical for value calculations and financial analysis
- `platform`: Important for protocol comparison and multi-protocol analysis
- `block_timestamp`: Primary field for time-series analysis and trend detection
{% enddocs %}

View File

@ -0,0 +1,26 @@
{% docs defi__ez_lending_deposits %}
## Description
This table tracks all lending deposits across multiple DeFi lending protocols on Aptos, combining data from Echelon and Echo protocols. It captures when users deposit assets into lending markets to earn interest or provide liquidity, including complete transaction context, token metadata, and USD pricing information.
## Key Use Cases
- Lending protocol deposit analysis and TVL tracking
- DeFi user behavior analysis and deposit pattern identification
- Protocol performance metrics and yield farming analysis
- Cross-protocol deposit flow monitoring and comparison
- User journey analysis and deposit-to-withdrawal lifecycle tracking
## Important Relationships
- Utilizes token price data from `price.ez_prices_hourly` for USD calculations
- References token metadata from `core.dim_tokens` for decimal precision
- Complements `defi.ez_lending_withdraws`, `defi.ez_lending_borrows`, and `defi.ez_lending_repayments` for complete lending activity analysis
## Commonly-used Fields
- `tx_hash`: Essential for linking to transaction details and verification
- `depositor`: Core field for user behavior analysis and wallet tracking
- `token_address` and `token_symbol`: Key for filtering by specific tokens and DeFi analysis
- `amount_raw` and `amount_usd`: Critical for value calculations and financial analysis
- `platform`: Important for protocol comparison and multi-protocol analysis
- `block_timestamp`: Primary field for time-series analysis and trend detection
{% enddocs %}

View File

@ -0,0 +1,27 @@
{% docs defi__ez_lending_liquidations %}
## Description
This table tracks all lending liquidations across multiple DeFi lending protocols on Aptos, combining data from Echelon and Echo protocols. It captures when borrowers' positions are liquidated due to insufficient collateralization, including complete transaction context, both collateral and debt token information, and USD pricing calculations.
## Key Use Cases
- Lending protocol liquidation analysis and risk monitoring
- DeFi market stress testing and systemic risk assessment
- Liquidator behavior analysis and profit tracking
- Borrower risk profile analysis and collateralization monitoring
- Protocol liquidation efficiency and market impact analysis
## Important Relationships
- Utilizes token price data from `price.ez_prices_hourly` for USD calculations of both collateral and debt tokens
- References token metadata from `core.dim_tokens` for decimal precision
- Complements `defi.ez_lending_borrows` and `defi.ez_lending_repayments` for complete lending risk analysis
## Commonly-used Fields
- `tx_hash`: Essential for linking to transaction details and verification
- `liquidator` and `borrower`: Core fields for user behavior analysis and wallet tracking
- `collateral_token` and `debt_token`: Key for understanding liquidation mechanics and token relationships
- `collateral_token_symbol` and `debt_token_symbol`: Important for token identification and analysis
- `amount_raw` and `amount_usd`: Critical for value calculations and liquidation impact analysis
- `platform`: Important for protocol comparison and multi-protocol risk analysis
- `block_timestamp`: Primary field for time-series analysis and market stress detection
{% enddocs %}

View File

@ -0,0 +1,26 @@
{% docs defi__ez_lending_repayments %}
## Description
This table tracks all lending repayments across multiple DeFi lending protocols on Aptos, combining data from Echelon and Echo protocols. It captures when users repay their borrowed assets to lending markets, including complete transaction context, token metadata, and USD pricing information. This includes both self-repayments and third-party repayments.
## Key Use Cases
- Lending protocol repayment analysis and debt management tracking
- DeFi user behavior analysis and repayment pattern identification
- Protocol health monitoring and bad debt risk assessment
- Cross-protocol repayment efficiency analysis
- Borrower creditworthiness and repayment behavior evaluation
## Important Relationships
- Utilizes token price data from `price.ez_prices_hourly` for USD calculations
- References token metadata from `core.dim_tokens` for decimal precision
- Complements `defi.ez_lending_borrows` and `defi.ez_lending_liquidations` for complete lending activity analysis
## Commonly-used Fields
- `tx_hash`: Essential for linking to transaction details and verification
- `payer` and `borrower`: Core fields for user behavior analysis and wallet tracking
- `token_address` and `token_symbol`: Key for filtering by specific tokens and DeFi analysis
- `amount_raw` and `amount_usd`: Critical for value calculations and financial analysis
- `platform`: Important for protocol comparison and multi-protocol analysis
- `block_timestamp`: Primary field for time-series analysis and trend detection
{% enddocs %}

View File

@ -0,0 +1,26 @@
{% docs defi__ez_lending_withdraws %}
## Description
This table tracks all lending withdrawals across multiple DeFi lending protocols on Aptos, combining data from Echelon and Echo protocols. It captures when users withdraw their previously deposited collateral or liquidity from lending markets, including complete transaction context, token metadata, and USD pricing information.
## Key Use Cases
- Lending protocol withdrawal analysis and user behavior tracking
- DeFi liquidity flow monitoring and protocol comparison
- Risk assessment and collateral management analysis
- User journey analysis from deposit to withdrawal patterns
- Protocol performance metrics and TVL calculations
## Important Relationships
- Utilizes token price data from `price.ez_prices_hourly` for USD calculations
- References token metadata from `core.dim_tokens` for decimal precision
- Complements `defi.ez_lending_deposits` for complete lending activity analysis
## Commonly-used Fields
- `tx_hash`: Essential for linking to transaction details and verification
- `withdrawer`: Core field for user behavior analysis and wallet tracking
- `token_address` and `token_symbol`: Key for filtering by specific tokens and DeFi analysis
- `amount_raw` and `amount_usd`: Critical for value calculations and financial analysis
- `platform`: Important for protocol comparison and multi-protocol analysis
- `block_timestamp`: Primary field for time-series analysis and trend detection
{% enddocs %}

View File

@ -0,0 +1,129 @@
{{ config(
materialized = 'incremental',
unique_key = ['ez_lending_borrows_id'],
incremental_strategy = 'merge',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash);",
tags = ['noncore']
) }}
{% if execute %}
{% if is_incremental() %}
{% set max_modified_query %}
SELECT
MAX(modified_timestamp) AS modified_timestamp
FROM
{{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(max_modified_query)[0][0] %}
{% endif %}
{% endif %}
WITH borrows AS (
SELECT
'echelon' as platform,
'echelon' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
borrower,
token_address,
amount as amount_raw,
lending_echelon_borrows_id as ez_lending_borrows_id
FROM {{ ref('silver__lending_echelon_borrows') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'echo' as platform,
'echo' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
borrower,
token_address,
amount as amount_raw,
lending_echo_borrows_id as ez_lending_borrows_id
FROM
{{ ref('silver__lending_echo_borrows') }} a
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price,
decimals,
is_verified
FROM
{{ ref('price__ez_prices_hourly') }}
WHERE
hour >= (
SELECT
MIN(DATE_TRUNC('hour', block_timestamp))
FROM
borrows
)
)
SELECT
a.platform,
a.protocol,
a.protocol_version,
a.block_number,
a.block_timestamp,
a.version,
a.tx_hash,
a.event_index,
a.event_address,
a.borrower,
a.token_address,
b.symbol as token_symbol,
COALESCE(
b.is_verified,
FALSE
) AS token_is_verified,
a.amount_raw,
CASE
WHEN COALESCE(
t.decimals,
b.decimals
) IS NOT NULL THEN amount_raw / pow(10, COALESCE(t.decimals, b.decimals))
END AS amount,
ROUND(
amount * b.price,
2
) AS amount_usd,
ez_lending_borrows_id,
sysdate() AS inserted_timestamp,
sysdate() AS modified_timestamp
FROM borrows a
LEFT JOIN {{ ref('core__dim_tokens') }} t
ON LOWER(
A.token_address
) = LOWER(
t.token_address
)
LEFT JOIN prices b
ON LOWER(a.token_address) = LOWER(b.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = b.hour

View File

@ -0,0 +1,91 @@
version: 2
models:
- name: defi__ez_lending_borrows
description: "{{ doc('defi__ez_lending_borrows') }}"
recent_date_filter: &recent_date_filter
config:
where: block_timestamp >= current_date - 7
recent_modified_date_filter: &recent_modified_date_filter
config:
where: modified_timestamp >= current_date - 7
tests:
- recency_where:
field: BLOCK_TIMESTAMP
datepart: day
interval: 1
group_by_columns: [PLATFORM]
columns:
- name: PLATFORM
description: "{{ doc('lending_platform') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL
description: "{{ doc('lending_protocol') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL_VERSION
description: "{{ doc('lending_version') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_NUMBER
description: "{{ doc('block_number') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null: *recent_date_filter
- name: VERSION
description: "{{ doc('version') }}"
tests:
- not_null: *recent_date_filter
- name: TX_HASH
description: "{{ doc('tx_hash') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_INDEX
description: "{{ doc('event_index') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_ADDRESS
description: "{{ doc('event_address') }}"
tests:
- not_null: *recent_date_filter
- name: BORROWER
description: "{{ doc('lending_borrower') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_ADDRESS
description: "{{ doc('token_address') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
- name: TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_RAW
description: "{{ doc('amount_unadj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT
description: "{{ doc('amount_adj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_USD
description: "{{ doc('amount_usd') }}"
- name: EZ_LENDING_BORROWS_ID
description: "{{ doc('pk') }}"
tests:
- not_null: *recent_date_filter
- unique: *recent_date_filter
- name: INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter
- name: MODIFIED_TIMESTAMP
description: "{{ doc('modified_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter

View File

@ -0,0 +1,129 @@
{{ config(
materialized = 'incremental',
unique_key = ['ez_lending_deposits_id'],
incremental_strategy = 'merge',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash);",
tags = ['noncore']
) }}
{% if execute %}
{% if is_incremental() %}
{% set max_modified_query %}
SELECT
MAX(modified_timestamp) AS modified_timestamp
FROM
{{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(max_modified_query)[0][0] %}
{% endif %}
{% endif %}
WITH deposits AS (
select
'echelon' as platform,
'echelon' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
depositor,
token_address,
amount as amount_raw,
lending_echelon_deposits_id as ez_lending_deposits_id
from {{ ref('silver__lending_echelon_deposits') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'echo' as platform,
'echo' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
depositor,
token_address,
amount as amount_raw,
lending_echo_deposits_id as ez_lending_deposits_id
FROM
{{ ref('silver__lending_echo_deposits') }} a
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price,
decimals,
is_verified
FROM
{{ ref('price__ez_prices_hourly') }}
WHERE
hour >= (
SELECT
MIN(DATE_TRUNC('hour', block_timestamp))
FROM
deposits
)
)
select
a.platform,
a.protocol,
a.protocol_version,
a.block_number,
a.block_timestamp,
a.version,
a.tx_hash,
a.event_index,
a.event_address,
a.depositor,
a.token_address,
b.symbol as token_symbol,
COALESCE(
b.is_verified,
FALSE
) AS token_is_verified,
a.amount_raw,
CASE
WHEN COALESCE(
t.decimals,
b.decimals
) IS NOT NULL THEN amount_raw / pow(10, COALESCE(t.decimals, b.decimals))
END AS amount,
ROUND(
amount * b.price,
2
) AS amount_usd,
ez_lending_deposits_id,
sysdate() AS inserted_timestamp,
sysdate() AS modified_timestamp
from deposits a
LEFT JOIN {{ ref('core__dim_tokens') }} t
ON LOWER(
A.token_address
) = LOWER(
t.token_address
)
left join prices b
on lower(a.token_address) = lower(b.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = b.hour

View File

@ -0,0 +1,90 @@
version: 2
models:
- name: defi__ez_lending_deposits
description: "{{ doc('defi__ez_lending_deposits') }}"
recent_date_filter: &recent_date_filter
config:
where: block_timestamp >= current_date - 7
recent_modified_date_filter: &recent_modified_date_filter
config:
where: modified_timestamp >= current_date - 7
tests:
- recency_where:
field: BLOCK_TIMESTAMP
datepart: day
interval: 1
group_by_columns: [PLATFORM]
columns:
- name: PLATFORM
description: "{{ doc('lending_platform') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL
description: "{{ doc('lending_protocol') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL_VERSION
description: "{{ doc('lending_version') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_NUMBER
description: "{{ doc('block_number') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null: *recent_date_filter
- name: VERSION
description: "{{ doc('version') }}"
tests:
- not_null: *recent_date_filter
- name: TX_HASH
description: "{{ doc('tx_hash') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_INDEX
description: "{{ doc('event_index') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_ADDRESS
description: "{{ doc('event_address') }}"
tests:
- not_null: *recent_date_filter
- name: DEPOSITOR
description: "{{ doc('lending_depositor') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_ADDRESS
description: "{{ doc('token_address') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
- name: TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_RAW
description: "{{ doc('amount_unadj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT
description: "{{ doc('amount_adj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_USD
description: "{{ doc('amount_usd') }}"
- name: EZ_LENDING_DEPOSITS_ID
description: "{{ doc('pk') }}"
tests:
- not_null: *recent_date_filter
- name: INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter
- name: MODIFIED_TIMESTAMP
description: "{{ doc('modified_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter

View File

@ -0,0 +1,146 @@
{{ config(
materialized = 'incremental',
unique_key = ['ez_lending_liquidations_id'],
incremental_strategy = 'merge',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash);",
tags = ['noncore']
) }}
{% if execute %}
{% if is_incremental() %}
{% set max_modified_query %}
SELECT
MAX(modified_timestamp) AS modified_timestamp
FROM
{{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(max_modified_query)[0][0] %}
{% endif %}
{% endif %}
WITH liquidations AS (
SELECT
'echelon' as platform,
'echelon' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
liquidator,
borrower,
amount as amount_raw,
collateral_token,
debt_token,
lending_echelon_liquidations_id as ez_lending_liquidations_id
FROM {{ ref('silver__lending_echelon_liquidations') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'echo' as platform,
'echo' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
liquidator,
borrower,
amount as amount_raw,
collateral_token,
debt_token,
lending_echo_liquidations_id as ez_lending_liquidations_id
FROM
{{ ref('silver__lending_echo_liquidations') }} a
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price,
decimals,
is_verified
FROM
{{ ref('price__ez_prices_hourly') }}
WHERE
hour >= (
SELECT
MIN(DATE_TRUNC('hour', block_timestamp))
FROM
liquidations
)
)
SELECT
a.platform,
a.protocol,
a.protocol_version,
a.block_number,
a.block_timestamp,
a.version,
a.tx_hash,
a.event_index,
a.event_address,
a.liquidator,
a.borrower,
a.collateral_token,
a.debt_token,
collateral_prices.symbol as collateral_token_symbol,
COALESCE(
collateral_prices.is_verified,
FALSE
) AS collateral_token_is_verified,
debt_prices.symbol as debt_token_symbol,
COALESCE(
debt_prices.is_verified,
FALSE
) AS debt_token_is_verified,
a.amount_raw,
CASE
WHEN COALESCE(
debt_t.decimals,
debt_prices.decimals
) IS NOT NULL THEN amount_raw / pow(10, COALESCE(debt_t.decimals, debt_prices.decimals))
END AS amount,
ROUND(
amount * debt_prices.price,
2
) AS amount_usd,
ez_lending_liquidations_id,
sysdate() AS inserted_timestamp,
sysdate() AS modified_timestamp
FROM liquidations a
LEFT JOIN {{ ref('core__dim_tokens') }} debt_t
ON LOWER(
A.debt_token
) = LOWER(
debt_t.token_address
)
LEFT JOIN prices collateral_prices
ON LOWER(a.collateral_token) = LOWER(collateral_prices.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = collateral_prices.hour
LEFT JOIN prices debt_prices
ON LOWER(a.debt_token) = LOWER(debt_prices.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = debt_prices.hour

View File

@ -0,0 +1,110 @@
version: 2
models:
- name: defi__ez_lending_liquidations
description: "{{ doc('defi__ez_lending_liquidations') }}"
recent_date_filter: &recent_date_filter
config:
where: block_timestamp >= current_date - 7
recent_modified_date_filter: &recent_modified_date_filter
config:
where: modified_timestamp >= current_date - 7
tests:
- recency_where:
field: BLOCK_TIMESTAMP
datepart: day
interval: 7
group_by_columns: [PLATFORM]
columns:
- name: PLATFORM
description: "{{ doc('lending_platform') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL
description: "{{ doc('lending_protocol') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL_VERSION
description: "{{ doc('lending_version') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_NUMBER
description: "{{ doc('block_number') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null: *recent_date_filter
- name: VERSION
description: "{{ doc('version') }}"
tests:
- not_null: *recent_date_filter
- name: TX_HASH
description: "{{ doc('tx_hash') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_INDEX
description: "{{ doc('event_index') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_ADDRESS
description: "{{ doc('event_address') }}"
tests:
- not_null: *recent_date_filter
- name: LIQUIDATOR
description: "{{ doc('lending_liquidator') }}"
tests:
- not_null: *recent_date_filter
- name: BORROWER
description: "{{ doc('lending_borrower') }}"
tests:
- not_null: *recent_date_filter
- name: COLLATERAL_TOKEN
description: "{{ doc('lending_collateral_token') }}"
tests:
- not_null: *recent_date_filter
- name: DEBT_TOKEN
description: "{{ doc('lending_debt_token') }}"
tests:
- not_null: *recent_date_filter
- name: COLLATERAL_TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
tests:
- not_null: *recent_date_filter
- name: COLLATERAL_TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: DEBT_TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
tests:
- not_null: *recent_date_filter
- name: DEBT_TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_RAW
description: "{{ doc('amount_unadj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT
description: "{{ doc('amount_adj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_USD
description: "{{ doc('amount_usd') }}"
tests:
- not_null: *recent_date_filter
- name: EZ_LENDING_LIQUIDATIONS_ID
description: "{{ doc('pk') }}"
tests:
- not_null: *recent_date_filter
- name: INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter
- name: MODIFIED_TIMESTAMP
description: "{{ doc('modified_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter

View File

@ -0,0 +1,132 @@
{{ config(
materialized = 'incremental',
unique_key = ['ez_lending_repayments_id'],
incremental_strategy = 'merge',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash);",
tags = ['noncore']
) }}
{% if execute %}
{% if is_incremental() %}
{% set max_modified_query %}
SELECT
MAX(modified_timestamp) AS modified_timestamp
FROM
{{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(max_modified_query)[0][0] %}
{% endif %}
{% endif %}
WITH repayments AS (
SELECT
'echelon' as platform,
'echelon' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
payer,
borrower,
token_address,
amount as amount_raw,
lending_echelon_repayments_id as ez_lending_repayments_id
FROM {{ ref('silver__lending_echelon_repayments') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'echo' as platform,
'echo' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
payer,
borrower,
token_address,
amount as amount_raw,
lending_echo_repayments_id as ez_lending_repayments_id
FROM
{{ ref('silver__lending_echo_repayments') }} a
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price,
decimals,
is_verified
FROM
{{ ref('price__ez_prices_hourly') }}
WHERE
hour >= (
SELECT
MIN(DATE_TRUNC('hour', block_timestamp))
FROM
repayments
)
)
SELECT
a.platform,
a.protocol,
a.protocol_version,
a.block_number,
a.block_timestamp,
a.version,
a.tx_hash,
a.event_index,
a.event_address,
a.payer,
a.borrower,
a.token_address,
b.symbol as token_symbol,
COALESCE(
b.is_verified,
FALSE
) AS token_is_verified,
a.amount_raw,
CASE
WHEN COALESCE(
t.decimals,
b.decimals
) IS NOT NULL THEN amount_raw / pow(10, COALESCE(t.decimals, b.decimals))
END AS amount,
ROUND(
amount * b.price,
2
) AS amount_usd,
ez_lending_repayments_id,
sysdate() AS inserted_timestamp,
sysdate() AS modified_timestamp
FROM repayments a
LEFT JOIN {{ ref('core__dim_tokens') }} t
ON LOWER(
A.token_address
) = LOWER(
t.token_address
)
LEFT JOIN prices b
ON LOWER(a.token_address) = LOWER(b.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = b.hour

View File

@ -0,0 +1,94 @@
version: 2
models:
- name: defi__ez_lending_repayments
description: "{{ doc('defi__ez_lending_repayments') }}"
recent_date_filter: &recent_date_filter
config:
where: block_timestamp >= current_date - 7
recent_modified_date_filter: &recent_modified_date_filter
config:
where: modified_timestamp >= current_date - 7
tests:
- recency_where:
field: BLOCK_TIMESTAMP
datepart: day
interval: 1
group_by_columns: [PLATFORM]
columns:
- name: PLATFORM
description: "{{ doc('lending_platform') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL
description: "{{ doc('lending_protocol') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL_VERSION
description: "{{ doc('lending_version') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_NUMBER
description: "{{ doc('block_number') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null: *recent_date_filter
- name: VERSION
description: "{{ doc('version') }}"
tests:
- not_null: *recent_date_filter
- name: TX_HASH
description: "{{ doc('tx_hash') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_INDEX
description: "{{ doc('event_index') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_ADDRESS
description: "{{ doc('event_address') }}"
tests:
- not_null: *recent_date_filter
- name: PAYER
description: "{{ doc('lending_payer') }}"
tests:
- not_null: *recent_date_filter
- name: BORROWER
description: "{{ doc('lending_borrower') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_ADDRESS
description: "{{ doc('token_address') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
- name: TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_RAW
description: "{{ doc('amount_unadj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT
description: "{{ doc('amount_adj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_USD
description: "{{ doc('amount_usd') }}"
- name: EZ_LENDING_REPAYMENTS_ID
description: "{{ doc('pk') }}"
tests:
- not_null: *recent_date_filter
- name: INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter
- name: MODIFIED_TIMESTAMP
description: "{{ doc('modified_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter

View File

@ -0,0 +1,129 @@
{{ config(
materialized = 'incremental',
unique_key = ['ez_lending_withdraws_id'],
incremental_strategy = 'merge',
incremental_predicates = ["dynamic_range_predicate", "block_timestamp::DATE"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(tx_hash);",
tags = ['noncore']
) }}
{% if execute %}
{% if is_incremental() %}
{% set max_modified_query %}
SELECT
MAX(modified_timestamp) AS modified_timestamp
FROM
{{ this }}
{% endset %}
{% set max_modified_timestamp = run_query(max_modified_query)[0][0] %}
{% endif %}
{% endif %}
WITH withdraws AS (
SELECT
'echelon' as platform,
'echelon' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
depositor,
token_address,
amount as amount_raw,
lending_echelon_withdraws_id as ez_lending_withdraws_id
FROM {{ ref('silver__lending_echelon_withdraws') }}
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
UNION ALL
SELECT
'echo' as platform,
'echo' as protocol,
'v1' as protocol_version,
block_number,
block_timestamp,
version,
tx_hash,
event_index,
event_address,
depositor,
token_address,
amount as amount_raw,
lending_echo_withdraws_id as ez_lending_withdraws_id
FROM
{{ ref('silver__lending_echo_withdraws') }} a
{% if is_incremental() %}
WHERE
modified_timestamp >= '{{ max_modified_timestamp }}'
{% endif %}
),
prices AS (
SELECT
HOUR,
token_address,
symbol,
price,
decimals,
is_verified
FROM
{{ ref('price__ez_prices_hourly') }}
WHERE
hour >= (
SELECT
MIN(DATE_TRUNC('hour', block_timestamp))
FROM
withdraws
)
)
SELECT
a.platform,
a.protocol,
a.protocol_version,
a.block_number,
a.block_timestamp,
a.version,
a.tx_hash,
a.event_index,
a.event_address,
a.depositor,
a.token_address,
b.symbol as token_symbol,
COALESCE(
b.is_verified,
FALSE
) AS token_is_verified,
a.amount_raw,
CASE
WHEN COALESCE(
t.decimals,
b.decimals
) IS NOT NULL THEN amount_raw / pow(10, COALESCE(t.decimals, b.decimals))
END AS amount,
ROUND(
amount * b.price,
2
) AS amount_usd,
ez_lending_withdraws_id,
sysdate() AS inserted_timestamp,
sysdate() AS modified_timestamp
FROM withdraws a
LEFT JOIN {{ ref('core__dim_tokens') }} t
ON LOWER(
A.token_address
) = LOWER(
t.token_address
)
LEFT JOIN prices b
ON LOWER(a.token_address) = LOWER(b.token_address)
AND DATE_TRUNC(
'hour',
a.block_timestamp
) = b.hour

View File

@ -0,0 +1,90 @@
version: 2
models:
- name: defi__ez_lending_withdraws
description: "{{ doc('defi__ez_lending_withdraws') }}"
recent_date_filter: &recent_date_filter
config:
where: block_timestamp >= current_date - 7
recent_modified_date_filter: &recent_modified_date_filter
config:
where: modified_timestamp >= current_date - 7
tests:
- recency_where:
field: BLOCK_TIMESTAMP
datepart: day
interval: 1
group_by_columns: [PLATFORM]
columns:
- name: PLATFORM
description: "{{ doc('lending_platform') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL
description: "{{ doc('lending_protocol') }}"
tests:
- not_null: *recent_date_filter
- name: PROTOCOL_VERSION
description: "{{ doc('lending_version') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_NUMBER
description: "{{ doc('block_number') }}"
tests:
- not_null: *recent_date_filter
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp') }}"
tests:
- not_null: *recent_date_filter
- name: VERSION
description: "{{ doc('version') }}"
tests:
- not_null: *recent_date_filter
- name: TX_HASH
description: "{{ doc('tx_hash') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_INDEX
description: "{{ doc('event_index') }}"
tests:
- not_null: *recent_date_filter
- name: EVENT_ADDRESS
description: "{{ doc('event_address') }}"
tests:
- not_null: *recent_date_filter
- name: DEPOSITOR
description: "{{ doc('lending_withdrawer') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_ADDRESS
description: "{{ doc('token_address') }}"
tests:
- not_null: *recent_date_filter
- name: TOKEN_SYMBOL
description: "{{ doc('symbol') }}"
- name: TOKEN_IS_VERIFIED
description: "{{ doc('prices_is_verified') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_RAW
description: "{{ doc('amount_unadj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT
description: "{{ doc('amount_adj') }}"
tests:
- not_null: *recent_date_filter
- name: AMOUNT_USD
description: "{{ doc('amount_usd') }}"
- name: EZ_LENDING_WITHDRAWS_ID
description: "{{ doc('pk') }}"
tests:
- not_null: *recent_date_filter
- name: INSERTED_TIMESTAMP
description: "{{ doc('inserted_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter
- name: MODIFIED_TIMESTAMP
description: "{{ doc('modified_timestamp') }}"
tests:
- not_null: *recent_modified_date_filter

View File

@ -0,0 +1,103 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echelon_borrows_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:account_addr::string AS borrower,
event_data:amount::number AS amount,
event_data:market_obj:inner::string AS lending_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND event_module = 'lending'
AND event_resource = 'BorrowEvent'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
),
changes AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
change_data,
change_type,
address,
inner_change_type,
change_address,
change_module,
change_resource,
CASE
WHEN change_resource = 'FungibleAssetInfo' THEN change_data:metadata:inner::string
WHEN change_resource = 'CoinInfo' THEN change_data:type_name::string
END AS token_address,
_inserted_timestamp
FROM {{ ref('silver__changes') }}
WHERE change_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND change_module = 'lending'
AND change_resource IN ('FungibleAssetInfo', 'CoinInfo')
AND tx_hash IN (SELECT DISTINCT tx_hash FROM events)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.borrower,
A.amount,
A.lending_market,
B.token_address,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echelon_borrows_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
A._inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN changes B
ON A.tx_hash = B.tx_hash
AND A.lending_market = B.address

View File

@ -0,0 +1,105 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echelon_deposits_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:account_addr::string AS depositor,
event_data:amount::number AS amount,
-- For lending_market: Echelon uses isolated lending markets; a deposit mints "shares" tracked against a specific Market object,
-- not an ERC-20-style aToken, so no 'protocol_market' column. The deposit emits ::lending::SupplyEvent with market_obj.inner pointing to the market. Use that address as the canonical market ID
event_data:market_obj:inner::string AS lending_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND event_module = 'lending'
AND event_resource = 'SupplyEvent'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
),
changes AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
change_data,
change_type,
address,
inner_change_type,
change_address,
change_module,
change_resource,
CASE
WHEN change_resource = 'FungibleAssetInfo' THEN change_data:metadata:inner::string
WHEN change_resource = 'CoinInfo' THEN change_data:type_name::string
END AS token_address,
_inserted_timestamp
FROM {{ ref('silver__changes') }}
WHERE change_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND change_module = 'lending'
AND change_resource IN ('FungibleAssetInfo', 'CoinInfo')
AND tx_hash IN (SELECT DISTINCT tx_hash FROM events)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.depositor,
A.amount,
A.lending_market,
B.token_address,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echelon_deposits_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
A._inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN changes B
ON A.tx_hash = B.tx_hash
AND A.lending_market = B.address

View File

@ -0,0 +1,103 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echelon_liquidations_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:liquidator_addr::string AS liquidator,
event_data:borrower_addr::string AS borrower,
event_data:repay_amount::number AS amount,
event_data:collateral_market_obj:inner::string AS collateral_lending_market,
event_data:borrow_market_obj:inner::string AS debt_lending_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND event_module = 'lending'
AND event_resource = 'LiquidateEvent'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
),
changes AS (
SELECT
tx_hash,
address,
CASE
WHEN change_resource = 'FungibleAssetInfo' THEN change_data:metadata:inner::string
WHEN change_resource = 'CoinInfo' THEN change_data:type_name::string
END AS token_address
FROM {{ ref('silver__changes') }}
WHERE change_module = 'lending'
AND change_resource IN ('FungibleAssetInfo', 'CoinInfo')
AND tx_hash IN (SELECT DISTINCT tx_hash FROM events)
AND address IN (
SELECT DISTINCT collateral_lending_market FROM events
UNION
SELECT DISTINCT debt_lending_market FROM events
)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.liquidator,
A.borrower,
A.amount,
A.collateral_lending_market,
A.debt_lending_market,
C1.token_address AS collateral_token,
C2.token_address AS debt_token,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echelon_liquidations_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
A._inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN changes C1
ON A.tx_hash = C1.tx_hash
AND A.collateral_lending_market = C1.address
LEFT JOIN changes C2
ON A.tx_hash = C2.tx_hash
AND A.debt_lending_market = C2.address

View File

@ -0,0 +1,106 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echelon_repayments_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:repayer_addr::string AS payer,
event_data:borrower_addr::string AS borrower,
event_data:amount::number AS amount,
-- Market object inner address points to the specific lending market
event_data:market_obj:inner::string AS lending_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND event_module = 'lending'
AND event_resource = 'RepayEvent'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
),
changes AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
change_data,
change_type,
address,
inner_change_type,
change_address,
change_module,
change_resource,
CASE
WHEN change_resource = 'FungibleAssetInfo' THEN change_data:metadata:inner::string
WHEN change_resource = 'CoinInfo' THEN change_data:type_name::string
END AS token_address,
_inserted_timestamp
FROM {{ ref('silver__changes') }}
WHERE change_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND change_module = 'lending'
AND change_resource IN ('FungibleAssetInfo', 'CoinInfo')
AND tx_hash IN (SELECT DISTINCT tx_hash FROM events)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.payer,
A.borrower,
A.amount,
A.lending_market,
B.token_address,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echelon_repayments_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
A._inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN changes B
ON A.tx_hash = B.tx_hash
AND A.lending_market = B.address

View File

@ -0,0 +1,103 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echelon_withdraws_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:account_addr::string AS depositor, -- withdrawer
event_data:amount::number AS amount,
event_data:market_obj:inner::string AS lending_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND event_module = 'lending'
AND event_resource = 'WithdrawEvent'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
),
changes AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
change_data,
change_type,
address,
inner_change_type,
change_address,
change_module,
change_resource,
CASE
WHEN change_resource = 'FungibleAssetInfo' THEN change_data:metadata:inner::string
WHEN change_resource = 'CoinInfo' THEN change_data:type_name::string
END AS token_address,
_inserted_timestamp
FROM {{ ref('silver__changes') }}
WHERE change_address = '0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba'
AND change_module = 'lending'
AND change_resource IN ('FungibleAssetInfo', 'CoinInfo')
AND tx_hash IN (SELECT DISTINCT tx_hash FROM events)
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-03-16'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.depositor, -- the withdrawer
A.amount,
A.lending_market,
B.token_address,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echelon_withdraws_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
A._inserted_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN changes B
ON A.tx_hash = B.tx_hash
AND A.lending_market = B.address

View File

@ -0,0 +1,63 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echo_borrows_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:user::string AS borrower,
event_data:amount::number AS amount,
event_data:reserve::string AS lending_market, -- reserve is the market
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed'
AND event_module = 'borrow_logic'
AND event_resource = 'Borrow'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-08-26'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.borrower,
A.amount,
A.lending_market, -- The reserve/market identifier
B.token AS token_address,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echo_borrows_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN {{ ref('silver__lending_echo_markets') }} b
ON A.lending_market = b.reserve

View File

@ -0,0 +1,63 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echo_deposits_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:user::string AS depositor,
event_data:amount::number AS amount,
event_data:reserve::string AS lending_market, -- reserve is the market
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed'
AND event_module = 'supply_logic'
AND event_resource = 'Supply'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-08-26'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.depositor,
A.amount,
A.lending_market, -- The reserve/market identifier
B.token AS token_address,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echo_deposits_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN {{ ref('silver__lending_echo_markets') }} b
ON A.lending_market = b.reserve

View File

@ -0,0 +1,73 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echo_liquidations_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:liquidator::string as liquidator,
event_data:user::string as borrower,
event_data:liquidated_collateral_amount::number AS amount,
event_data:collateral_asset::string AS collateral_token_market,
event_data:debt_asset::string AS debt_token_market,
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed'
AND event_module = 'liquidation_logic'
AND event_resource = 'LiquidationCall'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-08-26'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.liquidator,
A.borrower,
A.amount,
A.collateral_token_market,
A.debt_token_market,
B.token AS collateral_token,
c.token AS debt_token,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echo_liquidations_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN {{ ref('silver__lending_echo_markets') }} b
ON A.collateral_token_market = b.reserve
LEFT JOIN {{ ref('silver__lending_echo_markets') }} c
ON A.debt_token_market = c.reserve

View File

@ -0,0 +1,65 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echo_repayments_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:repayer::string AS payer,
event_data:user::string AS borrower,
event_data:amount::number AS amount,
event_data:reserve::string AS lending_market, -- reserve is the market
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed'
AND event_module = 'borrow_logic'
AND event_resource = 'Repay'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-08-26'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.payer,
A.borrower,
A.amount,
A.lending_market, -- The reserve/market identifier
B.token AS token_address,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echo_repayments_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN {{ ref('silver__lending_echo_markets') }} b
ON A.lending_market = b.reserve

View File

@ -0,0 +1,63 @@
{{ config(
materialized = 'incremental',
unique_key = "lending_echo_withdraws_id",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['modified_timestamp::DATE'],
tags = ['noncore']
) }}
WITH events AS (
SELECT
block_number,
block_timestamp,
version,
tx_hash,
success,
payload_function,
event_index,
event_type,
event_address,
event_module,
event_resource,
event_data,
event_data:user::string AS depositor,
event_data:amount::number AS amount,
event_data:reserve::string AS lending_market, -- reserve is the market
_inserted_timestamp
FROM {{ ref('silver__events') }}
WHERE event_address = '0xeab7ea4d635b6b6add79d5045c4a45d8148d88287b1cfa1c3b6a4b56f46839ed'
AND event_module = 'supply_logic'
AND event_resource = 'Withdraw'
{% if is_incremental() %}
AND _inserted_timestamp >= (
SELECT
MAX(_inserted_timestamp)
FROM
{{ this }}
)
{% else %}
AND block_timestamp :: DATE >= '2024-08-26'
{% endif %}
)
SELECT
A.block_number,
A.block_timestamp,
A.version,
A.tx_hash,
A.event_index,
A.event_address,
A.event_resource,
A.depositor,
A.amount,
A.lending_market, -- The reserve/market identifier
B.token AS token_address,
A._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['A.tx_hash', 'A.event_index']) }} AS lending_echo_withdraws_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id
FROM events A
LEFT JOIN {{ ref('silver__lending_echo_markets') }} b
ON A.lending_market = b.reserve