From df0e5891001df91741c0eda9cfb84bfa3e47da92 Mon Sep 17 00:00:00 2001 From: clemlak Date: Fri, 26 Apr 2024 14:25:36 +0200 Subject: [PATCH] feat: add token index check in G3M prepareSwap --- src/GeometricMean/GeometricMeanSolver.sol | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/GeometricMean/GeometricMeanSolver.sol b/src/GeometricMean/GeometricMeanSolver.sol index 3ca48220..6bd0ec6a 100644 --- a/src/GeometricMean/GeometricMeanSolver.sol +++ b/src/GeometricMean/GeometricMeanSolver.sol @@ -119,8 +119,15 @@ contract GeometricMeanSolver is ISolver { uint256 tokenOutIndex, uint256 amountIn ) public view returns (bool, uint256, bytes memory) { + if ( + tokenInIndex > 1 || tokenOutIndex > 1 + || tokenInIndex == tokenOutIndex + ) { + revert InvalidTokenIndex(); + } + GeometricMeanParams memory params = getPoolParams(poolId); - Pool memory pool = IDFMM(IStrategy(strategy).dfmm()).pools(poolId); + Pool memory pool = IDFMM(strategy.dfmm()).pools(poolId); SimulateSwapState memory state; @@ -161,9 +168,8 @@ contract GeometricMeanSolver is ISolver { bytes memory swapData = abi.encode(tokenInIndex, tokenOutIndex, amountIn, state.amountOut); - (bool valid,,,,,,) = IStrategy(strategy).validateSwap( - address(this), poolId, pool, swapData - ); + (bool valid,,,,,,) = + strategy.validateSwap(address(this), poolId, pool, swapData); return (valid, state.amountOut, swapData); }