Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solana transfers: it's time to finally add the beast #4954

Merged
merged 29 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a8e9093
it's time
andrewhong5297 Dec 6, 2023
2e26fd8
add reader note
andrewhong5297 Dec 6, 2023
845ea0b
add 30 day filter first
andrewhong5297 Dec 6, 2023
2c9ccd9
remove changes
andrewhong5297 Dec 6, 2023
7eeeccc
fixes
andrewhong5297 Dec 6, 2023
233058d
coalesce null to 0
andrewhong5297 Dec 6, 2023
48a65d3
just make token accounts unique, dgaf about the 214 weird ones
andrewhong5297 Dec 6, 2023
a963c2a
try full history
andrewhong5297 Dec 6, 2023
d43e880
Merge branch 'main' into solana_utils_transfers
andrewhong5297 Dec 6, 2023
85a27a5
add predicate config
andrewhong5297 Dec 6, 2023
80d38c2
add block_time to partition?
andrewhong5297 Dec 6, 2023
ef23f48
add block_slot instead
andrewhong5297 Dec 6, 2023
9eaed2a
Merge branch 'main' into solana_utils_transfers
aalan3 Dec 7, 2023
26ebcd3
Merge branch 'main' into solana_utils_transfers
andrewhong5297 Dec 7, 2023
ec83f8a
add partition
andrewhong5297 Dec 7, 2023
29eb261
remove native SOL transfers
andrewhong5297 Dec 7, 2023
97f812b
add in native transfers model
andrewhong5297 Dec 7, 2023
fcbad4a
Merge branch 'main' into solana_utils_transfers
andrewhong5297 Dec 7, 2023
69ad775
remove partition
andrewhong5297 Dec 7, 2023
eb26dd7
rem
andrewhong5297 Dec 7, 2023
619b4ab
Merge branch 'main' into solana_utils_transfers
andrewhong5297 Dec 8, 2023
5ac007e
try 30
andrewhong5297 Dec 8, 2023
1c887df
Merge branch 'solana_utils_transfers' of https://github.com/duneanaly…
andrewhong5297 Dec 8, 2023
693468e
try 300 day
andrewhong5297 Dec 8, 2023
d7ceada
try 600
andrewhong5297 Dec 8, 2023
64fb7e0
add back in partition, try all history again
andrewhong5297 Dec 8, 2023
f273fd3
remove partition again
andrewhong5297 Dec 8, 2023
363855a
remove system transfers
andrewhong5297 Dec 10, 2023
2d48b4b
add partition back in
andrewhong5297 Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions models/orca_whirlpool/orca_whirlpool_trades_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,4 @@ sources:
- name: whirlpool_call_initializeFeeTier
loaded_at_field: call_block_time
- name: whirlpool_call_setDefaultFeeRate
loaded_at_field: call_block_time

- name: spl_token_solana
description: "spl_token decoded tables"
freshness: # default freshness
warn_after: { count: 12, period: hour }
error_after: { count: 24, period: hour }
tables:
- name: spl_token_call_transfer
loaded_at_field: call_block_time
4 changes: 1 addition & 3 deletions models/solana_utils/solana_utils_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,4 @@ models:
- &favorite_domain
name: favorite_domain
- &owned_domains
name: owned_domains


name: owned_domains
11 changes: 5 additions & 6 deletions models/solana_utils/solana_utils_token_accounts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
unique_key = ['token_mint_address','address'],
unique_key = ['address'],
post_hook='{{ expose_spells(\'["solana"]\',
"sector",
"solana_utils",
Expand All @@ -15,16 +15,15 @@
WITH
distinct_accounts as (
SELECT
aa.token_mint_address
, aa.address
, max_by(aa.token_balance_owner, aa.block_time) as token_balance_owner --some account created before and then again after token owner schema change, so then it created dupes.
, min(aa.block_time) as created_at
aa.address
, max_by(aa.token_balance_owner, aa.block_time) as token_balance_owner
, max_by(aa.token_mint_address, aa.block_time) as token_mint_address
FROM {{ source('solana','account_activity') }} aa
WHERE aa.token_mint_address is not null
{% if is_incremental() %}
AND {{incremental_predicate('aa.block_time')}}
{% endif %}
group by 1,2
group by 1
)

