Summary
The _convertAssetsToUsdc function in CreditDelegationBranch.sol (lines 727-752) handles the conversion of various assets to USDC using a specified DEX swap strategy. However, the function does not incorporate slippage protection mechanisms during swaps. As a result, the conversion process might yield significantly lower USDC outputs than expected, particularly in volatile market conditions or scenarios with high price impact.
Vulnerability Details
function _convertAssetsToUsdc(
uint128 dexSwapStrategyId,
address asset,
uint256 assetAmount,
bytes memory path,
address recipient,
address usdc
)
internal
returns (uint256 usdcOut)
{
if (assetAmount == 0) revert Errors.AssetAmountIsZero(asset);
if (asset == usdc) {
usdcOut = assetAmount;
} else {
DexSwapStrategy.Data storage dexSwapStrategy = DexSwapStrategy.loadExisting(dexSwapStrategyId);
IERC20(asset).approve(dexSwapStrategy.dexAdapter, assetAmount);
if (path.length == 0) {
SwapExactInputSinglePayload memory swapCallData = SwapExactInputSinglePayload({
tokenIn: asset,
tokenOut: usdc,
amountIn: assetAmount,
recipient: recipient
});
usdcOut = dexSwapStrategy.executeSwapExactInputSingle(swapCallData);
} else {
@> SwapExactInputPayload memory swapCallData = SwapExactInputPayload({
path: path,
tokenIn: asset,
tokenOut: usdc,
amountIn: assetAmount,
recipient: recipient
});
@> usdcOut = dexSwapStrategy.executeSwapExactInput(swapCallData);
}
As we can see in the pointer precision can be lost when converting assets.
Impact
Users may receive far less USDC than anticipated due to unfavorable price movements or insufficient liquidity on the DEX.
Tools Used
Manual Audit
Recommendations
Introduce minAmountOut
if (usdcOut < minimumOutput) {
revert Errors.SlippageExceeded();
}