ENG-181: Deal-related and fee-related cash event integration#253
ENG-181: Deal-related and fee-related cash event integration#253Connorbelez merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Sorry @Connorbelez, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughAdds four deal- and fee-related cash-posting mutations with tests, persists optional Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Integrations as Integrations.postDealBuyerFundsReceived
participant Accounts as CashAccountService
participant PostEntry as postCashEntryInternal
participant Journal as CashLedgerJournal
Caller->>Integrations: call(dealId, amount, source)
Integrations->>Accounts: getOrCreateCashAccount(TRUST_CASH, mortgageId)
Accounts-->>Integrations: trustAccount
Integrations->>Accounts: getOrCreateCashAccount(CASH_CLEARING, mortgageId)
Accounts-->>Integrations: clearingAccount
Integrations->>PostEntry: post(CASH_RECEIVED, debit:trust, credit:clearing, idempotencyKey:dealId, metadata:{buyerId,sellerId,dealId})
PostEntry->>Journal: persist(entry with dealId)
Journal-->>PostEntry: persistedEntry
PostEntry-->>Integrations: success
Integrations-->>Caller: return(createdEntry)
sequenceDiagram
participant Caller
participant Integrations as Integrations.postDealSellerPayout
participant Accounts as CashAccountService
participant PostEntry as postCashEntryInternal
participant Journal as CashLedgerJournal
Caller->>Integrations: call(dealId, lenderId, amount, source)
Integrations->>Accounts: getOrCreateCashAccount(LENDER_PAYABLE, lenderId)
Accounts-->>Integrations: lenderPayable
Integrations->>Accounts: getOrCreateCashAccount(TRUST_CASH, mortgageId)
Accounts-->>Integrations: trustAccount
Integrations->>PostEntry: post(LENDER_PAYOUT_SENT, debit:lenderPayable, credit:trust, idempotencyKey:dealId+lenderId, metadata:{sellerId,buyerId,dealId})
PostEntry->>Journal: persist(entry with dealId)
Journal-->>PostEntry: persistedEntry
PostEntry-->>Integrations: success
Integrations-->>Caller: return(createdEntry)
sequenceDiagram
participant Caller
participant Integrations as Integrations.postLockingFeeReceived
participant Accounts as CashAccountService
participant PostEntry as postCashEntryInternal
participant Journal as CashLedgerJournal
Caller->>Integrations: call(feeId, mortgageId, amount, dealId?, source)
Integrations->>Accounts: getOrCreateCashAccount(TRUST_CASH, mortgageId)
Accounts-->>Integrations: trustAccount
Integrations->>Accounts: getOrCreateCashAccount(UNAPPLIED_CASH, mortgageId)
Accounts-->>Integrations: unappliedAccount
Integrations->>PostEntry: post(CASH_RECEIVED, debit:trust, credit:unapplied, idempotencyKey:feeId (+dealId?), metadata:{feeType,feeId,dealId?})
PostEntry->>Journal: persist(entry with dealId)
Journal-->>PostEntry: persistedEntry
PostEntry-->>Integrations: success
Integrations-->>Caller: return(createdEntry)
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Connorbelez has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Pull request overview
Wires new deal-related and fee-related cash events into the cash-ledger posting pipeline, and updates accounting semantics so CASH_CLEARING / UNAPPLIED_CASH are treated as credit-normal (liability) families. Also extends cash ledger journal entries to optionally associate entries with a deal for downstream reporting/querying.
Changes:
- Add new cash-ledger integration helpers for deal buyer funds, deal seller payouts, locking fees, and commitment deposits.
- Update cash ledger type constraints and balance polarity (
CREDIT_NORMAL_FAMILIES,CASH_ENTRY_TYPE_FAMILY_MAP) to treat CASH_CLEARING and UNAPPLIED_CASH as credit-normal and allow them in CASH_RECEIVED postings. - Extend cash ledger journal entry schema + mutation args to include optional
dealId, with a new index; add/adjust tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| convex/schema.ts | Adds dealId field to cash ledger journal entries and indexes by deal. |
| convex/payments/cashLedger/validators.ts | Extends postCashEntry args validator to accept optional dealId. |
| convex/payments/cashLedger/types.ts | Expands CASH_RECEIVED family constraints and updates credit-normal families. |
| convex/payments/cashLedger/postEntry.ts | Persists dealId onto journal entries and threads it through the input type. |
| convex/payments/cashLedger/integrations.ts | Adds 4 new integration functions for deal/fee cash events. |
| convex/payments/cashLedger/tests/entryTypes.test.ts | Updates tests to reflect UNAPPLIED_CASH being credit-normal. |
| convex/payments/cashLedger/tests/dealCashEvents.test.ts | Adds comprehensive tests for new deal/fee integrations (including idempotency + errors). |
| convex/payments/cashLedger/tests/controlSubaccounts.test.ts | Adjusts setup to pre-fund UNAPPLIED_CASH correctly under new polarity rules. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@coderabbitai please review |
|
🧠 Learnings used✅ Actions performedReview triggered.
|
Wire 4 deal/fee cash events through the posting pipeline: - postDealBuyerFundsReceived (CASH_RECEIVED → TRUST_CASH/CASH_CLEARING) - postDealSellerPayout (LENDER_PAYOUT_SENT → LENDER_PAYABLE/TRUST_CASH) - postLockingFeeReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) - postCommitmentDepositReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) Also fixes CREDIT_NORMAL_FAMILIES to include CASH_CLEARING and UNAPPLIED_CASH — these are liabilities (credit-normal) not assets, which corrects balance computation polarity for all future entries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…s-mortgage collisions postLockingFeeReceived and postCommitmentDepositReceived used plain-string feeId/depositId as the sole idempotency discriminant. Since these are not globally-unique Convex IDs, reusing the same identifier across mortgages would cause cross-mortgage idempotency collisions. Now includes mortgageId (and dealId when present) in the key, matching the scoping pattern used by the other deal integration functions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…255) ENG-181: Deal-related and fee-related cash event integration (#253) ## Wire 4 deal/fee cash events through the posting pipeline - postDealBuyerFundsReceived (CASH_RECEIVED → TRUST_CASH/CASH_CLEARING) - postDealSellerPayout (LENDER_PAYOUT_SENT → LENDER_PAYABLE/TRUST_CASH) - postLockingFeeReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) - postCommitmentDepositReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) Also fixes CREDIT_NORMAL_FAMILIES to include CASH_CLEARING and UNAPPLIED_CASH — these are liabilities (credit-normal) not assets, which corrects balance computation polarity for all future entries. ### Changes - Adds 4 new integration functions in `integrations.ts` with proper idempotency keys and metadata - Expands CASH_RECEIVED family map to accept CASH_CLEARING and UNAPPLIED_CASH as credit accounts - Adds dealId field to journal entries schema with corresponding index - Includes comprehensive test coverage for all functions including idempotency and error handling - Corrects account normal balance classifications for proper accounting semantics ## Summary by Sourcery Bug Fixes: - Fix runtime crash in obligation settlement dispersal caused by missing paymentFrequency argument in servicing fee calculation. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added cash posting functions for deal-related transactions: buyer funds received, seller payouts, locking fees, and commitment deposits. * Added support for associating cash ledger entries with specific deals for better transaction tracking. * **Tests** * Comprehensive test coverage for new cash posting functions, including idempotency and error handling scenarios. * **Bug Fixes** * Corrected cash account balance preconditions in existing tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ENG-224: Pass paymentFrequency to calculateServicingFee ENG-152 added paymentFrequency as a required third parameter but the caller in calculateServicingSplit was not updated, causing a runtime crash on any obligation settlement triggering dispersal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Wire 4 deal/fee cash events through the posting pipeline - postDealBuyerFundsReceived (CASH_RECEIVED → TRUST_CASH/CASH_CLEARING) - postDealSellerPayout (LENDER_PAYOUT_SENT → LENDER_PAYABLE/TRUST_CASH) - postLockingFeeReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) - postCommitmentDepositReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) Also fixes CREDIT_NORMAL_FAMILIES to include CASH_CLEARING and UNAPPLIED_CASH — these are liabilities (credit-normal) not assets, which corrects balance computation polarity for all future entries. ### Changes - Adds 4 new integration functions in `integrations.ts` with proper idempotency keys and metadata - Expands CASH_RECEIVED family map to accept CASH_CLEARING and UNAPPLIED_CASH as credit accounts - Adds dealId field to journal entries schema with corresponding index - Includes comprehensive test coverage for all functions including idempotency and error handling - Corrects account normal balance classifications for proper accounting semantics <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added cash posting functions for deal-related transactions: buyer funds received, seller payouts, locking fees, and commitment deposits. * Added support for associating cash ledger entries with specific deals for better transaction tracking. * **Tests** * Comprehensive test coverage for new cash posting functions, including idempotency and error handling scenarios. * **Bug Fixes** * Corrected cash account balance preconditions in existing tests. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…255) ENG-181: Deal-related and fee-related cash event integration (#253) ## Wire 4 deal/fee cash events through the posting pipeline - postDealBuyerFundsReceived (CASH_RECEIVED → TRUST_CASH/CASH_CLEARING) - postDealSellerPayout (LENDER_PAYOUT_SENT → LENDER_PAYABLE/TRUST_CASH) - postLockingFeeReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) - postCommitmentDepositReceived (CASH_RECEIVED → TRUST_CASH/UNAPPLIED_CASH) Also fixes CREDIT_NORMAL_FAMILIES to include CASH_CLEARING and UNAPPLIED_CASH — these are liabilities (credit-normal) not assets, which corrects balance computation polarity for all future entries. ### Changes - Adds 4 new integration functions in `integrations.ts` with proper idempotency keys and metadata - Expands CASH_RECEIVED family map to accept CASH_CLEARING and UNAPPLIED_CASH as credit accounts - Adds dealId field to journal entries schema with corresponding index - Includes comprehensive test coverage for all functions including idempotency and error handling - Corrects account normal balance classifications for proper accounting semantics ## Summary by Sourcery Bug Fixes: - Fix runtime crash in obligation settlement dispersal caused by missing paymentFrequency argument in servicing fee calculation. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added cash posting functions for deal-related transactions: buyer funds received, seller payouts, locking fees, and commitment deposits. * Added support for associating cash ledger entries with specific deals for better transaction tracking. * **Tests** * Comprehensive test coverage for new cash posting functions, including idempotency and error handling scenarios. * **Bug Fixes** * Corrected cash account balance preconditions in existing tests. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ENG-224: Pass paymentFrequency to calculateServicingFee ENG-152 added paymentFrequency as a required third parameter but the caller in calculateServicingSplit was not updated, causing a runtime crash on any obligation settlement triggering dispersal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Wire 4 deal/fee cash events through the posting pipeline
Also fixes CREDIT_NORMAL_FAMILIES to include CASH_CLEARING and UNAPPLIED_CASH — these are liabilities (credit-normal) not assets, which corrects balance computation polarity for all future entries.
Changes
integrations.tswith proper idempotency keys and metadataSummary by CodeRabbit
New Features
Behavior
Tests
Bug Fixes