WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e8835e6

Browse files
committed
feat: migrateTo
1 parent 643594d commit e8835e6

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/PolygonMigration.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ contract PolygonMigration is Ownable2StepUpgradeable, IPolygonMigration {
5151
polygon.safeTransfer(msg.sender, amount);
5252
}
5353

54+
/// @inheritdoc IPolygonMigration
55+
function migrateTo(address recipient, uint256 amount) external {
56+
emit Migrated(msg.sender, amount);
57+
58+
matic.safeTransferFrom(msg.sender, address(this), amount);
59+
polygon.safeTransfer(recipient, amount);
60+
}
61+
5462
/// @inheritdoc IPolygonMigration
5563
function unmigrate(uint256 amount) external onlyUnmigrationUnlocked {
5664
emit Unmigrated(msg.sender, msg.sender, amount);

src/interfaces/IPolygonMigration.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ interface IPolygonMigration {
3838
/// @dev the function does not do any validation since the migration is a one-way process
3939
function migrate(uint256 amount) external;
4040

41+
/// @notice this function allows for migrating MATIC tokens to POL tokens to an account
42+
/// @param recipient address to receive POL tokens
43+
/// @param amount amount of MATIC to migrate
44+
/// @dev the function does not do any validation since the migration is a one-way process
45+
function migrateTo(address recipient, uint256 amount) external;
46+
4147
/// @notice this function allows for unmigrating from POL tokens to MATIC tokens
4248
/// @param amount amount of POL to migrate
4349
/// @dev the function can only be called when unmigration is unlocked (lock updatable by governance)

test/PolygonMigration.t.sol

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ contract PolygonMigrationTest is Test {
2020
address public stakeManager;
2121
address public emissionManager;
2222

23+
uint256 mainnetFork;
24+
2325
function setUp() external {
26+
mainnetFork = vm.createFork(vm.rpcUrl("mainnet"), 20678429);
27+
vm.selectFork(mainnetFork);
28+
2429
treasury = makeAddr("treasury");
2530
governance = makeAddr("governance");
2631
stakeManager = makeAddr("stakeManager");
@@ -86,6 +91,27 @@ contract PolygonMigrationTest is Test {
8691
assertEq(polygon.balanceOf(user), amount);
8792
}
8893

94+
function test_MigrateTo(address migrateTo, address user, uint256 amount) external {
95+
vm.assume(
96+
amount <= 10000000000 * 10 ** 18 && user != address(0) && user != address(migration) && user != governance
97+
&& user != address(admin) && migrateTo != address(0) && migrateTo != address(migration)
98+
&& polygon.balanceOf(migrateTo) == 0 && matic.balanceOf(user) == 0
99+
&& amount <= matic.balanceOf(address(matic))
100+
);
101+
102+
matic = ERC20PresetMinterPauser(0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0);
103+
104+
vm.startPrank(address(matic));
105+
matic.transfer(user, amount);
106+
vm.startPrank(user);
107+
matic.approve(address(migration), amount);
108+
migration.migrateTo(migrateTo, amount);
109+
110+
assertEq(matic.balanceOf(user), 0);
111+
assertEq(matic.balanceOf(address(migration)), amount);
112+
assertEq(polygon.balanceOf(migrateTo), amount);
113+
}
114+
89115
function test_CannotResetPolygonToken() external {
90116
address user = makeAddr("user");
91117
vm.prank(user);
@@ -204,7 +230,7 @@ contract PolygonMigrationTest is Test {
204230
assertEq(matic.balanceOf(address(migration)), amount);
205231
assertEq(polygon.balanceOf(user), amount);
206232

207-
uint256 deadline = 1 minutes;
233+
uint256 deadline = block.timestamp + 1 minutes;
208234
SigUtils.Permit memory permit = SigUtils.Permit({
209235
owner: user,
210236
spender: address(migration),

0 commit comments

Comments
 (0)