1a6a4ebfbb
Signed-off-by: AlienTornadosaurusHex <>
181 lines
14 KiB
HTML
181 lines
14 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<title>LCOV - lcov.info - v1/libraries/UniswapV3OracleHelper.sol</title>
|
|
<link rel="stylesheet" type="text/css" href="../../gcov.css">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="title">LCOV - code coverage report</td></tr>
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
|
|
<tr>
|
|
<td width="100%">
|
|
<table cellpadding=1 border=0 width="100%">
|
|
<tr>
|
|
<td width="10%" class="headerItem">Current view:</td>
|
|
<td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">v1/libraries</a> - UniswapV3OracleHelper.sol<span style="font-size: 80%;"> (source / <a href="UniswapV3OracleHelper.sol.func-sort-c.html">functions</a>)</span></td>
|
|
<td width="5%"></td>
|
|
<td width="15%"></td>
|
|
<td width="10%" class="headerCovTableHead">Hit</td>
|
|
<td width="10%" class="headerCovTableHead">Total</td>
|
|
<td width="15%" class="headerCovTableHead">Coverage</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Test:</td>
|
|
<td class="headerValue">lcov.info</td>
|
|
<td></td>
|
|
<td class="headerItem">Lines:</td>
|
|
<td class="headerCovTableEntry">0</td>
|
|
<td class="headerCovTableEntry">8</td>
|
|
<td class="headerCovTableEntryLo">0.0 %</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Date:</td>
|
|
<td class="headerValue">2023-06-20 21:04:08</td>
|
|
<td></td>
|
|
<td class="headerItem">Functions:</td>
|
|
<td class="headerCovTableEntry">0</td>
|
|
<td class="headerCovTableEntry">4</td>
|
|
<td class="headerCovTableEntryLo">0.0 %</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="headerItem">Legend:</td>
|
|
<td class="headerValueLeg"> Lines:
|
|
<span class="coverLegendCov">hit</span>
|
|
<span class="coverLegendNoCov">not hit</span>
|
|
</td>
|
|
<td></td>
|
|
</tr>
|
|
<tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
</table>
|
|
|
|
<table cellpadding=0 cellspacing=0 border=0>
|
|
<tr>
|
|
<td><br></td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<pre class="sourceHeading"> Line data Source code</pre>
|
|
<pre class="source">
|
|
<a name="1"><span class="lineNum"> 1 </span> : // SPDX-License-Identifier: MIT</a>
|
|
<a name="2"><span class="lineNum"> 2 </span> : </a>
|
|
<a name="3"><span class="lineNum"> 3 </span> : pragma solidity ^0.6.12;</a>
|
|
<a name="4"><span class="lineNum"> 4 </span> : </a>
|
|
<a name="5"><span class="lineNum"> 5 </span> : import { OracleLibrary } from "@uniswap/v3-periphery/contracts/libraries/OracleLibrary.sol";</a>
|
|
<a name="6"><span class="lineNum"> 6 </span> : import { IUniswapV3Factory } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";</a>
|
|
<a name="7"><span class="lineNum"> 7 </span> : import { LowGasSafeMath } from "@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol";</a>
|
|
<a name="8"><span class="lineNum"> 8 </span> : </a>
|
|
<a name="9"><span class="lineNum"> 9 </span> : interface IERC20Decimals {</a>
|
|
<a name="10"><span class="lineNum"> 10 </span> : function decimals() external view returns (uint8);</a>
|
|
<a name="11"><span class="lineNum"> 11 </span> : }</a>
|
|
<a name="12"><span class="lineNum"> 12 </span> : </a>
|
|
<a name="13"><span class="lineNum"> 13 </span> : library UniswapV3OracleHelper {</a>
|
|
<a name="14"><span class="lineNum"> 14 </span> : using LowGasSafeMath for uint256;</a>
|
|
<a name="15"><span class="lineNum"> 15 </span> : </a>
|
|
<a name="16"><span class="lineNum"> 16 </span> : IUniswapV3Factory internal constant UniswapV3Factory = IUniswapV3Factory(0x1F98431c8aD98523631AE4a59f267346ea31F984);</a>
|
|
<a name="17"><span class="lineNum"> 17 </span> : address internal constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;</a>
|
|
<a name="18"><span class="lineNum"> 18 </span> : uint256 internal constant RATIO_DIVIDER = 1e18;</a>
|
|
<a name="19"><span class="lineNum"> 19 </span> : </a>
|
|
<a name="20"><span class="lineNum"> 20 </span> : /**</a>
|
|
<a name="21"><span class="lineNum"> 21 </span> : * @notice This function should return the price of baseToken in quoteToken, as in: quote/base (WETH/TORN)</a>
|
|
<a name="22"><span class="lineNum"> 22 </span> : * @dev uses the Uniswap written OracleLibrary "getQuoteAtTick", does not call external libraries,</a>
|
|
<a name="23"><span class="lineNum"> 23 </span> : * uses decimals() for the correct power of 10</a>
|
|
<a name="24"><span class="lineNum"> 24 </span> : * @param baseToken token which will be denominated in quote token</a>
|
|
<a name="25"><span class="lineNum"> 25 </span> : * @param quoteToken token in which price will be denominated</a>
|
|
<a name="26"><span class="lineNum"> 26 </span> : * @param fee the uniswap pool fee, pools have different fees so this is a pool selector for our usecase</a>
|
|
<a name="27"><span class="lineNum"> 27 </span> : * @param period the amount of seconds we are going to look into the past for the new token price</a>
|
|
<a name="28"><span class="lineNum"> 28 </span> : * @return returns the price of baseToken in quoteToken</a>
|
|
<a name="29"><span class="lineNum"> 29 </span> : * */</a>
|
|
<a name="30"><span class="lineNum"> 30 </span> : function getPriceOfTokenInToken(</a>
|
|
<a name="31"><span class="lineNum"> 31 </span> : address baseToken,</a>
|
|
<a name="32"><span class="lineNum"> 32 </span> : address quoteToken,</a>
|
|
<a name="33"><span class="lineNum"> 33 </span> : uint24 fee,</a>
|
|
<a name="34"><span class="lineNum"> 34 </span> : uint32 period</a>
|
|
<a name="35"><span class="lineNum"> 35 </span> : ) internal view returns (uint256) {</a>
|
|
<a name="36"><span class="lineNum"> 36 </span><span class="lineNoCov"> 0 : uint128 base = uint128(10)**uint128(IERC20Decimals(quoteToken).decimals());</span></a>
|
|
<a name="37"><span class="lineNum"> 37 </span><span class="lineNoCov"> 0 : if (baseToken == quoteToken) return base;</span></a>
|
|
<a name="38"><span class="lineNum"> 38 </span> : else</a>
|
|
<a name="39"><span class="lineNum"> 39 </span><span class="lineNoCov"> 0 : return</span></a>
|
|
<a name="40"><span class="lineNum"> 40 </span><span class="lineNoCov"> 0 : OracleLibrary.getQuoteAtTick(</span></a>
|
|
<a name="41"><span class="lineNum"> 41 </span> : OracleLibrary.consult(UniswapV3Factory.getPool(baseToken, quoteToken, fee), period),</a>
|
|
<a name="42"><span class="lineNum"> 42 </span> : base,</a>
|
|
<a name="43"><span class="lineNum"> 43 </span> : baseToken,</a>
|
|
<a name="44"><span class="lineNum"> 44 </span> : quoteToken</a>
|
|
<a name="45"><span class="lineNum"> 45 </span> : );</a>
|
|
<a name="46"><span class="lineNum"> 46 </span> : }</a>
|
|
<a name="47"><span class="lineNum"> 47 </span> : </a>
|
|
<a name="48"><span class="lineNum"> 48 </span> : /**</a>
|
|
<a name="49"><span class="lineNum"> 49 </span> : * @notice This function should return the price of token in WETH</a>
|
|
<a name="50"><span class="lineNum"> 50 </span> : * @dev simply feeds WETH in to the above function</a>
|
|
<a name="51"><span class="lineNum"> 51 </span> : * @param token token which will be denominated in WETH</a>
|
|
<a name="52"><span class="lineNum"> 52 </span> : * @param fee the uniswap pool fee, pools have different fees so this is a pool selector for our usecase</a>
|
|
<a name="53"><span class="lineNum"> 53 </span> : * @param period the amount of seconds we are going to look into the past for the new token price</a>
|
|
<a name="54"><span class="lineNum"> 54 </span> : * @return returns the price of token in WETH</a>
|
|
<a name="55"><span class="lineNum"> 55 </span> : * */</a>
|
|
<a name="56"><span class="lineNum"> 56 </span> : function getPriceOfTokenInWETH(</a>
|
|
<a name="57"><span class="lineNum"> 57 </span> : address token,</a>
|
|
<a name="58"><span class="lineNum"> 58 </span> : uint24 fee,</a>
|
|
<a name="59"><span class="lineNum"> 59 </span> : uint32 period</a>
|
|
<a name="60"><span class="lineNum"> 60 </span> : ) internal view returns (uint256) {</a>
|
|
<a name="61"><span class="lineNum"> 61 </span><span class="lineNoCov"> 0 : return getPriceOfTokenInToken(token, WETH, fee, period);</span></a>
|
|
<a name="62"><span class="lineNum"> 62 </span> : }</a>
|
|
<a name="63"><span class="lineNum"> 63 </span> : </a>
|
|
<a name="64"><span class="lineNum"> 64 </span> : /**</a>
|
|
<a name="65"><span class="lineNum"> 65 </span> : * @notice This function should return the price of WETH in token</a>
|
|
<a name="66"><span class="lineNum"> 66 </span> : * @dev simply feeds WETH into getPriceOfTokenInToken</a>
|
|
<a name="67"><span class="lineNum"> 67 </span> : * @param token token which WETH will be denominated in</a>
|
|
<a name="68"><span class="lineNum"> 68 </span> : * @param fee the uniswap pool fee, pools have different fees so this is a pool selector for our usecase</a>
|
|
<a name="69"><span class="lineNum"> 69 </span> : * @param period the amount of seconds we are going to look into the past for the new token price</a>
|
|
<a name="70"><span class="lineNum"> 70 </span> : * @return returns the price of token in WETH</a>
|
|
<a name="71"><span class="lineNum"> 71 </span> : * */</a>
|
|
<a name="72"><span class="lineNum"> 72 </span> : function getPriceOfWETHInToken(</a>
|
|
<a name="73"><span class="lineNum"> 73 </span> : address token,</a>
|
|
<a name="74"><span class="lineNum"> 74 </span> : uint24 fee,</a>
|
|
<a name="75"><span class="lineNum"> 75 </span> : uint32 period</a>
|
|
<a name="76"><span class="lineNum"> 76 </span> : ) internal view returns (uint256) {</a>
|
|
<a name="77"><span class="lineNum"> 77 </span><span class="lineNoCov"> 0 : return getPriceOfTokenInToken(WETH, token, fee, period);</span></a>
|
|
<a name="78"><span class="lineNum"> 78 </span> : }</a>
|
|
<a name="79"><span class="lineNum"> 79 </span> : </a>
|
|
<a name="80"><span class="lineNum"> 80 </span> : /**</a>
|
|
<a name="81"><span class="lineNum"> 81 </span> : * @notice This function returns the price of token[0] in token[1], but more precisely and importantly the price ratio of the tokens in WETH</a>
|
|
<a name="82"><span class="lineNum"> 82 </span> : * @dev this is done as to always have good prices due to WETH-token pools mostly always having the most liquidity</a>
|
|
<a name="83"><span class="lineNum"> 83 </span> : * @param tokens array of tokens to get ratio for</a>
|
|
<a name="84"><span class="lineNum"> 84 </span> : * @param fees the uniswap pool FEES, since these are two independent tokens</a>
|
|
<a name="85"><span class="lineNum"> 85 </span> : * @param period the amount of seconds we are going to look into the past for the new token price</a>
|
|
<a name="86"><span class="lineNum"> 86 </span> : * @return returns the price of token[0] in token[1]</a>
|
|
<a name="87"><span class="lineNum"> 87 </span> : * */</a>
|
|
<a name="88"><span class="lineNum"> 88 </span> : function getPriceRatioOfTokens(</a>
|
|
<a name="89"><span class="lineNum"> 89 </span> : address[2] memory tokens,</a>
|
|
<a name="90"><span class="lineNum"> 90 </span> : uint24[2] memory fees,</a>
|
|
<a name="91"><span class="lineNum"> 91 </span> : uint32 period</a>
|
|
<a name="92"><span class="lineNum"> 92 </span> : ) internal view returns (uint256) {</a>
|
|
<a name="93"><span class="lineNum"> 93 </span><span class="lineNoCov"> 0 : return</span></a>
|
|
<a name="94"><span class="lineNum"> 94 </span><span class="lineNoCov"> 0 : getPriceOfTokenInWETH(tokens[0], fees[0], period).mul(RATIO_DIVIDER) / getPriceOfTokenInWETH(tokens[1], fees[1], period);</span></a>
|
|
<a name="95"><span class="lineNum"> 95 </span> : }</a>
|
|
<a name="96"><span class="lineNum"> 96 </span> : }</a>
|
|
</pre>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
|
|
<table width="100%" border=0 cellspacing=0 cellpadding=0>
|
|
<tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
|
|
<tr><td class="versionInfo">Generated by: <a href="https://github.com/linux-test-project/lcov" target="_parent">LCOV version 1.16</a></td></tr>
|
|
</table>
|
|
<br>
|
|
|
|
</body>
|
|
</html>
|