Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Aug 2, 2024
2 parents 724b509 + daf74ce commit 78821d3
Show file tree
Hide file tree
Showing 56 changed files with 385 additions and 152 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134126
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
134264

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
126921
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
127059
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
372012
371963
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_native.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
336712
336663
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_nativeWithSweep.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345244
345146
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickLower.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
314694
314645
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
315336
315287
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_mint_sameRange.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
240918
240869
Original file line number Diff line number Diff line change
@@ -1 +1 @@
370018
370009
Original file line number Diff line number Diff line change
@@ -1 +1 @@
320712
320663
Original file line number Diff line number Diff line change
@@ -1 +1 @@
416388
416339
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_Bytecode.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7157
7342
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120513
120464
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119708
119659
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128580
128531
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135410
135361
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186917
186868
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
178852
178803
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238449
238400
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
230408
230359
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134175
134126
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119278
119229
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactInputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
118451
118402
Original file line number Diff line number Diff line change
@@ -1 +1 @@
126310
126261
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
120543
120494
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_oneForZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129415
129366
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut1Hop_zeroForOne.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
134216
134167
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
186326
186277
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut2Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183221
183172
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
238476
238427
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
235395
235346
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229628
229579
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
132979
132930
Original file line number Diff line number Diff line change
@@ -1 +1 @@
125073
125024
2 changes: 1 addition & 1 deletion .forge-snapshots/V4Router_ExactOutputSingle_nativeOut.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119364
119315
4 changes: 2 additions & 2 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ contract PositionManager is
address owner,
bytes calldata hookData
) = params.decodeMintParams();
_mint(config, liquidity, amount0Max, amount1Max, owner, hookData);
_mint(config, liquidity, amount0Max, amount1Max, _map(owner), hookData);
} else if (action == Actions.CLOSE_CURRENCY) {
Currency currency = params.decodeCurrency();
_close(currency);
Expand All @@ -129,7 +129,7 @@ contract PositionManager is
_settleWithBalance(currency);
} else if (action == Actions.SWEEP) {
(Currency currency, address to) = params.decodeCurrencyAndAddress();
_sweep(currency, to);
_sweep(currency, _map(to));
} else {
revert UnsupportedAction(action);
}
Expand Down
5 changes: 2 additions & 3 deletions src/V4Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ abstract contract V4Router is IV4Router, BaseActionsRouter, DeltaResolver {
uint256 amount = _getFullTakeAmount(currency);

// TODO should _take have a minAmountOut added slippage check?
// TODO recipient mapping
_take(currency, recipient, amount);
_take(currency, _map(recipient), amount);
} else if (action == Actions.TAKE_PORTION) {
(Currency currency, address recipient, uint256 bips) = params.decodeCurrencyAddressAndUint256();
_take(currency, recipient, _getFullTakeAmount(currency).calculatePortion(bips));
_take(currency, _map(recipient), _getFullTakeAmount(currency).calculatePortion(bips));
} else {
revert UnsupportedAction(action);
}
Expand Down
14 changes: 14 additions & 0 deletions src/base/BaseActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {SafeCallback} from "./SafeCallback.sol";
import {CalldataDecoder} from "../libraries/CalldataDecoder.sol";
import {Actions} from "../libraries/Actions.sol";

/// @notice Abstract contract for performing a combination of actions on Uniswap v4.
/// @dev Suggested uint256 action values are defined in Actions.sol, however any definition can be used
Expand Down Expand Up @@ -52,4 +53,17 @@ abstract contract BaseActionsRouter is SafeCallback {
/// `msg.sender` shouldnt be used, as this will be the v4 pool manager contract that calls `unlockCallback`
/// If using ReentrancyLock.sol, this function can return _getLocker()
function _msgSender() internal view virtual returns (address);

/// @notice Calculates the address for a action
/// @param recipient The address or address-flag for the action
/// @return output The resultant address for the action
function _map(address recipient) internal view returns (address) {
if (recipient == Actions.MSG_SENDER) {
return _msgSender();
} else if (recipient == Actions.ADDRESS_THIS) {
return address(this);
} else {
return recipient;
}
}
}
7 changes: 7 additions & 0 deletions src/libraries/Actions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ library Actions {
// minting/burning 6909s to close deltas
uint256 constant MINT_6909 = 0x20;
uint256 constant BURN_6909 = 0x21;

// helper constants to signal certain addresses
// Used as a flag for identifying that msg.sender should be used
address internal constant MSG_SENDER = address(1);

// Used as a flag for identifying address(this) should be used
address internal constant ADDRESS_THIS = address(2);
}
11 changes: 11 additions & 0 deletions test/BaseActionsRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,15 @@ contract BaseActionsRouterTest is Test, Deployers, GasSnapshot {
router.executeActions(data);
assertEq(router.burnCount(), 10);
}

