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

Update to v4-core latest #64

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddInitialLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
413041
412696
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
207307
206962
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeFirstSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
153143
154763
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
879088
879542
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200439
200095
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidityAndRebalance.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
380062
379287
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSecondSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
110682
112303
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
151418
153038
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMMSubmitOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
123914
123576
6 changes: 3 additions & 3 deletions contracts/hooks/examples/FullRange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ contract FullRange is BaseHook, ILockCallback {

PoolId poolId = key.toId();

(uint160 sqrtPriceX96,,,,,) = poolManager.getSlot0(poolId);
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolId);

if (sqrtPriceX96 == 0) revert PoolNotInitialized();

Expand Down Expand Up @@ -172,7 +172,7 @@ contract FullRange is BaseHook, ILockCallback {

PoolId poolId = key.toId();

(uint160 sqrtPriceX96,,,,,) = poolManager.getSlot0(poolId);
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolId);

if (sqrtPriceX96 == 0) revert PoolNotInitialized();

Expand Down Expand Up @@ -332,7 +332,7 @@ contract FullRange is BaseHook, ILockCallback {
) * FixedPointMathLib.sqrt(FixedPoint96.Q96)
).toUint160();

(uint160 sqrtPriceX96,,,,,) = poolManager.getSlot0(poolId);
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolId);

