feat(holdout): Add reasonable slippage assertion to always-leave scenario
- Modified sellAllKrk helper to return WETH delta received - Added assertion: WETH received >= 90% of ETH spent (0.09 ETH minimum) - Added log showing actual slippage percentage - This proves 'always leave' with reasonable slippage, not just exit ability
This commit is contained in:
parent
c9e84b2c34
commit
74a043262d
2 changed files with 17 additions and 5 deletions
|
|
@ -119,8 +119,10 @@ export async function buyKrk(page: Page, ethAmount: string): Promise<void> {
|
|||
* 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');
|
||||
|
||||
|
|
@ -175,9 +177,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue