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-division-before-multiplication #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion contracts/DODOStablePool/lib/DODOMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ library DODOMath {
// bAbs = abs(part1-part2)
// if part1>part2 => b is negative => bSig is false
// if part2>part1 => b is positive => bSig is true
uint256 part2 = k.mul(V0).div(V1).mul(V0).add(i.mul(delta)); // kQ0^2/Q1-i*deltaB
uint256 part2 = k.mul(V0).mul(V0).div(V1).add(i.mul(delta)); // kQ0^2/Q1-i*deltaB
uint256 bAbs = DecimalMath.ONE.sub(k).mul(V1); // (1-k)Q1

bool bSig;
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/DODOMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ library DODOMath {
// bAbs = abs(part1-part2)
// if part1>part2 => b is negative => bSig is false
// if part2>part1 => b is positive => bSig is true
uint256 part2 = k * (V0) / (V1) * (V0) + (i * (delta)); // kQ0^2/Q1-i*deltaB
uint256 part2 = k * (V0) * (V0) / (V1) + (i * (delta)); // kQ0^2/Q1-i*deltaB
uint256 bAbs = (DecimalMath.ONE - k) * (V1); // (1-k)Q1

bool bSig;
Expand Down
4 changes: 2 additions & 2 deletions test/TestGasSavingPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ contract TestGasSavingPool is Test {
gsp.getPMMState();
dsp.getPMMState();
assertEq(receiveBaseAmount1, receiveBaseAmount2, "gsp receiveBaseAmount != dsp receiveBaseAmount");
uint256 tmp = i == 0 ? 1999730072785929125 : 1998897790924520164 ;
uint256 tmp = i == 0 ? 1999730072785929125 : 1998897790924520174 ;
assertEq(receiveBaseAmount1, tmp);

// check baseReserve, quoteReserve
(baseReserve1, quoteReserve1) = gsp.getVaultReserve();
(baseReserve2, quoteReserve2) = dsp.getVaultReserve();
assertEq(baseReserve1, baseReserve2, "gsp baseReserve != dsp baseReserve");
tmp = i == 0 ? 8000249929713368009 : 6001332149611046822;
tmp = i == 0 ? 8000249929713368009 : 6001332149611046812;
assertEq(baseReserve1, tmp);
assertEq(quoteReserve1, quoteReserve2, "gsp quoteReserve != dsp quoteReserve");
tmp = i == 0 ? 12000000 : 14000000;
Expand Down
Loading