Skip to content

Commit

Permalink
fix init logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed May 6, 2024
1 parent 9a995d9 commit 4d2ad6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions src/RMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
18 changes: 10 additions & 8 deletions test/RMM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -476,25 +476,27 @@ 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,
sigma_: basicParams.sigma,
maturity_: basicParams.maturity
});

console2.log("amountY", amountY);

subject().init(
address(tokenX),
address(tokenY),
basicParams.reserveX,
basicParams.reserveY,
amountY,
totalLiquidity,
basicParams.strike,
basicParams.sigma,
Expand All @@ -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.");
Expand Down

0 comments on commit 4d2ad6f

Please sign in to comment.