Skip to content

Conversation

@youngkidwarrior
Copy link
Collaborator

Summary

This PR implements deterministic reconciliation for transfer intents, replacing the old fuzzy matching approach that could cause race conditions and cross-linking issues.

Changes

1. Deterministic Reconciliation Trigger

  • New reconcile_transfer_on_index() function that matches intents by exact tx_hash or user_op_hash only
  • No more fuzzy matching by (from, to, value) which could cross-link similar transfers
  • Creates transfer_reconciliations record with UNIQUE(chain_id, tx_hash, log_idx) constraint

2. Merged Activity Feed View

  • New activity_feed_merged view that shows:
    • Pending transfers from transfer_intents (not yet indexed)
    • Confirmed transfers from indexed events with notes merged from intents
  • Each transfer appears exactly once in the feed

3. Removed Fuzzy Matching

  • Dropped send_account_transfers_delete_temporal_activity() function
  • Dropped send_account_transfers_trigger_delete_temporal_activity trigger
  • These used fuzzy matching that could delete wrong activities

4. Updated Tests

  • Extended test suite from 12 to 20 tests
  • Added collision invariant tests: two intents with identical (from,to,value) must not cross-link
  • Added note persistence tests: notes survive reconciliation
  • Added feed invariant tests: proper status transitions

Key Invariants

  1. Collision Prevention: Two intents with identical (from, to, value) will NEVER cross-link
  2. Single Entry: Once reconciled, the feed returns exactly one entry per transfer
  3. Note Persistence: Notes always survive regardless of temporal ordering

Testing

Run the test suite:

cd supabase && yarn test

Expected: All 20 tests pass

Migration

The migration will:

  1. Drop old fuzzy triggers and functions
  2. Create new deterministic reconciliation trigger
  3. Create merged activity feed view
  4. Grant appropriate permissions

This PR was generated with Warp.

Implement deterministic reconciliation for transfer intents:
- Add reconcile_transfer_on_index() trigger using exact tx_hash/user_op_hash matching
- Create activity_feed_merged view for unified pending/confirmed transfers
- Remove old fuzzy matching (send_account_transfers_delete_temporal_activity)
- Add 8 new collision/race invariant tests (total 20 tests)

Key invariants enforced:
- Two intents with identical (from,to,value) cannot cross-link
- Same (chain_id, tx_hash, log_idx) links to exactly one intent
- Notes persist regardless of temporal ordering

Co-Authored-By: Warp <agent@warp.dev>
@github-actions
Copy link

Vercel Unique URL: https://sendapp-imt3439dv-0xsend.vercel.app
Vercel Preview URL: sendapp-deterministic-reconciliation--0xsend.vercel.app
Last Commit: fd9ccd8

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