Skip to content

fix: resolve Gateway depositor address in payout burn path#36

Open
theyavuzarslan wants to merge 1 commit into
circlefin:masterfrom
theyavuzarslan:fix/gateway-depositor-address
Open

fix: resolve Gateway depositor address in payout burn path#36
theyavuzarslan wants to merge 1 commit into
circlefin:masterfrom
theyavuzarslan:fix/gateway-depositor-address

Conversation

@theyavuzarslan

@theyavuzarslan theyavuzarslan commented Jul 6, 2026

Copy link
Copy Markdown

depositorWallet is declared in app/api/payout/route.ts (line 137 on current master) but never assigned anywhere in the function. Any payout that reaches the Gateway execution path dereferences depositorWallet.address at the burn call, throws TypeError: Cannot read properties of undefined, and the outer catch turns that into a generic 500 Internal server error.

This hits two routing paths:

  1. Auto mode, when there is no wallet on the destination chain and a Gateway balance is found
  2. A user-selected wallet going cross-chain (sourceType: "wallet" with a different destination chain, which also sets useGateway = true)

In both cases the burn intent never gets submitted, so Gateway payouts on these paths always fail.

The fix replaces the never-assigned depositorWallet with a depositorAddress hoisted to function scope and assigned in both branches: the selected wallet's address in wallet mode, and eoaAddressWithBalance in auto mode (that variable was previously scoped inside the auto-mode block, so it was unusable at the burn site anyway). I also guarded the burn call so an unresolved depositor returns an explicit error instead of crashing.

Found by inspection rather than a repro: grep -n depositorWallet app/api/payout/route.ts shows one declaration and one dereference, zero assignments, so the Gateway branch can't complete. It compiles despite strict: true because wallets comes from an untyped Supabase query, which makes typeof wallets[0] resolve to any.

depositorWallet was declared but never assigned, so every payout that
reached the Gateway execution path (auto-mode fallback and user-selected
cross-chain) threw 'Cannot read properties of undefined' at the burn
call and surfaced as a generic 500.

Replace it with a hoisted depositorAddress that is assigned in both
routing branches: the selected wallet's address in wallet mode, and the
EOA found holding the Gateway balance in auto mode. Guard the burn call
so an unresolved depositor returns an explicit error instead of a crash.
@theyavuzarslan
theyavuzarslan force-pushed the fix/gateway-depositor-address branch from 2ac6757 to 5311707 Compare July 13, 2026 13:48
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.

1 participant