UNPKG

hardlydifficult-eth

Version:

A collection of reusable contracts and Javascript helpers for Ethereum.

778 lines (777 loc) 339 kB
{ "contractName": "UniswapOracle", "abi": [ { "inputs": [ { "internalType": "address", "name": "_factory", "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "PERIOD", "outputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "factory", "outputs": [ { "internalType": "address", "name": "", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_tokenIn", "type": "address" }, { "internalType": "address", "name": "_tokenOut", "type": "address" } ], "name": "update", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_tokenIn", "type": "address" }, { "internalType": "uint256", "name": "_amountIn", "type": "uint256" }, { "internalType": "address", "name": "_tokenOut", "type": "address" } ], "name": "consult", "outputs": [ { "internalType": "uint256", "name": "_amountOut", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", "name": "_tokenIn", "type": "address" }, { "internalType": "uint256", "name": "_amountIn", "type": "uint256" }, { "internalType": "address", "name": "_tokenOut", "type": "address" } ], "name": "updateAndConsult", "outputs": [ { "internalType": "uint256", "name": "_amountOut", "type": "uint256" } ], "stateMutability": "nonpayable", "type": "function" } ], "metadata": "{\"compiler\":{\"version\":\"0.6.10+commit.00c0fcaf\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_factory\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"PERIOD\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_tokenIn\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amountIn\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"_tokenOut\",\"type\":\"address\"}],\"name\":\"consult\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"_amountOut\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"factory\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_tokenIn\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"_tokenOut\",\"type\":\"address\"}],\"name\":\"update\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_tokenIn\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_amountIn\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"_tokenOut\",\"type\":\"address\"}],\"name\":\"updateAndConsult\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"_amountOut\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"methods\":{\"update(address,address)\":{\"details\":\"For the first 24 hours the rate will be 0.\"}}},\"userdoc\":{\"methods\":{\"consult(address,uint256,address)\":{\"notice\":\"Returns the rate after `update` has been called.\"},\"update(address,address)\":{\"notice\":\"Updates and stores the exchange rate\"},\"updateAndConsult(address,uint256,address)\":{\"notice\":\"Calls `update` and returns the rate in a single call\"}}}},\"settings\":{\"compilationTarget\":{\"project:/contracts/protocols/Uniswap/UniswapOracle.sol\":\"UniswapOracle\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":2000000},\"remappings\":[]},\"sources\":{\"@openzeppelin/contracts/math/SafeMath.sol\":{\"keccak256\":\"0xcc78a17dd88fa5a2edc60c8489e2f405c0913b377216a5b26b35656b2d0dab52\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://526dc85e1f9b9b45830e202568d267d93dde7a4fcccf4ad7798dadcd92304d3c\",\"dweb:/ipfs/QmaoXMB972J3cSDLtBq3xBo4jLwqD2uzXTwujtSPqkYVhR\"]},\"@uniswap/lib/contracts/libraries/Babylonian.sol\":{\"keccak256\":\"0x2799682d733a6ef3aae1dce7dbe2cff5513f0244e4abd07338fe7a45c8fd9733\",\"license\":\"GPL-3.0-or-later\",\"urls\":[\"bzz-raw://332968199300fe6025b9ad8f3d69f252ec2a3a092fa42a0ef7f2d1397f59a7e5\",\"dweb:/ipfs/Qme4wBzDwfHr7zHk8WrCwCpozpt4KHuDQSxfJTDoHL8Pdi\"]},\"@uniswap/lib/contracts/libraries/BitMath.sol\":{\"keccak256\":\"0x0ef2d7cd41b3f1818fa41019b38948489238efccebe428d4b04919174378abf5\",\"license\":\"GPL-3.0-or-later\",\"urls\":[\"bzz-raw://696ac37d8731506cbac9b428afb7bdfa35a490df139022be2b04ab3815113cf4\",\"dweb:/ipfs/QmUQ5ty49YATw4Gf5PrtFkxNErcnwhNUpRF3WFaVJxATf9\"]},\"@uniswap/lib/contracts/libraries/FixedPoint.sol\":{\"keccak256\":\"0x0e8d7f2bfad7505f9d029ea060eab9747363d50bf01f2d954bf719da6fac342f\",\"license\":\"GPL-3.0-or-later\",\"urls\":[\"bzz-raw://35dd605e2fd59d2606529ab1575cd937082018cd041cfbb843b68e97e440b9b0\",\"dweb:/ipfs/QmUHbzyCdzwUSCUPVFFm9N6oKXiisVdscX8H73nwNXmmpV\"]},\"@uniswap/lib/contracts/libraries/FullMath.sol\":{\"keccak256\":\"0xf3dd7fc13a7eee86c17cdfe13b03a7f24ebaf09588550b64b581ae7b2bd59273\",\"license\":\"CC-BY-4.0\",\"urls\":[\"bzz-raw://492ced3afa929c790c9b1314b86454a977528e8f3d408a55b1275a396154d097\",\"dweb:/ipfs/QmbX2YAgtoM13Z2MRnV5WnUpzmw3fMxmhzCnsKKxQUjGJJ\"]},\"@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol\":{\"keccak256\":\"0xe5905c0989cf5a865ed9bb7b9252536ca011c5b744017a82a7d4443b9c00a891\",\"urls\":[\"bzz-raw://5d2a90a0a796491507462a3da18c3f8819721d571572d765a2207c35bf0a0389\",\"dweb:/ipfs/Qmf9ACYiT3qzjgsYuhm866FBdiBpRMXAPpQhSFbgqcyhHt\"]},\"@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol\":{\"keccak256\":\"0x7c9bc70e5996c763e02ff38905282bc24fb242b0ef2519a003b36824fc524a4b\",\"urls\":[\"bzz-raw://85d5ad2dd23ee127f40907a12865a1e8cb5828814f6f2480285e1827dd72dedf\",\"dweb:/ipfs/QmayKQWJgWmr46DqWseADyUanmqxh662hPNdAkdHRjiQQH\"]},\"@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol\":{\"keccak256\":\"0x993538630a9568290c39140d54c034a66cf1b95cdeef4ba804a948c4ee2fc311\",\"urls\":[\"bzz-raw://adff017b539750d5ac84403360967c4d6b02a1ee9b8f2487f0bcddd7fa7c523e\",\"dweb:/ipfs/QmQqUiUvoezf33f2SZa64M8KgksHSXFPrGuwDvxijtXYMo\"]},\"project:/contracts/protocols/Uniswap/IUniswapOracle.sol\":{\"keccak256\":\"0x05b6d798d77c056327991f472b01b7cba705b0136da35e6ab7253029f08d147a\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://e2e55aca59c764faafc065bc48086dbb53afbfc02f47c76aebaadd730c635507\",\"dweb:/ipfs/QmeGfMkeibFNkM1ewT5LutvF1Z9XvfCVPSgVz6FTiKNfqG\"]},\"project:/contracts/protocols/Uniswap/UniswapOracle.sol\":{\"keccak256\":\"0xed121ed35d335a397fba79e7dc0d63fc8aca5815a94ab6bd86a2faa07814c590\",\"license\":\"GPL-3.0\",\"urls\":[\"bzz-raw://86cc1f263514f7bcaf6a511eb571667252821f25ae5f099403c25375cd38cb9d\",\"dweb:/ipfs/QmYn2upw6fQJkq3rFD2nC8YvXPjrZfKwPadtMNYJ2aaZWe\"]},\"project:/contracts/protocols/Uniswap/UniswapV2Library.sol\":{\"keccak256\":\"0x65165b942a31dbf2bbd457075244dc8de9914d1b242568a26e310e12d824e8b9\",\"license\":\"GPL-3.0\",\"urls\":[\"bzz-raw://8e2724628228ef70e3df52f2fa11a3f6825ff9427af700988d051f3d7dad740c\",\"dweb:/ipfs/QmUo6akdzoDwSdtrbVB75BGAA9qE2KCuURVrisTTHiWnCY\"]}},\"version\":1}", "bytecode": "0x60a060405234801561001057600080fd5b50604051610c12380380610c128339818101604052602081101561003357600080fd5b5051606081901b6001600160601b0319166080526001600160a01b0316610ba1610071600039806101825280610302528061032b5250610ba16000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c8063c1e553e711610050578063c1e553e7146100c9578063c45a01551461010c578063c640752d1461013d57610067565b80638c86f1e41461006c578063b4d1d795146100c1575b600080fd5b6100af6004803603606081101561008257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135916040909101351661017a565b60408051918252519081900360200190f35b6100af6102da565b6100af600480360360608110156100df57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013591604090910135166102e1565b610114610300565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101786004803603604081101561015357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610324565b005b6000806101a87f000000000000000000000000000000000000000000000000000000000000000086856104c5565b73ffffffffffffffffffffffffffffffffffffffff811660009081526020819052604081209192506101da87866105b0565b5090508073ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff16141561027557604080516020810190915260038301547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16815261025a90610255908863ffffffff61070316565b6107c6565b71ffffffffffffffffffffffffffffffffffff1693506102d0565b604080516020810190915260048301547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526102b990610255908863ffffffff61070316565b71ffffffffffffffffffffffffffffffffffff1693505b5050509392505050565b6201518081565b60006102ed8483610324565b6102f884848461017a565b949350505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60006103517f000000000000000000000000000000000000000000000000000000000000000084846104c5565b73ffffffffffffffffffffffffffffffffffffffff811660009081526020819052604081209192508080610384856107cd565b925092509250600084600001548263ffffffff16039050620151808163ffffffff16106104bb576001850154156104a35760405180602001604052808263ffffffff1687600101548703816103d557fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff90811690915290516003870180547fffffffff00000000000000000000000000000000000000000000000000000000169190921617905560408051602081019091526002860154819063ffffffff84169086038161044d57fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff90811690915290516004870180547fffffffff0000000000000000000000000000000000000000000000000000000016919092161790555b600185018490556002850183905563ffffffff821685555b5050505050505050565b60008060006104d485856105b0565b604080517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501207fff0000000000000000000000000000000000000000000000000000000000000060688401529a90941b9093166069840152607d8301989098527f96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b6000808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415610638576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180610b476025913960400191505060405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1610610672578284610675565b83835b909250905073ffffffffffffffffffffffffffffffffffffffff82166106fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f556e697377617056324c6962726172793a205a45524f5f414444524553530000604482015290519081900360640190fd5b9250929050565b61070b610b21565b600082158061074657505082517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff168281029083828161074357fe5b04145b6107b157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4669786564506f696e743a204d554c5f4f564552464c4f570000000000000000604482015290519081900360640190fd5b60408051602081019091529081529392505050565b5160701c90565b60008060006107da610a1f565b90508373ffffffffffffffffffffffffffffffffffffffff16635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b15801561082257600080fd5b505afa158015610836573d6000803e3d6000fd5b505050506040513d602081101561084c57600080fd5b5051604080517f5a3d5493000000000000000000000000000000000000000000000000000000008152905191945073ffffffffffffffffffffffffffffffffffffffff861691635a3d549391600480820192602092909190829003018186803b1580156108b857600080fd5b505afa1580156108cc573d6000803e3d6000fd5b505050506040513d60208110156108e257600080fd5b5051604080517f0902f1ac00000000000000000000000000000000000000000000000000000000815290519193506000918291829173ffffffffffffffffffffffffffffffffffffffff891691630902f1ac916004808301926060929190829003018186803b15801561095457600080fd5b505afa158015610968573d6000803e3d6000fd5b505050506040513d606081101561097e57600080fd5b5080516020820151604090920151909450909250905063ffffffff80821690851614610a155780840363ffffffff81166109b88486610a29565b517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1602969096019563ffffffff81166109ee8585610a29565b517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16029590950194505b5050509193909250565b63ffffffff421690565b610a31610b34565b6000826dffffffffffffffffffffffffffff1611610ab057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4669786564506f696e743a204449565f42595f5a45524f5f4652414354494f4e604482015290519081900360640190fd5b6040805160208101909152806dffffffffffffffffffffffffffff84167bffffffffffffffffffffffffffff0000000000000000000000000000607087901b1681610af757fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16815250905092915050565b6040518060200160405280600081525090565b6040805160208101909152600081529056fe556e697377617056324c6962726172793a204944454e544943414c5f414444524553534553a26469706673582212205208d9920c4bbfc57b832303162b811d7b986182e42bd68e676ea1d7b5209f8164736f6c634300060a0033", "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100675760003560e01c8063c1e553e711610050578063c1e553e7146100c9578063c45a01551461010c578063c640752d1461013d57610067565b80638c86f1e41461006c578063b4d1d795146100c1575b600080fd5b6100af6004803603606081101561008257600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020810135916040909101351661017a565b60408051918252519081900360200190f35b6100af6102da565b6100af600480360360608110156100df57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135811691602081013591604090910135166102e1565b610114610300565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b6101786004803603604081101561015357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610324565b005b6000806101a87f000000000000000000000000000000000000000000000000000000000000000086856104c5565b73ffffffffffffffffffffffffffffffffffffffff811660009081526020819052604081209192506101da87866105b0565b5090508073ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff16141561027557604080516020810190915260038301547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16815261025a90610255908863ffffffff61070316565b6107c6565b71ffffffffffffffffffffffffffffffffffff1693506102d0565b604080516020810190915260048301547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526102b990610255908863ffffffff61070316565b71ffffffffffffffffffffffffffffffffffff1693505b5050509392505050565b6201518081565b60006102ed8483610324565b6102f884848461017a565b949350505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60006103517f000000000000000000000000000000000000000000000000000000000000000084846104c5565b73ffffffffffffffffffffffffffffffffffffffff811660009081526020819052604081209192508080610384856107cd565b925092509250600084600001548263ffffffff16039050620151808163ffffffff16106104bb576001850154156104a35760405180602001604052808263ffffffff1687600101548703816103d557fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff90811690915290516003870180547fffffffff00000000000000000000000000000000000000000000000000000000169190921617905560408051602081019091526002860154819063ffffffff84169086038161044d57fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff90811690915290516004870180547fffffffff0000000000000000000000000000000000000000000000000000000016919092161790555b600185018490556002850183905563ffffffff821685555b5050505050505050565b60008060006104d485856105b0565b604080517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606094851b811660208084019190915293851b81166034830152825160288184030181526048830184528051908501207fff0000000000000000000000000000000000000000000000000000000000000060688401529a90941b9093166069840152607d8301989098527f96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f609d808401919091528851808403909101815260bd909201909752805196019590952095945050505050565b6000808273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff161415610638576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180610b476025913960400191505060405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1610610672578284610675565b83835b909250905073ffffffffffffffffffffffffffffffffffffffff82166106fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f556e697377617056324c6962726172793a205a45524f5f414444524553530000604482015290519081900360640190fd5b9250929050565b61070b610b21565b600082158061074657505082517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff168281029083828161074357fe5b04145b6107b157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4669786564506f696e743a204d554c5f4f564552464c4f570000000000000000604482015290519081900360640190fd5b60408051602081019091529081529392505050565b5160701c90565b60008060006107da610a1f565b90508373ffffffffffffffffffffffffffffffffffffffff16635909c0d56040518163ffffffff1660e01b815260040160206040518083038186803b15801561082257600080fd5b505afa158015610836573d6000803e3d6000fd5b505050506040513d602081101561084c57600080fd5b5051604080517f5a3d5493000000000000000000000000000000000000000000000000000000008152905191945073ffffffffffffffffffffffffffffffffffffffff861691635a3d549391600480820192602092909190829003018186803b1580156108b857600080fd5b505afa1580156108cc573d6000803e3d6000fd5b505050506040513d60208110156108e257600080fd5b5051604080517f0902f1ac00000000000000000000000000000000000000000000000000000000815290519193506000918291829173ffffffffffffffffffffffffffffffffffffffff891691630902f1ac916004808301926060929190829003018186803b15801561095457600080fd5b505afa158015610968573d6000803e3d6000fd5b505050506040513d606081101561097e57600080fd5b5080516020820151604090920151909450909250905063ffffffff80821690851614610a155780840363ffffffff81166109b88486610a29565b517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1602969096019563ffffffff81166109ee8585610a29565b517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16029590950194505b5050509193909250565b63ffffffff421690565b610a31610b34565b6000826dffffffffffffffffffffffffffff1611610ab057604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4669786564506f696e743a204449565f42595f5a45524f5f4652414354494f4e604482015290519081900360640190fd5b6040805160208101909152806dffffffffffffffffffffffffffff84167bffffffffffffffffffffffffffff0000000000000000000000000000607087901b1681610af757fe5b047bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16815250905092915050565b6040518060200160405280600081525090565b6040805160208101909152600081529056fe556e697377617056324c6962726172793a204944454e544943414c5f414444524553534553a26469706673582212205208d9920c4bbfc57b832303162b811d7b986182e42bd68e676ea1d7b5209f8164736f6c634300060a0033", "immutableReferences": { "2940": [ { "length": 32, "start": 386 }, { "length": 32, "start": 770 }, { "length": 32, "start": 811 } ] }, "sourceMap": "620:2887:14:-:0;;;1112:76;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1112:76:14;1165:18;;;;-1:-1:-1;;;;;;1165:18:14;;;-1:-1:-1;;;;;620:2887:14;;;;;;;;", "deployedSourceMap": "620:2887:14:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2626:562;;;;;;;;;;;;;;;;-1:-1:-1;2626:562:14;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;877:47;;;:::i;3272:233::-;;;;;;;;;;;;;;;;-1:-1:-1;3272:233:14;;;;;;;;;;;;;;;;;;:::i;928:41::-;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1307:1241;;;;;;;;;;;;;;;;-1:-1:-1;1307:1241:14;;;;;;;;;;;:::i;:::-;;2626:562;2746:15;2771:12;2786:54;2811:7;2820:8;2830:9;2786:24;:54::i;:::-;2880:22;;;2846:31;2880:22;;;;;;;;;;2771:69;;-1:-1:-1;2928:48:14;2956:8;2966:9;2928:27;:48::i;:::-;2908:68;;;2998:6;2986:18;;:8;:18;;;2982:202;;;3031:29;;;;;;;;;:25;;;:29;;;;;:52;;:40;;3061:9;3031:40;:29;:40;:::i;:::-;:50;:52::i;:::-;3018:65;;;;2982:202;;;3125:29;;;;;;;;;:25;;;:29;;;;;:52;;:40;;3155:9;3125:40;:29;:40;:::i;:52::-;3112:65;;;;2982:202;2626:562;;;;;;;;:::o;877:47::-;916:8;877:47;:::o;3272:233::-;3396:15;3421:27;3428:8;3438:9;3421:6;:27::i;:::-;3461:39;3469:8;3479:9;3490;3461:7;:39::i;:::-;3454:46;3272:233;-1:-1:-1;;;;3272:233:14:o;928:41::-;;;:::o;1307:1241::-;1396:12;1411:54;1436:7;1445:8;1455:9;1411:24;:54::i;:::-;1505:22;;;1471:31;1505:22;;;;;;;;;;1396:69;;-1:-1:-1;1471:31:14;;1611:61;1396:69;1611:46;:61::i;:::-;1533:139;;;;;;1678:18;1723:11;:21;;;1706:14;:38;;;1678:67;;916:8;1855:11;:21;;;1852:692;;1893:28;;;;:32;1890:492;;2147:94;;;;;;;;2228:11;2176:63;;2196:11;:28;;;2177:16;:47;2176:63;;;;;;2147:94;;;;;;;2119:122;;:25;;;:122;;;;;;;;;;;2279:94;;;;;;;;;2328:28;;;;2279:94;;2308:63;;;;2309:47;;2308:63;;;;;;2279:94;;;;;;;2251:122;;:25;;;:122;;;;;;;;;;;1890:492;2389:28;;;:47;;;2444:28;;;:47;;;2499:38;;;;;1852:692;1307:1241;;;;;;;;:::o;936:470:15:-;1025:12;1050:14;1066;1084:26;1095:6;1103;1084:10;:26::i;:::-;1244:32;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1234:43;;;;;;1150:246;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1140:257;;;;;;;;;936:470;-1:-1:-1;;;;;936:470:15:o;502:345::-;577:14;593;637:6;627:16;;:6;:16;;;;619:66;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;723:6;714:15;;:6;:15;;;:53;;752:6;760;714:53;;;733:6;741;714:53;695:72;;-1:-1:-1;695:72:15;-1:-1:-1;785:20:15;;;777:63;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;502:345;;;;;:::o;1676:236:4:-;1746:16;;:::i;:::-;1774:9;1805:6;;;:42;;-1:-1:-1;;1840:7:4;;1815:32;;1820:11;;;;1835:1;1820:11;1835:1;1815:21;;;;;:32;1805:42;1797:79;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1893:12;;;;;;;;;;;;;1676:236;-1:-1:-1;;;1676:236:4:o;1454:128::-;1553:7;532:3;1553:21;;1454:128::o;646:1040:8:-;730:21;753;776;826:23;:21;:23::i;:::-;809:40;;893:4;878:41;;;:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;878:43:8;950;;;;;;;;878;;-1:-1:-1;950:41:8;;;;;;:43;;;;;878;;950;;;;;;;;:41;:43;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;950:43:8;1170:34;;;;;;;;950:43;;-1:-1:-1;1105:16:8;;;;;;1170:32;;;;;;:34;;;;;;;;;;;;;;:32;:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1170:34:8;;;;;;;;;;;;;-1:-1:-1;1170:34:8;;-1:-1:-1;1170:34:8;-1:-1:-1;1218:36:8;;;;;;;;1214:466;;1338:35;;;1481:62;;;1486:39;1506:8;1516;1486:19;:39::i;:::-;:42;1481:48;;:62;1461:82;;;;;1607:62;;;1612:39;1632:8;1642;1612:19;:39::i;:::-;:42;1607:48;;:62;1587:82;;;;;-1:-1:-1;1214:466:8;646:1040;;;;;;;;:::o;422:121::-;510:25;:15;:25;;422:121::o;4489:252:4:-;4570:16;;:::i;:::-;4620:1;4606:11;:15;;;4598:60;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4675:59;;;;;;;;;;4685:48;;;4686:32;532:3;4686:32;;;;4685:48;;;;;;4675:59;;;;;4668:66;;4489:252;;;;:::o;-1:-1:-1:-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;:::o", "source": "\n// SPDX-License-Identifier: GPL-3.0\n// Original source: https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/examples\n// Modified to unpin solidity version and to support multiple pairs\npragma solidity ^0.6.6;\n\nimport '@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol';\nimport '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';\nimport '@uniswap/lib/contracts/libraries/FixedPoint.sol';\nimport '@openzeppelin/contracts/math/SafeMath.sol';\nimport '@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol';\nimport './UniswapV2Library.sol';\nimport './IUniswapOracle.sol';\n\ncontract UniswapOracle is IUniswapOracle\n{ \n using FixedPoint for *;\n\n struct Observation\n {\n uint timestamp;\n uint price0Cumulative;\n uint price1Cumulative;\n FixedPoint.uq112x112 price0Average;\n FixedPoint.uq112x112 price1Average;\n }\n\n uint public override constant PERIOD = 24 hours;\n address public override immutable factory;\n // mapping from pair address to a list of price observations of that pair\n mapping(address => Observation) private pairObservations;\n \n constructor(\n address _factory\n ) public\n {\n factory = _factory;\n }\n\n /**\n * @notice Updates and stores the exchange rate\n * @dev For the first 24 hours the rate will be 0.\n */\n function update(\n address _tokenIn,\n address _tokenOut\n ) public override\n {\n address pair = UniswapV2Library.pairFor(factory, _tokenIn, _tokenOut);\n Observation storage observation = pairObservations[pair];\n (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) =\n UniswapV2OracleLibrary.currentCumulativePrices(address(pair));\n uint32 timeElapsed = uint32(blockTimestamp - observation.timestamp); // overflow is desired\n\n // ensure that at least one full period has passed since the last update\n if(timeElapsed >= PERIOD)\n {\n if(observation.price0Cumulative > 0)\n {\n // overflow is desired, casting never truncates\n // cumulative price is in (uq112x112 price * seconds) units so we simply wrap it after division by time elapsed\n observation.price0Average = FixedPoint.uq112x112(uint224((price0Cumulative - observation.price0Cumulative) / timeElapsed));\n observation.price1Average = FixedPoint.uq112x112(uint224((price1Cumulative - observation.price1Cumulative) / timeElapsed));\n }\n observation.price0Cumulative = price0Cumulative;\n observation.price1Cumulative = price1Cumulative;\n observation.timestamp = blockTimestamp;\n }\n }\n\n /**\n * @notice Returns the rate after `update` has been called.\n */\n function consult(\n address _tokenIn,\n uint _amountIn,\n address _tokenOut\n ) public override view\n returns (uint _amountOut)\n {\n address pair = UniswapV2Library.pairFor(factory, _tokenIn, _tokenOut);\n Observation storage observation = pairObservations[pair];\n (address token0,) = UniswapV2Library.sortTokens(_tokenIn, _tokenOut);\n if (_tokenIn == token0)\n {\n _amountOut = observation.price0Average.mul(_amountIn).decode144();\n }\n else\n {\n _amountOut = observation.price1Average.mul(_amountIn).decode144();\n }\n }\n \n /**\n * @notice Calls `update` and returns the rate in a single call\n */\n function updateAndConsult(\n address _tokenIn,\n uint _amountIn,\n address _tokenOut\n ) public override\n returns (uint _amountOut)\n {\n update(_tokenIn, _tokenOut);\n return consult(_tokenIn, _amountIn, _tokenOut);\n }\n}", "sourcePath": "/home/circleci/repo/contracts/protocols/Uniswap/UniswapOracle.sol", "ast": { "absolutePath": "project:/contracts/protocols/Uniswap/UniswapOracle.sol", "exportedSymbols": { "UniswapOracle": [ 3157 ] }, "id": 3158, "license": "GPL-3.0", "nodeType": "SourceUnit", "nodes": [ { "id": 2911, "literals": [ "solidity", "^", "0.6", ".6" ], "nodeType": "PragmaDirective", "src": "204:23:14" }, { "absolutePath": "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol", "file": "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol", "id": 2912, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 1443, "src": "229:69:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol", "file": "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol", "id": 2913, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 1685, "src": "299:66:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "@uniswap/lib/contracts/libraries/FixedPoint.sol", "file": "@uniswap/lib/contracts/libraries/FixedPoint.sol", "id": 2914, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 1167, "src": "366:57:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "@openzeppelin/contracts/math/SafeMath.sol", "file": "@openzeppelin/contracts/math/SafeMath.sol", "id": 2915, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 355, "src": "424:51:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol", "file": "@uniswap/v2-periphery/contracts/libraries/UniswapV2OracleLibrary.sol", "id": 2916, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 1792, "src": "476:78:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "project:/contracts/protocols/Uniswap/UniswapV2Library.sol", "file": "./UniswapV2Library.sol", "id": 2917, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 3630, "src": "555:32:14", "symbolAliases": [], "unitAlias": "" }, { "absolutePath": "project:/contracts/protocols/Uniswap/IUniswapOracle.sol", "file": "./IUniswapOracle.sol", "id": 2918, "nodeType": "ImportDirective", "scope": 3158, "sourceUnit": 2910, "src": "588:30:14", "symbolAliases": [], "unitAlias": "" }, { "abstract": false, "baseContracts": [ { "arguments": null, "baseName": { "contractScope": null, "id": 2919, "name": "IUniswapOracle", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 2909, "src": "646:14:14", "typeDescriptions": { "typeIdentifier": "t_contract$_IUniswapOracle_$2909", "typeString": "contract IUniswapOracle" } }, "id": 2920, "nodeType": "InheritanceSpecifier", "src": "646:14:14" } ], "contractDependencies": [ 2909 ], "contractKind": "contract", "documentation": null, "fullyImplemented": true, "id": 3157, "linearizedBaseContracts": [ 3157, 2909 ], "name": "UniswapOracle", "nodeType": "ContractDefinition", "nodes": [ { "id": 2922, "libraryName": { "contractScope": null, "id": 2921, "name": "FixedPoint", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 1166, "src": "672:10:14", "typeDescriptions": { "typeIdentifier": "t_contract$_FixedPoint_$1166", "typeString": "library FixedPoint" } }, "nodeType": "UsingForDirective", "src": "666:23:14", "typeName": null }, { "canonicalName": "UniswapOracle.Observation", "id": 2933, "members": [ { "constant": false, "id": 2924, "mutability": "mutable", "name": "timestamp", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2933, "src": "720:14:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2923, "name": "uint", "nodeType": "ElementaryTypeName", "src": "720:4:14", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 2926, "mutability": "mutable", "name": "price0Cumulative", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2933, "src": "740:21:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2925, "name": "uint", "nodeType": "ElementaryTypeName", "src": "740:4:14", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 2928, "mutability": "mutable", "name": "price1Cumulative", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2933, "src": "767:21:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2927, "name": "uint", "nodeType": "ElementaryTypeName", "src": "767:4:14", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 2930, "mutability": "mutable", "name": "price0Average", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2933, "src": "794:34:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_struct$_uq112x112_$614_storage_ptr", "typeString": "struct FixedPoint.uq112x112" }, "typeName": { "contractScope": null, "id": 2929, "name": "FixedPoint.uq112x112", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 614, "src": "794:20:14", "typeDescriptions": { "typeIdentifier": "t_struct$_uq112x112_$614_storage_ptr", "typeString": "struct FixedPoint.uq112x112" } }, "value": null, "visibility": "internal" }, { "constant": false, "id": 2932, "mutability": "mutable", "name": "price1Average", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2933, "src": "834:34:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_struct$_uq112x112_$614_storage_ptr", "typeString": "struct FixedPoint.uq112x112" }, "typeName": { "contractScope": null, "id": 2931, "name": "FixedPoint.uq112x112", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 614, "src": "834:20:14", "typeDescriptions": { "typeIdentifier": "t_struct$_uq112x112_$614_storage_ptr", "typeString": "struct FixedPoint.uq112x112" } }, "value": null, "visibility": "internal" } ], "name": "Observation", "nodeType": "StructDefinition", "scope": 3157, "src": "693:180:14", "visibility": "public" }, { "baseFunctions": [ 2874 ], "constant": true, "functionSelector": "b4d1d795", "id": 2937, "mutability": "constant", "name": "PERIOD", "nodeType": "VariableDeclaration", "overrides": { "id": 2935, "nodeType": "OverrideSpecifier", "overrides": [], "src": "889:8:14" }, "scope": 3157, "src": "877:47:14", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" }, "typeName": { "id": 2934, "name": "uint", "nodeType": "ElementaryTypeName", "src": "877:4:14", "typeDescriptions": { "typeIdentifier": "t_uint256", "typeString": "uint256" } }, "value": { "argumentTypes": null, "hexValue": "3234", "id": 2936, "isConstant": false, "isLValue": false, "isPure": true, "kind": "number", "lValueRequested": false, "nodeType": "Literal", "src": "916:8:14", "subdenomination": "hours", "typeDescriptions": { "typeIdentifier": "t_rational_86400_by_1", "typeString": "int_const 86400" }, "value": "24" }, "visibility": "public" }, { "baseFunctions": [ 2879 ], "constant": false, "functionSelector": "c45a0155", "id": 2940, "mutability": "immutable", "name": "factory", "nodeType": "VariableDeclaration", "overrides": { "id": 2939, "nodeType": "OverrideSpecifier", "overrides": [], "src": "943:8:14" }, "scope": 3157, "src": "928:41:14", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 2938, "name": "address", "nodeType": "ElementaryTypeName", "src": "928:7:14", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "public" }, { "constant": false, "id": 2944, "mutability": "mutable", "name": "pairObservations", "nodeType": "VariableDeclaration", "overrides": null, "scope": 3157, "src": "1049:56:14", "stateVariable": true, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_address_$_t_struct$_Observation_$2933_storage_$", "typeString": "mapping(address => struct UniswapOracle.Observation)" }, "typeName": { "id": 2943, "keyType": { "id": 2941, "name": "address", "nodeType": "ElementaryTypeName", "src": "1057:7:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "Mapping", "src": "1049:31:14", "typeDescriptions": { "typeIdentifier": "t_mapping$_t_address_$_t_struct$_Observation_$2933_storage_$", "typeString": "mapping(address => struct UniswapOracle.Observation)" }, "valueType": { "contractScope": null, "id": 2942, "name": "Observation", "nodeType": "UserDefinedTypeName", "referencedDeclaration": 2933, "src": "1068:11:14", "typeDescriptions": { "typeIdentifier": "t_struct$_Observation_$2933_storage_ptr", "typeString": "struct UniswapOracle.Observation" } } }, "value": null, "visibility": "private" }, { "body": { "id": 2953, "nodeType": "Block", "src": "1159:29:14", "statements": [ { "expression": { "argumentTypes": null, "id": 2951, "isConstant": false, "isLValue": false, "isPure": false, "lValueRequested": false, "leftHandSide": { "argumentTypes": null, "id": 2949, "name": "factory", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2940, "src": "1165:7:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "nodeType": "Assignment", "operator": "=", "rightHandSide": { "argumentTypes": null, "id": 2950, "name": "_factory", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2946, "src": "1175:8:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "src": "1165:18:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "id": 2952, "nodeType": "ExpressionStatement", "src": "1165:18:14" } ] }, "documentation": null, "id": 2954, "implemented": true, "kind": "constructor", "modifiers": [], "name": "", "nodeType": "FunctionDefinition", "overrides": null, "parameters": { "id": 2947, "nodeType": "ParameterList", "parameters": [ { "constant": false, "id": 2946, "mutability": "mutable", "name": "_factory", "nodeType": "VariableDeclaration", "overrides": null, "scope": 2954, "src": "1129:16:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 2945, "name": "address", "nodeType": "ElementaryTypeName", "src": "1129:7:14", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "src": "1123:26:14" }, "returnParameters": { "id": 2948, "nodeType": "ParameterList", "parameters": [], "src": "1159:0:14" }, "scope": 3157, "src": "1112:76:14", "stateMutability": "nonpayable", "virtual": false, "visibility": "public" }, { "baseFunctions": [ 2886 ], "body": { "id": 3067, "nodeType": "Block", "src": "1390:1158:14", "statements": [ { "assignments": [ 2964 ], "declarations": [ { "constant": false, "id": 2964, "mutability": "mutable", "name": "pair", "nodeType": "VariableDeclaration", "overrides": null, "scope": 3067, "src": "1396:12:14", "stateVariable": false, "storageLocation": "default", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" }, "typeName": { "id": 2963, "name": "address", "nodeType": "ElementaryTypeName", "src": "1396:7:14", "stateMutability": "nonpayable", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, "value": null, "visibility": "internal" } ], "id": 2971, "initialValue": { "argumentTypes": null, "arguments": [ { "argumentTypes": null, "id": 2967, "name": "factory", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2940, "src": "1436:7:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, { "argumentTypes": null, "id": 2968, "name": "_tokenIn", "nodeType": "Identifier", "overloadedDeclarations": [], "referencedDeclaration": 2957, "src": "1445:8:14", "typeDescriptions": { "typeIdentifier": "t_address", "typeString": "address" } }, { "argumentTypes": null, "id": 2969, "name": "_tokenOut",