diff --git a/src/RMM.sol b/src/RMM.sol index 0d6ad91..2fe3fcf 100644 --- a/src/RMM.sol +++ b/src/RMM.sol @@ -120,16 +120,15 @@ contract RMM is ERC20 { function prepareInit(uint256 priceX, uint256 amountX, uint256 strike_, uint256 sigma_, uint256 maturity_) public view - returns (uint256 totalLiquidity_) + returns (uint256 totalLiquidity_, uint256 amountY) { uint256 tau_ = computeTauWadYears(maturity_ - block.timestamp); uint256 initialLiquidity = computeLGivenX({reserveX_: amountX, S: priceX, strike_: strike_, sigma_: sigma_, tau_: tau_}); - console2.log("initialLiquidity", initialLiquidity); - uint256 amountY = - solveY({reserveX_: amountX, liquidity: initialLiquidity, strike_: strike_, sigma_: sigma_, tau_: tau_}); - totalLiquidity_ = solveL(initialLiquidity, reserveX, amountY, strike_, sigma_, tau_, tau_); + amountY = + computeY({reserveX_: amountX, liquidity: initialLiquidity, strike_: strike_, sigma_: sigma_, tau_: tau_}); + totalLiquidity_ = solveL(initialLiquidity, amountX, amountY, strike_, sigma_, tau_, tau_); } /// todo: need a way to compute initial liquidity based on price user input! diff --git a/test/RMM.t.sol b/test/RMM.t.sol index 7cf44d8..6a4671f 100644 --- a/test/RMM.t.sol +++ b/test/RMM.t.sol @@ -476,13 +476,13 @@ contract RMMTest is Test { assertEq(balance - newBalance, basicParams.reserveY, "Token Y balance did not decrease by reserve amount."); } - function test_init() public { - deal(address(tokenX), address(this), basicParams.reserveX); - deal(address(tokenY), address(this), basicParams.reserveY); - tokenX.approve(address(subject()), basicParams.reserveX); - tokenY.approve(address(subject()), basicParams.reserveY); + function test_init_pool() public { + deal(address(tokenX), address(this), 100e18); + deal(address(tokenY), address(this), 100e18); + tokenX.approve(address(subject()), 100e18); + tokenY.approve(address(subject()), 100e18); - uint256 totalLiquidity = subject().prepareInit({ + (uint256 totalLiquidity, uint256 amountY) = subject().prepareInit({ priceX: 1 ether, amountX: basicParams.reserveX, strike_: basicParams.strike, @@ -490,11 +490,13 @@ contract RMMTest is Test { maturity_: basicParams.maturity }); + console2.log("amountY", amountY); + subject().init( address(tokenX), address(tokenY), basicParams.reserveX, - basicParams.reserveY, + amountY, totalLiquidity, basicParams.strike, basicParams.sigma, @@ -506,7 +508,7 @@ contract RMMTest is Test { assertEq(subject().tokenX(), address(tokenX), "Token X address is not correct."); assertEq(subject().tokenY(), address(tokenY), "Token Y address is not correct."); assertEq(subject().reserveX(), basicParams.reserveX, "Reserve X is not correct."); - assertEq(subject().reserveY(), basicParams.reserveY, "Reserve Y is not correct."); + assertEq(subject().reserveY(), amountY, "Reserve Y is not correct."); assertEq(subject().totalLiquidity(), totalLiquidity, "Total liquidity is not correct."); assertEq(subject().strike(), basicParams.strike, "Strike is not correct."); assertEq(subject().sigma(), basicParams.sigma, "Sigma is not correct.");