Skip to content

Commit

Permalink
pr feedback nits
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Aug 29, 2024
1 parent 7efca6b commit 0d0ada1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/base/Permit2Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract Permit2Forwarder {
external
payable
{
// use try/catch in case an actor front-runs the permit, which would DOS multicalls
try permit2.permit(owner, permitSingle, signature) {} catch {}
}

Expand All @@ -27,6 +28,7 @@ contract Permit2Forwarder {
external
payable
{
// use try/catch in case an actor front-runs the permit, which would DOS multicalls
try permit2.permit(owner, _permitBatch, signature) {} catch {}
}
}
31 changes: 30 additions & 1 deletion test/position-managers/PositionManager.multicall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest
bytes[] memory calls = new bytes[](1);
calls[0] = abi.encodeWithSelector(IPositionManager.modifyLiquidities.selector, actions, _deadline);

address charlie = makeAddr("CHARLIE");
vm.startPrank(charlie);
vm.expectRevert(abi.encodeWithSelector(IPositionManager.NotApproved.selector, charlie));
lpm.multicall(calls);
Expand Down Expand Up @@ -357,6 +356,18 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest
lpm.permit(charlie, permit1, sig1);
vm.stopPrank();

// bob's front-run was successful
(uint160 _amount, uint48 _expiration, uint48 _nonce) =
permit2.allowance(charlie, Currency.unwrap(currency0), address(lpm));
assertEq(_amount, permitAmount);
assertEq(_expiration, permitExpiration);
assertEq(_nonce, permitNonce + 1);
(uint160 _amount1, uint48 _expiration1, uint48 _nonce1) =
permit2.allowance(charlie, Currency.unwrap(currency1), address(lpm));
assertEq(_amount1, permitAmount);
assertEq(_expiration1, permitExpiration);
assertEq(_nonce1, permitNonce + 1);

// charlie tries to mint an LP token with multicall(permit, permit, mint)
bytes[] memory calls = new bytes[](3);
calls[0] = abi.encodeWithSelector(Permit2Forwarder(lpm).permit.selector, charlie, permit0, sig0);
Expand All @@ -365,6 +376,9 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest
calls[2] = abi.encodeWithSelector(IPositionManager.modifyLiquidities.selector, mintCall, _deadline);

uint256 tokenId = lpm.nextTokenId();
vm.expectRevert();
lpm.ownerOf(tokenId); // token does not exist

lpm.multicall(calls);

assertEq(lpm.ownerOf(tokenId), charlie);
Expand Down Expand Up @@ -392,13 +406,28 @@ contract PositionManagerMulticallTest is Test, Permit2SignatureHelpers, PosmTest
vm.prank(bob);
lpm.permitBatch(charlie, permit, sig);

// bob's front-run was successful
(uint160 _amount, uint48 _expiration, uint48 _nonce) =
permit2.allowance(charlie, Currency.unwrap(currency0), address(lpm));
assertEq(_amount, permitAmount);
assertEq(_expiration, permitExpiration);
assertEq(_nonce, permitNonce + 1);
(uint160 _amount1, uint48 _expiration1, uint48 _nonce1) =
permit2.allowance(charlie, Currency.unwrap(currency1), address(lpm));
assertEq(_amount1, permitAmount);
assertEq(_expiration1, permitExpiration);
assertEq(_nonce1, permitNonce + 1);

// charlie tries to mint an LP token with multicall(permitBatch, mint)
bytes[] memory calls = new bytes[](2);
calls[0] = abi.encodeWithSelector(Permit2Forwarder(lpm).permitBatch.selector, charlie, permit, sig);
bytes memory mintCall = getMintEncoded(config, 10e18, charlie, ZERO_BYTES);
calls[1] = abi.encodeWithSelector(IPositionManager.modifyLiquidities.selector, mintCall, _deadline);

uint256 tokenId = lpm.nextTokenId();
vm.expectRevert();
lpm.ownerOf(tokenId); // token does not exist

lpm.multicall(calls);

assertEq(lpm.ownerOf(tokenId), charlie);
Expand Down

0 comments on commit 0d0ada1

Please sign in to comment.