-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor out looking up clob pair into SQL function. #784
Conversation
WalkthroughThe changes primarily involve the introduction of a new PostgreSQL function Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (6)
- indexer/services/ender/src/helpers/postgres/postgres-functions.ts (1 hunks)
- indexer/services/ender/src/scripts/dydx_get_perpetual_market_for_clob_pair.sql (1 hunks)
- indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (1 hunks)
- indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql (1 hunks)
- indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql (2 hunks)
- indexer/services/ender/src/scripts/dydx_update_perpetual_position_aggregate_fields.sql (1 hunks)
Files skipped from review due to trivial changes (2)
- indexer/services/ender/src/helpers/postgres/postgres-functions.ts
- indexer/services/ender/src/scripts/dydx_stateful_order_handler.sql
Additional comments: 4
indexer/services/ender/src/scripts/dydx_get_perpetual_market_for_clob_pair.sql (1)
- 1-23: The new function
dydx_get_perpetual_market_for_clob_pair
is well defined and handles exceptions for no data found and too many rows. It returns aperpetual_markets
type. Ensure that the function is being used correctly in the rest of the codebase.indexer/services/ender/src/scripts/dydx_update_perpetual_position_aggregate_fields.sql (1)
- 15-21: The change in the declaration of
perpetual_position_record
to match the row type of theperpetual_positions
table is a good practice. It ensures that the variable will have the same structure as the table, which can prevent potential issues if the table structure changes in the future.indexer/services/ender/src/scripts/dydx_liquidation_fill_handler_per_order.sql (1)
- 52-55: The retrieval of the
perpetual_market_record
has been abstracted into thedydx_get_perpetual_market_for_clob_pair
function. This improves code readability and maintainability. Ensure that the new function handles all edge cases and exceptions that were previously handled in this script.indexer/services/ender/src/scripts/dydx_order_fill_handler_per_order.sql (1)
- 46-49: The new function
dydx_get_perpetual_market_for_clob_pair
is used here to retrieve the perpetual market data. Ensure that this function is correctly implemented and tested, as it is now a critical part of thedydx_order_fill_handler_per_order
function.
BEGIN | ||
SELECT * INTO STRICT asset_record FROM assets WHERE "id" = usdc_asset_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query to retrieve the asset record is not wrapped in a try-catch block. If the query fails for any reason (e.g., the asset with the given ID does not exist), it will cause the entire function to fail. Consider adding error handling here.
+ BEGIN
SELECT * INTO STRICT asset_record FROM assets WHERE "id" = usdc_asset_id;
+ EXCEPTION
+ WHEN NO_DATA_FOUND THEN
+ RAISE EXCEPTION 'Unable to find asset with id %', usdc_asset_id;
+ END;
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
BEGIN | |
SELECT * INTO STRICT asset_record FROM assets WHERE "id" = usdc_asset_id; | |
BEGIN | |
SELECT * INTO STRICT asset_record FROM assets WHERE "id" = usdc_asset_id; | |
EXCEPTION | |
WHEN NO_DATA_FOUND THEN | |
RAISE EXCEPTION 'Unable to find asset with id %', usdc_asset_id; | |
END; |
Changelist
Refactor out looking up clob pair into SQL function.
Test Plan
No change.
Author/Reviewer Checklist
state-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.