Skip to content

Commit 5311707

Browse files
fix: resolve Gateway depositor address in payout burn path
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.
1 parent ce792af commit 5311707

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

app/api/payout/route.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const POST = withAuth(async (req, { user, supabase }) => {
134134

135135
// Routing logic based on source type
136136
let sourceWallet: WalletBalance | undefined;
137-
let depositorWallet: typeof wallets[0] | undefined; // Wallet that has the Gateway balance
137+
let depositorAddress: Address | undefined; // EOA that holds the Gateway balance (burn source)
138138
let strategy: "same-chain" | "gateway" = "same-chain";
139139
let estimatedFee = 0.50;
140140
let estimatedTime = 30;
@@ -174,6 +174,8 @@ export const POST = withAuth(async (req, { user, supabase }) => {
174174
estimatedFee = 2.01;
175175
estimatedTime = 60;
176176
useGateway = true;
177+
// The selected wallet is the EOA whose Gateway balance will be burned
178+
depositorAddress = selectedWallet.address as Address;
177179
}
178180

179181
console.log(`User selected wallet: ${sourceWallet.walletId} on ${sourceWallet.chain}`);
@@ -545,6 +547,7 @@ export const POST = withAuth(async (req, { user, supabase }) => {
545547
strategy = "gateway";
546548
estimatedFee = 2.01;
547549
estimatedTime = 60;
550+
depositorAddress = eoaAddressWithBalance;
548551
console.log(`Auto-selected Gateway from ${bestSourceChain}. Balance: ${Number(maxGatewayBalance) / 1_000_000} USDC from EOA ${eoaAddressWithBalance}`);
549552
}
550553
}
@@ -558,14 +561,25 @@ export const POST = withAuth(async (req, { user, supabase }) => {
558561
console.log(`Initiating Gateway transfer from ${sourceWallet.chain} to ${destinationChain}`);
559562

560563
// Step 1: Burn with EOA signature
561-
// Use the depositor wallet address (the one that has the Gateway balance)
564+
// Use the depositor address (the EOA that holds the Gateway balance)
565+
if (!depositorAddress) {
566+
return NextResponse.json(
567+
{
568+
error: "No Gateway depositor address resolved",
569+
userMessage:
570+
"Could not determine which wallet holds the Gateway balance for this transfer. Please retry or select a source wallet explicitly.",
571+
},
572+
{ status: 500 }
573+
);
574+
}
575+
562576
const { transferId, attestation, attestationSignature } = await signAndSubmitGatewayBurnIntent(
563577
user.id,
564578
amountInAtomicUnits,
565579
sourceWallet.chain,
566580
destinationChain,
567581
recipientAddress as Address,
568-
depositorWallet.address as Address // Pass the depositor address
582+
depositorAddress // Pass the depositor address
569583
);
570584

571585
console.log(`Burn intent submitted. Transfer ID: ${transferId}`);

0 commit comments

Comments
 (0)