Skip to content

Commit

Permalink
move enforce min of 1
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanSanderson committed Feb 25, 2024
1 parent 4a2f50e commit c37e6fc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pumps/MultiFlowPump.sol
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,13 @@ contract MultiFlowPump is IPump, IMultiFlowPumpErrors, IInstantaneousPump, ICumu
// If `_capLpTokenSupply` decreases the reserves, cap the ratio first, to maximize precision.
if (returnIfBelowMin) return new uint256[](0);
cappedReserves = tryCalcLPTokenUnderlying(mfpWf, maxLpTokenSupply, cappedReserves, lpTokenSupply, data);
if (cappedReserves[0] == 0) cappedReserves[0] = 1;
if (cappedReserves[1] == 0) cappedReserves[1] = 1;
}
// If LP Token Suppply decreased, check that it didn't increase below the min.
} else if (lpTokenSupply < lastLpTokenSupply) {
uint256 minLpTokenSupply = lastLpTokenSupply
* (ABDKMathQuad.ONE.sub(crp.maxLpSupplyDecrease)).powu(capExponent).to128x128().toUint256() / CAP_PRECISION2;
if (lpTokenSupply < minLpTokenSupply) {
cappedReserves = tryCalcLPTokenUnderlying(mfpWf, minLpTokenSupply, cappedReserves, lpTokenSupply, data);
if (cappedReserves[0] == 0) cappedReserves[0] = 1;
if (cappedReserves[1] == 0) cappedReserves[1] = 1;
}
}
}
Expand Down Expand Up @@ -553,6 +549,7 @@ contract MultiFlowPump is IPump, IMultiFlowPumpErrors, IInstantaneousPump, ICumu
/**
* @dev Assumes that if `calcLPTokenUnderlying` fails, it fails because of overflow.
* If the call fails, returns the maximum possible return value for `calcLPTokenUnderlying`.
* Also, enforces a minimum of 1 for each reserve.
*/
function tryCalcLPTokenUnderlying(
IMultiFlowPumpWellFunction wf,
Expand All @@ -565,6 +562,11 @@ contract MultiFlowPump is IPump, IMultiFlowPumpErrors, IInstantaneousPump, ICumu
uint256[] memory _underlyingAmounts
) {
underlyingAmounts = _underlyingAmounts;
for (uint256 i; i < underlyingAmounts.length; ++i) {
if (underlyingAmounts[i] == 0) {
underlyingAmounts[i] = 1;
}
}
} catch {
underlyingAmounts = new uint256[](reserves.length);
for (uint256 i; i < reserves.length; ++i) {
Expand Down

0 comments on commit c37e6fc

Please sign in to comment.