Error: Returned values aren't valid, did it run Out of Gas?

0
open
markpatx
markpatx
Posted 4 months ago

Error: Returned values aren't valid, did it run Out of Gas? #11

Hello, I was trying your code but was getting this error:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.

I traced it down to computeProfitMaximizingTrade, I made a simplified single file to test it:

const Web3 = require('web3')
const UniswapV2Pair = {"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint112","name":"reserve0","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"reserve1","type":"uint112"}],"name":"Sync","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_LIQUIDITY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReserves","outputs":[{"internalType":"uint112","name":"reserve0","type":"uint112"},{"internalType":"uint112","name":"reserve1","type":"uint112"},{"internalType":"uint32","name":"blockTimestampLast","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"kLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"price0CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price1CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Out","type":"uint256"},{"internalType":"uint256","name":"amount1Out","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"sync","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"evm":{"bytecode":{"linkReferences":{},"object":"","opcodes":"","sourceMap":""},"deployedBytecode":{"immutableReferences":{},"linkReferences":{},"object":"","opcodes":"","sourceMap":""}},"interface":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount0In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1In","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount0Out","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1Out","type":"uint256"},{"indexed":true,"internalType":"address","name":"to","type":"address"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint112","name":"reserve0","type":"uint112"},{"indexed":false,"internalType":"uint112","name":"reserve1","type":"uint112"}],"name":"Sync","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_LIQUIDITY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"burn","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getReserves","outputs":[{"internalType":"uint112","name":"reserve0","type":"uint112"},{"internalType":"uint112","name":"reserve1","type":"uint112"},{"internalType":"uint32","name":"blockTimestampLast","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"kLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"price0CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price1CumulativeLast","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"skim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Out","type":"uint256"},{"internalType":"uint256","name":"amount1Out","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"sync","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":""};
const UniswapV2Factory = {"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"setFeeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],"evm":{"bytecode":{"linkReferences":{},"object":"","opcodes":"","sourceMap":""},"deployedBytecode":{"linkReferences":{},"object":"","opcodes":"","sourceMap":""}},"interface":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"setFeeTo","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"setFeeToSetter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}],"bytecode":""};
const IERC20 = {"abi":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"evm":{"bytecode":{"linkReferences":{},"object":"","opcodes":"","sourceMap":""},"deployedBytecode":{"immutableReferences":{},"linkReferences":{},"object":"","opcodes":"","sourceMap":""}},"interface":[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"bytecode":""};
const Utils = {"contractName":"Utils","abi":[{"inputs":[{"internalType":"uint256","name":"truePriceTokenA","type":"uint256"},{"internalType":"uint256","name":"truePriceTokenB","type":"uint256"},{"internalType":"uint256","name":"reserveA","type":"uint256"},{"internalType":"uint256","name":"reserveB","type":"uint256"}],"name":"computeProfitMaximizingTrade","outputs":[{"internalType":"bool","name":"aToB","type":"bool"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"stateMutability":"pure","type":"function"}],"metadata":"{\"compiler\":{\"version\":\"0.6.6+commit.6c089d02\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"truePriceTokenA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"truePriceTokenB\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"reserveA\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"reserveB\",\"type\":\"uint256\"}],\"name\":\"computeProfitMaximizingTrade\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"aToB\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"amountIn\",\"type\":\"uint256\"}],\"stateMutability\":\"pure\",\"type\":\"function\"}],\"devdoc\":{\"methods\":{}},\"userdoc\":{\"methods\":{}}},\"settings\":{\"compilationTarget\":{\"/home/sammy/ropsten/contracts/Utils.sol\":\"Utils\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":false,\"runs\":200},\"remappings\":[]},\"sources\":{\"/home/sammy/ropsten/contracts/FullMath.sol\":{\"keccak256\":\"0xecdaf7f1163d8a3060d5c2c556f987196dc06b89dc2ed1c75423a380b94845cd\",\"urls\":[\"bzz-raw://cd753f0a5e0f9b6b5e167d4f66750b21a00dfa737bb5c0259155c6e413d865c6\",\"dweb:/ipfs/QmVrsaNiaLTa1ojjr7V9DspDcoDvRL5EkP9WZENyHCji2Q\"]},\"/home/sammy/ropsten/contracts/Utils.sol\":{\"keccak256\":\"0x2ee7c57c844797d8c3177c4975dfc8246955ae6f9c43daf55e17b49a0fb9fa53\",\"urls\":[\"bzz-raw://6d2921272cf1d1873fd689d4a38005ac6067cfb60a3e8f9108d9d6d49c71974d\",\"dweb:/ipfs/QmRdJMBTEjat2SzJt5nDtgBsvPbFHc2jmHC3be3SqxMk9s\"]},\"@uniswap/lib/contracts/libraries/Babylonian.sol\":{\"keccak256\":\"0xe20fc48e3575b4a2932e5d2dd53b6742e1ca96f652bd41038cb89d7f5d49a096\",\"urls\":[\"bzz-raw://6ba298d8e592d39960eabc2328b7d4a01ad6cf8b06366adc3ef0133d3b196a9f\",\"dweb:/ipfs/QmQgrNaHssJ8XVsPUCMHpyYRFLbBqNrumaoFgXHWdDiTyy\"]},\"@uniswap/v2-periphery/contracts/libraries/SafeMath.sol\":{\"keccak256\":\"0x27f0ea82f879b3b01387b583e6d9d0ec858dca3b22b0aad173f8fbda06e761e1\",\"urls\":[\"bzz-raw://0db9cf37793eb7035f0bfced36323d240f0212150009c39a3a108701d9b50b6c\",\"dweb:/ipfs/QmUAdiG9XNcieXkKfiMB49zQqD34FbXFE15csV2KQzwEqg\"]}},\"version\":1}","bytecode":"0x608060405234801561001057600080fd5b5061051b806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063fa65315414610030575b600080fd5b61007a6004803603608081101561004657600080fd5b810190808035906020019092919080359060200190929190803590602001909291908035906020019092919050505061009b565b60405180831515151581526020018281526020019250505060405180910390f35b600080856100aa85878661019b565b10915060006100c2848661027b90919063ffffffff16565b905060006101196101146100e16103e88561027b90919063ffffffff16565b866100ec57896100ee565b8a5b61010f6103e5896100ff578d610101565b8c5b61027b90919063ffffffff16565b61019b565b610310565b905060006103e58561013f5761013a6103e88861027b90919063ffffffff16565b610155565b6101546103e88961027b90919063ffffffff16565b5b8161015c57fe5b049050808210156101795760008080905094509450505050610192565b61018c818361037290919063ffffffff16565b93505050505b94509492505050565b60008060006101aa86866103f5565b91509150600084806101b857fe5b8688099050828111156101cc576001820391505b808303925060008214156101ee578483816101e357fe5b049350505050610274565b848210610263576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f46756c6c4d6174683a2046554c4c4449565f4f564552464c4f5700000000000081525060200191505060405180910390fd5b61026e838387610448565b93505050505b9392505050565b600080821480610298575082828385029250828161029557fe5b04145b61030a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f64732d6d6174682d6d756c2d6f766572666c6f7700000000000000000000000081525060200191505060405180910390fd5b92915050565b6000600382111561035f57819050600060016002848161032c57fe5b040190505b818110156103595780915060028182858161034857fe5b04018161035157fe5b049050610331565b5061036d565b6000821461036c57600190505b5b919050565b60008282840391508111156103ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f64732d6d6174682d7375622d756e646572666c6f77000000000000000000000081525060200191505060405180910390fd5b92915050565b60008060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8061042257fe5b84860990508385029250828103915082811015610440576001820391505b509250929050565b600080826000038316905080838161045c57fe5b04925080858161046857fe5b049450600181826000038161047957fe5b0401840285019450600060019050808402600203810290508084026002038102905080840260020381029050808402600203810290508084026002038102905080840260020381029050808402600203810290508084026002038102905080860292505050939250505056fea2646970667358221220d4eeacd1a2200e62440c3d89cbb634369ec613720efe0adefb2ee0b1b43684b664736f6c63430006060033","deployedBytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063fa65315414610030575b600080fd5b61007a6004803603608081101561004657600080fd5b810190808035906020019092919080359060200190929190803590602001909291908035906020019092919050505061009b565b60405180831515151581526020018281526020019250505060405180910390f35b600080856100aa85878661019b565b10915060006100c2848661027b90919063ffffffff16565b905060006101196101146100e16103e88561027b90919063ffffffff16565b866100ec57896100ee565b8a5b61010f6103e5896100ff578d610101565b8c5b61027b90919063ffffffff16565b61019b565b610310565b905060006103e58561013f5761013a6103e88861027b90919063ffffffff16565b610155565b6101546103e88961027b90919063ffffffff16565b5b8161015c57fe5b049050808210156101795760008080905094509450505050610192565b61018c818361037290919063ffffffff16565b93505050505b94509492505050565b60008060006101aa86866103f5565b91509150600084806101b857fe5b8688099050828111156101cc576001820391505b808303925060008214156101ee578483816101e357fe5b049350505050610274565b848210610263576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601a8152602001807f46756c6c4d6174683a2046554c4c4449565f4f564552464c4f5700000000000081525060200191505060405180910390fd5b61026e838387610448565b93505050505b9392505050565b600080821480610298575082828385029250828161029557fe5b04145b61030a576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f64732d6d6174682d6d756c2d6f766572666c6f7700000000000000000000000081525060200191505060405180910390fd5b92915050565b6000600382111561035f57819050600060016002848161032c57fe5b040190505b818110156103595780915060028182858161034857fe5b04018161035157fe5b049050610331565b5061036d565b6000821461036c57600190505b5b919050565b60008282840391508111156103ef576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f64732d6d6174682d7375622d756e646572666c6f77000000000000000000000081525060200191505060405180910390fd5b92915050565b60008060007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8061042257fe5b84860990508385029250828103915082811015610440576001820391505b509250929050565b600080826000038316905080838161045c57fe5b04925080858161046857fe5b049450600181826000038161047957fe5b0401840285019450600060019050808402600203810290508084026002038102905080840260020381029050808402600203810290508084026002038102905080840260020381029050808402600203810290508084026002038102905080860292505050939250505056fea2646970667358221220d4eeacd1a2200e62440c3d89cbb634369ec613720efe0adefb2ee0b1b43684b664736f6c63430006060033","immutableReferences":{},"sourceMap":"174:1033:1:-:0;;;;5:9:-1;2:2;;;27:1;24;17:12;2:2;174:1033:1;;;;;;;","deployedSourceMap":"174:1033:1:-:0;;;;5:9:-1;2:2;;;27:1;24;17:12;2:2;174:1033:1;;;;;;;;;;;;;;;;12:1:-1;9;2:12;303:901:1;;;;;;15:3:-1;10;7:12;4:2;;;32:1;29;22:12;4:2;303:901:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;486:9;497:16;587:15;532:52;548:8;558:15;575:8;532:15;:52::i;:::-;:70;525:77;;613:17;633:22;646:8;633;:12;;:22;;;;:::i;:::-;613:42;;666:16;685:232;714:193;747:19;761:4;747:9;:13;;:19;;;;:::i;:::-;784:4;:40;;809:15;784:40;;;791:15;784:40;842:51;889:3;843:4;:40;;868:15;843:40;;;850:15;843:40;842:46;;:51;;;;:::i;:::-;714:15;:193::i;:::-;685:15;:232::i;:::-;666:251;;927:17;998:3;948:4;:46;;976:18;989:4;976:8;:12;;:18;;;;:::i;:::-;948:46;;;955:18;968:4;955:8;:12;;:18;;;;:::i;:::-;948:46;947:54;;;;;;927:74;;1027:9;1016:8;:20;1012:43;;;1046:5;1053:1;1038:17;;;;;;;;;;;;1012:43;1174:23;1187:9;1174:8;:12;;:23;;;;:::i;:::-;1163:34;;303:901;;;;;;;;;;;:::o;897:373:0:-;999:7;1019:9;1030;1043:13;1051:1;1054;1043:7;:13::i;:::-;1018:38;;;;1067:10;1093:1;1080:15;;;;;1090:1;1087;1080:15;1067:28;;1114:1;1109:2;:6;1105:18;;;1122:1;1117:6;;;;1105:18;1138:2;1133:7;;;;1160:1;1155;:6;1151:24;;;1174:1;1170;:5;;;;;;1163:12;;;;;;;1151:24;1198:1;1194;:5;1186:44;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1247:16;1255:1;1258;1261;1247:7;:16::i;:::-;1240:23;;;;;897:373;;;;;;:::o;419:140:3:-;471:6;502:1;497;:6;:30;;;;526:1;521;516;512;:5;508:9;;;507:15;;;;;;:20;497:30;489:63;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;419:140;;;;:::o;189:314:2:-;234:6;260:1;256;:5;252:223;;;281:1;277:5;;296:6;313:1;309;305;:5;;;;;;:9;296:18;;328:89;339:1;335;:5;328:89;;;364:1;360:5;;401:1;396;392;388;:5;;;;;;:9;387:15;;;;;;383:19;;328:89;;;252:223;;;;442:1;437;:6;433:42;;463:1;459:5;;433:42;252:223;189:314;;;:::o;286:127:3:-;338:6;379:1;373;369;:5;365:9;;;364:16;;356:50;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;286:127;;;;:::o;216:206:0:-;278:9;289;310:10;344:2;323:25;;;;;333:1;330;323:25;310:38;;366:1;362;:5;358:9;;386:1;381:2;:6;377:10;;406:1;401:2;:6;397:18;;;414:1;409:6;;;;397:18;216:206;;;;;;:::o;428:463::-;530:7;549:12;569:1;568:2;;564:1;:6;549:21;;585:4;580:9;;;;;;;;;604:4;599:9;;;;;;;;;645:1;638:4;630;629:5;;628:14;;;;;;:18;623:1;:24;618:29;;;;657:9;669:1;657:13;;693:1;689;:5;685:1;:9;680:14;;;;717:1;713;:5;709:1;:9;704:14;;;;741:1;737;:5;733:1;:9;728:14;;;;765:1;761;:5;757:1;:9;752:14;;;;789:1;785;:5;781:1;:9;776:14;;;;813:1;809;:5;805:1;:9;800:14;;;;837:1;833;:5;829:1;:9;824:14;;;;861:1;857;:5;853:1;:9;848:14;;;;883:1;879;:5;872:12;;;;428:463;;;;;:::o","source":"pragma solidity =0.6.6;\n\nimport '@uniswap/lib/contracts/libraries/Babylonian.sol';\nimport '@uniswap/v2-periphery/contracts/libraries/SafeMath.sol';\nimport './FullMath.sol';\n\ncontract Utils {\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 public 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}\n","sourcePath":"/home/sammy/ropsten/contracts/Utils.sol","ast":{"absolutePath":"/home/sammy/ropsten/contracts/Utils.sol","exportedSymbols":{"Utils":[319]},"id":320,"nodeType":"SourceUnit","nodes":[{"id":222,"literals":["solidity","=","0.6",".6"],"nodeType":"PragmaDirective","src":"0:23:1"},{"absolutePath":"@uniswap/lib/contracts/libraries/Babylonian.sol","file":"@uniswap/lib/contracts/libraries/Babylonian.sol","id":223,"nodeType":"ImportDirective","scope":320,"sourceUnit":377,"src":"25:57:1","symbolAliases":[],"unitAlias":""},{"absolutePath":"@uniswap/v2-periphery/contracts/libraries/SafeMath.sol","file":"@uniswap/v2-periphery/contracts/libraries/SafeMath.sol","id":224,"nodeType":"ImportDirective","scope":320,"sourceUnit":452,"src":"83:64:1","symbolAliases":[],"unitAlias":""},{"absolutePath":"/home/sammy/ropsten/contracts/FullMath.sol","file":"./FullMath.sol","id":225,"nodeType":"ImportDirective","scope":320,"sourceUnit":221,"src":"148:24:1","symbolAliases":[],"unitAlias":""},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","documentation":null,"fullyImplemented":true,"id":319,"linearizedBaseContracts":[319],"name":"Utils","nodeType":"ContractDefinition","nodes":[{"id":228,"libraryName":{"contractScope":null,"id":226,"name":"SafeMath","nodeType":"UserDefinedTypeName","referencedDeclaration":451,"src":"201:8:1","typeDescriptions":{"typeIdentifier":"t_contract$_SafeMath_$451","typeString":"library SafeMath"}},"nodeType":"UsingForDirective","src":"195:27:1","typeName":{"id":227,"name":"uint256","nodeType":"ElementaryTypeName","src":"214:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}},{"body":{"id":317,"nodeType":"Block","src":"515:689:1","statements":[{"expression":{"argumentTypes":null,"id":252,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftHandSide":{"argumentTypes":null,"id":243,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"525:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"nodeType":"Assignment","operator":"=","rightHandSide":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":251,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":246,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"548:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"id":247,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"558:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"id":248,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"575:8:1","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":244,"name":"FullMath","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":220,"src":"532:8:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_FullMath_$220_$","typeString":"type(library FullMath)"}},"id":245,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mulDiv","nodeType":"MemberAccess","referencedDeclaration":219,"src":"532:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256,uint256,uint256) pure returns (uint256)"}},"id":249,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"532:52:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"<","rightExpression":{"argumentTypes":null,"id":250,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"587:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"532:70:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"src":"525:77:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"id":253,"nodeType":"ExpressionStatement","src":"525:77:1"},{"assignments":[255],"declarations":[{"constant":false,"id":255,"mutability":"mutable","name":"invariant","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"613:17:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":254,"name":"uint256","nodeType":"ElementaryTypeName","src":"613:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":260,"initialValue":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":258,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"646:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":256,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"633:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":257,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"633:12:1","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":259,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"633:22:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"613:42:1"},{"assignments":[262],"declarations":[{"constant":false,"id":262,"mutability":"mutable","name":"leftSide","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"666:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":261,"name":"uint256","nodeType":"ElementaryTypeName","src":"666:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":285,"initialValue":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"arguments":[{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":269,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"761:4:1","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":267,"name":"invariant","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":255,"src":"747:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":268,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"747:13:1","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":270,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"747:19:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"condition":{"argumentTypes":null,"id":271,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"784:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"id":273,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"809:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":274,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"784:40:1","trueExpression":{"argumentTypes":null,"id":272,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"791:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"393937","id":281,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"889:3:1","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":275,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"843:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"id":277,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"868:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":278,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"843:40:1","trueExpression":{"argumentTypes":null,"id":276,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"850:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"id":279,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"TupleExpression","src":"842:42:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":280,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"842:46:1","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":282,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"842:51:1","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":265,"name":"FullMath","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":220,"src":"714:8:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_FullMath_$220_$","typeString":"type(library FullMath)"}},"id":266,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mulDiv","nodeType":"MemberAccess","referencedDeclaration":219,"src":"714:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256,uint256,uint256) pure returns (uint256)"}},"id":283,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"714:193:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":263,"name":"Babylonian","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":376,"src":"685:10:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_Babylonian_$376_$","typeString":"type(library Babylonian)"}},"id":264,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"sqrt","nodeType":"MemberAccess","referencedDeclaration":375,"src":"685:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256) pure returns (uint256)"}},"id":284,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"685:232:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"666:251:1"},{"assignments":[287],"declarations":[{"constant":false,"id":287,"mutability":"mutable","name":"rightSide","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"927:17:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":286,"name":"uint256","nodeType":"ElementaryTypeName","src":"927:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":301,"initialValue":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":300,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"components":[{"argumentTypes":null,"condition":{"argumentTypes":null,"id":288,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"948:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":295,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"989:4:1","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":293,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"976:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":294,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"976:12:1","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":296,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"976:18:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":297,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"948:46:1","trueExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":291,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"968:4:1","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":289,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"955:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":290,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"955:12:1","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":292,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"955:18:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"id":298,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"TupleExpression","src":"947:48:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"/","rightExpression":{"argumentTypes":null,"hexValue":"393937","id":299,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"998:3:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_rational_997_by_1","typeString":"int_const 997"},"value":"997"},"src":"947:54:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"927:74:1"},{"condition":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":304,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"id":302,"name":"leftSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":262,"src":"1016:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"<","rightExpression":{"argumentTypes":null,"id":303,"name":"rightSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":287,"src":"1027:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"1016:20:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseBody":null,"id":309,"nodeType":"IfStatement","src":"1012:43:1","trueBody":{"expression":{"argumentTypes":null,"components":[{"argumentTypes":null,"hexValue":"66616c7365","id":305,"isConstant":false,"isLValue":false,"isPure":true,"kind":"bool","lValueRequested":false,"nodeType":"Literal","src":"1046:5:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"},"value":"false"},{"argumentTypes":null,"hexValue":"30","id":306,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"1053:1:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_rational_0_by_1","typeString":"int_const 0"},"value":"0"}],"id":307,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":true,"lValueRequested":false,"nodeType":"TupleExpression","src":"1045:10:1","typeDescriptions":{"typeIdentifier":"t_tuple$_t_bool_$_t_rational_0_by_1_$","typeString":"tuple(bool,int_const 0)"}},"functionReturnParameters":242,"id":308,"nodeType":"Return","src":"1038:17:1"}},{"expression":{"argumentTypes":null,"id":315,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftHandSide":{"argumentTypes":null,"id":310,"name":"amountIn","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":241,"src":"1163:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"Assignment","operator":"=","rightHandSide":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":313,"name":"rightSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":287,"src":"1187:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":311,"name":"leftSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":262,"src":"1174:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":312,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"sub","nodeType":"MemberAccess","referencedDeclaration":422,"src":"1174:12:1","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":314,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"1174:23:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"1163:34:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":316,"nodeType":"ExpressionStatement","src":"1163:34:1"}]},"documentation":null,"functionSelector":"fa653154","id":318,"implemented":true,"kind":"function","modifiers":[],"name":"computeProfitMaximizingTrade","nodeType":"FunctionDefinition","overrides":null,"parameters":{"id":237,"nodeType":"ParameterList","parameters":[{"constant":false,"id":230,"mutability":"mutable","name":"truePriceTokenA","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"350:23:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":229,"name":"uint256","nodeType":"ElementaryTypeName","src":"350:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":232,"mutability":"mutable","name":"truePriceTokenB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"383:23:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":231,"name":"uint256","nodeType":"ElementaryTypeName","src":"383:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":234,"mutability":"mutable","name":"reserveA","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"416:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":233,"name":"uint256","nodeType":"ElementaryTypeName","src":"416:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":236,"mutability":"mutable","name":"reserveB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"442:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":235,"name":"uint256","nodeType":"ElementaryTypeName","src":"442:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"src":"340:124:1"},"returnParameters":{"id":242,"nodeType":"ParameterList","parameters":[{"constant":false,"id":239,"mutability":"mutable","name":"aToB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"486:9:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"},"typeName":{"id":238,"name":"bool","nodeType":"ElementaryTypeName","src":"486:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"value":null,"visibility":"internal"},{"constant":false,"id":241,"mutability":"mutable","name":"amountIn","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"497:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":240,"name":"uint256","nodeType":"ElementaryTypeName","src":"497:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"src":"485:29:1"},"scope":319,"src":"303:901:1","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":320,"src":"174:1033:1"}],"src":"0:1208:1"},"legacyAST":{"absolutePath":"/home/sammy/ropsten/contracts/Utils.sol","exportedSymbols":{"Utils":[319]},"id":320,"nodeType":"SourceUnit","nodes":[{"id":222,"literals":["solidity","=","0.6",".6"],"nodeType":"PragmaDirective","src":"0:23:1"},{"absolutePath":"@uniswap/lib/contracts/libraries/Babylonian.sol","file":"@uniswap/lib/contracts/libraries/Babylonian.sol","id":223,"nodeType":"ImportDirective","scope":320,"sourceUnit":377,"src":"25:57:1","symbolAliases":[],"unitAlias":""},{"absolutePath":"@uniswap/v2-periphery/contracts/libraries/SafeMath.sol","file":"@uniswap/v2-periphery/contracts/libraries/SafeMath.sol","id":224,"nodeType":"ImportDirective","scope":320,"sourceUnit":452,"src":"83:64:1","symbolAliases":[],"unitAlias":""},{"absolutePath":"/home/sammy/ropsten/contracts/FullMath.sol","file":"./FullMath.sol","id":225,"nodeType":"ImportDirective","scope":320,"sourceUnit":221,"src":"148:24:1","symbolAliases":[],"unitAlias":""},{"abstract":false,"baseContracts":[],"contractDependencies":[],"contractKind":"contract","documentation":null,"fullyImplemented":true,"id":319,"linearizedBaseContracts":[319],"name":"Utils","nodeType":"ContractDefinition","nodes":[{"id":228,"libraryName":{"contractScope":null,"id":226,"name":"SafeMath","nodeType":"UserDefinedTypeName","referencedDeclaration":451,"src":"201:8:1","typeDescriptions":{"typeIdentifier":"t_contract$_SafeMath_$451","typeString":"library SafeMath"}},"nodeType":"UsingForDirective","src":"195:27:1","typeName":{"id":227,"name":"uint256","nodeType":"ElementaryTypeName","src":"214:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}},{"body":{"id":317,"nodeType":"Block","src":"515:689:1","statements":[{"expression":{"argumentTypes":null,"id":252,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftHandSide":{"argumentTypes":null,"id":243,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"525:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"nodeType":"Assignment","operator":"=","rightHandSide":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":251,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":246,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"548:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"id":247,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"558:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"id":248,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"575:8:1","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":244,"name":"FullMath","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":220,"src":"532:8:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_FullMath_$220_$","typeString":"type(library FullMath)"}},"id":245,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mulDiv","nodeType":"MemberAccess","referencedDeclaration":219,"src":"532:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256,uint256,uint256) pure returns (uint256)"}},"id":249,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"532:52:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"<","rightExpression":{"argumentTypes":null,"id":250,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"587:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"532:70:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"src":"525:77:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"id":253,"nodeType":"ExpressionStatement","src":"525:77:1"},{"assignments":[255],"declarations":[{"constant":false,"id":255,"mutability":"mutable","name":"invariant","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"613:17:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":254,"name":"uint256","nodeType":"ElementaryTypeName","src":"613:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":260,"initialValue":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":258,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"646:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":256,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"633:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":257,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"633:12:1","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":259,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"633:22:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"613:42:1"},{"assignments":[262],"declarations":[{"constant":false,"id":262,"mutability":"mutable","name":"leftSide","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"666:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":261,"name":"uint256","nodeType":"ElementaryTypeName","src":"666:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":285,"initialValue":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"arguments":[{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":269,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"761:4:1","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":267,"name":"invariant","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":255,"src":"747:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":268,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"747:13:1","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":270,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"747:19:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"condition":{"argumentTypes":null,"id":271,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"784:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"id":273,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"809:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":274,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"784:40:1","trueExpression":{"argumentTypes":null,"id":272,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"791:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"393937","id":281,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"889:3:1","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":275,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"843:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"id":277,"name":"truePriceTokenA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":230,"src":"868:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":278,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"843:40:1","trueExpression":{"argumentTypes":null,"id":276,"name":"truePriceTokenB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":232,"src":"850:15:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"id":279,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"TupleExpression","src":"842:42:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":280,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"842:46:1","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":282,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"842:51:1","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":265,"name":"FullMath","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":220,"src":"714:8:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_FullMath_$220_$","typeString":"type(library FullMath)"}},"id":266,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mulDiv","nodeType":"MemberAccess","referencedDeclaration":219,"src":"714:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$_t_uint256_$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256,uint256,uint256) pure returns (uint256)"}},"id":283,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"714:193:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":263,"name":"Babylonian","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":376,"src":"685:10:1","typeDescriptions":{"typeIdentifier":"t_type$_t_contract$_Babylonian_$376_$","typeString":"type(library Babylonian)"}},"id":264,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"sqrt","nodeType":"MemberAccess","referencedDeclaration":375,"src":"685:15:1","typeDescriptions":{"typeIdentifier":"t_function_internal_pure$_t_uint256_$returns$_t_uint256_$","typeString":"function (uint256) pure returns (uint256)"}},"id":284,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"685:232:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"666:251:1"},{"assignments":[287],"declarations":[{"constant":false,"id":287,"mutability":"mutable","name":"rightSide","nodeType":"VariableDeclaration","overrides":null,"scope":317,"src":"927:17:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":286,"name":"uint256","nodeType":"ElementaryTypeName","src":"927:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"id":301,"initialValue":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":300,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"components":[{"argumentTypes":null,"condition":{"argumentTypes":null,"id":288,"name":"aToB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":239,"src":"948:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":295,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"989:4:1","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":293,"name":"reserveB","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":236,"src":"976:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":294,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"976:12:1","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":296,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"976:18:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":297,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"Conditional","src":"948:46:1","trueExpression":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"hexValue":"31303030","id":291,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"968:4:1","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":289,"name":"reserveA","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":234,"src":"955:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":290,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"mul","nodeType":"MemberAccess","referencedDeclaration":450,"src":"955:12:1","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":292,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"955:18:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"id":298,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":false,"lValueRequested":false,"nodeType":"TupleExpression","src":"947:48:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"/","rightExpression":{"argumentTypes":null,"hexValue":"393937","id":299,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"998:3:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_rational_997_by_1","typeString":"int_const 997"},"value":"997"},"src":"947:54:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"VariableDeclarationStatement","src":"927:74:1"},{"condition":{"argumentTypes":null,"commonType":{"typeIdentifier":"t_uint256","typeString":"uint256"},"id":304,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftExpression":{"argumentTypes":null,"id":302,"name":"leftSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":262,"src":"1016:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"BinaryOperation","operator":"<","rightExpression":{"argumentTypes":null,"id":303,"name":"rightSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":287,"src":"1027:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"1016:20:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"falseBody":null,"id":309,"nodeType":"IfStatement","src":"1012:43:1","trueBody":{"expression":{"argumentTypes":null,"components":[{"argumentTypes":null,"hexValue":"66616c7365","id":305,"isConstant":false,"isLValue":false,"isPure":true,"kind":"bool","lValueRequested":false,"nodeType":"Literal","src":"1046:5:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"},"value":"false"},{"argumentTypes":null,"hexValue":"30","id":306,"isConstant":false,"isLValue":false,"isPure":true,"kind":"number","lValueRequested":false,"nodeType":"Literal","src":"1053:1:1","subdenomination":null,"typeDescriptions":{"typeIdentifier":"t_rational_0_by_1","typeString":"int_const 0"},"value":"0"}],"id":307,"isConstant":false,"isInlineArray":false,"isLValue":false,"isPure":true,"lValueRequested":false,"nodeType":"TupleExpression","src":"1045:10:1","typeDescriptions":{"typeIdentifier":"t_tuple$_t_bool_$_t_rational_0_by_1_$","typeString":"tuple(bool,int_const 0)"}},"functionReturnParameters":242,"id":308,"nodeType":"Return","src":"1038:17:1"}},{"expression":{"argumentTypes":null,"id":315,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"leftHandSide":{"argumentTypes":null,"id":310,"name":"amountIn","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":241,"src":"1163:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"nodeType":"Assignment","operator":"=","rightHandSide":{"argumentTypes":null,"arguments":[{"argumentTypes":null,"id":313,"name":"rightSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":287,"src":"1187:9:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}}],"expression":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"expression":{"argumentTypes":null,"id":311,"name":"leftSide","nodeType":"Identifier","overloadedDeclarations":[],"referencedDeclaration":262,"src":"1174:8:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":312,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"memberName":"sub","nodeType":"MemberAccess","referencedDeclaration":422,"src":"1174:12:1","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":314,"isConstant":false,"isLValue":false,"isPure":false,"kind":"functionCall","lValueRequested":false,"names":[],"nodeType":"FunctionCall","src":"1174:23:1","tryCall":false,"typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"src":"1163:34:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"id":316,"nodeType":"ExpressionStatement","src":"1163:34:1"}]},"documentation":null,"functionSelector":"fa653154","id":318,"implemented":true,"kind":"function","modifiers":[],"name":"computeProfitMaximizingTrade","nodeType":"FunctionDefinition","overrides":null,"parameters":{"id":237,"nodeType":"ParameterList","parameters":[{"constant":false,"id":230,"mutability":"mutable","name":"truePriceTokenA","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"350:23:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":229,"name":"uint256","nodeType":"ElementaryTypeName","src":"350:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":232,"mutability":"mutable","name":"truePriceTokenB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"383:23:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":231,"name":"uint256","nodeType":"ElementaryTypeName","src":"383:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":234,"mutability":"mutable","name":"reserveA","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"416:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":233,"name":"uint256","nodeType":"ElementaryTypeName","src":"416:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"},{"constant":false,"id":236,"mutability":"mutable","name":"reserveB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"442:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":235,"name":"uint256","nodeType":"ElementaryTypeName","src":"442:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"src":"340:124:1"},"returnParameters":{"id":242,"nodeType":"ParameterList","parameters":[{"constant":false,"id":239,"mutability":"mutable","name":"aToB","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"486:9:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"},"typeName":{"id":238,"name":"bool","nodeType":"ElementaryTypeName","src":"486:4:1","typeDescriptions":{"typeIdentifier":"t_bool","typeString":"bool"}},"value":null,"visibility":"internal"},{"constant":false,"id":241,"mutability":"mutable","name":"amountIn","nodeType":"VariableDeclaration","overrides":null,"scope":318,"src":"497:16:1","stateVariable":false,"storageLocation":"default","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"},"typeName":{"id":240,"name":"uint256","nodeType":"ElementaryTypeName","src":"497:7:1","typeDescriptions":{"typeIdentifier":"t_uint256","typeString":"uint256"}},"value":null,"visibility":"internal"}],"src":"485:29:1"},"scope":319,"src":"303:901:1","stateMutability":"pure","virtual":false,"visibility":"public"}],"scope":320,"src":"174:1033:1"}],"src":"0:1208:1"},"compiler":{"name":"solc","version":"0.6.6+commit.6c089d02.Emscripten.clang"},"networks":{},"schemaVersion":"3.2.3","updatedAt":"2021-05-04T13:57:46.311Z","devdoc":{"methods":{}},"userdoc":{"methods":{}}};

web3 = new Web3(`wss://mainnet.infura.io/ws/v3/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`);

const run = async () => {
    const newBlockEvent = web3.eth.subscribe('newBlockHeaders');
    const sushiFactory = new web3.eth.Contract(UniswapV2Factory.abi, '0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac');
    const uniswapFactory = new web3.eth.Contract(UniswapV2Factory.abi, '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f');

    const token0 = new web3.eth.Contract(IERC20.abi, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
    const token1 = new web3.eth.Contract(IERC20.abi, '0x6b175474e89094c44da98b954eedeac495271d0f');

    const utils = new web3.eth.Contract(Utils.abi, '0xE78941610Ffef0eEA391BAe6d842175E389973E9');
    const sushiPair = new web3.eth.Contract(UniswapV2Pair.abi, (await sushiFactory.methods.getPair(token0.options.address, token1.options.address).call()));
    const uniswapPair = new web3.eth.Contract(UniswapV2Pair.abi, (await sushiFactory.methods.getPair(token0.options.address, token1.options.address).call()));

    newBlockEvent.on('data', async function(blockHeader){
        try {
            console.log(blockHeader.number);

            const sushiReserves = await sushiPair.methods.getReserves().call();
            const uniswapReserves = await uniswapPair.methods.getReserves().call();

            console.log(sushiReserves, uniswapReserves);

            const result = await utils.methods.computeProfitMaximizingTrade(sushiReserves[0], sushiReserves[1], uniswapReserves[0], uniswapReserves[1]).call();

            console.log(result);
        } catch(e) {
            console.error(e);
        }
    });
};

run();

The blockHeader.number is printed, the reserves are printed, but before printing result it shows this error:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced. at ABICoder.decodeParametersWith (/home/x/node_modules/web3-eth-abi/lib/index.js:298:15) at ABICoder.decodeParameters (/home/x/node_modules/web3-eth-abi/lib/index.js:285:17) at Contract._decodeMethodReturn (/home/x/node_modules/web3-eth-contract/lib/index.js:470:22) at Method.outputFormatter (/home/x/node_modules/web3-eth-contract/lib/index.js:760:42) at Method.formatOutput (/home/x/node_modules/web3-core-method/lib/index.js:147:54) at sendTxCallback (/home/x/node_modules/web3-core-method/lib/index.js:523:33) at Object.callback (/home/x/node_modules/web3-core-requestmanager/lib/index.js:308:9) at /home/x/node_modules/web3-providers-ws/lib/index.js:114:45 at Array.forEach () at WebsocketProvider._onMessage (/home/x/node_modules/web3-providers-ws/lib/index.js:102:69) at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/x/node_modules/yaeti/lib/EventTarget.js:115:12) at W3CWebSocket.onMessage (/home/x/node_modules/websocket/lib/W3CWebSocket.js:234:14) at WebSocketConnection. (/home/x/node_modules/websocket/lib/W3CWebSocket.js:205:19) at WebSocketConnection.emit (events.js:198:13) at WebSocketConnection.processFrame (/home/x/node_modules/websocket/lib/WebSocketConnection.js:554:26) at /home/x/node_modules/websocket/lib/WebSocketConnection.js:323:40

If I comment the computeProfitMaximizingTrade it doesn't show the error.

Any ideas?