Skip to content

Commit

Permalink
Add deadlines to uniswap v3 swaps with dex swapper uManager
Browse files Browse the repository at this point in the history
  • Loading branch information
crispymangoes committed Apr 3, 2024
1 parent d400d07 commit ddf67b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/micro-managers/DexSwapperUManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ contract DexSwapperUManager is Auth {

error DexSwapperUManager__Slippage();
error DexSwapperUManager__NewSlippageTooLarge();
error DexSwapperUManager__UniswapV3BadPathOrFees();

//============================== EVENTS ===============================

Expand Down Expand Up @@ -88,14 +89,16 @@ contract DexSwapperUManager is Auth {
* @param fees the fees to specify which pools to swap with
* @param amountIn the amount of path[0] to swap
* @param amountOutMinimum the minimum amount of path[path.length - 1] to get out from the swap
* @param deadline the swap deadline
*/
function swapWithUniswapV3(
bytes32[][] calldata manageProofs,
address[] calldata decodersAndSanitizers,
ERC20[] memory path,
uint24[] memory fees,
uint256 amountIn,
uint256 amountOutMinimum
uint256 amountOutMinimum,
uint256 deadline
) external requiresAuth {
address[] memory targets = new address[](2);
bytes[] memory targetData = new bytes[](2);
Expand All @@ -107,15 +110,15 @@ contract DexSwapperUManager is Auth {

// Build ExactInputParams.
{
if (path.length - 1 != fees.length) revert("Bad path/fees");
if (path.length - 1 != fees.length) revert DexSwapperUManager__UniswapV3BadPathOrFees();
bytes memory packedPath = abi.encodePacked(path[0]);
for (uint256 i; i < fees.length; ++i) {
packedPath = abi.encodePacked(packedPath, fees[i], path[i + 1]);
}
IUniswapV3Router.ExactInputParams memory params = IUniswapV3Router.ExactInputParams({
path: packedPath,
recipient: boringVault,
deadline: block.timestamp,
deadline: deadline,
amountIn: amountIn,
amountOutMinimum: amountOutMinimum
});
Expand Down
6 changes: 4 additions & 2 deletions test/micro-managers/DexSwapperUManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ contract DexSwapperUManagerTest is Test, MainnetAddresses {
fees[0] = 500;

// This swap is acceptable.
dexSwapperUManager.swapWithUniswapV3(manageProofs, decodersAndSanitizers, path, fees, 10e18, 0);
dexSwapperUManager.swapWithUniswapV3(manageProofs, decodersAndSanitizers, path, fees, 10e18, 0, block.timestamp);

// But if strategist tries to perform a high slippage swap it reverts.
vm.expectRevert(abi.encodeWithSelector(DexSwapperUManager.DexSwapperUManager__Slippage.selector));
dexSwapperUManager.swapWithUniswapV3(manageProofs, decodersAndSanitizers, path, fees, 9_990e18, 0);
dexSwapperUManager.swapWithUniswapV3(
manageProofs, decodersAndSanitizers, path, fees, 9_990e18, 0, block.timestamp
);

// uManager should also be able to revoke approvals to router.
manageLeafs = new ManageLeaf[](1);
Expand Down

0 comments on commit ddf67b3

Please sign in to comment.