Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions test/PriorityWithdrawalQueue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1666,17 +1666,41 @@ contract PriorityWithdrawalQueueTest is TestSetup {

uint256 remainderAmount = priorityQueue.getRemainderAmount();

// Only test if there are remainder shares. The remainder is just a few wei on mainnet
// fork (rounding dust), so halving it can round `sharesForAmount(eEthAmount)` to zero
// and leave `totalRemainderShares` untouched. Sweep the full remainder so the share
// delta is non-zero and the post-condition can fire.
// The remainder is typically just a few wei of rounding dust on a mainnet
// fork. Because of the shares<->amount rounding asymmetry, a sub-share
// remainder is un-sweepable: getRemainderAmount() rounds shares DOWN to an
// eEth amount, and handleRemainder converts that amount back via
// sharesForAmount() which rounds DOWN again, so `totalRemainderShares` may
// legitimately move by ZERO. Asserting an unconditional strict decrease is
// therefore flaky against live fork state.
//
// Instead, replicate handleRemainder's exact share accounting and assert
// the share balance drops by EXACTLY that amount (deterministic, fork-rate
// independent, and strictly stronger than the old inequality). Only when
// the remainder is genuinely sweepable (>=1 share moves) do we additionally
// assert the strict decrease.
if (remainderAmount > 0) {
uint256 remainderBefore = priorityQueue.totalRemainderShares();
uint256 sharesBefore = priorityQueue.totalRemainderShares();

// mirror handleRemainder(): treasury split rounds UP, burn gets the rest
uint256 splitBps = priorityQueue.shareRemainderSplitToTreasuryInBps();
uint256 toTreasury = Math.mulDiv(remainderAmount, splitBps, 10_000, Math.Rounding.Up);
uint256 toBurn = remainderAmount - toTreasury;
uint256 expectedSharesMoved =
liquidityPoolInstance.sharesForAmount(toBurn) + liquidityPoolInstance.sharesForAmount(toTreasury);

vm.prank(alice);
priorityQueue.handleRemainder(remainderAmount);

assertLt(priorityQueue.totalRemainderShares(), remainderBefore, "Remainder should decrease");
assertEq(
priorityQueue.totalRemainderShares(),
sharesBefore - expectedSharesMoved,
"totalRemainderShares must drop by exactly the swept share amount"
);
// Meaningful direction: a genuinely-sweepable remainder strictly decreases.
if (expectedSharesMoved > 0) {
assertLt(priorityQueue.totalRemainderShares(), sharesBefore, "sweepable remainder should strictly decrease");
}
}
}

Expand Down