FV-SOL-8-C3 Insufficient Liquidity

TLDR

If a DEX doesn’t have enough liquidity in the token pair, the price impact will be disproportionately high, leading to significant slippage or failed transactions.

Game

If the DEX’s liquidity is low, the swap might incur heavy slippage, or worse, revert due to insufficient output tokens. What to do??

// SPDX-License-Identifier: MIT
// Open me in VSCode and really think before opening the hints!
// Add @audit tags wherever suspicious
// Go to the solidity docs to complete missing knowledge of what's happening here
// Solve by drafting a fix!
pragma solidity ^0.8.0;

interface IDEX {
    function swap(address tokenIn, address tokenOut, uint256 amountIn) external returns (uint256);
    function getAvailableLiquidity(address tokenOut) external view returns (uint256);
}

contract InsufficientLiquidityGame {
    IDEX public dex;
    address public tokenOut;

    constructor(address _dex, address _tokenOut) {
        dex = IDEX(_dex);
        tokenOut = _tokenOut;
    }

    function executeSwap(address tokenIn, uint256 amountIn) public {
        uint256 amountOut = dex.swap(tokenIn, tokenOut, amountIn);
        require(amountOut > 0, "Swap failed");
    }
}

Last updated