add test, yml and gold view

This commit is contained in:
WHYTEWYLL 2024-02-18 16:14:53 +01:00
parent cdb8e8979a
commit 75504605d7
14 changed files with 400 additions and 62 deletions

View File

@ -0,0 +1,7 @@
{% docs action %}
The action that the user is taking.
Deposit: user is depositing funds to be used for lending
Withdraw: user has changed their mind and are no longer willing to lend, so they withdraw their asset
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs sender %}
Sender is the address of the user who initiated the transaction
{% enddocs %}

View File

@ -0,0 +1,82 @@
{{ config(
materialized = 'view',
secure = false,
meta ={ 'database_tags':{ 'table':{ 'PURPOSE': 'DEFI, BRIDGING' }} },
tags = ['core']
) }}
WITH borrows AS
(
SELECT
*
FROM
{{ ref('silver__burrow_borrows') }}
),
collaterals AS
(
SELECT
*
FROM
{{ ref('silver__burrow_collaterals') }}
),
deposits AS
(
SELECT
*
FROM
{{ ref('silver__burrow_deposits') }}
),
repay AS
(
SELECT
*
FROM
{{ ref('silver__burrow_repay') }}
),
withdrawals AS
(
SELECT
*
FROM
{{ ref('silver__burrow_withdraws') }}
),
FINAL AS (
SELECT
*
FROM
borrows
UNION ALL
SELECT
*
FROM
collaterals
UNION ALL
SELECT
*
FROM
deposits
UNION ALL
SELECT
*
FROM
repay
UNION ALL
SELECT
*
FROM
withdrawals
)
SELECT
tx_hash,
block_number,
block_timestamp,
sender,
actions,
contract_address,
amount,
token_contract_address
FROM
FINAL

View File

@ -0,0 +1,44 @@
version: 2
models:
- name: defi__fact_lending_burrow
columns:
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
tests:
- not_null
- name: ACTIONS
description: "{{ doc('action')}}"
tests:
- not_null
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
tests:
- not_null
- name: AMOUNT
description: "{{ doc('amount')}}"
tests:
- not_null
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
tests:
- not_null

View File

@ -1,7 +1,8 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = "_action_id",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
@ -10,6 +11,7 @@ WITH --borrows from Burrow LendingPool contracts
borrows AS (
SELECT
action_id as _action_id,
block_id,
block_timestamp,
tx_hash,
@ -31,12 +33,13 @@ FINAL AS (
SELECT
*,
args :sender_id AS sender,
receiver_id AS contract_address,
PARSE_JSON(
args :msg
) :Execute :actions [0] :Borrow AS segmented_data,
segmented_data :token_id AS token_contract_address,
segmented_data :amount AS amount,
'borrow' AS actions
'borrow' :: STRING AS actions
FROM
borrows
WHERE
@ -46,18 +49,19 @@ FINAL AS (
AND receipt_succeeded = TRUE
)
SELECT
_action_id,
tx_hash,
block_id AS block_number,
block_timestamp,
receiver_id AS contract_address,
sender,
token_contract_address,
actions,
contract_address,
amount,
token_contract_address,
_inserted_timestamp,
_partition_by_block_number,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
['_action_id']
) }} AS actions_events_addkey_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,

View File

@ -4,17 +4,55 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- _action_id
columns:
- name: _ACTION_ID
description: "{{ doc('action_id')}}"
tests:
- not_null
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: month
interval: 1
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
- name: ACTIONS
description: "{{ doc('action')}}"
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
- name: AMOUNT
description: "{{ doc('amount')}}"
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
- name: _PARTITION_BY_BLOCK_NUMBER
description: "{{ doc('_partition_by_block_number')}}"
- name: ACTIONS_EVENTS_ID
description: "{{doc('id')}}"
- name: INSERTED_TIMESTAMP
description: "{{doc('inserted_timestamp')}}"
- name: MODIFIED_TIMESTAMP
description: "{{doc('modified_timestamp')}}"
- name: _INVOCATION_ID
description: "{{doc('invocation_id')}}"

View File

