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

Pool tests #726

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions src/libraries/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,17 @@ library Pool {
}

/// @notice Donates the given amount of currency0 and currency1 to the pool
function donate(State storage state, uint256 amount0, uint256 amount1) internal returns (BalanceDelta delta) {
uint128 liquidity = state.liquidity;
function donate(State storage self, uint256 amount0, uint256 amount1) internal returns (BalanceDelta delta) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

uint128 liquidity = self.liquidity;
if (liquidity == 0) NoLiquidityToReceiveFees.selector.revertWith();
unchecked {
// negation safe as amount0 and amount1 are always positive
delta = toBalanceDelta(-(amount0.toInt128()), -(amount1.toInt128()));
if (amount0 > 0) {
state.feeGrowthGlobal0X128 += FullMath.mulDiv(amount0, FixedPoint128.Q128, liquidity);
self.feeGrowthGlobal0X128 += FullMath.mulDiv(amount0, FixedPoint128.Q128, liquidity);
}
if (amount1 > 0) {
state.feeGrowthGlobal1X128 += FullMath.mulDiv(amount1, FixedPoint128.Q128, liquidity);
self.feeGrowthGlobal1X128 += FullMath.mulDiv(amount1, FixedPoint128.Q128, liquidity);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/ModifyLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ contract ModifyLiquidityTest is Test, Logger, Deployers, JavascriptFfi, Fuzzers,
}

// assert solc/js result is at most off by 1/100th of a bip (aka one pip)
function _checkError(int128 solc, int128 js, string memory errMsg) public pure returns (int128) {
function _checkError(int128 solc, int128 js, string memory errMsg) public pure {
if (solc != js) {
// Ensures no div by 0 in the case of one-sided liquidity adds.
(int128 gtResult, int128 ltResult) = js > solc ? (js, solc) : (solc, js);
Expand Down
Loading
Loading