Skip to content

Commit

Permalink
refactor: restructure & renaming accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed Jul 10, 2024
1 parent 805fd58 commit 42daa01
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/pool-bin/BinMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,7 @@ contract BinMigrator is IBinMigrator, BaseMigrator {
uint256 extraAmount0,
uint256 extraAmount1
) external payable override {
IV3NonfungiblePositionManager.DecreaseLiquidityParams memory decreaseLiquidityParams =
IV3NonfungiblePositionManager.DecreaseLiquidityParams({
tokenId: v3PoolParams.tokenId,
liquidity: v3PoolParams.liquidity,
amount0Min: v3PoolParams.amount0Min,
amount1Min: v3PoolParams.amount1Min,
deadline: v4MintParams.deadline
});
(uint256 amount0Received, uint256 amount1Received) =
withdrawLiquidityFromV3(v3PoolParams.nfp, decreaseLiquidityParams, v3PoolParams.collectFee);
(uint256 amount0Received, uint256 amount1Received) = withdrawLiquidityFromV3(v3PoolParams);

/// @notice if user mannually specify the price range, they need to send extra token
batchAndNormalizeTokens(
Expand Down Expand Up @@ -113,7 +104,12 @@ contract BinMigrator is IBinMigrator, BaseMigrator {

function _addLiquidityToTargetPool(IBinFungiblePositionManager.AddLiquidityParams memory params)
internal
returns (uint128 amount0, uint128 amount1, uint256[] memory tokenIds, uint256[] memory liquidityMinted)
returns (
uint128 amount0Consumed,
uint128 amount1Consumed,
uint256[] memory tokenIds,
uint256[] memory liquidityMinted
)
{
/// @dev currency1 cant be NATIVE
bool nativePair = params.poolKey.currency0.isNative();
Expand All @@ -122,9 +118,11 @@ contract BinMigrator is IBinMigrator, BaseMigrator {
}
approveMaxIfNeeded(params.poolKey.currency1, address(binFungiblePositionManager), params.amount1);

(amount0, amount1, tokenIds, liquidityMinted) =
(amount0Consumed, amount1Consumed, tokenIds, liquidityMinted) =
binFungiblePositionManager.addLiquidity{value: nativePair ? params.amount0 : 0}(params);
if (nativePair) {

// receive surplus ETH from positionManager
if (nativePair && params.amount0 > amount0Consumed) {
binFungiblePositionManager.refundETH();
}
}
Expand Down

0 comments on commit 42daa01

Please sign in to comment.