@ -1,7 +1,8 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = "_action_id",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
@ -10,6 +11,7 @@ WITH
actions AS (
SELECT
action_id AS _action_id,
block_id,
block_timestamp,
tx_hash,
@ -40,7 +42,7 @@ FINAL AS (
segmented_data :data [0] :account_id AS account_id,
segmented_data :data [0] :token_id AS token_contract_address,
segmented_data :data [0] :amount :: NUMBER AS amount,
segmented_data :event AS actions
segmented_data :event :: STRING AS actions
FROM actions
WHERE
receiver_id = 'contract.main.burrow.near'
@ -55,20 +57,19 @@ FINAL AS (
)
)
SELECT
_action_id,
tx_hash,
block_id AS block_number,
block_timestamp,
sender,
actions,
contract_address,
account_id,
receiver_id,
sender,
token_contract_address,
amount,
token_contract_address,
_inserted_timestamp,
_partition_by_block_number,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
['_action_id']
) }} AS actions_events_addkey_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,

View File

@ -4,17 +4,55 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- _action_id
columns:
- name: _ACTION_ID
description: "{{ doc('action_id')}}"
tests:
- not_null
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: month
interval: 1
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
- name: ACTIONS
description: "{{ doc('action')}}"
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
- name: AMOUNT
description: "{{ doc('amount')}}"
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
- name: _PARTITION_BY_BLOCK_NUMBER
description: "{{ doc('_partition_by_block_number')}}"
- name: ACTIONS_EVENTS_ID
description: "{{doc('id')}}"
- name: INSERTED_TIMESTAMP
description: "{{doc('inserted_timestamp')}}"
- name: MODIFIED_TIMESTAMP
description: "{{doc('modified_timestamp')}}"
- name: _INVOCATION_ID
description: "{{doc('invocation_id')}}"

View File

@ -1,7 +1,8 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = "_action_id",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
@ -10,6 +11,7 @@ WITH
deposits AS (
SELECT
action_id AS _action_id,
block_id,
block_timestamp,
tx_hash,
@ -38,7 +40,7 @@ FINAL AS (
segmented_data :data [0] :account_id AS account_id,
segmented_data :data [0] :token_id AS token_contract_address,
segmented_data :data [0] :amount :: NUMBER AS amount,
segmented_data :event AS actions
segmented_data :event :: STRING AS actions
FROM
deposits
WHERE
@ -47,18 +49,19 @@ FINAL AS (
AND receipt_succeeded = TRUE
)
SELECT
_action_id,
tx_hash,
block_id AS block_number,
block_timestamp,
sender,
actions,
contract_address,
sender,
token_contract_address,
amount,
token_contract_address,
_inserted_timestamp,
_partition_by_block_number,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
['_action_id']
) }} AS actions_events_addkey_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,

View File

@ -4,17 +4,55 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- _action_id
columns:
- name: _ACTION_ID
description: "{{ doc('action_id')}}"
tests:
- not_null
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: month
interval: 1
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
- name: ACTIONS
description: "{{ doc('action')}}"
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
- name: AMOUNT
description: "{{ doc('amount')}}"
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
- name: _PARTITION_BY_BLOCK_NUMBER
description: "{{ doc('_partition_by_block_number')}}"
- name: ACTIONS_EVENTS_ID
description: "{{doc('id')}}"
- name: INSERTED_TIMESTAMP
description: "{{doc('inserted_timestamp')}}"
- name: MODIFIED_TIMESTAMP
description: "{{doc('modified_timestamp')}}"
- name: _INVOCATION_ID
description: "{{doc('invocation_id')}}"

View File

@ -1,7 +1,8 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = "_action_id",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
@ -10,6 +11,7 @@ WITH
actions AS (
SELECT
action_id AS _action_id,
block_id,
block_timestamp,
tx_hash,
@ -38,7 +40,7 @@ FINAL AS (
segmented_data :data [0] :account_id AS account_id,
segmented_data :data [0] :token_id AS token_contract_address,
segmented_data :data [0] :amount :: NUMBER AS amount,
segmented_data :event AS actions
segmented_data :event :: STRING AS actions
FROM
actions
WHERE
@ -55,19 +57,19 @@ FINAL AS (
AND receipt_succeeded = TRUE
)
SELECT
_action_id,
tx_hash,
block_id AS block_number,
block_timestamp,
sender,
actions,
contract_address,
sender,
token_contract_address,
amount,
account_id,
token_contract_address,
_inserted_timestamp,
_partition_by_block_number,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
['_action_id']
) }} AS actions_events_addkey_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,

