Skip to content

Commit 4f8d7a3

Browse files
committed
feat: Add NEAR ft_transfer_calls
Adds a spell for NEAR blockchain (resolution of ft_transfer_calls). ft_transfer_call is one of the two ways to send fungible tokens according to the NEP-141 standard. Until now only the other method is covered (ft_transfer through the ft_transfers table). This contribution adds coverage for the ft_transfer_call, which according to the standard: transfer tokens and call a method on a receiver contract. A successful workflow will end in a success execution outcome to the callback on the same contract at the method ft_resolve_transfer. You can think of this as being similar to attaching native NEAR tokens to a function call. It allows you to attach any Fungible Token in a call to a receiver contract.
1 parent 155529a commit 4f8d7a3

File tree

2 files changed

+179
-0
lines changed

2 files changed

+179
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{{
2+
config(
3+
schema = 'near',
4+
alias = 'ft_transfer_calls',
5+
materialized = 'incremental',
6+
file_format = 'delta',
7+
incremental_strategy = 'merge',
8+
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_date')],
9+
unique_key = ['block_date', 'receipt_id', 'resolve_receipt_id'],
10+
post_hook = '{{ expose_spells(\'["near"]\',
11+
"sector",
12+
"transfers",
13+
\'["danzipie"]\') }}'
14+
)
15+
}}
16+
17+
WITH
18+
ft_transfer_calls AS (
19+
SELECT
20+
block_date,
21+
block_height,
22+
block_time,
23+
block_hash,
24+
chunk_hash,
25+
shard_id,
26+
tx_hash,
27+
action_function_call_args_parsed,
28+
receipt_id
29+
FROM
30+
{{ source('near', 'actions') }}
31+
WHERE
32+
action_function_call_call_method_name = 'ft_transfer_call'
33+
{% if is_incremental() %}
34+
AND {{ incremental_predicate('block_date') }}
35+
{% endif %}
36+
)
37+
SELECT
38+
ft_transfer_calls.block_date,
39+
ft_transfer_calls.block_height,
40+
ft_transfer_calls.block_time,
41+
ft_transfer_calls.block_hash,
42+
ft_transfer_calls.chunk_hash,
43+
ft_transfer_calls.shard_id,
44+
'nep141' AS standard,
45+
ft_resolve_transfers.receipt_receiver_account_id AS contract_account_id,
46+
ft_transfer_calls.receipt_id,
47+
ft_resolve_transfers.receipt_id as resolve_receipt_id,
48+
ft_resolve_transfers.tx_status AS resolve_status,
49+
ft_resolve_transfers.tx_hash,
50+
'ft_transfer_call' AS cause,
51+
CAST(
52+
json_extract(ft_transfer_calls.action_function_call_args_parsed, '$.memo') AS varchar
53+
) AS memo,
54+
CAST(
55+
json_extract(
56+
ft_resolve_transfers.action_function_call_args_parsed,
57+
'$.receiver_id'
58+
) AS varchar
59+
) AS affected_account_id,
60+
CAST(
61+
json_extract(
62+
ft_resolve_transfers.action_function_call_args_parsed,
63+
'$.sender_id'
64+
) AS varchar
65+
) AS involved_account_id,
66+
CAST(
67+
json_extract(
68+
ft_resolve_transfers.action_function_call_args_parsed,
69+
'$.amount'
70+
) AS varchar
71+
) AS delta_amount,
72+
ft_resolve_transfers._updated_at,
73+
ft_resolve_transfers._ingested_at
74+
FROM
75+
{{ source('near', 'actions') }} AS ft_resolve_transfers
76+
JOIN ft_transfer_calls ON (
77+
ft_resolve_transfers.tx_hash = ft_transfer_calls.tx_hash
78+
AND ft_resolve_transfers.block_date >= ft_transfer_calls.block_date
79+
)
80+
WHERE
81+
ft_resolve_transfers.receipt_predecessor_account_id = ft_resolve_transfers.receipt_receiver_account_id
82+
AND ft_resolve_transfers.action_function_call_call_method_name = 'ft_resolve_transfer'
83+
AND json_extract(
84+
ft_resolve_transfers.action_function_call_args_parsed,
85+
'$.amount'
86+
) IS NOT NULL -- this excludes the contract_account_id 'aurora' that is not fully nep141 compliant
87+
AND contains(ft_transfer_calls.execution_outcome_receipt_ids, ft_resolve_transfers.receipt_id)
88+
{% if is_incremental() %}
89+
AND {{ incremental_predicate('ft_resolve_transfers.block_date') }}
90+
{% endif %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: 2
2+
3+
models:
4+
- name: near_ft_transfer_calls
5+
meta:
6+
blockchain: near
7+
sector: transfers
8+
project: ft_transfer_calls
9+
contributors: danzipie
10+
config:
11+
tags:
12+
["near", "nep141"]
13+
description: >
14+
This table contains token transfers on the NEAR blockchain for the `ft_transfer_call` function.
15+
columns:
16+
- name: block_date
17+
description: "Date of the block of the ft_transfer_call"
18+
tests:
19+
- not_null
20+
- name: block_height
21+
description: "Height of the block of the ft_transfer_call"
22+
tests:
23+
- not_null
24+
- name: block_time
25+
description: "Timestamp of the block of the ft_transfer_call"
26+
tests:
27+
- not_null
28+
- name: block_hash
29+
description: "Hash of the block of the ft_transfer_call"
30+
tests:
31+
- not_null
32+
- name: chunk_hash
33+
description: "Hash of the chunk of the ft_transfer_call"
34+
tests:
35+
- not_null
36+
- name: shard_id
37+
description: "ID of the shard of the ft_transfer_call"
38+
tests:
39+
- not_null
40+
- name: standard
41+
description: "Token standard"
42+
tests:
43+
- not_null
44+
- name: contract_account_id
45+
description: "ID of the token contract account"
46+
tests:
47+
- not_null
48+
- name: receipt_id
49+
description: "ID of the receipt of the ft_transfer_call"
50+
tests:
51+
- not_null
52+
- name: resolve_receipt_id
53+
description: "ID of the receipt of the ft_resolve_call"
54+
tests:
55+
- not_null
56+
- name: resolve_status
57+
description: "Status of the ft_resolve_call"
58+
tests:
59+
- not_null
60+
- name: tx_hash
61+
description: "Hash of the transaction"
62+
tests:
63+
- not_null
64+
- name: cause
65+
description: "Cause of the transfer"
66+
tests:
67+
- not_null
68+
- name: memo
69+
description: "Memo field of the transaction"
70+
- name: affected_account_id
71+
description: "Account ID affected by the transfer"
72+
tests:
73+
- not_null
74+
- name: involved_account_id
75+
description: "Account ID involved in the transfer"
76+
tests:
77+
- not_null
78+
- name: delta_amount
79+
description: "Amount of tokens transferred"
80+
tests:
81+
- not_null
82+
- name: _updated_at
83+
description: "Last update timestamp"
84+
tests:
85+
- not_null
86+
- name: _ingested_at
87+
description: "Ingestion timestamp"
88+
tests:
89+
- not_null

0 commit comments

Comments
 (0)