forked from Uniswap/v4-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: faling fuzz tests (Uniswap#441)
* Add failing fuzz test * Add bounds * added out of range checks * changed assume to bound * forge fmt * changed Position -> Liquidity on merge main * moved amount helper to utils --------- Co-authored-by: Austin Adams <[email protected]>
- Loading branch information
Showing
4 changed files
with
45 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
175475 | ||
173543 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import {LiquidityAmounts} from "./LiquidityAmounts.sol"; | ||
import {IPoolManager} from "../../src/interfaces/IPoolManager.sol"; | ||
import {PoolManager} from "../../src/PoolManager.sol"; | ||
import {PoolId, PoolIdLibrary} from "../../src/types/PoolId.sol"; | ||
import {TickMath} from "../../src/libraries/TickMath.sol"; | ||
import {PoolKey} from "../../src/types/PoolKey.sol"; | ||
|
||
/// @title Calculate token<>liquidity | ||
/// @notice Helps calculate amounts for bounding fuzz tests | ||
library AmountHelpers { | ||
function getMaxAmountInForPool( | ||
PoolManager manager, | ||
IPoolManager.ModifyLiquidityParams memory params, | ||
PoolKey memory key | ||
) public view returns (uint256 amount0, uint256 amount1) { | ||
PoolId id = PoolIdLibrary.toId(key); | ||
uint128 liquidity = manager.getLiquidity(id); | ||
(uint160 sqrtPriceX96,,) = manager.getSlot0(id); | ||
|
||
uint160 sqrtPriceX96Lower = TickMath.getSqrtRatioAtTick(params.tickLower); | ||
uint160 sqrtPriceX96Upper = TickMath.getSqrtRatioAtTick(params.tickUpper); | ||
|
||
amount0 = LiquidityAmounts.getAmount0ForLiquidity(sqrtPriceX96Lower, sqrtPriceX96, liquidity); | ||
amount1 = LiquidityAmounts.getAmount0ForLiquidity(sqrtPriceX96Upper, sqrtPriceX96, liquidity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters