UNPKG

upgrades

Version:
901 lines (900 loc) 37.1 kB
{ "fileName": "ZosBaseUpgradeabilityProxy.sol", "contractName": "ZosBaseUpgradeabilityProxy", "source": "pragma solidity ^0.6.0;\n// SPDX-License-Identifier: MIT\n\nimport '../../upgradeability/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 ZosBaseUpgradeabilityProxy 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 \"org.zeppelinos.proxy.implementation\", and is\n * validated in the constructor.\n */\n bytes32 internal constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3;\n\n /**\n * @dev Returns the current implementation.\n * @return impl Address of the current implementation\n */\n function _implementation() internal override view 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/mocks/zos/ZosBaseUpgradeabilityProxy.sol", "sourceMap": "349:1548:29:-:0;;;;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "349:1548:29:-:0;;;;;;;;;;;;514:50:39;548:11;:9;:11;;:::i;:::-;514:50;349:1548:29;;459:51:39;494:11;:9;:11;;:::i;:::-;459:51;349:1548:29;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;1011:165:29:-;1070:12;1090;826:66;1105:19;;1090:34;;1161:4;1155:11;1147:19;;1139: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/mocks/zos/ZosBaseUpgradeabilityProxy.sol", "exportedSymbols": { "ZosBaseUpgradeabilityProxy": [ 5493 ] }, "id": 5494, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 5430, "literals": [ "solidity", "^", "0.6", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:29" }, { "absolutePath": "contracts/upgradeability/Proxy.sol", "file": "../../upgradeability/Proxy.sol", "id": 5431, "nodeType": "ImportDirective", "scope": 5494, "sourceUnit": 6258, "src": "57:40:29", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "contracts/utils/Address.sol", "file": "../../utils/Address.sol", "id": 5432, "nodeType": "ImportDirective", "scope": 5494, "sourceUnit": 6775, "src": "98:33:29", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 5434, "name": "Proxy", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 6257, "src": "388:5:29", "typeDescriptions": { "typeIdentifier": "t_contract$_Proxy_$6257", "typeString": "contract Proxy" } }, "id": 5435, "nodeType": "InheritanceSpecifier", "src": "388:5:29" } ], "contractDependencies": [ 6257 ], "contractKind": "contract", "documentation": { "id": 5433, "nodeType": "StructuredDocumentation", "src": "133:215:29", "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": 5493, "linearizedBaseContracts": [ 5493, 6257 ], "name": "ZosBaseUpgradeabilityProxy", "nodeType": "ContractDefinition", "nodes": [ { "anonymous": false, "documentation": { "id": 5436, "nodeType": "StructuredDocumentation", "src": "398:126:29", "text": " @dev Emitted when the implementation is upgraded.\n @param implementation Address of the new implementation." }, "id": 5440, "name": "Upgraded", "nodeType": "EventDefinition", "parameters": { "id": 5439, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5438, "indexed": true, "mutability": "mutable", "name": "implementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5440, "src": "542:30:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5437, "name": "address", "nodeType": "ElementaryTypeName", "src": "542:7:29", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "541:32:29" }, "src": "527:47:29" }, { "constant": true, "documentation": { "id": 5441, "nodeType": "StructuredDocumentation", "src": "578:197:29", "text": " @dev Storage slot with the address of the current implementation.\n This is the keccak-256 hash of \"org.zeppelinos.proxy.implementation\", and is\n validated in the constructor." }, "id": 5444, "mutability": "constant", "name": "IMPLEMENTATION_SLOT", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5493, "src": "778:114:29", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5442, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "778:7:29", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": { "argumentTypes": null, "hexValue": "307837303530633965306634636137363963363962643361386566373430626333373933346638653263303336653561373233666438656530343865643366386333", "id": 5443, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "826:66:29", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_50801780122331352337026042894847907698553222651959119521779622085092237899971_by_1", "typeString": "int_const 5080...(69 digits omitted)...9971" }, "value": "0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3" }, "visibility": "internal" }, { "baseFunctions": [ 6230 ], "body": { "id": 5456, "nodeType": "Block", "src": "1084:92:29", "statements": [ { "assignments": [ 5452 ], "declarations": [ { "constant": false, "id": 5452, "mutability": "mutable", "name": "slot", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5456, "src": "1090:12:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5451, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1090:7:29", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 5454, "initialValue": { "argumentTypes": null, "id": 5453, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5444, "src": "1105:19:29", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1090:34:29" }, { "AST": { "nodeType": "YulBlock", "src": "1139:33:29", "statements": [ { "nodeType": "YulAssignment", "src": "1147:19:29", "value": { "arguments": [ { "name": "slot", "nodeType": "YulIdentifier", "src": "1161:4:29" } ], "functionName": { "name": "sload", "nodeType": "YulIdentifier", "src": "1155:5:29" }, "nodeType": "YulFunctionCall", "src": "1155:11:29" }, "variableNames": [ { "name": "impl", "nodeType": "YulIdentifier", "src": "1147:4:29" } ] } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 5449, "isOffset": false, "isSlot": false, "src": "1147:4:29", "valueSize": 1 }, { "declaration": 5452, "isOffset": false, "isSlot": false, "src": "1161:4:29", "valueSize": 1 } ], "id": 5455, "nodeType": "InlineAssembly", "src": "1130:42:29" } ] }, "documentation": { "id": 5445, "nodeType": "StructuredDocumentation", "src": "897:111:29", "text": " @dev Returns the current implementation.\n @return impl Address of the current implementation" }, "id": 5457, "implemented": true, "kind": "function", "modifiers": [], "name": "_implementation", "nodeType": "FunctionDefinition", "overrides": { "id": 5447, "nodeType": "OverrideSpecifier", "overrides": [], "src": "1047:8:29" }, "parameters": { "id": 5446, "nodeType": "ParameterList", "parameters": [], "src": "1035:2:29" }, "returnParameters": { "id": 5450, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5449, "mutability": "mutable", "name": "impl", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5457, "src": "1070:12:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5448, "name": "address", "nodeType": "ElementaryTypeName", "src": "1070:7:29", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1069:14:29" }, "scope": 5493, "src": "1011:165:29", "stateMutability": "view", "virtual": false, "visibility": "internal" }, { "body": { "id": 5471, "nodeType": "Block", "src": "1367:86:29", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5464, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5460, "src": "1392:17:29", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 5463, "name": "_setImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5492, "src": "1373:18:29", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 5465, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1373:37:29", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5466, "nodeType": "ExpressionStatement", "src": "1373:37:29" }, { "eventCall": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5468, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5460, "src": "1430:17:29", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 5467, "name": "Upgraded", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5440, "src": "1421:8:29", "typeDescriptions": { "typeIdentifier": "t_function_event_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 5469, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1421:27:29", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5470, "nodeType": "EmitStatement", "src": "1416:32:29" } ] }, "documentation": { "id": 5458, "nodeType": "StructuredDocumentation", "src": "1180:128:29", "text": " @dev Upgrades the proxy to a new implementation.\n @param newImplementation Address of the new implementation." }, "id": 5472, "implemented": true, "kind": "function", "modifiers": [], "name": "_upgradeTo", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 5461, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5460, "mutability": "mutable", "name": "newImplementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5472, "src": "1331:25:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5459, "name": "address", "nodeType": "ElementaryTypeName", "src": "1331:7:29", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1330:27:29" }, "returnParameters": { "id": 5462, "nodeType": "ParameterList", "parameters": [], "src": "1367:0:29" }, "scope": 5493, "src": "1311:142:29", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" }, { "body": { "id": 5491, "nodeType": "Block", "src": "1654:241:29", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5481, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5475, "src": "1707:17:29", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "expression": { "argumentTypes": null, "id": 5479, "name": "OpenZeppelinUpgradesAddress", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6774, "src": "1668:27:29", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_OpenZeppelinUpgradesAddress_$6774_$", "typeString": "type(library OpenZeppelinUpgradesAddress)" } }, "id": 5480, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "isContract", "nodeType": "MemberAccess", "referencedDeclaration": 6773, "src": "1668:38:29", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$_t_address_$returns$_t_bool_$", "typeString": "function (address) view returns (bool)" } }, "id": 5482, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1668:57:29", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "43616e6e6f742073657420612070726f787920696d706c656d656e746174696f6e20746f2061206e6f6e2d636f6e74726163742061646472657373", "id": 5483, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "1727:61:29", "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": 5478, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ -18, -18 ], "referencedDeclaration": -18, "src": "1660:7:29", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 5484, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1660:129:29", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5485, "nodeType": "ExpressionStatement", "src": "1660:129:29" }, { "assignments": [ 5487 ], "declarations": [ { "constant": false, "id": 5487, "mutability": "mutable", "name": "slot", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5491, "src": "1796:12:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5486, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1796:7:29", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 5489, "initialValue": { "argumentTypes": null, "id": 5488, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5444, "src": "1811:19:29", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1796:34:29" }, { "AST": { "nodeType": "YulBlock", "src": "1846:45:29", "statements": [ { "expression": { "arguments": [ { "name": "slot", "nodeType": "YulIdentifier", "src": "1861:4:29" }, { "name": "newImplementation", "nodeType": "YulIdentifier", "src": "1867:17:29" } ], "functionName": { "name": "sstore", "nodeType": "YulIdentifier", "src": "1854:6:29" }, "nodeType": "YulFunctionCall", "src": "1854:31:29" }, "nodeType": "YulExpressionStatement", "src": "1854:31:29" } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 5475, "isOffset": false, "isSlot": false, "src": "1867:17:29", "valueSize": 1 }, { "declaration": 5487, "isOffset": false, "isSlot": false, "src": "1861:4:29", "valueSize": 1 } ], "id": 5490, "nodeType": "InlineAssembly", "src": "1837:54:29" } ] }, "documentation": { "id": 5473, "nodeType": "StructuredDocumentation", "src": "1457:130:29", "text": " @dev Sets the implementation address of the proxy.\n @param newImplementation Address of the new implementation." }, "id": 5492, "implemented": true, "kind": "function", "modifiers": [], "name": "_setImplementation", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 5476, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5475, "mutability": "mutable", "name": "newImplementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 5492, "src": "1618:25:29", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5474, "name": "address", "nodeType": "ElementaryTypeName", "src": "1618:7:29", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1617:27:29" }, "returnParameters": { "id": 5477, "nodeType": "ParameterList", "parameters": [], "src": "1654:0:29" }, "scope": 5493, "src": "1590:305:29", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" } ], "scope": 5494, "src": "349:1548:29" } ], "src": "0:1898:29" }, "bytecode": "0x60806040523480156100115760006000fd5b50610017565b60f4806100256000396000f3fe608060405260043610600c575b366020575b601d603063ffffffff16565b5b005b5b602d603063ffffffff16565b5b005b603c605763ffffffff16565b6054604a605a63ffffffff16565b608d63ffffffff16565b5b565b5b565b600060007f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c360001b905080549150505b90565b36600060003760006000366000845af43d600060003e806000811460b3573d6000f360b8565b3d6000fd5b50505b5056fea2646970667358221220d22e08cd9d9405a9d1703fc02760b9b912fc44f470ed937766c1d1f27953a6c664736f6c634300060a0033", "deployedBytecode": "0x608060405260043610600c575b366020575b601d603063ffffffff16565b5b005b5b602d603063ffffffff16565b5b005b603c605763ffffffff16565b6054604a605a63ffffffff16565b608d63ffffffff16565b5b565b5b565b600060007f7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c360001b905080549150505b90565b36600060003760006000366000845af43d600060003e806000811460b3573d6000f360b8565b3d6000fd5b50505b5056fea2646970667358221220d22e08cd9d9405a9d1703fc02760b9b912fc44f470ed937766c1d1f27953a6c664736f6c634300060a0033", "compiler": { "name": "solc", "version": "0.6.10+commit.00c0fcaf.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }