fix: add swap refund skipping logic to Moralis deposit processing - #658
fix: add swap refund skipping logic to Moralis deposit processing#658sundayonah wants to merge 2 commits into
Conversation
- Introduced a check to skip processing deposits that are identified as swap refunds, enhancing the handling of transactions. - Added logging for development environment to indicate when a deposit is skipped due to being a swap refund. - Updated both native and ERC20 deposit processing functions to include this new logic, ensuring consistent behavior across transaction types.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMoralis deposit processing now skips transfers identified as swap refunds. The change adds shared gateway address detection, swap-order transaction matching, and tests for Paycrest gateway address recognition. ChangesMoralis swap-refund filtering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant DepositProcessor
participant SwapRefundHelper
participant Supabase
DepositProcessor->>SwapRefundHelper: Check wallet, tx hash, and sender
SwapRefundHelper->>Supabase: Query matching swap-order transactions
Supabase-->>SwapRefundHelper: Query result
SwapRefundHelper-->>DepositProcessor: Skip or continue
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
__tests__/moralis-skip-swap-refund.test.ts (1)
3-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the actual refund-skip decision paths.
Add mocked-Supabase tests for matching
tx_hash, lookup errors failing open, and the intendedrefundingcorrelation; add native and ERC-20 assertions that skipped transfers do not trigger Activepieces or insert acreditrow.🤖 Prompt for 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. In `@__tests__/moralis-skip-swap-refund.test.ts` around lines 3 - 20, Expand the tests around isPaycrestGatewayAddress and the refund-skip flow with mocked Supabase cases for matching tx_hash, lookup errors failing open, and the intended refunding correlation. Add native and ERC-20 assertions verifying skipped transfers neither trigger Activepieces nor insert a credit row, while preserving the existing address-validation coverage.
🤖 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 `@app/lib/moralis-skip-swap-refund.ts`:
- Around line 50-52: Update the refund-skip condition around swapOrderExists so
it matches the specific refund associated with the inbound transfer, using the
expected sender or refund transaction identifier rather than wallet-level
refunding status alone. Ensure unrelated deposits continue through the existing
notification and credit flow unchanged.
---
Nitpick comments:
In `@__tests__/moralis-skip-swap-refund.test.ts`:
- Around line 3-20: Expand the tests around isPaycrestGatewayAddress and the
refund-skip flow with mocked Supabase cases for matching tx_hash, lookup errors
failing open, and the intended refunding correlation. Add native and ERC-20
assertions verifying skipped transfers neither trigger Activepieces nor insert a
credit row, while preserving the existing address-validation coverage.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 218715c8-e47b-4738-a200-79a8d2a64eb2
📒 Files selected for processing (5)
__tests__/moralis-skip-swap-refund.test.tsapp/lib/moralis-deposit-processing.tsapp/lib/moralis-skip-swap-refund.tsapp/types.tsapp/utils.ts
Description
When a Noblocks swap fails and Paycrest refunds crypto to the user’s wallet, two systems were handling the same on-chain transfer:
refunded.credittransaction (shown as “Funded” in history), and sends a deposit email via Activepieces → Brevo.Users saw duplicate history rows and an unwanted “you received funds” email for money that was already tied to a failed swap.
This PR adds refund detection in Moralis deposit processing so failed-swap refunds are not recorded as deposits and not emailed.
Implementation
app/lib/moralis-skip-swap-refund.ts—shouldSkipMoralisDepositAsSwapRefund()skips when:fromis a known Paycrest gateway contract (isPaycrestGatewayAddressinutils.ts)onramp,offramp,bridge,swapviaSWAP_ORDER_TRANSACTION_TYPESintypes.ts)refundingstatus (in-flight refund)app/lib/moralis-deposit-processing.ts— calls the skip helper beforetriggerActivepiecesDepositand thecreditinsert for both native and ERC-20 transfers.app/utils.ts— extractsGATEWAY_CONTRACT_ADDRESSESas the single source of truth for gateway addresses;getGatewayContractAddress()behavior is unchanged for existing callers (TransactionPreview).app/types.ts— addsSWAP_ORDER_TRANSACTION_TYPES, a typed subset ofTransactionHistoryTypefor order rows that can refund.Impacts
creditrows created before this fix are not removed (prevention only).Breaking changes: None.
Alternatives considered
refundedstatus — too late if Moralis fires before status update; gateway +refunding+ tx-hash checks cover timing gaps.API / contracts / DB: No changes.
References
KAN-731
Testing
Manual (staging)
creditrow for the same tx hash.Environment: Noblocks (
@paycrest/noblocks), Next.js 15, TypeScript, Node.js on Windows (local dev); Moralis Streams webhook + Supabase.Checklist
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.
Summary by CodeRabbit