UNPKG

hardlydifficult-ethereum-contracts

Version:
768 lines 35.4 kB
{ "contractName": "Clone2Factory", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.5.17+commit.d19bba13\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/circleci/repo/contracts/proxies/Clone2Factory.sol\":\"Clone2Factory\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"optimizer\":{\"enabled\":true,\"runs\":2000000},\"remappings\":[]},\"sources\":{\"/home/circleci/repo/contracts/proxies/Clone2Factory.sol\":{\"keccak256\":\"0x20ad3c3465defae97e35187a1f74bbdfcfa5ef493d79cca00e5692fed6feeec1\",\"urls\":[\"bzz-raw://6ffd068b3b4761476990d58d23ae546eec0103fb2e5f896c31303a08d4c39c92\",\"dweb:/ipfs/QmSNL1DVqb5WX4eW4DXkuTEMYsccwkVdXb14L2SKp7Utzf\"]}},\"version\":1}", "bytecode": "0x60556023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72315820da43462dd7af1920e0bac511b4b9d1a2d720b681eeef48e9ef3ee7b1f4974bcc64736f6c63430005110032", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72315820da43462dd7af1920e0bac511b4b9d1a2d720b681eeef48e9ef3ee7b1f4974bcc64736f6c63430005110032", "sourceMap": "191:2392:8:-;;132:2:-1;166:7;155:9;146:7;137:37;255:7;249:14;246:1;241:23;235:4;232:33;222:2;;269:9;222:2;293:9;290:1;283:20;323:4;314:7;306:22;347:7;338;331:24", "deployedSourceMap": "191:2392:8:-;;;;;;;;", "source": "pragma solidity ^0.5.0;\n\n\n// From https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol\n// Updated to support Solidity 5, switch to `create2` and revert on fail\nlibrary Clone2Factory\n{\n /**\n * @notice Uses create2 to deploy a clone to a pre-determined address.\n * @param target the address of the template contract, containing the logic for this contract.\n * @param salt a salt used to determine the contract address before the transaction is mined,\n * may be random or sequential.\n * The salt to use with the create2 call can be `msg.sender+salt` in order to\n * prevent an attacker from front-running another user's deployment.\n * @return proxyAddress the address of the newly deployed contract.\n * @dev Using `bytes12` for the salt saves 6 gas over using `uint96` (requires another shift).\n * Will revert on fail.\n */\n function createClone2(\n address target,\n bytes32 salt\n ) internal\n returns (address proxyAddress)\n {\n // solium-disable-next-line\n assembly\n {\n let pointer := mload(0x40)\n\n // Create the bytecode for deployment based on the Minimal Proxy Standard (EIP-1167)\n // bytecode: 0x0\n mstore(pointer, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(pointer, 0x14), shl(96, target))\n mstore(add(pointer, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n\n // `create2` consumes all available gas if called with a salt that's already been consumed\n // we check if the address is available first so that doesn't happen\n // Costs ~958 gas\n\n // Calculate the hash\n let contractCodeHash := keccak256(pointer, 0x37)\n\n // salt: 0x100\n mstore(add(pointer, 0x100), salt)\n\n // addressSeed: 0x40\n // 0xff\n mstore(add(pointer, 0x40), 0xff00000000000000000000000000000000000000000000000000000000000000)\n // this\n mstore(add(pointer, 0x41), shl(96, address))\n // salt\n mstore(add(pointer, 0x55), mload(add(pointer, 0x100)))\n // hash\n mstore(add(pointer, 0x75), contractCodeHash)\n\n proxyAddress := keccak256(add(pointer, 0x40), 0x55)\n\n switch extcodesize(proxyAddress)\n case 0 {\n // Deploy the contract, returning the address or 0 on fail\n proxyAddress := create2(0, pointer, 0x37, mload(add(pointer, 0x100)))\n }\n default {\n proxyAddress := 0\n }\n }\n\n // Revert if the deployment fails (possible if salt was already used)\n require(proxyAddress != address(0), 'PROXY_DEPLOY_FAILED');\n }\n}\n", "sourcePath": "/home/circleci/repo/contracts/proxies/Clone2Factory.sol", "ast": { "absolutePath": "/home/circleci/repo/contracts/proxies/Clone2Factory.sol", "exportedSymbols": { "Clone2Factory": [ 1352 ] }, "id": 1353, "nodeType": "SourceUnit", "nodes": [ { "id": 1331, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:8" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 1352, "linearizedBaseContracts": [ 1352 ], "name": "Clone2Factory", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 1350, "nodeType": "Block", "src": "983:1598:8", "statements": [ { "externalReferences": [ { "target": { "declaration": 1333, "isOffset": false, "isSlot": false, "src": "1315:6:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2123:12:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2201:12:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2305:12:8", "valueSize": 1 } }, { "salt": { "declaration": 1335, "isOffset": false, "isSlot": false, "src": "1762:4:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2407:12:8", "valueSize": 1 } } ], "id": 1340, "nodeType": "InlineAssembly", "operations": "{\n let pointer := mload(0x40)\n mstore(pointer, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(pointer, 0x14), shl(96, target))\n mstore(add(pointer, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n let contractCodeHash := keccak256(pointer, 0x37)\n mstore(add(pointer, 0x100), salt)\n mstore(add(pointer, 0x40), 0xff00000000000000000000000000000000000000000000000000000000000000)\n mstore(add(pointer, 0x41), shl(96, address()))\n mstore(add(pointer, 0x55), mload(add(pointer, 0x100)))\n mstore(add(pointer, 0x75), contractCodeHash)\n proxyAddress := keccak256(add(pointer, 0x40), 0x55)\n switch extcodesize(proxyAddress)\n case 0 {\n proxyAddress := create2(0, pointer, 0x37, mload(add(pointer, 0x100)))\n }\n default { proxyAddress := 0 }\n}", "src": "1021:1417:8" }, { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_address", "typeString": "address" }, "id": 1346, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 1342, "name": "proxyAddress", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1338, "src": "2526:12:8", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "30", "id": 1344, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2550:1:8", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" } ], "id": 1343, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "2542:7:8", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": "address" }, "id": 1345, "isConstant": false, "isLValue": false, "isPure": true, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2542:10:8", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" } }, "src": "2526:26:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "50524f58595f4445504c4f595f4641494c4544", "id": 1347, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "2554:21:8", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_76ce64557a80c95a1320c50cbae5822a174534010f3ef3154270eeca62982be7", "typeString": "literal_string \"PROXY_DEPLOY_FAILED\"" }, "value": "PROXY_DEPLOY_FAILED" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_76ce64557a80c95a1320c50cbae5822a174534010f3ef3154270eeca62982be7", "typeString": "literal_string \"PROXY_DEPLOY_FAILED\"" } ], "id": 1341, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 2266, 2267 ], "referencedDeclaration": 2267, "src": "2518:7:8", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 1348, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2518:58:8", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 1349, "nodeType": "ExpressionStatement", "src": "2518:58:8" } ] }, "documentation": "@notice Uses create2 to deploy a clone to a pre-determined address.\n@param target the address of the template contract, containing the logic for this contract.\n@param salt a salt used to determine the contract address before the transaction is mined,\nmay be random or sequential.\nThe salt to use with the create2 call can be `msg.sender+salt` in order to\nprevent an attacker from front-running another user's deployment.\n@return proxyAddress the address of the newly deployed contract.\n@dev Using `bytes12` for the salt saves 6 gas over using `uint96` (requires another shift).\nWill revert on fail.", "id": 1351, "implemented": true, "kind": "function", "modifiers": [], "name": "createClone2", "nodeType": "FunctionDefinition", "parameters": { "id": 1336, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1333, "name": "target", "nodeType": "VariableDeclaration", "scope": 1351, "src": "900:14:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1332, "name": "address", "nodeType": "ElementaryTypeName", "src": "900:7:8", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1335, "name": "salt", "nodeType": "VariableDeclaration", "scope": 1351, "src": "920:12:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 1334, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "920:7:8", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "src": "894:42:8" }, "returnParameters": { "id": 1339, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1338, "name": "proxyAddress", "nodeType": "VariableDeclaration", "scope": 1351, "src": "959:20:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1337, "name": "address", "nodeType": "ElementaryTypeName", "src": "959:7:8", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "958:22:8" }, "scope": 1352, "src": "873:1708:8", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" } ], "scope": 1353, "src": "191:2392:8" } ], "src": "0:2584:8" }, "legacyAST": { "absolutePath": "/home/circleci/repo/contracts/proxies/Clone2Factory.sol", "exportedSymbols": { "Clone2Factory": [ 1352 ] }, "id": 1353, "nodeType": "SourceUnit", "nodes": [ { "id": 1331, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:8" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 1352, "linearizedBaseContracts": [ 1352 ], "name": "Clone2Factory", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 1350, "nodeType": "Block", "src": "983:1598:8", "statements": [ { "externalReferences": [ { "target": { "declaration": 1333, "isOffset": false, "isSlot": false, "src": "1315:6:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2123:12:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2201:12:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2305:12:8", "valueSize": 1 } }, { "salt": { "declaration": 1335, "isOffset": false, "isSlot": false, "src": "1762:4:8", "valueSize": 1 } }, { "proxyAddress": { "declaration": 1338, "isOffset": false, "isSlot": false, "src": "2407:12:8", "valueSize": 1 } } ], "id": 1340, "nodeType": "InlineAssembly", "operations": "{\n let pointer := mload(0x40)\n mstore(pointer, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(pointer, 0x14), shl(96, target))\n mstore(add(pointer, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n let contractCodeHash := keccak256(pointer, 0x37)\n mstore(add(pointer, 0x100), salt)\n mstore(add(pointer, 0x40), 0xff00000000000000000000000000000000000000000000000000000000000000)\n mstore(add(pointer, 0x41), shl(96, address()))\n mstore(add(pointer, 0x55), mload(add(pointer, 0x100)))\n mstore(add(pointer, 0x75), contractCodeHash)\n proxyAddress := keccak256(add(pointer, 0x40), 0x55)\n switch extcodesize(proxyAddress)\n case 0 {\n proxyAddress := create2(0, pointer, 0x37, mload(add(pointer, 0x100)))\n }\n default { proxyAddress := 0 }\n}", "src": "1021:1417:8" }, { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_address", "typeString": "address" }, "id": 1346, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 1342, "name": "proxyAddress", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1338, "src": "2526:12:8", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "30", "id": 1344, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2550:1:8", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" } ], "id": 1343, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "2542:7:8", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": "address" }, "id": 1345, "isConstant": false, "isLValue": false, "isPure": true, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2542:10:8", "typeDescriptions": { "typeIdentifier": "t_address_payable", "typeString": "address payable" } }, "src": "2526:26:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "50524f58595f4445504c4f595f4641494c4544", "id": 1347, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "2554:21:8", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_76ce64557a80c95a1320c50cbae5822a174534010f3ef3154270eeca62982be7", "typeString": "literal_string \"PROXY_DEPLOY_FAILED\"" }, "value": "PROXY_DEPLOY_FAILED" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_76ce64557a80c95a1320c50cbae5822a174534010f3ef3154270eeca62982be7", "typeString": "literal_string \"PROXY_DEPLOY_FAILED\"" } ], "id": 1341, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 2266, 2267 ], "referencedDeclaration": 2267, "src": "2518:7:8", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 1348, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2518:58:8", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 1349, "nodeType": "ExpressionStatement", "src": "2518:58:8" } ] }, "documentation": "@notice Uses create2 to deploy a clone to a pre-determined address.\n@param target the address of the template contract, containing the logic for this contract.\n@param salt a salt used to determine the contract address before the transaction is mined,\nmay be random or sequential.\nThe salt to use with the create2 call can be `msg.sender+salt` in order to\nprevent an attacker from front-running another user's deployment.\n@return proxyAddress the address of the newly deployed contract.\n@dev Using `bytes12` for the salt saves 6 gas over using `uint96` (requires another shift).\nWill revert on fail.", "id": 1351, "implemented": true, "kind": "function", "modifiers": [], "name": "createClone2", "nodeType": "FunctionDefinition", "parameters": { "id": 1336, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1333, "name": "target", "nodeType": "VariableDeclaration", "scope": 1351, "src": "900:14:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1332, "name": "address", "nodeType": "ElementaryTypeName", "src": "900:7:8", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 1335, "name": "salt", "nodeType": "VariableDeclaration", "scope": 1351, "src": "920:12:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 1334, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "920:7:8", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "src": "894:42:8" }, "returnParameters": { "id": 1339, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1338, "name": "proxyAddress", "nodeType": "VariableDeclaration", "scope": 1351, "src": "959:20:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 1337, "name": "address", "nodeType": "ElementaryTypeName", "src": "959:7:8", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "958:22:8" }, "scope": 1352, "src": "873:1708:8", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" } ], "scope": 1353, "src": "191:2392:8" } ], "src": "0:2584:8" }, "compiler": { "name": "solc", "version": "0.5.17+commit.d19bba13.Emscripten.clang" }, "networks": {}, "schemaVersion": "3.0.23", "updatedAt": "2020-04-07T20:17:34.943Z", "devdoc": { "methods": {} }, "userdoc": { "methods": {} } }