Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Jul 10, 2024
1 parent 9e9d2c0 commit 8f50bdc
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_exactUnclaimedFees.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
295465
295470
Original file line number Diff line number Diff line change
@@ -1 +1 @@
227824
227829
2 changes: 1 addition & 1 deletion .forge-snapshots/autocompound_excessFeesCredit.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
316004
316009
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
213445
213449
2 changes: 1 addition & 1 deletion .forge-snapshots/decreaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
213455
213459
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc20.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
199081
199086
2 changes: 1 addition & 1 deletion .forge-snapshots/increaseLiquidity_erc6909.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
199093
199098
2 changes: 1 addition & 1 deletion .forge-snapshots/mintWithLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
490191
490196
19 changes: 15 additions & 4 deletions contracts/NonfungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {TransientStateLibrary} from "@uniswap/v4-core/src/libraries/TransientSta
import {SafeCast} from "@uniswap/v4-core/src/libraries/SafeCast.sol";
import {TransientLiquidityDelta} from "./libraries/TransientLiquidityDelta.sol";

import "forge-std/console2.sol";

contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidityManagement, ERC721Permit {
using CurrencyLibrary for Currency;
using CurrencySettleTake for Currency;
Expand Down Expand Up @@ -62,11 +64,17 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit
(bytes[] memory data, Currency[] memory currencies) = abi.decode(payload, (bytes[], Currency[]));

bool success;

bytes memory callReturn;
for (uint256 i; i < data.length; i++) {
// TODO: Move to internal call and bubble up all call return data.
(success,) = address(this).call(data[i]);
if (!success) revert("EXECUTE_FAILED");
(success, callReturn) = address(this).call(data[i]);
if (!success) {
// if the call failed, bubble up the reason
/// @solidity memory-safe-assembly
assembly {
revert(add(callReturn, 32), mload(callReturn))
}
}
}

// close the final deltas
Expand Down Expand Up @@ -123,7 +131,10 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit
}

// TODO: in v3, we can partially collect fees, but what was the usecase here?
function collect(uint256 tokenId, address recipient, bytes calldata hookData, bool claims) external {
function collect(uint256 tokenId, address recipient, bytes calldata hookData, bool claims)
external
isAuthorizedForToken(tokenId)
{
TokenPosition memory tokenPos = tokenPositions[tokenId];

_collect(recipient, tokenPos.owner, tokenPos.range, hookData);
Expand Down
9 changes: 4 additions & 5 deletions test/position-managers/Permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ contract PermitTest is Test, Deployers, GasSnapshot, Fuzzers, LiquidityOperation
uint256 balance0BobBefore = currency0.balanceOf(bob);
uint256 balance1BobBefore = currency1.balanceOf(bob);
vm.prank(bob);
_increaseLiquidity(tokenIdAlice, newLiquidity, ZERO_BYTES, false);
_increaseLiquidity(range, tokenIdAlice, newLiquidity, ZERO_BYTES, false);

// alice's position has new liquidity
(uint256 liquidity,,,,) = lpm.positions(alice, range.toId());
assertEq(liquidity, liquidityAlice + newLiquidity);

// bob used his tokens to increase liquidity
// TODO: enable after we fix msg.sender
// assertGt(balance0BobBefore, currency0.balanceOf(bob));
// assertGt(balance1BobBefore, currency1.balanceOf(bob));
assertGt(balance0BobBefore, currency0.balanceOf(bob));
assertGt(balance1BobBefore, currency1.balanceOf(bob));
}

function test_permit_decreaseLiquidity() public {
Expand All @@ -116,7 +115,7 @@ contract PermitTest is Test, Deployers, GasSnapshot, Fuzzers, LiquidityOperation
// bob can decrease liquidity on alice's token
uint256 liquidityToRemove = 0.4444e18;
vm.prank(bob);
_decreaseLiquidity(tokenIdAlice, liquidityToRemove, ZERO_BYTES, false);
_decreaseLiquidity(range, tokenIdAlice, liquidityToRemove, ZERO_BYTES, false);

// alice's position decreased liquidity
(uint256 liquidity,,,,) = lpm.positions(alice, range.toId());
Expand Down

0 comments on commit 8f50bdc

Please sign in to comment.