-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IND-473] Update ender perpetual market create to execute updates via…
… a SQL function. (#760)
- Loading branch information
1 parent
f2587ef
commit 476ada4
Showing
5 changed files
with
187 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
Parameters: | ||
- event_data: The 'data' field of the IndexerTendermintEvent (https://github.com/dydxprotocol/v4-proto/blob/8d35c86/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). | ||
*/ | ||
CREATE OR REPLACE FUNCTION dydx_perpetual_market_handler(event_data jsonb) RETURNS jsonb AS $$ | ||
DECLARE | ||
perpetual_market_record perpetual_markets%ROWTYPE; | ||
BEGIN | ||
perpetual_market_record."id" = (event_data->'id')::bigint; | ||
perpetual_market_record."clobPairId" = (event_data->'clobPairId')::bigint; | ||
perpetual_market_record."ticker" = event_data->>'ticker'; | ||
perpetual_market_record."marketId" = (event_data->'marketId')::integer; | ||
perpetual_market_record."status" = dydx_clob_pair_status_to_market_status(event_data->'status'); | ||
perpetual_market_record."lastPrice" = 0; | ||
perpetual_market_record."priceChange24H" = 0; | ||
perpetual_market_record."trades24H" = 0; | ||
perpetual_market_record."volume24H" = 0; | ||
perpetual_market_record."nextFundingRate" = 0; | ||
perpetual_market_record."openInterest"= 0; | ||
perpetual_market_record."quantumConversionExponent" = (event_data->'quantumConversionExponent')::integer; | ||
perpetual_market_record."atomicResolution" = (event_data->'atomicResolution')::integer; | ||
perpetual_market_record."subticksPerTick" = (event_data->'subticksPerTick')::integer; | ||
perpetual_market_record."stepBaseQuantums" = dydx_from_jsonlib_long(event_data->'stepBaseQuantums'); | ||
perpetual_market_record."liquidityTierId" = (event_data->'liquidityTier')::integer; | ||
|
||
INSERT INTO perpetual_markets VALUES (perpetual_market_record.*) RETURNING * INTO perpetual_market_record; | ||
|
||
RETURN jsonb_build_object( | ||
'perpetual_market', | ||
dydx_to_jsonb(perpetual_market_record) | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; |