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.
- Loading branch information
Showing
4 changed files
with
58 additions
and
38 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 |
---|---|---|
@@ -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
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