dense ranks on all swaps models

This commit is contained in:
drethereum 2023-09-29 16:12:38 -06:00
parent eed3ea241d
commit 705a80c379
13 changed files with 152 additions and 107 deletions

View File

@ -92,3 +92,6 @@ FROM
swaps_base s
INNER JOIN pool_name pn
ON pn.pool_address = s.pool_address
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -213,4 +213,7 @@ SELECT
_inserted_timestamp,
'curve' AS platform
FROM
ready_pool_info
ready_pool_info
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -12,8 +12,9 @@ WITH pools AS (
pool_address,
base_token,
quote_token
FROM {{ ref('silver_dex__dodo_v1_pools') }}
),
FROM
{{ ref('silver_dex__dodo_v1_pools') }}
),
proxies AS (
SELECT
'0xdbfaf391c37339c903503495395ad7d6b096e192' AS proxy_address
@ -126,47 +127,55 @@ AND _inserted_timestamp >= (
{{ this }}
)
{% endif %}
),
FINAL AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
seller_address AS sender,
origin_from_address AS tx_to,
tokenIn AS token_in,
tokenOut AS token_out,
amountIn AS amount_in_unadj,
amountOut AS amount_out_unadj,
'SellBaseToken' AS event_name,
'dodo-v1' AS platform,
_log_id,
_inserted_timestamp
FROM
sell_base_token
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
buyer_address AS sender,
origin_from_address AS tx_to,
tokenIn AS token_in,
tokenOut AS token_out,
amountIn AS amount_in_unadj,
amountOut AS amount_out_unadj,
'BuyBaseToken' AS event_name,
'dodo-v1' AS platform,
_log_id,
_inserted_timestamp
FROM
buy_base_token
)
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
seller_address AS sender,
origin_from_address AS tx_to,
tokenIn AS token_in,
tokenOut AS token_out,
amountIn AS amount_in_unadj,
amountOut AS amount_out_unadj,
'SellBaseToken' AS event_name,
'dodo-v1' AS platform,
_log_id,
_inserted_timestamp
*
FROM
sell_base_token
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
buyer_address AS sender,
origin_from_address AS tx_to,
tokenIn AS token_in,
tokenOut AS token_out,
amountIn AS amount_in_unadj,
amountOut AS amount_out_unadj,
'BuyBaseToken' AS event_name,
'dodo-v1' AS platform,
_log_id,
_inserted_timestamp
FROM
buy_base_token
FINAL qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -114,4 +114,7 @@ SELECT
_inserted_timestamp
FROM
swaps_base
WHERE token_in <> token_out
WHERE token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -210,3 +210,6 @@ FROM
WHERE
token_in <> '0x0000000000000000000000000000000000000000'
AND token_out <> '0x0000000000000000000000000000000000000000'
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -122,3 +122,6 @@ FROM
swaps_base
WHERE
token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -122,3 +122,6 @@ FROM
swaps_base
WHERE
token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -117,3 +117,6 @@ FROM
swaps_base
WHERE
token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -116,3 +116,6 @@ FROM
swaps_base
WHERE
token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -89,6 +89,6 @@ FINAL AS (
SELECT
*
FROM
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
FINAL qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
_inserted_timestamp DESC)) = 1
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -116,3 +116,6 @@ FROM
swaps_base
WHERE
token_in <> token_out
qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -93,6 +93,6 @@ FINAL AS (
SELECT
*
FROM
FINAL qualify(ROW_NUMBER() over(PARTITION BY _log_id
FINAL qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
_inserted_timestamp DESC)) = 1
block_number DESC, _inserted_timestamp DESC)) = 1

View File

@ -59,7 +59,8 @@ WITH router_swaps_base AS (
l
WHERE
contract_address IN (
'0x9d1a92e601db0901e69bd810029f2c14bcca3128', --v1
'0x9d1a92e601db0901e69bd810029f2c14bcca3128',
--v1
'0x817eb46d60762442da3d931ff51a30334ca39b74' --v2
)
AND topics [0] :: STRING = '0x27c98e911efdd224f4002f6cd831c3ad0d2759ee176f9ee8466d95826af22a1c' --WooRouterSwap
@ -142,63 +143,71 @@ AND _inserted_timestamp >= (
{{ this }}
)
{% endif %}
),
FINAL AS (
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
CASE
WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE from_token
END AS token_in,
CASE
WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE to_token
END AS token_out,
to_address AS tx_to,
swapType AS swap_type,
fromAmount AS amount_in_unadj,
toAmount AS amount_out_unadj,
from_address AS sender,
rebateTo AS rebate_to,
'WooRouterSwap' AS event_name,
'woofi' AS platform,
_log_id,
_inserted_timestamp
FROM
router_swaps_base
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
CASE
WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE from_token
END AS token_in,
CASE
WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE to_token
END AS token_out,
to_address AS tx_to,
NULL AS swap_type,
fromAmount AS amount_in_unadj,
toAmount AS amount_out_unadj,
from_address AS sender,
rebateTo AS rebate_to,
'WooSwap' AS event_name,
'woofi' AS platform,
_log_id,
_inserted_timestamp
FROM
swaps_base
)
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
CASE
WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE from_token
END AS token_in,
CASE
WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE to_token
END AS token_out,
to_address AS tx_to,
swapType AS swap_type,
fromAmount AS amount_in_unadj,
toAmount AS amount_out_unadj,
from_address AS sender,
rebateTo AS rebate_to,
'WooRouterSwap' AS event_name,
'woofi' AS platform,
_log_id,
_inserted_timestamp
*
FROM
router_swaps_base
UNION ALL
SELECT
block_number,
block_timestamp,
tx_hash,
origin_function_signature,
origin_from_address,
origin_to_address,
event_index,
contract_address,
CASE
WHEN from_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE from_token
END AS token_in,
CASE
WHEN to_token = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' THEN '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'
ELSE to_token
END AS token_out,
to_address AS tx_to,
NULL AS swap_type,
fromAmount AS amount_in_unadj,
toAmount AS amount_out_unadj,
from_address AS sender,
rebateTo AS rebate_to,
'WooSwap' AS event_name,
'woofi' AS platform,
_log_id,
_inserted_timestamp
FROM
swaps_base
FINAL qualify(DENSE_RANK() over (PARTITION BY tx_hash
ORDER BY
block_number DESC, _inserted_timestamp DESC)) = 1