-
Notifications
You must be signed in to change notification settings - Fork 226
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
restrict increase, decrease, and burn and v4 initialize pool call #416
Changes from 4 commits
c39570d
8cc587b
d02e36a
3ad3fef
3034164
6c5baa8
91745bc
6fffb82
db7c0a7
d80c241
44fd388
e5ad3bd
696d96d
ef8bb2f
4994b4a
6fb80be
ddc45c5
99c7506
5bc8881
b6f402a
0a0de10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ import {IAllowanceTransfer} from 'permit2/src/interfaces/IAllowanceTransfer.sol' | |
import {IERC721Permit} from '@uniswap/v3-periphery/contracts/interfaces/IERC721Permit.sol'; | ||
import {ActionConstants} from '@uniswap/v4-periphery/src/libraries/ActionConstants.sol'; | ||
import {CalldataDecoder} from '@uniswap/v4-periphery/src/libraries/CalldataDecoder.sol'; | ||
import {Actions} from '@uniswap/v4-periphery/src/libraries/Actions.sol'; | ||
import {PoolInitializer} from '@uniswap/v4-periphery/src/base/PoolInitializer.sol'; | ||
|
||
/// @title Decodes and Executes Commands | ||
/// @notice Called by the UniversalRouter contract to efficiently decode and execute a singular command | ||
|
@@ -26,6 +28,7 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V4SwapRout | |
error BalanceTooLow(); | ||
error InvalidAction(bytes4 action); | ||
error NotAuthorizedForToken(uint256 tokenId); | ||
error OnlyMintAllowed(); | ||
|
||
/// @notice Executes encoded commands along with provided inputs. | ||
/// @param commands A set of concatenated commands, each 1 byte in length | ||
|
@@ -254,7 +257,6 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V4SwapRout | |
if (!isValidAction(selector)) { | ||
revert InvalidAction(selector); | ||
} | ||
|
||
uint256 tokenId; | ||
assembly { | ||
// tokenId is always the first parameter in the valid actions | ||
|
@@ -269,9 +271,40 @@ abstract contract Dispatcher is Payments, V2SwapRouter, V3SwapRouter, V4SwapRout | |
} | ||
|
||
(success, output) = address(V3_POSITION_MANAGER).call(inputs); | ||
} else if (command == Commands.V4_INITIALIZE_POOL) { | ||
bytes4 selector; | ||
assembly { | ||
selector := calldataload(inputs.offset) | ||
} | ||
if (selector != PoolInitializer.initializePool.selector) { | ||
revert InvalidAction(selector); | ||
} | ||
(success, output) = address(V4_POSITION_MANAGER).call(inputs); | ||
hensha256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else if (command == Commands.V4_POSITION_CALL) { | ||
// should only call modifyLiquidities() to mint | ||
// do not permit or approve this contract over a v4 position or someone could use this command to decrease, burn, or transfer your position | ||
bytes4 selector; | ||
assembly { | ||
selector := calldataload(inputs.offset) | ||
} | ||
if (selector != V4_POSITION_MANAGER.modifyLiquidities.selector) { | ||
revert InvalidAction(selector); | ||
} | ||
|
||
bytes calldata slice = inputs[4:]; | ||
(bytes calldata actions,) = slice.toBytes(0).decodeActionsRouterParams(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh you never use the parameters its decoding... i feel like it would be possible instead (and more efficient) to try this... |
||
|
||
uint256 numActions = actions.length; | ||
|
||
for (uint256 actionIndex = 0; actionIndex < numActions; actionIndex++) { | ||
uint256 action = uint8(actions[actionIndex]); | ||
|
||
if ( | ||
action == Actions.INCREASE_LIQUIDITY || action == Actions.DECREASE_LIQUIDITY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this should all be in a helper function thats called like
and i'd argue we shouldve done the same for v3 but that can be separate PR to refactor |
||
|| action == Actions.BURN_POSITION | ||
) { | ||
revert OnlyMintAllowed(); | ||
} | ||
} | ||
(success, output) = address(V4_POSITION_MANAGER).call{value: address(this).balance}(inputs); | ||
} else { | ||
// placeholder area for commands 0x13-0x20 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just moved to the v3 migrator module