Skip to content

fix(credit): always use safe prices after partial-liquidation withdrawals - #314

Open
SashaMIT wants to merge 1 commit into
Gearbox-protocol:mainfrom
SashaMIT:fix/partial-liquidation-safe-prices-v2
Open

SashaMIT wants to merge 1 commit into
Gearbox-protocol:mainfrom
SashaMIT:fix/partial-liquidation-safe-prices-v2

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Aug 8, 2026

Copy link
Copy Markdown

Problem

partiallyLiquidateCreditAccount always withdraws collateral (fee in underlying to treasury, seized token to the liquidator), then runs _fullCollateralCheck with a hardcoded useSafePrices: false.

The multicall path treats any withdrawCollateral as requiring safe prices: after the withdraw (and after any phantom-token adapter call) it unconditionally ORs USE_SAFE_PRICES_FLAG into the flags used for the final check (CreditFacadeV3._withdrawCollateral, return flags | REVERT_ON_FORBIDDEN_TOKENS_FLAG | USE_SAFE_PRICES_FLAG). That includes the case where a phantom withdrawer's adapter returns false for useSafePrices.

So the partial-liquidation path could leave an account that passed on a manipulated main feed after collateral left the account, while the equivalent multicall withdraw would have forced the stricter min(main, reserve) check (and zero for tokens with no reserve feed).

Related: #313 only forwards flags & USE_SAFE_PRICES_FLAG from the phantom/external call. That is incomplete for ordinary (non-phantom) seizes, and also incomplete when a phantom adapter returns false (the in-repo PhantomTokenWithdrawerMock does exactly that). This PR supersedes that approach.

Fix

Pass useSafePrices: true on the partial-liquidation collateral check. Withdrawals always happen on this path, so this matches multicall withdraw semantics.

Verification

forge test --match-test 'test_U_FA_16_partiallyLiquidateCreditAccount_works_as_expected|testU_FA_16A_partiallyLiqudiateCreditAccount_works_as_expected_with_phantom_token'

Both pass. Unit expectations updated from false to true on the fullCollateralCheck call.

Made with Cursor

…wals

partiallyLiquidateCreditAccount always withdraws fee + seized collateral, but
passed useSafePrices: false into the final fullCollateralCheck. Multicall's
withdrawCollateral path unconditionally ORs USE_SAFE_PRICES_FLAG after any
withdrawal (including when a phantom adapter returns false). Honour the same
post-withdrawal rule here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant