feat: add treasury transaction ingestion#11
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
More reviews will be available in 39 minutes and 1 second. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR adds a complete treasury transaction sync system: schema definitions for storing transfers and transactions with direction/pricing metadata, a service layer that fetches from Safe Transaction Service, deduplicates by transaction hash, persists via Drizzle ORM with conflict avoidance, and exposes authenticated API endpoints for syncing and reading. It updates the dashboard UI to display account addresses inline with copy buttons. ChangesTreasury Transaction Sync and Listing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR introduces a treasury transaction ingestion pipeline backed by new database tables, along with an admin-only API to trigger syncs and fetch recent imported activity from the Safe Transaction Service (Gnosis), plus a small treasury dashboard layout adjustment.
Changes:
- Add
treasury_transactions+treasury_transaction_transferstables (andtreasury_transfer_directionenum) to persist imported Safe transfer activity. - Implement server-side ingestion utilities to sync main-safe + active Gnosis side-vault transfers idempotently.
- Add an admin-only API route to trigger sync runs and retrieve recent imported rows; refine treasury dashboard address/copy-button layout.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/treasury/transactions.ts | Adds Safe Transaction Service fetching, normalization, idempotent insert logic, and “recent” query helper. |
| src/lib/treasury/accounts.ts | Adds helper to list active Gnosis side-vault accounts used as ingestion sources. |
| src/db/schema.ts | Adds Drizzle schema definitions for treasury transactions/transfers and direction enum. |
| src/components/treasury/treasury-dashboard.tsx | Moves the copy-address button next to each displayed account address. |
| src/app/api/treasury/transactions/route.ts | Adds admin-only GET (recent) and POST (sync) endpoints with audit logging. |
| drizzle/0006_shocking_franklin_storm.sql | Migration creating the new enum, tables, constraints, and indexes. |
| drizzle/meta/0006_snapshot.json | Drizzle schema snapshot update for the migration. |
| drizzle/meta/_journal.json | Drizzle migration journal update referencing 0006. |
| .env.example | Documents SAFE_TRANSACTION_SERVICE_URL configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/api/treasury/transactions/route.ts`:
- Around line 51-79: The current try block mixes the sync and audit so a failing
writeAuditEvent can mask a successful sync; refactor by calling
syncTreasuryTransactions first and then wrapping writeAuditEvent in its own
try-catch so audit failures do not change the successful response (use the same
metadata shape and session.address), and in the outer catch (where sync fails)
add a separate writeAuditEvent call in its own try-catch to record the failed
sync (include error details in metadata like error.message and stack) before
returning the error response; reference syncTreasuryTransactions,
writeAuditEvent, session.address and the existing response handling
(NextResponse.json) when making these changes.
In `@src/lib/treasury/transactions.ts`:
- Around line 153-179: The getAssetMetadata function currently hardcodes
usdPrice for xDAI, USDC, and wxDAI; replace this by querying a price service (or
internal price oracle) instead of returning the literal "1.00000000" in both the
ETHER_TRANSFER branch and the token branch (getAssetMetadata and its use of
tokenInfo/tokenAddress); implement a call to a shared price-fetch helper (or
inject a PriceProvider) that returns current price plus a timestamp, set
usdPrice to the fetched value formatted to 8 decimals, and add a
fallback/staleness check (e.g., if the price is missing or older than configured
threshold, return null or mark as stale) so downstream consumers can handle
depegging; update any callers/constructors to accept the PriceProvider
dependency and document the assumption and acceptable drift tolerance in the
function comment.
- Around line 536-540: The current use of Promise.all with
sources.map(syncAccountTransfers) causes a single account failure to abort the
whole sync; change the logic in the block that builds accounts (currently
calling syncAccountTransfers for each source) to use Promise.allSettled so every
account is attempted, then collect successful results and capture failures into
an errors array keyed by account id/name; update the return shape to include
both the aggregated successful accounts and an errors field listing failures
(with function reference syncAccountTransfers and variable accounts) so partial
results are returned instead of throwing on first error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8c8473c8-a5bd-4153-a126-a6a2b093b536
📒 Files selected for processing (9)
.env.exampledrizzle/0006_shocking_franklin_storm.sqldrizzle/meta/0006_snapshot.jsondrizzle/meta/_journal.jsonsrc/app/api/treasury/transactions/route.tssrc/components/treasury/treasury-dashboard.tsxsrc/db/schema.tssrc/lib/treasury/accounts.tssrc/lib/treasury/transactions.ts
Summary
This pull request introduces a new treasury transaction and transfer tracking system, including database schema changes, API endpoints, and supporting utilities. The main focus is to enable structured storage and retrieval of treasury transaction and transfer data, with admin-only access to synchronize and fetch recent transactions. Additionally, there are minor improvements to the UI and configuration.
Database schema changes for treasury transactions and transfers:
treasury_transactionsandtreasury_transaction_transferswith appropriate fields, indexes, and foreign key constraints to support detailed tracking of transactions and their associated transfers. Also introduced thetreasury_transfer_directionenum. (drizzle/0006_shocking_franklin_storm.sql[1]src/db/schema.ts[2] [3]drizzle/meta/_journal.jsondrizzle/meta/_journal.jsonR46-R52)API and backend logic:
src/app/api/treasury/transactions/route.ts) to fetch recent treasury transactions (GET) and trigger a sync/import of transactions (POST), including audit logging. (src/app/api/treasury/transactions/route.tssrc/app/api/treasury/transactions/route.tsR1-R80)Utilities and data access:
src/lib/treasury/accounts.tssrc/lib/treasury/accounts.tsR158-R182)User interface improvements:
src/components/treasury/treasury-dashboard.tsxsrc/components/treasury/treasury-dashboard.tsxL271-L292)Configuration:
SAFE_TRANSACTION_SERVICE_URLto.env.examplefor configuring the Safe's Gnosis Transaction Service endpoint. (.env.example.env.exampleR23-R24)Summary by CodeRabbit
New Features
Improvements
Chores