-
Notifications
You must be signed in to change notification settings - Fork 104
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
Fix unsettled funding sign #854
Conversation
WalkthroughThe overall changes involve adjustments to the financial calculations related to funding and profit and loss (PnL) across various functions and test cases. The logic for computing values such as maintenance margin, unsettled funding, net funding, realized PnL, and adjusted size has been updated, with operations like addition and subtraction being swapped in several instances. These modifications suggest a correction or refinement in the way financial metrics are calculated within the system. 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: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- indexer/packages/postgres/tests/db/helpers.test.ts (3 hunks)
- indexer/packages/postgres/src/db/helpers.ts (2 hunks)
- indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- indexer/packages/postgres/tests/db/helpers.test.ts
Additional comments: 3
indexer/packages/postgres/src/db/helpers.ts (2)
- 58-64: The calculation in
getUnsettledFunding
still performs a subtraction, which contradicts the PR objective of reversing the sign from minus to plus. This needs to be corrected to align with the intended logic change.- lastUpdateFundingIndexMap[position.perpetualId].minus( - latestFundingIndexMap[position.perpetualId], + latestFundingIndexMap[position.perpetualId].minus( + lastUpdateFundingIndexMap[position.perpetualId],
- 40-49: The updated comments in the
getUnsettledFunding
function provide clear guidance on the behavior of unsettled funding based on the direction of the funding index change, which aligns with the PR objective.indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts (1)
- 361-364: The change in the
calculateEquity
function to addtotalUnsettledFundingPayment
instead of subtracting it aligns with the PR objective to correct the sign used in the calculation of unsettled funding within the PnL calculation task. This is a significant change in the logic of the financial calculations and should be thoroughly tested to ensure accuracy.
This function will need to be fixed as well. |
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 (4)
- indexer/services/comlink/tests/controllers/api/v4/addresses-controller.test.ts (2 hunks)
- indexer/services/comlink/tests/controllers/api/v4/perpetual-positions-controller.test.ts (2 hunks)
- indexer/services/comlink/tests/lib/helpers.test.ts (6 hunks)
- indexer/services/comlink/src/lib/helpers.ts (1 hunks)
Additional comments: 9
indexer/services/comlink/__tests__/controllers/api/v4/addresses-controller.test.ts (2)
89-100: The changes in the test values for
netFunding
andrealizedPnl
correctly reflect the updated logic for unsettled funding calculation, as per the PR's objective. The comments in the code provide clarity on the calculation and its expected outcome, which is helpful for understanding the changes.246-257: The changes in the test values for
netFunding
andrealizedPnl
in this second hunk are consistent with the changes in the first hunk and align with the PR's objective to correct the sign in the calculation of unsettled funding. The comments in the code are consistent and provide a clear explanation of the expected values based on the updated logic.indexer/services/comlink/__tests__/controllers/api/v4/perpetual-positions-controller.test.ts (2)
75-86: The test case for a long position reflects the updated logic for the calculation of net funding and realized Pnl. The comments explain the calculation steps, which is helpful for maintainability. The calculation seems to be consistent with the PR's objective of correcting the sign in the calculation of unsettled funding.
126-137: The test case for a short position also reflects the updated logic for the calculation of net funding and realized Pnl. The comments and calculations are consistent with the changes described in the PR's objective. It's important to ensure that the actual implementation of
getUnsettledFunding
in the source code matches these test expectations.indexer/services/comlink/__tests__/lib/helpers.test.ts (4)
415-421: The test cases for
adjustUSDCAssetPosition
have been updated, but the summary does not mention any changes to this function. Please ensure that the changes in these test cases are consistent with the actual changes made to theadjustUSDCAssetPosition
function in the source code.478-483: The test cases for
adjustUSDCAssetPosition
have been updated, but the summary does not mention any changes to this function. Please ensure that the changes in these test cases are consistent with the actual changes made to theadjustUSDCAssetPosition
function in the source code.543-549: The test cases for
adjustUSDCAssetPosition
have been updated, but the summary does not mention any changes to this function. Please ensure that the changes in these test cases are consistent with the actual changes made to theadjustUSDCAssetPosition
function in the source code.593-598: The test cases for
adjustUSDCAssetPosition
have been updated, but the summary does not mention any changes to this function. Please ensure that the changes in these test cases are consistent with the actual changes made to theadjustUSDCAssetPosition
function in the source code.indexer/services/comlink/src/lib/helpers.ts (1)
- 456-462: The changes in the
adjustUSDCAssetPosition
function correctly reflect the PR's objective to correct the sign used in the calculation of unsettled funding. The addition ofunsettledFunding
tosignedUsdcPositionSize
on line 459 is consistent with the PR description and the summary provided.
); | ||
|
||
expect(unsettledFunding).toEqual( | ||
Big(perpetualPosition.size).times('100').plus( | ||
Big(perpetualPosition2.size).times('1000'), | ||
Big(perpetualPosition.size).times('-100').plus( | ||
Big(perpetualPosition2.size).times('-1000'), | ||
), | ||
); |
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 test case for getTotalUnsettledFunding
seems to be expecting negative values for unsettled funding, which contradicts the PR objective of changing the sign from minus to plus in the getUnsettledFunding
function. Please verify that the expected values in this test case align with the updated logic in the getUnsettledFunding
function.
* [CLOB-976] Push indexer ECR images to mainnet. (#766) * Fix unsettled funding sign (#854) --------- Co-authored-by: vincentwschau <[email protected]>
Changelist
Fix unsettled funding sign
Since the sign was changed in the shared
getUnsettledFunding
function, updated minus -> plus in roundtable pnl calculation task. Pnl unit tests are still passing.Test Plan
Unit tests
Author/Reviewer Checklist
state-breaking
label.indexer-postgres-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.