UNPKG

@daostack/upgrades

Version:
993 lines (992 loc) 41.2 kB
{ "fileName": "Initializable.sol", "contractName": "Initializable", "source": "pragma solidity >=0.4.24 <0.7.0;\n// SPDX-License-Identifier: MIT\n\n\n/**\n * @title Initializable\n *\n * @dev Helper contract to support initializer functions. To use it, replace\n * the constructor with a function that has the `initializer` modifier.\n * WARNING: Unlike constructors, initializer functions must be manually\n * invoked. This applies both to deploying an Initializable contract, as well\n * as extending an Initializable contract via inheritance.\n * WARNING: When used with inheritance, manual care must be taken to not invoke\n * a parent initializer twice, or ensure that all initializers are idempotent,\n * because this is not dealt with automatically as with constructors.\n */\ncontract Initializable {\n\n /**\n * @dev Indicates that the contract has been initialized.\n */\n bool private initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private initializing;\n\n /**\n * @dev Modifier to use in the initializer function of a contract.\n */\n modifier initializer() {\n require(initializing || isConstructor() || !initialized, \"Contract instance has already been initialized\");\n\n bool isTopLevelCall = !initializing;\n if (isTopLevelCall) {\n initializing = true;\n initialized = true;\n }\n\n _;\n\n if (isTopLevelCall) {\n initializing = false;\n }\n }\n\n /// @dev Returns true if and only if the function is running in the constructor\n function isConstructor() private view returns (bool) {\n // extcodesize checks the size of the code stored in an address, and\n // address returns the current address. Since the code is still not\n // deployed when running a constructor, any checks on its code size will\n // yield zero, making it an effective way to detect if a contract is\n // under construction or not.\n address self = address(this);\n uint256 cs;\n assembly { cs := extcodesize(self) }\n return cs == 0;\n }\n\n // Reserved storage space to allow for layout changes in the future.\n uint256[50] private ______gap;\n}\n", "sourcePath": "contracts/Initializable.sol", "sourceMap": "689:1357:0:-:0;;;;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "689:1357:0:-:0;;;;;;;;;;;", "abi": [], "ast": { "absolutePath": "contracts/Initializable.sol", "exportedSymbols": { "Initializable": [ 74 ] }, "id": 75, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 1, "literals": [ "solidity", ">=", "0.4", ".24", "<", "0.7", ".0" ], "nodeType": "PragmaDirective", "src": "0:32:0" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": { "id": 2, "nodeType": "StructuredDocumentation", "src": "67:621:0", "text": " @title Initializable\n @dev Helper contract to support initializer functions. To use it, replace\n the constructor with a function that has the `initializer` modifier.\n WARNING: Unlike constructors, initializer functions must be manually\n invoked. This applies both to deploying an Initializable contract, as well\n as extending an Initializable contract via inheritance.\n WARNING: When used with inheritance, manual care must be taken to not invoke\n a parent initializer twice, or ensure that all initializers are idempotent,\n because this is not dealt with automatically as with constructors." }, "fullyImplemented": true, "id": 74, "linearizedBaseContracts": [ 74 ], "name": "Initializable", "nodeType": "ContractDefinition", "nodes": [ { "constant": false, "documentation": { "id": 3, "nodeType": "StructuredDocumentation", "src": "717:69:0", "text": " @dev Indicates that the contract has been initialized." }, "id": 5, "mutability": "mutable", "name": "initialized", "nodeType": "VariableDeclaration", "overrides": null, "scope": 74, "src": "789:24:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 4, "name": "bool", "nodeType": "ElementaryTypeName", "src": "789:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "private" }, { "constant": false, "documentation": { "id": 6, "nodeType": "StructuredDocumentation", "src": "818:87:0", "text": " @dev Indicates that the contract is in the process of being initialized." }, "id": 8, "mutability": "mutable", "name": "initializing", "nodeType": "VariableDeclaration", "overrides": null, "scope": 74, "src": "908:25:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 7, "name": "bool", "nodeType": "ElementaryTypeName", "src": "908:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "private" }, { "body": { "id": 46, "nodeType": "Block", "src": "1042:313:0", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 18, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 15, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 12, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8, "src": "1056:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "||", "rightExpression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 13, "name": "isConstructor", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 69, "src": "1072:13:0", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$__$returns$_t_bool_$", "typeString": "function () view returns (bool)" } }, "id": 14, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1072:15:0", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1056:31:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "||", "rightExpression": { "argumentTypes": null, "id": 17, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "UnaryOperation", "operator": "!", "prefix": true, "src": "1091:12:0", "subExpression": { "argumentTypes": null, "id": 16, "name": "initialized", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1092:11:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1056:47:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "436f6e747261637420696e7374616e63652068617320616c7265616479206265656e20696e697469616c697a6564", "id": 19, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "1105:48:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_9fbba6c4dcac9134893b633b9564f36435b3f927c1d5fa152c5c14b20cecb1a4", "typeString": "literal_string \"Contract instance has already been initialized\"" }, "value": "Contract instance has already been initialized" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_9fbba6c4dcac9134893b633b9564f36435b3f927c1d5fa152c5c14b20cecb1a4", "typeString": "literal_string \"Contract instance has already been initialized\"" } ], "id": 11, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ -18, -18 ], "referencedDeclaration": -18, "src": "1048:7:0", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 20, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1048:106:0", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 21, "nodeType": "ExpressionStatement", "src": "1048:106:0" }, { "assignments": [ 23 ], "declarations": [ { "constant": false, "id": 23, "mutability": "mutable", "name": "isTopLevelCall", "nodeType": "VariableDeclaration", "overrides": null, "scope": 46, "src": "1161:19:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 22, "name": "bool", "nodeType": "ElementaryTypeName", "src": "1161:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "internal" } ], "id": 26, "initialValue": { "argumentTypes": null, "id": 25, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "UnaryOperation", "operator": "!", "prefix": true, "src": "1183:13:0", "subExpression": { "argumentTypes": null, "id": 24, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8, "src": "1184:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "VariableDeclarationStatement", "src": "1161:35:0" }, { "condition": { "argumentTypes": null, "id": 27, "name": "isTopLevelCall", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 23, "src": "1206:14:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 37, "nodeType": "IfStatement", "src": "1202:80:0", "trueBody": { "id": 36, "nodeType": "Block", "src": "1222:60:0", "statements": [ { "expression": { "argumentTypes": null, "id": 30, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 28, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8, "src": "1230:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "74727565", "id": 29, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1245:4:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "true" }, "src": "1230:19:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 31, "nodeType": "ExpressionStatement", "src": "1230:19:0" }, { "expression": { "argumentTypes": null, "id": 34, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 32, "name": "initialized", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5, "src": "1257:11:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "74727565", "id": 33, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1271:4:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "true" }, "src": "1257:18:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 35, "nodeType": "ExpressionStatement", "src": "1257:18:0" } ] } }, { "id": 38, "nodeType": "PlaceholderStatement", "src": "1288:1:0" }, { "condition": { "argumentTypes": null, "id": 39, "name": "isTopLevelCall", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 23, "src": "1300:14:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 45, "nodeType": "IfStatement", "src": "1296:55:0", "trueBody": { "id": 44, "nodeType": "Block", "src": "1316:35:0", "statements": [ { "expression": { "argumentTypes": null, "id": 42, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 40, "name": "initializing", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8, "src": "1324:12:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "66616c7365", "id": 41, "isConstant": false, "isLValue": false, "isPure": true, "kind": "bool", "lValueRequested": false, "nodeType": "Literal", "src": "1339:5:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "value": "false" }, "src": "1324:20:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 43, "nodeType": "ExpressionStatement", "src": "1324:20:0" } ] } } ] }, "documentation": { "id": 9, "nodeType": "StructuredDocumentation", "src": "938:78:0", "text": " @dev Modifier to use in the initializer function of a contract." }, "id": 47, "name": "initializer", "nodeType": "ModifierDefinition", "overrides": null, "parameters": { "id": 10, "nodeType": "ParameterList", "parameters": [], "src": "1039:2:0" }, "src": "1019:336:0", "virtual": false, "visibility": "internal" }, { "body": { "id": 68, "nodeType": "Block", "src": "1494:445:0", "statements": [ { "assignments": [ 54 ], "declarations": [ { "constant": false, "id": 54, "mutability": "mutable", "name": "self", "nodeType": "VariableDeclaration", "overrides": null, "scope": 68, "src": "1829:12:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 53, "name": "address", "nodeType": "ElementaryTypeName", "src": "1829:7:0", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "id": 59, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 57, "name": "this", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": -28, "src": "1852:4:0", "typeDescriptions": { "typeIdentifier": "t_contract$_Initializable_$74", "typeString": "contract Initializable" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_contract$_Initializable_$74", "typeString": "contract Initializable" } ], "id": 56, "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "nodeType": "ElementaryTypeNameExpression", "src": "1844:7:0", "typeDescriptions": { "typeIdentifier": "t_type$_t_address_$", "typeString": "type(address)" }, "typeName": { "id": 55, "name": "address", "nodeType": "ElementaryTypeName", "src": "1844:7:0", "typeDescriptions": { "typeIdentifier": null, "typeString": null } } }, "id": 58, "isConstant": false, "isLValue": false, "isPure": false, "kind": "typeConversion", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1844:13:0", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "VariableDeclarationStatement", "src": "1829:28:0" }, { "assignments": [ 61 ], "declarations": [ { "constant": false, "id": 61, "mutability": "mutable", "name": "cs", "nodeType": "VariableDeclaration", "overrides": null, "scope": 68, "src": "1863:10:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 60, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1863:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 62, "initialValue": null, "nodeType": "VariableDeclarationStatement", "src": "1863:10:0" }, { "AST": { "nodeType": "YulBlock", "src": "1888:27:0", "statements": [ { "nodeType": "YulAssignment", "src": "1890:23:0", "value": { "arguments": [ { "name": "self", "nodeType": "YulIdentifier", "src": "1908:4:0" } ], "functionName": { "name": "extcodesize", "nodeType": "YulIdentifier", "src": "1896:11:0" }, "nodeType": "YulFunctionCall", "src": "1896:17:0" }, "variableNames": [ { "name": "cs", "nodeType": "YulIdentifier", "src": "1890:2:0" } ] } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 61, "isOffset": false, "isSlot": false, "src": "1890:2:0", "valueSize": 1 }, { "declaration": 54, "isOffset": false, "isSlot": false, "src": "1908:4:0", "valueSize": 1 } ], "id": 63, "nodeType": "InlineAssembly", "src": "1879:36:0" }, { "expression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 66, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 64, "name": "cs", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 61, "src": "1927:2:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "==", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 65, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1933:1:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "1927:7:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "functionReturnParameters": 52, "id": 67, "nodeType": "Return", "src": "1920:14:0" } ] }, "documentation": { "id": 48, "nodeType": "StructuredDocumentation", "src": "1359:79:0", "text": "@dev Returns true if and only if the function is running in the constructor" }, "id": 69, "implemented": true, "kind": "function", "modifiers": [], "name": "isConstructor", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 49, "nodeType": "ParameterList", "parameters": [], "src": "1463:2:0" }, "returnParameters": { "id": 52, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 51, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "overrides": null, "scope": 69, "src": "1488:4:0", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 50, "name": "bool", "nodeType": "ElementaryTypeName", "src": "1488:4:0", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "value": null, "visibility": "internal" } ], "src": "1487:6:0" }, "scope": 74, "src": "1441:498:0", "stateMutability": "view", "virtual": false, "visibility": "private" }, { "constant": false, "id": 73, "mutability": "mutable", "name": "______gap", "nodeType": "VariableDeclaration", "overrides": null, "scope": 74, "src": "2014:29:0", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$50_storage", "typeString": "uint256[50]" }, "typeName": { "baseType": { "id": 70, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "2014:7:0", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 72, "length": { "argumentTypes": null, "hexValue": "3530", "id": 71, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "2022:2:0", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_50_by_1", "typeString": "int_const 50" }, "value": "50" }, "nodeType": "ArrayTypeName", "src": "2014:11:0", "typeDescriptions": { "typeIdentifier": "t_array$_t_uint256_$50_storage_ptr", "typeString": "uint256[50]" } }, "value": null, "visibility": "private" } ], "scope": 75, "src": "689:1357:0" } ], "src": "0:2047:0" }, "bytecode": "0x608060405234801560105760006000fd5b506015565b60488060226000396000f3fe608060405260043610600c575b60006000fdfea26469706673582212208ac8b0a530c1710f75a8971bd0c98fea045f74b51733bed5858be73243643d5f64736f6c634300060a0033", "deployedBytecode": "0x608060405260043610600c575b60006000fdfea26469706673582212208ac8b0a530c1710f75a8971bd0c98fea045f74b51733bed5858be73243643d5f64736f6c634300060a0033", "compiler": { "name": "solc", "version": "0.6.10+commit.00c0fcaf.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }