From 2ed1eacc4db50d009f90b818f362d6c6bbcd5e87 Mon Sep 17 00:00:00 2001 From: Thrilok Kumar Date: Thu, 24 Sep 2020 16:23:42 +0530 Subject: [PATCH] Updated flusher.sol to fallback function --- contracts/flusher/flusher.sol | 57 +++++++++++++++-------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/contracts/flusher/flusher.sol b/contracts/flusher/flusher.sol index 3535b8a..648b539 100644 --- a/contracts/flusher/flusher.sol +++ b/contracts/flusher/flusher.sol @@ -1,42 +1,35 @@ // SPDX-License-Identifier: MIT - pragma solidity ^0.6.8; pragma experimental ABIEncoderV2; -interface DeployerInterface { - function signer(address) external view returns (bool); - function isConnector(address[] calldata) external view returns (bool); -} +import "@openzeppelin/contracts/proxy/Proxy.sol"; -contract Flusher { - event LogCast(address indexed sender, uint value); +contract Flusher is Proxy { + /** + * @dev Storage slot with the address of the current implementation. + * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1 + */ + bytes32 private constant _IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1); // 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc - string constant public name = "Flusher-v1"; - - DeployerInterface public constant deployer = DeployerInterface(address(0)); // TODO - Change while deploying - - function spell(address _target, bytes memory _data) internal { - require(_target != address(0), "target-invalid"); - assembly { - let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) - switch iszero(succeeded) - case 1 { - let size := returndatasize() - returndatacopy(0x00, 0x00, size) - revert(0x00, size) + /** + * @dev Returns the current implementation address. + */ + function _implementation() internal override view returns (address impl) { + bytes32 slot = _IMPLEMENTATION_SLOT; + // solhint-disable-next-line no-inline-assembly + assembly { + impl := sload(slot) } } - } - function cast(address[] calldata _targets, bytes[] calldata _datas) external payable { - require(deployer.signer(msg.sender), "not-signer"); - require(_targets.length == _datas.length , "invalid-array-length"); - require(deployer.isConnector(_targets), "not-connector"); - for (uint i = 0; i < _targets.length; i++) { - spell(_targets[i], _datas[i]); + function setBasic(address newImplementation) public { + require(_implementation() == address(0), "_implementation-logic-already-set"); + require(newImplementation == address(0), "newImplementation-not-vaild"); + bytes32 slot = _IMPLEMENTATION_SLOT; + + // solhint-disable-next-line no-inline-assembly + assembly { + sstore(slot, newImplementation) + } } - emit LogCast(msg.sender, msg.value); - } - - receive() external payable {} -} \ No newline at end of file +}