UNPKG

@daostack/upgrades

Version:
901 lines (900 loc) 37.1 kB
{ "fileName": "BaseUpgradeabilityProxy.sol", "contractName": "BaseUpgradeabilityProxy", "source": "pragma solidity ^0.6.0;\n// SPDX-License-Identifier: MIT\n\nimport './Proxy.sol';\nimport '../utils/Address.sol';\n\n/**\n * @title BaseUpgradeabilityProxy\n * @dev This contract implements a proxy that allows to change the\n * implementation address to which it will delegate.\n * Such a change is called an implementation upgrade.\n */\ncontract BaseUpgradeabilityProxy is Proxy {\n /**\n * @dev Emitted when the implementation is upgraded.\n * @param implementation Address of the new implementation.\n */\n event Upgraded(address indexed implementation);\n\n /**\n * @dev Storage slot with the address of the current implementation.\n * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n * validated in the constructor.\n */\n bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n /**\n * @dev Returns the current implementation.\n * @return impl Address of the current implementation\n */\n function _implementation() internal view override returns (address impl) {\n bytes32 slot = IMPLEMENTATION_SLOT;\n assembly {\n impl := sload(slot)\n }\n }\n\n /**\n * @dev Upgrades the proxy to a new implementation.\n * @param newImplementation Address of the new implementation.\n */\n function _upgradeTo(address newImplementation) internal {\n _setImplementation(newImplementation);\n emit Upgraded(newImplementation);\n }\n\n /**\n * @dev Sets the implementation address of the proxy.\n * @param newImplementation Address of the new implementation.\n */\n function _setImplementation(address newImplementation) internal {\n require(OpenZeppelinUpgradesAddress.isContract(newImplementation), \"Cannot set a proxy implementation to a non-contract address\");\n\n bytes32 slot = IMPLEMENTATION_SLOT;\n\n assembly {\n sstore(slot, newImplementation)\n }\n }\n}\n", "sourcePath": "contracts/upgradeability/BaseUpgradeabilityProxy.sol", "sourceMap": "327:1554:36:-:0;;;;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "327:1554:36:-:0;;;;;;;;;;;;514:50:39;548:11;:9;:11;;:::i;:::-;514:50;327:1554:36;;459:51:39;494:11;:9;:11;;:::i;:::-;459:51;327:1554:36;2075:90:39;2111:15;:13;:15;;:::i;:::-;2132:28;2142:17;:15;:17;;:::i;:::-;2132:9;:28;;:::i;:::-;2075:90;:::o;1933:47::-;;:::o;995:165:36:-;1054:12;1074;810:66;1089:19;;1074:34;;1145:4;1139:11;1131:19;;1123:33;;;:::o;981:743:39:-;1283:14;1280:1;1277;1264:34;1479:1;1476;1460:14;1457:1;1441:14;1434:5;1421:60;1543:16;1540:1;1537;1522:38;1575:6;1635:1;1630:38;;;;1695:16;1692:1;1685:27;1568:146;;1630:38;1649:16;1646:1;1639:27;1568:146;;1048:672;;;:::o", "abi": [ { "anonymous": false, "inputs": [ { "indexed": true, "internalType": "address", "name": "implementation", "type": "address" } ], "name": "Upgraded", "type": "event" }, { "stateMutability": "payable", "type": "fallback" }, { "stateMutability": "payable", "type": "receive" } ], "ast": { "absolutePath": "contracts/upgradeability/BaseUpgradeabilityProxy.sol", "exportedSymbols": { "BaseUpgradeabilityProxy": [ 6064 ] }, "id": 6065, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 6001, "literals": [ "solidity", "^", "0.6", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:36" }, { "absolutePath": "contracts/upgradeability/Proxy.sol", "file": "./Proxy.sol", "id": 6002, "nodeType": "ImportDirective", "scope": 6065, "sourceUnit": 6258, "src": "57:21:36", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "contracts/utils/Address.sol", "file": "../utils/Address.sol", "id": 6003, "nodeType": "ImportDirective", "scope": 6065, "sourceUnit": 6775, "src": "79:30:36", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 6005, "name": "Proxy", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 6257, "src": "363:5:36", "typeDescriptions": { "typeIdentifier": "t_contract$_Proxy_$6257", "typeString": "contract Proxy" } }, "id": 6006, "nodeType": "InheritanceSpecifier", "src": "363:5:36" } ], "contractDependencies": [ 6257 ], "contractKind": "contract", "documentation": { "id": 6004, "nodeType": "StructuredDocumentation", "src": "111:215:36", "text": " @title BaseUpgradeabilityProxy\n @dev This contract implements a proxy that allows to change the\n implementation address to which it will delegate.\n Such a change is called an implementation upgrade." }, "fullyImplemented": true, "id": 6064, "linearizedBaseContracts": [ 6064, 6257 ], "name": "BaseUpgradeabilityProxy", "nodeType": "ContractDefinition", "nodes": [ { "anonymous": false, "documentation": { "id": 6007, "nodeType": "StructuredDocumentation", "src": "373:126:36", "text": " @dev Emitted when the implementation is upgraded.\n @param implementation Address of the new implementation." }, "id": 6011, "name": "Upgraded", "nodeType": "EventDefinition", "parameters": { "id": 6010, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6009, "indexed": true, "mutability": "mutable", "name": "implementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6011, "src": "517:30:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6008, "name": "address", "nodeType": "ElementaryTypeName", "src": "517:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "516:32:36" }, "src": "502:47:36" }, { "constant": true, "documentation": { "id": 6012, "nodeType": "StructuredDocumentation", "src": "553:206:36", "text": " @dev Storage slot with the address of the current implementation.\n This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n validated in the constructor." }, "id": 6015, "mutability": "constant", "name": "IMPLEMENTATION_SLOT", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6064, "src": "762:114:36", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 6013, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "762:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": { "argumentTypes": null, "hexValue": "307833363038393461313362613161333231303636376338323834393264623938646361336532303736636333373335613932306133636135303564333832626263", "id": 6014, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "810:66:36", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_24440054405305269366569402256811496959409073762505157381672968839269610695612_by_1", "typeString": "int_const 2444...(69 digits omitted)...5612" }, "value": "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" }, "visibility": "internal" }, { "baseFunctions": [ 6230 ], "body": { "id": 6027, "nodeType": "Block", "src": "1068:92:36", "statements": [ { "assignments": [ 6023 ], "declarations": [ { "constant": false, "id": 6023, "mutability": "mutable", "name": "slot", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6027, "src": "1074:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 6022, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1074:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 6025, "initialValue": { "argumentTypes": null, "id": 6024, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6015, "src": "1089:19:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1074:34:36" }, { "AST": { "nodeType": "YulBlock", "src": "1123:33:36", "statements": [ { "nodeType": "YulAssignment", "src": "1131:19:36", "value": { "arguments": [ { "name": "slot", "nodeType": "YulIdentifier", "src": "1145:4:36" } ], "functionName": { "name": "sload", "nodeType": "YulIdentifier", "src": "1139:5:36" }, "nodeType": "YulFunctionCall", "src": "1139:11:36" }, "variableNames": [ { "name": "impl", "nodeType": "YulIdentifier", "src": "1131:4:36" } ] } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 6020, "isOffset": false, "isSlot": false, "src": "1131:4:36", "valueSize": 1 }, { "declaration": 6023, "isOffset": false, "isSlot": false, "src": "1145:4:36", "valueSize": 1 } ], "id": 6026, "nodeType": "InlineAssembly", "src": "1114:42:36" } ] }, "documentation": { "id": 6016, "nodeType": "StructuredDocumentation", "src": "881:111:36", "text": " @dev Returns the current implementation.\n @return impl Address of the current implementation" }, "id": 6028, "implemented": true, "kind": "function", "modifiers": [], "name": "_implementation", "nodeType": "FunctionDefinition", "overrides": { "id": 6018, "nodeType": "OverrideSpecifier", "overrides": [], "src": "1036:8:36" }, "parameters": { "id": 6017, "nodeType": "ParameterList", "parameters": [], "src": "1019:2:36" }, "returnParameters": { "id": 6021, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6020, "mutability": "mutable", "name": "impl", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6028, "src": "1054:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6019, "name": "address", "nodeType": "ElementaryTypeName", "src": "1054:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1053:14:36" }, "scope": 6064, "src": "995:165:36", "stateMutability": "view", "virtual": false, "visibility": "internal" }, { "body": { "id": 6042, "nodeType": "Block", "src": "1351:86:36", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 6035, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6031, "src": "1376:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 6034, "name": "_setImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6063, "src": "1357:18:36", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 6036, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1357:37:36", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6037, "nodeType": "ExpressionStatement", "src": "1357:37:36" }, { "eventCall": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 6039, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6031, "src": "1414:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 6038, "name": "Upgraded", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6011, "src": "1405:8:36", "typeDescriptions": { "typeIdentifier": "t_function_event_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 6040, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1405:27:36", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6041, "nodeType": "EmitStatement", "src": "1400:32:36" } ] }, "documentation": { "id": 6029, "nodeType": "StructuredDocumentation", "src": "1164:128:36", "text": " @dev Upgrades the proxy to a new implementation.\n @param newImplementation Address of the new implementation." }, "id": 6043, "implemented": true, "kind": "function", "modifiers": [], "name": "_upgradeTo", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6032, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6031, "mutability": "mutable", "name": "newImplementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6043, "src": "1315:25:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6030, "name": "address", "nodeType": "ElementaryTypeName", "src": "1315:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1314:27:36" }, "returnParameters": { "id": 6033, "nodeType": "ParameterList", "parameters": [], "src": "1351:0:36" }, "scope": 6064, "src": "1295:142:36", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" }, { "body": { "id": 6062, "nodeType": "Block", "src": "1638:241:36", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 6052, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6046, "src": "1691:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "expression": { "argumentTypes": null, "id": 6050, "name": "OpenZeppelinUpgradesAddress", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6774, "src": "1652:27:36", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_OpenZeppelinUpgradesAddress_$6774_$", "typeString": "type(library OpenZeppelinUpgradesAddress)" } }, "id": 6051, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "isContract", "nodeType": "MemberAccess", "referencedDeclaration": 6773, "src": "1652:38:36", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$_t_address_$returns$_t_bool_$", "typeString": "function (address) view returns (bool)" } }, "id": 6053, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1652:57:36", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "43616e6e6f742073657420612070726f787920696d706c656d656e746174696f6e20746f2061206e6f6e2d636f6e74726163742061646472657373", "id": 6054, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "1711:61:36", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_stringliteral_b5145a64ce8c406e5785204fe5b300f0ceda96d6636350b38fdccb9cd8c0c37c", "typeString": "literal_string \"Cannot set a proxy implementation to a non-contract address\"" }, "value": "Cannot set a proxy implementation to a non-contract address" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_b5145a64ce8c406e5785204fe5b300f0ceda96d6636350b38fdccb9cd8c0c37c", "typeString": "literal_string \"Cannot set a proxy implementation to a non-contract address\"" } ], "id": 6049, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ -18, -18 ], "referencedDeclaration": -18, "src": "1644:7:36", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 6055, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1644:129:36", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6056, "nodeType": "ExpressionStatement", "src": "1644:129:36" }, { "assignments": [ 6058 ], "declarations": [ { "constant": false, "id": 6058, "mutability": "mutable", "name": "slot", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6062, "src": "1780:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 6057, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1780:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 6060, "initialValue": { "argumentTypes": null, "id": 6059, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6015, "src": "1795:19:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1780:34:36" }, { "AST": { "nodeType": "YulBlock", "src": "1830:45:36", "statements": [ { "expression": { "arguments": [ { "name": "slot", "nodeType": "YulIdentifier", "src": "1845:4:36" }, { "name": "newImplementation", "nodeType": "YulIdentifier", "src": "1851:17:36" } ], "functionName": { "name": "sstore", "nodeType": "YulIdentifier", "src": "1838:6:36" }, "nodeType": "YulFunctionCall", "src": "1838:31:36" }, "nodeType": "YulExpressionStatement", "src": "1838:31:36" } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 6046, "isOffset": false, "isSlot": false, "src": "1851:17:36", "valueSize": 1 }, { "declaration": 6058, "isOffset": false, "isSlot": false, "src": "1845:4:36", "valueSize": 1 } ], "id": 6061, "nodeType": "InlineAssembly", "src": "1821:54:36" } ] }, "documentation": { "id": 6044, "nodeType": "StructuredDocumentation", "src": "1441:130:36", "text": " @dev Sets the implementation address of the proxy.\n @param newImplementation Address of the new implementation." }, "id": 6063, "implemented": true, "kind": "function", "modifiers": [], "name": "_setImplementation", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6047, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6046, "mutability": "mutable", "name": "newImplementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6063, "src": "1602:25:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6045, "name": "address", "nodeType": "ElementaryTypeName", "src": "1602:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1601:27:36" }, "returnParameters": { "id": 6048, "nodeType": "ParameterList", "parameters": [], "src": "1638:0:36" }, "scope": 6064, "src": "1574:305:36", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" } ], "scope": 6065, "src": "327:1554:36" } ], "src": "0:1882:36" }, "bytecode": "0x60806040523480156100115760006000fd5b50610017565b60f4806100256000396000f3fe608060405260043610600c575b366020575b601d603063ffffffff16565b5b005b5b602d603063ffffffff16565b5b005b603c605763ffffffff16565b6054604a605a63ffffffff16565b608d63ffffffff16565b5b565b5b565b600060007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b905080549150505b90565b36600060003760006000366000845af43d600060003e806000811460b3573d6000f360b8565b3d6000fd5b50505b5056fea2646970667358221220c88730672ed25f2bae5914a7ccb062abedfe7e7426b61e31d06a01ea00de724664736f6c634300060a0033", "deployedBytecode": "0x608060405260043610600c575b366020575b601d603063ffffffff16565b5b005b5b602d603063ffffffff16565b5b005b603c605763ffffffff16565b6054604a605a63ffffffff16565b608d63ffffffff16565b5b565b5b565b600060007f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b905080549150505b90565b36600060003760006000366000845af43d600060003e806000811460b3573d6000f360b8565b3d6000fd5b50505b5056fea2646970667358221220c88730672ed25f2bae5914a7ccb062abedfe7e7426b61e31d06a01ea00de724664736f6c634300060a0033", "compiler": { "name": "solc", "version": "0.6.10+commit.00c0fcaf.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }