-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix claimTokens to support all token transfers (#213)
* Add contract `Claimable` to contain functionality related ability to claim tokens * The new contract is used in the bridge contracts and the erc677 token implementation * Fix claimTokens to support all token transfers
- Loading branch information
Showing
7 changed files
with
223 additions
and
27 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
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,52 @@ | ||
pragma solidity 0.4.24; | ||
|
||
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol"; | ||
import "./Sacrifice.sol"; | ||
|
||
contract Claimable { | ||
|
||
modifier validAddress(address _to) { | ||
require(_to != address(0)); | ||
_; | ||
} | ||
|
||
function claimValues(address _token, address _to) internal { | ||
if (_token == address(0)) { | ||
claimNativeCoins(_to); | ||
} else { | ||
claimErc20Tokens(_token, _to); | ||
} | ||
} | ||
|
||
function claimNativeCoins(address _to) internal { | ||
uint256 value = address(this).balance; | ||
if (!_to.send(value)) { | ||
(new Sacrifice).value(value)(_to); | ||
} | ||
} | ||
|
||
function claimErc20Tokens(address _token, address _to) internal { | ||
ERC20Basic token = ERC20Basic(_token); | ||
uint256 balance = token.balanceOf(this); | ||
safeTransfer(_token, _to, balance); | ||
} | ||
|
||
function safeTransfer(address _token, address _to, uint256 _value) internal { | ||
bytes memory returnData; | ||
bool returnDataResult; | ||
bytes memory callData = abi.encodeWithSignature("transfer(address,uint256)", _to, _value); | ||
assembly { | ||
let result := call(gas, _token, 0x0, add(callData, 0x20), mload(callData), 0, 32) | ||
returnData := mload(0) | ||
returnDataResult := mload(0) | ||
|
||
switch result | ||
case 0 { revert(0, 0) } | ||
} | ||
|
||
// Return data is optional | ||
if (returnData.length > 0) { | ||
require(returnDataResult); | ||
} | ||
} | ||
} |
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,37 @@ | ||
pragma solidity 0.4.24; | ||
|
||
import "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
|
||
|
||
contract NoReturnTransferTokenMock { | ||
using SafeMath for uint256; | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
|
||
mapping(address => uint256) internal balances; | ||
uint256 internal totalSupply_; | ||
|
||
function totalSupply() public view returns (uint256) { | ||
return totalSupply_; | ||
} | ||
|
||
function mint(address _to, uint256 _amount) public returns (bool) { | ||
totalSupply_ = totalSupply_.add(_amount); | ||
balances[_to] = balances[_to].add(_amount); | ||
emit Transfer(address(0), _to, _amount); | ||
return true; | ||
} | ||
|
||
function balanceOf(address _owner) public view returns (uint256) { | ||
return balances[_owner]; | ||
} | ||
|
||
function transfer(address _to, uint256 _value) public { | ||
require(_value <= balances[msg.sender]); | ||
require(_to != address(0)); | ||
|
||
balances[msg.sender] = balances[msg.sender].sub(_value); | ||
balances[_to] = balances[_to].add(_value); | ||
emit Transfer(msg.sender, _to, _value); | ||
} | ||
} |
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