yield-contract/contracts/flusher.sol

43 lines
1.3 KiB
Solidity
Raw Normal View History

// SPDX-License-Identifier: MIT
2020-09-06 21:11:23 +00:00
pragma solidity ^0.6.8;
pragma experimental ABIEncoderV2;
interface RegistryInterface {
function signer(address) external view returns (bool);
2020-09-06 21:11:23 +00:00
function isConnector(address[] calldata) external view returns (bool);
}
contract Flusher {
2020-09-06 21:11:23 +00:00
event LogCast(address indexed sender, uint value);
2020-09-06 21:11:23 +00:00
string constant public name = "Flusher-v1";
2020-09-06 22:05:09 +00:00
uint constant version = 1;
2020-09-07 04:51:20 +00:00
RegistryInterface public constant registry = RegistryInterface(address(0)); // TODO - Change while deploying
2020-09-06 21:11:23 +00:00
function spell(address _target, bytes memory _data) internal {
require(_target != address(0), "target-invalid");
assembly {
2020-09-06 21:11:23 +00:00
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0)
switch iszero(succeeded)
2020-09-06 21:11:23 +00:00
case 1 {
let size := returndatasize()
returndatacopy(0x00, 0x00, size)
revert(0x00, size)
}
}
}
2020-09-06 21:11:23 +00:00
function cast(address[] calldata _targets, bytes[] calldata _datas) external payable {
require(registry.signer(msg.sender), "not-signer");
require(_targets.length == _datas.length , "invalid-array-length");
require(registry.isConnector(_targets), "not-connector");
for (uint i = 0; i < _targets.length; i++) {
spell(_targets[i], _datas[i]);
}
emit LogCast(msg.sender, msg.value);
}
2020-08-24 17:32:13 +00:00
2020-09-06 21:11:23 +00:00
receive() external payable {}
}