mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
seperated flusher master
This commit is contained in:
parent
c3a05c66d7
commit
52fbd8c0fc
|
@ -2,36 +2,38 @@
|
||||||
|
|
||||||
pragma solidity ^0.6.8;
|
pragma solidity ^0.6.8;
|
||||||
|
|
||||||
contract Deployer {
|
contract Controller {
|
||||||
|
|
||||||
event LogNewFlusher(address indexed owner, address indexed flusher, address indexed logic);
|
event LogNewMaster(address indexed master);
|
||||||
|
event LogUpdateMaster(address indexed master);
|
||||||
event LogEnableConnector(address indexed connector);
|
event LogEnableConnector(address indexed connector);
|
||||||
event LogDisableConnector(address indexed connector);
|
event LogDisableConnector(address indexed connector);
|
||||||
|
|
||||||
mapping (address => address) public flushers;
|
address private newMaster;
|
||||||
|
address public master;
|
||||||
mapping (address => bool) public connectors;
|
mapping (address => bool) public connectors;
|
||||||
|
|
||||||
// deploy create2 + minimal proxy
|
modifier isMaster() {
|
||||||
function deployLogic(address owner, address logic) public returns (address proxy) {
|
require(msg.sender == master, "not-master");
|
||||||
require(!(isFlusherDeployed(getAddress(owner, logic))), "flusher-already-deployed");
|
_;
|
||||||
bytes32 salt = keccak256(abi.encodePacked(owner, proxy));
|
}
|
||||||
bytes20 targetBytes = bytes20(logic);
|
|
||||||
// solium-disable-next-line security/no-inline-assembly
|
// change the master address
|
||||||
assembly {
|
function changeMaster(address _newMaster) external isMaster {
|
||||||
let clone := mload(0x40)
|
require(_newMaster != master, "already-a-master");
|
||||||
mstore(
|
require(_newMaster != address(0), "not-valid-address");
|
||||||
clone,
|
require(newMaster != _newMaster, "already-a-new-master");
|
||||||
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
|
newMaster = _newMaster;
|
||||||
)
|
emit LogNewMaster(_newMaster);
|
||||||
mstore(add(clone, 0x14), targetBytes)
|
}
|
||||||
mstore(
|
|
||||||
add(clone, 0x28),
|
// new master claiming master position
|
||||||
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
|
function claimMaster() external {
|
||||||
)
|
require(newMaster != address(0), "not-valid-address");
|
||||||
proxy := create2(0, clone, 0x37, salt)
|
require(msg.sender == newMaster, "not-new-master");
|
||||||
}
|
master = newMaster;
|
||||||
flushers[proxy] = owner;
|
newMaster = address(0);
|
||||||
emit LogNewFlusher(owner, proxy, logic);
|
emit LogUpdateMaster(master);
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable flusher connector
|
// enable flusher connector
|
||||||
|
@ -60,6 +62,37 @@ contract Deployer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Deployer is Controller {
|
||||||
|
|
||||||
|
event LogNewFlusher(address indexed owner, address indexed flusher, address indexed logic);
|
||||||
|
|
||||||
|
mapping (address => address) public flushers;
|
||||||
|
|
||||||
|
// deploy create2 + minimal proxy
|
||||||
|
function deployLogic(address owner, address logic) public returns (address proxy) {
|
||||||
|
require(!(isFlusherDeployed(getAddress(owner, logic))), "flusher-already-deployed");
|
||||||
|
bytes32 salt = keccak256(abi.encodePacked(owner, proxy));
|
||||||
|
bytes20 targetBytes = bytes20(logic);
|
||||||
|
// solium-disable-next-line security/no-inline-assembly
|
||||||
|
assembly {
|
||||||
|
let clone := mload(0x40)
|
||||||
|
mstore(
|
||||||
|
clone,
|
||||||
|
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
|
||||||
|
)
|
||||||
|
mstore(add(clone, 0x14), targetBytes)
|
||||||
|
mstore(
|
||||||
|
add(clone, 0x28),
|
||||||
|
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
|
||||||
|
)
|
||||||
|
proxy := create2(0, clone, 0x37, salt)
|
||||||
|
}
|
||||||
|
flushers[proxy] = owner;
|
||||||
|
emit LogNewFlusher(owner, proxy, logic);
|
||||||
|
}
|
||||||
|
|
||||||
// is flusher deployed?
|
// is flusher deployed?
|
||||||
function isFlusherDeployed(address _address) public view returns (bool) {
|
function isFlusherDeployed(address _address) public view returns (bool) {
|
||||||
uint32 size;
|
uint32 size;
|
||||||
|
@ -92,4 +125,9 @@ contract Deployer {
|
||||||
return abi.encodePacked(a, b, c);
|
return abi.encodePacked(a, b, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(address _master) public {
|
||||||
|
master = _master;
|
||||||
|
emit LogUpdateMaster(master);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -159,5 +159,5 @@ contract Registry {
|
||||||
constructor(address _chief) public {
|
constructor(address _chief) public {
|
||||||
chief[_chief] = true;
|
chief[_chief] = true;
|
||||||
emit LogAddChief(_chief);
|
emit LogAddChief(_chief);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user