Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Adds a spell for NEAR blockchain ft_transfer_calls #7900

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{{
config(
schema = 'near',
alias = 'ft_transfer_calls',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')],
unique_key = ['block_date', 'receipt_id', 'resolve_receipt_id'],
post_hook = '{{ expose_spells(\'["near"]\',
"sector",
"transfers",
\'["danzipie"]\') }}'
)
}}

WITH
ft_transfer_calls AS (
SELECT
block_date,
block_height,
block_time,
block_hash,
chunk_hash,
shard_id,
tx_hash,
action_function_call_args_parsed,
receipt_id,
execution_outcome_receipt_ids
FROM
{{ source('near', 'actions') }}
WHERE
action_function_call_call_method_name = 'ft_transfer_call'
{% if is_incremental() %}
AND {{ incremental_predicate('block_date') }}
{% endif %}
)
SELECT
ft_transfer_calls.block_date,
ft_transfer_calls.block_height,
ft_transfer_calls.block_time,
ft_transfer_calls.block_hash,
ft_transfer_calls.chunk_hash,
ft_transfer_calls.shard_id,
'nep141' AS standard,
ft_resolve_transfers.receipt_receiver_account_id AS contract_account_id,
ft_transfer_calls.receipt_id,
ft_resolve_transfers.receipt_id as resolve_receipt_id,
ft_resolve_transfers.tx_status AS resolve_status,
ft_resolve_transfers.tx_hash,
'ft_transfer_call' AS cause,
CAST(
json_extract(ft_transfer_calls.action_function_call_args_parsed, '$.memo') AS varchar
) AS memo,
CAST(
json_extract(
ft_resolve_transfers.action_function_call_args_parsed,
'$.receiver_id'
) AS varchar
) AS affected_account_id,
CAST(
json_extract(
ft_resolve_transfers.action_function_call_args_parsed,
'$.sender_id'
) AS varchar
) AS involved_account_id,
CAST(
json_extract(
ft_resolve_transfers.action_function_call_args_parsed,
'$.amount'
) AS varchar
) AS delta_amount,
ft_resolve_transfers._updated_at,
ft_resolve_transfers._ingested_at
FROM
{{ source('near', 'actions') }} AS ft_resolve_transfers
JOIN ft_transfer_calls ON (
ft_resolve_transfers.tx_hash = ft_transfer_calls.tx_hash
AND ft_resolve_transfers.block_date >= ft_transfer_calls.block_date
)
WHERE
ft_resolve_transfers.receipt_predecessor_account_id = ft_resolve_transfers.receipt_receiver_account_id
AND ft_resolve_transfers.action_function_call_call_method_name = 'ft_resolve_transfer'
AND json_extract(
ft_resolve_transfers.action_function_call_args_parsed,
'$.amount'
) IS NOT NULL -- this excludes the contract_account_id 'aurora' that is not fully nep141 compliant
AND contains(ft_transfer_calls.execution_outcome_receipt_ids, ft_resolve_transfers.receipt_id)
{% if is_incremental() %}
AND {{ incremental_predicate('ft_resolve_transfers.block_date') }}
{% endif %}
89 changes: 89 additions & 0 deletions dbt_subprojects/daily_spellbook/models/near/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
version: 2

models:
- name: near_ft_transfer_calls
meta:
blockchain: near
sector: transfers
project: ft_transfer_calls
contributors: danzipie
config:
tags:
["near", "nep141"]
description: >
This table contains token transfers on the NEAR blockchain for the `ft_transfer_call` function.
columns:
- name: block_date
description: "Date of the block of the ft_transfer_call"
tests:
- not_null
- name: block_height
description: "Height of the block of the ft_transfer_call"
tests:
- not_null
- name: block_time
description: "Timestamp of the block of the ft_transfer_call"
tests:
- not_null
- name: block_hash
description: "Hash of the block of the ft_transfer_call"
tests:
- not_null
- name: chunk_hash
description: "Hash of the chunk of the ft_transfer_call"
tests:
- not_null
- name: shard_id
description: "ID of the shard of the ft_transfer_call"
tests:
- not_null
- name: standard
description: "Token standard"
tests:
- not_null
- name: contract_account_id
description: "ID of the token contract account"
tests:
- not_null
- name: receipt_id
description: "ID of the receipt of the ft_transfer_call"
tests:
- not_null
- name: resolve_receipt_id
description: "ID of the receipt of the ft_resolve_call"
tests:
- not_null
- name: resolve_status
description: "Status of the ft_resolve_call"
tests:
- not_null
- name: tx_hash
description: "Hash of the transaction"
tests:
- not_null
- name: cause
description: "Cause of the transfer"
tests:
- not_null
- name: memo
description: "Memo field of the transaction"
- name: affected_account_id
description: "Account ID affected by the transfer"
tests:
- not_null
- name: involved_account_id
description: "Account ID involved in the transfer"
tests:
- not_null
- name: delta_amount
description: "Amount of tokens transferred"
tests:
- not_null
- name: _updated_at
description: "Last update timestamp"
tests:
- not_null
- name: _ingested_at
description: "Ingestion timestamp"
tests:
- not_null