diff --git a/src/ConstantSum/ConstantSum.sol b/src/ConstantSum/ConstantSum.sol index 646df92a..27ca92b4 100644 --- a/src/ConstantSum/ConstantSum.sol +++ b/src/ConstantSum/ConstantSum.sol @@ -50,7 +50,7 @@ contract ConstantSum is PairStrategy { function init( address, uint256 poolId, - Pool calldata, + Pool calldata pool, bytes calldata data ) public @@ -66,6 +66,10 @@ contract ConstantSum is PairStrategy { (reserves, totalLiquidity, params) = abi.decode(data, (uint256[], uint256, ConstantSumParams)); + if (pool.reserves.length != 2 || reserves.length != 2) { + revert InvalidReservesLength(); + } + internalParams[poolId].price = params.price; internalParams[poolId].swapFee = params.swapFee; internalParams[poolId].controller = params.controller; diff --git a/src/GeometricMean/G3MMath.sol b/src/GeometricMean/G3MMath.sol index 0e409569..d5aff9e3 100644 --- a/src/GeometricMean/G3MMath.sol +++ b/src/GeometricMean/G3MMath.sol @@ -251,6 +251,9 @@ function computeInitialPoolData( L = computeNextLiquidity(amountX, rY, invariant, L, params); - return - abi.encode(amountX, rY, L, params.wX, params.swapFee, params.controller); + uint256[] memory reserves = new uint256[](2); + reserves[0] = amountX; + reserves[1] = rY; + + return abi.encode(reserves, L, params.wX, params.swapFee, params.controller); } diff --git a/src/GeometricMean/GeometricMean.sol b/src/GeometricMean/GeometricMean.sol index 1dcf1942..3d20d9b2 100644 --- a/src/GeometricMean/GeometricMean.sol +++ b/src/GeometricMean/GeometricMean.sol @@ -74,23 +74,22 @@ contract GeometricMean is PairStrategy { function init( address, uint256 poolId, - Pool calldata, + Pool calldata pool, bytes calldata data ) external onlyDFMM returns (bool, int256, uint256[] memory, uint256) { InitState memory state; - state.reserves = new uint256[](2); - ( - state.reserves[0], - state.reserves[1], + state.reserves, state.totalLiquidity, state.wX, state.swapFee, state.controller - ) = abi.decode( - data, (uint256, uint256, uint256, uint256, uint256, address) - ); + ) = abi.decode(data, (uint256[], uint256, uint256, uint256, address)); + + if (pool.reserves.length != 2 || state.reserves.length != 2) { + revert InvalidReservesLength(); + } if (state.wX >= ONE) { revert InvalidWeightX(); diff --git a/src/LogNormal/LogNormal.sol b/src/LogNormal/LogNormal.sol index 1bcd5513..ccdb3e1a 100644 --- a/src/LogNormal/LogNormal.sol +++ b/src/LogNormal/LogNormal.sol @@ -58,7 +58,7 @@ contract LogNormal is PairStrategy { function init( address, uint256 poolId, - Pool calldata, + Pool calldata pool, bytes calldata data ) public @@ -74,6 +74,10 @@ contract LogNormal is PairStrategy { (reserves, totalLiquidity, params) = abi.decode(data, (uint256[], uint256, LogNormalParams)); + if (pool.reserves.length != 2 || reserves.length != 2) { + revert InvalidReservesLength(); + } + internalParams[poolId].mean.lastComputedValue = params.mean; internalParams[poolId].width.lastComputedValue = params.width; internalParams[poolId].swapFee = params.swapFee; diff --git a/src/interfaces/IStrategy.sol b/src/interfaces/IStrategy.sol index 40027f55..0b10cd9a 100644 --- a/src/interfaces/IStrategy.sol +++ b/src/interfaces/IStrategy.sol @@ -23,6 +23,9 @@ interface IStrategy { /// @dev Thrown when an expected delta does not match the actual delta. error DeltaError(uint256 expected, uint256 actual); + /// @dev Thrown when the reserves length is not 2. + error InvalidReservesLength(); + // Setters /**