View File

@ -4,19 +4,55 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- AMOUNT
- _action_id
columns:
- name: _ACTION_ID
description: "{{ doc('action_id')}}"
tests:
- not_null
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: month
interval: 1
```
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
- name: ACTIONS
description: "{{ doc('action')}}"
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
- name: AMOUNT
description: "{{ doc('amount')}}"
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
- name: _PARTITION_BY_BLOCK_NUMBER
description: "{{ doc('_partition_by_block_number')}}"
- name: ACTIONS_EVENTS_ID
description: "{{doc('id')}}"
- name: INSERTED_TIMESTAMP
description: "{{doc('inserted_timestamp')}}"
- name: MODIFIED_TIMESTAMP
description: "{{doc('modified_timestamp')}}"
- name: _INVOCATION_ID
description: "{{doc('invocation_id')}}"

View File

@ -1,7 +1,8 @@
{{ config(
materialized = 'incremental',
incremental_strategy = 'delete+insert',
unique_key = "block_number",
incremental_strategy = 'merge',
merge_exclude_columns = ["inserted_timestamp"],
unique_key = "_action_id",
cluster_by = ['block_timestamp::DATE'],
tags = ['curated']
) }}
@ -10,6 +11,7 @@ WITH -- successfull withdraws
withdraws AS (
SELECT
action_id AS _action_id,
block_id,
block_timestamp,
tx_hash,
@ -34,10 +36,10 @@ FINAL AS (
*,
receiver_id AS contract_address,
PARSE_JSON(SUBSTRING(logs [0], 12)) AS segmented_data,
segmented_data :data [0] :account_id AS account_id,
segmented_data :data [0] :account_id AS sender,
segmented_data :data [0] :token_id AS token_contract_address,
segmented_data :data [0] :amount :: NUMBER AS amount,
segmented_data :event AS actions
segmented_data :event :: STRING AS actions
FROM
withdraws
WHERE
@ -46,18 +48,19 @@ FINAL AS (
AND receipt_succeeded = TRUE
)
SELECT
_action_id,
tx_hash,
block_id AS block_number,
block_timestamp,
sender,
actions,
contract_address,
account_id,
token_contract_address,
amount,
token_contract_address,
_inserted_timestamp,
_partition_by_block_number,
{{ dbt_utils.generate_surrogate_key(
['tx_hash']
['_action_id']
) }} AS actions_events_addkey_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,

View File

@ -4,18 +4,55 @@ models:
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- TX_HASH
- AMOUNT
- _action_id
columns:
- name: _ACTION_ID
description: "{{ doc('action_id')}}"
tests:
- not_null
- name: TX_HASH
description: "{{ doc('tx_hash')}}"
tests:
- not_null
- name: BLOCK_NUMBER
description: "{{ doc('block_id')}}"
tests:
- not_null
- name: BLOCK_TIMESTAMP
description: "{{ doc('block_timestamp')}}"
tests:
- not_null
- dbt_expectations.expect_row_values_to_have_recent_data:
datepart: month
interval: 1
- not_null:
where: _inserted_timestamp <= current_timestamp - interval '1 hour'
- name: SENDER
description: "{{ doc('sender')}}"
- name: ACTIONS
description: "{{ doc('action')}}"
- name: CONTRACT_ADDRESS
description: "{{ doc('contract_address')}}"
- name: AMOUNT
description: "{{ doc('amount')}}"
- name: TOKEN_CONTRACT_ADDRESS
description: "{{ doc('token_contract')}}"
- name: _PARTITION_BY_BLOCK_NUMBER
description: "{{ doc('_partition_by_block_number')}}"
- name: ACTIONS_EVENTS_ID
description: "{{doc('id')}}"
- name: INSERTED_TIMESTAMP
description: "{{doc('inserted_timestamp')}}"
- name: MODIFIED_TIMESTAMP
description: "{{doc('modified_timestamp')}}"
- name: _INVOCATION_ID
description: "{{doc('invocation_id')}}"