UNPKG

hardlydifficult-eth

Version:

A collection of reusable contracts and Javascript helpers for Ethereum.

1,111 lines (1,110 loc) 74.6 kB
{ "contractName": "Babylonian", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.6.10+commit.00c0fcaf\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"@uniswap/lib/contracts/libraries/Babylonian.sol\":\"Babylonian\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":2000000},\"remappings\":[]},\"sources\":{\"@uniswap/lib/contracts/libraries/Babylonian.sol\":{\"keccak256\":\"0x2799682d733a6ef3aae1dce7dbe2cff5513f0244e4abd07338fe7a45c8fd9733\",\"license\":\"GPL-3.0-or-later\",\"urls\":[\"bzz-raw://332968199300fe6025b9ad8f3d69f252ec2a3a092fa42a0ef7f2d1397f59a7e5\",\"dweb:/ipfs/Qme4wBzDwfHr7zHk8WrCwCpozpt4KHuDQSxfJTDoHL8Pdi\"]}},\"version\":1}", "bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207f2632875038b2ef30dfb71284fb8d364a140533ee395c666af1f2327c4f027664736f6c634300060a0033", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207f2632875038b2ef30dfb71284fb8d364a140533ee395c666af1f2327c4f027664736f6c634300060a0033", "immutableReferences": {}, "sourceMap": "210:350:2:-:0;;;;;;;;;;;;;;;;;;;;;;;;;", "deployedSourceMap": "210:350:2:-:0;;;;;;;;", "source": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity >=0.4.0;\n\n// computes square roots using the babylonian method\n// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method\nlibrary Babylonian {\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n // else z = 0\n }\n}\n", "sourcePath": "@uniswap/lib/contracts/libraries/Babylonian.sol", "ast": { "absolutePath": "@uniswap/lib/contracts/libraries/Babylonian.sol", "exportedSymbols": { "Babylonian": [ 489 ] }, "id": 490, "license": "GPL-3.0-or-later", "nodeType": "SourceUnit", "nodes": [ { "id": 434, "literals": [ "solidity", ">=", "0.4", ".0" ], "nodeType": "PragmaDirective", "src": "46:24:2" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 489, "linearizedBaseContracts": [ 489 ], "name": "Babylonian", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 487, "nodeType": "Block", "src": "294:264:2", "statements": [ { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 443, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 441, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 436, "src": "308:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">", "rightExpression": { "argumentTypes": null, "hexValue": "33", "id": 442, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "312:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_3_by_1", "typeString": "int_const 3" }, "value": "3" }, "src": "308:5:2", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 479, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 477, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 436, "src": "492:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 478, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "497:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "492:6:2", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 485, "nodeType": "IfStatement", "src": "488:42:2", "trueBody": { "id": 484, "nodeType": "Block", "src": "500:30:2", "statements": [ { "expression": { "argumentTypes": null, "id": 482, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 480, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 439, "src": "514:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "31", "id": 481, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "518:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "514:5:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 483, "nodeType": "ExpressionStatement", "src": "514:5:2" } ] } }, "id": 486, "nodeType": "IfStatement", "src": "304:226:2", "trueBody": { "id": 476, "nodeType": "Block", "src": "315:167:2", "statements": [ { "expression": { "argumentTypes": null, "id": 446, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 444, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 439, "src": "329:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 445, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 436, "src": "333:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "329:5:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 447, "nodeType": "ExpressionStatement", "src": "329:5:2" }, { "assignments": [ 449 ], "declarations": [ { "constant": false, "id": 449, "mutability": "mutable", "name": "x", "nodeType": "VariableDeclaration", "overrides": null, "scope": 476, "src": "348:9:2", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 448, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "348:7:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 455, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 454, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 452, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 450, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 436, "src": "360:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 451, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "364:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "360:5:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "+", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 453, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "368:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "360:9:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "348:21:2" }, { "body": { "id": 474, "nodeType": "Block", "src": "397:75:2", "statements": [ { "expression": { "argumentTypes": null, "id": 461, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 459, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 439, "src": "415:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 460, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 449, "src": "419:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "415:5:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 462, "nodeType": "ExpressionStatement", "src": "415:5:2" }, { "expression": { "argumentTypes": null, "id": 472, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 463, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 449, "src": "438:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 471, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 468, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 466, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 464, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 436, "src": "443:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "id": 465, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 449, "src": "447:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "443:5:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "+", "rightExpression": { "argumentTypes": null, "id": 467, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 449, "src": "451:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "443:9:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "id": 469, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "442:11:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 470, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "456:1:2", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "442:15:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "438:19:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 473, "nodeType": "ExpressionStatement", "src": "438:19:2" } ] }, "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 458, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 456, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 449, "src": "390:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "<", "rightExpression": { "argumentTypes": null, "id": 457, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 439, "src": "394:1:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "390:5:2", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 475, "nodeType": "WhileStatement", "src": "383:89:2" } ] } } ] }, "documentation": null, "id": 488, "implemented": true, "kind": "function", "modifiers": [], "name": "sqrt", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 437, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 436, "mutability": "mutable", "name": "y", "nodeType": "VariableDeclaration", "overrides": null, "scope": 488, "src": "249:9:2", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 435, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "249:7:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "src": "248:11:2" }, "returnParameters": { "id": 440, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 439, "mutability": "mutable", "name": "z", "nodeType": "VariableDeclaration", "overrides": null, "scope": 488, "src": "283:9:2", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 438, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "283:7:2", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "src": "282:11:2" }, "scope": 489, "src": "235:323:2", "stateMutability": "pure", "virtual": false, "visibility": "internal" } ], "scope": 490, "src": "210:350:2" } ], "src": "46:515:2" }, "legacyAST": { "attributes": { "absolutePath": "@uniswap/lib/contracts/libraries/Babylonian.sol", "exportedSymbols": { "Babylonian": [ 489 ] }, "license": "GPL-3.0-or-later" }, "children": [ { "attributes": { "literals": [ "solidity", ">=", "0.4", ".0" ] }, "id": 434, "name": "PragmaDirective", "src": "46:24:2" }, { "attributes": { "abstract": false, "baseContracts": [ null ], "contractDependencies": [ null ], "contractKind": "library", "documentation": null, "fullyImplemented": true, "linearizedBaseContracts": [ 489 ], "name": "Babylonian", "scope": 490 }, "children": [ { "attributes": { "documentation": null, "implemented": true, "isConstructor": false, "kind": "function", "modifiers": [ null ], "name": "sqrt", "overrides": null, "scope": 489, "stateMutability": "pure", "virtual": false, "visibility": "internal" }, "children": [ { "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "y", "overrides": null, "scope": 488, "stateVariable": false, "storageLocation": "default", "type": "uint256", "value": null, "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 435, "name": "ElementaryTypeName", "src": "249:7:2" } ], "id": 436, "name": "VariableDeclaration", "src": "249:9:2" } ], "id": 437, "name": "ParameterList", "src": "248:11:2" }, { "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "z", "overrides": null, "scope": 488, "stateVariable": false, "storageLocation": "default", "type": "uint256", "value": null, "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 438, "name": "ElementaryTypeName", "src": "283:7:2" } ], "id": 439, "name": "VariableDeclaration", "src": "283:9:2" } ], "id": 440, "name": "ParameterList", "src": "282:11:2" }, { "children": [ { "children": [ { "attributes": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": ">", "type": "bool" }, "children": [ { "attributes": { "argumentTypes": null, "overloadedDeclarations": [ null ], "referencedDeclaration": 436, "type": "uint256", "value": "y" }, "id": 441, "name": "Identifier", "src": "308:1:2" }, { "attributes": { "argumentTypes": null, "hexvalue": "33", "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "subdenomination": null, "token": "number", "type": "int_const 3", "value": "3" }, "id": 442, "name": "Literal", "src": "312:1:2" } ], "id": 443, "name": "BinaryOperation", "src": "308:5:2" }, { "children": [ { "children": [ { "attributes": { "argumentTypes": null, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": "=", "type": "uint256" }, "children": [ { "attributes": { "argumentTypes": null, "overloadedDeclarations": [ null ], "referencedDeclaration": 439, "type": "uint256", "value": "z" }, "id": 444, "name": "Identifier", "src": "329:1:2" }, { "attributes": { "argumentTypes": null, "overloadedDeclarations": [ null ], "referencedDeclaration": 436, "type": "uint256", "value": "y" }, "id": 445, "name": "Identifier", "src": "333:1:2" } ], "id": 446, "name": "Assignment", "src": "329:5:2" } ], "id": 447, "name": "ExpressionStatement", "src": "329:5:2" }, { "attributes": { "assignments": [ 449 ] }, "children": [ { "attributes": { "constant": false, "mutability": "mutable", "name": "x", "overrides": null, "scope": 476, "stateVariable": false, "storageLocation": "default", "type": "uint256", "value": null, "visibility": "internal" }, "children": [ { "attributes": { "name": "uint256", "type": "uint256" }, "id": 448, "name": "ElementaryTypeName", "src": "348:7:2" } ], "id": 449, "name": "VariableDeclaration", "src": "348:9:2" }, { "attributes": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": "+", "type": "uint256" }, "children": [ { "attributes": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "operator": "/", "type": "uint256" }, "children": [ { "attributes": { "argumentTypes": null, "overloadedDeclarations": [ null ], "referencedDeclaration": 436, "type": "uint256", "value": "y" }, "id": 450, "name": "Identifier", "src": "360:1:2" }, { "attributes": { "argumentTypes": null, "hexvalue": "32", "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "subdenomination": null, "token": "number", "type": "int_const 2", "value": "2" }, "id": 451, "name": "Literal", "src": "364:1:2" } ], "id": 452, "name": "BinaryOperation", "src": "360:5:2" }, { "attributes": { "argumentTypes": null, "hexvalue": "31", "isConstant": false, "isLValue": false, "isPure": true, "lValueRequested": false, "subdenomination": null, "token": "number", "type": "int_const 1",