Skip to content

feat: add treasury transaction ingestion#11

Merged
ECWireless merged 2 commits into
mainfrom
codex/treasury-transaction-ingestion
Jun 3, 2026
Merged

feat: add treasury transaction ingestion#11
ECWireless merged 2 commits into
mainfrom
codex/treasury-transaction-ingestion

Conversation

@ECWireless
Copy link
Copy Markdown
Member

@ECWireless ECWireless commented Jun 3, 2026

Summary

  • add treasury transaction and transfer tables for imported Safe activity
  • add admin-only treasury transaction sync/read API
  • ingest env-configured main Safe plus active Gnosis side-vault transfers from Safe Transaction Service
  • make imports idempotent by source account and transfer id
  • audit transaction sync runs
  • move treasury account copy buttons next to the addresses they copy

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:

  • Added new tables treasury_transactions and treasury_transaction_transfers with appropriate fields, indexes, and foreign key constraints to support detailed tracking of transactions and their associated transfers. Also introduced the treasury_transfer_direction enum. (drizzle/0006_shocking_franklin_storm.sql [1] src/db/schema.ts [2] [3]
  • Updated the migration journal to include the new migration. (drizzle/meta/_journal.json drizzle/meta/_journal.jsonR46-R52)

API and backend logic:

  • Added a new admin-only API route (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.ts src/app/api/treasury/transactions/route.tsR1-R80)

Utilities and data access:

User interface improvements:

Configuration:

  • Added SAFE_TRANSACTION_SERVICE_URL to .env.example for configuring the Safe's Gnosis Transaction Service endpoint. (.env.example .env.exampleR23-R24)

Summary by CodeRabbit

  • New Features

    • Added treasury transaction history tracking with sync capability to pull transaction data
    • Added API endpoint to retrieve recent treasury transactions
  • Improvements

    • Enhanced address display formatting in the treasury dashboard for better readability
  • Chores

    • Updated environment configuration template with additional optional settings

Copilot AI review requested due to automatic review settings June 3, 2026 22:26
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
raidguild-accounting Ready Ready Preview, Comment Jun 3, 2026 10:47pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Warning

Review limit reached

@ECWireless, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48eb968f-2f6c-429b-9040-ae4460441730

📥 Commits

Reviewing files that changed from the base of the PR and between 0cd3170 and 066e101.

📒 Files selected for processing (2)
  • src/app/api/treasury/transactions/route.ts
  • src/lib/treasury/transactions.ts
📝 Walkthrough

Walkthrough

This 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.

Changes

Treasury Transaction Sync and Listing

Layer / File(s) Summary
Database schema and migration for treasury transactions
.env.example, src/db/schema.ts, drizzle/0006_shocking_franklin_storm.sql, drizzle/meta/0006_snapshot.json, drizzle/meta/_journal.json
Environment config for Safe Transaction Service URL; Drizzle enum treasuryTransferDirectionEnum (inflow/outflow/internal) and two new tables: treasuryTransactions (transaction metadata, hashes, execution time, optional account/metadata links) and treasuryTransactionTransfers (individual transfer records with direction, addresses, amounts, USD pricing, indexed and uniquely constrained by normalized address + hash); SQL migration adds enum, tables, foreign keys (cascade from transfers to transactions; set-null from both to accounts), and indexes; Drizzle snapshot captures full schema state and migration journal records entry 0006.
Treasury transaction sync and read service
src/lib/treasury/transactions.ts, src/lib/treasury/accounts.ts
Sync layer fetches transfers from Safe Transaction Service for main safe and all active Gnosis side-vault accounts, normalizes Safe transfer shape (addresses, direction, amounts, decimals, USD pricing, IDs), persists into treasuryTransactions and treasuryTransactionTransfers with deduplication by (chainId, accountAddress, txHash) and conflict avoidance, tracks scanned vs imported counts per source, returns aggregate result with syncedAt timestamp; also exports getRecentTreasuryTransactions() to query transfers ordered by execution time descending.
Treasury transaction API endpoints
src/app/api/treasury/transactions/route.ts
Admin-only authenticated routes: GET reads optional limit, fetches recent transfers, returns {transfers} JSON; POST parses optional limit/maxPages, calls sync, records audit event with import/scan summary, returns sync result JSON or 502 error with console logging on failure.
Dashboard account address display update
src/components/treasury/treasury-dashboard.tsx
Restructured account row to render address and copy button together in a single inline-flex container instead of separate columns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • raid-guild/accounting#8: Overlapping changes to src/components/treasury/treasury-dashboard.tsx's account address and copy-button rendering logic.
  • raid-guild/accounting#7: Treasury sync queries active side_vault accounts via listActiveGnosisSideVaultAccounts(), which depends on the treasury_accounts.archived_at field introduced in PR #7.
  • raid-guild/accounting#2: Extends the Drizzle schema/migrations and database foundation with new treasury enum/tables, building on the core setup from PR #2.

Poem

🐰 Treasury ledgers now align and sync,
Safe transfers fetched with seamless link,
Addresses copied, amounts precise,
A vault's true tale, no longer vice.
From source to store, the path is bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add treasury transaction ingestion' accurately and concisely summarizes the main change: introducing a complete treasury transaction ingestion system with schema, API, utilities, and UI updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/treasury-transaction-ingestion

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_transfers tables (and treasury_transfer_direction enum) 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.

Comment thread src/app/api/treasury/transactions/route.ts
Comment thread src/lib/treasury/transactions.ts
Comment thread src/lib/treasury/transactions.ts
Comment thread src/lib/treasury/transactions.ts
Comment thread src/lib/treasury/transactions.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between aadff02 and 0cd3170.

📒 Files selected for processing (9)
  • .env.example
  • drizzle/0006_shocking_franklin_storm.sql
  • drizzle/meta/0006_snapshot.json
  • drizzle/meta/_journal.json
  • src/app/api/treasury/transactions/route.ts
  • src/components/treasury/treasury-dashboard.tsx
  • src/db/schema.ts
  • src/lib/treasury/accounts.ts
  • src/lib/treasury/transactions.ts

Comment thread src/app/api/treasury/transactions/route.ts
Comment thread src/lib/treasury/transactions.ts
Comment thread src/lib/treasury/transactions.ts Outdated
@ECWireless ECWireless merged commit d3cd361 into main Jun 3, 2026
5 checks passed
@ECWireless ECWireless deleted the codex/treasury-transaction-ingestion branch June 3, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants