Skip to content

Commit aa5eb71

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 aa5eb71

File tree

3 files changed

+236
-0
lines changed

3 files changed

+236
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 = ['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_height = ft_transfer_calls.block_height
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
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)