UNPKG

moonwalkerswap-v2-periphery

Version:
916 lines (915 loc) 635 kB
{ "contractName": "MoonwalkerswapV2LiquidityMathLibrary", "abi": [], "metadata": "{\"compiler\":{\"version\":\"0.6.6+commit.6c089d02\"},\"language\":\"Solidity\",\"output\":{\"abi\":[],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2LiquidityMathLibrary.sol\":\"MoonwalkerswapV2LiquidityMathLibrary\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2Library.sol\":{\"keccak256\":\"0x159bee476db809637551ce5ad20be89ad14ea04cb5150cd0c0ec857e81d82c24\",\"urls\":[\"bzz-raw://41d88c1b2583bf07daf655dfebdae4ac77e8ee10b96ec860666f0dd5bfabdaab\",\"dweb:/ipfs/QmNi6c4r9JoJRbkvmB5bbmDKgwXTyuqoHLVESAekem3quu\"]},\"/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2LiquidityMathLibrary.sol\":{\"keccak256\":\"0x355113861dc69cdd15e7c18fb1d4c139ec269083ba083985680319049c237b84\",\"urls\":[\"bzz-raw://5837bb980e46863bae883f80005372bc9ede07859270095454c9ac9ee2e0dfef\",\"dweb:/ipfs/QmdSZs5vUjLpMWsEXSdHEoacCt26DLcZRSJ5exZQAVBXi8\"]},\"/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/SafeMath.sol\":{\"keccak256\":\"0x27f0ea82f879b3b01387b583e6d9d0ec858dca3b22b0aad173f8fbda06e761e1\",\"urls\":[\"bzz-raw://0db9cf37793eb7035f0bfced36323d240f0212150009c39a3a108701d9b50b6c\",\"dweb:/ipfs/QmUAdiG9XNcieXkKfiMB49zQqD34FbXFE15csV2KQzwEqg\"]},\"moonwalkerswap-libraries/contracts/libraries/Babylonian.sol\":{\"keccak256\":\"0xeb1c2a281a00f4660775f75ccfa1e51fbe1d75f86aeb9d0d297151ecdb900177\",\"urls\":[\"bzz-raw://68515f0265381bddfb1d1356ea10ce4e5784276fc09f197fcdcedfa5c75cc069\",\"dweb:/ipfs/QmXWVVPnuJwRUAu3Qpu1s7Fyc5WPQxmZPczVEe5cJ5wVHZ\"]},\"moonwalkerswap-libraries/contracts/libraries/FullMath.sol\":{\"keccak256\":\"0xc4ffcf28169f73fc9fdd1f82345d6d4fcccf3fd5aea83c133437c25e4e0950a9\",\"urls\":[\"bzz-raw://c9257a47501005f0a648bc4801ef4abc33843681aaf03a6d0c43d46b69e37407\",\"dweb:/ipfs/QmciHvDrqhxs5fjsrm9aNq29FZXpunMn17n2wWj83Zsh3B\"]},\"moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerFactory.sol\":{\"keccak256\":\"0xeb65ccec387520ac1b49bc1a9e0d317fd85f69c831c57f45b8bd753e3a670090\",\"urls\":[\"bzz-raw://d72d7d945689ad68b45feecc9fdeb9d66717ec1d99546a69094594f479c597bb\",\"dweb:/ipfs/QmW2XrR7vYWpKhUT9fqfzJ1YYWwFhQqDBM2ehi4FFZ7fE4\"]},\"moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerPair.sol\":{\"keccak256\":\"0x4c888477bfd9725859e9136902f4e0e2b00c1f60fa640083226cb04a2e6e2b2d\",\"urls\":[\"bzz-raw://6bdfa268dbce3f14b7a324c84094d2aa4b51764a344c61eb7e7d179ca54f6861\",\"dweb:/ipfs/QmcGAFVuybBuNyp8Woza32E8T1Dsh9nrrCgecmHEazFTx6\"]}},\"version\":1}", "bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220d4f101002ffd780a6179c3be6e54beb498f4f18043744131b43c0acc077db3e864736f6c63430006060033", "deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220d4f101002ffd780a6179c3be6e54beb498f4f18043744131b43c0acc077db3e864736f6c63430006060033", "immutableReferences": {}, "sourceMap": "533:5557:11:-:0;;132:2:-1;166:7;155:9;146:7;137:37;255:7;249:14;246:1;241:23;235:4;232:33;222:2;;269:9;222:2;293:9;290:1;283:20;323:4;314:7;306:22;347:7;338;331:24", "deployedSourceMap": "533:5557:11:-:0;;;;;;12:1:-1;9;2:12", "source": "pragma solidity >=0.5.0;\n\nimport 'moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerPair.sol';\nimport 'moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerFactory.sol';\nimport 'moonwalkerswap-libraries/contracts/libraries/Babylonian.sol';\nimport 'moonwalkerswap-libraries/contracts/libraries/FullMath.sol';\n\nimport './SafeMath.sol';\nimport './MoonwalkerswapV2Library.sol';\n\n// library containing some math for dealing with the liquidity shares of a pair, e.g. computing their exact value\n// in terms of the underlying tokens\nlibrary MoonwalkerswapV2LiquidityMathLibrary {\n using SafeMath for uint256;\n\n // computes the direction and magnitude of the profit-maximizing trade\n function computeProfitMaximizingTrade(\n uint256 truePriceTokenA,\n uint256 truePriceTokenB,\n uint256 reserveA,\n uint256 reserveB\n ) pure internal returns (bool aToB, uint256 amountIn) {\n aToB = FullMath.mulDiv(reserveA, truePriceTokenB, reserveB) < truePriceTokenA;\n\n uint256 invariant = reserveA.mul(reserveB);\n\n uint256 leftSide = Babylonian.sqrt(\n FullMath.mulDiv(\n invariant.mul(1000),\n aToB ? truePriceTokenA : truePriceTokenB,\n (aToB ? truePriceTokenB : truePriceTokenA).mul(997)\n )\n );\n uint256 rightSide = (aToB ? reserveA.mul(1000) : reserveB.mul(1000)) / 997;\n\n if (leftSide < rightSide) return (false, 0);\n\n // compute the amount that must be sent to move the price to the profit-maximizing price\n amountIn = leftSide.sub(rightSide);\n }\n\n // gets the reserves after an arbitrage moves the price to the profit-maximizing ratio given an externally observed true price\n function getReservesAfterArbitrage(\n address factory,\n address tokenA,\n address tokenB,\n uint256 truePriceTokenA,\n uint256 truePriceTokenB\n ) view internal returns (uint256 reserveA, uint256 reserveB) {\n // first get reserves before the swap\n (reserveA, reserveB) = MoonwalkerswapV2Library.getReserves(factory, tokenA, tokenB);\n\n require(reserveA > 0 && reserveB > 0, 'MoonwalkerswapV2ArbitrageLibrary: ZERO_PAIR_RESERVES');\n\n // then compute how much to swap to arb to the true price\n (bool aToB, uint256 amountIn) = computeProfitMaximizingTrade(truePriceTokenA, truePriceTokenB, reserveA, reserveB);\n\n if (amountIn == 0) {\n return (reserveA, reserveB);\n }\n\n // now affect the trade to the reserves\n if (aToB) {\n uint amountOut = MoonwalkerswapV2Library.getAmountOut(amountIn, reserveA, reserveB);\n reserveA += amountIn;\n reserveB -= amountOut;\n } else {\n uint amountOut = MoonwalkerswapV2Library.getAmountOut(amountIn, reserveB, reserveA);\n reserveB += amountIn;\n reserveA -= amountOut;\n }\n }\n\n // computes liquidity value given all the parameters of the pair\n function computeLiquidityValue(\n uint256 reservesA,\n uint256 reservesB,\n uint256 totalSupply,\n uint256 liquidityAmount,\n bool feeOn,\n uint kLast\n ) internal pure returns (uint256 tokenAAmount, uint256 tokenBAmount) {\n if (feeOn && kLast > 0) {\n uint rootK = Babylonian.sqrt(reservesA.mul(reservesB));\n uint rootKLast = Babylonian.sqrt(kLast);\n if (rootK > rootKLast) {\n uint numerator1 = totalSupply;\n uint numerator2 = rootK.sub(rootKLast);\n uint denominator = rootK.mul(5).add(rootKLast);\n uint feeLiquidity = FullMath.mulDiv(numerator1, numerator2, denominator);\n totalSupply = totalSupply.add(feeLiquidity);\n }\n }\n return (reservesA.mul(liquidityAmount) / totalSupply, reservesB.mul(liquidityAmount) / totalSupply);\n }\n\n // get all current parameters from the pair and compute value of a liquidity amount\n // **note this is subject to manipulation, e.g. sandwich attacks**. prefer passing a manipulation resistant price to\n // #getLiquidityValueAfterArbitrageToPrice\n function getLiquidityValue(\n address factory,\n address tokenA,\n address tokenB,\n uint256 liquidityAmount\n ) internal view returns (uint256 tokenAAmount, uint256 tokenBAmount) {\n (uint256 reservesA, uint256 reservesB) = MoonwalkerswapV2Library.getReserves(factory, tokenA, tokenB);\n IMoonwalkerPair pair = IMoonwalkerPair(MoonwalkerswapV2Library.pairFor(factory, tokenA, tokenB));\n bool feeOn = IMoonwalkerFactory(factory).feeTo() != address(0);\n uint kLast = feeOn ? pair.kLast() : 0;\n uint totalSupply = pair.totalSupply();\n return computeLiquidityValue(reservesA, reservesB, totalSupply, liquidityAmount, feeOn, kLast);\n }\n\n // given two tokens, tokenA and tokenB, and their \"true price\", i.e. the observed ratio of value of token A to token B,\n // and a liquidity amount, returns the value of the liquidity in terms of tokenA and tokenB\n function getLiquidityValueAfterArbitrageToPrice(\n address factory,\n address tokenA,\n address tokenB,\n uint256 truePriceTokenA,\n uint256 truePriceTokenB,\n uint256 liquidityAmount\n ) internal view returns (\n uint256 tokenAAmount,\n uint256 tokenBAmount\n ) {\n bool feeOn = IMoonwalkerFactory(factory).feeTo() != address(0);\n IMoonwalkerPair pair = IMoonwalkerPair(MoonwalkerswapV2Library.pairFor(factory, tokenA, tokenB));\n uint kLast = feeOn ? pair.kLast() : 0;\n uint totalSupply = pair.totalSupply();\n\n // this also checks that totalSupply > 0\n require(totalSupply >= liquidityAmount && liquidityAmount > 0, 'ComputeLiquidityValue: LIQUIDITY_AMOUNT');\n\n (uint reservesA, uint reservesB) = getReservesAfterArbitrage(factory, tokenA, tokenB, truePriceTokenA, truePriceTokenB);\n\n return computeLiquidityValue(reservesA, reservesB, totalSupply, liquidityAmount, feeOn, kLast);\n }\n}\n", "sourcePath": "/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2LiquidityMathLibrary.sol", "ast": { "absolutePath": "/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2LiquidityMathLibrary.sol", "exportedSymbols": { "MoonwalkerswapV2LiquidityMathLibrary": [ 5185 ] }, "id": 5186, "nodeType": "SourceUnit", "nodes": [ { "id": 4721, "literals": [ "solidity", ">=", "0.5", ".0" ], "nodeType": "PragmaDirective", "src": "0:24:11" }, { "absolutePath": "moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerPair.sol", "file": "moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerPair.sol", "id": 4722, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 8545, "src": "26:73:11", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerFactory.sol", "file": "moonwalkerswap-v2-core/contracts/interfaces/IMoonwalkerFactory.sol", "id": 4723, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 8303, "src": "100:76:11", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "moonwalkerswap-libraries/contracts/libraries/Babylonian.sol", "file": "moonwalkerswap-libraries/contracts/libraries/Babylonian.sol", "id": 4724, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 6952, "src": "177:69:11", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "moonwalkerswap-libraries/contracts/libraries/FullMath.sol", "file": "moonwalkerswap-libraries/contracts/libraries/FullMath.sol", "id": 4725, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 8080, "src": "247:67:11", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/SafeMath.sol", "file": "./SafeMath.sol", "id": 4726, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 5368, "src": "316:24:11", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "/Users/warrenmason/Documents/UniswapV3Contracts/Core/LiveContracts/Moonwalkerswap-v2-periphery/contracts/libraries/MoonwalkerswapV2Library.sol", "file": "./MoonwalkerswapV2Library.sol", "id": 4727, "nodeType": "ImportDirective", "scope": 5186, "sourceUnit": 4720, "src": "341:39:11", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [], "contractDependencies": [], "contractKind": "library", "documentation": null, "fullyImplemented": true, "id": 5185, "linearizedBaseContracts": [ 5185 ], "name": "MoonwalkerswapV2LiquidityMathLibrary", "nodeType": "ContractDefinition", "nodes": [ { "id": 4730, "libraryName": { "contractScope": null, "id": 4728, "name": "SafeMath", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 5367, "src": "590:8:11", "typeDescriptions": { "typeIdentifier": "t_contract$_SafeMath_$5367", "typeString": "library SafeMath" } }, "nodeType": "UsingForDirective", "src": "584:27:11", "typeName": { "id": 4729, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "603:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } }, { "body": { "id": 4819, "nodeType": "Block", "src": "906:689:11", "statements": [ { "expression": { "argumentTypes": null, "id": 4754, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 4745, "name": "aToB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4741, "src": "916:4:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 4753, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 4748, "name": "reserveA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4736, "src": "939:8:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, { "argumentTypes": null, "id": 4749, "name": "truePriceTokenB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4734, "src": "949:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, { "argumentTypes": null, "id": 4750, "name": "reserveB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4738, "src": "966:8:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" }, { "typeIdentifier": "t_uint256", "typeString": "uint256" }, { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "argumentTypes": null, "id": 4746, "name": "FullMath", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8079, "src": "923:8:11", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_FullMath_$8079_$", "typeString": "type(library FullMath)" } }, "id": 4747, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mulDiv", "nodeType": "MemberAccess", "referencedDeclaration": 8078, "src": "923:15:11", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$", "typeString": "function (uint256,uint256,uint256) pure returns (uint256)" } }, "id": 4751, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "923:52:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "BinaryOperation", "operator": "<", "rightExpression": { "argumentTypes": null, "id": 4752, "name": "truePriceTokenA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4732, "src": "978:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "src": "923:70:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "src": "916:77:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "id": 4755, "nodeType": "ExpressionStatement", "src": "916:77:11" }, { "assignments": [ 4757 ], "declarations": [ { "constant": false, "id": 4757, "mutability": "mutable", "name": "invariant", "nodeType": "VariableDeclaration", "overrides": null, "scope": 4819, "src": "1004:17:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 4756, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1004:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 4762, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 4760, "name": "reserveB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4738, "src": "1037:8:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "argumentTypes": null, "id": 4758, "name": "reserveA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4736, "src": "1024:8:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 4759, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mul", "nodeType": "MemberAccess", "referencedDeclaration": 5366, "src": "1024:12:11", "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": 4761, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1024:22:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "1004:42:11" }, { "assignments": [ 4764 ], "declarations": [ { "constant": false, "id": 4764, "mutability": "mutable", "name": "leftSide", "nodeType": "VariableDeclaration", "overrides": null, "scope": 4819, "src": "1057:16:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 4763, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1057:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 4787, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "31303030", "id": 4771, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1152:4:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1000_by_1", "typeString": "int_const 1000" }, "value": "1000" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_1000_by_1", "typeString": "int_const 1000" } ], "expression": { "argumentTypes": null, "id": 4769, "name": "invariant", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4757, "src": "1138:9:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 4770, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mul", "nodeType": "MemberAccess", "referencedDeclaration": 5366, "src": "1138:13:11", "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": 4772, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1138:19:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, { "argumentTypes": null, "condition": { "argumentTypes": null, "id": 4773, "name": "aToB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4741, "src": "1175:4:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseExpression": { "argumentTypes": null, "id": 4775, "name": "truePriceTokenB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4734, "src": "1200:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 4776, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "Conditional", "src": "1175:40:11", "trueExpression": { "argumentTypes": null, "id": 4774, "name": "truePriceTokenA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4732, "src": "1182:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "393937", "id": 4783, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1280:3:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_997_by_1", "typeString": "int_const 997" }, "value": "997" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_997_by_1", "typeString": "int_const 997" } ], "expression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "condition": { "argumentTypes": null, "id": 4777, "name": "aToB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4741, "src": "1234:4:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseExpression": { "argumentTypes": null, "id": 4779, "name": "truePriceTokenA", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4732, "src": "1259:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 4780, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "Conditional", "src": "1234:40:11", "trueExpression": { "argumentTypes": null, "id": 4778, "name": "truePriceTokenB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4734, "src": "1241:15:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "id": 4781, "isConstant": false, "isInlineArray": false, "isLValue": false, "isPure": false, "lValueRequested": false, "nodeType": "TupleExpression", "src": "1233:42:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "id": 4782, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mul", "nodeType": "MemberAccess", "referencedDeclaration": 5366, "src": "1233:46:11", "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": 4784, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1233:51:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" }, { "typeIdentifier": "t_uint256", "typeString": "uint256" }, { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "argumentTypes": null, "id": 4767, "name": "FullMath", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 8079, "src": "1105:8:11", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_FullMath_$8079_$", "typeString": "type(library FullMath)" } }, "id": 4768, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "mulDiv", "nodeType": "MemberAccess", "referencedDeclaration": 8078, "src": "1105:15:11", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$", "typeString": "function (uint256,uint256,uint256) pure returns (uint256)" } }, "id": 4785, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1105:193:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_uint256", "typeString": "uint256" } ], "expression": { "argumentTypes": null, "id": 4765, "name": "Babylonian", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 6951, "src": "1076:10:11", "typeDescriptions": { "typeIdentifier": "t_type$_t_contract$_Babylonian_$6951_$", "typeString": "type(library Babylonian)" } }, "id": 4766, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "memberName": "sqrt", "nodeType": "MemberAccess", "referencedDeclaration": 6950, "src": "1076:15:11", "typeDescriptions": { "typeIdentifier": "t_function_internal_pure$_t_uint256_$returns$_t_uint256_$", "typeString": "function (uint256) pure returns (uint256)" } }, "id": 4786, "isConstant": false, "isLValue": false, "isPure": false, "kind": "functionCall", "lValueRequested": false, "names": [], "nodeType": "FunctionCall", "src": "1076:232:11", "tryCall": false, "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "nodeType": "VariableDeclarationStatement", "src": "1057:251:11" }, { "assignments": [ 4789 ], "declarations": [ { "constant": false, "id": 4789, "mutability": "mutable", "name": "rightSide", "nodeType": "VariableDeclaration", "overrides": null, "scope": 4819, "src": "1318:17:11", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 4788, "name": "uint256", "nodeType": "ElementaryTypeName", "src": "1318:7:11", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" } ], "id": 4803, "initialValue": { "argumentTypes": null, "commonType": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "id": 4802, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftExpression": { "argumentTypes": null, "components": [ { "argumentTypes": null, "condition": { "argumentTypes": null, "id": 4790, "name": "aToB", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 4741, "src": "1339:4:11", "typeDescriptions": { "typeIdentifier": "t_bool", "typeString": "bool" } }, "falseExpression": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "hexValue": "31303030", "id": 4797, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "1380:4:11", "subdenomination": null, "typeDescriptions": { "typeIdentifier": "t_rational_1000_by_1", "typeString": "int_const 1000" }, "value": "1000" } ], "expression": { "argumentTypes": [ { "typeIdentifier": "t_rational_1000_by_1", "typeString": "int_const 1000" } ], "expression": { "argumentTypes": null, "id": 4795, "name": "reserveB",