UNPKG

@daostack/upgrades

Version:
809 lines (808 loc) 33 kB
{ "fileName": "Proxy.sol", "contractName": "Proxy", "source": "pragma solidity ^0.6.0;\n// SPDX-License-Identifier: MIT\n\n/**\n * @title Proxy\n * @dev Implements delegation of calls to other contracts, with proper\n * forwarding of return values and bubbling of failures.\n * It defines a fallback function that delegates all calls to the address\n * returned by the abstract _implementation() internal function.\n */\nabstract contract Proxy {\n /**\n * @dev Fallback function.\n * Implemented entirely in `_fallback`.\n */\n fallback () payable external {\n _fallback();\n }\n\n receive () payable external {\n _fallback();\n }\n\n /**\n * @return The Address of the implementation.\n */\n function _implementation() internal view virtual returns (address);\n\n /**\n * @dev Delegates execution to an implementation contract.\n * This is a low level function that doesn't return to its internal call site.\n * It will return to the external caller whatever the implementation returns.\n * @param implementation Address to delegate.\n */\n function _delegate(address implementation) internal {\n assembly {\n // Copy msg.data. We take full control of memory in this inline assembly\n // block because it will not return to Solidity code. We overwrite the\n // Solidity scratch pad at memory position 0.\n calldatacopy(0, 0, calldatasize())\n\n // Call the implementation.\n // out and outsize are 0 because we don't know the size yet.\n let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)\n\n // Copy the returned data.\n returndatacopy(0, 0, returndatasize())\n\n switch result\n // delegatecall returns 0 on error.\n case 0 { revert(0, returndatasize()) }\n default { return(0, returndatasize()) }\n }\n }\n\n /**\n * @dev Function that is run as the first thing in the fallback function.\n * Can be redefined in derived contracts to add functionality.\n * Redefinitions must call super._willFallback().\n */\n function _willFallback() internal virtual {\n }\n\n /**\n * @dev fallback implementation.\n * Extracted to enable manual triggering.\n */\n function _fallback() internal {\n _willFallback();\n _delegate(_implementation());\n }\n}\n", "sourcePath": "contracts/upgradeability/Proxy.sol", "sourceMap": "", "deployedSourceMap": "", "abi": [ { "stateMutability": "payable", "type": "fallback" }, { "stateMutability": "payable", "type": "receive" } ], "ast": { "absolutePath": "contracts/upgradeability/Proxy.sol", "exportedSymbols": { "Proxy": [ 6257 ] }, "id": 6258, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 6208, "literals": [ "solidity", "^", "0.6", ".0" ], "nodeType": "PragmaDirective", "src": "0:23:39" }, { "abstract": true, "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": { "id": 6209, "nodeType": "StructuredDocumentation", "src": "57:290:39", "text": " @title Proxy\n @dev Implements delegation of calls to other contracts, with proper\n forwarding of return values and bubbling of failures.\n It defines a fallback function that delegates all calls to the address\n returned by the abstract _implementation() internal function." }, "fullyImplemented": false, "id": 6257, "linearizedBaseContracts": [ 6257 ], "name": "Proxy", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 6216, "nodeType": "Block", "src": "488:22:39", "statements": [ { "expression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 6213, "name": "_fallback", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6256, "src": "494:9:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$__$returns$__$", "typeString": "function ()" } }, "id": 6214, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "494:11:39", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6215, "nodeType": "ExpressionStatement", "src": "494:11:39" } ] }, "documentation": { "id": 6210, "nodeType": "StructuredDocumentation", "src": "376:80:39", "text": " @dev Fallback function.\n Implemented entirely in `_fallback`." }, "id": 6217, "implemented": true, "kind": "fallback", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6211, "nodeType": "ParameterList", "parameters": [], "src": "468:2:39" }, "returnParameters": { "id": 6212, "nodeType": "ParameterList", "parameters": [], "src": "488:0:39" }, "scope": 6257, "src": "459:51:39", "stateMutability": "payable", "virtual": false, "visibility": "external" }, { "body": { "id": 6223, "nodeType": "Block", "src": "542:22:39", "statements": [ { "expression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 6220, "name": "_fallback", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6256, "src": "548:9:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$__$returns$__$", "typeString": "function ()" } }, "id": 6221, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "548:11:39", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6222, "nodeType": "ExpressionStatement", "src": "548:11:39" } ] }, "documentation": null, "id": 6224, "implemented": true, "kind": "receive", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6218, "nodeType": "ParameterList", "parameters": [], "src": "522:2:39" }, "returnParameters": { "id": 6219, "nodeType": "ParameterList", "parameters": [], "src": "542:0:39" }, "scope": 6257, "src": "514:50:39", "stateMutability": "payable", "virtual": false, "visibility": "external" }, { "body": null, "documentation": { "id": 6225, "nodeType": "StructuredDocumentation", "src": "568:57:39", "text": " @return The Address of the implementation." }, "id": 6230, "implemented": false, "kind": "function", "modifiers": [], "name": "_implementation", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6226, "nodeType": "ParameterList", "parameters": [], "src": "652:2:39" }, "returnParameters": { "id": 6229, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6228, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6230, "src": "686:7:39", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6227, "name": "address", "nodeType": "ElementaryTypeName", "src": "686:7:39", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "685:9:39" }, "scope": 6257, "src": "628:67:39", "stateMutability": "view", "virtual": true, "visibility": "internal" }, { "body": { "id": 6237, "nodeType": "Block", "src": "1033:691:39", "statements": [ { "AST": { "nodeType": "YulBlock", "src": "1048:672:39", "statements": [ { "expression": { "arguments": [ { "kind": "number", "nodeType": "YulLiteral", "src": "1277:1:39", "type": "", "value": "0" }, { "kind": "number", "nodeType": "YulLiteral", "src": "1280:1:39", "type": "", "value": "0" }, { "arguments": [], "functionName": { "name": "calldatasize", "nodeType": "YulIdentifier", "src": "1283:12:39" }, "nodeType": "YulFunctionCall", "src": "1283:14:39" } ], "functionName": { "name": "calldatacopy", "nodeType": "YulIdentifier", "src": "1264:12:39" }, "nodeType": "YulFunctionCall", "src": "1264:34:39" }, "nodeType": "YulExpressionStatement", "src": "1264:34:39" }, { "nodeType": "YulVariableDeclaration", "src": "1407:74:39", "value": { "arguments": [ { "arguments": [], "functionName": { "name": "gas", "nodeType": "YulIdentifier", "src": "1434:3:39" }, "nodeType": "YulFunctionCall", "src": "1434:5:39" }, { "name": "implementation", "nodeType": "YulIdentifier", "src": "1441:14:39" }, { "kind": "number", "nodeType": "YulLiteral", "src": "1457:1:39", "type": "", "value": "0" }, { "arguments": [], "functionName": { "name": "calldatasize", "nodeType": "YulIdentifier", "src": "1460:12:39" }, "nodeType": "YulFunctionCall", "src": "1460:14:39" }, { "kind": "number", "nodeType": "YulLiteral", "src": "1476:1:39", "type": "", "value": "0" }, { "kind": "number", "nodeType": "YulLiteral", "src": "1479:1:39", "type": "", "value": "0" } ], "functionName": { "name": "delegatecall", "nodeType": "YulIdentifier", "src": "1421:12:39" }, "nodeType": "YulFunctionCall", "src": "1421:60:39" }, "variables": [ { "name": "result", "nodeType": "YulTypedName", "src": "1411:6:39", "type": "" } ] }, { "expression": { "arguments": [ { "kind": "number", "nodeType": "YulLiteral", "src": "1537:1:39", "type": "", "value": "0" }, { "kind": "number", "nodeType": "YulLiteral", "src": "1540:1:39", "type": "", "value": "0" }, { "arguments": [], "functionName": { "name": "returndatasize", "nodeType": "YulIdentifier", "src": "1543:14:39" }, "nodeType": "YulFunctionCall", "src": "1543:16:39" } ], "functionName": { "name": "returndatacopy", "nodeType": "YulIdentifier", "src": "1522:14:39" }, "nodeType": "YulFunctionCall", "src": "1522:38:39" }, "nodeType": "YulExpressionStatement", "src": "1522:38:39" }, { "cases": [ { "body": { "nodeType": "YulBlock", "src": "1637:31:39", "statements": [ { "expression": { "arguments": [ { "kind": "number", "nodeType": "YulLiteral", "src": "1646:1:39", "type": "", "value": "0" }, { "arguments": [], "functionName": { "name": "returndatasize", "nodeType": "YulIdentifier", "src": "1649:14:39" }, "nodeType": "YulFunctionCall", "src": "1649:16:39" } ], "functionName": { "name": "revert", "nodeType": "YulIdentifier", "src": "1639:6:39" }, "nodeType": "YulFunctionCall", "src": "1639:27:39" }, "nodeType": "YulExpressionStatement", "src": "1639:27:39" } ] }, "nodeType": "YulCase", "src": "1630:38:39", "value": { "kind": "number", "nodeType": "YulLiteral", "src": "1635:1:39", "type": "", "value": "0" } }, { "body": { "nodeType": "YulBlock", "src": "1683:31:39", "statements": [ { "expression": { "arguments": [ { "kind": "number", "nodeType": "YulLiteral", "src": "1692:1:39", "type": "", "value": "0" }, { "arguments": [], "functionName": { "name": "returndatasize", "nodeType": "YulIdentifier", "src": "1695:14:39" }, "nodeType": "YulFunctionCall", "src": "1695:16:39" } ], "functionName": { "name": "return", "nodeType": "YulIdentifier", "src": "1685:6:39" }, "nodeType": "YulFunctionCall", "src": "1685:27:39" }, "nodeType": "YulExpressionStatement", "src": "1685:27:39" } ] }, "nodeType": "YulCase", "src": "1675:39:39", "value": "default" } ], "expression": { "name": "result", "nodeType": "YulIdentifier", "src": "1575:6:39" }, "nodeType": "YulSwitch", "src": "1568:146:39" } ] }, "evmVersion": "constantinople", "externalReferences": [ { "declaration": 6233, "isOffset": false, "isSlot": false, "src": "1441:14:39", "valueSize": 1 } ], "id": 6236, "nodeType": "InlineAssembly", "src": "1039:681:39" } ] }, "documentation": { "id": 6231, "nodeType": "StructuredDocumentation", "src": "699:279:39", "text": " @dev Delegates execution to an implementation contract.\n This is a low level function that doesn't return to its internal call site.\n It will return to the external caller whatever the implementation returns.\n @param implementation Address to delegate." }, "id": 6238, "implemented": true, "kind": "function", "modifiers": [], "name": "_delegate", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6234, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 6233, "mutability": "mutable", "name": "implementation", "nodeType": "VariableDeclaration", "overrides": null, "scope": 6238, "src": "1000:22:39", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 6232, "name": "address", "nodeType": "ElementaryTypeName", "src": "1000:7:39", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "999:24:39" }, "returnParameters": { "id": 6235, "nodeType": "ParameterList", "parameters": [], "src": "1033:0:39" }, "scope": 6257, "src": "981:743:39", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" }, { "body": { "id": 6242, "nodeType": "Block", "src": "1975:5:39", "statements": [] }, "documentation": { "id": 6239, "nodeType": "StructuredDocumentation", "src": "1728:202:39", "text": " @dev Function that is run as the first thing in the fallback function.\n Can be redefined in derived contracts to add functionality.\n Redefinitions must call super._willFallback()." }, "id": 6243, "implemented": true, "kind": "function", "modifiers": [], "name": "_willFallback", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6240, "nodeType": "ParameterList", "parameters": [], "src": "1955:2:39" }, "returnParameters": { "id": 6241, "nodeType": "ParameterList", "parameters": [], "src": "1975:0:39" }, "scope": 6257, "src": "1933:47:39", "stateMutability": "nonpayable", "virtual": true, "visibility": "internal" }, { "body": { "id": 6255, "nodeType": "Block", "src": "2105:60:39", "statements": [ { "expression": { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 6247, "name": "_willFallback", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6243, "src": "2111:13:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$__$returns$__$", "typeString": "function ()" } }, "id": 6248, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2111:15:39", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6249, "nodeType": "ExpressionStatement", "src": "2111:15:39" }, { "expression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [], "expression": { "argumentTypes": [], "id": 6251, "name": "_implementation", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6230, "src": "2142:15:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_view$__$returns$_t_address_$", "typeString": "function () view returns (address)" } }, "id": 6252, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2142:17:39", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_address", "typeString": "address" } ], "id": 6250, "name": "_delegate", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6238, "src": "2132:9:39", "typeDescriptions": { "typeIdentifier": "t_function_internal_nonpayable$_t_address_$returns$__$", "typeString": "function (address)" } }, "id": 6253, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2132:28:39", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6254, "nodeType": "ExpressionStatement", "src": "2132:28:39" } ] }, "documentation": { "id": 6244, "nodeType": "StructuredDocumentation", "src": "1984:88:39", "text": " @dev fallback implementation.\n Extracted to enable manual triggering." }, "id": 6256, "implemented": true, "kind": "function", "modifiers": [], "name": "_fallback", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 6245, "nodeType": "ParameterList", "parameters": [], "src": "2093:2:39" }, "returnParameters": { "id": 6246, "nodeType": "ParameterList", "parameters": [], "src": "2105:0:39" }, "scope": 6257, "src": "2075:90:39", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" } ], "scope": 6258, "src": "348:1819:39" } ], "src": "0:2168:39" }, "bytecode": "0x", "deployedBytecode": "0x", "compiler": { "name": "solc", "version": "0.6.10+commit.00c0fcaf.Emscripten.clang", "optimizer": {}, "evmVersion": "constantinople" } }