Skip to content

Commit 59733b9

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 59733b9

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{{
2+
config(
3+
schema = 'near_ft_transfer_calls',
4+
alias = 'ft_transfer_calls',
5+
materialized = 'table',
6+
post_hook = '{{ expose_spells(\'["near"]\',
7+
"project",
8+
"ft_transfer_calls",
9+
\'["danzipie"]\') }}'
10+
)
11+
}}
12+
13+
WITH
14+
ft_transfer_calls AS (
15+
SELECT
16+
block_date,
17+
block_height,
18+
block_time,
19+
block_hash,
20+
chunk_hash,
21+
shard_id,
22+
tx_hash,
23+
action_function_call_args_parsed,
24+
receipt_id
25+
FROM
26+
{{ source('near', 'actions') }}
27+
WHERE
28+
action_function_call_call_method_name = 'ft_transfer_call'
29+
)
30+
SELECT
31+
ft_transfer_calls.block_date,
32+
ft_transfer_calls.block_height,
33+
ft_transfer_calls.block_time,
34+
ft_transfer_calls.block_hash,
35+
ft_transfer_calls.chunk_hash,
36+
ft_transfer_calls.shard_id,
37+
'nep141' AS standard,
38+
ft_resolve_transfers.receipt_receiver_account_id AS token_id,
39+
ft_transfer_calls.receipt_id,
40+
ft_resolve_transfers.receipt_id as resolve_receipt_id,
41+
ft_resolve_transfers.tx_status AS resolve_status,
42+
ft_resolve_transfers.tx_hash,
43+
'ft_transfer_call' AS cause,
44+
CAST(
45+
json_extract(ft_transfer_calls.action_function_call_args_parsed, '$.memo') AS varchar
46+
) AS memo,
47+
CAST(
48+
json_extract(
49+
ft_resolve_transfers.action_function_call_args_parsed,
50+
'$.receiver_id'
51+
) AS varchar
52+
) AS affected_account_id,
53+
CAST(
54+
json_extract(
55+
ft_resolve_transfers.action_function_call_args_parsed,
56+
'$.sender_id'
57+
) AS varchar
58+
) AS involved_account_id,
59+
CAST(
60+
json_extract(
61+
ft_resolve_transfers.action_function_call_args_parsed,
62+
'$.amount'
63+
) AS varchar
64+
) AS delta_amount,
65+
ft_resolve_transfers._updated_at,
66+
ft_resolve_transfers._ingested_at
67+
FROM
68+
{{ source('near', 'actions') }} AS ft_resolve_transfers
69+
JOIN ft_transfer_calls ON ft_resolve_transfers.tx_hash = ft_transfer_calls.tx_hash
70+
WHERE
71+
ft_resolve_transfers.receipt_predecessor_account_id = ft_resolve_transfers.receipt_receiver_account_id
72+
AND ft_resolve_transfers.action_function_call_call_method_name = 'ft_resolve_transfer'
73+
AND json_extract(
74+
ft_resolve_transfers.action_function_call_args_parsed,
75+
'$.amount'
76+
) IS NOT NULL -- this excludes the token_id 'aurora' that is not fully nep141 compliant
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: 1
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: token_id
45+
description: "ID of the token"
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

sources/_base_sources/other/near_base_sources.yml

+61
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,67 @@ sources:
227227
description: Ingestion timestamp
228228
type: timestamp
229229

230+
- name: ft_transfer_calls
231+
description: Contains all fungible token transfers attached to a function call on the NEAR blockchain
232+
columns:
233+
- name: block_date
234+
description: Date of the block of the ft_transfer_call
235+
type: date
236+
- name: block_height
237+
description: Height of the block of the ft_transfer_call
238+
type: bigint
239+
- name: block_time
240+
description: Timestamp of the block of the ft_transfer_call
241+
type: timestamp
242+
- name: block_hash
243+
description: Hash of the block of the ft_transfer_call
244+
type: varchar
245+
- name: chunk_hash
246+
description: Hash of the chunk of the ft_transfer_call
247+
type: varchar
248+
- name: shard_id
249+
description: ID of the shard of the ft_transfer_call
250+
type: bigint
251+
- name: standard
252+
description: Token standard
253+
type: varchar
254+
- name: token_id
255+
description: ID of the token
256+
type: varchar
257+
- name: receipt_id
258+
description: ID of the receipt of the ft_transfer_call
259+
type: varchar
260+
- name: resolve_receipt_id
261+
description: ID of the receipt of the ft_resolve_call
262+
type: varchar
263+
- name: resolve_status
264+
description: Status of the ft_resolve_call
265+
type: varchar
266+
- name: tx_hash
267+
description: Hash of the transfer
268+
type: varchar
269+
- name: cause
270+
description: Cause of the transfer
271+
type: varchar
272+
- name: memo
273+
description: Memo attached to the transfer
274+
type: varchar
275+
- name: affected_account_id
276+
description: Account ID affected by the transfer
277+
type: varchar
278+
- name: involved_account_id
279+
description: Account ID involved in the transfer
280+
type: varchar
281+
- name: delta_amount
282+
description: Amount of tokens transferred
283+
type: decimal(38,0)
284+
- name: _updated_at
285+
description: Last update timestamp
286+
type: timestamp
287+
- name: _ingested_at
288+
description: Ingestion timestamp
289+
type: timestamp
290+
230291
- name: block_chunks
231292
description: Contains block and chunk information from the NEAR blockchain
232293
columns:

0 commit comments

Comments
 (0)