Skip to content

Commit

Permalink
chore: typo and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger committed Jul 10, 2024
1 parent dd3a7ea commit 8ed8199
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
48 changes: 24 additions & 24 deletions src/pool-cl/CLMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,80 +17,80 @@ contract CLMigrator is ICLMigrator, BaseMigrator {

function migrateFromV2(
V2PoolParams calldata v2PoolParams,
V4CLPoolParams calldata v4MintParams,
V4CLPoolParams calldata v4PoolParams,
uint256 extraAmount0,
uint256 extraAmount1
) external payable override {
(uint256 amount0Received, uint256 amount1Received) = withdrawLiquidityFromV2(v2PoolParams);

/// @notice if user mannually specify the price range, they might need to send extra token
batchAndNormalizeTokens(
v4MintParams.poolKey.currency0, v4MintParams.poolKey.currency1, extraAmount0, extraAmount1
v4PoolParams.poolKey.currency0, v4PoolParams.poolKey.currency1, extraAmount0, extraAmount1
);

uint256 amount0In = amount0Received + extraAmount0;
uint256 amount1In = amount1Received + extraAmount1;
INonfungiblePositionManager.MintParams memory mintParams = INonfungiblePositionManager.MintParams({
poolKey: v4MintParams.poolKey,
tickLower: v4MintParams.tickLower,
tickUpper: v4MintParams.tickUpper,
salt: v4MintParams.salt,
poolKey: v4PoolParams.poolKey,
tickLower: v4PoolParams.tickLower,
tickUpper: v4PoolParams.tickUpper,
salt: v4PoolParams.salt,
amount0Desired: amount0In,
amount1Desired: amount1In,
amount0Min: v4MintParams.amount0Min,
amount1Min: v4MintParams.amount1Min,
recipient: v4MintParams.recipient,
deadline: v4MintParams.deadline
amount0Min: v4PoolParams.amount0Min,
amount1Min: v4PoolParams.amount1Min,
recipient: v4PoolParams.recipient,
deadline: v4PoolParams.deadline
});
(,, uint256 amount0Consumed, uint256 amount1Consumed) = _addLiquidityToTargetPool(mintParams);

// refund if necessary, ETH is supported by CurrencyLib
unchecked {
if (amount0In > amount0Consumed) {
v4MintParams.poolKey.currency0.transfer(v4MintParams.recipient, amount0In - amount0Consumed);
v4PoolParams.poolKey.currency0.transfer(v4PoolParams.recipient, amount0In - amount0Consumed);
}
if (amount1In > amount1Consumed) {
v4MintParams.poolKey.currency1.transfer(v4MintParams.recipient, amount1In - amount1Consumed);
v4PoolParams.poolKey.currency1.transfer(v4PoolParams.recipient, amount1In - amount1Consumed);
}
}
}

function migrateFromV3(
V3PoolParams calldata v3PoolParams,
V4CLPoolParams calldata v4MintParams,
V4CLPoolParams calldata v4PoolParams,
uint256 extraAmount0,
uint256 extraAmount1
) external payable override {
(uint256 amount0Received, uint256 amount1Received) = withdrawLiquidityFromV3(v3PoolParams);

/// @notice if user mannually specify the price range, they need to send extra token
batchAndNormalizeTokens(
v4MintParams.poolKey.currency0, v4MintParams.poolKey.currency1, extraAmount0, extraAmount1
v4PoolParams.poolKey.currency0, v4PoolParams.poolKey.currency1, extraAmount0, extraAmount1
);

uint256 amount0In = amount0Received + extraAmount0;
uint256 amount1In = amount1Received + extraAmount1;
INonfungiblePositionManager.MintParams memory mintParams = INonfungiblePositionManager.MintParams({
poolKey: v4MintParams.poolKey,
tickLower: v4MintParams.tickLower,
tickUpper: v4MintParams.tickUpper,
salt: v4MintParams.salt,
poolKey: v4PoolParams.poolKey,
tickLower: v4PoolParams.tickLower,
tickUpper: v4PoolParams.tickUpper,
salt: v4PoolParams.salt,
amount0Desired: amount0In,
amount1Desired: amount1In,
amount0Min: v4MintParams.amount0Min,
amount1Min: v4MintParams.amount1Min,
recipient: v4MintParams.recipient,
deadline: v4MintParams.deadline
amount0Min: v4PoolParams.amount0Min,
amount1Min: v4PoolParams.amount1Min,
recipient: v4PoolParams.recipient,
deadline: v4PoolParams.deadline
});
(,, uint256 amount0Consumed, uint256 amount1Consumed) = _addLiquidityToTargetPool(mintParams);

// refund if necessary, ETH is supported by CurrencyLib
unchecked {
if (amount0In > amount0Consumed) {
v4MintParams.poolKey.currency0.transfer(v4MintParams.recipient, amount0In - amount0Consumed);
v4PoolParams.poolKey.currency0.transfer(v4PoolParams.recipient, amount0In - amount0Consumed);
}
if (amount1In > amount1Consumed) {
v4MintParams.poolKey.currency1.transfer(v4MintParams.recipient, amount1In - amount1Consumed);
v4PoolParams.poolKey.currency1.transfer(v4PoolParams.recipient, amount1In - amount1Consumed);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pool-cl/interfaces/ICLMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ interface ICLMigrator is IBaseMigrator {

function migrateFromV2(
V2PoolParams calldata v2PoolParams,
V4CLPoolParams calldata v4MintParams,
V4CLPoolParams calldata v4PoolParams,
// extra funds to be added
uint256 extraAmount0,
uint256 extraAmount1
) external payable;

function migrateFromV3(
V3PoolParams calldata v3PoolParams,
V4CLPoolParams calldata v4MintParams,
V4CLPoolParams calldata v4PoolParams,
// extra funds to be added
uint256 extraAmount0,
uint256 extraAmount1
Expand Down
6 changes: 2 additions & 4 deletions test/pool-cl/migrator/CLMigratorFromV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ abstract contract CLMigratorFromV3 is OldVersionHelper, GasSnapshot {
}

function testMigrateFromV3AddExtraAmountThroughWETH() public {
// 1. mint some liquidity to the v2 pair
// 1. mint some liquidity to the v3 pool
_mintV3Liquidity(address(weth), address(token0));
assertEq(v3Nfpm.ownerOf(1), address(this));
Expand Down Expand Up @@ -487,7 +486,7 @@ abstract contract CLMigratorFromV3 is OldVersionHelper, GasSnapshot {

weth.approve(address(migrator), 20 ether);
IERC20(address(token0)).approve(address(migrator), 20 ether);
// 4. migrate from v2 to v4, not sending ETH denotes pay by WETH
// 4. migrate from v3 to v4, not sending ETH denotes pay by WETH
migrator.migrateFromV3(v3PoolParams, v4MintParams, 20 ether, 20 ether);

// necessary checks
Expand Down Expand Up @@ -664,7 +663,7 @@ abstract contract CLMigratorFromV3 is OldVersionHelper, GasSnapshot {
uint256 balance0Before = token0.balanceOf(address(this));
uint256 balance1Before = token1.balanceOf(address(this));

// 4. migrate from v2 to v4
// 4. migrate from v3 to v4
migrator.migrateFromV3(v3PoolParams, v4MintParams, 0, 0);

// necessary checks
Expand All @@ -675,7 +674,6 @@ abstract contract CLMigratorFromV3 is OldVersionHelper, GasSnapshot {
// WETH balance unchanged
assertEq(weth.balanceOf(address(this)), 100 ether);

// v2 pair should be burned already
// v3 liqudity should be 0
(,,,,,,, uint128 liquidityFromV3After,,,,) = v3Nfpm.positions(1);
assertEq(liquidityFromV3After, 0);
Expand Down

0 comments on commit 8ed8199

Please sign in to comment.