Skip to content

Commit

Permalink
chore: add deadline for LP operation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujia6139 committed Sep 27, 2023
1 parent 33328c8 commit 498f856
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 14 deletions.
4 changes: 3 additions & 1 deletion contracts/interfaces/INTokenLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ interface INTokenLiquidity {
* @param amountAdd1 The amount to add of token1
* @param amount0Min The minimum amount to add of token0
* @param amount1Min The minimum amount to add of token1
* @param deadline The time by which the transaction must be included
*/
function increaseLiquidity(
address payer,
uint256 tokenId,
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) external payable;
}
4 changes: 3 additions & 1 deletion contracts/interfaces/IPoolLpOperation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ interface IPoolLpOperation {
* @param amountAdd1 The amount to add of token1
* @param amount0Min The minimum amount to add of token0
* @param amount1Min The minimum amount to add of token1
* @param deadline The time by which the transaction must be included
*/
function increaseLiquidity(
address asset,
uint256 tokenId,
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) external payable;

/**
Expand Down
1 change: 1 addition & 0 deletions contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ library DataTypes {
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}

struct AssetInfo {
Expand Down
17 changes: 13 additions & 4 deletions contracts/protocol/pool/PoolLpOperation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ contract PoolLpOperation is
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) external payable virtual override nonReentrant {
DataTypes.PoolStorage storage ps = poolStorage();

Expand All @@ -109,7 +110,15 @@ contract PoolLpOperation is

INTokenLiquidity(reserveCache.xTokenAddress).increaseLiquidity{
value: msg.value
}(msg.sender, tokenId, amountAdd0, amountAdd1, amount0Min, amount1Min);
}(
msg.sender,
tokenId,
amountAdd0,
amountAdd1,
amount0Min,
amount1Min,
deadline
);
}

/// @inheritdoc IPoolLpOperation
Expand Down Expand Up @@ -256,7 +265,7 @@ contract PoolLpOperation is
amount0Min: mintParams.amount0Min,
amount1Min: mintParams.amount1Min,
recipient: reserveCache.xTokenAddress,
deadline: block.timestamp
deadline: mintParams.deadline
});
(newTokenId, , , ) = INonfungiblePositionManager(
assetInfo.asset
Expand All @@ -275,7 +284,7 @@ contract PoolLpOperation is
yLim: mintParams.amount1Desired.toUint128(),
amountXMin: mintParams.amount0Min.toUint128(),
amountYMin: mintParams.amount1Min.toUint128(),
deadline: block.timestamp
deadline: mintParams.deadline
});
(newTokenId, , , ) = ILiquidityManager(assetInfo.asset).mint(
params
Expand Down
5 changes: 3 additions & 2 deletions contracts/protocol/tokenization/NTokenIzumi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ contract NTokenIzumi is NTokenLiquidity {
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) internal override returns (uint256 amount0, uint256 amount1) {
ILiquidityManager POSITION_MANAGER = ILiquidityManager(positionManager);

Expand All @@ -82,7 +83,7 @@ contract NTokenIzumi is NTokenLiquidity {
yLim: amountAdd1.toUint128(),
amountXMin: amount0Min.toUint128(),
amountYMin: amount1Min.toUint128(),
deadline: block.timestamp
deadline: deadline
});

(, amount0, amount1) = POSITION_MANAGER.addLiquidity{value: msg.value}(
Expand Down
7 changes: 5 additions & 2 deletions contracts/protocol/tokenization/NTokenLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ abstract contract NTokenLiquidity is NToken, INTokenLiquidity {
uint256,
uint256,
uint256,
uint256,
uint256
) internal virtual returns (uint256, uint256) {
return (0, 0);
Expand Down Expand Up @@ -135,7 +136,8 @@ abstract contract NTokenLiquidity is NToken, INTokenLiquidity {
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) external payable onlyPool nonReentrant {
address positionManager = _ERC721Data.underlyingAsset;

Expand Down Expand Up @@ -172,7 +174,8 @@ abstract contract NTokenLiquidity is NToken, INTokenLiquidity {
amountAdd0,
amountAdd1,
amount0Min,
amount1Min
amount1Min,
deadline
);

// refund unused tokens
Expand Down
5 changes: 3 additions & 2 deletions contracts/protocol/tokenization/NTokenUniswapV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ contract NTokenUniswapV3 is NTokenLiquidity {
uint256 amountAdd0,
uint256 amountAdd1,
uint256 amount0Min,
uint256 amount1Min
uint256 amount1Min,
uint256 deadline
) internal override returns (uint256 amount0, uint256 amount1) {
INonfungiblePositionManager.IncreaseLiquidityParams
memory params = INonfungiblePositionManager
Expand All @@ -81,7 +82,7 @@ contract NTokenUniswapV3 is NTokenLiquidity {
amount1Desired: amountAdd1,
amount0Min: amount0Min,
amount1Min: amount1Min,
deadline: block.timestamp
deadline: deadline
});

(, amount0, amount1) = INonfungiblePositionManager(positionManager)
Expand Down
10 changes: 10 additions & 0 deletions test/_pool_lp_operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("1"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -314,6 +315,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("25"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -387,6 +389,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("25"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -450,6 +453,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("5"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -525,6 +529,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("5"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -592,6 +597,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("1"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -666,6 +672,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("25"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -740,6 +747,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("25"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -804,6 +812,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("5"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down Expand Up @@ -880,6 +889,7 @@ describe("Pool LP Operation", () => {
amount1Desired: parseEther("5"),
amount0Min: 0,
amount1Min: 0,
deadline: 2659537628,
}
)
);
Expand Down
5 changes: 5 additions & 0 deletions test/_uniswapv3_pool_operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.RESERVE_INACTIVE);
Expand Down Expand Up @@ -521,6 +522,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down Expand Up @@ -570,6 +572,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.RESERVE_PAUSED);
Expand Down Expand Up @@ -619,6 +622,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down Expand Up @@ -659,6 +663,7 @@ describe("Uniswap V3 NFT supply, withdraw, setCollateral, liquidation and transf
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.NOT_THE_OWNER);
Expand Down
6 changes: 5 additions & 1 deletion test/_uniswapv3_position_control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ describe("Uniswap V3 NFT position control", () => {
userDaiAmount,
userWethAmount,
0,
0
0,
2659537628
)
);

Expand Down Expand Up @@ -157,6 +158,7 @@ describe("Uniswap V3 NFT position control", () => {
userWethAmount,
0,
0,
2659537628,
{
gasLimit: 12_450_000,
value: userWethAmount,
Expand Down Expand Up @@ -230,6 +232,7 @@ describe("Uniswap V3 NFT position control", () => {
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down Expand Up @@ -319,6 +322,7 @@ describe("Uniswap V3 NFT position control", () => {
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down
9 changes: 9 additions & 0 deletions test/izumi_pool_operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
userWethAmount,
0,
0,
2659537628,
{
gasLimit: 12_450_000,
}
Expand Down Expand Up @@ -487,6 +488,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
userWethAmount,
0,
0,
2659537628,
{
gasLimit: 12_450_000,
}
Expand Down Expand Up @@ -524,6 +526,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
userWethAmount,
0,
0,
2659537628,
{
gasLimit: 12_450_000,
}
Expand Down Expand Up @@ -563,6 +566,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
userWethAmount,
0,
0,
2659537628,
{
gasLimit: 12_450_000,
}
Expand Down Expand Up @@ -617,6 +621,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.RESERVE_INACTIVE);
Expand Down Expand Up @@ -665,6 +670,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down Expand Up @@ -713,6 +719,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.RESERVE_PAUSED);
Expand Down Expand Up @@ -761,6 +768,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
);
Expand Down Expand Up @@ -801,6 +809,7 @@ describe("IZUMI LP NFT supply, withdraw, setCollateral, liquidation and transfer
amount1Desired: 0,
amount0Min: 0,
amount1Min: 0,
deadline: 0,
}
)
).to.be.revertedWith(ProtocolErrors.NOT_THE_OWNER);
Expand Down
Loading

0 comments on commit 498f856

Please sign in to comment.