function test_fuzz_map(address recipient) public view {
address mappedRecipient = router.map(recipient);
if (recipient == Actions.MSG_SENDER) {
assertEq(mappedRecipient, address(0xdeadbeef));
} else if (recipient == Actions.ADDRESS_THIS) {
assertEq(mappedRecipient, address(router));
} else {
assertEq(mappedRecipient, recipient);
}
}
}
8 changes: 6 additions & 2 deletions test/mocks/MockBaseActionsRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ contract MockBaseActionsRouter is BaseActionsRouter, ReentrancyLock {
}
}

function _msgSender() internal view override returns (address) {
return _getLocker();
function _msgSender() internal pure override returns (address) {
return address(0xdeadbeef);
}

function _settle(bytes calldata /* params **/ ) internal {
Expand Down Expand Up @@ -80,4 +80,8 @@ contract MockBaseActionsRouter is BaseActionsRouter, ReentrancyLock {
function _clear(bytes calldata /* params **/ ) internal {
clearCount++;
}

function map(address recipient) external view returns (address) {
return _map(recipient);
}
}
12 changes: 7 additions & 5 deletions test/position-managers/Execute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers {
initialLiquidity = bound(initialLiquidity, 1e18, 1000e18);
liquidityToAdd = bound(liquidityToAdd, 1e18, 1000e18);
uint256 tokenId = lpm.nextTokenId();
mint(config, initialLiquidity, address(this), ZERO_BYTES);
mint(config, initialLiquidity, Actions.MSG_SENDER, ZERO_BYTES);

increaseLiquidity(tokenId, config, liquidityToAdd, ZERO_BYTES);

Expand All @@ -87,7 +87,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers {
liquidityToAdd = bound(liquidityToAdd, 1e18, 1000e18);
liquidityToAdd2 = bound(liquidityToAdd2, 1e18, 1000e18);
uint256 tokenId = lpm.nextTokenId();
mint(config, initialLiquidity, address(this), ZERO_BYTES);
mint(config, initialLiquidity, Actions.MSG_SENDER, ZERO_BYTES);

Plan memory planner = Planner.init();

Expand Down Expand Up @@ -122,7 +122,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers {
planner.add(
Actions.MINT_POSITION,
abi.encode(
config, initialLiquidity, MAX_SLIPPAGE_INCREASE, MAX_SLIPPAGE_INCREASE, address(this), ZERO_BYTES
config, initialLiquidity, MAX_SLIPPAGE_INCREASE, MAX_SLIPPAGE_INCREASE, Actions.MSG_SENDER, ZERO_BYTES
)
);
planner.add(
Expand All @@ -146,7 +146,7 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers {

// mint a position on range [-300, 300]
uint256 tokenId = lpm.nextTokenId();
mint(config, initialLiquidity, address(this), ZERO_BYTES);
mint(config, initialLiquidity, Actions.MSG_SENDER, ZERO_BYTES);
BalanceDelta delta = getLastDelta();

// we'll burn and mint a new position on [-60, 60]; calculate the liquidity units for the new range
Expand All @@ -173,7 +173,9 @@ contract ExecuteTest is Test, PosmTestSetup, LiquidityFuzzers {
);
planner.add(
Actions.MINT_POSITION,
abi.encode(newConfig, newLiquidity, MAX_SLIPPAGE_INCREASE, MAX_SLIPPAGE_INCREASE, address(this), ZERO_BYTES)
abi.encode(
newConfig, newLiquidity, MAX_SLIPPAGE_INCREASE, MAX_SLIPPAGE_INCREASE, Actions.MSG_SENDER, ZERO_BYTES
)
);
bytes memory calls = planner.finalizeModifyLiquidity(config.poolKey);

Expand Down
Loading

0 comments on commit 78821d3

Please sign in to comment.