diff --git a/contracts/interfaces/INTokenUniswapV3.sol b/contracts/interfaces/INTokenUniswapV3.sol index ddb633ad7..bf8a143e9 100644 --- a/contracts/interfaces/INTokenUniswapV3.sol +++ b/contracts/interfaces/INTokenUniswapV3.sol @@ -18,6 +18,7 @@ interface INTokenUniswapV3 { uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, - bool receiveEthAsWeth + bool receiveEthAsWeth, + uint256 deadline ) external; } diff --git a/contracts/interfaces/IPoolCore.sol b/contracts/interfaces/IPoolCore.sol index 939b5a525..4df26ad9f 100644 --- a/contracts/interfaces/IPoolCore.sol +++ b/contracts/interfaces/IPoolCore.sol @@ -315,7 +315,8 @@ interface IPoolCore { uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, - bool receiveEthAsWeth + bool receiveEthAsWeth, + uint256 deadline ) external; /** diff --git a/contracts/protocol/libraries/logic/SupplyLogic.sol b/contracts/protocol/libraries/logic/SupplyLogic.sol index c062ba058..7689cf34f 100644 --- a/contracts/protocol/libraries/logic/SupplyLogic.sol +++ b/contracts/protocol/libraries/logic/SupplyLogic.sol @@ -440,7 +440,8 @@ library SupplyLogic { params.liquidityDecrease, params.amount0Min, params.amount1Min, - params.receiveEthAsWeth + params.receiveEthAsWeth, + params.deadline ); bool isUsedAsCollateral = ICollateralizableERC721( diff --git a/contracts/protocol/libraries/types/DataTypes.sol b/contracts/protocol/libraries/types/DataTypes.sol index 63b825d9f..1d4f285b3 100644 --- a/contracts/protocol/libraries/types/DataTypes.sol +++ b/contracts/protocol/libraries/types/DataTypes.sol @@ -185,6 +185,7 @@ library DataTypes { uint256 amount0Min; uint256 amount1Min; bool receiveEthAsWeth; + uint256 deadline; address oracle; } diff --git a/contracts/protocol/pool/PoolCore.sol b/contracts/protocol/pool/PoolCore.sol index 987793456..e8c7abb08 100644 --- a/contracts/protocol/pool/PoolCore.sol +++ b/contracts/protocol/pool/PoolCore.sol @@ -240,7 +240,8 @@ contract PoolCore is uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, - bool receiveEthAsWeth + bool receiveEthAsWeth, + uint256 deadline ) external virtual override nonReentrant { DataTypes.PoolStorage storage ps = poolStorage(); @@ -258,6 +259,7 @@ contract PoolCore is amount0Min: amount0Min, amount1Min: amount1Min, receiveEthAsWeth: receiveEthAsWeth, + deadline: deadline, oracle: ADDRESSES_PROVIDER.getPriceOracle() }) ); diff --git a/contracts/protocol/tokenization/NTokenUniswapV3.sol b/contracts/protocol/tokenization/NTokenUniswapV3.sol index cd4f52dad..cb3d91e2b 100644 --- a/contracts/protocol/tokenization/NTokenUniswapV3.sol +++ b/contracts/protocol/tokenization/NTokenUniswapV3.sol @@ -54,7 +54,8 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 { uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, - bool receiveEthAsWeth + bool receiveEthAsWeth, + uint256 deadline ) internal returns (uint256 amount0, uint256 amount1) { if (liquidityDecrease > 0) { // amount0Min and amount1Min are price slippage checks @@ -66,7 +67,7 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 { liquidity: liquidityDecrease, amount0Min: amount0Min, amount1Min: amount1Min, - deadline: block.timestamp + deadline: deadline }); INonfungiblePositionManager(_underlyingAsset).decreaseLiquidity( @@ -105,14 +106,14 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 { .collect(collectParams); if (receiveEthAsWeth) { - uint256 balanceWeth = IERC20(weth).balanceOf(address(this)); - if (balanceWeth > 0) { - IWETH(weth).withdraw(balanceWeth); - _safeTransferETH(user, balanceWeth); + uint256 balanceToken = IERC20(weth).balanceOf(address(this)); + if (balanceToken > 0) { + IWETH(weth).withdraw(balanceToken); + _safeTransferETH(user, balanceToken); } address pairToken = (token0 == weth) ? token1 : token0; - uint256 balanceToken = IERC20(pairToken).balanceOf(address(this)); + balanceToken = IERC20(pairToken).balanceOf(address(this)); if (balanceToken > 0) { IERC20(pairToken).safeTransfer(user, balanceToken); } @@ -126,7 +127,8 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 { uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, - bool receiveEthAsWeth + bool receiveEthAsWeth, + uint256 deadline ) external onlyPool nonReentrant { require(user == ownerOf(tokenId), Errors.NOT_THE_OWNER); @@ -137,7 +139,8 @@ contract NTokenUniswapV3 is NToken, INTokenUniswapV3 { liquidityDecrease, amount0Min, amount1Min, - receiveEthAsWeth + receiveEthAsWeth, + deadline ); } diff --git a/test/_uniswapv3_pool_operation.spec.ts b/test/_uniswapv3_pool_operation.spec.ts index 92430dc44..afe94a916 100644 --- a/test/_uniswapv3_pool_operation.spec.ts +++ b/test/_uniswapv3_pool_operation.spec.ts @@ -14,7 +14,7 @@ import {encodeSqrtRatioX96} from "@uniswap/v3-sdk"; import {getUniswapV3OracleWrapper} from "../helpers/contracts-getters"; import {ProtocolErrors} from "../helpers/types"; import {snapshot} from "./helpers/snapshot-manager"; -import {loadFixture} from "@nomicfoundation/hardhat-network-helpers"; +import {loadFixture, time} from "@nomicfoundation/hardhat-network-helpers"; import {testEnvFixture} from "./helpers/setup-env"; describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transfer test", () => { @@ -453,6 +453,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -485,6 +486,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -517,6 +519,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -549,6 +552,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -573,6 +577,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -694,6 +699,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } diff --git a/test/_uniswapv3_position_control.spec.ts b/test/_uniswapv3_position_control.spec.ts index b84badfae..4ebdf2ca1 100644 --- a/test/_uniswapv3_position_control.spec.ts +++ b/test/_uniswapv3_position_control.spec.ts @@ -13,7 +13,7 @@ import { } from "./helpers/uniswapv3-helper"; import {encodeSqrtRatioX96} from "@uniswap/v3-sdk"; import {DRE} from "../helpers/misc-utils"; -import {loadFixture} from "@nomicfoundation/hardhat-network-helpers"; +import {loadFixture, time} from "@nomicfoundation/hardhat-network-helpers"; import {testEnvFixture} from "./helpers/setup-env"; describe("Uniswap V3 NFT position control", () => { @@ -218,6 +218,7 @@ describe("Uniswap V3 NFT position control", () => { 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -259,6 +260,7 @@ describe("Uniswap V3 NFT position control", () => { 0, 0, true, + (await time.latest()) + 100, { gasLimit: 12_450_000, } @@ -314,6 +316,7 @@ describe("Uniswap V3 NFT position control", () => { 0, 0, false, + (await time.latest()) + 100, { gasLimit: 12_450_000, }