-
-
Save thrilok209/d9d1ebc15f27a3a1ef1e6358110dd274 to your computer and use it in GitHub Desktop.
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
pragma solidity ^0.6.6; | |
import {IERC20, Wallet} from "./wallet.sol"; | |
contract Deployer { | |
bytes public contractCode; | |
constructor () public { | |
contractCode = type(Wallet).creationCode; | |
} | |
function deployMinimalWithCreate2( | |
uint256 _salt, | |
address _logic | |
) public returns (address proxy) { | |
bytes32 salt = _getSalt(_salt, msg.sender); | |
bytes20 targetBytes = bytes20(_logic); | |
assembly { | |
let clone := mload(0x40) | |
mstore( | |
clone, | |
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000 | |
) | |
mstore(add(clone, 0x14), targetBytes) | |
mstore( | |
add(clone, 0x28), | |
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000 | |
) | |
proxy := create2(0, clone, 0x37, salt) | |
} | |
} | |
function getDeploymentAddress(uint256 _salt, address _sender, bytes memory _data) public view returns (address) { | |
bytes32 codeHash = keccak256(_data); | |
bytes32 salt = _getSalt(_salt, _sender); | |
bytes32 rawAddress = keccak256( | |
abi.encodePacked( | |
bytes1(0xff), | |
address(this), | |
salt, | |
codeHash | |
)); | |
return address(bytes20(rawAddress << 96)); | |
} | |
function getDeploymentAddress2(uint256 _salt, address dep, address _sender, bytes memory _data) public pure returns (address) { | |
bytes32 codeHash = keccak256(_data); | |
bytes32 salt = _getSalt(_salt, _sender); | |
bytes32 rawAddress = keccak256( | |
abi.encodePacked( | |
bytes1(0xff), | |
dep, | |
salt, | |
codeHash | |
)); | |
return address(uint(rawAddress)); | |
} | |
function _getSalt(uint256 _salt, address _sender) internal pure returns (bytes32) { | |
return keccak256(abi.encodePacked(_salt, _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
pragma solidity ^0.6.6; | |
interface IERC20 { | |
function balanceOf(address) external view returns (uint); | |
function transfer(address, uint) external returns (bool); | |
} | |
contract Wallet { | |
function flush(address token) public { | |
address payable treasury = 0x1d29756e8f7b091cE6c11a35980dE79c7eDa5D1f; | |
if (token != address(0x0)) IERC20(token).transfer(treasury, IERC20(token).balanceOf(address(this))); | |
if (address(this).balance > 0) treasury.transfer(address(this).balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment