Elastic-Finance-DAO / eefi_contracts

0 stars 0 forks source link

[TRE-02C] Inefficient Specification of Swap Paths #106

Open stalker474 opened 3 weeks ago

stalker474 commented 3 weeks ago

TRE-02C: Inefficient Specification of Swap Paths

Type Severity Location
Gas Optimization Trader.sol:L31, L32, L38-L41

Description:

The referenced variables are meant to specify swap paths using a storage data location that is significantly inefficient as all variables involved are either constant or immutable.

Example:

IERC20 public constant amplToken = IERC20(0xD46bA6D942050d489DBd938a2C909A5d5039A161);
IERC20 public constant ohmToken = IERC20(0x64aa3364F17a4D01c6f1751Fd97C2BD3D7e7f1D5);
IWETH9 public constant wethToken = IWETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
ISwapRouter public constant uniswapV3Router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
IUniswapV2Router02 public constant uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
IERC20 public immutable eefiToken;

address[] public pathAMPLETH = new address[](2);
address[] public pathOHMEEFI = new address[](2);

constructor(IERC20 _eefiToken) {
    require(address(_eefiToken) != address(0), "Trader: Invalid eefi token address");
    eefiToken = IERC20(_eefiToken);
    pathAMPLETH[0] = address(amplToken);
    pathAMPLETH[1] = address(wethToken);
    pathOHMEEFI[0] = address(ohmToken);
    pathOHMEEFI[1] = address(_eefiToken);
}

Recommendation:

We advise dedicated getter functions to be defined that are pure and yield the swap path directly, greatly optimizing all functions that would normally utilize them.