mirror of
https://github.com/FlipsideCrypto/solana-models.git
synced 2026-02-06 11:47:08 +00:00
An 4131/an 4152/jupv5 and jupv6 models (#387)
* v5 swaps, first contract * rename * tests wip * update swap_index * fix duplicates and null mints for marinade deposits * disable models * An 4131/add jupv6 (#385) * wip * fix index join * clean up * adjust cols and union to swaps * fix null _log_id col * update swap_index * remove solana_dev prefix --------- Co-authored-by: Desmond Hui <desmond@flipsidecrypto.com> * initial jup v5.2 model (#386) * initial jup v5.2 model * testing and swap_index update * fix duplicates * fix transfer ordering issue, fix mint actions bad join --------- Co-authored-by: tarikceric <tarik@flipsidecrypto.com> * make same fixes as in v5_2 model * disable v5 models as there are no longer new events for them * add incremental predicate * add new udf to be created * add succeeded column for v5 models * remove v6 from silver swaps, add to defi.swaps view directly --------- Co-authored-by: tarikceric <tarik@flipsidecrypto.com> Co-authored-by: tarikceric <46071768+tarikceric@users.noreply.github.com>
This commit is contained in:
parent
a04a80d7ea
commit
ec6a458253
12
data/testing__swaps_intermediate_jupiterv5_1.csv
Normal file
12
data/testing__swaps_intermediate_jupiterv5_1.csv
Normal file
@ -0,0 +1,12 @@
|
||||
tx_id,swapper,from_mint,from_amt,to_mint,to_amt,swap_index
|
||||
2EaNmoZiLacMXuiArEVUb3VkT7qH21EDXvZVfgCNPrXC5DVmapsTBGyRRk97bwnyo7MB5g5J22V3q9u9sk2hGcT7,F3QqXMK8AiN8kP85fEZC9GbawLa7AvXQyZe7oTHwNgyZ,So11111111111111111111111111111111111111112,71,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,0.79225248,6
|
||||
2ZDacDp1wdUT9wugzPWKjJ81DnhrQSQZJCvvyRS1CGps7SU4ynLtEbceNQvRmNmsMCHsh8u1nHf3ubKU6GaB2FQq,9pkeVjdmdHSHtEnrKb51hXptHNzLZSmLiMUX2iJhDzBt,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,6.2,DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263,10485706.16602,1
|
||||
3qsYnQtSZTKFna1Cj8vGqHfpkZaV7Cwubhe5GMAWPREw75evd7WpmzQMTSZrs7tjMzndavwxCdHLr4mNdAQDhqxu,8WgoJbTu7JqQXuUaYGUNTBgG5a9UfuFVRLgSPEjhGkYQ,So11111111111111111111111111111111111111112,0.6,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,12.245675,4
|
||||
3rPg4WvKXtVvxHiM3rUxtZntBJ4BUbCna4isCzorHrZ7ow5XSJ83PXufTmVZtt2D2d2iDbyuLBTYX7SrbWfbWfY7,BXt779uGCMKXNr9ecU7fhcUdRxjgowS1ExYtwNEEkTPZ,Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB,436.5512,SHDWyBxihqiCj6YekG2GUr7wqKLeLAMK1gHZck9pL6y,3211.5748187,1
|
||||
4pLtamVfK8BzxmtoCJ8w8wo8VcRCjX3fjUhtY8CiW4X3fyTDj8Rjyp4jTiBuiW4rxCJQGfemVypAzqzt7Me99Ct8,AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,1135.578979,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,61.902431059,3
|
||||
5pYiirYrJ6JFPWxUtTTJinQzFZAHxS9FMxS3DSzHWwTnit8SD81wLmRxnD9gG3m9624grhRBgKsodqkjW1j5sJuE,BkSaR7gqRw7Q5XR2DA21a9DervhgkTeCdrhL8tnnAqdU,FoRGERiW7odcCBGU1bztZi16osPBHjxharvDathL5eds,150,So11111111111111111111111111111111111111112,0.943935556,2
|
||||
661Te778ZUAFiJZBBcKnPJrh45pYt58sbNQJX6m1JuXnJvShWKx1jFhPYaHTpB27FFbkKSWvbQx3gCZ2WmT8h1et,9hBviAPw5Jh2Tmf5xUtfcnyKoqFYqd7nDLcMJ5Wnbf3b,So11111111111111111111111111111111111111112,0.12,Ao94rg8D6oK2TAq3nm8YEQxfS73vZ2GWYw2AKaUihDEY,311.924326547,5
|
||||
YzW7iKgsuvwUFLDqh1JLTygPecb7cUK3j2oMGmvcWN2LXFep4KpTy3zZvyrboKZncWytJ1CWnxkRM6ZBpdraPBv,AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU,7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj,1.743192724,So11111111111111111111111111111111111111112,1.933324022,4
|
||||
RipLfMrdihYbKFJbC3LvpQHfZHJsQwcsRC6pQnkfJqsXHKdgE6PuW7xU1DKnWQ7ReppeXvigzBXKG6Dy7G6f6vk,64oTH9vE9zKG29ku2oSmMRVxi8EubJTJ4F2kKv5UfhMj,So11111111111111111111111111111111111111112,0.005,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,0.00448896,8
|
||||
kmjRLLXq9z7kWkibAp6NEYsXxL1G96C7xtpnaRqbvRdZfJfFbWRGqhpkgcJC6fxai7gCvjkBxHzCLFcLwAD3AA5,AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,9084.631836,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,495.111297311,3
|
||||
4JbowertcD6Fr7GRaUFw3fVTYUz9XYcCrxZyZwai9g9Lxtjj8MVpLRdtc9uBPRxD4QY9BgtAqVWdXhqMjUKn7XPK,6uKhWELcjyfZUCnRJRSRNspa64QBSWphWyTYh4FcmTBf,So11111111111111111111111111111111111111112,110,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,2026.246985,6
|
||||
|
16
data/testing__swaps_intermediate_jupiterv5_2.csv
Normal file
16
data/testing__swaps_intermediate_jupiterv5_2.csv
Normal file
@ -0,0 +1,16 @@
|
||||
tx_id,swapper,from_mint,from_amt,to_mint,to_amt,swap_index
|
||||
vDN32m4cUoCXG5jTxxbCM6MD4q7X8kXT4AvtDfdjdMdTvfHfmJvUkA4JE7CYf9LZXUfQnFqVXk9nAFsyDeixMgV,EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv,7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj,0.387340063,So11111111111111111111111111111111111111112,0.431893386,4
|
||||
59WjNoQcoHN78GagayEhjrh5STa4XZ3ZiteQZYJjVfiYEwGVVmazQNnMVNPSzWRQAhqoRXnUpNsGrmagayFUzo45,EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,0.406784391,So11111111111111111111111111111111111111112,0.455967148,3
|
||||
4mPjnnnbanquhQHbeQofTRurwwdnwBBN5Yuq7xW57RRbxgsoXpa3QMSsTJ1cBDPwh6H1ixypFtnVho6mtsBjxsea,5SeNtCBx15SLG7VHKh1g5Ntj3pBUvo5ik1RBMz6uWsD7,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,0.00121392,So11111111111111111111111111111111111111112,0.111577101,3
|
||||
2tCfkNuhChjFi5WpH4BUpiyw56yvMtALkEFPC8RQsU9jxapSHboVFBVFcdEdaRtHpRgfRmLLCyQne5FzyGYsUWZx,5SeNtCBx15SLG7VHKh1g5Ntj3pBUvo5ik1RBMz6uWsD7,So11111111111111111111111111111111111111112,0.004846682,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,0.00004932,3
|
||||
2oxFxDrRiaK5KPtXs5i2wiJVH332nvj38yzZFrYhJpk1Qp1EEU4srB71BzE7egbLjsiYkiLtY24iFWv3eQjerkoR,6jPZyLmDNRJDMKEWD7fRJF6ZG1K9xkoCUYBtBcYKTKh3,iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns,5000,hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux,1.24113139,1
|
||||
PjsiQNcw6Gj8oy5kfFTrJYWGsAByvPMCCbFyKn94hWHdpJsKyx91jLu3x3qiLFAD6FsCUQoddosc9WrFGJkdHPT,FkrJtvLar5nSrNjCC4nsnx1r9BPV18Znuz41P4K4VtTD,7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU,6778.7418,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,25.105294,2
|
||||
4uGmB1tmQafyxtarFHnmbCAiK9JerfkkzNxopnEBzrA3BegKgbbwCcUzSjFqWuWZmG4gryDcmMsdkVhSaN5wAKin,Azv6MPxWSF3QPrVwuMYWhzAHomXHR21w1tWN3QFLYSmo,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,36.585292,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,0.02,2
|
||||
54JLHAeGxMsnHzB3WFVgEpFKg9BoWnmqxm58CJqPKno3vTAULfBTELyZfAs95i3jkpfcKD7vx99ch1oLnbFZaHDc,9zg3seAh4Er1Nz8GAuiciH437apxtzgUWBT8frhudevR,2kMpEJCZL8vEDZe7YPLMCS9Y3WKSAMedXBn7xHPvsWvi,3551.34213,So11111111111111111111111111111111111111112,0.00085794,2
|
||||
3HYjbvaqNd9XN7966LJas8VnAnVrTNd1yCNDqnNoCgWaQavMrumxXXGw1qiQVhmDg1VReJZFnT8rsWMkRH56xhv5,HKDKrp4s3spsEb1826yLAgCmvm4QqCeeHuwjtAXAwxaW,iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns,447000,hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux,112.55026207,1
|
||||
2tHcbLfg5cWmuqYHUeKFK3DffmpmyHx5LuxwiKT9m1Hg9645BemDcyuHRNuFE2XCaJ6Unrmcjz4NryqNKivvmh4m,Fp2C2dFTa7UFprUEZYsaKQKckLWNUd2HFcLusBDty19p,So11111111111111111111111111111111111111112,2.73,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,2.44161061,4
|
||||
4YVJXQM6tnn2ZCUrbdSCZTkafyMXi3q7aXPZJtSziExkbG8MLKAhd57zZwy5ALCq8x4HBEe1qU4b8YZ6YUKQHrtg,9fyn5Ra34NJytmDX25PWV6bb2hDDgCYamFVHVzywBHoM,7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj,76.22136708,bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1,79.62696554,1
|
||||
3DQUWFHU2wYzaoKxoW2gn2VeytFAJBwtfxgW4XaMar6fmEFJofiUJ9594V1tej9RhNmrzEx2C9zAQuojKWrcKPJs,4C1QjT4qh1AC7qjviLcP6xHiyF6ApgyAJuhaNg6yH3R5,7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj,497.68980451,J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn,530.87522371,2
|
||||
2LrMaVMCCBaf8tNeTy65QxMvtj5dabHx41shreuJu5pFxy8rkJwguthFfszULT7yxLVkMKUV4y2yjeyXUJKQ599B,9fyn5Ra34NJytmDX25PWV6bb2hDDgCYamFVHVzywBHoM,So11111111111111111111111111111111111111112,199.42230514,mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So,177.92142306,4
|
||||
9WwUywW8j9tm58Qa2MjADiDYgLqVfEzRpQjDFtwnhenJDbMshzd7cgzTxokfunGSYqtp6uE3RBGEQ2MF3FPp9gM,AQknXHXuYYeezphiY2sb9SmxBbJLv833JEwc9Q8vBNP2,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,68,bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1,2.53534484,4
|
||||
5nXQfkg7AKdHeC9kLQUgyKUjebCx17ZswGYuar8whMAtptz2ssBcjRsSaZQ7AdpGDCvX36XqyMRx2xa8RjAcdSoc,844fKP7j6XuUgVffVzhmSSZLYSQdmiL6G8uZpXvD5NXu,So11111111111111111111111111111111111111112,200,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,3333.003723,5
|
||||
|
9
data/testing__swaps_intermediate_jupiterv6.csv
Normal file
9
data/testing__swaps_intermediate_jupiterv6.csv
Normal file
@ -0,0 +1,9 @@
|
||||
tx_id,swapper,from_amt,from_mint,to_amt,to_mint,swap_index
|
||||
33NLhAHDz2dAVRCqfgankDS2CAr78J1Q7LorotWhTaqcT2EDAVzPaWDK2sQsw4zSJM1KVXWzxvx6mDpvzAmNkzN1,CwCjc3BbNEbhqmBV2s1FGJDYxMWeMeJRZEP1zdWQ2dcy,950.491457,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,45.881,So11111111111111111111111111111111111111112,5
|
||||
3DqnEWswNa8qD7GrqxUi7yyD2fgAk8GYdykHX6aZRQpxbVrdkj3rcFHPF13WuS7oMRs2gqtJGDcjCkDXzD5geprS,AwqwB1CehyuriGiZLXueyo7PmKwHwf23a77SY9GSwpAe,0.05,So11111111111111111111111111111111111111112,1.01476,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,4
|
||||
4ckGB7iEDkxgtZszKRn1xLvYFSGBanuF2PwhTyqwWAdgqZLPezvtLwrDHUGQoZVYQHyruXjVjLLmNf6wEiyVnuhf,EccxYg7rViwYfn9EMoNu7sUaV82QGyFt6ewiQaH1GYjv,280.017141,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,350.352807836,AURYydfxJib1ZkTir1Jn1J9ECYUtjb6rKQVmtYaixWPP,1
|
||||
5dnKpNshPu6F7JnhHRjGNodUrigVYmUq2ffVdyxPFn8ABWNcNg9p9v3GBZd4N9R3qk2nnHKk1PcnVSxu7HYfYeUX,AfQ1oaudsGjvznX4JNEw671hi57JfWo4CWqhtkdgoVHU,62.87570818,poLisWXnNRwC6oBu1vHiuKQzFjGL4XDSu4g9qjz9qVk,0.281074736,So11111111111111111111111111111111111111112,2
|
||||
5nhXU7f282fFdi3FynukwNLiybV5NYqptUNU6BJH7RpYRPe4mcporxadKmhC9ioxx3vJp9uVmMbXz35QffHTxrFz,UPLyv3ParCUUkYF5y5TW5HTJre7S8VxUChcdU98wBVi,20,SHDWyBxihqiCj6YekG2GUr7wqKLeLAMK1gHZck9pL6y,1977.414794742,5qKDWkBejLtRh1UGFV7e58QEkdn2fRyH5ehVXqUYujNW,2
|
||||
5YrfH1RDhZkhh98eikYFcuqRxHY8K87A7hBBFAasaJyCeMW1dr1nG5xNDps3e3GaHnt2cp1tssZJQS2eFaUwcPz9,S5ARSDD3ddZqqqqqb2EUE2h2F1XQHBk7bErRW1WPGe4,0.00097,So11111111111111111111111111111111111111112,0.018899,EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v,4
|
||||
GD7mFaoiFFxRKEi4EfYbRHmCRN1Q7hCwrQaZbiRq998vXU7bwY22ET1SwXcgDYKSbVLVTmkbM7HgE7G1HSJDT4T,8wHvL3R61pqVxi3TLmsB9pXYGnJB1saR9rFyfpbk18sN,4908.088807,iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns,0.115696271,So11111111111111111111111111111111111111112,2
|
||||
JLHisghyiom2v1fY4z2tntjQYz7Fupe679pTJSuWaPvymEwEau9WvFbxGEyvvM1SPZqZPHKroLWqZkrrXtH9WkP,AHH4fRDrZv49kWmBqLonvVJbcDNs3J4faXCEWRH584v8,0.197252365,So11111111111111111111111111111111111111112,0.00247394,7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs,6
|
||||
|
@ -50,6 +50,10 @@
|
||||
create_udf_get_tx_size(
|
||||
schema = "silver"
|
||||
) }}
|
||||
{{
|
||||
create_udf_get_account_pubkey_by_name(
|
||||
schema = "silver"
|
||||
) }}
|
||||
{% endset %}
|
||||
{% do run_query(sql) %}
|
||||
{% endif %}
|
||||
|
||||
@ -275,4 +275,23 @@ def get_tx_size(accts, instructions, version, addr_lookups, signers) -> int:
|
||||
return transaction_size
|
||||
|
||||
$$;
|
||||
{% endmacro %}
|
||||
|
||||
{% macro create_udf_get_account_pubkey_by_name(schema) %}
|
||||
create or replace function {{ schema }}.udf_get_account_pubkey_by_name(name string, accounts array)
|
||||
returns string
|
||||
language python
|
||||
runtime_version = '3.8'
|
||||
handler = 'get_account_pubkey_by_name'
|
||||
as
|
||||
$$
|
||||
def get_account_pubkey_by_name(name, accounts) -> str:
|
||||
if accounts is None:
|
||||
return None
|
||||
for i,a in enumerate(accounts):
|
||||
if a and a.get("name","").lower() == name.lower():
|
||||
return a.get("pubkey")
|
||||
|
||||
return None
|
||||
$$;
|
||||
{% endmacro %}
|
||||
@ -22,3 +22,63 @@ FROM
|
||||
LEFT OUTER JOIN {{ ref('core__dim_labels') }}
|
||||
l
|
||||
ON s.program_id = l.address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
succeeded,
|
||||
swapper,
|
||||
from_amt AS swap_from_amount,
|
||||
from_mint AS swap_from_mint,
|
||||
to_amt AS swap_to_amount,
|
||||
to_mint AS swap_to_mint,
|
||||
program_id,
|
||||
l.address_name AS swap_program,
|
||||
concat_ws('-',tx_id,swap_index) as _log_id
|
||||
FROM
|
||||
{{ ref('silver__swaps_intermediate_jupiterv6') }}
|
||||
s
|
||||
LEFT OUTER JOIN {{ ref('core__dim_labels') }}
|
||||
l
|
||||
ON s.program_id = l.address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
succeeded,
|
||||
swapper,
|
||||
from_amt AS swap_from_amount,
|
||||
from_mint AS swap_from_mint,
|
||||
to_amt AS swap_to_amount,
|
||||
to_mint AS swap_to_mint,
|
||||
program_id,
|
||||
l.address_name AS swap_program,
|
||||
concat_ws('-',tx_id,swap_index) as _log_id
|
||||
FROM
|
||||
{{ source('solana_silver','swaps_intermediate_jupiterv5_1') }}
|
||||
s
|
||||
LEFT OUTER JOIN {{ ref('core__dim_labels') }}
|
||||
l
|
||||
ON s.program_id = l.address
|
||||
UNION ALL
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
succeeded,
|
||||
swapper,
|
||||
from_amt AS swap_from_amount,
|
||||
from_mint AS swap_from_mint,
|
||||
to_amt AS swap_to_amount,
|
||||
to_mint AS swap_to_mint,
|
||||
program_id,
|
||||
l.address_name AS swap_program,
|
||||
concat_ws('-',tx_id,swap_index) as _log_id
|
||||
FROM
|
||||
{{ source('solana_silver','swaps_intermediate_jupiterv5_2') }}
|
||||
s
|
||||
LEFT OUTER JOIN {{ ref('core__dim_labels') }}
|
||||
l
|
||||
ON s.program_id = l.address
|
||||
|
||||
@ -283,4 +283,4 @@ FROM
|
||||
WHERE
|
||||
succeeded = FALSE qualify(ROW_NUMBER() over (PARTITION BY block_id, tx_id, program_id, from_mint, to_mint
|
||||
ORDER BY
|
||||
block_timestamp)) = 1
|
||||
block_timestamp)) = 1
|
||||
209
models/silver/swaps/silver__swaps_intermediate_jupiterv5_1.sql
Normal file
209
models/silver/swaps/silver__swaps_intermediate_jupiterv5_1.sql
Normal file
@ -0,0 +1,209 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['tx_id','swap_index','program_id'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
|
||||
enabled=false
|
||||
) }}
|
||||
|
||||
WITH base_events AS(
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
program_id = 'JUP5pEAZeHdHrLxh5UCwAbpjGwYKKoquCpda2hfP4u8'
|
||||
AND
|
||||
succeeded
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-05-30' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_decoded as (
|
||||
select
|
||||
*
|
||||
from
|
||||
{{ ref('silver__decoded_instructions') }}
|
||||
WHERE
|
||||
program_id = 'JUP5pEAZeHdHrLxh5UCwAbpjGwYKKoquCpda2hfP4u8'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-05-30' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_transfers as (
|
||||
SELECT
|
||||
*,
|
||||
split(index,'.') as split_index,
|
||||
concat_ws('.',split_index[0],lpad(split_index[1],2,'0')) as padded_index
|
||||
FROM
|
||||
{{ ref('silver__transfers') }}
|
||||
WHERE
|
||||
succeeded
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-05-30' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_token_mint_actions as (
|
||||
SELECT
|
||||
tma.*,
|
||||
ma.token_account
|
||||
FROM
|
||||
{{ ref('silver__mint_actions') }} ma
|
||||
join {{ ref('silver__token_mint_actions') }} tma
|
||||
on ma.block_timestamp::date = tma.block_timestamp::date
|
||||
and ma.tx_id = tma.tx_id
|
||||
and ma.index = tma.index
|
||||
and ma.inner_index = tma.inner_index
|
||||
WHERE
|
||||
ma.succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND ma._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND ma.block_timestamp :: DATE >= '2023-05-30' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
pre_final as (
|
||||
select
|
||||
e.block_id,
|
||||
e.block_timestamp,
|
||||
e.tx_id,
|
||||
e.index,
|
||||
e.program_id,
|
||||
e.succeeded,
|
||||
silver.udf_get_account_pubkey_by_name('userTransferAuthority', d.decoded_instruction:accounts) as swapper,
|
||||
silver.udf_get_account_pubkey_by_name('destinationTokenAccount', d.decoded_instruction:accounts) as dest_token_account,
|
||||
e._inserted_timestamp
|
||||
from base_events e
|
||||
left outer join base_decoded d
|
||||
on e.block_timestamp::date = d.block_timestamp::date
|
||||
and e.tx_id = d.tx_id
|
||||
and e.index = d.index
|
||||
where decoded_instruction:error::string is null /* a few non-swap instructions resulted in errors in idl parsing */
|
||||
and decoded_instruction:name::string <> 'createOpenOrders'
|
||||
and swapper is not null /* eliminate non-swap instructions */
|
||||
),
|
||||
source_transfers as (
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index,
|
||||
pf.program_id,
|
||||
tr.source_token_account,
|
||||
max(tr.mint) as mint,
|
||||
sum(tr.amount) as amount,
|
||||
min(padded_index) as tr_index
|
||||
from
|
||||
pre_final pf
|
||||
left outer join base_transfers tr
|
||||
on pf.block_timestamp::date = tr.block_timestamp::date
|
||||
and pf.tx_id = tr.tx_id
|
||||
and pf.index = split(tr.index,'.')[0]::number
|
||||
and pf.swapper = tr.tx_from
|
||||
group by 1,2,3,4,5,6
|
||||
qualify(row_number() over (partition by pf.tx_id, pf.index order by tr_index)) = 1
|
||||
),
|
||||
find_null_source_mints as (
|
||||
select
|
||||
st.tx_id,
|
||||
st.index,
|
||||
tr.mint
|
||||
from source_transfers st
|
||||
join base_transfers tr on st.tx_id = tr.tx_id and (st.source_token_account = tr.tx_to or st.source_token_account = tr.tx_from) and tr.mint is not null
|
||||
where st.mint is null
|
||||
),
|
||||
dest_transfers as (
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index,
|
||||
pf.program_id,
|
||||
pf.dest_token_account,
|
||||
tr.mint,
|
||||
sum(tr.amount) as amount
|
||||
from
|
||||
pre_final pf
|
||||
left outer join base_transfers tr
|
||||
on pf.block_timestamp::date = tr.block_timestamp::date
|
||||
and pf.tx_id = tr.tx_id
|
||||
and pf.index = split(tr.index,'.')[0]::number
|
||||
and pf.dest_token_account = coalesce(tr.dest_token_account,tr.tx_to)
|
||||
group by 1,2,3,4,5,6,7
|
||||
),
|
||||
find_marinade_deposits as (
|
||||
select
|
||||
dt.tx_id,
|
||||
dt.index,
|
||||
tma.mint,
|
||||
tma.mint_amount * pow(10,-tma.decimal) as amount
|
||||
from dest_transfers dt
|
||||
join base_token_mint_actions tma
|
||||
on dt.block_timestamp::date = tma.block_timestamp::date
|
||||
and dt.tx_id = tma.tx_id
|
||||
and dt.index = tma.index
|
||||
and dt.dest_token_account = tma.token_account
|
||||
where
|
||||
tma.mint_amount is not null
|
||||
and
|
||||
tma.decimal is not null
|
||||
)
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index as swap_index,
|
||||
pf.program_id,
|
||||
pf.succeeded,
|
||||
pf.swapper,
|
||||
st.amount as from_amt,
|
||||
coalesce(st.mint,nm.mint) as from_mint,
|
||||
coalesce(dt.amount,0) + coalesce(md.amount,0) as to_amt,
|
||||
coalesce(dt.mint,md.mint) as to_mint,
|
||||
pf._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['pf.tx_id','pf.index','pf.program_id']) }} as swaps_intermediate_jupiterv5_id,
|
||||
sysdate() as inserted_timestamp,
|
||||
sysdate() as modified_timestamp,
|
||||
'{{ invocation_id }}' AS invocation_id
|
||||
from pre_final pf
|
||||
left outer join source_transfers st
|
||||
on pf.tx_id = st.tx_id
|
||||
and pf.index = st.index
|
||||
left outer join dest_transfers dt
|
||||
on pf.tx_id = dt.tx_id
|
||||
and pf.index = dt.index
|
||||
left outer join find_null_source_mints nm
|
||||
on pf.tx_id = nm.tx_id
|
||||
and pf.index = nm.index
|
||||
left outer join find_marinade_deposits md
|
||||
on pf.tx_id = md.tx_id
|
||||
and pf.index = md.index
|
||||
@ -0,0 +1,80 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__swaps_intermediate_jupiterv5_1
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_ID
|
||||
- SWAP_INDEX
|
||||
- PROGRAM_ID
|
||||
- compare_model_subset:
|
||||
name: silver__swaps_intermediate_jupiterv5_1_business_logic_test
|
||||
compare_model: ref('testing__swaps_intermediate_jupiterv5_1')
|
||||
compare_columns:
|
||||
- tx_id
|
||||
- swapper
|
||||
- from_mint
|
||||
- round(from_amt,8)
|
||||
- to_mint
|
||||
- round(to_amt,8)
|
||||
- swap_index
|
||||
model_condition: "where tx_id in ('2ZDacDp1wdUT9wugzPWKjJ81DnhrQSQZJCvvyRS1CGps7SU4ynLtEbceNQvRmNmsMCHsh8u1nHf3ubKU6GaB2FQq',
|
||||
'3rPg4WvKXtVvxHiM3rUxtZntBJ4BUbCna4isCzorHrZ7ow5XSJ83PXufTmVZtt2D2d2iDbyuLBTYX7SrbWfbWfY7',
|
||||
'2EaNmoZiLacMXuiArEVUb3VkT7qH21EDXvZVfgCNPrXC5DVmapsTBGyRRk97bwnyo7MB5g5J22V3q9u9sk2hGcT7',
|
||||
'661Te778ZUAFiJZBBcKnPJrh45pYt58sbNQJX6m1JuXnJvShWKx1jFhPYaHTpB27FFbkKSWvbQx3gCZ2WmT8h1et',
|
||||
'5pYiirYrJ6JFPWxUtTTJinQzFZAHxS9FMxS3DSzHWwTnit8SD81wLmRxnD9gG3m9624grhRBgKsodqkjW1j5sJuE',
|
||||
'YzW7iKgsuvwUFLDqh1JLTygPecb7cUK3j2oMGmvcWN2LXFep4KpTy3zZvyrboKZncWytJ1CWnxkRM6ZBpdraPBv',
|
||||
'3qsYnQtSZTKFna1Cj8vGqHfpkZaV7Cwubhe5GMAWPREw75evd7WpmzQMTSZrs7tjMzndavwxCdHLr4mNdAQDhqxu',
|
||||
'4pLtamVfK8BzxmtoCJ8w8wo8VcRCjX3fjUhtY8CiW4X3fyTDj8Rjyp4jTiBuiW4rxCJQGfemVypAzqzt7Me99Ct8',
|
||||
'RipLfMrdihYbKFJbC3LvpQHfZHJsQwcsRC6pQnkfJqsXHKdgE6PuW7xU1DKnWQ7ReppeXvigzBXKG6Dy7G6f6vk',
|
||||
'kmjRLLXq9z7kWkibAp6NEYsXxL1G96C7xtpnaRqbvRdZfJfFbWRGqhpkgcJC6fxai7gCvjkBxHzCLFcLwAD3AA5',
|
||||
'4JbowertcD6Fr7GRaUFw3fVTYUz9XYcCrxZyZwai9g9Lxtjj8MVpLRdtc9uBPRxD4QY9BgtAqVWdXhqMjUKn7XPK')"
|
||||
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: SUCCEEDED
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROGRAM_ID
|
||||
description: "{{ doc('program_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAPPER
|
||||
description: "{{ doc('swaps_swapper') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_AMT
|
||||
description: "{{ doc('swaps_from_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_MINT
|
||||
description: "{{ doc('swaps_from_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_AMT
|
||||
description: "{{ doc('swaps_to_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_MINT
|
||||
description: "{{ doc('swaps_to_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAP_INDEX
|
||||
description: "{{ doc('swaps_swap_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
227
models/silver/swaps/silver__swaps_intermediate_jupiterv5_2.sql
Normal file
227
models/silver/swaps/silver__swaps_intermediate_jupiterv5_2.sql
Normal file
@ -0,0 +1,227 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['tx_id','swap_index','program_id'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
|
||||
enabled=false
|
||||
) }}
|
||||
|
||||
WITH base_events AS(
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__events') }}
|
||||
WHERE
|
||||
program_id = 'JUP5cHjnnCx2DppVsufsLrXs8EBZeEZzGtEK9Gdz6ow'
|
||||
AND
|
||||
succeeded
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-06-06' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_decoded as (
|
||||
select
|
||||
*
|
||||
from
|
||||
{{ ref('silver__decoded_instructions') }}
|
||||
WHERE
|
||||
program_id = 'JUP5cHjnnCx2DppVsufsLrXs8EBZeEZzGtEK9Gdz6ow'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-06-06' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_transfers as (
|
||||
SELECT
|
||||
*,
|
||||
split(index,'.') as split_index,
|
||||
concat_ws('.',split_index[0],lpad(split_index[1],2,'0')) as padded_index
|
||||
FROM
|
||||
{{ ref('silver__transfers') }}
|
||||
WHERE
|
||||
succeeded
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-06-06' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
base_token_mint_actions as (
|
||||
SELECT
|
||||
tma.*,
|
||||
ma.token_account
|
||||
FROM
|
||||
{{ ref('silver__mint_actions') }} ma
|
||||
join {{ ref('silver__token_mint_actions') }} tma
|
||||
on ma.block_timestamp::date = tma.block_timestamp::date
|
||||
and ma.tx_id = tma.tx_id
|
||||
and ma.index = tma.index
|
||||
and ma.inner_index = tma.inner_index
|
||||
WHERE
|
||||
ma.succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND ma._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND ma.block_timestamp :: DATE >= '2023-06-06' -- first tx with v5
|
||||
{% endif %}
|
||||
),
|
||||
pre_final as (
|
||||
select
|
||||
e.block_id,
|
||||
e.block_timestamp,
|
||||
e.tx_id,
|
||||
e.index,
|
||||
e.program_id,
|
||||
e.succeeded,
|
||||
silver.udf_get_account_pubkey_by_name('userTransferAuthority', d.decoded_instruction:accounts) as swapper,
|
||||
silver.udf_get_account_pubkey_by_name('destinationTokenAccount', d.decoded_instruction:accounts) as dest_token_account,
|
||||
silver.udf_get_account_pubkey_by_name('destinationMint', d.decoded_instruction:accounts) as destination_mint,
|
||||
iff(OBJECT_KEYS(decoded_instruction:args:routePlan:"0":swap)[0]::string = 'heliumTreasuryManagementRedeemV0', true, false) as is_helium_redeem,
|
||||
iff(OBJECT_KEYS(decoded_instruction:args:routePlan:"0":swap)[0]::string = 'stakeDexSwapViaStake', true, false)as is_stake_dex_swap,
|
||||
iff(OBJECT_KEYS(decoded_instruction:args:routePlan:"0":swap)[0]::string = 'saberAddDecimalsWithdraw', true, false)as is_saber_withdraw,
|
||||
decoded_instruction:args:inAmount::number as args_in_amount,
|
||||
e._inserted_timestamp
|
||||
from base_events e
|
||||
left outer join base_decoded d
|
||||
on e.block_timestamp::date = d.block_timestamp::date
|
||||
and e.tx_id = d.tx_id
|
||||
and e.index = d.index
|
||||
where decoded_instruction:error::string is null /* a few non-swap instructions resulted in errors in idl parsing */
|
||||
and swapper is not null /* eliminate non-swap instructions */
|
||||
and not is_saber_withdraw
|
||||
),
|
||||
swaps_using_burns as (
|
||||
select
|
||||
tx_id,
|
||||
index,
|
||||
iff(is_helium_redeem,'iotEVVZLEywoTn1QdwNPddxPWszn3zFhEot3MfL9fns','7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj') as mint,
|
||||
args_in_amount * pow(10,iff(is_helium_redeem,-6,-9)) as amount
|
||||
from pre_final
|
||||
where
|
||||
(is_helium_redeem or is_stake_dex_swap)
|
||||
),
|
||||
source_transfers as (
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index,
|
||||
pf.program_id,
|
||||
tr.source_token_account,
|
||||
max(tr.mint) as mint,
|
||||
sum(tr.amount) as amount,
|
||||
min(padded_index) as tr_index
|
||||
from
|
||||
pre_final pf
|
||||
left outer join base_transfers tr
|
||||
on pf.block_timestamp::date = tr.block_timestamp::date
|
||||
and pf.tx_id = tr.tx_id
|
||||
and pf.index = split(tr.index,'.')[0]::number
|
||||
and pf.swapper = tr.tx_from
|
||||
group by 1,2,3,4,5,6
|
||||
qualify(row_number() over (partition by pf.tx_id, pf.index order by tr_index)) = 1
|
||||
),
|
||||
find_null_source_mints as (
|
||||
select
|
||||
st.tx_id,
|
||||
st.index,
|
||||
tr.mint
|
||||
from source_transfers st
|
||||
join base_transfers tr on st.tx_id = tr.tx_id and (st.source_token_account = tr.tx_to or st.source_token_account = tr.tx_from) and tr.mint is not null
|
||||
where st.mint is null
|
||||
),
|
||||
dest_transfers as (
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index,
|
||||
pf.program_id,
|
||||
pf.dest_token_account,
|
||||
tr.mint,
|
||||
sum(tr.amount) as amount
|
||||
from
|
||||
pre_final pf
|
||||
left outer join base_transfers tr
|
||||
on pf.block_timestamp::date = tr.block_timestamp::date
|
||||
and pf.tx_id = tr.tx_id
|
||||
and pf.index = split(tr.index,'.')[0]::number
|
||||
and pf.dest_token_account = coalesce(tr.dest_token_account,tr.tx_to)
|
||||
group by 1,2,3,4,5,6,7
|
||||
),
|
||||
find_marinade_deposits as (
|
||||
select
|
||||
dt.tx_id,
|
||||
dt.index,
|
||||
tma.mint,
|
||||
tma.mint_amount * pow(10,-tma.decimal) as amount
|
||||
from dest_transfers dt
|
||||
join base_token_mint_actions tma
|
||||
on dt.block_timestamp::date = tma.block_timestamp::date
|
||||
and dt.tx_id = tma.tx_id
|
||||
and dt.index = tma.index
|
||||
and dt.dest_token_account = tma.token_account
|
||||
where
|
||||
tma.mint_amount is not null
|
||||
and
|
||||
tma.decimal is not null
|
||||
)
|
||||
select
|
||||
pf.block_id,
|
||||
pf.block_timestamp,
|
||||
pf.tx_id,
|
||||
pf.index as swap_index,
|
||||
pf.program_id,
|
||||
pf.succeeded,
|
||||
pf.swapper,
|
||||
coalesce(st.amount,burns.amount) as from_amt,
|
||||
coalesce(st.mint,burns.mint,nm.mint) as from_mint,
|
||||
coalesce(dt.amount,0) + coalesce(md.amount,0) as to_amt,
|
||||
coalesce(dt.mint,md.mint) as to_mint,
|
||||
pf._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['pf.tx_id','pf.index','pf.program_id']) }} as swaps_intermediate_jupiterv5_id,
|
||||
sysdate() as inserted_timestamp,
|
||||
sysdate() as modified_timestamp,
|
||||
'{{ invocation_id }}' AS invocation_id
|
||||
from pre_final pf
|
||||
left outer join source_transfers st
|
||||
on pf.tx_id = st.tx_id
|
||||
and pf.index = st.index
|
||||
left outer join dest_transfers dt
|
||||
on pf.tx_id = dt.tx_id
|
||||
and pf.index = dt.index
|
||||
left outer join swaps_using_burns burns
|
||||
on pf.tx_id = burns.tx_id
|
||||
and pf.index = burns.index
|
||||
left outer join find_null_source_mints nm
|
||||
on pf.tx_id = nm.tx_id
|
||||
and pf.index = nm.index
|
||||
left outer join find_marinade_deposits md
|
||||
on pf.tx_id = md.tx_id
|
||||
and pf.index = md.index
|
||||
@ -0,0 +1,83 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__swaps_intermediate_jupiterv5_2
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_ID
|
||||
- SWAP_INDEX
|
||||
- PROGRAM_ID
|
||||
- compare_model_subset:
|
||||
name: silver__swaps_intermediate_jupiterv5_2_business_logic_test
|
||||
compare_model: ref('testing__swaps_intermediate_jupiterv5_2')
|
||||
compare_columns:
|
||||
- tx_id
|
||||
- swapper
|
||||
- round(from_amt,8)
|
||||
- from_mint
|
||||
- round(to_amt,8)
|
||||
- to_mint
|
||||
- swap_index
|
||||
model_condition: "where tx_id in ('vDN32m4cUoCXG5jTxxbCM6MD4q7X8kXT4AvtDfdjdMdTvfHfmJvUkA4JE7CYf9LZXUfQnFqVXk9nAFsyDeixMgV',
|
||||
'59WjNoQcoHN78GagayEhjrh5STa4XZ3ZiteQZYJjVfiYEwGVVmazQNnMVNPSzWRQAhqoRXnUpNsGrmagayFUzo45',
|
||||
'4mPjnnnbanquhQHbeQofTRurwwdnwBBN5Yuq7xW57RRbxgsoXpa3QMSsTJ1cBDPwh6H1ixypFtnVho6mtsBjxsea',
|
||||
'2tCfkNuhChjFi5WpH4BUpiyw56yvMtALkEFPC8RQsU9jxapSHboVFBVFcdEdaRtHpRgfRmLLCyQne5FzyGYsUWZx',
|
||||
'2oxFxDrRiaK5KPtXs5i2wiJVH332nvj38yzZFrYhJpk1Qp1EEU4srB71BzE7egbLjsiYkiLtY24iFWv3eQjerkoR',
|
||||
'PjsiQNcw6Gj8oy5kfFTrJYWGsAByvPMCCbFyKn94hWHdpJsKyx91jLu3x3qiLFAD6FsCUQoddosc9WrFGJkdHPT',
|
||||
'4uGmB1tmQafyxtarFHnmbCAiK9JerfkkzNxopnEBzrA3BegKgbbwCcUzSjFqWuWZmG4gryDcmMsdkVhSaN5wAKin',
|
||||
'54JLHAeGxMsnHzB3WFVgEpFKg9BoWnmqxm58CJqPKno3vTAULfBTELyZfAs95i3jkpfcKD7vx99ch1oLnbFZaHDc',
|
||||
'3HYjbvaqNd9XN7966LJas8VnAnVrTNd1yCNDqnNoCgWaQavMrumxXXGw1qiQVhmDg1VReJZFnT8rsWMkRH56xhv5',
|
||||
'2tHcbLfg5cWmuqYHUeKFK3DffmpmyHx5LuxwiKT9m1Hg9645BemDcyuHRNuFE2XCaJ6Unrmcjz4NryqNKivvmh4m',
|
||||
'4YVJXQM6tnn2ZCUrbdSCZTkafyMXi3q7aXPZJtSziExkbG8MLKAhd57zZwy5ALCq8x4HBEe1qU4b8YZ6YUKQHrtg',
|
||||
'3DQUWFHU2wYzaoKxoW2gn2VeytFAJBwtfxgW4XaMar6fmEFJofiUJ9594V1tej9RhNmrzEx2C9zAQuojKWrcKPJs',
|
||||
'2LrMaVMCCBaf8tNeTy65QxMvtj5dabHx41shreuJu5pFxy8rkJwguthFfszULT7yxLVkMKUV4y2yjeyXUJKQ599B',
|
||||
'2ZqeMBri7UiSD2TJmp4tJiRGXE6yfg17M7LXL27u89uDRwZtGHieZKQGT2on7g3UEBt4ntP8HzNTAsAWYzke5fYV',
|
||||
'9WwUywW8j9tm58Qa2MjADiDYgLqVfEzRpQjDFtwnhenJDbMshzd7cgzTxokfunGSYqtp6uE3RBGEQ2MF3FPp9gM',
|
||||
'5nXQfkg7AKdHeC9kLQUgyKUjebCx17ZswGYuar8whMAtptz2ssBcjRsSaZQ7AdpGDCvX36XqyMRx2xa8RjAcdSoc')"
|
||||
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: SUCCEEDED
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROGRAM_ID
|
||||
description: "{{ doc('program_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAPPER
|
||||
description: "{{ doc('swaps_swapper') }}"
|
||||
- name: FROM_AMT
|
||||
description: "{{ doc('swaps_from_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_MINT
|
||||
description: "{{ doc('swaps_from_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_AMT
|
||||
description: "{{ doc('swaps_to_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_MINT
|
||||
description: "{{ doc('swaps_to_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAP_INDEX
|
||||
description: "{{ doc('swaps_swap_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
102
models/silver/swaps/silver__swaps_intermediate_jupiterv6.sql
Normal file
102
models/silver/swaps/silver__swaps_intermediate_jupiterv6.sql
Normal file
@ -0,0 +1,102 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
unique_key = ['tx_id','swap_index','program_id'],
|
||||
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
|
||||
merge_exclude_columns = ["inserted_timestamp"],
|
||||
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
|
||||
) }}
|
||||
|
||||
WITH base AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__decoded_instructions') }}
|
||||
WHERE
|
||||
program_id = 'JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4'
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND _inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND block_timestamp :: DATE >= '2023-07-04'
|
||||
{% endif %}
|
||||
),
|
||||
decoded AS (
|
||||
SELECT
|
||||
block_timestamp,
|
||||
block_id,
|
||||
tx_id,
|
||||
index,
|
||||
_inserted_timestamp,
|
||||
program_id,
|
||||
silver.udf_get_account_pubkey_by_name('userTransferAuthority', decoded_instruction:accounts) as swapper,
|
||||
silver.udf_get_account_pubkey_by_name('sourceTokenAccount', decoded_instruction:accounts) as source_token_account,
|
||||
silver.udf_get_account_pubkey_by_name('sourceMint', decoded_instruction:accounts) as source_mint,
|
||||
silver.udf_get_account_pubkey_by_name('destinationMint', decoded_instruction:accounts) as destination_mint,
|
||||
silver.udf_get_account_pubkey_by_name('destinationTokenAccount', decoded_instruction:accounts) as destination_token_account,
|
||||
silver.udf_get_account_pubkey_by_name('programDestinationTokenAccount', decoded_instruction:accounts) as program_destination_token_account,
|
||||
silver.udf_get_account_pubkey_by_name('programSourceTokenAccount', decoded_instruction:accounts) as program_source_token_account
|
||||
FROM
|
||||
base
|
||||
),
|
||||
transfers AS (
|
||||
SELECT
|
||||
A.*
|
||||
FROM
|
||||
{{ ref('silver__transfers') }} A
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
DISTINCT tx_id
|
||||
FROM
|
||||
decoded
|
||||
) d
|
||||
ON d.tx_id = A.tx_id
|
||||
where a.succeeded
|
||||
|
||||
{% if is_incremental() %}
|
||||
AND
|
||||
A._inserted_timestamp >= (
|
||||
SELECT
|
||||
MAX(_inserted_timestamp)
|
||||
FROM
|
||||
{{ this }}
|
||||
)
|
||||
{% else %}
|
||||
AND
|
||||
A.block_timestamp :: DATE >= '2023-07-04'
|
||||
{% endif %}
|
||||
)
|
||||
SELECT
|
||||
A.block_id,
|
||||
A.block_timestamp,
|
||||
A.program_id,
|
||||
A.tx_id,
|
||||
A.index as swap_index,
|
||||
C.succeeded,
|
||||
A.swapper,
|
||||
b.amount AS from_amt,
|
||||
A.source_mint AS from_mint,
|
||||
C.amount AS to_amt,
|
||||
A.destination_mint AS to_mint,
|
||||
A._inserted_timestamp,
|
||||
{{ dbt_utils.generate_surrogate_key(['a.tx_id','a.index','a.program_id']) }} as swaps_intermediate_jupiterv6_id,
|
||||
sysdate() as inserted_timestamp,
|
||||
sysdate() as modified_timestamp,
|
||||
'{{ invocation_id }}' AS invocation_id
|
||||
FROM
|
||||
decoded A
|
||||
inner JOIN transfers b
|
||||
ON A.tx_id = b.tx_id
|
||||
AND A.source_token_account = b.source_token_account
|
||||
AND A.program_source_token_account = b.dest_token_account
|
||||
AND COALESCE(SPLIT_PART(b.index :: text, '.', 1) :: INT, b.index :: INT) = A.index
|
||||
inner JOIN transfers C
|
||||
ON A.tx_id = C.tx_id
|
||||
AND A.destination_token_account = C.dest_token_account
|
||||
AND A.program_destination_token_account = C.source_token_account
|
||||
AND COALESCE(SPLIT_PART(C.index :: text, '.', 1) :: INT, C.index :: INT) = A.index
|
||||
81
models/silver/swaps/silver__swaps_intermediate_jupiterv6.yml
Normal file
81
models/silver/swaps/silver__swaps_intermediate_jupiterv6.yml
Normal file
@ -0,0 +1,81 @@
|
||||
version: 2
|
||||
models:
|
||||
- name: silver__swaps_intermediate_jupiterv6
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- TX_ID
|
||||
- SWAP_INDEX
|
||||
- PROGRAM_ID
|
||||
- compare_model_subset:
|
||||
name: silver__swaps_intermediate_jupiterv6_business_logic_test
|
||||
compare_model: ref('testing__swaps_intermediate_jupiterv6')
|
||||
compare_columns:
|
||||
- tx_id
|
||||
- swapper
|
||||
- round(from_amt,8)
|
||||
- from_mint
|
||||
- round(to_amt,8)
|
||||
- to_mint
|
||||
- swap_index
|
||||
model_condition: "where tx_id in ('33NLhAHDz2dAVRCqfgankDS2CAr78J1Q7LorotWhTaqcT2EDAVzPaWDK2sQsw4zSJM1KVXWzxvx6mDpvzAmNkzN1',
|
||||
'3DqnEWswNa8qD7GrqxUi7yyD2fgAk8GYdykHX6aZRQpxbVrdkj3rcFHPF13WuS7oMRs2gqtJGDcjCkDXzD5geprS',
|
||||
'4ckGB7iEDkxgtZszKRn1xLvYFSGBanuF2PwhTyqwWAdgqZLPezvtLwrDHUGQoZVYQHyruXjVjLLmNf6wEiyVnuhf',
|
||||
'5dnKpNshPu6F7JnhHRjGNodUrigVYmUq2ffVdyxPFn8ABWNcNg9p9v3GBZd4N9R3qk2nnHKk1PcnVSxu7HYfYeUX',
|
||||
'5nhXU7f282fFdi3FynukwNLiybV5NYqptUNU6BJH7RpYRPe4mcporxadKmhC9ioxx3vJp9uVmMbXz35QffHTxrFz',
|
||||
'5YrfH1RDhZkhh98eikYFcuqRxHY8K87A7hBBFAasaJyCeMW1dr1nG5xNDps3e3GaHnt2cp1tssZJQS2eFaUwcPz9',
|
||||
'GD7mFaoiFFxRKEi4EfYbRHmCRN1Q7hCwrQaZbiRq998vXU7bwY22ET1SwXcgDYKSbVLVTmkbM7HgE7G1HSJDT4T',
|
||||
'JLHisghyiom2v1fY4z2tntjQYz7Fupe679pTJSuWaPvymEwEau9WvFbxGEyvvM1SPZqZPHKroLWqZkrrXtH9WkP')"
|
||||
columns:
|
||||
- name: BLOCK_TIMESTAMP
|
||||
description: "{{ doc('block_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_row_values_to_have_recent_data:
|
||||
datepart: day
|
||||
interval: 2
|
||||
- name: BLOCK_ID
|
||||
description: "{{ doc('block_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TX_ID
|
||||
description: "{{ doc('tx_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SUCCEEDED
|
||||
description: "{{ doc('tx_succeeded') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: PROGRAM_ID
|
||||
description: "{{ doc('program_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAPPER
|
||||
description: "{{ doc('swaps_swapper') }}"
|
||||
tests:
|
||||
- not_null:
|
||||
where: succeeded = TRUE
|
||||
- name: FROM_AMT
|
||||
description: "{{ doc('swaps_from_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: FROM_MINT
|
||||
description: "{{ doc('swaps_from_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_AMT
|
||||
description: "{{ doc('swaps_to_amt') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: TO_MINT
|
||||
description: "{{ doc('swaps_to_mint') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: SWAP_INDEX
|
||||
description: "{{ doc('swaps_swap_index') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- name: _INSERTED_TIMESTAMP
|
||||
description: "{{ doc('_inserted_timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
@ -74,6 +74,8 @@ sources:
|
||||
- name: gauges_votes_marinade
|
||||
- name: gauges_creates_marinade
|
||||
- name: nft_sales_coral_cube
|
||||
- name: swaps_intermediate_jupiterv5_1
|
||||
- name: swaps_intermediate_jupiterv5_2
|
||||
- name: solana_streamline
|
||||
schema: streamline
|
||||
tables:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user