An 5223/jupiter limit orders (#689)

* add limit order logic

* limit signers

* filter out incorrectly labeled limit swaps
This commit is contained in:
tarikceric 2024-11-05 12:28:12 -08:00 committed by GitHub
parent 5688bce773
commit e4de79882d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 1 deletions

View File

@ -79,6 +79,18 @@
'JD25qVdtd65FoiXNmR89JjmoJdYk9sjYQeSTZAALFiMy'
] %}
{% set jupiter_limit_signers = [
'j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF',
'Gw9QoW4y72hFDVt3RRzyqcD4qrV4pSqjhMMzwdGunz6H',
'LoAFmGjxUL84rWHk4X6k8jzrw12Hmb5yyReUXfkFRY6',
'71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6',
'EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv',
'j1oeQoPeuEDmjvyMwBmCWexzCQup77kbKKxV59CnYbd',
'JTJ9Cz7i43DBeps5PZdX1QVKbEkbWegBzKPxhWgkAf1',
'j1opmdubY84LUeidrPCsSGskTCYmeJVzds1UWm6nngb',
'AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU'
] %}
WITH all_routes AS (
SELECT
*
@ -190,6 +202,17 @@ dca_filled AS (
{{ between_stmts }}
AND program_id = 'DCA265Vj8a9CEuX1eb1LWRnDT7uK6q1xMipnNyatn23M'
AND event_type = 'Filled'
),
limit_filled AS (
SELECT
tx_id,
silver.udf_get_account_pubkey_by_name('maker', decoded_instruction:accounts) AS limit_requester,
FROM
{{ ref('silver__decoded_instructions_combined') }}
WHERE
{{ between_stmts }}
AND program_id in ('j1o2qRpjcyUwEvwtcfhEQefh773ZgjxcVRry7LDqg5X','jupoNjAxXgZ4rjzxzPMP4oxduvQsQtZzyknqvzYNrNu')
AND event_type = 'flashFillOrder'
)
SELECT
b.block_timestamp,
@ -210,6 +233,11 @@ SELECT
AND d.tx_id IS NOT NULL
) AS is_dca_swap,
d.dca_requester,
(
i.swapper IN ('{{ jupiter_limit_signers | join("','") }}')
AND e.tx_id IS NOT NULL
) AS is_limit_swap,
e.limit_requester,
b._inserted_timestamp,
{{ dbt_utils.generate_surrogate_key(['b.tx_id','b.index','b.inner_index']) }} AS swaps_intermediate_jupiterv6_id,
sysdate() AS inserted_timestamp,
@ -230,3 +258,6 @@ LEFT JOIN
LEFT JOIN
dca_filled d
ON b.tx_id = d.tx_id
LEFT JOIN
limit_filled e
ON b.tx_id = e.tx_id

View File

@ -118,6 +118,25 @@ models:
is_dca_swap
AND _inserted_timestamp >= current_date - 7
AND block_timestamp >= '2024-05-12' /* last recorded date where some txs used the Beta DCA program (Betam4GuxvAes2uQ5vX8SackcxL5pxRuHowM5m2Ykmcq) */
- name: IS_LIMIT_SWAP
description: "Whether the swap was initiated by a Jupiter limit order. If value is NULL then it is NOT a limit order swap"
tests:
- dbt_utils.expression_is_true:
expression: "= True"
config:
where: >
swapper IN ('j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF','Gw9QoW4y72hFDVt3RRzyqcD4qrV4pSqjhMMzwdGunz6H','LoAFmGjxUL84rWHk4X6k8jzrw12Hmb5yyReUXfkFRY6','71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6','EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv','j1oeQoPeuEDmjvyMwBmCWexzCQup77kbKKxV59CnYbd','JTJ9Cz7i43DBeps5PZdX1QVKbEkbWegBzKPxhWgkAf1','j1opmdubY84LUeidrPCsSGskTCYmeJVzds1UWm6nngb','AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU')
AND _inserted_timestamp >= current_date - 7
AND block_timestamp >= '2023-10-01'
- name: LIMIT_REQUESTER
description: "Original address that requested the limit order swap"
tests:
- not_null:
config:
where: >
is_limit_swap
AND _inserted_timestamp >= current_date - 7
AND block_timestamp >= '2023-10-01'
- name: _INSERTED_TIMESTAMP
description: "{{ doc('_inserted_timestamp') }}"
tests:

View File

@ -0,0 +1,18 @@
SELECT DISTINCT
signers[0]::string AS signer
FROM
{{ ref('silver__decoded_instructions_combined') }}
WHERE
program_id in ('j1o2qRpjcyUwEvwtcfhEQefh773ZgjxcVRry7LDqg5X','jupoNjAxXgZ4rjzxzPMP4oxduvQsQtZzyknqvzYNrNu')
AND event_type = 'flashFillOrder'
AND _inserted_timestamp >= current_date - 7
AND signer NOT IN ('j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF',
'Gw9QoW4y72hFDVt3RRzyqcD4qrV4pSqjhMMzwdGunz6H',
'LoAFmGjxUL84rWHk4X6k8jzrw12Hmb5yyReUXfkFRY6',
'71WDyyCsZwyEYDV91Qrb212rdg6woCHYQhFnmZUBxiJ6',
'EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv',
'j1oeQoPeuEDmjvyMwBmCWexzCQup77kbKKxV59CnYbd',
'JTJ9Cz7i43DBeps5PZdX1QVKbEkbWegBzKPxhWgkAf1',
'j1opmdubY84LUeidrPCsSGskTCYmeJVzds1UWm6nngb',
'AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU'
)