If a trader is blacklisted from a blacklistable ERC20 token while has an open position, it may not be possible to liquidate the position.
When liquidate position, it will eventually calculate the amount of token that need to be send to borrower, the amount will be non-zero if the position is profitable or the borrower has excess premium.
function _closePosition(
DataStruct.ClosePositionParams calldata params,
DataCache.ClosePositionCache memory cache,
Lien.Info memory lien,
address borrower
) internal {
...
// calculate the the amounts owed to LP up to the premium in the lien
// must ensure enough amount is left to pay for interest first, then send gains and fund left to borrower
///@dev refundWithCheck ensures actual cannot be more than expected, since amount owed to LP is in actual,
/// it ensures (1) on the collateralFrom part of refund, tokenOwed is covered, and (2) on the amountReceived
/// part, received is no less than liquidity addback + token owed.
if (lien.zeroForOne) {
cache.token0Owed = cache.token0Owed < cache.tokenToPremium ? cache.token0Owed : cache.tokenToPremium;
cache.token1Owed = cache.token1Owed < cache.tokenFromPremium ? cache.token1Owed : cache.tokenFromPremium;
>>> Base.refundWithCheck(
borrower,
cache.tokenFrom,
cache.collateralFrom + cache.tokenFromPremium,
cache.amountSpent + cache.amountFromAdd + cache.token1Owed
);
>>> Base.refundWithCheck(
borrower,
cache.tokenTo,
cache.amountReceived + cache.tokenToPremium,
cache.amountToAdd + cache.token0Owed
);
} else {
cache.token0Owed = cache.token0Owed < cache.tokenFromPremium ? cache.token0Owed : cache.tokenFromPremium;
cache.token1Owed = cache.token1Owed < cache.tokenToPremium ? cache.token1Owed : cache.tokenToPremium;
>>> Base.refundWithCheck(
borrower,
cache.tokenFrom,
cache.collateralFrom + cache.tokenFromPremium,
cache.amountSpent + cache.amountFromAdd + cache.token0Owed
);
>>> Base.refundWithCheck(
borrower,
cache.tokenTo,
cache.amountReceived + cache.tokenToPremium,
cache.amountToAdd + cache.token1Owed
);
}
// pay for interest
lps.addTokensOwed(lien.tokenId, cache.token0Owed, cache.token1Owed);
}
The issue with this design is that if a borrower is blacklisted from a blacklistable token, such as USDC, it will not be possible to send profits or excess premium back to the borrower.
This will not only impact the borrower but also the liquidity provider, as the token cannot be added back to the Uniswap V3 LP position.
Manual review
use the “Pull over Push” design for sending profit/excess premium to the borrower.
Token-Transfer
The text was updated successfully, but these errors were encountered:
All reactions