SELECT * FROM distinct_accounts
22 changes: 22 additions & 0 deletions models/tokens/solana/tokens_solana.sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ sources:
loaded_at_field: call_block_time
- name: spl_token_call_initializeMint2
loaded_at_field: call_block_time
- name: spl_token_call_transfer
loaded_at_field: call_block_time
- name: spl_token_call_transferChecked
loaded_at_field: call_block_time
- name: spl_token_call_mintTo
loaded_at_field: call_block_time
- name: spl_token_call_mintToChecked
loaded_at_field: call_block_time
- name: spl_token_call_burn
loaded_at_field: call_block_time
- name: spl_token_call_burnChecked
loaded_at_field: call_block_time
- name: system_program_solana
description: "system program decoded tables"
freshness: # default freshness
warn_after: { count: 12, period: hour }
error_after: { count: 24, period: hour }
tables:
- name: system_program_call_Transfer
loaded_at_field: call_block_time
- name: system_program_call_TransferWithSeed
loaded_at_field: call_block_time
- name: mpl_token_metadata_solana
description: "mpl metadata decoded tables"
freshness: # default freshness
Expand Down
28 changes: 27 additions & 1 deletion models/tokens/solana/tokens_solana_schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ models:
- name: call_tx_id
- name: call_block_time
- name: call_block_slot
- name: call_tx_signer
- name: call_tx_signer


- name: tokens_solana_transfers
meta:
blockchain: solana
contributors: [ilemi]
config:
tags: ['solana','transfers','erc20','nft','spl']
description: >
get all spl token transfers (will add in token2022 later)
columns:
- name: block_time
- name: block_date
- name: block_slot
- name: action
- name: token_mint_address
- name: amount
- name: from_owner
- name: to_owner
- name: from_token_account
- name: to_token_account
- name: tx_signer
- name: tx_id
- name: outer_instruction_index
- name: inner_instruction_index
- name: outer_executing_account
69 changes: 69 additions & 0 deletions models/tokens/solana/tokens_solana_transfers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{
config(
schema = 'tokens_solana',
alias = 'transfers',
materialized = 'incremental',
file_format = 'delta',
incremental_strategy = 'merge',
andrewhong5297 marked this conversation as resolved.
Show resolved Hide resolved
partition_by = ['block_date'],
incremental_predicates = [incremental_predicate('DBT_INTERNAL_DEST.block_time')],
unique_key = ['tx_id','outer_instruction_index','inner_instruction_index', 'block_slot'],
post_hook='{{ expose_spells(\'["solana"]\',
"sector",
"tokens",
\'["ilemi"]\') }}')
}}

SELECT
call_block_time as block_time
andrewhong5297 marked this conversation as resolved.
Show resolved Hide resolved
, cast (date_trunc('day', call_block_time) as date) as block_date
, call_block_slot as block_slot
, action
, amount
, COALESCE(tk_s.token_mint_address, tk_d.token_mint_address) as token_mint_address
, tk_s.token_balance_owner as from_owner
, tk_d.token_balance_owner as to_owner
, account_source as from_token_account
, account_destination as to_token_account
, call_tx_signer as tx_signer
, call_tx_id as tx_id
, call_outer_instruction_index as outer_instruction_index
, COALESCE(call_inner_instruction_index,0) as inner_instruction_index
, call_outer_executing_account as outer_executing_account
FROM (
SELECT account_source, account_destination, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'transfer' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_transfer') }}

UNION ALL

SELECT account_source, account_destination, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'transfer' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_transferChecked') }}

UNION ALL

SELECT null, account_account as account_destination, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'mint' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_mintTo') }}

UNION ALL

SELECT null, account_account as account_destination, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'mint' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_mintToChecked') }}

UNION ALL

SELECT account_account as account_source, null, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'burn' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_burn') }}

UNION ALL

SELECT account_account as account_source, null, amount, call_tx_id, call_block_time, call_block_slot, call_outer_executing_account, call_tx_signer, 'burn' as action, call_outer_instruction_index, call_inner_instruction_index
FROM {{ source('spl_token_solana','spl_token_call_burnChecked') }}
) tr
--get token and accounts
LEFT JOIN {{ ref('solana_utils_token_accounts') }} tk_s ON tk_s.address = tr.account_source
LEFT JOIN {{ ref('solana_utils_token_accounts') }} tk_d ON tk_d.address = tr.account_destination
WHERE 1=1
{% if is_incremental() %}
AND {{incremental_predicate('call_block_time')}}
{% endif %}
-- AND call_block_time > now() - interval '600' day