UNPKG

@andrekorol/kollateral

Version:

Typescript library for Kollateral, the flash loan building block

840 lines (839 loc) 60.1 kB
{ "contractName": "ReentrancyGuard", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.7.3+commit.9bfce1f6\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"details\":\"Contract module that helps prevent reentrant calls to a function. Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier available, which can be applied to functions to make sure there are no nested (reentrant) calls to them. Note that because there is a single `nonReentrant` guard, functions marked as `nonReentrant` may not call one another. This can be worked around by making those functions `private`, and then adding `external` `nonReentrant` entry points to them. TIP: If you would like to learn more about reentrancy and alternative ways to protect against it, check out our blog post https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\",\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"@openzeppelin/contracts/utils/ReentrancyGuard.sol\":\"ReentrancyGuard\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/utils/ReentrancyGuard.sol\":{\"keccak256\":\"0x1153f6dd334c01566417b8c551122450542a2b75a2bbb379d59a8c320ed6da28\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://002b4e5c26a2a069ba42486b83bf9c4b5461f3d5def32f9ef52b0aef8905d6d2\",\"dweb:/ipfs/QmPG44XDF4npiqRzzGvqJroDtUKfcR78wcreQ9bXa6guW6\"]}},\"version\":1}", "bytecode": "0x", "deployedBytecode": "0x", "immutableReferences": {}, "generatedSources": [], "deployedGeneratedSources": [], "sourceMap": "", "deployedSourceMap": "", "source": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.7.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor () {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and make it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n}\n", "sourcePath": "@openzeppelin/contracts/utils/ReentrancyGuard.sol", "ast": { "absolutePath": "@openzeppelin/contracts/utils/ReentrancyGuard.sol", "exportedSymbols": { "ReentrancyGuard": [ 6295 ] }, "id": 6296, "license": "MIT", "nodeType": "SourceUnit", "nodes": [ { "id": 6257, "literals": [ "solidity", "^", "0.7", ".0" ], "nodeType": "PragmaDirective", "src": "33:23:44" }, { "abstract": true, "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "documentation": { "id": 6258, "nodeType": "StructuredDocumentation", "src": "58:750:44", "text": " @dev Contract module that helps prevent reentrant calls to a function.\n Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n available, which can be applied to functions to make sure there are no nested\n (reentrant) calls to them.\n Note that because there is a single `nonReentrant` guard, functions marked as\n `nonReentrant` may not call one another. This can be worked around by making\n those functions `private`, and then adding `external` `nonReentrant` entry\n points to them.\n TIP: If you would like to learn more about reentrancy and alternative ways\n to protect against it, check out our blog post\n https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]." }, "fullyImplemented": true, "id": 6295, "linearizedBaseContracts": [ 6295 ], "name": "ReentrancyGuard", "nodeType": "ContractDefinition", "nodes": [ { "constant": true, "id": 6261, "mutability": "constant", "name": "_NOT_ENTERED", "nodeType": "VariableDeclaration", "scope": 6295, "src": "1597:41:44", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 6259, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1597:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "hexValue": "31", "id": 6260, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1637:1:44", "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "visibility": "private" }, { "constant": true, "id": 6264, "mutability": "constant", "name": "_ENTERED", "nodeType": "VariableDeclaration", "scope": 6295, "src": "1644:37:44", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 6262, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1644:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "hexValue": "32", "id": 6263, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1680:1:44", "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "visibility": "private" }, { "constant": false, "id": 6266, "mutability": "mutable", "name": "_status", "nodeType": "VariableDeclaration", "scope": 6295, "src": "1688:23:44", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 6265, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1688:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "private" }, { "body": { "id": 6273, "nodeType": "Block", "src": "1733:39:44", "statements": [ { "expression": { "id": 6271, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "id": 6269, "name": "_status", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6266, "src": "1743:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "id": 6270, "name": "_NOT_ENTERED", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6261, "src": "1753:12:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "1743:22:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 6272, "nodeType": "ExpressionStatement", "src": "1743:22:44" } ] }, "id": 6274, "implemented": true, "kind": "constructor", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "parameters": { "id": 6267, "nodeType": "ParameterList", "parameters": [], "src": "1730:2:44" }, "returnParameters": { "id": 6268, "nodeType": "ParameterList", "parameters": [], "src": "1733:0:44" }, "scope": 6295, "src": "1718:54:44", "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" }, { "body": { "id": 6293, "nodeType": "Block", "src": "2171:421:44", "statements": [ { "expression": { "arguments": [ { "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 6280, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "id": 6278, "name": "_status", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6266, "src": "2260:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "id": 6279, "name": "_ENTERED", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6264, "src": "2271:8:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "2260:19:44", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, { "hexValue": "5265656e7472616e637947756172643a207265656e7472616e742063616c6c", "id": 6281, "isConstant": false, "isLValue": false, "isPure": true, "kind": "string", "lValueRequested": false, "nodeType": "Literal", "src": "2281:33:44", "typeDescriptions": { "typeIdentifier": "t_stringliteral_ebf73bba305590e4764d5cb53b69bffd6d4d092d1a67551cb346f8cfcdab8619", "typeString": "literal_string \"ReentrancyGuard: reentrant call\"" }, "value": "ReentrancyGuard: reentrant call" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_ebf73bba305590e4764d5cb53b69bffd6d4d092d1a67551cb346f8cfcdab8619", "typeString": "literal_string \"ReentrancyGuard: reentrant call\"" } ], "id": 6277, "name": "require", "nodeType": "Identifier", "overloadedDeclarations": [ -18, -18 ], "referencedDeclaration": -18, "src": "2252:7:44", "typeDescriptions": { "typeIdentifier": "t_function_require_pure$_t_bool_$_t_string_memory_ptr_$returns$__$", "typeString": "function (bool,string memory) pure" } }, "id": 6282, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "2252:63:44", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_tuple$__$", "typeString": "tuple()" } }, "id": 6283, "nodeType": "ExpressionStatement", "src": "2252:63:44" }, { "expression": { "id": 6286, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "id": 6284, "name": "_status", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6266, "src": "2390:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "id": 6285, "name": "_ENTERED", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6264, "src": "2400:8:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "2390:18:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 6287, "nodeType": "ExpressionStatement", "src": "2390:18:44" }, { "id": 6288, "nodeType": "PlaceholderStatement", "src": "2419:1:44" }, { "expression": { "id": 6291, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "id": 6289, "name": "_status", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6266, "src": "2563:7:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "id": 6290, "name": "_NOT_ENTERED", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6261, "src": "2573:12:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "2563:22:44", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 6292, "nodeType": "ExpressionStatement", "src": "2563:22:44" } ] }, "documentation": { "id": 6275, "nodeType": "StructuredDocumentation", "src": "1778:364:44", "text": " @dev Prevents a contract from calling itself, directly or indirectly.\n Calling a `nonReentrant` function from another `nonReentrant`\n function is not supported. It is possible to prevent this from happening\n by making the `nonReentrant` function external, and make it call a\n `private` function that does the actual work." }, "id": 6294, "name": "nonReentrant", "nodeType": "ModifierDefinition", "parameters": { "id": 6276, "nodeType": "ParameterList", "parameters": [], "src": "2168:2:44" }, "src": "2147:445:44", "virtual": false, "visibility": "internal" } ], "scope": 6296, "src": "809:1785:44" } ], "src": "33:2562:44" }, "legacyAST": { "attributes": { "absolutePath": "@openzeppelin/contracts/utils/ReentrancyGuard.sol", "exportedSymbols": { "ReentrancyGuard": [ 6295 ] }, "license": "MIT" }, "children": [ { "attributes": { "literals": [ "solidity", "^", "0.7", ".0" ] }, "id": 6257, "name": "PragmaDirective", "src": "33:23:44" }, { "attributes": { "abstract": true, "baseContracts": [ null ], "contractDependencies": [ null ], "contractKind": "contract", "fullyImplemented": true, "linearizedBaseContracts": [ 6295 ], "name": "ReentrancyGuard", "scope": 6296 }, "children": [ { "attributes": { "text": " @dev Contract module that helps prevent reentrant calls to a function.\n Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n available, which can be applied to functions to make sure there are no nested\n (reentrant) calls to them.\n Note that because there is a single `nonReentrant` guard, functions marked as\n `nonReentrant` may not call one another. This can be worked around by making\n those functions `private`, and then adding `external` `nonReentrant` entry\n points to them.\n TIP: If you would like to learn more about reentrancy and alternative ways\n to protect against it, check out our blog post\n https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]." }, "id": 6258, "name": "StructuredDocumentation", "src": "58:750:44" }, { "attributes": { "constant": true, "mutability": "constant", "name": "_NOT_ENTERED", "scope": 6295, "stateVariable": true, "storageLocation": "default", "type": "uint256", "visibility": "private" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 6259, "name": "ElementaryTypeName", "src": "1597:7:44" }, { "attributes": { "hexvalue": "31", "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "token": "number", "type": "int_const 1", "value": "1" }, "id": 6260, "name": "Literal", "src": "1637:1:44" } ], "id": 6261, "name": "VariableDeclaration", "src": "1597:41:44" }, { "attributes": { "constant": true, "mutability": "constant", "name": "_ENTERED", "scope": 6295, "stateVariable": true, "storageLocation": "default", "type": "uint256", "visibility": "private" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 6262, "name": "ElementaryTypeName", "src": "1644:7:44" }, { "attributes": { "hexvalue": "32", "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "token": "number", "type": "int_const 2", "value": "2" }, "id": 6263, "name": "Literal", "src": "1680:1:44" } ], "id": 6264, "name": "VariableDeclaration", "src": "1644:37:44" }, { "attributes": { "constant": false, "mutability": "mutable", "name": "_status", "scope": 6295, "stateVariable": true, "storageLocation": "default", "type": "uint256", "visibility": "private" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 6265, "name": "ElementaryTypeName", "src": "1688:7:44" } ], "id": 6266, "name": "VariableDeclaration", "src": "1688:23:44" }, { "attributes": { "implemented": true, "isConstructor": true, "kind": "constructor", "modifiers": [ null ], "name": "", "scope": 6295, "stateMutability": "nonpayable", "virtual": false, "visibility": "internal" }, "children": [ { "attributes": { "parameters": [ null ] }, "children": [], "id": 6267, "name": "ParameterList", "src": "1730:2:44" }, { "attributes": { "parameters": [ null ] }, "children": [], "id": 6268, "name": "ParameterList", "src": "1733:0:44" }, { "children": [ { "children": [ { "attributes": { "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": "=", "type": "uint256" }, "children": [ { "attributes": { "overloadedDeclarations": [ null ], "referencedDeclaration": 6266, "type": "uint256", "value": "_status" }, "id": 6269, "name": "Identifier", "src": "1743:7:44" }, { "attributes": { "overloadedDeclarations": [ null ], "referencedDeclaration": 6261, "type": "uint256", "value": "_NOT_ENTERED" }, "id": 6270, "name": "Identifier", "src": "1753:12:44" } ], "id": 6271, "name": "Assignment", "src": "1743:22:44" } ], "id": 6272, "name": "ExpressionStatement", "src": "1743:22:44" } ], "id": 6273, "name": "Block", "src": "1733:39:44" } ], "id": 6274, "name": "FunctionDefinition", "src": "1718:54:44" }, { "attributes": { "name": "nonReentrant", "virtual": false, "visibility": "internal" }, "children": [ { "attributes": { "text": " @dev Prevents a contract from calling itself, directly or indirectly.\n Calling a `nonReentrant` function from another `nonReentrant`\n function is not supported. It is possible to prevent this from happening\n by making the `nonReentrant` function external, and make it call a\n `private` function that does the actual work." }, "id": 6275, "name": "StructuredDocumentation", "src": "1778:364:44" }, { "attributes": { "parameters": [ null ] }, "children": [], "id": 6276, "name": "ParameterList", "src": "2168:2:44" }, { "children": [ { "children": [ { "attributes": { "isConstant": false, "isLValue": false, "isPure": false, "isStructConstructorCall": false, "lValueRequested": false, "names": [ null ], "tryCall": false, "type": "tuple()", "type_conversion": false }, "children": [ { "attributes": { "argumentTypes": [ { "typeIdentifier": "t_bool", "typeString": "bool" }, { "typeIdentifier": "t_stringliteral_ebf73bba305590e4764d5cb53b69bffd6d4d092d1a67551cb346f8cfcdab8619", "typeString": "literal_string \"ReentrancyGuard: reentrant call\"" } ], "overloadedDeclarations": [ -18, -18 ], "referencedDeclaration": -18, "type": "function (bool,string memory) pure", "value": "require" }, "id": 6277, "name": "Identifier", "src": "2252:7:44" }, { "attributes": { "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": "!=", "type": "bool" }, "children": [ { "attributes": { "overloadedDeclarations": [ null ], "referencedDeclaration": 6266, "type": "uint256", "value": "_status" }, "id": 6278, "name": "Identifier", "src": "2260:7:44" }, { "attributes": { "overloadedDeclarations": [ null ], "referencedDeclaration": 6264, "type": "uint256", "value": "_ENTERED" }, "id": 6279, "name": "Identifier", "src": "2271:8:44" } ], "id": 6280, "name": "BinaryOperation", "src": "2260:19:44" },