Skip to content

Commit

Permalink
feat: Remove deadline in AddLiquidityParams and RemoveLiquidityParams
Browse files Browse the repository at this point in the history
  • Loading branch information
ChefSnoopy committed Aug 7, 2024
1 parent 1234db4 commit 3d14b86
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180350
180120
Original file line number Diff line number Diff line change
@@ -1 +1 @@
634518
634289
Original file line number Diff line number Diff line change
@@ -1 +1 @@
900791
900548
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1265997
1265777
Original file line number Diff line number Diff line change
@@ -1 +1 @@
913724
913480
Original file line number Diff line number Diff line change
@@ -1 +1 @@
900791
900549
Original file line number Diff line number Diff line change
@@ -1 +1 @@
222788
222600
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212283
212096
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146429
146273
Original file line number Diff line number Diff line change
@@ -1 +1 @@
212282
212096
Original file line number Diff line number Diff line change
@@ -1 +1 @@
237793
237562
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1017338
1017192
Original file line number Diff line number Diff line change
@@ -1 +1 @@
977526
977380
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1021675
1021528
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1096266
1096118
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1056506
1056359
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1094035
1093888
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1017350
1017204
Original file line number Diff line number Diff line change
@@ -1 +1 @@
977538
977392
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1021672
1021525
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1094248
1094100
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1054488
1054341
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1092013
1091866
17 changes: 9 additions & 8 deletions src/pool-bin/BinMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ contract BinMigrator is IBinMigrator, BaseMigrator {
deltaIds: v4PoolParams.deltaIds,
distributionX: v4PoolParams.distributionX,
distributionY: v4PoolParams.distributionY,
to: v4PoolParams.to,
deadline: v4PoolParams.deadline
to: v4PoolParams.to
});
(uint256 amount0Consumed, uint256 amount1Consumed,,) = _addLiquidityToTargetPool(addLiquidityParams);
(uint256 amount0Consumed, uint256 amount1Consumed,,) =
_addLiquidityToTargetPool(addLiquidityParams, v4PoolParams.deadline);

// refund if necessary, ETH is supported by CurrencyLib
unchecked {
Expand Down Expand Up @@ -94,10 +94,10 @@ contract BinMigrator is IBinMigrator, BaseMigrator {
deltaIds: v4PoolParams.deltaIds,
distributionX: v4PoolParams.distributionX,
distributionY: v4PoolParams.distributionY,
to: v4PoolParams.to,
deadline: v4PoolParams.deadline
to: v4PoolParams.to
});
(uint256 amount0Consumed, uint256 amount1Consumed,,) = _addLiquidityToTargetPool(addLiquidityParams);
(uint256 amount0Consumed, uint256 amount1Consumed,,) =
_addLiquidityToTargetPool(addLiquidityParams, v4PoolParams.deadline);

// refund if necessary, ETH is supported by CurrencyLib
unchecked {
Expand All @@ -112,11 +112,12 @@ contract BinMigrator is IBinMigrator, BaseMigrator {

/// @dev adding liquidity to target bin pool, collect surplus ETH if necessary
/// @param params bin position manager add liquidity params
/// @param deadline the deadline of the transaction
/// @return amount0Consumed the actual amount of token0 consumed
/// @return amount1Consumed the actual amount of token1 consumed
/// @return tokenIds the list of the id of the position token minted
/// @return liquidityMinted the list of the amount of the position token minted
function _addLiquidityToTargetPool(IBinFungiblePositionManager.AddLiquidityParams memory params)
function _addLiquidityToTargetPool(IBinFungiblePositionManager.AddLiquidityParams memory params, uint256 deadline)
internal
returns (
uint128 amount0Consumed,
Expand All @@ -142,7 +143,7 @@ contract BinMigrator is IBinMigrator, BaseMigrator {

(amount0Consumed, amount1Consumed, tokenIds, liquidityMinted) = abi.decode(
binFungiblePositionManager.modifyLiquidities{value: nativePair ? params.amount0 : 0}(
abi.encode(lockData), params.deadline
abi.encode(lockData), deadline
)[0],
(uint128, uint128, uint256[], uint256[])
);
Expand Down
4 changes: 0 additions & 4 deletions src/pool-bin/interfaces/IBinFungiblePositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ interface IBinFungiblePositionManager is IBinFungibleToken, IPeripheryPayments,
/// - distributionX: Distribution of tokenX with sum(distributionX) = 100e18 (100%) or 0 (0%)
/// - distributionY: Distribution of tokenY with sum(distributionY) = 100e18 (100%) or 0 (0%)
/// - to: Address of recipient
/// - deadline: Deadline of transaction
struct AddLiquidityParams {
PoolKey poolKey;
uint128 amount0;
Expand All @@ -49,7 +48,6 @@ interface IBinFungiblePositionManager is IBinFungibleToken, IPeripheryPayments,
uint256[] distributionX;
uint256[] distributionY;
address to;
uint256 deadline;
}

/// @notice RemoveLiquidityParams
Expand All @@ -59,7 +57,6 @@ interface IBinFungiblePositionManager is IBinFungibleToken, IPeripheryPayments,
/// - amounts: List of share amount to remove for each bin
/// - from: Address of NFT holder to burn the NFT
/// - to: Address of recipient for amount0 and amount1 recieved
/// - deadline: Deadline of transaction
struct RemoveLiquidityParams {
PoolKey poolKey;
uint128 amount0Min;
Expand All @@ -68,7 +65,6 @@ interface IBinFungiblePositionManager is IBinFungibleToken, IPeripheryPayments,
uint256[] amounts;
address from;
address to;
uint256 deadline;
}

enum CallbackDataType {
Expand Down
6 changes: 2 additions & 4 deletions test/pool-bin/BinFungiblePositionManager_AddLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract BinFungiblePositionManager_AddLiquidityTest is Test, GasSnapshot, Liqui
// generate modifyLiquidities data
bytes memory payload = _getModifyLiquiditiesAddPayload(params, false);

bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, params.deadline);
bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, block.timestamp + 1);

return abi.decode(returnDataArrayBytes[0], (uint128, uint128, uint256[], uint256[]));
}
Expand All @@ -119,7 +119,6 @@ contract BinFungiblePositionManager_AddLiquidityTest is Test, GasSnapshot, Liqui
vm.warp(1000); // set block.timestamp
IBinFungiblePositionManager.AddLiquidityParams memory params =
_getAddParams(key1, binIds, 1 ether, 1 ether, activeId, alice);
params.deadline = 900; // set deadline before block.timestamp

bytes memory payload = _getModifyLiquiditiesAddPayload(params, false);
vm.expectRevert(abi.encodeWithSelector(PeripheryValidation.TransactionTooOld.selector));
Expand Down Expand Up @@ -668,8 +667,7 @@ contract BinFungiblePositionManager_AddLiquidityTest is Test, GasSnapshot, Liqui
deltaIds: convertToRelative(binIds, activeId),
distributionX: distribX,
distributionY: distribY,
to: alice,
deadline: block.timestamp + 600
to: alice
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ contract BinFungiblePositionManager_RemoveLiquidityTest is Test, GasSnapshot, Li
// generate modifyLiquidities data
bytes memory payload = _getModifyLiquiditiesAddPayload(params, false);

bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, params.deadline);
bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, block.timestamp + 1);

