Merge pull request 'feat(holdout): Add reasonable slippage assertion to always-leave scenario' (#436) from fix/holdout-slippage-check into master

This commit is contained in:
johba 2026-03-03 22:41:23 +01:00
commit 05191bb15f
2 changed files with 17 additions and 5 deletions

View file

@ -174,8 +174,10 @@ export async function buyKrk(page: Page, ethAmount: string, opts?: BuyKrkOptions
* Logs a warning 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).
*
* @returns The WETH delta (wethAfter - wethBefore) received from the swap.
*/
export async function sellAllKrk(page: Page, config: SellConfig): Promise<void> {
export async function sellAllKrk(page: Page, config: SellConfig): Promise<bigint> {
const krkBalance = await erc20BalanceOf(config.rpcUrl, config.krkAddress, config.accountAddress);
if (krkBalance === 0n) throw new Error('sellAllKrk: KRK balance is 0 — nothing to sell');
@ -230,9 +232,11 @@ export async function sellAllKrk(page: Page, config: SellConfig): Promise<void>
console.log('[swap] Swap mined');
const wethAfter = await erc20BalanceOf(config.rpcUrl, WETH, config.accountAddress);
if (wethAfter <= wethBefore) {
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 ${wethAfter - wethBefore} WETH`);
console.log(`[swap] Received ${wethReceived} WETH`);
}
return wethReceived;
}