mirror of
https://github.com/FlipsideCrypto/aptos-models.git
synced 2026-02-06 13:22:04 +00:00
Merge pull request #68 from FlipsideCrypto/an-6537/aries_lending
add aries lending
This commit is contained in:
commit
f6f43f92f0
@ -62,6 +62,27 @@ FROM
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'aries' as platform,
|
||||
'aries' 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_aries_borrows_id as ez_lending_borrows_id
|
||||
FROM
|
||||
{{ ref('silver__lending_aries_borrows') }} a
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
|
||||
@ -62,6 +62,27 @@ FROM
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'aries' as platform,
|
||||
'aries' 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_aries_deposits_id as ez_lending_deposits_id
|
||||
FROM
|
||||
{{ ref('silver__lending_aries_deposits') }} a
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
|
||||
@ -66,6 +66,29 @@ FROM
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'aries' as platform,
|
||||
'aries' 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_aries_liquidations_id as ez_lending_liquidations_id
|
||||
FROM
|
||||
{{ ref('silver__lending_aries_liquidations') }} a
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
|
||||
@ -79,7 +79,8 @@ models:
|
||||
- name: DEBT_TOKEN_SYMBOL
|
||||
description: "{{ doc('symbol') }}"
|
||||
tests:
|
||||
- not_null: *recent_date_filter
|
||||
- not_null:
|
||||
where: block_timestamp >= current_date - 7 AND platform != 'echo'
|
||||
- name: DEBT_TOKEN_IS_VERIFIED
|
||||
description: "{{ doc('prices_is_verified') }}"
|
||||
tests:
|
||||
@ -95,7 +96,8 @@ models:
|
||||
- name: AMOUNT_USD
|
||||
description: "{{ doc('amount_usd') }}"
|
||||
tests:
|
||||
- not_null: *recent_date_filter
|
||||
- not_null:
|
||||
where: block_timestamp >= current_date - 7 AND platform != 'echo'
|
||||
- name: EZ_LENDING_LIQUIDATIONS_ID
|
||||
description: "{{ doc('pk') }}"
|
||||
tests:
|
||||
|
||||
@ -64,6 +64,28 @@ FROM
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'aries' as platform,
|
||||
'aries' 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_aries_repayments_id as ez_lending_repayments_id
|
||||
FROM
|
||||
{{ ref('silver__lending_aries_repayments') }} a
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
|
||||
@ -62,6 +62,27 @@ FROM
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'aries' as platform,
|
||||
'aries' 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_aries_withdraws_id as ez_lending_withdraws_id
|
||||
FROM
|
||||
{{ ref('silver__lending_aries_withdraws') }} a
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
modified_timestamp >= '{{ max_modified_timestamp }}'
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "lending_aries_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:sender::string AS borrower,
|
||||
event_data:borrow_amount::number AS amount,
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
) AS token_address,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__events') }}
|
||||
WHERE event_address = '0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3'
|
||||
AND event_module = 'controller'
|
||||
AND event_resource LIKE 'WithdrawEvent%'
|
||||
AND event_data:borrow_amount::number > 0 -- Only events with actual borrowing
|
||||
AND event_data:allow_borrow = true -- Ensure borrowing is allowed
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2024-01-05'
|
||||
{% endif %}
|
||||
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_address,
|
||||
event_resource,
|
||||
borrower,
|
||||
amount,
|
||||
token_address,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS lending_aries_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
_inserted_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM events
|
||||
@ -0,0 +1,66 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "lending_aries_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:sender::string AS depositor,
|
||||
event_data:deposit_amount::number AS amount,
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
) AS token_address,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__events') }}
|
||||
WHERE event_address = '0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3'
|
||||
AND event_module = 'controller'
|
||||
AND event_resource LIKE 'DepositEvent%'
|
||||
AND (event_data:repay_only = false OR event_data:repay_only IS NULL) -- remove borrows
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2024-01-05'
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_address,
|
||||
event_resource,
|
||||
depositor,
|
||||
amount,
|
||||
token_address,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS lending_aries_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
_inserted_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM events
|
||||
@ -0,0 +1,83 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "lending_aries_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:liquidatee::string AS borrower,
|
||||
event_data:repay_amount::number AS amount,
|
||||
-- Parse the two tokens from event_type
|
||||
-- Format: LiquidateEvent<debt_token, collateral_token>
|
||||
SPLIT_PART(
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
),
|
||||
', ',
|
||||
1
|
||||
) AS debt_token,
|
||||
SPLIT_PART(
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
),
|
||||
', ',
|
||||
2
|
||||
) AS collateral_token,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__events') }}
|
||||
WHERE event_address = '0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3'
|
||||
AND event_module = 'controller'
|
||||
AND event_resource LIKE 'LiquidateEvent%'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2024-01-05'
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_address,
|
||||
event_resource,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount,
|
||||
debt_token,
|
||||
collateral_token,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS lending_aries_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
_inserted_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM events
|
||||
@ -0,0 +1,87 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "lending_aries_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:receiver::string AS borrower, -- The person whose debt is being repaid
|
||||
CASE
|
||||
WHEN event_data:repay_amount::number > 0 THEN event_data:repay_amount::number
|
||||
WHEN event_data:deposit_amount::number > 0 THEN event_data:deposit_amount::number
|
||||
ELSE 0
|
||||
END AS amount,
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
) AS token_address,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__events') }}
|
||||
WHERE event_address = '0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3'
|
||||
AND event_module = 'controller'
|
||||
AND event_resource LIKE 'DepositRepayForEvent%'
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2024-01-05'
|
||||
{% endif %}
|
||||
),
|
||||
tx_sender AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
sender
|
||||
FROM {{ ref('silver__transactions') }}
|
||||
WHERE 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-01-05'
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
e.block_number,
|
||||
e.block_timestamp,
|
||||
e.version,
|
||||
e.tx_hash,
|
||||
e.event_index,
|
||||
e.event_address,
|
||||
t.sender AS payer,
|
||||
e.borrower,
|
||||
e.amount,
|
||||
e.token_address,
|
||||
e._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['e.tx_hash', 'e.event_index']) }} AS lending_aries_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM events e
|
||||
LEFT JOIN tx_sender t
|
||||
ON e.tx_hash = t.tx_hash
|
||||
AND e.block_timestamp::DATE = t.block_timestamp::DATE
|
||||
@ -0,0 +1,67 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = "lending_aries_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:sender::string AS depositor,
|
||||
event_data:withdraw_amount::number AS amount,
|
||||
SUBSTRING(
|
||||
event_type,
|
||||
POSITION('<' IN event_type) + 1,
|
||||
POSITION('>' IN event_type) - POSITION('<' IN event_type) - 1
|
||||
) AS token_address,
|
||||
_inserted_timestamp
|
||||
FROM {{ ref('silver__events') }}
|
||||
WHERE event_address = '0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3'
|
||||
AND event_module = 'controller'
|
||||
AND event_resource LIKE 'WithdrawEvent%'
|
||||
AND event_data:borrow_amount::number = 0 -- removes borrows
|
||||
AND event_data:withdraw_amount::number > 0
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2024-01-05'
|
||||
{% endif %}
|
||||
)
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
version,
|
||||
tx_hash,
|
||||
event_index,
|
||||
event_address,
|
||||
event_resource,
|
||||
depositor,
|
||||
amount,
|
||||
token_address,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS lending_aries_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
_inserted_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM events
|
||||
Loading…
Reference in New Issue
Block a user