-
Notifications
You must be signed in to change notification settings - Fork 116
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
De-duplicate and filter out invalid pnl ticks for megavault. #2540
Conversation
Co-authored-by: Adam Fraser <adamfraser0@gmail.com>
…2410) Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com>
Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com>
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (2)
95-111
: Consider handling undefined firstMainVaultTransferTimestampWhen
firstMainVaultTransferTimestamp
is undefined, it's passed directly toaggregateVaultPnlTicks
. While the function handles this case, consider adding a log message or documentation to explain this scenario.
Line range hint
729-734
: Improve error message formattingThe error message concatenation could be improved:
- Use template literals consistently
- Include more structured information in the log
- message: `Vault clob pair id ${vaultMapping[subaccountId]} does not correspond to a ` + - 'perpetual market.', + message: `Vault clob pair id ${vaultMapping[subaccountId].clobPairId} does not correspond to a perpetual market`, + vault: vaultMapping[subaccountId],
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts (4 hunks)
- indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- indexer/services/comlink/tests/controllers/api/v4/vault-controller.test.ts
🔇 Additional comments (4)
indexer/services/comlink/src/controllers/api/v4/vault-controller.ts (4)
28-31
: LGTM: Type safety improvementsThe changes to the
VaultMapping
interface and additional type imports enhance type safety and provide better access to vault properties.Also applies to: 64-64, 71-71
538-550
: LGTM: Improved PnL tick validationThe updated signature and implementation properly handle PnL tick aggregation with vault validation.
652-669
: LGTM: Well-implemented transfer timestamp retrievalThe function properly handles the case when no transfers exist and uses appropriate ordering.
681-709
: Consider additional error handling in binary searchThe binary search implementation using
bounds.le
should consider handling potential edge cases:
- Empty array of vault creation times
- Invalid DateTime comparisons
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Adam Fraser <adamfraser0@gmail.com> Co-authored-by: jerryfan01234 <44346807+jerryfan01234@users.noreply.github.com> Co-authored-by: dydxwill <119354122+dydxwill@users.noreply.github.com> Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com> Co-authored-by: Mohammed Affan <affan@dydx.exchange> (cherry picked from commit 4ccfe2b)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Adam Fraser <adamfraser0@gmail.com> Co-authored-by: jerryfan01234 <44346807+jerryfan01234@users.noreply.github.com> Co-authored-by: dydxwill <119354122+dydxwill@users.noreply.github.com> Co-authored-by: roy-dydx <133032749+roy-dydx@users.noreply.github.com> Co-authored-by: Mohammed Affan <affan@dydx.exchange>
Changelist
Add logic to de-duplicate pnl ticks for the same vault when combining PnL of multiple vaults to derive the megavault PnL.
Add logic to filter out megavault Pnl ticks that are aggregated from less Pnl ticks than the number of vaults existing at the time of the Pnl tick.
Both changes are to filter out inconsistencies caused by issues with the PnL task, where it either:
Test Plan
Updated 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
.Summary by CodeRabbit
Release Notes
New Features
AggregatedPnlTick
for improved handling of profit and loss (P&L) tick data.vincentc/dedup-filter-ticks
.Bug Fixes
GET /megavault/historicalPnl
endpoint.Chores