UNPKG

@andrekorol/kollateral

Version:

Typescript library for Kollateral, the flash loan building block

836 lines (835 loc) 77.6 kB
{ "contractName": "ExtendedMath", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.7.3+commit.9bfce1f6\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol\":\"ExtendedMath\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol\":{\"keccak256\":\"0x5ced249631b5dfe431f449d725d9f318b01ab0785306ca5e73cdf43760ab271a\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://3f3aef65abfcc02e451ad27a849caba0e6375abb26e28e7605928d19d561c3dd\",\"dweb:/ipfs/QmY5zMeH5x3QMS5xkxkY3DH4SDPWLGJyfPk1R8wPJXH9vr\"]},\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0xba96bc371ba999f452985a98717cca1e4c4abb598dc038a9a9c3db08129b1ba4\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://26e50e3f7b6482fb6f598f2e006994a74aa492687daa4b3eee7fd4fb5398ce7f\",\"dweb:/ipfs/QmZudqoPSkA4USLMFsBBmt19dDPZFS8aaAmL5R7pECXu6t\"]}},\"version\":1}", "bytecode": "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea264697066735822122087822d324e42172db97636784962ce5724bd2c135c0fbc0ea36317959473c8dd64736f6c63430007030033", "deployedBytecode": "0x6080604052600080fdfea264697066735822122087822d324e42172db97636784962ce5724bd2c135c0fbc0ea36317959473c8dd64736f6c63430007030033", "immutableReferences": {}, "generatedSources": [], "deployedGeneratedSources": [], "sourceMap": "718:340:8:-:0;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "718:340:8:-:0;;;;;", "source": "/*\n\n Copyright 2020 Kollateral LLC.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n*/\n\n// SPDX-License-Identifier: Apache-2.0\npragma solidity ^0.7.0;\n\nimport \"@openzeppelin/contracts/math/SafeMath.sol\";\n\ncontract ExtendedMath {\n using SafeMath for uint256;\n\n // divide a/b then optionally floor or ceiling\n function divAndRound(\n uint256 a,\n uint256 b,\n bool ceiling\n ) internal pure returns (uint256) {\n uint256 floor = a.div(b);\n return (ceiling && a.mod(b) != 0) ? floor.add(1) : floor;\n }\n}\n", "sourcePath": "/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol", "ast": { "absolutePath": "/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol", "exportedSymbols": { "ExtendedMath": [ 1506 ], "SafeMath": [ 5584 ] }, "id": 1507, "license": "Apache-2.0", "nodeType": "SourceUnit", "nodes": [ { "id": 1466, "literals": [ "solidity", "^", "0.7", ".0" ], "nodeType": "PragmaDirective", "src": "640:23:8" }, { "absolutePath": "@openzeppelin/contracts/math/SafeMath.sol", "file": "@openzeppelin/contracts/math/SafeMath.sol", "id": 1467, "nodeType": "ImportDirective", "scope": 1507, "sourceUnit": 5585, "src": "665:51:8", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "contract", "fullyImplemented": true, "id": 1506, "linearizedBaseContracts": [ 1506 ], "name": "ExtendedMath", "nodeType": "ContractDefinition", "nodes": [ { "id": 1470, "libraryName": { "id": 1468, "name": "SafeMath", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 5584, "src": "752:8:8", "typeDescriptions": { "typeIdentifier": "t_contract$_SafeMath_$5584", "typeString": "library SafeMath" } }, "nodeType": "UsingForDirective", "src": "746:27:8", "typeName": { "id": 1469, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "765:7:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } }, { "body": { "id": 1504, "nodeType": "Block", "src": "949:107:8", "statements": [ { "assignments": [ 1482 ], "declarations": [ { "constant": false, "id": 1482, "mutability": "mutable", "name": "floor", "nodeType": "VariableDeclaration", "scope": 1504, "src": "959:13:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1481, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "959:7:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" } ], "id": 1487, "initialValue": { "arguments": [ { "id": 1485, "name": "b", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1474, "src": "981:1:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "id": 1483, "name": "a", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1472, "src": "975:1:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 1484, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "div", "nodeType": "MemberAccess", "referencedDeclaration": 5514, "src": "975:5:8", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$returns$_t_uint256_$bound_to$_t_uint256_$", "typeString": "function (uint256,uint256) pure returns (uint256)" } }, "id": 1486, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "975:8:8", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "959:24:8" }, { "expression": { "condition": { "components": [ { "commonType": { "typeIdentifier": "t_bool", "typeString": "bool" }, "id": 1495, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "id": 1488, "name": "ceiling", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1476, "src": "1001:7:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "BinaryOperation", "operator": "&&", "rightExpression": { "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 1494, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "arguments": [ { "id": 1491, "name": "b", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1474, "src": "1018:1:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "id": 1489, "name": "a", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1472, "src": "1012:1:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 1490, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mod", "nodeType": "MemberAccess", "referencedDeclaration": 5559, "src": "1012:5:8", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$returns$_t_uint256_$bound_to$_t_uint256_$", "typeString": "function (uint256,uint256) pure returns (uint256)" } }, "id": 1492, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1012:8:8", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "hexValue": "30", "id": 1493, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1024:1:8", "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "1012:13:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "1001:24:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } } ], "id": 1496, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "1000:26:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseExpression": { "id": 1501, "name": "floor", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1482, "src": "1044:5:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 1502, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "Conditional", "src": "1000:49:8", "trueExpression": { "arguments": [ { "hexValue": "31", "id": 1499, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1039:1:8", "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" } ], "expression": { "id": 1497, "name": "floor", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 1482, "src": "1029:5:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 1498, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "add", "nodeType": "MemberAccess", "referencedDeclaration": 5417, "src": "1029:9:8", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$returns$_t_uint256_$bound_to$_t_uint256_$", "typeString": "function (uint256,uint256) pure returns (uint256)" } }, "id": 1500, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1029:12:8", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "functionReturnParameters": 1480, "id": 1503, "nodeType": "Return", "src": "993:56:8" } ] }, "id": 1505, "implemented": true, "kind": "function", "modifiers": [], "name": "divAndRound", "nodeType": "FunctionDefinition", "parameters": { "id": 1477, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1472, "mutability": "mutable", "name": "a", "nodeType": "VariableDeclaration", "scope": 1505, "src": "860:9:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1471, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "860:7:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" }, { "constant": false, "id": 1474, "mutability": "mutable", "name": "b", "nodeType": "VariableDeclaration", "scope": 1505, "src": "879:9:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1473, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "879:7:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" }, { "constant": false, "id": 1476, "mutability": "mutable", "name": "ceiling", "nodeType": "VariableDeclaration", "scope": 1505, "src": "898:12:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" }, "typeName": { "id": 1475, "name": "bool", "nodeType": "ElementaryTypeName", "src": "898:4:8", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "visibility": "internal" } ], "src": "850:66:8" }, "returnParameters": { "id": 1480, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 1479, "mutability": "mutable", "name": "", "nodeType": "VariableDeclaration", "scope": 1505, "src": "940:7:8", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 1478, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "940:7:8", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "visibility": "internal" } ], "src": "939:9:8" }, "scope": 1506, "src": "830:226:8", "stateMutability": "pure", "virtual": false, "visibility": "internal" } ], "scope": 1507, "src": "718:340:8" } ], "src": "640:419:8" }, "legacyAST": { "attributes": { "absolutePath": "/Users/andrekorol/src/kollateral/protocol/contracts/common/utils/ExtendedMath.sol", "exportedSymbols": { "ExtendedMath": [ 1506 ], "SafeMath": [ 5584 ] }, "license": "Apache-2.0" }, "children": [ { "attributes": { "literals": [ "solidity", "^", "0.7", ".0" ] }, "id": 1466, "name": "PragmaDirective", "src": "640:23:8" }, { "attributes": { "SourceUnit": 5585, "absolutePath": "@openzeppelin/contracts/math/SafeMath.sol", "file": "@openzeppelin/contracts/math/SafeMath.sol", "scope": 1507, "symbolAliases": [ null ], "unitAlias": "" }, "id": 1467, "name": "ImportDirective", "src": "665:51:8" }, { "attributes": { "abstract": false, "baseContracts": [ null ], "contractDependencies": [ null ], "contractKind": "contract", "fullyImplemented": true, "linearizedBaseContracts": [ 1506 ], "name": "ExtendedMath", "scope": 1507 }, "children": [ { "children": [ { "attributes": { "name": "SafeMath", "referencedDeclaration": 5584, "type": "library SafeMath" }, "id": 1468, "name": "UserDefinedTypeName", "src": "752:8:8" }, { "attributes": { "name": "uint256", "type": "uint256" }, "id": 1469, "name": "ElementaryTypeName", "src": "765:7:8" } ], "id": 1470, "name": "UsingForDirective", "src": "746:27:8" }, { "attributes": { "implemented": true, "isConstructor": false, "kind": "function", "modifiers": [ null ], "name": "divAndRound", "scope": 1506, "stateMutability": "pure", "virtual": false, "visibility": "internal" }, "children": [ { "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "a", "scope": 1505, "stateVariable": false, "storageLocation": "default", "type": "uint256", "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 1471, "name": "ElementaryTypeName", "src": "860:7:8" } ], "id": 1472, "name": "VariableDeclaration", "src": "860:9:8" }, { "attributes": { "constant": false, "mutability": "mutable", "name": "b", "scope": 1505, "stateVariable": false, "storageLocation": "default", "type": "uint256", "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 1473, "name": "ElementaryTypeName", "src": "879:7:8" } ], "id": 1474, "name": "VariableDeclaration", "src": "879:9:8" }, { "attributes": { "constant": false, "mutability": "mutable", "name": "ceiling", "scope": 1505, "stateVariable": false, "storageLocation": "default", "type": "bool", "visibility": "internal" }, "children": [ { "attributes": { "name": "bool", "type": "bool" }, "id": 1475, "name": "ElementaryTypeName", "src": "898:4:8" } ], "id": 1476, "name": "VariableDeclaration", "src": "898:12:8" } ], "id": 1477, "name": "ParameterList", "src": "850:66:8" }, { "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "", "scope": 1505, "stateVariable": false, "storageLocation": "default", "type": "uint256", "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 1478, "name": "ElementaryTypeName", "src": "940:7:8" } ], "id": 1479, "name": "VariableDeclaration", "src": "940:7:8" } ], "id": 1480, "name": "ParameterList", "src": "939:9:8" }, { "children": [ { "attributes": { "assignments": [ 1482 ] }, "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "floor", "scope": 1504, "stateVariable": false, "storageLocation": "default", "type": "uint256", "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 1481, "name": "ElementaryTypeName", "src": "959:7:8" } ], "id": 1482, "name": "VariableDeclaration", "src": "959:13:8" }, { "attributes": { "isConstant": false, "isLValue": false, "isPure": false, "isStructConstructorCall": false, "lValueRequested": false, "names": [