blitz-perps-fix (#45)

* add int udfs

* move product id join
This commit is contained in:
Matt Romano 2024-05-02 12:24:01 -07:00 committed by GitHub
parent 6f928b22aa
commit f6d80b61ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,10 +44,10 @@ AND _inserted_timestamp >= (
),
order_fill_decode_v2 AS (
SELECT
l.block_number,
l.block_timestamp,
l.tx_hash,
l.contract_address,
block_number,
block_timestamp,
tx_hash,
contract_address,
'FillOrder' AS event_name,
event_index,
origin_function_signature,
@ -57,7 +57,6 @@ order_fill_decode_v2 AS (
utils.udf_hex_to_int(
topics [1] :: STRING
) :: STRING AS product_id,
s.symbol,
topics [2] :: STRING AS digest,
--unique hash of the order
LEFT(
@ -98,36 +97,31 @@ order_fill_decode_v2 AS (
l._inserted_timestamp
FROM
logs l
INNER JOIN blitz_products s
ON s.product_id = utils.udf_hex_to_int(
topics [1] :: STRING
)
),
order_fill_format AS (
SELECT
block_number,
block_timestamp,
tx_hash,
contract_address,
l.block_number,
l.block_timestamp,
l.tx_hash,
l.contract_address,
event_name,
event_index,
origin_function_signature,
origin_from_address,
origin_to_address,
symbol,
product_id,
s.symbol,
l.product_id,
digest,
trader,
subaccount,
expiration AS expiration_raw,
arbitrum.UTILS.UDF_INT_TO_BINARY(TRY_TO_NUMBER(expiration)) AS exp_binary,
arbitrum.utils.udf_binary_to_int(SUBSTR(exp_binary, -2)) AS order_type,
arbitrum.utils.udf_binary_to_int(SUBSTR(exp_binary, -3, 1)) AS market_reduce_flag,
utils.udf_int_to_binary(TRY_TO_NUMBER(expiration)) AS exp_binary,
utils.udf_binary_to_int(SUBSTR(exp_binary, -2)) AS order_type,
utils.udf_binary_to_int(SUBSTR(exp_binary, -3, 1)) AS market_reduce_flag,
CASE
WHEN len(expiration) < 11 THEN TRY_TO_TIMESTAMP(arbitrum.utils.udf_binary_to_int(exp_binary) :: STRING)
WHEN len(expiration) < 11 THEN TRY_TO_TIMESTAMP(utils.udf_binary_to_int(exp_binary) :: STRING)
ELSE TRY_TO_TIMESTAMP(
arbitrum.utils.udf_binary_to_int(SUBSTR(exp_binary, 24)) :: STRING
utils.udf_binary_to_int(SUBSTR(exp_binary, 24)) :: STRING
)
END AS expiration,
nonce,
@ -160,7 +154,9 @@ order_fill_format AS (
_log_id,
_inserted_timestamp
FROM
order_fill_decode_v2
order_fill_decode_v2 l
INNER JOIN blitz_products s
ON s.product_id = l.product_id
),
FINAL AS (
SELECT