Skip to content

Commit

Permalink
WIP fix L-01
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaman1337 committed Jun 17, 2024
1 parent 43d3e24 commit 001a8c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/pumps/MultiFlowPump.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {LibLastReserveBytes} from "src/libraries/LibLastReserveBytes.sol";
import {Math} from "oz/utils/math/Math.sol";
import {SafeCast} from "oz/utils/math/SafeCast.sol";
import {LibMath} from "src/libraries/LibMath.sol";
import {console} from "test/TestHelper.sol";

/**
* @title MultiFlowPump
Expand Down Expand Up @@ -275,19 +276,25 @@ contract MultiFlowPump is IPump, IMultiFlowPumpErrors, IInstantaneousPump, ICumu
if (crv.r > crv.rLimit) {
calcReservesAtRatioSwap(mfpWf, crv.rLimit, cappedReserves, i, j, data);
}
// If the ratio decreased, check that it didn't decrease below the max.
// If the ratio decreased, check that it didn't overflow during calculation
} else if (crv.r < crv.rLast) {
crv.rLimit = crv.rLast.mulDiv(
ABDKMathQuad.ONE.div(ABDKMathQuad.ONE.add(crp.maxRateChanges[j][i])).powu(capExponent).to128x128()
.toUint256(),
CAP_PRECISION2
);
bytes16 tempExp = ABDKMathQuad.ONE.div(ABDKMathQuad.ONE.add(crp.maxRateChanges[j][i])).powu(capExponent);
// Check for overflow before converting to 128x128
if (tempExp.cmp(MAX_CONVERT_TO_128x128) != -1) {
crv.rLimit = 0; // Set limit to 0 in case of overflow
console.log("overflow happened, so setting to zero");
revert("overflow");
} else {
console.log("there was no overflow");
crv.rLimit = crv.rLast.mulDiv(tempExp.to128x128().toUint256(), CAP_PRECISION2);
}
if (crv.r < crv.rLimit) {
calcReservesAtRatioSwap(mfpWf, crv.rLimit, cappedReserves, i, j, data);
}
}
}


/**
* @dev Cap the change in LP Token Supply of `reserves` to a maximum % change from `lastReserves`.
*/
Expand Down
6 changes: 6 additions & 0 deletions test/pumps/Pump.Fuzz.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ contract PumpFuzzTest is TestHelper, MultiFlowPump {
initReserves[i] = bound(initReserves[i], 1e6, 1e32);
reserves[i] = bound(reserves[i], 1e6, 1e32);
}

timeIncrease = 1099511627775; //1099511627775 is max uint40

vm.assume(block.timestamp + timeIncrease <= type(uint40).max);

// Start by updating the Pump with the initial reserves. Also initializes the Pump.
Expand Down Expand Up @@ -119,5 +122,8 @@ contract PumpFuzzTest is TestHelper, MultiFlowPump {
}
}
}
// assertTrue(false);
}


}

0 comments on commit 001a8c1

Please sign in to comment.