fix: sellAllKrk uses amountOutMinimum: 0n with no throw on 0 output (#450)

Replace console.warn with a thrown Error when wethReceived <= 0n so any
caller without a return-value check is protected, not just always-leave.spec.ts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-06 01:51:23 +00:00
parent 61f9e07e60
commit d0e651ffc9

View file

@ -297,7 +297,7 @@ export async function sellKrk(
* This is the "sovereign exit" path it bypasses the UI swap widget and
* sends transactions directly so the test is not gated on the sell-side UI.
*
* Logs a warning if the WETH balance does not increase after the swap, which
* Throws if the WETH balance does not increase after the swap, which
* indicates the pool returned 0 output (possible with amountOutMinimum: 0n on
* a partially-drained pool).
*
@ -360,9 +360,8 @@ export async function sellAllKrk(page: Page, config: SellConfig): Promise<bigint
const wethAfter = await erc20BalanceOf(config.rpcUrl, WETH, config.accountAddress);
const wethReceived = wethAfter - wethBefore;
if (wethReceived <= 0n) {
console.warn('[swap] WARNING: WETH balance did not increase after sell — pool may have returned 0 output');
} else {
console.log(`[swap] Received ${wethReceived} WETH`);
throw new Error('sellAllKrk: swap returned 0 WETH — pool may be drained or price impact exceeded balance');
}
console.log(`[swap] Received ${wethReceived} WETH`);
return wethReceived;
}