-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add Deposits table #502
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
base: stage
Are you sure you want to change the base?
Conversation
- Replace separate protocol queries with single query against new Deposit table - Add Deposit entity with foreign keys to V3FundsDeposited, DepositForBurn, OFTSent events - Implement updateDeposits helper to maintain deposit index across all protocols - Simplify getDeposits method from 440+ lines to 200+ lines with improved performance - Add proper TypeORM joins and filtering logic for cross-protocol deposit queries - Create migration for new deposit table with optimized indices for common query patterns
| OFT = "oft", | ||
| } | ||
|
|
||
| export enum DepositStatus { |
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 deposits endpoint only cares about whether a deposit is finished or not. All other statuses are irrelevant to the deposit endpoint.
| @Index("IX_deposits_depositor_timestamp", ["depositor", "blockTimestamp"]) | ||
| @Index("IX_deposits_recipient_timestamp", ["recipient", "blockTimestamp"]) | ||
| // 3. Status Index: Fast "Unfilled" lookups | ||
| @Index("IX_deposits_status_timestamp", ["status", "blockTimestamp"]) |
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 indices are chosen based on the current behaviour of the API to make these lookups as fast as possible.
| }); | ||
|
|
||
| const chunkedEvents = across.utils.chunk(formattedEvents, chunkSize); | ||
| const chunkedEvents: Partial<TEntity>[][] = across.utils.chunk( |
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.
We need explicit typing for updating the saved events in storeEvents functions.
This PR introduces the Deposit entity and the
updateDepositsfunctionality.This new table serves as an aggregation layer for all cross-chain activities (Across V3, CCTP, and LayerZero OFT), so that we can serve the deposits without a hardcoded limit and with a small response time.
Instead of querying three distinct protocol tables and merging them in-memory (which scales poorly), we now maintain a single table for deposits.
Database Design: The Deposit Entity
The
Deposittable is designed to store the relevant information for fast indexing and querying without containing non-relevant information that can be sourced from other tables. .It duplicates only the fields necessary for sorting, filtering, and pagination, while delegating protocol-specific data to linked foreign tables.The fields that exist in the table are based on the current requirements of the
depositsendpoint. Ideally, the fields that currently exist can be used to index the relevant rows fast (as it is currently done in memory for the endpoint) and then additional information can beadded by merging the relevant columns through the stored foreign keys.Table Structure
• Across:
internalHash• CCTP:
${nonce}-${destinationChainId}• OFT:
guidORDER BY timestamp DESC. Enables O(1) pagination instead of merging 3 tables in-memory.Ingestion Logic: updateDeposits
Every event is processed using:
INSERT ... ON CONFLICT (uniqueId) DO UPDATEWe cannot guarantee that source events arrive before destination events.
Behavior
status = PENDINGstatus = FILLED(Orphan Fill)status = FILLED