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:
parent
61f9e07e60
commit
d0e651ffc9
1 changed files with 3 additions and 4 deletions
|
|
@ -297,7 +297,7 @@ export async function sellKrk(
|
||||||
* This is the "sovereign exit" path — it bypasses the UI swap widget and
|
* 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.
|
* 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
|
* indicates the pool returned 0 output (possible with amountOutMinimum: 0n on
|
||||||
* a partially-drained pool).
|
* 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 wethAfter = await erc20BalanceOf(config.rpcUrl, WETH, config.accountAddress);
|
||||||
const wethReceived = wethAfter - wethBefore;
|
const wethReceived = wethAfter - wethBefore;
|
||||||
if (wethReceived <= 0n) {
|
if (wethReceived <= 0n) {
|
||||||
console.warn('[swap] WARNING: WETH balance did not increase after sell — pool may have returned 0 output');
|
throw new Error('sellAllKrk: swap returned 0 WETH — pool may be drained or price impact exceeded balance');
|
||||||
} else {
|
|
||||||
console.log(`[swap] Received ${wethReceived} WETH`);
|
|
||||||
}
|
}
|
||||||
|
console.log(`[swap] Received ${wethReceived} WETH`);
|
||||||
return wethReceived;
|
return wethReceived;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue