From 81c7d43bc370d19344a9c597e2598474a26c06c7 Mon Sep 17 00:00:00 2001 From: Lukasz Cwik Date: Thu, 9 Nov 2023 12:23:12 -0800 Subject: [PATCH] [IND-399] Improve comments, remove SQL function that wasn't being used, fix some stylistic choices in case statements. --- .../ender/__tests__/scripts/scripts.test.ts | 13 ------- .../helpers/postgres/postgres-functions.ts | 1 - ...dydx_clob_pair_status_to_market_status.sql | 8 ++-- .../scripts/dydx_create_tendermint_event.sql | 6 +-- .../src/scripts/dydx_deleveraging_handler.sql | 14 +++---- .../src/scripts/dydx_event_id_from_parts.sql | 4 +- .../dydx_event_to_transaction_index.sql | 21 ---------- .../scripts/dydx_from_protocol_order_side.sql | 8 ++-- .../dydx_from_protocol_time_in_force.sql | 16 ++++---- .../scripts/dydx_from_serializable_int.sql | 4 +- .../src/scripts/dydx_funding_handler.sql | 6 +-- .../src/scripts/dydx_get_order_status.sql | 39 +++++++++++-------- .../src/scripts/dydx_get_weighted_average.sql | 2 +- ...ydx_liquidation_fill_handler_per_order.sql | 12 +++--- .../scripts/dydx_liquidity_tier_handler.sql | 4 +- .../scripts/dydx_market_create_handler.sql | 4 +- .../scripts/dydx_market_modify_handler.sql | 4 +- .../dydx_market_price_update_handler.sql | 6 +-- .../dydx_order_fill_handler_per_order.sql | 12 +++--- .../scripts/dydx_perpetual_market_handler.sql | 4 +- ..._protocol_condition_type_to_order_type.sql | 22 +++-------- .../scripts/dydx_stateful_order_handler.sql | 4 +- .../dydx_subaccount_update_handler.sql | 10 ++--- ..._tendermint_event_to_transaction_index.sql | 25 +++++------- .../src/scripts/dydx_transfer_handler.sql | 8 ++-- .../scripts/dydx_update_clob_pair_handler.sql | 4 +- .../scripts/dydx_update_perpetual_handler.sql | 4 +- .../dydx_uuid_from_oracle_price_parts.sql | 2 +- .../src/scripts/dydx_uuid_from_order_id.sql | 2 +- .../scripts/dydx_uuid_from_order_id_parts.sql | 2 +- .../scripts/dydx_uuid_from_subaccount_id.sql | 2 +- .../dydx_uuid_from_subaccount_id_parts.sql | 2 +- 32 files changed, 114 insertions(+), 161 deletions(-) delete mode 100644 indexer/services/ender/src/scripts/dydx_event_to_transaction_index.sql diff --git a/indexer/services/ender/__tests__/scripts/scripts.test.ts b/indexer/services/ender/__tests__/scripts/scripts.test.ts index 7be6875a340..7b602792555 100644 --- a/indexer/services/ender/__tests__/scripts/scripts.test.ts +++ b/indexer/services/ender/__tests__/scripts/scripts.test.ts @@ -134,19 +134,6 @@ describe('SQL Function Tests', () => { )); }); - it.each([ - { transactionIndex: 5 } as IndexerTendermintEvent, - { - blockEvent: IndexerTendermintEvent_BlockEvent.BLOCK_EVENT_BEGIN_BLOCK, - } as IndexerTendermintEvent, - { - blockEvent: IndexerTendermintEvent_BlockEvent.BLOCK_EVENT_END_BLOCK, - } as IndexerTendermintEvent, - ])('dydx_event_to_transaction_index (%s)', async (event: IndexerTendermintEvent) => { - const result = await getSingleRawQueryResultRow(`SELECT dydx_event_to_transaction_index('${JSON.stringify(event)}') AS result;`); - expect(result).toEqual(indexerTendermintEventToTransactionIndex(event)); - }); - it.each([ Long.fromNumber(1_000_000_000, true), Long.fromNumber(1_000_000_000, false), diff --git a/indexer/services/ender/src/helpers/postgres/postgres-functions.ts b/indexer/services/ender/src/helpers/postgres/postgres-functions.ts index 058238fc152..d822bc411f7 100644 --- a/indexer/services/ender/src/helpers/postgres/postgres-functions.ts +++ b/indexer/services/ender/src/helpers/postgres/postgres-functions.ts @@ -36,7 +36,6 @@ const scripts: string[] = [ 'dydx_market_modify_handler.sql', 'dydx_market_price_update_handler.sql', 'dydx_event_id_from_parts.sql', - 'dydx_event_to_transaction_index.sql', 'dydx_from_jsonlib_long.sql', 'dydx_from_protocol_order_side.sql', 'dydx_from_protocol_time_in_force.sql', diff --git a/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql b/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql index 6d69b9dd7fd..14272a0ae10 100644 --- a/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql +++ b/indexer/services/ender/src/scripts/dydx_clob_pair_status_to_market_status.sql @@ -1,10 +1,10 @@ /** - Returns the market status (https://github.com/dydxprotocol/v4-chain/blob/ea4f6895a73627aaa9bc5e21eed1ba51313b1ce4/indexer/packages/postgres/src/types/perpetual-market-types.ts#L60) - from the clob pair status (https://github.com/dydxprotocol/v4-chain/blob/ea4f6895a73627aaa9bc5e21eed1ba51313b1ce4/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L157). - The conversion is equivalent to https://github.com/dydxprotocol/v4-chain/blob/ea4f6895a73627aaa9bc5e21eed1ba51313b1ce4/indexer/packages/postgres/src/lib/protocol-translations.ts#L351. + Returns the market status (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/types/perpetual-market-types.ts#L60) + from the clob pair status (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L157). + The conversion is equivalent to https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/lib/protocol-translations.ts#L351. Parameters: - - status: the ClobPairStatus (https://github.com/dydxprotocol/v4-chain/blob/ea4f6895a73627aaa9bc5e21eed1ba51313b1ce4/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L157) + - status: the ClobPairStatus (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L157) */ CREATE OR REPLACE FUNCTION dydx_clob_pair_status_to_market_status(status jsonb) RETURNS text AS $$ diff --git a/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql b/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql index aeaf41fe53d..09da974ee16 100644 --- a/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql +++ b/indexer/services/ender/src/scripts/dydx_create_tendermint_event.sql @@ -15,9 +15,9 @@ BEGIN transaction_idx := dydx_tendermint_event_to_transaction_index(event); event_id := dydx_event_id_from_parts(CAST(block_height AS int), transaction_idx, CAST(event->>'eventIndex' AS int)); - INSERT INTO tendermint_events ("id", "blockHeight", "transactionIndex", "eventIndex") - VALUES (event_id, block_height::bigint, transaction_idx, CAST(event->>'eventIndex' AS int)) - RETURNING to_jsonb(tendermint_events.*) INTO inserted_event; + INSERT INTO tendermint_events ("id", "blockHeight", "transactionIndex", "eventIndex") + VALUES (event_id, block_height::bigint, transaction_idx, CAST(event->>'eventIndex' AS int)) + RETURNING to_jsonb(tendermint_events.*) INTO inserted_event; RETURN inserted_event; END; diff --git a/indexer/services/ender/src/scripts/dydx_deleveraging_handler.sql b/indexer/services/ender/src/scripts/dydx_deleveraging_handler.sql index 421e1232b06..187dd4dedf7 100644 --- a/indexer/services/ender/src/scripts/dydx_deleveraging_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_deleveraging_handler.sql @@ -2,18 +2,18 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) - transaction_hash: The transaction hash corresponding to this event from the IndexerTendermintBlock 'tx_hashes'. Returns: JSON object containing fields: - - liquidated_fill: The created liquidated fill in fill-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/fill-model.ts). - - offsetting_fill: The created offsetting fill in fill-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/fill-model.ts). - - perpetual_market: The perpetual market for the deleveraging in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). - - liquidated_perpetual_position: The updated liquidated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-position-model.ts). - - offsetting_perpetual_position: The updated offsetting perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-position-model.ts). + - liquidated_fill: The created liquidated fill in fill-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/fill-model.ts). + - offsetting_fill: The created offsetting fill in fill-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/fill-model.ts). + - perpetual_market: The perpetual market for the deleveraging in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). + - liquidated_perpetual_position: The updated liquidated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-position-model.ts). + - offsetting_perpetual_position: The updated offsetting perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-position-model.ts). */ CREATE OR REPLACE FUNCTION dydx_deleveraging_handler( block_height int, block_time timestamp, event_data jsonb, event_index int, transaction_index int, diff --git a/indexer/services/ender/src/scripts/dydx_event_id_from_parts.sql b/indexer/services/ender/src/scripts/dydx_event_id_from_parts.sql index f66d772fda5..801be4e3892 100644 --- a/indexer/services/ender/src/scripts/dydx_event_id_from_parts.sql +++ b/indexer/services/ender/src/scripts/dydx_event_id_from_parts.sql @@ -4,7 +4,7 @@ Parameters: - block_height: the height of the block being processing. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) - event_index: The 'event_index' of the IndexerTendermintEvent. */ CREATE OR REPLACE FUNCTION dydx_event_id_from_parts(block_height int, transaction_index int, event_index int) RETURNS bytea AS $$ @@ -14,7 +14,7 @@ BEGIN || is the byte string concatenation operator. transactionIndex is -2 for BEGIN_BLOCK events, and -1 for END_BLOCK events. Increment by 2 to ensure result is >= 0. - See https://github.com/dydxprotocol/indexer/blob/6aafb97/packages/postgres/src/stores/tendermint-event-table.ts#L33 + See https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/stores/tendermint-event-table.ts#L34 */ RETURN int4send(block_height) || int4send(transaction_index + 2) || int4send(event_index); END; diff --git a/indexer/services/ender/src/scripts/dydx_event_to_transaction_index.sql b/indexer/services/ender/src/scripts/dydx_event_to_transaction_index.sql deleted file mode 100644 index f36d78de022..00000000000 --- a/indexer/services/ender/src/scripts/dydx_event_to_transaction_index.sql +++ /dev/null @@ -1,21 +0,0 @@ -/** - Converts a JSON.stringify format of an IndexerTendermintEvent to a transaction index (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25). -*/ -CREATE OR REPLACE FUNCTION dydx_event_to_transaction_index(event jsonb) RETURNS int AS $$ -BEGIN - IF event->'transactionIndex' IS NOT NULL THEN - RETURN (event->'transactionIndex')::int; - ELSIF event->'blockEvent' IS NOT NULL THEN - CASE event->'blockEvent' - WHEN '1'::jsonb /* BLOCK_EVENT_BEGIN_BLOCK */ - THEN RETURN -2; - WHEN '2'::jsonb /* BLOCK_EVENT_END_BLOCK */ - THEN RETURN -1; - ELSE - RAISE EXCEPTION 'Received V4 event with invalid block event type: %', event->'blockEvent'; - END CASE; - END IF; - - RAISE EXCEPTION 'TendermintEventTable.orderingWithinBlock.oneOfKind cannot be undefined'; -END; -$$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; diff --git a/indexer/services/ender/src/scripts/dydx_from_protocol_order_side.sql b/indexer/services/ender/src/scripts/dydx_from_protocol_order_side.sql index f9d7571761f..e00e212c85d 100644 --- a/indexer/services/ender/src/scripts/dydx_from_protocol_order_side.sql +++ b/indexer/services/ender/src/scripts/dydx_from_protocol_order_side.sql @@ -1,14 +1,12 @@ /** - Converts the 'Side' enum from the IndexerOrder protobuf (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/clob.proto#L56) + Converts the 'Side' enum from the IndexerOrder protobuf (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L56) to the 'OrderSide' enum in postgres. */ CREATE OR REPLACE FUNCTION dydx_from_protocol_order_side(order_side jsonb) RETURNS text AS $$ BEGIN CASE order_side - WHEN '1'::jsonb THEN - RETURN 'BUY'; - ELSE - RETURN 'SELL'; + WHEN '1'::jsonb THEN RETURN 'BUY'; /** SIDE_BUY */ + ELSE RETURN 'SELL'; END CASE; END; $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; diff --git a/indexer/services/ender/src/scripts/dydx_from_protocol_time_in_force.sql b/indexer/services/ender/src/scripts/dydx_from_protocol_time_in_force.sql index cebb60656fe..12712187c4f 100644 --- a/indexer/services/ender/src/scripts/dydx_from_protocol_time_in_force.sql +++ b/indexer/services/ender/src/scripts/dydx_from_protocol_time_in_force.sql @@ -1,5 +1,5 @@ /** - Converts the TimeInForce field from an IndexerOrder proto (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/clob.proto#L95) + Converts the TimeInForce field from an IndexerOrder proto (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L94) to a TimeInForce enum in postgres. Raise an exception if the input TimeInForce enum is not in the known enum values for TimeInForce. @@ -7,14 +7,12 @@ CREATE OR REPLACE FUNCTION dydx_from_protocol_time_in_force(tif jsonb) RETURNS text AS $$ BEGIN CASE tif - -- Default behavior with UNRECOGNIZED = GTT (Good-Til-Time) - WHEN '-1'::jsonb THEN RETURN 'GTT'; - -- Default behavior with TIME_IN_FORCE_UNSPECIFIED = GTT (Good-Til-Time) - WHEN '0'::jsonb THEN RETURN 'GTT'; - WHEN '1'::jsonb THEN RETURN 'IOC'; - WHEN '2'::jsonb THEN RETURN 'POST_ONLY'; - WHEN '3'::jsonb THEN RETURN 'FOK'; + WHEN '-1'::jsonb THEN RETURN 'GTT'; /** Default behavior with UNRECOGNIZED = GTT (Good-Til-Time) */ + WHEN '0'::jsonb THEN RETURN 'GTT'; /** Default behavior with TIME_IN_FORCE_UNSPECIFIED = GTT (Good-Til-Time) */ + WHEN '1'::jsonb THEN RETURN 'IOC'; /** TIME_IN_FORCE_IOC */ + WHEN '2'::jsonb THEN RETURN 'POST_ONLY'; /** TIME_IN_FORCE_POST_ONLY */ + WHEN '3'::jsonb THEN RETURN 'FOK'; /** TIME_IN_FORCE_FILL_OR_KILL */ ELSE RAISE EXCEPTION 'Unexpected TimeInForce from protocol %', tif; - END CASE; + END CASE; END; $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; diff --git a/indexer/services/ender/src/scripts/dydx_from_serializable_int.sql b/indexer/services/ender/src/scripts/dydx_from_serializable_int.sql index 447e10cfbde..02e03c7b10c 100644 --- a/indexer/services/ender/src/scripts/dydx_from_serializable_int.sql +++ b/indexer/services/ender/src/scripts/dydx_from_serializable_int.sql @@ -1,7 +1,7 @@ /** Converts a JSON.stringify byte array representing a SerializableInt - (https://github.com/dydxprotocol/v4/blob/f77b074/dtypes/serializable_int.go#L57) to a numeric. Note that the - underlying SerializableInt encoding format uses the big.Int GobEncoding + (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/protocol/dtypes/serializable_int.go#L84) to a numeric. + Note that the underlying SerializableInt encoding format uses the big.Int GobEncoding (https://github.com/golang/go/blob/886fba5/src/math/big/intmarsh.go#L18) which is represented as [versionAndSignByte bigEndianByte0 bigEndianByte1 ... bigEndianByte2] byte array. diff --git a/indexer/services/ender/src/scripts/dydx_funding_handler.sql b/indexer/services/ender/src/scripts/dydx_funding_handler.sql index d9c057cbdac..420f89f9cc6 100644 --- a/indexer/services/ender/src/scripts/dydx_funding_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_funding_handler.sql @@ -2,13 +2,13 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) Returns: JSON object containing fields: - - perpetual_markets: A mapping from perpetual market id to the associated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_markets: A mapping from perpetual market id to the associated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). - errors: An array containing an error string (or NULL if no error occurred) for each FundingEventUpdate. */ CREATE OR REPLACE FUNCTION dydx_funding_handler( diff --git a/indexer/services/ender/src/scripts/dydx_get_order_status.sql b/indexer/services/ender/src/scripts/dydx_get_order_status.sql index bc10a323118..aba421e1bf2 100644 --- a/indexer/services/ender/src/scripts/dydx_get_order_status.sql +++ b/indexer/services/ender/src/scripts/dydx_get_order_status.sql @@ -1,20 +1,27 @@ /** - * The obvious case is if totalFilled >= size, then the order status should always be `FILLED`. - * The difficult case is if totalFilled < size after a fill, then we need to keep the following - * cases in mind: - * 1. Stateful Orders - All cancelations are on-chain events, so the will be `OPEN`. The - * CanceledOrdersCache does not store any stateful orders and we never send - * BEST_EFFORT_CANCELED notifications for stateful orders. - * 2. Short-term FOK - FOK orders can never be `OPEN`, since they don't rest on the orderbook, so - * totalFilled cannot be < size. By the end of the block, the order will be filled, so we mark - * it as `FILLED`. - * 3. Short-term IOC - Protocol guarantees that an IOC order will only ever be filled in a single - * block, so status should be `CANCELED`. - * 4. Short-term Limit & Post-only - If the order is in the CanceledOrdersCache, then it should be - * set to the corresponding CanceledOrderStatus, otherwise `OPEN`. - * @param isCanceled - if the order is in the CanceledOrderCache, always false for liquidiation - * orders - */ + Computes the order status given a set of order parameters. + + The obvious case is if totalFilled >= size, then the order status should always be `FILLED`. + The difficult case is if totalFilled < size after a fill, then we need to keep the following + cases in mind: + 1. Stateful Orders - All cancelations are on-chain events, so the will be `OPEN`. The + CanceledOrdersCache does not store any stateful orders and we never send + BEST_EFFORT_CANCELED notifications for stateful orders. + 2. Short-term FOK - FOK orders can never be `OPEN`, since they don't rest on the orderbook, so + totalFilled cannot be < size. By the end of the block, the order will be filled, so we mark + it as `FILLED`. + 3. Short-term IOC - Protocol guarantees that an IOC order will only ever be filled in a single + block, so status should be `CANCELED`. + 4. Short-term Limit & Post-only - If the order is in the CanceledOrdersCache, then it should be + set to the corresponding CanceledOrderStatus, otherwise `OPEN`. + + Parameters: + - total_filled - The amount the order is filled. + - size - The order size. + - order_canceled_status - The status of the order. + - order_flags - The flags of the order. + Returns the order status. +*/ CREATE OR REPLACE FUNCTION dydx_get_order_status(total_filled numeric, size numeric, order_canceled_status text, order_flags bigint, time_in_force text) RETURNS text AS $$ BEGIN diff --git a/indexer/services/ender/src/scripts/dydx_get_weighted_average.sql b/indexer/services/ender/src/scripts/dydx_get_weighted_average.sql index 95188283103..4ff135a4020 100644 --- a/indexer/services/ender/src/scripts/dydx_get_weighted_average.sql +++ b/indexer/services/ender/src/scripts/dydx_get_weighted_average.sql @@ -1,7 +1,7 @@ /** Returns the weighted average between two prices. - Note that since division is used the scale of the resulting number if limited to 20 which matches the division + Note that since division is used the scale of the resulting number is limited to 20 which matches the division precision (DP) of the https://mikemcl.github.io/big.js/ library. Parameters: diff --git a/indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql b/indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql index 745edda0b00..6bc574e030f 100644 --- a/indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql +++ b/indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql @@ -3,21 +3,21 @@ - field: the field storing the order to process. - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) - transaction_hash: The transaction hash corresponding to this event from the IndexerTendermintBlock 'tx_hashes'. - fill_liquidity: The liquidity for the fill record. - fill_type: The type for the fill record. - usdc_asset_id: The USDC asset id. Returns: JSON object containing fields: - - order: The updated order in order-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/order-model.ts). + - order: The updated order in order-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/order-model.ts). Only returned if field == 'makerOrder'. - - fill: The updated fill in fill-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/fill-model.ts). - - perpetual_market: The perpetual market for the order in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). - - perpetual_position: The updated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-position-model.ts). + - fill: The updated fill in fill-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/fill-model.ts). + - perpetual_market: The perpetual market for the order in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_position: The updated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-position-model.t). */ CREATE OR REPLACE FUNCTION dydx_liquidation_fill_handler_per_order( field text, block_height int, block_time timestamp, event_data jsonb, event_index int, transaction_index int, diff --git a/indexer/services/ender/src/scripts/dydx_liquidity_tier_handler.sql b/indexer/services/ender/src/scripts/dydx_liquidity_tier_handler.sql index c59b05ac5b3..77a034f1023 100644 --- a/indexer/services/ender/src/scripts/dydx_liquidity_tier_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_liquidity_tier_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - liquidy_tier: The upserted liquidity tier in liquidity-tiers-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/liquidity-tiers-model.ts). + - liquidy_tier: The upserted liquidity tier in liquidity-tiers-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/liquidity-tiers-model.ts). */ CREATE OR REPLACE FUNCTION dydx_liquidity_tier_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_market_create_handler.sql b/indexer/services/ender/src/scripts/dydx_market_create_handler.sql index db130c4ec5a..c00b99dac77 100644 --- a/indexer/services/ender/src/scripts/dydx_market_create_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_market_create_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - market: The created market in market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/market-model.ts). + - market: The created market in market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/market-model.ts). */ CREATE OR REPLACE FUNCTION dydx_market_create_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_market_modify_handler.sql b/indexer/services/ender/src/scripts/dydx_market_modify_handler.sql index de6b3af1b59..82bc9527052 100644 --- a/indexer/services/ender/src/scripts/dydx_market_modify_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_market_modify_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - market: The updated market in market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/market-model.ts). + - market: The updated market in market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/market-model.ts). */ CREATE OR REPLACE FUNCTION dydx_market_modify_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_market_price_update_handler.sql b/indexer/services/ender/src/scripts/dydx_market_price_update_handler.sql index afbabce7eb5..3c7f99da485 100644 --- a/indexer/services/ender/src/scripts/dydx_market_price_update_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_market_price_update_handler.sql @@ -2,11 +2,11 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - market: The updated market in market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/market-model.ts). - - oracle_price: The created oracle price in oracle-price-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/oracle-price-model.ts). + - market: The updated market in market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/market-model.ts). + - oracle_price: The created oracle price in oracle-price-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/oracle-price-model.ts). */ CREATE OR REPLACE FUNCTION dydx_market_price_update_handler(block_height int, block_time timestamp, event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql b/indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql index ccc4413afff..70515bd62bf 100644 --- a/indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql +++ b/indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql @@ -3,21 +3,21 @@ - field: the field storing the order to process. - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) - transaction_hash: The transaction hash corresponding to this event from the IndexerTendermintBlock 'tx_hashes'. - fill_liquidity: The liquidity for the fill record. - fill_type: The type for the fill record. - usdc_asset_id: The USDC asset id. - order_canceled_status: Status of order cancelation Returns: JSON object containing fields: - - order: The updated order in order-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/order-model.ts). - - fill: The updated fill in fill-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/fill-model.ts). - - perpetual_market: The perpetual market for the order in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). - - perpetual_position: The updated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-position-model.ts). + - order: The updated order in order-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/order-model.ts). + - fill: The updated fill in fill-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/fill-model.ts). + - perpetual_market: The perpetual market for the order in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_position: The updated perpetual position in perpetual-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-position-model.ts). */ CREATE OR REPLACE FUNCTION dydx_order_fill_handler_per_order( field text, block_height int, block_time timestamp, event_data jsonb, event_index int, transaction_index int, diff --git a/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql b/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql index e34d6867f38..488df44cc90 100644 --- a/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_perpetual_market_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). */ CREATE OR REPLACE FUNCTION dydx_perpetual_market_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_protocol_condition_type_to_order_type.sql b/indexer/services/ender/src/scripts/dydx_protocol_condition_type_to_order_type.sql index 8ca8a7bf996..7d991ed4e30 100644 --- a/indexer/services/ender/src/scripts/dydx_protocol_condition_type_to_order_type.sql +++ b/indexer/services/ender/src/scripts/dydx_protocol_condition_type_to_order_type.sql @@ -1,25 +1,15 @@ /** - Converts the 'ConditionType' enum from the IndexerOrder protobuf (https://github.com/dydxprotocol/v4-proto/blob/4b721881fdfe99485336e221def03dc5b86eb0a1/dydxprotocol/indexer/protocol/v1/clob.proto#L131) + Converts the 'ConditionType' enum from the IndexerOrder protobuf (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L130) to the 'OrderType' enum in postgres. */ CREATE OR REPLACE FUNCTION dydx_protocol_condition_type_to_order_type(condition_type jsonb) RETURNS text AS $$ -DECLARE - UNRECOGNIZED constant jsonb = '-1'::jsonb; - CONDITION_TYPE_UNSPECIFIED constant jsonb = '0'::jsonb; - CONDITION_TYPE_STOP_LOSS constant jsonb = '1'::jsonb; - CONDITION_TYPE_TAKE_PROFIT constant jsonb = '2'::jsonb; BEGIN CASE condition_type - WHEN UNRECOGNIZED THEN - RETURN 'LIMIT'; - WHEN CONDITION_TYPE_UNSPECIFIED THEN - RETURN 'LIMIT'; - WHEN CONDITION_TYPE_STOP_LOSS THEN - RETURN 'STOP_LIMIT'; - WHEN CONDITION_TYPE_TAKE_PROFIT THEN - RETURN 'TAKE_PROFIT'; - ELSE - RAISE EXCEPTION 'Unexpected ConditionType: %', condition_type; + WHEN '-1'::jsonb THEN RETURN 'LIMIT'; /** UNRECOGNIZED */ + WHEN '0'::jsonb THEN RETURN 'LIMIT'; /** CONDITION_TYPE_UNSPECIFIED */ + WHEN '1'::jsonb THEN RETURN 'STOP_LIMIT'; /** CONDITION_TYPE_STOP_LOSS */ + WHEN '2'::jsonb THEN RETURN 'TAKE_PROFIT'; /** CONDITION_TYPE_TAKE_PROFIT */ + ELSE RAISE EXCEPTION 'Unexpected ConditionType: %', condition_type; END CASE; END; $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; diff --git a/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql b/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql index 275a2a61850..3adfb095a74 100644 --- a/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql @@ -2,10 +2,10 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - order: The upserted order in order-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/order-model.ts). + - order: The upserted order in order-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/order-model.ts). */ CREATE OR REPLACE FUNCTION dydx_stateful_order_handler( block_height int, block_time timestamp, event_data jsonb) RETURNS jsonb AS $$ diff --git a/indexer/services/ender/src/scripts/dydx_subaccount_update_handler.sql b/indexer/services/ender/src/scripts/dydx_subaccount_update_handler.sql index 6636e883505..8af561e321d 100644 --- a/indexer/services/ender/src/scripts/dydx_subaccount_update_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_subaccount_update_handler.sql @@ -2,15 +2,15 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) Returns: JSON object containing fields: - - subaccount: The upserted subaccount in subaccount-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/subaccount-model.ts). - - perpetual_positions: A JSON array of upserted perpetual positions in perpetual-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-position-model.ts). - - asset_positions: A JSON array of upserted asset positions in asset-position-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/asset-position-model.ts). + - subaccount: The upserted subaccount in subaccount-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/subaccount-model.ts). + - perpetual_positions: A JSON array of upserted perpetual positions in perpetual-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-position-model.ts). + - asset_positions: A JSON array of upserted asset positions in asset-position-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/asset-position-model.ts). */ CREATE OR REPLACE FUNCTION dydx_subaccount_update_handler( block_height int, block_time timestamp, event_data jsonb, event_index int, transaction_index int) diff --git a/indexer/services/ender/src/scripts/dydx_tendermint_event_to_transaction_index.sql b/indexer/services/ender/src/scripts/dydx_tendermint_event_to_transaction_index.sql index b046af95dc6..7f6b0399964 100644 --- a/indexer/services/ender/src/scripts/dydx_tendermint_event_to_transaction_index.sql +++ b/indexer/services/ender/src/scripts/dydx_tendermint_event_to_transaction_index.sql @@ -1,25 +1,20 @@ /** Gets the transaction index from the IndexerTendermint event. + Parameters: - - event: The IndexerTendermintEvent object. + - event: The JSON.stringify of a IndexerTendermintEvent object (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25). Returns: int. */ CREATE OR REPLACE FUNCTION dydx_tendermint_event_to_transaction_index(event jsonb) RETURNS int AS $$ -DECLARE - transaction_index_text text; - block_event_text text; BEGIN - transaction_index_text := jsonb_extract_path_text(event, 'transactionIndex'); - block_event_text := jsonb_extract_path_text(event, 'blockEvent'); - - IF transaction_index_text IS NOT NULL THEN - RETURN transaction_index_text::int; - ELSIF block_event_text IS NOT NULL THEN - CASE block_event_text - WHEN '1' THEN RETURN -2; -- BLOCK_EVENT_BEGIN_BLOCK - WHEN '2' THEN RETURN -1; -- BLOCK_EVENT_END_BLOCK - ELSE RAISE EXCEPTION 'Received V4 event with invalid block event type: %', block_event_text; - END CASE; + IF event->'transactionIndex' IS NOT NULL THEN + RETURN (event->'transactionIndex')::int; + ELSIF event->'blockEvent' IS NOT NULL THEN + CASE event->'blockEvent' + WHEN '1'::jsonb THEN RETURN -2; /** BLOCK_EVENT_BEGIN_BLOCK */ + WHEN '2'::jsonb THEN RETURN -1; /** BLOCK_EVENT_END_BLOCK */ + ELSE RAISE EXCEPTION 'Received V4 event with invalid block event type: %', event->'blockEvent'; + END CASE; END IF; RAISE EXCEPTION 'Either transactionIndex or blockEvent must be defined in IndexerTendermintEvent'; diff --git a/indexer/services/ender/src/scripts/dydx_transfer_handler.sql b/indexer/services/ender/src/scripts/dydx_transfer_handler.sql index 3077c74b6c3..22845f71219 100644 --- a/indexer/services/ender/src/scripts/dydx_transfer_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_transfer_handler.sql @@ -2,15 +2,15 @@ Parameters: - block_height: the height of the block being processing. - block_time: the time of the block being processed. - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. - event_index: The 'event_index' of the IndexerTendermintEvent. - transaction_index: The transaction_index of the IndexerTendermintEvent after the conversion that takes into - account the block_event (https://github.com/dydxprotocol/indexer/blob/cc70982/services/ender/src/lib/helper.ts#L33) + account the block_event (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/services/ender/src/lib/helper.ts#L41) - transaction_hash: The transaction hash corresponding to this event from the IndexerTendermintBlock 'tx_hashes'. Returns: JSON object containing fields: - - asset: The existing asset in asset-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/asset-model.ts). - - transfer: The new transfer in transfer-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/transfer-model.ts). + - asset: The existing asset in asset-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/asset-model.ts). + - transfer: The new transfer in transfer-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/transfer-model.ts). */ CREATE OR REPLACE FUNCTION dydx_transfer_handler( block_height int, block_time timestamp, event_data jsonb, event_index int, transaction_index int, diff --git a/indexer/services/ender/src/scripts/dydx_update_clob_pair_handler.sql b/indexer/services/ender/src/scripts/dydx_update_clob_pair_handler.sql index 3ed74ac0cda..96bfaf146a4 100644 --- a/indexer/services/ender/src/scripts/dydx_update_clob_pair_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_update_clob_pair_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). */ CREATE OR REPLACE FUNCTION dydx_update_clob_pair_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_update_perpetual_handler.sql b/indexer/services/ender/src/scripts/dydx_update_perpetual_handler.sql index c1df39c3588..c1b143d8e56 100644 --- a/indexer/services/ender/src/scripts/dydx_update_perpetual_handler.sql +++ b/indexer/services/ender/src/scripts/dydx_update_perpetual_handler.sql @@ -1,9 +1,9 @@ /** Parameters: - - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/dydxprotocol/indexer/indexer_manager/event.proto#L25) + - event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/indexer_manager/event.proto#L25) converted to JSON format. Conversion to JSON is expected to be done by JSON.stringify. Returns: JSON object containing fields: - - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/indexer/blob/cc70982/packages/postgres/src/models/perpetual-market-model.ts). + - perpetual_market: The updated perpetual market in perpetual-market-model format (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/models/perpetual-market-model.ts). */ CREATE OR REPLACE FUNCTION dydx_update_perpetual_handler(event_data jsonb) RETURNS jsonb AS $$ DECLARE diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_oracle_price_parts.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_oracle_price_parts.sql index 52ed7122764..3bf8e0fb75b 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_oracle_price_parts.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_oracle_price_parts.sql @@ -1,5 +1,5 @@ /** - Returns a UUID using the parts of an OraclePrice (https://github.com/dydxprotocol/v4-chain/blob/755b0b928be793072d19eb3a1608e7a2503f396a/indexer/packages/postgres/src/stores/oracle-price-table.ts#L24). + Returns a UUID using the parts of an OraclePrice (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/indexer/packages/postgres/src/stores/oracle-price-table.ts#L24). */ CREATE OR REPLACE FUNCTION dydx_uuid_from_oracle_price_parts(market_id int, block_height int) RETURNS uuid AS $$ BEGIN diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_order_id.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_order_id.sql index 1ad07f6f8c8..b33a4da93f7 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_order_id.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_order_id.sql @@ -1,5 +1,5 @@ /** - Returns a UUID using the JSON.stringify format of an IndexerOrderId (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/clob.proto#L15). + Returns a UUID using the JSON.stringify format of an IndexerOrderId (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L15). */ CREATE OR REPLACE FUNCTION dydx_uuid_from_order_id(order_id jsonb) RETURNS uuid AS $$ BEGIN diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_order_id_parts.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_order_id_parts.sql index 1717218a81f..b583ff6e49e 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_order_id_parts.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_order_id_parts.sql @@ -1,5 +1,5 @@ /** - Returns a UUID using the parts of an IndexerOrderId (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/clob.proto#L15). + Returns a UUID using the parts of an IndexerOrderId (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/clob.proto#L15). */ CREATE OR REPLACE FUNCTION dydx_uuid_from_order_id_parts(subaccount_id uuid, client_id text, clob_pair_id text, order_flags text) RETURNS uuid AS $$ BEGIN diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id.sql index 54e085808ab..2a6d480d435 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id.sql @@ -1,5 +1,5 @@ /** - Returns a UUID using the JSON.stringify format of an IndexerSubAccountId (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/subaccount.proto#L15). + Returns a UUID using the JSON.stringify format of an IndexerSubaccountId (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/subaccount.proto#L15). */ CREATE OR REPLACE FUNCTION dydx_uuid_from_subaccount_id(subaccount_id jsonb) RETURNS uuid AS $$ BEGIN diff --git a/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id_parts.sql b/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id_parts.sql index cba45862951..c51ff8addbc 100644 --- a/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id_parts.sql +++ b/indexer/services/ender/src/scripts/dydx_uuid_from_subaccount_id_parts.sql @@ -1,5 +1,5 @@ /** - Returns a UUID using the parts of an IndexerSubaccountId (https://github.com/dydxprotocol/v4-proto/blob/437f6d8/dydxprotocol/indexer/protocol/v1/subaccount.proto#L15). + Returns a UUID using the parts of an IndexerSubaccountId (https://github.com/dydxprotocol/v4-chain/blob/9ed26bd/proto/dydxprotocol/indexer/protocol/v1/subaccount.proto#L15). */ CREATE OR REPLACE FUNCTION dydx_uuid_from_subaccount_id_parts(address text, subaccount_number text) RETURNS uuid AS $$ BEGIN