UNPKG

@sonicxchain/soxswap-periphery

Version:

Peripheral smart contracts for interacting with Soxswap

1,115 lines 68.1 kB
{ "contractName": "Babylonian", "abi": [], "bytecode": "0x604c602c600b82828239805160001a60731460008114601c57601e565bfe5b5030600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a7230582015761f47004194bd2a9036532065cc277630efdc051c44f706dcb8e625b7bd0b0029", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea165627a7a7230582015761f47004194bd2a9036532065cc277630efdc051c44f706dcb8e625b7bd0b0029", "sourceMap": "168:364:10:-;;132:2:-1;166:7;155:9;146:7;137:37;252:7;246:14;243:1;238:23;232:4;229:33;270:1;265:20;;;;222:63;;265:20;274:9;222:63;;298:9;295:1;288:20;328:4;319:7;311:22;352:7;343;336:24", "deployedSourceMap": "168:364:10:-;;;;;;;;", "source": "pragma solidity >=0.4.0;\r\n\r\n// computes square roots using the babylonian method\r\n// https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method\r\nlibrary Babylonian {\r\n function sqrt(uint256 y) internal pure returns (uint256 z) {\r\n if (y > 3) {\r\n z = y;\r\n uint256 x = y / 2 + 1;\r\n while (x < z) {\r\n z = x;\r\n x = (y / x + x) / 2;\r\n }\r\n } else if (y != 0) {\r\n z = 1;\r\n }\r\n // else z = 0\r\n }\r\n}\r\n", "sourcePath": "@sonicxchain\\soxswap-lib\\contracts\\libraries\\Babylonian.sol", "ast": { "absolutePath": "@sonicxchain/soxswap-lib/contracts/libraries/Babylonian.sol", "exportedSymbols": { "Babylonian": [ 3711 ] }, "id": 3712, "nodeType": "SourceUnit", "nodes": [ { "id": 3656, "literals": [ "solidity", ">=", "0.4", ".0" ], "nodeType": "PragmaDirective", "src": "0:24:10" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 3711, "linearizedBaseContracts": [ 3711 ], "name": "Babylonian", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 3709, "nodeType": "Block", "src": "253:276:10", "statements": [ { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3665, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3663, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "268:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">", "rightExpression": { "argumentTypes": null, "hexValue": "33", "id": 3664, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "272:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_3_by_1", "typeString": "int_const 3" }, "value": "3" }, "src": "268:5:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3701, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3699, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "459:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 3700, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "464:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "459:6:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 3707, "nodeType": "IfStatement", "src": "455:44:10", "trueBody": { "id": 3706, "nodeType": "Block", "src": "467:32:10", "statements": [ { "expression": { "argumentTypes": null, "id": 3704, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3702, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "482:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "31", "id": 3703, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "486:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "482:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3705, "nodeType": "ExpressionStatement", "src": "482:5:10" } ] } }, "id": 3708, "nodeType": "IfStatement", "src": "264:235:10", "trueBody": { "id": 3698, "nodeType": "Block", "src": "275:174:10", "statements": [ { "expression": { "argumentTypes": null, "id": 3668, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3666, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "290:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 3667, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "294:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "290:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3669, "nodeType": "ExpressionStatement", "src": "290:5:10" }, { "assignments": [ 3671 ], "declarations": [ { "constant": false, "id": 3671, "name": "x", "nodeType": "VariableDeclaration", "scope": 3698, "src": "310:9:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3670, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "310:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 3677, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3676, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3674, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3672, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "322:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 3673, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "326:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "322:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "+", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 3675, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "330:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "322:9:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "310:21:10" }, { "body": { "id": 3696, "nodeType": "Block", "src": "360:78:10", "statements": [ { "expression": { "argumentTypes": null, "id": 3683, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3681, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "379:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 3682, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3671, "src": "383:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "379:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3684, "nodeType": "ExpressionStatement", "src": "379:5:10" }, { "expression": { "argumentTypes": null, "id": 3694, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3685, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3671, "src": "403:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3693, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3690, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3688, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3686, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "408:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "id": 3687, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3671, "src": "412:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "408:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "+", "rightExpression": { "argumentTypes": null, "id": 3689, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3671, "src": "416:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "408:9:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "id": 3691, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "407:11:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 3692, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "421:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "407:15:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "403:19:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3695, "nodeType": "ExpressionStatement", "src": "403:19:10" } ] }, "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3680, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3678, "name": "x", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3671, "src": "353:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "<", "rightExpression": { "argumentTypes": null, "id": 3679, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "357:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "353:5:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 3697, "nodeType": "WhileStatement", "src": "346:92:10" } ] } } ] }, "documentation": null, "id": 3710, "implemented": true, "kind": "function", "modifiers": [], "name": "sqrt", "nodeType": "FunctionDefinition", "parameters": { "id": 3659, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 3658, "name": "y", "nodeType": "VariableDeclaration", "scope": 3710, "src": "208:9:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3657, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "208:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "src": "207:11:10" }, "returnParameters": { "id": 3662, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 3661, "name": "z", "nodeType": "VariableDeclaration", "scope": 3710, "src": "242:9:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3660, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "242:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "src": "241:11:10" }, "scope": 3711, "src": "194:335:10", "stateMutability": "pure", "superFunction": null, "visibility": "internal" } ], "scope": 3712, "src": "168:364:10" } ], "src": "0:534:10" }, "legacyAST": { "absolutePath": "@sonicxchain/soxswap-lib/contracts/libraries/Babylonian.sol", "exportedSymbols": { "Babylonian": [ 3711 ] }, "id": 3712, "nodeType": "SourceUnit", "nodes": [ { "id": 3656, "literals": [ "solidity", ">=", "0.4", ".0" ], "nodeType": "PragmaDirective", "src": "0:24:10" }, { "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 3711, "linearizedBaseContracts": [ 3711 ], "name": "Babylonian", "nodeType": "ContractDefinition", "nodes": [ { "body": { "id": 3709, "nodeType": "Block", "src": "253:276:10", "statements": [ { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3665, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3663, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "268:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": ">", "rightExpression": { "argumentTypes": null, "hexValue": "33", "id": 3664, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "272:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_3_by_1", "typeString": "int_const 3" }, "value": "3" }, "src": "268:5:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": { "condition": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3701, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3699, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "459:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "!=", "rightExpression": { "argumentTypes": null, "hexValue": "30", "id": 3700, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "464:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_0_by_1", "typeString": "int_const 0" }, "value": "0" }, "src": "459:6:10", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseBody": null, "id": 3707, "nodeType": "IfStatement", "src": "455:44:10", "trueBody": { "id": 3706, "nodeType": "Block", "src": "467:32:10", "statements": [ { "expression": { "argumentTypes": null, "id": 3704, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3702, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "482:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "hexValue": "31", "id": 3703, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "486:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1_by_1", "typeString": "int_const 1" }, "value": "1" }, "src": "482:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3705, "nodeType": "ExpressionStatement", "src": "482:5:10" } ] } }, "id": 3708, "nodeType": "IfStatement", "src": "264:235:10", "trueBody": { "id": 3698, "nodeType": "Block", "src": "275:174:10", "statements": [ { "expression": { "argumentTypes": null, "id": 3668, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 3666, "name": "z", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3661, "src": "290:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 3667, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "294:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "290:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 3669, "nodeType": "ExpressionStatement", "src": "290:5:10" }, { "assignments": [ 3671 ], "declarations": [ { "constant": false, "id": 3671, "name": "x", "nodeType": "VariableDeclaration", "scope": 3698, "src": "310:9:10", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 3670, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "310:7:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 3677, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3676, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 3674, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "id": 3672, "name": "y", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 3658, "src": "322:1:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "/", "rightExpression": { "argumentTypes": null, "hexValue": "32", "id": 3673, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "326:1:10", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_2_by_1", "typeString": "int_const 2" }, "value": "2" }, "src": "322:5:10", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "+", "rightExpression": { "argumentTypes": null, "hexValue": "31", "id": 3675, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "3