From 163d7d300f6358e9c8983045915b000ba521159f Mon Sep 17 00:00:00 2001 From: clemlak Date: Tue, 19 Mar 2024 15:15:05 +0400 Subject: [PATCH 1/4] fix: return controller in ConstantSum getPoolParams --- src/ConstantSum/ConstantSum.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ConstantSum/ConstantSum.sol b/src/ConstantSum/ConstantSum.sol index 08a1c27d..5e9a44a9 100644 --- a/src/ConstantSum/ConstantSum.sol +++ b/src/ConstantSum/ConstantSum.sol @@ -105,6 +105,7 @@ contract ConstantSum is PairStrategy { params.price = internalParams[poolId].price; params.swapFee = internalParams[poolId].swapFee; + params.controller = internalParams[poolId].controller; return abi.encode(params); } From 21031b5e4bc0ba0324a28fbfff0db57526d1ac46 Mon Sep 17 00:00:00 2001 From: clemlak Date: Tue, 19 Mar 2024 15:15:29 +0400 Subject: [PATCH 2/4] test: add test_ConstantSum_getPoolParams --- test/ConstantSum/unit/GetPoolParams.t.sol | 41 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/ConstantSum/unit/GetPoolParams.t.sol b/test/ConstantSum/unit/GetPoolParams.t.sol index 8381be67..742b7c05 100644 --- a/test/ConstantSum/unit/GetPoolParams.t.sol +++ b/test/ConstantSum/unit/GetPoolParams.t.sol @@ -1,6 +1,43 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; -import { ConstantSumSetUp } from "./SetUp.sol"; +import { ConstantSumSetUp, ConstantSumParams, InitParams } from "./SetUp.sol"; -contract ConstantSumGetPoolParamsTest is ConstantSumSetUp { } +contract ConstantSumGetPoolParamsTest is ConstantSumSetUp { + function test_ConstantSum_getPoolParams() public { + ConstantSumParams memory initialParams = ConstantSumParams({ + price: 1 ether, + swapFee: TEST_SWAP_FEE, + controller: address(this) + }); + + uint256 reserveX = 1 ether; + uint256 reserveY = 1 ether; + + bytes memory initData = + solver.getInitialPoolData(reserveX, reserveY, initialParams); + + address[] memory tokens = new address[](2); + tokens[0] = address(tokenX); + tokens[1] = address(tokenY); + + InitParams memory initParams = InitParams({ + name: "", + symbol: "", + strategy: address(constantSum), + tokens: tokens, + data: initData, + feeCollector: address(0), + controllerFee: 0 + }); + + dfmm.init(initParams); + + ConstantSumParams memory poolParams = + abi.decode(constantSum.getPoolParams(0), (ConstantSumParams)); + + assertEq(poolParams.price, initialParams.price); + assertEq(poolParams.swapFee, initialParams.swapFee); + assertEq(poolParams.controller, initialParams.controller); + } +} From fa84ff188a4fb789db3fce9313806a5c32ed4aa3 Mon Sep 17 00:00:00 2001 From: clemlak Date: Tue, 19 Mar 2024 18:40:50 +0400 Subject: [PATCH 3/4] test: update ConstantSum getPoolParams test --- test/ConstantSum/unit/GetPoolParams.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ConstantSum/unit/GetPoolParams.t.sol b/test/ConstantSum/unit/GetPoolParams.t.sol index 742b7c05..67f74d09 100644 --- a/test/ConstantSum/unit/GetPoolParams.t.sol +++ b/test/ConstantSum/unit/GetPoolParams.t.sol @@ -31,10 +31,10 @@ contract ConstantSumGetPoolParamsTest is ConstantSumSetUp { controllerFee: 0 }); - dfmm.init(initParams); + (uint256 poolId,,) = dfmm.init(initParams); ConstantSumParams memory poolParams = - abi.decode(constantSum.getPoolParams(0), (ConstantSumParams)); + abi.decode(constantSum.getPoolParams(poolId), (ConstantSumParams)); assertEq(poolParams.price, initialParams.price); assertEq(poolParams.swapFee, initialParams.swapFee); From 88b596be688d73593e56ced76e07832e432077fc Mon Sep 17 00:00:00 2001 From: clemlak Date: Tue, 19 Mar 2024 18:41:10 +0400 Subject: [PATCH 4/4] fix: add missing controller param in ConstantSum init --- src/ConstantSum/ConstantSum.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ConstantSum/ConstantSum.sol b/src/ConstantSum/ConstantSum.sol index 5e9a44a9..aaa2d170 100644 --- a/src/ConstantSum/ConstantSum.sol +++ b/src/ConstantSum/ConstantSum.sol @@ -63,6 +63,7 @@ contract ConstantSum is PairStrategy { internalParams[poolId].price = params.price; internalParams[poolId].swapFee = params.swapFee; + internalParams[poolId].controller = params.controller; // Get the trading function and check this is valid invariant =