UNPKG

@openzeppelin/upgrades

Version:

JavaScript library for the OpenZeppelin smart contract platform

779 lines (778 loc) 32.1 kB
{ "fileName": "BaseUpgradeabilityProxy.sol", "contractName": "BaseUpgradeabilityProxy", "source": "pragma solidity ^0.5.0;\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 Address of the current implementation\n */\n function _implementation() internal 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/upgradeability/BaseUpgradeabilityProxy.sol", "sourceMap": "295:1540:36:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;295:1540:36;;;;;;;", "deployedSourceMap": "295:1540:36:-;;;453:11:39;:9;:11::i;:::-;295:1540:36;1952:90:39;1988:15;:13;:15::i;:::-;2009:28;2019:17;:15;:17::i;:::-;2009:9;:28::i;:::-;1952:90::o;1818:39::-;:::o;958:156:36:-;1008:12;1028;778:66;1043:19;;1028:34;;1099:4;1093:11;1085:19;;1077:33;;:::o;878:731:39:-;1180:12;1177:1;1174;1161:32;1370:1;1367;1353:12;1350:1;1334:14;1329:3;1316:56;1434:14;1431:1;1428;1413:36;1464:6;1524:1;1519:36;;;;1582:14;1579:1;1572:25;1519:36;1538:14;1535:1;1528:25", "abi": [ { "payable": true, "stateMutability": "payable", "type": "fallback" }, { "anonymous": false, "inputs": [ { "indexed": true, "name": "implementation", "type": "address" } ], "name": "Upgraded", "type": "event" } ], "ast": { "absolutePath": "contracts/upgradeability/BaseUpgradeabilityProxy.sol", "exportedSymbols": { "BaseUpgradeabilityProxy": [ 5747 ] }, "id": 5748, "nodeType": "SourceUnit", "nodes": [ { "id": 5691, "literals": [ "solidity", "^", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:36" }, { "absolutePath": "contracts/upgradeability/Proxy.sol", "file": "./Proxy.sol", "id": 5692, "nodeType": "ImportDirective", "scope": 5748, "sourceUnit": 5897, "src": "25:21:36", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "contracts/utils/Address.sol", "file": "../utils/Address.sol", "id": 5693, "nodeType": "ImportDirective", "scope": 5748, "sourceUnit": 6390, "src": "47:30:36", "symbolAliases": [], "unitAlias": "" }, { "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 5694, "name": "Proxy", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 5896, "src": "331:5:36", "typeDescriptions": { "typeIdentifier": "t_contract$_Proxy_$5896", "typeString": "contract Proxy" } }, "id": 5695, "nodeType": "InheritanceSpecifier", "src": "331:5:36" } ], "contractDependencies": [ 5896 ], "contractKind": "contract", "documentation": "@title BaseUpgradeabilityProxy\n@dev This contract implements a proxy that allows to change the\nimplementation address to which it will delegate.\nSuch a change is called an implementation upgrade.", "fullyImplemented": true, "id": 5747, "linearizedBaseContracts": [ 5747, 5896 ], "name": "BaseUpgradeabilityProxy", "nodeType": "ContractDefinition", "nodes": [ { "anonymous": false, "documentation": "@dev Emitted when the implementation is upgraded.\n@param implementation Address of the new implementation.", "id": 5699, "name": "Upgraded", "nodeType": "EventDefinition", "parameters": { "id": 5698, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5697, "indexed": true, "name": "implementation", "nodeType": "VariableDeclaration", "scope": 5699, "src": "485:30:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5696, "name": "address", "nodeType": "ElementaryTypeName", "src": "485:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "484:32:36" }, "src": "470:47:36" }, { "constant": true, "id": 5702, "name": "IMPLEMENTATION_SLOT", "nodeType": "VariableDeclaration", "scope": 5747, "src": "730:114:36", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5700, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "730:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": { "argumentTypes": null, "hexValue": "307833363038393461313362613161333231303636376338323834393264623938646361336532303736636333373335613932306133636135303564333832626263", "id": 5701, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "778:66:36", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_24440054405305269366569402256811496959409073762505157381672968839269610695612_by_1", "typeString": "int_const 2444...(69 digits omitted)...5612" }, "value": "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc" }, "visibility": "internal" }, { "body": { "id": 5712, "nodeType": "Block", "src": "1022:92:36", "statements": [ { "assignments": [ 5708 ], "declarations": [ { "constant": false, "id": 5708, "name": "slot", "nodeType": "VariableDeclaration", "scope": 5712, "src": "1028:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5707, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1028:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 5710, "initialValue": { "argumentTypes": null, "id": 5709, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5702, "src": "1043:19:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1028:34:36" }, { "externalReferences": [ { "impl": { "declaration": 5705, "isOffset": false, "isSlot": false, "src": "1085:4:36", "valueSize": 1 } }, { "slot": { "declaration": 5708, "isOffset": false, "isSlot": false, "src": "1099:4:36", "valueSize": 1 } } ], "id": 5711, "nodeType": "InlineAssembly", "operations": "{\n impl := sload(slot)\n}", "src": "1068:46:36" } ] }, "documentation": "@dev Returns the current implementation.\n@return Address of the current implementation", "id": 5713, "implemented": true, "kind": "function", "modifiers": [], "name": "_implementation", "nodeType": "FunctionDefinition", "parameters": { "id": 5703, "nodeType": "ParameterList", "parameters": [], "src": "982:2:36" }, "returnParameters": { "id": 5706, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5705, "name": "impl", "nodeType": "VariableDeclaration", "scope": 5713, "src": "1008:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5704, "name": "address", "nodeType": "ElementaryTypeName", "src": "1008:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1007:14:36" }, "scope": 5747, "src": "958:156:36", "stateMutability": "view", "superFunction": 5872, "visibility": "internal" }, { "body": { "id": 5726, "nodeType": "Block", "src": "1305:86:36", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5719, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5715, "src": "1330:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 5718, "name": "_setImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5746, "src": "1311:18:36", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 5720, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1311:37:36", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5721, "nodeType": "ExpressionStatement", "src": "1311:37:36" }, { "eventCall": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5723, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5715, "src": "1368:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 5722, "name": "Upgraded", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5699, "src": "1359:8:36", "typeDescriptions": { "typeIdentifier": "t_function_event_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 5724, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1359:27:36", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5725, "nodeType": "EmitStatement", "src": "1354:32:36" } ] }, "documentation": "@dev Upgrades the proxy to a new implementation.\n@param newImplementation Address of the new implementation.", "id": 5727, "implemented": true, "kind": "function", "modifiers": [], "name": "_upgradeTo", "nodeType": "FunctionDefinition", "parameters": { "id": 5716, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5715, "name": "newImplementation", "nodeType": "VariableDeclaration", "scope": 5727, "src": "1269:25:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5714, "name": "address", "nodeType": "ElementaryTypeName", "src": "1269:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1268:27:36" }, "returnParameters": { "id": 5717, "nodeType": "ParameterList", "parameters": [], "src": "1305:0:36" }, "scope": 5747, "src": "1249:142:36", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" }, { "body": { "id": 5745, "nodeType": "Block", "src": "1592:241:36", "statements": [ { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 5735, "name": "newImplementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5729, "src": "1645:17:36", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "expression": { "argumentTypes": null, "id": 5733, "name": "OpenZeppelinUpgradesAddress", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6389, "src": "1606:27:36", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_OpenZeppelinUpgradesAddress_$6389_$", "typeString": "type(library OpenZeppelinUpgradesAddress)" } }, "id": 5734, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "isContract", "nodeType": "MemberAccess", "referencedDeclaration": 6388, "src": "1606:38:36", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$_t_address_$returns$_t_bool_$", "typeString": "function (address) view returns (bool)" } }, "id": 5736, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1606:57:36", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "argumentTypes": null, "hexValue": "43616e6e6f742073657420612070726f787920696d706c656d656e746174696f6e20746f2061206e6f6e2d636f6e74726163742061646472657373", "id": 5737, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "1665: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": 5732, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ 6466, 6467 ], "referencedDeclaration": 6467, "src": "1598:7:36", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 5738, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1598:129:36", "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 5739, "nodeType": "ExpressionStatement", "src": "1598:129:36" }, { "assignments": [ 5741 ], "declarations": [ { "constant": false, "id": 5741, "name": "slot", "nodeType": "VariableDeclaration", "scope": 5745, "src": "1734:12:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" }, "typeName": { "id": 5740, "name": "bytes32", "nodeType": "ElementaryTypeName", "src": "1734:7:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "value": null, "visibility": "internal" } ], "id": 5743, "initialValue": { "argumentTypes": null, "id": 5742, "name": "IMPLEMENTATION_SLOT", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 5702, "src": "1749:19:36", "typeDescriptions": { "typeIdentifier": "t_bytes32", "typeString": "bytes32" } }, "nodeType": "VariableDeclarationStatement", "src": "1734:34:36" }, { "externalReferences": [ { "slot": { "declaration": 5741, "isOffset": false, "isSlot": false, "src": "1799:4:36", "valueSize": 1 } }, { "newImplementation": { "declaration": 5729, "isOffset": false, "isSlot": false, "src": "1805:17:36", "valueSize": 1 } } ], "id": 5744, "nodeType": "InlineAssembly", "operations": "{\n sstore(slot, newImplementation)\n}", "src": "1775:58:36" } ] }, "documentation": "@dev Sets the implementation address of the proxy.\n@param newImplementation Address of the new implementation.", "id": 5746, "implemented": true, "kind": "function", "modifiers": [], "name": "_setImplementation", "nodeType": "FunctionDefinition", "parameters": { "id": 5730, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 5729, "name": "newImplementation", "nodeType": "VariableDeclaration", "scope": 5746, "src": "1556:25:36", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 5728, "name": "address", "nodeType": "ElementaryTypeName", "src": "1556:7:36", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1555:27:36" }, "returnParameters": { "id": 5731, "nodeType": "ParameterList", "parameters": [], "src": "1592:0:36" }, "scope": 5747, "src": "1528:305:36", "stateMutability": "nonpayable", "superFunction": null, "visibility": "internal" } ], "scope": 5748, "src": "295:1540:36" } ], "src": "0:1836:36" }, "bytecode": "0x608060405234801561001057600080fd5b5060a48061001f6000396000f3fe6080604052600a600c565b005b60126020565b601e601a6022565b6053565b565b565b6000807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b9050805491505090565b3660008037600080366000845af43d6000803e80600081146073573d6000f35b3d6000fdfea165627a7a723058209e20dc00bd8e8f447bdd74b725d17794ae5565354dd55c87ebfbfd4c2c8d8d4d0029", "deployedBytecode": "0x6080604052600a600c565b005b60126020565b601e601a6022565b6053565b565b565b6000807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc60001b9050805491505090565b3660008037600080366000845af43d6000803e80600081146073573d6000f35b3d6000fdfea165627a7a723058209e20dc00bd8e8f447bdd74b725d17794ae5565354dd55c87ebfbfd4c2c8d8d4d0029", "compiler": { "name": "solc", "version": "0.5.3+commit.10d17f24.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }