Skip to content

Commit

Permalink
remove vm assume
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Dec 5, 2024
1 parent 7c370a0 commit 938be10
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/positionDescriptor bytecode size.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
24110
24179
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ffi = true
fs_permissions = [{ access = "read-write", path = ".forge-snapshots/"}]
evm_version = "cancun"
gas_limit = "3000000000"
fuzz.runs = 10_000
fuzz.runs = 1000
bytecode_hash = "none"

[profile.debug]
Expand Down
91 changes: 75 additions & 16 deletions test/position-managers/NativeToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {PosmTestSetup} from "../shared/PosmTestSetup.sol";
import {Planner, Plan} from "../shared/Planner.sol";
import {PositionConfig} from "../shared/PositionConfig.sol";

contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
contract NativeTokenPoolManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
using FixedPointMathLib for uint256;
using CurrencyLibrary for Currency;
using Planner for Plan;
Expand Down Expand Up @@ -66,8 +66,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
}

function test_fuzz_mint_native(IPoolManager.ModifyLiquidityParams memory params) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -99,8 +103,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {

// minting with excess native tokens are returned to caller
function test_fuzz_mint_native_excess_withClose(IPoolManager.ModifyLiquidityParams memory params) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -154,8 +162,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
}

function test_fuzz_mint_native_excess_withSettlePair(IPoolManager.ModifyLiquidityParams memory params) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -211,8 +223,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
uint256 balance0Start = address(this).balance;
uint256 balance1Start = currency1.balanceOfSelf();

// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -264,8 +280,11 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
uint256 balance0Start = address(this).balance;
uint256 balance1Start = currency1.balanceOfSelf();

params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -322,8 +341,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
uint256 balance0Start = address(this).balance;
uint256 balance1Start = currency1.balanceOfSelf();

// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -370,8 +393,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
uint256 balance0Start = address(this).balance;
uint256 balance1Start = currency1.balanceOfSelf();

// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

uint256 liquidityToAdd =
params.liquidityDelta < 0 ? uint256(-params.liquidityDelta) : uint256(params.liquidityDelta);
Expand Down Expand Up @@ -461,8 +488,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
public
{
// fuzz for the range
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

// TODO: figure out if we can fuzz the increase liquidity delta. we're annoyingly getting TickLiquidityOverflow
uint256 liquidityToAdd = 1e18;
Expand Down Expand Up @@ -512,8 +543,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
public
{
// fuzz for the range
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

// TODO: figure out if we can fuzz the increase liquidity delta. we're annoyingly getting TickLiquidityOverflow
uint256 liquidityToAdd = 1e18;
Expand Down Expand Up @@ -562,8 +597,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
IPoolManager.ModifyLiquidityParams memory params,
uint256 decreaseLiquidityDelta
) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity
decreaseLiquidityDelta = bound(decreaseLiquidityDelta, 1, uint256(params.liquidityDelta));

PositionConfig memory config =
Expand Down Expand Up @@ -599,8 +638,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
IPoolManager.ModifyLiquidityParams memory params,
uint256 decreaseLiquidityDelta
) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity
decreaseLiquidityDelta = bound(decreaseLiquidityDelta, 1, uint256(params.liquidityDelta));

PositionConfig memory config =
Expand Down Expand Up @@ -639,8 +682,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
}

function test_fuzz_collect_native_withClose(IPoolManager.ModifyLiquidityParams memory params) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

PositionConfig memory config =
PositionConfig({poolKey: nativeKey, tickLower: params.tickLower, tickUpper: params.tickUpper});
Expand All @@ -665,8 +712,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
}

function test_fuzz_collect_native_withTakePair(IPoolManager.ModifyLiquidityParams memory params) public {
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

PositionConfig memory config =
PositionConfig({poolKey: nativeKey, tickLower: params.tickLower, tickUpper: params.tickUpper});
Expand Down Expand Up @@ -698,8 +749,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
function test_fuzz_collect_native_withTakePair_addressRecipient(IPoolManager.ModifyLiquidityParams memory params)
public
{
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

PositionConfig memory config =
PositionConfig({poolKey: nativeKey, tickLower: params.tickLower, tickUpper: params.tickUpper});
Expand Down Expand Up @@ -741,8 +796,12 @@ contract PositionManagerTest is Test, PosmTestSetup, LiquidityFuzzers {
function test_fuzz_collect_native_withTakePair_msgSenderRecipient(IPoolManager.ModifyLiquidityParams memory params)
public
{
// two-sided liquidity
params.tickLower =
int24(bound(params.tickLower, TickMath.minUsableTick(nativeKey.tickSpacing), -nativeKey.tickSpacing));
params.tickUpper =
int24(bound(params.tickUpper, nativeKey.tickSpacing, TickMath.maxUsableTick(nativeKey.tickSpacing)));
params = createFuzzyLiquidityParams(nativeKey, params, SQRT_PRICE_1_1);
vm.assume(params.tickLower < 0 && 0 < params.tickUpper); // two-sided liquidity

PositionConfig memory config =
PositionConfig({poolKey: nativeKey, tickLower: params.tickLower, tickUpper: params.tickUpper});
Expand Down
19 changes: 1 addition & 18 deletions test/position-managers/PositionManager.modifyLiquidities.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -847,24 +847,7 @@ contract PositionManagerModifyLiquiditiesTest is Test, PosmTestSetup, LiquidityF
bips = bound(bips, 1, 10_000);
MockFOT(address(fotToken)).setFee(bips);

tickLower = int24(
bound(
tickLower,
fotKey.tickSpacing * (TickMath.MIN_TICK / fotKey.tickSpacing),
fotKey.tickSpacing * (TickMath.MAX_TICK / fotKey.tickSpacing)
)
);
tickUpper = int24(
bound(
tickUpper,
fotKey.tickSpacing * (TickMath.MIN_TICK / fotKey.tickSpacing),
fotKey.tickSpacing * (TickMath.MAX_TICK / fotKey.tickSpacing)
)
);

tickLower = fotKey.tickSpacing * (tickLower / fotKey.tickSpacing);
tickUpper = fotKey.tickSpacing * (tickUpper / fotKey.tickSpacing);
vm.assume(tickUpper > tickLower);
(tickLower, tickUpper) = boundTicks(fotKey, tickLower, tickUpper);

(uint160 sqrtPriceX96,,,) = manager.getSlot0(fotKey.toId());
uint128 maxLiquidityPerTick = Pool.tickSpacingToMaxLiquidityPerTick(fotKey.tickSpacing);
Expand Down

0 comments on commit 938be10

Please sign in to comment.