-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(universal-router-sdk): fix migration encoding (#156)
Co-authored-by: Alice Henshaw <[email protected]> Co-authored-by: Alice <[email protected]>
- Loading branch information
1 parent
f591a5e
commit 089431e
Showing
10 changed files
with
353 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
sdks/universal-router-sdk/test/forge/MigratorCallParameters.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {Test, stdJson} from "forge-std/Test.sol"; | ||
import {ERC20} from "solmate/src/tokens/ERC20.sol"; | ||
import {UniversalRouter} from "universal-router/UniversalRouter.sol"; | ||
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol"; | ||
import {DeployRouter} from "./utils/DeployRouter.sol"; | ||
import {MethodParameters, Interop} from "./utils/Interop.sol"; | ||
import {INonfungiblePositionManager} from "v3-periphery/interfaces/INonfungiblePositionManager.sol"; | ||
|
||
contract MigratorCallParametersTest is Test, Interop, DeployRouter { | ||
using stdJson for string; | ||
|
||
// starting eth balance | ||
uint256 constant BALANCE = 10 ether; | ||
|
||
function setUp() public { | ||
fromPrivateKey = 0x1234; | ||
from = vm.addr(fromPrivateKey); | ||
string memory root = vm.projectRoot(); | ||
json = vm.readFile(string.concat(root, "/test/forge/interop.json")); | ||
|
||
vm.createSelectFork(vm.envString("FORK_URL"), 16075500); | ||
deployV4Contracts(); | ||
initializeV4Pools(); | ||
vm.startPrank(from); | ||
deployRouter(); | ||
vm.deal(from, BALANCE); | ||
} | ||
|
||
function test_migrate_withoutPermit() public { | ||
MethodParameters memory params = readFixture(json, "._MIGRATE_WITHOUT_PERMIT"); | ||
|
||
// add the position to v3 so we have something to migrate | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 0); | ||
// USDC < WETH | ||
mintV3Position(address(USDC), address(WETH), 3000, 2500e6, 1e18); | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 1); | ||
|
||
// approve the UniversalRouter to access the position (instead of permit) | ||
vm.prank(from); | ||
INonfungiblePositionManager(V3_POSITION_MANAGER).setApprovalForAll(MAINNET_ROUTER, true); | ||
|
||
assertEq(params.value, 0); | ||
vm.prank(from); | ||
(bool success,) = address(router).call(params.data); | ||
require(success, "call failed"); | ||
|
||
// all funds were swept out of contracts | ||
assertEq(USDC.balanceOf(MAINNET_ROUTER), 0); | ||
assertEq(WETH.balanceOf(MAINNET_ROUTER), 0); | ||
assertEq(USDC.balanceOf(address(v4PositionManager)), 0); | ||
assertEq(WETH.balanceOf(address(v4PositionManager)), 0); | ||
|
||
// old position burned, new position minted | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 0, "V3 NOT BURNT"); | ||
assertEq(v4PositionManager.balanceOf(RECIPIENT), 1, "V4 NOT MINTED"); | ||
} | ||
|
||
function test_migrate_withPermit() public { | ||
MethodParameters memory params = readFixture(json, "._MIGRATE_WITH_PERMIT"); | ||
|
||
// add the position to v3 so we have something to migrate | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 0); | ||
// USDC < WETH | ||
mintV3Position(address(USDC), address(WETH), 3000, 2500e6, 1e18); | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 1); | ||
|
||
assertEq(params.value, 0); | ||
vm.prank(from); | ||
(bool success,) = address(router).call(params.data); | ||
require(success, "call failed"); | ||
|
||
// all funds were swept out of contracts | ||
assertEq(USDC.balanceOf(MAINNET_ROUTER), 0); | ||
assertEq(WETH.balanceOf(MAINNET_ROUTER), 0); | ||
assertEq(USDC.balanceOf(address(v4PositionManager)), 0); | ||
assertEq(WETH.balanceOf(address(v4PositionManager)), 0); | ||
|
||
// old position burned, new position minted | ||
assertEq(INonfungiblePositionManager(V3_POSITION_MANAGER).balanceOf(from), 0, "V3 NOT BURNT"); | ||
assertEq(v4PositionManager.balanceOf(RECIPIENT), 1, "V4 NOT MINTED"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.