return abi.decode(returnDataArrayBytes[0], (uint128, uint128, uint256[], uint256[]));
}
Expand All @@ -118,7 +118,7 @@ contract BinFungiblePositionManager_RemoveLiquidityTest is Test, GasSnapshot, Li
// generate modifyLiquidities data
bytes memory payload = _getModifyLiquiditiesRemovePayload(params, false);

bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, params.deadline);
bytes[] memory returnDataArrayBytes = binFungiblePositionManager.modifyLiquidities(payload, block.timestamp + 1);

return abi.decode(returnDataArrayBytes[0], (uint128, uint128, uint256[]));
}
Expand All @@ -136,7 +136,6 @@ contract BinFungiblePositionManager_RemoveLiquidityTest is Test, GasSnapshot, Li
// Remove liquidity
vm.warp(1000);
removeParams = _getRemoveParams(key1, binIds, liquidityMinted);
removeParams.deadline = 900; // set deadline before block.timestamp

bytes memory payload = _getModifyLiquiditiesRemovePayload(removeParams, false);
vm.expectRevert(abi.encodeWithSelector(PeripheryValidation.TransactionTooOld.selector));
Expand Down Expand Up @@ -618,8 +617,7 @@ contract BinFungiblePositionManager_RemoveLiquidityTest is Test, GasSnapshot, Li
ids: ids,
amounts: amounts,
from: alice,
to: alice,
deadline: block.timestamp + 600
to: alice
});
}

Expand Down
5 changes: 2 additions & 3 deletions test/pool-bin/helpers/LiquidityParamsHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract LiquidityParamsHelper {
uint128 amountY,
uint24 activeId,
address recipient
) internal view returns (IBinFungiblePositionManager.AddLiquidityParams memory params) {
) internal pure returns (IBinFungiblePositionManager.AddLiquidityParams memory params) {
uint256 totalBins = binIds.length;

uint8 nbBinX; // num of bins to the right
Expand Down Expand Up @@ -94,8 +94,7 @@ contract LiquidityParamsHelper {
deltaIds: convertToRelative(binIds, activeId),
distributionX: distribX,
distributionY: distribY,
to: recipient,
deadline: block.timestamp + 600
to: recipient
});
}
}
18 changes: 9 additions & 9 deletions test/pool-bin/migrator/BinMigratorFromV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

// 3. multicall, combine initialize and migrateFromV2
Expand Down Expand Up @@ -212,7 +212,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

// 3. multicall, combine initialize and migrateFromV2
Expand Down Expand Up @@ -269,7 +269,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

// 4. migrateFromV2
Expand Down Expand Up @@ -354,7 +354,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

// 4. migrate from v2 to v4
Expand Down Expand Up @@ -438,7 +438,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

uint256 balance0Before = address(this).balance;
Expand Down Expand Up @@ -530,7 +530,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

uint256 balance0Before = address(this).balance;
Expand Down Expand Up @@ -640,7 +640,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: distributionX,
distributionY: distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

uint256 balance0Before = address(this).balance;
Expand Down Expand Up @@ -744,7 +744,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: distributionX,
distributionY: distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

uint256 balance0Before = token0.balanceOf(address(this));
Expand Down Expand Up @@ -850,7 +850,7 @@ abstract contract BinMigratorFromV2 is OldVersionHelper, LiquidityParamsHelper,
distributionX: params.distributionX,
distributionY: params.distributionY,
to: params.to,
deadline: params.deadline
deadline: block.timestamp + 1
});

// 3. multicall, combine permit, initialize and migrateFromV2
Expand Down
Loading

0 comments on commit 3d14b86

Please sign in to comment.