Skip to content

Commit 943a6ae

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 943a6ae

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 = ['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+
)
79+
WHERE
80+
ft_resolve_transfers.receipt_predecessor_account_id = ft_resolve_transfers.receipt_receiver_account_id
81+
AND ft_resolve_transfers.action_function_call_call_method_name = 'ft_resolve_transfer'
82+
AND json_extract(
83+
ft_resolve_transfers.action_function_call_args_parsed,
84+
'$.amount'
85+
) IS NOT NULL -- this excludes the contract_account_id 'aurora' that is not fully nep141 compliant
86+
{% if is_incremental() %}
87+
AND {{ incremental_predicate('ft_resolve_transfers.block_date') }}
88+
{% 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

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: contract_account_id
255+
description: ID of the token contract account
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)