Factory and DelegatedCall Instance
This commit is contained in:
parent
9cb7cb31ae
commit
9671bd9f44
|
@ -1,4 +1,4 @@
|
|||
pragma solidity 0.4.17;
|
||||
pragma solidity ^0.4.17;
|
||||
import "./token/Token.sol";
|
||||
import "./token/ApproveAndCallFallBack.sol";
|
||||
import "./common/Controlled.sol";
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
pragma solidity ^0.4.17;
|
||||
|
||||
import "./common/Controlled.sol";
|
||||
import "./deploy/Instance.sol";
|
||||
import "./StandardBountyKernel.sol";
|
||||
|
||||
/**
|
||||
* @title StandardBountyKernel
|
||||
* @dev Creates a StandardBounty to be used by Instance contract
|
||||
*/
|
||||
contract StandardBountyFactory is Controlled {
|
||||
|
||||
event InstanceCreated(address indexed controller, address instance);
|
||||
|
||||
StandardBountyKernel public standardBountyKernel;
|
||||
|
||||
function StandardBountyFactory()
|
||||
public
|
||||
{
|
||||
standardBountyKernel = new StandardBountyKernel();
|
||||
}
|
||||
|
||||
function drainKernel(address _destination, address[] _drainTokens)
|
||||
external
|
||||
onlyController
|
||||
{
|
||||
standardBountyKernel.drainBounty(_destination, _drainTokens);
|
||||
}
|
||||
|
||||
function createStandardBounty(uint _timeout)
|
||||
external
|
||||
{
|
||||
createStandardBounty(msg.sender, _timeout);
|
||||
}
|
||||
|
||||
function createStandardBounty(address _controller, uint _timeout)
|
||||
public
|
||||
{
|
||||
StandardBountyKernel instance = StandardBountyKernel(new Instance(address(standardBountyKernel)));
|
||||
instance.initStandardBounty(_controller, _timeout);
|
||||
InstanceCreated(_controller, address(instance));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
pragma solidity ^0.4.17;
|
||||
import "./deploy/InstanceStorage.sol";
|
||||
import "./StandardBounty.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title StandardBountyKernel
|
||||
* @dev Creates a StandardBounty to be used by Instance contract
|
||||
*/
|
||||
contract StandardBountyKernel is InstanceStorage, StandardBounty {
|
||||
|
||||
function StandardBountyKernel()
|
||||
StandardBounty(0)
|
||||
public
|
||||
{
|
||||
state = State.FINALIZED; //enable manual recover of wrongly sent ERC20 tokens to Kernel contract
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Instance constructor for StandardBounty.
|
||||
* @param _controller The controller of the StandardBounty
|
||||
* @param _timeLimit Limit for withdrawing funds from the issue after its closed
|
||||
*/
|
||||
function initStandardBounty(address _controller, uint256 _timeLimit)
|
||||
external
|
||||
{
|
||||
require(controller == address(0)); //require clean instance
|
||||
require(_controller != address(0));
|
||||
controller = _controller;
|
||||
timeLimit = _timeLimit;
|
||||
state = State.OPEN;
|
||||
StateChanged(State.OPEN);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
pragma solidity ^0.4.17;
|
||||
|
||||
|
||||
/**
|
||||
* @title DelegatedCall
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* @dev Abstract contract that delegates calls by `delegated` modifier to result of `targetDelegatedCall()`
|
||||
* Important to avoid overwriting wrong storage pointers is that never define storage to this contract
|
||||
*/
|
||||
contract DelegatedCall {
|
||||
/**
|
||||
* @dev delegates the call of this function
|
||||
*/
|
||||
modifier delegated {
|
||||
//require successfull delegate call to remote `_target()`
|
||||
require(targetDelegatedCall().delegatecall(msg.data));
|
||||
assembly {
|
||||
let outSize := returndatasize
|
||||
let outDataPtr := mload(0x40) //load memory
|
||||
returndatacopy(outDataPtr, 0, outSize) //copy last return into pointer
|
||||
return(outDataPtr, outSize)
|
||||
}
|
||||
assert(false); //should never reach here
|
||||
_; //never will execute local logic
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev defines the address for delegation of calls
|
||||
*/
|
||||
function targetDelegatedCall()
|
||||
internal
|
||||
constant
|
||||
returns(address);
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
pragma solidity ^0.4.17;
|
||||
|
||||
import "./InstanceStorage.sol";
|
||||
import "./DelegatedCall.sol";
|
||||
|
||||
/**
|
||||
* @title Instance
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* @dev Contract that forward everything through delegatecall to defined kernel
|
||||
*/
|
||||
contract Instance is InstanceStorage, DelegatedCall {
|
||||
|
||||
function Instance(address _kernel) public {
|
||||
kernel = _kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev delegatecall everything (but declared functions) to `_target()`
|
||||
* @notice Verify `kernel()` code to predict behavior
|
||||
*/
|
||||
function () external delegated {
|
||||
//all goes to kernel
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev returns kernel if kernel that is configured
|
||||
* @return kernel address
|
||||
*/
|
||||
function targetDelegatedCall()
|
||||
internal
|
||||
constant
|
||||
returns(address)
|
||||
{
|
||||
return kernel;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
pragma solidity ^0.4.17;
|
||||
|
||||
|
||||
/**
|
||||
* @title InstanceStorage
|
||||
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)
|
||||
* @dev Defines kernel vars that Kernel contract share with Instance.
|
||||
* Important to avoid overwriting wrong storage pointers is that
|
||||
* InstanceStorage should be always the first contract at heritance.
|
||||
*/
|
||||
contract InstanceStorage {
|
||||
// protected zone start (InstanceStorage vars)
|
||||
address public kernel;
|
||||
// protected zone end
|
||||
}
|
Loading…
Reference in New Issue