From f6d80b61eedff24a4a8a4f590aa2c2159d73bccc Mon Sep 17 00:00:00 2001 From: Matt Romano <42412983+mattromano@users.noreply.github.com> Date: Thu, 2 May 2024 12:24:01 -0700 Subject: [PATCH] blitz-perps-fix (#45) * add int udfs * move product id join --- .../protocols/blitz/silver__blitz_perps.sql | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/models/silver/protocols/blitz/silver__blitz_perps.sql b/models/silver/protocols/blitz/silver__blitz_perps.sql index 09e4597..fd00218 100644 --- a/models/silver/protocols/blitz/silver__blitz_perps.sql +++ b/models/silver/protocols/blitz/silver__blitz_perps.sql @@ -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