-
Notifications
You must be signed in to change notification settings - Fork 4
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
0 parents
commit 4f80871
Showing
11 changed files
with
1,817 additions
and
0 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,3 @@ | ||
This software is a subject to Ambisafe License Agreement. | ||
No use or distribution is allowed without written permission from Ambisafe. | ||
https://www.ambisafe.co/terms-of-use/ |
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,4 @@ | ||
# etoken2 | ||
EToken2 public resources. | ||
========= | ||
|
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,203 @@ | ||
pragma solidity 0.4.8; | ||
|
||
import './AssetInterface.sol'; | ||
import {AssetProxyInterface as AssetProxy} from './AssetProxyInterface.sol'; | ||
|
||
/** | ||
* @title EToken2 Asset implementation contract. | ||
* | ||
* Basic asset implementation contract, without any additional logic. | ||
* Every other asset implementation contracts should derive from this one. | ||
* Receives calls from the proxy, and calls back immediatly without arguments modification. | ||
* | ||
* Note: all the non constant functions return false instead of throwing in case if state change | ||
* didn't happen yet. | ||
*/ | ||
contract Asset is AssetInterface { | ||
// Assigned asset proxy contract, immutable. | ||
AssetProxy public proxy; | ||
|
||
/** | ||
* Only assigned proxy is allowed to call. | ||
*/ | ||
modifier onlyProxy() { | ||
if (proxy == msg.sender) { | ||
_; | ||
} | ||
} | ||
|
||
/** | ||
* Sets asset proxy address. | ||
* | ||
* Can be set only once. | ||
* | ||
* @param _proxy asset proxy contract address. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function init(AssetProxy _proxy) returns(bool) { | ||
if (address(proxy) != 0x0) { | ||
return false; | ||
} | ||
proxy = _proxy; | ||
return true; | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performTransferWithReference(address _to, uint _value, string _reference, address _sender) onlyProxy() returns(bool) { | ||
return _transferWithReference(_to, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Calls back without modifications. | ||
* | ||
* @return success. | ||
* @dev function is virtual, and meant to be overridden. | ||
*/ | ||
function _transferWithReference(address _to, uint _value, string _reference, address _sender) internal returns(bool) { | ||
return proxy._forwardTransferFromWithReference(_sender, _to, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performTransferToICAPWithReference(bytes32 _icap, uint _value, string _reference, address _sender) onlyProxy() returns(bool) { | ||
return _transferToICAPWithReference(_icap, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Calls back without modifications. | ||
* | ||
* @return success. | ||
* @dev function is virtual, and meant to be overridden. | ||
*/ | ||
function _transferToICAPWithReference(bytes32 _icap, uint _value, string _reference, address _sender) internal returns(bool) { | ||
return proxy._forwardTransferFromToICAPWithReference(_sender, _icap, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) onlyProxy() returns(bool) { | ||
return _transferFromWithReference(_from, _to, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Calls back without modifications. | ||
* | ||
* @return success. | ||
* @dev function is virtual, and meant to be overridden. | ||
*/ | ||
function _transferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) internal returns(bool) { | ||
return proxy._forwardTransferFromWithReference(_from, _to, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) onlyProxy() returns(bool) { | ||
return _transferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Calls back without modifications. | ||
* | ||
* @return success. | ||
* @dev function is virtual, and meant to be overridden. | ||
*/ | ||
function _transferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) internal returns(bool) { | ||
return proxy._forwardTransferFromToICAPWithReference(_from, _icap, _value, _reference, _sender); | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return success. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performApprove(address _spender, uint _value, address _sender) onlyProxy() returns(bool) { | ||
return _approve(_spender, _value, _sender); | ||
} | ||
|
||
/** | ||
* Calls back without modifications. | ||
* | ||
* @return success. | ||
* @dev function is virtual, and meant to be overridden. | ||
*/ | ||
function _approve(address _spender, uint _value, address _sender) internal returns(bool) { | ||
return proxy._forwardApprove(_spender, _value, _sender); | ||
} | ||
|
||
/** | ||
* Passes execution into virtual function. | ||
* | ||
* Can only be called by assigned asset proxy. | ||
* | ||
* @return bytes32 result. | ||
* @dev function is final, and must not be overridden. | ||
*/ | ||
function _performGeneric(bytes _data, address _sender) payable onlyProxy() returns(bytes32) { | ||
return _generic(_data, _sender); | ||
} | ||
|
||
modifier onlyMe() { | ||
if (this == msg.sender) { | ||
_; | ||
} | ||
} | ||
|
||
// Most probably the following should neever be redefined in child contracts. | ||
address genericSender; | ||
function _generic(bytes _data, address _sender) internal returns(bytes32) { | ||
// Restrict reentrancy. | ||
if (genericSender != 0x0) { | ||
throw; | ||
} | ||
genericSender = _sender; | ||
bytes32 result = _callReturn(this, _data, msg.value); | ||
delete genericSender; | ||
return result; | ||
} | ||
|
||
function _callReturn(address _target, bytes _data, uint _value) internal returns(bytes32 result) { | ||
bool success; | ||
assembly { | ||
success := call(div(mul(gas, 63), 64), _target, _value, add(_data, 32), mload(_data), 0, 32) | ||
result := mload(0) | ||
} | ||
if (!success) { | ||
throw; | ||
} | ||
} | ||
|
||
// Decsendants should use _sender() instead of msg.sender to properly process proxied calls. | ||
function _sender() constant internal returns(address) { | ||
return this == msg.sender ? genericSender : msg.sender; | ||
} | ||
} |
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,12 @@ | ||
pragma solidity 0.4.8; | ||
|
||
contract AssetInterface { | ||
function _performTransferWithReference(address _to, uint _value, string _reference, address _sender) returns(bool); | ||
function _performTransferToICAPWithReference(bytes32 _icap, uint _value, string _reference, address _sender) returns(bool); | ||
function _performApprove(address _spender, uint _value, address _sender) returns(bool); | ||
function _performTransferFromWithReference(address _from, address _to, uint _value, string _reference, address _sender) returns(bool); | ||
function _performTransferFromToICAPWithReference(address _from, bytes32 _icap, uint _value, string _reference, address _sender) returns(bool); | ||
function _performGeneric(bytes _data, address _sender) payable returns(bytes32) { | ||
throw; | ||
} | ||
} |
Oops, something went wrong.