Skip to content

Commit 8ece5ba

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 8ece5ba

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{{
2+
config(
3+
schema = 'near',
4+
alias = 'ft_transfer_calls',
5+
materialized = 'incremental',
6+
file_format = 'delta',
7+
incremental_strategy = 'merge',
8+
unique_key = ['block_date', 'resolve_receipt_id'],
9+
post_hook = '{{ expose_spells(\'["near"]\',
10+
"sector",
11+
"transfers",
12+
\'["danzipie"]\') }}'
13+
)
14+
}}
15+
16+
WITH
17+
ft_transfer_calls AS (
18+
SELECT
19+
block_date,
20+
block_height,
21+
block_time,
22+
block_hash,
23+
chunk_hash,
24+
shard_id,
25+
tx_hash,
26+
action_function_call_args_parsed,
27+
receipt_id
28+
FROM
29+
{{ source('near', 'actions') }}
30+
WHERE
31+
action_function_call_call_method_name = 'ft_transfer_call'
32+
{% if is_incremental() %}
33+
AND {{ incremental_predicate('block_date') }}
34+
{% endif %}
35+
)
36+
SELECT
37+
ft_transfer_calls.block_date,
38+
ft_transfer_calls.block_height,
39+
ft_transfer_calls.block_time,
40+
ft_transfer_calls.block_hash,
41+
ft_transfer_calls.chunk_hash,
42+
ft_transfer_calls.shard_id,
43+
'nep141' AS standard,
44+
ft_resolve_transfers.receipt_receiver_account_id AS contract_account_id,
45+
ft_transfer_calls.receipt_id,
46+
ft_resolve_transfers.receipt_id as resolve_receipt_id,
47+
ft_resolve_transfers.tx_status AS resolve_status,
48+
ft_resolve_transfers.tx_hash,
49+
'ft_transfer_call' AS cause,
50+
CAST(
51+
json_extract(ft_transfer_calls.action_function_call_args_parsed, '$.memo') AS varchar
52+
) AS memo,
53+
CAST(
54+
json_extract(
55+
ft_resolve_transfers.action_function_call_args_parsed,
56+
'$.receiver_id'
57+
) AS varchar
58+
) AS affected_account_id,
59+
CAST(
60+
json_extract(
61+
ft_resolve_transfers.action_function_call_args_parsed,
62+
'$.sender_id'
63+
) AS varchar
64+
) AS involved_account_id,
65+
CAST(
66+
json_extract(
67+
ft_resolve_transfers.action_function_call_args_parsed,
68+
'$.amount'
69+
) AS varchar
70+
) AS delta_amount,
71+
ft_resolve_transfers._updated_at,
72+
ft_resolve_transfers._ingested_at
73+
FROM
74+
{{ source('near', 'actions') }} AS ft_resolve_transfers
75+
JOIN ft_transfer_calls ON (
76+
ft_resolve_transfers.tx_hash = ft_transfer_calls.tx_hash
77+
AND ft_resolve_transfers.block_height >= ft_transfer_calls.block_height
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+
{% if is_incremental() %}
88+
AND {{ incremental_predicate('ft_resolve_transfers.block_date') }}
89+
{% 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)