poolManager.swap(
key,
Expand Down
4 changes: 2 additions & 2 deletions contracts/hooks/examples/GeomeanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ contract GeomeanOracle is BaseHook {
/// @dev Called before any action that potentially modifies pool price or liquidity, such as swap or modify position
function _updatePool(PoolKey calldata key) private {
PoolId id = key.toId();
(, int24 tick,,,,) = poolManager.getSlot0(id);
(, int24 tick,,) = poolManager.getSlot0(id);

uint128 liquidity = poolManager.getLiquidity(id);

Expand Down Expand Up @@ -146,7 +146,7 @@ contract GeomeanOracle is BaseHook {

ObservationState memory state = states[id];

(, int24 tick,,,,) = poolManager.getSlot0(id);
(, int24 tick,,) = poolManager.getSlot0(id);

uint128 liquidity = poolManager.getLiquidity(id);

Expand Down
2 changes: 1 addition & 1 deletion contracts/hooks/examples/LimitOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract LimitOrder is BaseHook {
}

function getTick(PoolId poolId) private view returns (int24 tick) {
(, tick,,,,) = poolManager.getSlot0(poolId);
(, tick,,) = poolManager.getSlot0(poolId);
}

function getTickLower(int24 tick, int24 tickSpacing) private pure returns (int24) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/hooks/examples/TWAMM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ contract TWAMM is BaseHook, ITWAMM {
/// @inheritdoc ITWAMM
function executeTWAMMOrders(PoolKey memory key) public {
PoolId poolId = key.toId();
(uint160 sqrtPriceX96,,,,,) = poolManager.getSlot0(poolId);
(uint160 sqrtPriceX96,,,) = poolManager.getSlot0(poolId);
State storage twamm = twammStates[poolId];

(bool zeroForOne, uint160 sqrtPriceLimitX96) = _executeTWAMMOrders(
Expand Down
2 changes: 1 addition & 1 deletion lib/v4-core
Submodule v4-core updated 33 files
+1 −1 .forge-snapshots/donate gas with 1 token.snap
+1 −1 .forge-snapshots/donate gas with 2 tokens.snap
+1 −1 .forge-snapshots/initialize.snap
+1 −1 .forge-snapshots/mint with empty hook.snap
+1 −1 .forge-snapshots/mint with native token.snap
+1 −1 .forge-snapshots/mint.snap
+1 −1 .forge-snapshots/simple swap.snap
+1 −1 .forge-snapshots/swap against liquidity with native token.snap
+1 −1 .forge-snapshots/swap against liquidity.snap
+1 −1 .forge-snapshots/swap with dynamic fee.snap
+1 −1 .forge-snapshots/swap with hooks.snap
+1 −1 .forge-snapshots/swap with native.snap
+20 −19 contracts/Fees.sol
+11 −26 contracts/PoolManager.sol
+3 −8 contracts/interfaces/IHookFeeManager.sol
+3 −10 contracts/interfaces/IPoolManager.sol
+1 −1 contracts/interfaces/IProtocolFeeController.sol
+44 −41 contracts/libraries/Pool.sol
+43 −34 contracts/test/MockHooks.sol
+6 −3 contracts/test/PoolDonateTest.sol
+4 −3 contracts/test/PoolModifyPositionTest.sol
+12 −11 contracts/test/PoolSwapTest.sol
+6 −6 contracts/test/ProtocolFeeControllerTest.sol
+22 −11 test/PoolManager.gas.spec.ts
+49 −42 test/PoolManager.spec.ts
+73 −73 test/__snapshots__/PoolManager.gas.spec.ts.snap
+1 −1 test/__snapshots__/PoolManager.spec.ts.snap
+8 −2 test/foundry-tests/DynamicFees.t.sol
+171 −118 test/foundry-tests/Fees.t.sol
+31 −12 test/foundry-tests/Hooks.t.sol
+18 −4 test/foundry-tests/Pool.t.sol
+62 −54 test/foundry-tests/PoolManager.t.sol
+16 −2 test/foundry-tests/utils/Deployers.sol
22 changes: 12 additions & 10 deletions test/FullRange.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

snapStart("FullRangeSwap");
swapRouter.swap(key, params, settings);
swapRouter.swap(key, params, settings, ZERO_BYTES);
snapEnd();

(bool hasAccruedFees,) = fullRange.poolInfo(id);
Expand Down Expand Up @@ -319,7 +319,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings memory settings =
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

swapRouter.swap(key, params, settings);
swapRouter.swap(key, params, settings, ZERO_BYTES);

vm.expectRevert(FullRange.TooMuchSlippage.selector);
fullRange.addLiquidity(
Expand All @@ -345,14 +345,14 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

snapStart("FullRangeFirstSwap");
swapRouter.swap(testKey, params, settings);
swapRouter.swap(testKey, params, settings, ZERO_BYTES);
snapEnd();

(bool hasAccruedFees,) = fullRange.poolInfo(id);
assertEq(hasAccruedFees, true);

snapStart("FullRangeSecondSwap");
swapRouter.swap(testKey, params, settings);
swapRouter.swap(testKey, params, settings, ZERO_BYTES);
snapEnd();

(hasAccruedFees,) = fullRange.poolInfo(id);
Expand Down Expand Up @@ -380,8 +380,8 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

swapRouter.swap(key, params, testSettings);
swapRouter.swap(key2, params, testSettings);
swapRouter.swap(key, params, testSettings, ZERO_BYTES);
swapRouter.swap(key2, params, testSettings, ZERO_BYTES);

(bool hasAccruedFees,) = fullRange.poolInfo(id);
assertEq(hasAccruedFees, true);
Expand Down Expand Up @@ -563,7 +563,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

swapRouter.swap(keyWithLiq, params, testSettings);
swapRouter.swap(keyWithLiq, params, testSettings, ZERO_BYTES);

UniswapV4ERC20(liquidityToken).approve(address(fullRange), type(uint256).max);

Expand Down Expand Up @@ -690,7 +690,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

swapRouter.swap(key, params, testSettings);
swapRouter.swap(key, params, testSettings, ZERO_BYTES);

(bool hasAccruedFees,) = fullRange.poolInfo(id);
assertEq(hasAccruedFees, true);
Expand Down Expand Up @@ -745,7 +745,7 @@ contract TestFullRange is Test, Deployers, GasSnapshot {
PoolSwapTest.TestSettings memory testSettings =
PoolSwapTest.TestSettings({withdrawTokens: true, settleUsingTransfer: true});

swapRouter.swap(key, params, testSettings);
swapRouter.swap(key, params, testSettings, ZERO_BYTES);

// Test contract removes liquidity, succeeds
UniswapV4ERC20(liquidityToken).approve(address(fullRange), type(uint256).max);
Expand All @@ -765,7 +765,9 @@ contract TestFullRange is Test, Deployers, GasSnapshot {

vm.expectRevert(FullRange.SenderMustBeHook.selector);
modifyPositionRouter.modifyPosition(
key, IPoolManager.ModifyPositionParams({tickLower: MIN_TICK, tickUpper: MAX_TICK, liquidityDelta: 100})
key,
IPoolManager.ModifyPositionParams({tickLower: MIN_TICK, tickUpper: MAX_TICK, liquidityDelta: 100}),
ZERO_BYTES
);
}

Expand Down
9 changes: 6 additions & 3 deletions test/GeomeanOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ contract TestGeomeanOracle is Test, Deployers, TokenFixture {
key,
IPoolManager.ModifyPositionParams(
TickMath.minUsableTick(MAX_TICK_SPACING), TickMath.maxUsableTick(MAX_TICK_SPACING), 1000
)
),
ZERO_BYTES
);

GeomeanOracle.ObservationState memory observationState = geomeanOracle.getState(key);
Expand All @@ -149,7 +150,8 @@ contract TestGeomeanOracle is Test, Deployers, TokenFixture {
key,
IPoolManager.ModifyPositionParams(
TickMath.minUsableTick(MAX_TICK_SPACING), TickMath.maxUsableTick(MAX_TICK_SPACING), 1000
)
),
ZERO_BYTES
);

GeomeanOracle.ObservationState memory observationState = geomeanOracle.getState(key);
Expand Down Expand Up @@ -177,7 +179,8 @@ contract TestGeomeanOracle is Test, Deployers, TokenFixture {
key,
IPoolManager.ModifyPositionParams(
TickMath.minUsableTick(MAX_TICK_SPACING), TickMath.maxUsableTick(MAX_TICK_SPACING), 1000
)
),
ZERO_BYTES
);

// cardinality is updated
Expand Down
12 changes: 8 additions & 4 deletions test/LimitOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ contract TestLimitOrder is Test, Deployers, TokenFixture {
function testZeroForOneInRangeRevert() public {
// swapping is free, there's no liquidity in the pool, so we only need to specify 1 wei
swapRouter.swap(
key, IPoolManager.SwapParams(false, 1, SQRT_RATIO_1_1 + 1), PoolSwapTest.TestSettings(true, true)
key,
IPoolManager.SwapParams(false, 1, SQRT_RATIO_1_1 + 1),
PoolSwapTest.TestSettings(true, true),
ZERO_BYTES
);
vm.expectRevert(LimitOrder.InRange.selector);
limitOrder.place(key, 0, true, 1000000);
Expand All @@ -131,7 +134,7 @@ contract TestLimitOrder is Test, Deployers, TokenFixture {
function testNotZeroForOneInRangeRevert() public {
// swapping is free, there's no liquidity in the pool, so we only need to specify 1 wei
swapRouter.swap(
key, IPoolManager.SwapParams(true, 1, SQRT_RATIO_1_1 - 1), PoolSwapTest.TestSettings(true, true)
key, IPoolManager.SwapParams(true, 1, SQRT_RATIO_1_1 - 1), PoolSwapTest.TestSettings(true, true), ZERO_BYTES
);
vm.expectRevert(LimitOrder.InRange.selector);
limitOrder.place(key, -60, false, 1000000);
Expand Down Expand Up @@ -192,11 +195,12 @@ contract TestLimitOrder is Test, Deployers, TokenFixture {
swapRouter.swap(
key,
IPoolManager.SwapParams(false, 1e18, TickMath.getSqrtRatioAtTick(60)),
PoolSwapTest.TestSettings(true, true)
PoolSwapTest.TestSettings(true, true),
ZERO_BYTES
);

assertEq(limitOrder.getTickLowerLast(id), 60);
(, int24 tick,,,,) = manager.getSlot0(id);
(, int24 tick,,) = manager.getSlot0(id);
assertEq(tick, 60);

(bool filled,,, uint256 token0Total, uint256 token1Total,) = limitOrder.epochInfos(Epoch.wrap(1));
Expand Down
12 changes: 8 additions & 4 deletions test/TWAMM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ contract TWAMMTest is Test, Deployers, TokenFixture, GasSnapshot {
token1.approve(address(modifyPositionRouter), 100 ether);
token0.mint(address(this), 100 ether);
token1.mint(address(this), 100 ether);
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-60, 60, 10 ether));
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-120, 120, 10 ether));
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-60, 60, 10 ether), ZERO_BYTES);
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-120, 120, 10 ether), ZERO_BYTES);
modifyPositionRouter.modifyPosition(
poolKey, IPoolManager.ModifyPositionParams(TickMath.minUsableTick(60), TickMath.maxUsableTick(60), 10 ether)
poolKey,
IPoolManager.ModifyPositionParams(TickMath.minUsableTick(60), TickMath.maxUsableTick(60), 10 ether),
ZERO_BYTES
);
}

Expand Down Expand Up @@ -367,7 +369,9 @@ contract TWAMMTest is Test, Deployers, TokenFixture, GasSnapshot {

token0.approve(address(twamm), 100e18);
token1.approve(address(twamm), 100e18);
modifyPositionRouter.modifyPosition(poolKey, IPoolManager.ModifyPositionParams(-2400, 2400, 10 ether));
modifyPositionRouter.modifyPosition(
poolKey, IPoolManager.ModifyPositionParams(-2400, 2400, 10 ether), ZERO_BYTES
);

vm.warp(10000);
twamm.submitOrder(poolKey, orderKey1, orderAmount);
Expand Down