Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/missing constant sum controller #83

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ConstantSum/ConstantSum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -105,6 +106,7 @@ contract ConstantSum is PairStrategy {

params.price = internalParams[poolId].price;
params.swapFee = internalParams[poolId].swapFee;
params.controller = internalParams[poolId].controller;

return abi.encode(params);
}
Expand Down
41 changes: 39 additions & 2 deletions test/ConstantSum/unit/GetPoolParams.t.sol
Original file line number Diff line number Diff line change
@@ -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
});

(uint256 poolId,,) = dfmm.init(initParams);

ConstantSumParams memory poolParams =
abi.decode(constantSum.getPoolParams(poolId), (ConstantSumParams));

assertEq(poolParams.price, initialParams.price);
assertEq(poolParams.swapFee, initialParams.swapFee);
assertEq(poolParams.controller, initialParams.controller);
}
}
Loading