-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathPolygonMigration.sol
More file actions
110 lines (89 loc) · 4.03 KB
/
Copy pathPolygonMigration.sol
File metadata and controls
110 lines (89 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IERC20Permit} from "openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable2StepUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/access/Ownable2StepUpgradeable.sol";
import {IPolygonMigration} from "./interfaces/IPolygonMigration.sol";
/// @title Polygon Migration
/// @author Polygon Labs (@DhairyaSethi, @gretzke, @qedk)
/// @notice This is the migration contract for Matic <-> Polygon ERC20 token on Ethereum L1
/// @dev The contract allows for a 1-to-1 conversion from $MATIC into $POL and vice-versa
/// @custom:security-contact security@polygon.technology
contract PolygonMigration is Ownable2StepUpgradeable, IPolygonMigration {
using SafeERC20 for IERC20;
using SafeERC20 for IERC20Permit;
IERC20 public immutable matic;
IERC20 public polygon;
bool public unmigrationLocked;
modifier onlyUnmigrationUnlocked() {
if (unmigrationLocked) revert UnmigrationLocked();
_;
}
constructor(address matic_) {
if (matic_ == address(0)) revert InvalidAddress();
matic = IERC20(matic_);
// so that the implementation contract cannot be initialized
_disableInitializers();
}
function initialize() external initializer {
__Ownable_init();
}
/// @notice This function allows owner/governance to set POL token address *only once*
/// @param polygon_ Address of deployed POL token
function setPolygonToken(address polygon_) external onlyOwner {
if (polygon_ == address(0) || address(polygon) != address(0)) revert InvalidAddressOrAlreadySet();
polygon = IERC20(polygon_);
}
/// @inheritdoc IPolygonMigration
function migrate(uint256 amount) external {
emit Migrated(msg.sender, msg.sender, amount);
matic.safeTransferFrom(msg.sender, address(this), amount);
polygon.safeTransfer(msg.sender, amount);
}
/// @inheritdoc IPolygonMigration
function migrateTo(address recipient, uint256 amount) external {
emit Migrated(msg.sender, recipient, amount);
matic.safeTransferFrom(msg.sender, address(this), amount);
polygon.safeTransfer(recipient, amount);
}
/// @inheritdoc IPolygonMigration
function unmigrate(uint256 amount) external onlyUnmigrationUnlocked {
emit Unmigrated(msg.sender, msg.sender, amount);
polygon.safeTransferFrom(msg.sender, address(this), amount);
matic.safeTransfer(msg.sender, amount);
}
/// @inheritdoc IPolygonMigration
function unmigrateTo(address recipient, uint256 amount) external onlyUnmigrationUnlocked {
emit Unmigrated(msg.sender, recipient, amount);
polygon.safeTransferFrom(msg.sender, address(this), amount);
matic.safeTransfer(recipient, amount);
}
/// @inheritdoc IPolygonMigration
function unmigrateWithPermit(
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external onlyUnmigrationUnlocked {
emit Unmigrated(msg.sender, msg.sender, amount);
IERC20Permit(address(polygon)).safePermit(msg.sender, address(this), amount, deadline, v, r, s);
polygon.safeTransferFrom(msg.sender, address(this), amount);
matic.safeTransfer(msg.sender, amount);
}
/// @inheritdoc IPolygonMigration
function updateUnmigrationLock(bool unmigrationLocked_) external onlyOwner {
emit UnmigrationLockUpdated(unmigrationLocked_);
unmigrationLocked = unmigrationLocked_;
}
/// @inheritdoc IPolygonMigration
function version() external pure returns (string memory) {
return "1.2.0";
}
/// @inheritdoc IPolygonMigration
function burn(uint256 amount) external onlyOwner {
polygon.safeTransfer(0x000000000000000000000000000000000000dEaD, amount);
}
uint256[49] private __gap;
}