Oko contract explorer
Contract

Code for 0xa44d…1438

Since block 21423588

Verified contract

  1. pragma solidity 0.7.5;
  2. /*
  3. The MIT License (MIT)
  4. Copyright (c) 2018 Murray Software, LLC.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be included
  13. in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  18. CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  19. TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  20. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. //solhint-disable max-line-length
  23. //solhint-disable no-inline-assembly
  24. contract CloneFactory {
  25. function createClone(address target, bytes32 salt)
  26. internal
  27. returns (address payable result)
  28. {
  29. bytes20 targetBytes = bytes20(target);
  30. assembly {
  31. // load the next free memory slot as a place to store the clone contract data
  32. let clone := mload(0x40)
  33. // The bytecode block below is responsible for contract initialization
  34. // during deployment, it is worth noting the proxied contract constructor will not be called during
  35. // the cloning procedure and that is why an initialization function needs to be called after the
  36. // clone is created
  37. mstore(
  38. clone,
  39. 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
  40. )
  41. // This stores the address location of the implementation contract
  42. // so that the proxy knows where to delegate call logic to
  43. mstore(add(clone, 0x14), targetBytes)
  44. // The bytecode block is the actual code that is deployed for each clone created.
  45. // It forwards all calls to the already deployed implementation via a delegatecall
  46. mstore(
  47. add(clone, 0x28),
  48. 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
  49. )
  50. // deploy the contract using the CREATE2 opcode
  51. // this deploys the minimal proxy defined above, which will proxy all
  52. // calls to use the logic defined in the implementation contract `target`
  53. result := create2(0, clone, 0x37, salt)
  54. }
  55. }
  56. function isClone(address target, address query)
  57. internal
  58. view
  59. returns (bool result)
  60. {
  61. bytes20 targetBytes = bytes20(target);
  62. assembly {
  63. // load the next free memory slot as a place to store the comparison clone
  64. let clone := mload(0x40)
  65. // The next three lines store the expected bytecode for a miniml proxy
  66. // that targets `target` as its implementation contract
  67. mstore(
  68. clone,
  69. 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
  70. )
  71. mstore(add(clone, 0xa), targetBytes)
  72. mstore(
  73. add(clone, 0x1e),
  74. 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
  75. )
  76. // the next two lines store the bytecode of the contract that we are checking in memory
  77. let other := add(clone, 0x40)
  78. extcodecopy(query, other, 0, 0x2d)
  79. // Check if the expected bytecode equals the actual bytecode and return the result
  80. result := and(
  81. eq(mload(clone), mload(other)),
  82. eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
  83. )
  84. }
  85. }
  86. }
  87. /**
  88. * Contract that exposes the needed erc20 token functions
  89. */
  90. abstract contract ERC20Interface {
  91. // Send _value amount of tokens to address _to
  92. function transfer(address _to, uint256 _value)
  93. public
  94. virtual
  95. returns (bool success);
  96. // Get the account balance of another account with address _owner
  97. function balanceOf(address _owner)
  98. public
  99. virtual
  100. view
  101. returns (uint256 balance);
  102. }
  103. // helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
  104. library TransferHelper {
  105. function safeApprove(
  106. address token,
  107. address to,
  108. uint256 value
  109. ) internal {
  110. // bytes4(keccak256(bytes('approve(address,uint256)')));
  111. (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
  112. require(
  113. success && (data.length == 0 || abi.decode(data, (bool))),
  114. 'TransferHelper::safeApprove: approve failed'
  115. );
  116. }
  117. function safeTransfer(
  118. address token,
  119. address to,
  120. uint256 value
  121. ) internal {
  122. // bytes4(keccak256(bytes('transfer(address,uint256)')));
  123. (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
  124. require(
  125. success && (data.length == 0 || abi.decode(data, (bool))),
  126. 'TransferHelper::safeTransfer: transfer failed'
  127. );
  128. }
  129. function safeTransferFrom(
  130. address token,
  131. address from,
  132. address to,
  133. uint256 value
  134. ) internal {
  135. // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
  136. (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
  137. require(
  138. success && (data.length == 0 || abi.decode(data, (bool))),
  139. 'TransferHelper::transferFrom: transferFrom failed'
  140. );
  141. }
  142. function safeTransferETH(address to, uint256 value) internal {
  143. (bool success, ) = to.call{value: value}(new bytes(0));
  144. require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
  145. }
  146. }
  147. /**
  148. * Contract that will forward any incoming Ether to the creator of the contract
  149. *
  150. */
  151. contract Forwarder {
  152. // Address to which any funds sent to this contract will be forwarded
  153. address public parentAddress;
  154. event ForwarderDeposited(address from, uint256 value, bytes data);
  155. /**
  156. * Initialize the contract, and sets the destination address to that of the creator
  157. */
  158. function init(address _parentAddress) external onlyUninitialized {
  159. parentAddress = _parentAddress;
  160. uint256 value = address(this).balance;
  161. if (value == 0) {
  162. return;
  163. }
  164. (bool success, ) = parentAddress.call{ value: value }('');
  165. require(success, 'Flush failed');
  166. // NOTE: since we are forwarding on initialization,
  167. // we don't have the context of the original sender.
  168. // We still emit an event about the forwarding but set
  169. // the sender to the forwarder itself
  170. emit ForwarderDeposited(address(this), value, msg.data);
  171. }
  172. /**
  173. * Modifier that will execute internal code block only if the sender is the parent address
  174. */
  175. modifier onlyParent {
  176. require(msg.sender == parentAddress, 'Only Parent');
  177. _;
  178. }
  179. /**
  180. * Modifier that will execute internal code block only if the contract has not been initialized yet
  181. */
  182. modifier onlyUninitialized {
  183. require(parentAddress == address(0x0), 'Already initialized');
  184. _;
  185. }
  186. /**
  187. * Default function; Gets called when data is sent but does not match any other function
  188. */
  189. fallback() external payable {
  190. flush();
  191. }
  192. /**
  193. * Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
  194. */
  195. receive() external payable {
  196. flush();
  197. }
  198. /**
  199. * Execute a token transfer of the full balance from the forwarder token to the parent address
  200. * @param tokenContractAddress the address of the erc20 token contract
  201. */
  202. function flushTokens(address tokenContractAddress) external onlyParent {
  203. ERC20Interface instance = ERC20Interface(tokenContractAddress);
  204. address forwarderAddress = address(this);
  205. uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
  206. if (forwarderBalance == 0) {
  207. return;
  208. }
  209. TransferHelper.safeTransfer(
  210. tokenContractAddress,
  211. parentAddress,
  212. forwarderBalance
  213. );
  214. }
  215. /**
  216. * Flush the entire balance of the contract to the parent address.
  217. */
  218. function flush() public {
  219. uint256 value = address(this).balance;
  220. if (value == 0) {
  221. return;
  222. }
  223. (bool success, ) = parentAddress.call{ value: value }('');
  224. require(success, 'Flush failed');
  225. emit ForwarderDeposited(msg.sender, value, msg.data);
  226. }
  227. }
  228. contract ForwarderFactory is CloneFactory {
  229. address public implementationAddress;
  230. event ForwarderCreated(address newForwarderAddress, address parentAddress);
  231. constructor(address _implementationAddress) {
  232. implementationAddress = _implementationAddress;
  233. }
  234. function createForwarder(address parent, bytes32 salt) external {
  235. // include the signers in the salt so any contract deployed to a given address must have the same signers
  236. bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
  237. address payable clone = createClone(implementationAddress, finalSalt);
  238. Forwarder(clone).init(parent);
  239. emit ForwarderCreated(clone, parent);
  240. }
  241. }

Contract sourced from Etherscan. Solidity version v0.7.5+commit.eb77ed08.

Panoramix decompilation

# Palkeoramix decompiler. 

def _fallback(?) payable: # default function
  delegate 0x59ffafdc6ef594230de44f824e2bd0a51ca5ded with:
     funct call.data[return_data.size len 4]
       gas gas_remaining wei
      args call.data[return_data.size + 4 len calldata.size - 4]
  if not delegate.return_code:
      revert with ext_call.return_data[return_data.size len return_data.size]
  return ext_call.return_data[return_data.size len return_data.size]

Decompilation generated by Panoramix.

Raw bytecode

0x363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3