This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from maticnetwork/plasma-bridge-update
Plasma bridge update
- Loading branch information
Showing
12 changed files
with
438 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ test-blockchain/data | |
*.log | ||
|
||
.DS_Store | ||
.vscode | ||
*.env | ||
|
||
coverage/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pragma solidity ^0.5.2; | ||
|
||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Mintable.sol"; | ||
import "openzeppelin-solidity/contracts/utils/Address.sol"; | ||
|
||
|
||
contract POLTokenMock is ERC20Mintable { | ||
using Address for address; | ||
|
||
// detailed ERC20 | ||
string public name; | ||
string public symbol; | ||
uint8 public decimals = 18; | ||
|
||
constructor(string memory _name, string memory _symbol) public { | ||
name = _name; | ||
symbol = _symbol; | ||
|
||
uint256 value = 10**10 * (10**18); | ||
mint(msg.sender, value); | ||
} | ||
|
||
function safeTransfer(IERC20 token, address to, uint256 value) public { | ||
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); | ||
} | ||
|
||
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) public { | ||
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); | ||
} | ||
|
||
/** | ||
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement | ||
* on the return value: the return value is optional (but if data is returned, it must equal true). | ||
* @param token The token targeted by the call. | ||
* @param data The call data (encoded using abi.encode or one of its variants). | ||
*/ | ||
function callOptionalReturn(IERC20 token, bytes memory data) private { | ||
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since | ||
// we're implementing it ourselves. | ||
|
||
// A Solidity high level call has three parts: | ||
// 1. The target address is checked to verify it contains contract code | ||
// 2. The call itself is made, and success asserted | ||
// 3. The return value is decoded, which in turn checks the size of the returned data. | ||
|
||
require(address(token).isContract()); | ||
|
||
// solhint-disable-next-line avoid-low-level-calls | ||
(bool success, bytes memory returndata) = address(token).call(data); | ||
require(success); | ||
|
||
if (returndata.length > 0) { // Return data is optional | ||
require(abi.decode(returndata, (bool))); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.5.2; | ||
|
||
import {IERC20} from "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol"; | ||
|
||
// this impl was shortened for testing purposes | ||
// full impl at https://github.com/0xPolygon/indicia/blob/main/src/PolygonMigration.sol | ||
contract PolygonMigrationTest { | ||
using SafeERC20 for IERC20; | ||
|
||
event Migrated(address indexed account, uint256 amount); | ||
|
||
IERC20 public polygon; | ||
IERC20 public matic; | ||
|
||
function setTokenAddresses(address matic_, address polygon_) external { | ||
if (matic_ == address(0)) revert(); | ||
matic = IERC20(matic_); | ||
|
||
if (polygon_ == address(0)) revert(); | ||
polygon = IERC20(polygon_); | ||
} | ||
|
||
/// @notice This function allows for migrating MATIC tokens to POL tokens | ||
/// @dev The function does not do any validation since the migration is a one-way process | ||
/// @param amount Amount of MATIC to migrate | ||
function migrate(uint256 amount) external { | ||
emit Migrated(msg.sender, amount); | ||
|
||
matic.safeTransferFrom(msg.sender, address(this), amount); | ||
polygon.safeTransfer(msg.sender, amount); | ||
} | ||
} |
Oops, something went wrong.