mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 15:16:43 +00:00
AN-3837/add-evm-lending-protocols (#341)
* add aave v2 and comp v3 * add gold layer and docs * chain rename * fix gold * fix aave v2 * flashloan v2 fix * platform fix * fix table desc * remove old case when * AAVE TOKEN FIXES PR COMMENT UPDATES * tokens fix * fix test fails * quick flashloan doc fix * view column fix
This commit is contained in:
parent
d6f0e81552
commit
737b4d8cc9
@ -1,5 +0,0 @@
|
||||
{% docs borrower %}
|
||||
|
||||
Its the address of the user who is Borrowing or repaying the loan, depending on the action.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,381 @@
|
||||
{% docs complete_lending_borrow_rate_mode %}
|
||||
|
||||
The rate mode the user is swapping from. Stable: 1, Variable: 2. Borrowers can switch between the stable and variable rate at any time. Stable rates act as a fixed rate in the short-term, but can be re-balanced in the long-term in response to changes in market conditions. The variable rate is the rate based on the offer and demand. The stable rate, as its name indicates, will remain pretty stable and its the best option to plan how much interest you will have to pay. The variable rate will change over time and could be the optimal rate depending on market conditions.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_borrow_rate_stable %}
|
||||
|
||||
The stable interest rate for borrowing assets.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_borrow_rate_variable %}
|
||||
|
||||
The variable interest rate for borrowing assets.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_collateral_complete_lending_token %}
|
||||
|
||||
The interest bearing token that's burned when a liquidation occurs.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_collateral_asset %}
|
||||
|
||||
The asset provided as collateral, which can be liquidated.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_data_provider %}
|
||||
|
||||
The protocol data provider contract address.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_debt_complete_lending_token %}
|
||||
|
||||
The interest bearing token representing the debt.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_debt_asset %}
|
||||
|
||||
The debt asset, which the user borrowed.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_debt_to_cover_amount %}
|
||||
|
||||
The amount of debt the user must cover.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_debt_to_cover_amount_usd %}
|
||||
|
||||
The amount of debt the user must cover, valued in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_depositor_address %}
|
||||
|
||||
The depositor's address.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_end_voting_period %}
|
||||
|
||||
The block number in which the voting period ends.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloan_amount %}
|
||||
|
||||
The amount of assets flash loaned.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloan_amount_usd %}
|
||||
|
||||
The value of the flash loan amount, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_governance_contract %}
|
||||
|
||||
The governance contract address.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_initiator_address %}
|
||||
|
||||
The address that initiated the flash loan.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_issued_tokens %}
|
||||
|
||||
The amount of tokens that the user is depositing.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_lending_pool_contract %}
|
||||
|
||||
The address of the lending pool.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_liquidated_amount %}
|
||||
|
||||
The amount of asset liquidated.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_liquidated_amount_usd %}
|
||||
|
||||
The value of the liquidated asset, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_liquidator %}
|
||||
|
||||
The address that initiated the liquidation call.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_market %}
|
||||
|
||||
The asset contract for the applicable market.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_payer %}
|
||||
|
||||
The address that initiated the repayment.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_premium_amount %}
|
||||
|
||||
The flash loan fee, changeable via the normal governance process, decimal adjusted.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_premium_amount_usd %}
|
||||
|
||||
The flash loan fee, valued in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_proposal_id %}
|
||||
|
||||
The unique ID representing a proposal.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_proposal_tx %}
|
||||
|
||||
The transaction confirming a proposal submission.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_proposer %}
|
||||
|
||||
The user's address that submitted the proposal.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_repayed_tokens %}
|
||||
|
||||
The amount of tokens repaid.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_repayed_usd %}
|
||||
|
||||
The value of repaid tokens, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_stable_debt_token_address %}
|
||||
|
||||
Debt tokens are interest-accruing tokens that are minted and burned on borrow and repay, representing a debt to the protocol with a stable interest rate.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_start_voting_period %}
|
||||
|
||||
The block number in which the voting period begins.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_status %}
|
||||
|
||||
The proposal's status.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_supplied_usd %}
|
||||
|
||||
The value of the asset in USD that the user is depositing.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_supply_rate %}
|
||||
|
||||
The interest rate for supplying assets to the protocol.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_support %}
|
||||
|
||||
A value indicating their vote (For: true, Against: false).
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_target_address %}
|
||||
|
||||
The address receiving the flash loan.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_targets %}
|
||||
|
||||
List of the targeted addresses by proposal transactions.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_token %}
|
||||
|
||||
The interest bearing token contract.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_liquidity_token %}
|
||||
|
||||
The total supply of liquidity tokens.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_liquidity_usd %}
|
||||
|
||||
The total value of liquidity tokens, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_stable_debt_token %}
|
||||
|
||||
The total supply of debt tokens, representing a debt to the protocol with a stable interest rate.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_stable_debt_usd %}
|
||||
|
||||
The total USD value of debt tokens, representing a debt to the protocol with a stable interest rate.
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_variable_debt_token %}
|
||||
|
||||
The total supply of debt tokens, representing a debt to the protocol with a variable interest rate.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_total_variable_debt_usd %}
|
||||
|
||||
The total USD value of debt tokens, representing a debt to the protocol with a variable interest rate.
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_utilization_rate %}
|
||||
|
||||
The percentage of assets loaned out.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_variable_debt_token_address %}
|
||||
|
||||
Debt tokens are interest-accruing tokens that are minted and burned on borrow and repay, representing a debt to the protocol with a variable interest rate.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_version %}
|
||||
|
||||
The contract version. Example: Aave AMM, Aave v1, Aave v2
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_withdrawn_tokens %}
|
||||
|
||||
The amount of tokens withdrawn.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_withdrawn_usd %}
|
||||
|
||||
The value of withdrawn tokens, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_platform %}
|
||||
|
||||
The specific protocol where lending event occurred.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_protocol_token %}
|
||||
|
||||
The protocol's specific lending asset token, ie cWBTC or aETHUni.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_borrower %}
|
||||
|
||||
Address that initiated the borrow event.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_amount %}
|
||||
|
||||
The decimal adjusted amount of tokens involved in the lending transaction, where available.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_amount_usd %}
|
||||
|
||||
The value of the tokens in USD at the time of the lending transaction, where available.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_token_address %}
|
||||
|
||||
The address of the token associated with the lending action.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_token_symbol %}
|
||||
|
||||
The symbol of the token associated with the lending action.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_depositor %}
|
||||
|
||||
Address that initiated a deposit event.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_amount_unadj %}
|
||||
|
||||
The non-decimal adjusted amount of tokens involved in the lending transaction.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_premium_amount_unadj %}
|
||||
|
||||
The flash loan fee, changeable via the normal governance process, non-decimal adjusted.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloan_amount_unadj %}
|
||||
|
||||
The amount of assets flash loaned, non-decimal adjusted.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloan_token %}
|
||||
|
||||
The flashloaned token address.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloan_token_symbol %}
|
||||
|
||||
The flashloaned token symbol
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs borrower %}
|
||||
|
||||
Its the address of the user who is Borrowing or repaying the loan, depending on the action.
|
||||
|
||||
{% enddocs %}
|
||||
@ -0,0 +1,36 @@
|
||||
{% docs complete_lending_borrows_table_doc %}
|
||||
|
||||
This table contains transactions where users borrowed assets across AAVE and COMPOUND protocols. In order to borrow assets, a user must first deposit their preferred asset and amount as collateral.
|
||||
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_deposits_table_doc %}
|
||||
|
||||
This table contains deposit transactions across AAVE and COMPOUND protocols. A user deposits their preferred asset and amount. After depositing, users earn passive income based on the market borrowing demand. Additionally, depositing allows users to borrow by using their deposited assets as a collateral. Any interest earned by depositing funds helps offset the interest rate accumulated by borrowing.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_flashloans_table_doc %}
|
||||
|
||||
This table contains flash loan transactions across AAVE protocols. Flash loans are a feature designed for developers, due to the technical knowledge required to execute one. Flash Loans allow you to borrow any available amount of assets without providing any collateral, as long as the liquidity is returned to the protocol within one block transaction.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_liquidations_table_doc %}
|
||||
|
||||
This table contains transactions in which a borrower's collateral asset is liquidated across AAVE and COMPOUND protocols. Liquidations occur when a borrower's health factor goes below 1 due to their collateral value not properly covering their loan/debt value. This might happen when the collateral decreases in value or the borrowed debt increases in value against each other. This collateral vs loan value ratio is shown in the health factor. In a liquidation, up to 50% of a borrower's debt is repaid and that value + liquidation fee is taken from the collateral available, so after a liquidation the amount liquidated from one's debt is repaid.
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_repayments_table_doc %}
|
||||
|
||||
This table contains transactions in which a borrower repays their loan (debt) across the AAVE and COMPOUND protocols. Loans are repaid in the same asset borrowed, plus accrued interest. Borrowers can pay back their loan based on the USD price as they can borrow any of the available stable coins (USDC, DAI, USDT, etc.).
|
||||
|
||||
{% enddocs %}
|
||||
|
||||
{% docs complete_lending_withdraws_table_doc %}
|
||||
|
||||
This table contains transactions in which a user withdraws liquidity across the AAVE and COMPOUND protocols. Users need to make sure there is enough liquidity (not borrowed) in order to withdraw, if this is not the case, users need to wait for more liquidity from depositors or borrowers repaying.
|
||||
|
||||
{% enddocs %}
|
||||
@ -46,7 +46,12 @@ There is more information on how to use dbt docs in the last section of this doc
|
||||
- [dim_dex_liquidity_pools](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__dim_dex_liquidity_pools)
|
||||
- [ez_dex_swaps](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_dex_swaps)
|
||||
- [ez_bridge_activity](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_bridge_activity)
|
||||
|
||||
- [ez_borrows](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_borrows)
|
||||
- [ez_deposits](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_deposits)
|
||||
- [ez_flashloans](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_flashloans)
|
||||
- [ez_liquidations](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_liquidations)
|
||||
- [ez_repayments](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_repayments)
|
||||
- [ez_withdraws](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.defi__ez_withdraws)
|
||||
### NFT Tables (polygon.nft)
|
||||
- [ez_nft_mints](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.nft__ez_nft_mints)
|
||||
- [ez_nft_sales](https://flipsidecrypto.github.io/polygon-models/#!/model/model.polygon_models.nft__ez_nft_sales)
|
||||
|
||||
37
models/gold/defi/lending/defi__ez_lending_borrows.sql
Normal file
37
models/gold/defi/lending/defi__ez_lending_borrows.sql
Normal file
@ -0,0 +1,37 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND',
|
||||
'PURPOSE': 'LENDING, BORROWS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
borrower,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_borrows_id AS ez_lending_borrows_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_borrows') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_borrows.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_borrows.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_borrows
|
||||
description: '{{ doc("complete_lending_borrows_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("poly_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_BORROWS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
37
models/gold/defi/lending/defi__ez_lending_deposits.sql
Normal file
37
models/gold/defi/lending/defi__ez_lending_deposits.sql
Normal file
@ -0,0 +1,37 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND',
|
||||
'PURPOSE': 'LENDING, DEPOSITS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
protocol_market,
|
||||
depositor,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_deposits_id AS ez_lending_deposits_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_deposits') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_deposits.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_deposits.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_deposits
|
||||
description: '{{ doc("complete_lending_deposits_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: DEPOSITOR
|
||||
description: '{{ doc("complete_lending_depositor") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("poly_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_DEPOSITS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
41
models/gold/defi/lending/defi__ez_lending_flashloans.sql
Normal file
41
models/gold/defi/lending/defi__ez_lending_flashloans.sql
Normal file
@ -0,0 +1,41 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE',
|
||||
'PURPOSE': 'LENDING, FLASHLOANS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
initiator,
|
||||
target,
|
||||
protocol_market,
|
||||
flashloan_token,
|
||||
flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
premium_amount_usd,
|
||||
complete_lending_flashloans_id AS ez_lending_flashloans_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_flashloans') }}
|
||||
54
models/gold/defi/lending/defi__ez_lending_flashloans.yml
Normal file
54
models/gold/defi/lending/defi__ez_lending_flashloans.yml
Normal file
@ -0,0 +1,54 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_flashloans
|
||||
description: '{{ doc("complete_lending_flashloans_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: INITIATOR
|
||||
description: '{{ doc("complete_lending_initiator_address") }}'
|
||||
- name: TARGET
|
||||
description: '{{ doc("complete_lending_target_address") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: FLASHLOAN_TOKEN
|
||||
description: '{{ doc("complete_lending_flashloan_token") }}'
|
||||
- name: FLASHLOAN_TOKEN_SYMBOL
|
||||
description: '{{ doc("poly_symbol") }}'
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_flashloan_amount_unadj") }}'
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
description: '{{ doc("complete_lending_flashloan_amount") }}'
|
||||
- name: FLASHLOAN_AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_flashloan_amount_usd") }}'
|
||||
- name: PREMIUM_AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_premium_amount_unadj") }}'
|
||||
- name: PREMIUM_AMOUNT
|
||||
description: '{{ doc("complete_lending_premium_amount") }}'
|
||||
- name: PREMIUM_AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_premium_amount_usd") }}'
|
||||
- name: EZ_LENDING_FLASHLOANS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
40
models/gold/defi/lending/defi__ez_lending_liquidations.sql
Normal file
40
models/gold/defi/lending/defi__ez_lending_liquidations.sql
Normal file
@ -0,0 +1,40 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND',
|
||||
'PURPOSE': 'LENDING, LIQUIDATIONS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_market,
|
||||
collateral_token,
|
||||
collateral_token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
debt_token,
|
||||
debt_token_symbol,
|
||||
complete_lending_liquidations_id AS ez_lending_liquidations_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_liquidations') }}
|
||||
52
models/gold/defi/lending/defi__ez_lending_liquidations.yml
Normal file
52
models/gold/defi/lending/defi__ez_lending_liquidations.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_liquidations
|
||||
description: '{{ doc("complete_lending_liquidations_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: LIQUIDATOR
|
||||
description: '{{ doc("complete_lending_liquidator") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: COLLATERAL_TOKEN
|
||||
description: '{{ doc("complete_lending_collateral_asset") }}'
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
description: '{{ doc("poly_symbol") }}'
|
||||
- name: LIQUIDATED_AMOUNT_UNADJU
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: LIQUIDATED_AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: LIQUIDATED_AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: DEBT_TOKEN
|
||||
description: '{{ doc("complete_lending_debt_asset") }}'
|
||||
- name: DEBT_TOKEN_SYMBOL
|
||||
description: '{{ doc("poly_symbol") }}'
|
||||
- name: EZ_LENDING_LIQUDATIONS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
38
models/gold/defi/lending/defi__ez_lending_repayments.sql
Normal file
38
models/gold/defi/lending/defi__ez_lending_repayments.sql
Normal file
@ -0,0 +1,38 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND',
|
||||
'PURPOSE': 'LENDING, REPAYMENTS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
tx_hash,
|
||||
event_index,
|
||||
contract_address,
|
||||
event_name,
|
||||
platform,
|
||||
payer,
|
||||
borrower,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_repayments_id AS ez_lending_repayments_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_repayments') }}
|
||||
48
models/gold/defi/lending/defi__ez_lending_repayments.yml
Normal file
48
models/gold/defi/lending/defi__ez_lending_repayments.yml
Normal file
@ -0,0 +1,48 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_repayments
|
||||
description: '{{ doc("complete_lending_repayments_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: PAYER
|
||||
description: '{{ doc("complete_lending_payer") }}'
|
||||
- name: BORROWER
|
||||
description: '{{ doc("complete_lending_borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("complete_lending_token_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_REPAYMENTS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
37
models/gold/defi/lending/defi__ez_lending_withdraws.sql
Normal file
37
models/gold/defi/lending/defi__ez_lending_withdraws.sql
Normal file
@ -0,0 +1,37 @@
|
||||
{{ config(
|
||||
materialized = 'view',
|
||||
persist_docs ={ "relation": true,
|
||||
"columns": true },
|
||||
meta={
|
||||
'database_tags':{
|
||||
'table': {
|
||||
'PROTOCOL': 'AAVE, COMPOUND',
|
||||
'PURPOSE': 'LENDING, WITHDRAWS'
|
||||
}
|
||||
}
|
||||
}
|
||||
) }}
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
tx_hash,
|
||||
contract_address,
|
||||
event_name,
|
||||
event_index,
|
||||
origin_function_signature,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
platform,
|
||||
depositor,
|
||||
protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
amount_usd,
|
||||
complete_lending_withdraws_id AS ez_lending_withdraws_id,
|
||||
inserted_timestamp,
|
||||
modified_timestamp
|
||||
FROM
|
||||
{{ ref('silver__complete_lending_withdraws') }}
|
||||
46
models/gold/defi/lending/defi__ez_lending_withdraws.yml
Normal file
46
models/gold/defi/lending/defi__ez_lending_withdraws.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: defi__ez_lending_withdraws
|
||||
description: '{{ doc("complete_lending_withdraws_table_doc") }}'
|
||||
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
description: '{{ doc("poly_block_number") }}'
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: '{{ doc("poly_block_timestamp") }}'
|
||||
- name: TX_HASH
|
||||
description: '{{ doc("poly_logs_tx_hash") }}'
|
||||
- name: CONTRACT_ADDRESS
|
||||
description: '{{ doc("poly_logs_contract_address") }}'
|
||||
- name: EVENT_NAME
|
||||
description: '{{ doc("poly_event_name") }}'
|
||||
- name: EVENT_INDEX
|
||||
description: '{{ doc("poly_event_index") }}'
|
||||
- name: ORIGIN_FUNCTION_SIGNATURE
|
||||
description: '{{ doc("nft_origin_sig") }}'
|
||||
- name: ORIGIN_FROM_ADDRESS
|
||||
description: '{{ doc("poly_origin_from") }}'
|
||||
- name: ORIGIN_TO_ADDRESS
|
||||
description: '{{ doc("poly_origin_to") }}'
|
||||
- name: PLATFORM
|
||||
description: '{{ doc("complete_lending_platform") }}'
|
||||
- name: DEPOSITOR
|
||||
description: '{{ doc("borrower") }}'
|
||||
- name: PROTOCOL_MARKET
|
||||
description: '{{ doc("complete_lending_protocol_token") }}'
|
||||
- name: TOKEN_ADDRESS
|
||||
description: '{{ doc("complete_lending_token_address") }}'
|
||||
- name: TOKEN_SYMBOL
|
||||
description: '{{ doc("complete_lending_token_symbol") }}'
|
||||
- name: AMOUNT_UNADJ
|
||||
description: '{{ doc("complete_lending_amount_unadj") }}'
|
||||
- name: AMOUNT
|
||||
description: '{{ doc("complete_lending_amount") }}'
|
||||
- name: AMOUNT_USD
|
||||
description: '{{ doc("complete_lending_amount_usd") }}'
|
||||
- name: EZ_LENDING_WITHDRAWS_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
121
models/silver/defi/lending/aave/silver__aave_borrows.sql
Normal file
121
models/silver/defi/lending/aave/silver__aave_borrows.sql
Normal file
@ -0,0 +1,121 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH --borrows from Aave LendingPool contracts
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
borrow AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS onBehalfOf,
|
||||
utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER AS refferal,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 25, 40)) AS userAddress,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS borrow_quantity,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [2] :: STRING
|
||||
) :: INTEGER AS borrow_rate_mode,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [3] :: STRING
|
||||
) :: INTEGER AS borrowrate,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
origin_from_address AS borrower_address,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xc6a898309e823ee50bac64e45ca8adba6690e99e7841c45d754e2a38e9019d9b',
|
||||
'0xb3d084820fb1a9decffb176436bd02558d15fac9b0ddfed8c465bc7359d7dce0'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market,
|
||||
atoken_meta.atoken_address AS aave_token,
|
||||
borrow_quantity AS amount_unadj,
|
||||
borrow_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
borrower_address,
|
||||
CASE
|
||||
WHEN borrow_rate_mode = 2 THEN 'Variable Rate'
|
||||
ELSE 'Stable Rate'
|
||||
END AS borrow_rate_mode,
|
||||
lending_pool_contract,
|
||||
aave_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
atoken_meta.underlying_decimals AS underlying_decimals,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
borrow
|
||||
LEFT JOIN atoken_meta
|
||||
ON borrow.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
52
models/silver/defi/lending/aave/silver__aave_borrows.yml
Normal file
52
models/silver/defi/lending/aave/silver__aave_borrows.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: BORROWER_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROW_RATE_MODE
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
110
models/silver/defi/lending/aave/silver__aave_deposits.sql
Normal file
110
models/silver/defi/lending/aave/silver__aave_deposits.sql
Normal file
@ -0,0 +1,110 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
deposits AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS onBehalfOf,
|
||||
utils.udf_hex_to_int(
|
||||
topics [3] :: STRING
|
||||
) :: INTEGER AS refferal,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 42)) AS userAddress,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS deposit_quantity,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
origin_from_address AS depositor_address,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xde6857219544bb5b7746f48ed30be6386fefc61b2f864cacf559893bf50fd951',
|
||||
'0x2b627736bca15cd5381dcf80b0bf11fd197d01a037c52b927a881a10fb73ba61'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market,
|
||||
atoken_meta.atoken_address AS aave_token,
|
||||
deposit_quantity AS amount_unadj,
|
||||
deposit_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
depositor_address,
|
||||
lending_pool_contract,
|
||||
aave_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
deposits
|
||||
LEFT JOIN atoken_meta
|
||||
ON deposits.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
48
models/silver/defi/lending/aave/silver__aave_deposits.yml
Normal file
48
models/silver/defi/lending/aave/silver__aave_deposits.yml
Normal file
@ -0,0 +1,48 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
122
models/silver/defi/lending/aave/silver__aave_flashloans.sql
Normal file
122
models/silver/defi/lending/aave/silver__aave_flashloans.sql
Normal file
@ -0,0 +1,122 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
flashloan AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS target_address,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS initiator_address,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40))
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40))
|
||||
ELSE NULL
|
||||
END AS aave_market,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN utils.udf_hex_to_int(segmented_data [1] :: STRING) :: INTEGER
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN utils.udf_hex_to_int(segmented_data [0] :: STRING) :: INTEGER
|
||||
ELSE NULL
|
||||
END AS flashloan_quantity,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN utils.udf_hex_to_int(segmented_data [2] :: STRING) :: INTEGER
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN utils.udf_hex_to_int(segmented_data [1] :: STRING) :: INTEGER
|
||||
ELSE NULL
|
||||
END AS premium_quantity,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xefefaba5e921573100900a3ad9cf29f222d995fb3b6045797eaea7521bd8d6f0', --v3
|
||||
'0x631042c832b07452973831137f2d73e395028b44b250dedc5abb0ee766e168ac' --v2
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market,
|
||||
atoken_meta.atoken_address AS aave_token,
|
||||
flashloan_quantity AS flashloan_amount_unadj,
|
||||
flashloan_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS flashloan_amount,
|
||||
premium_quantity AS premium_amount_unadj,
|
||||
premium_quantity / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS premium_amount,
|
||||
initiator_address AS initiator_address,
|
||||
target_address AS target_address,
|
||||
aave_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
flashloan
|
||||
LEFT JOIN atoken_meta
|
||||
ON flashloan.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
49
models/silver/defi/lending/aave/silver__aave_flashloans.yml
Normal file
49
models/silver/defi/lending/aave/silver__aave_flashloans.yml
Normal file
@ -0,0 +1,49 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: INITIATOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TARGET_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
115
models/silver/defi/lending/aave/silver__aave_liquidations.sql
Normal file
115
models/silver/defi/lending/aave/silver__aave_liquidations.sql
Normal file
@ -0,0 +1,115 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
liquidation AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS collateral_asset,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS debt_asset,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS borrower_address,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS debt_to_cover_amount,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS liquidated_amount,
|
||||
CONCAT('0x', SUBSTR(segmented_data [2] :: STRING, 25, 40)) AS liquidator_address,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0xe413a321e8681d831f4dbccbca790d2952b56f977908e45be37335533e005286',
|
||||
'0x56864757fd5b1fc9f38f5f3a981cd8ae512ce41b902cf73fc506ee369c6bc237'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
collateral_asset,
|
||||
amc.atoken_address AS collateral_aave_token,
|
||||
liquidated_amount AS amount_unadj,
|
||||
liquidated_amount / pow(
|
||||
10,
|
||||
amc.atoken_decimals
|
||||
) AS amount,
|
||||
debt_asset,
|
||||
amd.atoken_address AS debt_aave_token,
|
||||
liquidator_address AS liquidator,
|
||||
borrower_address AS borrower,
|
||||
aave_version AS platform,
|
||||
amc.underlying_symbol AS collateral_token_symbol,
|
||||
amd.underlying_symbol AS debt_token_symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
liquidation
|
||||
LEFT JOIN atoken_meta amc
|
||||
ON liquidation.collateral_asset = amc.underlying_address
|
||||
LEFT JOIN atoken_meta amd
|
||||
ON liquidation.debt_asset = amd.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,53 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_AAVE_TOKEN
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEBT_AAVE_TOKEN
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
108
models/silver/defi/lending/aave/silver__aave_repayments.sql
Normal file
108
models/silver/defi/lending/aave/silver__aave_repayments.sql
Normal file
@ -0,0 +1,108 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
repay AS(
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower_address,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS repayer,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS repayed_amount,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
origin_from_address AS repayer_address,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x4cdde6e09bb755c9a5589ebaec640bbfedff1362d4b255ebf8339782b9942faa',
|
||||
'0xa534c8dbe71f871f9f3530e97a74601fea17b426cae02e1c5aee42c96c784051'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market,
|
||||
atoken_meta.atoken_address AS aave_token,
|
||||
repayed_amount AS amount_unadj,
|
||||
repayed_amount / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
repayer_address AS payer,
|
||||
borrower_address AS borrower,
|
||||
lending_pool_contract,
|
||||
aave_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
repay
|
||||
LEFT JOIN atoken_meta
|
||||
ON repay.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
52
models/silver/defi/lending/aave/silver__aave_repayments.yml
Normal file
52
models/silver/defi/lending/aave/silver__aave_repayments.yml
Normal file
@ -0,0 +1,52 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: LENDING_POOL_CONTRACT
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
280
models/silver/defi/lending/aave/silver__aave_tokens.sql
Normal file
280
models/silver/defi/lending/aave/silver__aave_tokens.sql
Normal file
@ -0,0 +1,280 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
tags = ['curated']
|
||||
) }}
|
||||
|
||||
WITH contracts as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contracts') }}
|
||||
),
|
||||
LOGS AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
block_number > 11182261
|
||||
AND
|
||||
origin_function_signature in (
|
||||
'0x0c14caef',
|
||||
'0xcef84c51',
|
||||
'0xfe0d94c1',
|
||||
'0x02fb45e6',
|
||||
'0x7bbaf1ea'
|
||||
)
|
||||
AND
|
||||
tx_status = 'SUCCESS'
|
||||
AND
|
||||
topics [0] IN
|
||||
(
|
||||
'0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b',
|
||||
'0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f'
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
),
|
||||
DECODE AS (
|
||||
|
||||
SELECT
|
||||
block_number AS atoken_created_block,
|
||||
origin_from_address AS token_creator_address,
|
||||
contract_address AS a_token_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS underlying_asset,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS aave_version_pool,
|
||||
utils.udf_hex_to_int(
|
||||
SUBSTR(
|
||||
segmented_data [2] :: STRING,
|
||||
27,
|
||||
40
|
||||
)
|
||||
) :: INTEGER AS atoken_decimals,
|
||||
utils.udf_hex_to_string (
|
||||
segmented_data [7] :: STRING
|
||||
) :: STRING AS atoken_name,
|
||||
utils.udf_hex_to_string (
|
||||
segmented_data [9] :: STRING
|
||||
) :: STRING AS atoken_symbol,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
LOGS
|
||||
l
|
||||
WHERE
|
||||
topics [0] = '0xb19e051f8af41150ccccb3fc2c2d8d15f4a4cf434f32a559ba75fe73d6eea20b'
|
||||
AND
|
||||
aave_version_pool IN
|
||||
('0x794a61358d6845594f94dc1db02a252b5b4814ad',
|
||||
'0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf')
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
WHERE
|
||||
atoken_version = 'Aave V3'
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
a_token_step_1 AS (
|
||||
SELECT
|
||||
atoken_created_block,
|
||||
token_creator_address,
|
||||
a_token_address,
|
||||
segmented_data,
|
||||
underlying_asset,
|
||||
aave_version_pool,
|
||||
atoken_decimals,
|
||||
atoken_name,
|
||||
atoken_symbol,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
DECODE
|
||||
WHERE
|
||||
atoken_name LIKE '%Aave%'
|
||||
),
|
||||
debt_tokens AS (
|
||||
SELECT
|
||||
block_number AS atoken_created_block,
|
||||
contract_address AS a_token_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS underlying_asset,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS atoken_address,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address,
|
||||
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
LOGS
|
||||
WHERE
|
||||
topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f'
|
||||
AND CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) IN (
|
||||
SELECT
|
||||
a_token_address
|
||||
FROM
|
||||
a_token_step_1
|
||||
)
|
||||
),
|
||||
a_token_step_2 AS (
|
||||
SELECT
|
||||
atoken_created_block,
|
||||
token_creator_address,
|
||||
a_token_address,
|
||||
segmented_data,
|
||||
underlying_asset,
|
||||
aave_version_pool,
|
||||
atoken_decimals,
|
||||
atoken_name,
|
||||
atoken_symbol,
|
||||
_inserted_timestamp,
|
||||
_log_id,
|
||||
CASE
|
||||
WHEN aave_version_pool = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN aave_version_pool = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'Error'
|
||||
END AS protocol
|
||||
FROM
|
||||
a_token_step_1
|
||||
),
|
||||
aave_token_pull AS (
|
||||
SELECT
|
||||
block_number AS atoken_created_block,
|
||||
origin_from_address as token_creator_address,
|
||||
'0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' as aave_version_pool,
|
||||
C.token_symbol AS a_token_symbol,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS a_token_address,
|
||||
CONCAT('0x', SUBSTR(segmented_data [0] :: STRING, 27, 40)) :: STRING AS atoken_stable_debt_address,
|
||||
CONCAT('0x', SUBSTR(segmented_data [1] :: STRING, 27, 40)) :: STRING AS atoken_variable_debt_address,
|
||||
C.token_decimals AS a_token_decimals,
|
||||
'Aave V2' AS aave_version,
|
||||
C.token_name AS a_token_name,
|
||||
c2.token_symbol AS underlying_symbol,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS underlying_address,
|
||||
c2.token_name AS underlying_name,
|
||||
c2.token_decimals AS underlying_decimals,
|
||||
l._inserted_timestamp,
|
||||
l._log_id
|
||||
FROM
|
||||
LOGS
|
||||
l
|
||||
LEFT JOIN contracts C
|
||||
ON a_token_address = C.contract_address
|
||||
LEFT JOIN contracts c2
|
||||
ON underlying_address = c2.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x3a0ca721fc364424566385a1aa271ed508cc2c0949c2272575fb3013a163a45f'
|
||||
AND (
|
||||
a_token_name LIKE '%Aave%'
|
||||
OR c2.token_symbol = 'GHO'
|
||||
)
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
WHERE
|
||||
atoken_version = 'Aave V2'
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
aave_token_pull_2 AS (
|
||||
SELECT
|
||||
atoken_created_block,
|
||||
aave_version_pool,
|
||||
a_token_symbol,
|
||||
a_token_address,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address,
|
||||
a_token_decimals,
|
||||
aave_version,
|
||||
a_token_name,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
underlying_address,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
aave_token_pull
|
||||
),
|
||||
|
||||
aave_backfill_1 as (
|
||||
SELECT
|
||||
atoken_created_block,
|
||||
aave_version_pool,
|
||||
a_token_symbol AS atoken_symbol,
|
||||
a_token_address AS atoken_address,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address,
|
||||
a_token_decimals AS atoken_decimals,
|
||||
aave_version AS atoken_version,
|
||||
a_token_name AS atoken_name,
|
||||
underlying_symbol,
|
||||
underlying_address,
|
||||
underlying_decimals,
|
||||
underlying_name,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
aave_token_pull_2
|
||||
)
|
||||
SELECT
|
||||
A.atoken_created_block,
|
||||
a.aave_version_pool,
|
||||
A.atoken_symbol AS atoken_symbol,
|
||||
A.a_token_address AS atoken_address,
|
||||
b.atoken_stable_debt_address,
|
||||
b.atoken_variable_debt_address,
|
||||
A.atoken_decimals AS atoken_decimals,
|
||||
A.protocol AS atoken_version,
|
||||
atoken_name AS atoken_name,
|
||||
C.token_symbol AS underlying_symbol,
|
||||
A.underlying_asset AS underlying_address,
|
||||
C.token_decimals AS underlying_decimals,
|
||||
C.token_name AS underlying_name,
|
||||
A._inserted_timestamp,
|
||||
A._log_id
|
||||
FROM
|
||||
a_token_step_2 A
|
||||
INNER JOIN debt_tokens b
|
||||
ON A.a_token_address = b.atoken_address
|
||||
INNER JOIN contracts C
|
||||
ON contract_address = A.underlying_asset
|
||||
UNION ALL
|
||||
SELECT
|
||||
atoken_created_block,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_address,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address,
|
||||
atoken_decimals,
|
||||
atoken_version,
|
||||
atoken_name,
|
||||
underlying_symbol,
|
||||
underlying_address,
|
||||
underlying_decimals,
|
||||
underlying_name,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
aave_backfill_1
|
||||
105
models/silver/defi/lending/aave/silver__aave_withdraws.sql
Normal file
105
models/silver/defi/lending/aave/silver__aave_withdraws.sql
Normal file
@ -0,0 +1,105 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
atoken_meta AS (
|
||||
SELECT
|
||||
atoken_address,
|
||||
aave_version_pool,
|
||||
atoken_symbol,
|
||||
atoken_name,
|
||||
atoken_decimals,
|
||||
underlying_address,
|
||||
underlying_symbol,
|
||||
underlying_name,
|
||||
underlying_decimals,
|
||||
atoken_version,
|
||||
atoken_created_block,
|
||||
atoken_stable_debt_address,
|
||||
atoken_variable_debt_address
|
||||
FROM
|
||||
{{ ref('silver__aave_tokens') }}
|
||||
),
|
||||
withdraw AS(
|
||||
|
||||
SELECT
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS aave_market,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS useraddress,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS depositor,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS withdraw_amount,
|
||||
tx_hash,
|
||||
CASE
|
||||
WHEN contract_address = '0x794a61358d6845594f94dc1db02a252b5b4814ad' THEN 'Aave V3'
|
||||
WHEN contract_address = '0x8dff5e27ea6b7ac08ebfdf9eb090f32ee9a30fcf' THEN 'Aave V2'
|
||||
ELSE 'ERROR'
|
||||
END AS aave_version,
|
||||
COALESCE(
|
||||
origin_to_address,
|
||||
contract_address
|
||||
) AS lending_pool_contract,
|
||||
_inserted_timestamp,
|
||||
_log_id
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
WHERE
|
||||
topics [0] :: STRING IN (
|
||||
'0x3115d1449a7b732c986cba18244e897a450f61e1bb8d589cd2e69e6c8924f9f7',
|
||||
'0x9c4ed599cd8555b9c1e8cd7643240d7d71eb76b792948c49fcb4d411f7b6b3c6'
|
||||
)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
AND contract_address IN (SELECT distinct(aave_version_pool) from atoken_meta)
|
||||
AND tx_status = 'SUCCESS' --excludes failed txs
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market,
|
||||
atoken_meta.atoken_address AS aave_token,
|
||||
withdraw_amount AS amount_unadj,
|
||||
withdraw_amount / pow(
|
||||
10,
|
||||
atoken_meta.underlying_decimals
|
||||
) AS amount,
|
||||
depositor depositor_address,
|
||||
aave_version AS platform,
|
||||
atoken_meta.underlying_symbol AS symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
withdraw
|
||||
LEFT JOIN atoken_meta
|
||||
ON withdraw.aave_market = atoken_meta.underlying_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
46
models/silver/defi/lending/aave/silver__aave_withdraws.yml
Normal file
46
models/silver/defi/lending/aave/silver__aave_withdraws.yml
Normal file
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__aave_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: AAVE_TOKEN
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
@ -0,0 +1,144 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower_address AS borrower,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'polygon' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_borrows') }} A
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
borrower,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
compound_version AS platform,
|
||||
'polygon' AS blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_borrows') }}
|
||||
A
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
),
|
||||
borrow_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
b.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'Withdraw'
|
||||
ELSE 'Borrow'
|
||||
END AS event_name,
|
||||
borrower,
|
||||
protocol_market,
|
||||
b.token_address,
|
||||
b.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
b._LOG_ID,
|
||||
b._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
borrow_union b
|
||||
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
ON b.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON b.token_address = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_borrows_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,55 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -0,0 +1,139 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
depositor_address,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
compound_version AS platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_deposits') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
deposit_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'SupplyCollateral'
|
||||
WHEN platform = 'Aave V3' THEN 'Supply'
|
||||
ELSE 'Deposit'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
deposit_union A
|
||||
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_deposits_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,55 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -0,0 +1,108 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market AS token_address,
|
||||
aave_token AS protocol_token,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
initiator_address,
|
||||
target_address,
|
||||
platform,
|
||||
symbol,
|
||||
blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_flashloans') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
flashloan_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
),
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
f.contract_address,
|
||||
'FlashLoan' AS event_name,
|
||||
protocol_token AS protocol_market,
|
||||
initiator_address AS initiator,
|
||||
target_address AS target,
|
||||
f.token_address AS flashloan_token,
|
||||
token_symbol AS flashloan_token_symbol,
|
||||
flashloan_amount_unadj,
|
||||
flashloan_amount,
|
||||
ROUND(
|
||||
flashloan_amount * price,
|
||||
2
|
||||
) AS flashloan_amount_usd,
|
||||
premium_amount_unadj,
|
||||
premium_amount,
|
||||
ROUND(
|
||||
premium_amount * price,
|
||||
2
|
||||
) AS premium_amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
f._LOG_ID,
|
||||
f._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
flashloan_union f
|
||||
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
ON f.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON f.token_address = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_flashloans_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,54 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_flashloans
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 60
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: INITIATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TARGET
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: FLASHLOAN_AMOUNT
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: FLASHLOAN_AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -0,0 +1,188 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
NULL AS liquidated_amount_usd,
|
||||
collateral_aave_token AS protocol_collateral_asset,
|
||||
collateral_asset,
|
||||
collateral_token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_token_symbol AS debt_asset_symbol,
|
||||
platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_liquidations') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
absorber AS liquidator,
|
||||
borrower,
|
||||
amount_unadj,
|
||||
amount AS liquidated_amount,
|
||||
amount_usd AS liquidated_amount_usd,
|
||||
compound_market AS protocol_collateral_asset,
|
||||
token_address AS collateral_asset,
|
||||
token_symbol AS collateral_asset_symbol,
|
||||
debt_asset,
|
||||
debt_asset_symbol,
|
||||
l.compound_version AS platform,
|
||||
'polygon' AS blockchain,
|
||||
l._LOG_ID,
|
||||
l._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_liquidations') }}
|
||||
l
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
liquidation_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
|
||||
contracts AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__contracts') }} C
|
||||
WHERE
|
||||
C.contract_address IN (
|
||||
SELECT
|
||||
DISTINCT(collateral_asset) AS asset
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
),
|
||||
prices AS (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
WHERE
|
||||
token_address IN (
|
||||
SELECT
|
||||
DISTINCT(collateral_asset) AS asset
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
AND HOUR > (
|
||||
SELECT
|
||||
MIN(block_timestamp)
|
||||
FROM
|
||||
liquidation_union
|
||||
)
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'AbsorbCollateral'
|
||||
ELSE 'LiquidationCall'
|
||||
END AS event_name,
|
||||
liquidator,
|
||||
borrower,
|
||||
protocol_collateral_asset AS protocol_market,
|
||||
collateral_asset AS collateral_token,
|
||||
collateral_asset_symbol AS collateral_token_symbol,
|
||||
amount_unadj,
|
||||
liquidated_amount AS amount,
|
||||
CASE
|
||||
WHEN platform <> 'Compound V3' THEN ROUND(
|
||||
liquidated_amount * p.price,
|
||||
2
|
||||
)
|
||||
ELSE ROUND(
|
||||
liquidated_amount_usd,
|
||||
2
|
||||
)
|
||||
END AS amount_usd,
|
||||
debt_asset AS debt_token,
|
||||
debt_asset_symbol AS debt_token_symbol,
|
||||
platform,
|
||||
A.blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
liquidation_union A
|
||||
LEFT JOIN prices p
|
||||
ON collateral_asset = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN contracts C
|
||||
ON collateral_asset = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_liquidations_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,58 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 60
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: LIQUIDATOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN
|
||||
tests:
|
||||
- not_null
|
||||
- name: COLLATERAL_TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -0,0 +1,140 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_market AS token_address,
|
||||
aave_token AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
symbol AS token_symbol,
|
||||
payer AS payer_address,
|
||||
borrower,
|
||||
platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_repayments') }}
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
token_address,
|
||||
compound_market AS protocol_market,
|
||||
amount_unadj,
|
||||
amount,
|
||||
token_symbol,
|
||||
repayer AS payer_address,
|
||||
borrower,
|
||||
compound_version AS platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_repayments') }}
|
||||
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
repayments_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'Supply'
|
||||
ELSE 'Repay'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
payer_address AS payer,
|
||||
borrower,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
A._LOG_ID,
|
||||
A._INSERTED_TIMESTAMP
|
||||
FROM
|
||||
repayments_union A
|
||||
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_repayments_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,58 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: PAYER
|
||||
tests:
|
||||
- not_null:
|
||||
where: PLATFORM <> 'Silo'
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -0,0 +1,142 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = ['block_number','platform'],
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['reorg','curated']
|
||||
) }}
|
||||
|
||||
WITH aave AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
aave_token AS protocol_market,
|
||||
aave_market AS token_address,
|
||||
symbol AS token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__aave_withdraws') }}
|
||||
|
||||
{% if is_incremental() and 'aave' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
comp as (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
compound_market AS protocol_market,
|
||||
token_address,
|
||||
token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
depositor_address,
|
||||
compound_version AS platform,
|
||||
'polygon' AS blockchain,
|
||||
_LOG_ID,
|
||||
_INSERTED_TIMESTAMP
|
||||
FROM
|
||||
{{ ref('silver__comp_withdraws') }}
|
||||
{% if is_incremental() and 'comp' not in var('HEAL_CURATED_MODEL') %}
|
||||
WHERE
|
||||
_inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '36 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
),
|
||||
withdraws_union as (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
aave
|
||||
UNION ALL
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
comp
|
||||
),
|
||||
|
||||
FINAL AS (
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
A.contract_address,
|
||||
CASE
|
||||
WHEN platform = 'Compound V3' THEN 'WithdrawCollateral'
|
||||
ELSE 'Withdraw'
|
||||
END AS event_name,
|
||||
protocol_market,
|
||||
depositor_address AS depositor,
|
||||
A.token_address,
|
||||
A.token_symbol,
|
||||
amount_unadj,
|
||||
amount,
|
||||
ROUND(
|
||||
amount * price,
|
||||
2
|
||||
) AS amount_usd,
|
||||
platform,
|
||||
blockchain,
|
||||
A._log_id,
|
||||
A._inserted_timestamp
|
||||
FROM
|
||||
withdraws_union A
|
||||
LEFT JOIN {{ ref('price__ez_hourly_token_prices') }}
|
||||
p
|
||||
ON A.token_address = p.token_address
|
||||
AND DATE_TRUNC(
|
||||
'hour',
|
||||
block_timestamp
|
||||
) = p.hour
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON A.token_address = C.contract_address
|
||||
)
|
||||
SELECT
|
||||
*,
|
||||
{{ dbt_utils.generate_surrogate_key(
|
||||
['tx_hash','event_index']
|
||||
) }} AS complete_lending_withdraws_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,56 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__complete_lending_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 30
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROTOCOL_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_USD
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- decimal
|
||||
- float
|
||||
- name: PLATFORM
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
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
|
||||
97
models/silver/defi/lending/compound/silver__comp_borrows.sql
Normal file
97
models/silver/defi/lending/compound/silver__comp_borrows.sql
Normal file
@ -0,0 +1,97 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_asset_name,
|
||||
underlying_asset_symbol,
|
||||
underlying_asset_decimals
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
borrow AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
contract_address AS asset,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS src_address,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS to_address,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS borrow_amount,
|
||||
origin_from_address AS borrower_address,
|
||||
'Compound V3' AS compound_version,
|
||||
C.compound_market_name AS NAME,
|
||||
C.compound_market_symbol AS symbol,
|
||||
C.compound_market_decimals AS decimals,
|
||||
C.underlying_asset_address,
|
||||
C.underlying_asset_symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
LEFT JOIN comp_assets C
|
||||
ON asset = C.compound_market_address
|
||||
WHERE
|
||||
topics [0] = '0x9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb' --withdrawl
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
w.asset AS compound_market,
|
||||
borrower_address AS borrower,
|
||||
w.underlying_asset_address AS token_address,
|
||||
w.underlying_asset_symbol AS token_symbol,
|
||||
borrow_amount AS amount_unadj,
|
||||
borrow_amount / pow(
|
||||
10,
|
||||
w.decimals
|
||||
) AS amount,
|
||||
w.symbol AS itoken_symbol,
|
||||
compound_version,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
borrow w qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
47
models/silver/defi/lending/compound/silver__comp_borrows.yml
Normal file
47
models/silver/defi/lending/compound/silver__comp_borrows.yml
Normal file
@ -0,0 +1,47 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_borrows
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_MARKET
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
@ -0,0 +1,94 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_asset_name,
|
||||
underlying_asset_symbol,
|
||||
underlying_asset_decimals
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
|
||||
supply AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
l.contract_address AS compound_market,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS supply_amount,
|
||||
origin_from_address AS depositor_address,
|
||||
'Compound V3' AS compound_version,
|
||||
C.contract_address AS underlying_asset_address,
|
||||
C.token_name,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xfa56f7b24f17183d81894d3ac2ee654e3c26388d17a28dbd9549b8114304e1f4' --SupplyCollateral
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
compound_market,
|
||||
depositor_address,
|
||||
asset AS token_address,
|
||||
token_symbol AS token_symbol,
|
||||
supply_amount AS amount_unadj,
|
||||
supply_amount / pow(
|
||||
10,
|
||||
w.token_decimals
|
||||
) AS amount,
|
||||
compound_version,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
supply w qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_deposits
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_MARKET
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
- name: SYMBOL
|
||||
- not_null
|
||||
@ -0,0 +1,108 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_asset_name,
|
||||
underlying_asset_symbol,
|
||||
underlying_asset_decimals
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
|
||||
liquidations AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
l.contract_address AS compound_market,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS asset,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS absorber,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS collateral_absorbed,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS usd_value,
|
||||
origin_from_address AS depositor_address,
|
||||
'Compound V3' AS compound_version,
|
||||
C.token_name,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON asset = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0x9850ab1af75177e4a9201c65a2cf7976d5d28e40ef63494b44366f86b2f9412e' --AbsorbCollateral
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
l.contract_address,
|
||||
compound_market,
|
||||
absorber,
|
||||
borrower,
|
||||
depositor_address,
|
||||
asset AS token_address,
|
||||
token_symbol,
|
||||
collateral_absorbed AS amount_unadj,
|
||||
collateral_absorbed / pow(
|
||||
10,
|
||||
token_decimals
|
||||
) AS amount,
|
||||
usd_value / pow(
|
||||
10,
|
||||
8
|
||||
) AS amount_usd,
|
||||
A.underlying_asset_address AS debt_asset,
|
||||
A.underlying_asset_symbol AS debt_asset_symbol,
|
||||
compound_version,
|
||||
blockchain,
|
||||
l._log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
liquidations l
|
||||
LEFT JOIN comp_assets A
|
||||
ON l.compound_market = A.compound_market_address qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,61 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_liquidations
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCKCHAIN
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_MARKET
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: ABSORBER
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_match_regex:
|
||||
regex: 0[xX][0-9a-fA-F]+
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_ASSET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEBT_ASSET_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
101
models/silver/defi/lending/compound/silver__comp_repayments.sql
Normal file
101
models/silver/defi/lending/compound/silver__comp_repayments.sql
Normal file
@ -0,0 +1,101 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_asset_name,
|
||||
underlying_asset_symbol,
|
||||
underlying_asset_decimals
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
repayments AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
l.contract_address AS asset,
|
||||
CONCAT('0x', SUBSTR(topics [1] :: STRING, 27, 40)) AS repayer,
|
||||
CONCAT('0x', SUBSTR(topics [2] :: STRING, 27, 40)) AS borrower,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS amount,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [1] :: STRING
|
||||
) :: INTEGER AS usd_value,
|
||||
origin_from_address AS depositor,
|
||||
'Compound V3' AS compound_version,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
C.underlying_asset_address AS underlying_asset,
|
||||
C.underlying_asset_symbol,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
LEFT JOIN comp_assets C
|
||||
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)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
w.asset AS compound_market,
|
||||
repayer,
|
||||
borrower,
|
||||
depositor,
|
||||
underlying_asset AS token_address,
|
||||
w.underlying_asset_symbol AS token_symbol,
|
||||
amount AS amount_unadj,
|
||||
amount / pow(
|
||||
10,
|
||||
w.compound_market_decimals
|
||||
) AS amount,
|
||||
compound_version,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
repayments w qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,46 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_repayments
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: REPAYER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BORROWER
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
@ -0,0 +1,94 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
unique_key = "block_number",
|
||||
cluster_by = ['block_timestamp::DATE'],
|
||||
tags = ['curated','reorg']
|
||||
) }}
|
||||
|
||||
|
||||
WITH
|
||||
comp_assets as (
|
||||
SELECT
|
||||
compound_market_address,
|
||||
compound_market_name,
|
||||
compound_market_symbol,
|
||||
compound_market_decimals,
|
||||
underlying_asset_address,
|
||||
underlying_asset_name,
|
||||
underlying_asset_symbol,
|
||||
underlying_asset_decimals
|
||||
FROM
|
||||
{{ ref('silver__comp_asset_details') }}
|
||||
),
|
||||
withdraw AS (
|
||||
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
l.contract_address,
|
||||
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
|
||||
l.contract_address AS compound_market,
|
||||
CONCAT('0x', SUBSTR(topics [3] :: STRING, 27, 40)) AS token_address,
|
||||
utils.udf_hex_to_int(
|
||||
segmented_data [0] :: STRING
|
||||
) :: INTEGER AS withdraw_amount,
|
||||
origin_from_address AS depositor_address,
|
||||
'Compound V3' AS compound_version,
|
||||
C.token_name,
|
||||
C.token_symbol,
|
||||
C.token_decimals,
|
||||
'polygon' AS blockchain,
|
||||
_log_id,
|
||||
l._inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__logs') }}
|
||||
l
|
||||
LEFT JOIN {{ ref('silver__contracts') }} C
|
||||
ON token_address = C.contract_address
|
||||
WHERE
|
||||
topics [0] = '0xd6d480d5b3068db003533b170d67561494d72e3bf9fa40a266471351ebba9e16' --WithdrawCollateral
|
||||
AND l.contract_address IN (SELECT DISTINCT(compound_market_address) FROM comp_assets)
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND l._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(
|
||||
_inserted_timestamp
|
||||
) - INTERVAL '12 hours'
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
tx_hash,
|
||||
block_number,
|
||||
block_timestamp,
|
||||
event_index,
|
||||
origin_from_address,
|
||||
origin_to_address,
|
||||
origin_function_signature,
|
||||
contract_address,
|
||||
compound_market,
|
||||
depositor_address,
|
||||
w.token_address,
|
||||
w.token_symbol,
|
||||
withdraw_amount AS amount_unadj,
|
||||
withdraw_amount / pow(
|
||||
10,
|
||||
w.token_decimals
|
||||
) AS amount,
|
||||
compound_version,
|
||||
blockchain,
|
||||
_log_id,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
withdraw w qualify(ROW_NUMBER() over(PARTITION BY _log_id
|
||||
ORDER BY
|
||||
_inserted_timestamp DESC)) = 1
|
||||
@ -0,0 +1,40 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__comp_withdraws
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_HASH
|
||||
- EVENT_INDEX
|
||||
columns:
|
||||
- name: TX_HASH
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_NUMBER
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_TIMESTAMP
|
||||
tests:
|
||||
- not_null
|
||||
- name: EVENT_INDEX
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_MARKET
|
||||
tests:
|
||||
- not_null
|
||||
- name: DEPOSITOR_ADDRESS
|
||||
- name: TOKEN_ADDRESS
|
||||
tests:
|
||||
- not_null
|
||||
- name: TOKEN_SYMBOL
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT_UNADJ
|
||||
tests:
|
||||
- not_null
|
||||
- name: AMOUNT
|
||||
tests:
|
||||
- not_null
|
||||
- name: COMPOUND_VERSION
|
||||
tests:
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user