mirror of
https://github.com/FlipsideCrypto/solana-models.git
synced 2026-02-06 11:47:08 +00:00
An 5156/jupv4 v5 swaps logs (#657)
* wip * finalize jupv5, update v4 * add filter * tests and cleanup * remove v4 and add tests * cleanup and add missing log_index to yml
This commit is contained in:
parent
9d00c8da97
commit
24a660de1c
5
data/testing__swaps_inner_intermediate_jupiterv5.csv
Normal file
5
data/testing__swaps_inner_intermediate_jupiterv5.csv
Normal file
@ -0,0 +1,5 @@
|
||||
tx_id,index,inner_index,swap_index,swapper,from_mint,from_amount,to_mint,to_amount,swap_program_id
|
||||
2wXMhEcikQ4Kc7uxUurDKfjvasUkEfonT7t3VbkSMo8bJaFAyBMtQqs6JfpTQGM8HGJaDDKV7jZAY8iECCjcqGWk,1,8,0,7g2Bza5nUnQX87D3AxACjrAN2S234HCruGF8SbSpEkxp,So11111111111111111111111111111111111111112,0.01,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,0.191958,whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc
|
||||
3trNn61H1H4bnTBGEY7RE4WBWjo3bZQBsVkLT1b2BMa1m31og5Toqa8f1NL2TUSKdnUBWy3vYQpQqDN3cQbS7yzy,1,18,0,3Cd5kn9VrBQ7zhfdxyfy7ooudDrrFoaLHPDkmvqSk38Y,So11111111111111111111111111111111111111112,0.001,4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R,0.113107,9W959DqEETiGZocYWCQPaJ6sBmUzgfxXfqGeTEdp3aQP
|
||||
3trNn61H1H4bnTBGEY7RE4WBWjo3bZQBsVkLT1b2BMa1m31og5Toqa8f1NL2TUSKdnUBWy3vYQpQqDN3cQbS7yzy,1,18,1,3Cd5kn9VrBQ7zhfdxyfy7ooudDrrFoaLHPDkmvqSk38Y,4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R,0.113107,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,0.023182,EewxydAPCCVuNEyrVN68PuSYdQ7wKn27V9Gjeoi8dy3S
|
||||
y9azZm22PdNNMND1ybaxKMtqfA4vLHoELEgzRvuUp6JsZvJwVhcxxNazzBGQWu3P4ii8tPegxb88EpMkg3frPny,1,6,0,BgreVEsWnYk2oxP5ts8mDo8GN5WS6Byb2KMAmt2eq6bd,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,1,So11111111111111111111111111111111111111112,0.0407317,CTMAxxk34HjKWxQ3QLZK1HpaLXmBveao3ESePXbiyfzh
|
||||
|
@ -0,0 +1,138 @@
|
||||
{{ config(
|
||||
materialized = 'table',
|
||||
unique_key = ['swaps_inner_intermediate_jupiterv5_id'],
|
||||
cluster_by = ['block_timestamp::DATE','modified_timestamp::DATE'],
|
||||
post_hook = enable_search_optimization(
|
||||
'{{this.schema}}',
|
||||
'{{this.identifier}}',
|
||||
'ON EQUALITY(tx_id, swapper, from_mint, to_mint)'
|
||||
)
|
||||
) }}
|
||||
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
program_id,
|
||||
INDEX,
|
||||
inner_index,
|
||||
log_index,
|
||||
succeeded,
|
||||
event_type,
|
||||
decoded_log :args :amm :: STRING AS swap_program_id,
|
||||
decoded_log :args :inputMint :: STRING AS from_mint,
|
||||
decoded_log :args :inputAmount :: STRING AS from_amount,
|
||||
decoded_log :args :outputMint :: STRING AS to_mint,
|
||||
decoded_log :args :outputAmount :: STRING AS to_amount,
|
||||
_inserted_timestamp,
|
||||
FROM
|
||||
{{ ref('silver__decoded_logs') }}
|
||||
WHERE
|
||||
program_id IN (
|
||||
'JUP5pEAZeHdHrLxh5UCwAbpjGwYKKoquCpda2hfP4u8',
|
||||
'JUP5cHjnnCx2DppVsufsLrXs8EBZeEZzGtEK9Gdz6ow'
|
||||
)
|
||||
AND event_type = 'SwapEvent'
|
||||
AND succeeded
|
||||
AND _inserted_timestamp :: DATE BETWEEN '2024-09-06' AND '2024-09-07'
|
||||
),
|
||||
swappers AS (
|
||||
SELECT
|
||||
tx_id,
|
||||
INDEX,
|
||||
inner_index,
|
||||
silver.udf_get_account_pubkey_by_name(
|
||||
'userTransferAuthority',
|
||||
decoded_instruction :accounts
|
||||
) AS swapper,
|
||||
_inserted_timestamp
|
||||
FROM
|
||||
{{ ref('silver__decoded_instructions_combined') }}
|
||||
WHERE
|
||||
_inserted_timestamp :: DATE in ('2023-11-03','2024-09-09','2024-09-12')
|
||||
AND program_id IN (
|
||||
'JUP5cHjnnCx2DppVsufsLrXs8EBZeEZzGtEK9Gdz6ow',
|
||||
'JUP5pEAZeHdHrLxh5UCwAbpjGwYKKoquCpda2hfP4u8'
|
||||
)
|
||||
AND event_type = 'route'
|
||||
AND swapper IS NOT NULL
|
||||
),
|
||||
token_decimals AS (
|
||||
SELECT
|
||||
mint,
|
||||
DECIMAL
|
||||
FROM
|
||||
{{ ref('silver__decoded_metadata') }}
|
||||
UNION ALL
|
||||
SELECT
|
||||
'So11111111111111111111111111111111111111112',
|
||||
9
|
||||
UNION ALL
|
||||
SELECT
|
||||
'GyD5AvrcZAhSP5rrhXXGPUHri6sbkRpq67xfG3x8ourT',
|
||||
9
|
||||
),
|
||||
pre_final AS (
|
||||
SELECT
|
||||
b.block_timestamp,
|
||||
b.block_id,
|
||||
b.tx_id,
|
||||
b.index,
|
||||
b.inner_index,
|
||||
b.log_index,
|
||||
ROW_NUMBER() over (
|
||||
PARTITION BY b.tx_id,
|
||||
b.index
|
||||
ORDER BY
|
||||
b.log_index
|
||||
) -1 AS swap_index,
|
||||
b.succeeded,
|
||||
b.swap_program_id,
|
||||
b.program_id AS aggregator_program_id,
|
||||
s.swapper,
|
||||
b.from_mint,
|
||||
b.from_amount AS from_amount_int,
|
||||
b.from_amount * pow(
|
||||
10,- d.decimal
|
||||
) AS from_amount,
|
||||
b.to_mint,
|
||||
b.to_amount AS to_amount_int,
|
||||
b.to_amount * pow(
|
||||
10,- d2.decimal
|
||||
) AS to_amount,
|
||||
b._inserted_timestamp
|
||||
FROM
|
||||
base b
|
||||
LEFT OUTER JOIN swappers s
|
||||
ON b.tx_id = s.tx_id
|
||||
AND b.index = s.index
|
||||
LEFT OUTER JOIN token_decimals d
|
||||
ON b.from_mint = d.mint
|
||||
LEFT OUTER JOIN token_decimals d2
|
||||
ON b.to_mint = d2.mint
|
||||
)
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
INDEX,
|
||||
inner_index,
|
||||
log_index,
|
||||
swap_index,
|
||||
succeeded,
|
||||
swap_program_id,
|
||||
aggregator_program_id,
|
||||
swapper,
|
||||
from_mint,
|
||||
from_amount,
|
||||
to_mint,
|
||||
to_amount,
|
||||
_inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['tx_id','index','log_index']) }} AS swaps_inner_intermediate_jupiterv5_id,
|
||||
SYSDATE() AS inserted_timestamp,
|
||||
SYSDATE() AS modified_timestamp,
|
||||
'{{ invocation_id }}' AS _invocation_id
|
||||
FROM
|
||||
pre_final
|
||||
@ -0,0 +1,101 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__swaps_inner_intermediate_jupiterv5
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_ID
|
||||
- INDEX
|
||||
- LOG_INDEX
|
||||
- compare_model_subset:
|
||||
name: silver__swaps_inner_intermediate_jupiterv5_business_logic_test
|
||||
compare_model: ref('testing__swaps_inner_intermediate_jupiterv5')
|
||||
compare_columns:
|
||||
- tx_id
|
||||
- index
|
||||
- inner_index
|
||||
- swap_index
|
||||
- swapper
|
||||
- from_mint
|
||||
- round(from_amount,2)
|
||||
- to_mint
|
||||
- round(to_amount,2)
|
||||
- swap_program_id
|
||||
model_condition: "where tx_id in ('2wXMhEcikQ4Kc7uxUurDKfjvasUkEfonT7t3VbkSMo8bJaFAyBMtQqs6JfpTQGM8HGJaDDKV7jZAY8iECCjcqGWk',
|
||||
'3trNn61H1H4bnTBGEY7RE4WBWjo3bZQBsVkLT1b2BMa1m31og5Toqa8f1NL2TUSKdnUBWy3vYQpQqDN3cQbS7yzy',
|
||||
'y9azZm22PdNNMND1ybaxKMtqfA4vLHoELEgzRvuUp6JsZvJwVhcxxNazzBGQWu3P4ii8tPegxb88EpMkg3frPny')"
|
||||
columns:
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: INDEX
|
||||
description: "{{ doc('event_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: INNER_INDEX
|
||||
description: "{{ doc('inner_index') }}. This is the inner index of the log event listing the inner swap"
|
||||
- name: SWAP_INDEX
|
||||
description: "{{ doc('swaps_swap_index') }} as it relates to the top level Jupiter V6 swap instruction"
|
||||
tests:
|
||||
- not_null
|
||||
- name: LOG_INDEX
|
||||
description: "{{ doc('log_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SUCCEEDED
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAP_PROGRAM_ID
|
||||
description: "{{ doc('program_id') }}. This is the AMM performing the swap."
|
||||
tests:
|
||||
- not_null
|
||||
- name: AGGREGATOR_PROGRAM_ID
|
||||
description: "{{ doc('program_id') }}. This is the aggregator calling the different AMMs."
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAPPER
|
||||
description: "{{ doc('swaps_swapper') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_AMOUNT
|
||||
description: "{{ doc('swaps_from_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_MINT
|
||||
description: "{{ doc('swaps_from_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_AMOUNT
|
||||
description: "{{ doc('swaps_to_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_MINT
|
||||
description: "{{ doc('swaps_to_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAPS_INNER_INTERMEDIATE_JUPITERV5_ID
|
||||
description: '{{ doc("pk") }}'
|
||||
tests:
|
||||
- unique
|
||||
- name: INSERTED_TIMESTAMP
|
||||
description: '{{ doc("inserted_timestamp") }}'
|
||||
tests:
|
||||
- not_null
|
||||
- name: MODIFIED_TIMESTAMP
|
||||
description: '{{ doc("modified_timestamp") }}'
|
||||
tests:
|
||||
- not_null
|
||||
Loading…
Reference in New Issue
Block a user