1a6a4ebfbb
Signed-off-by: AlienTornadosaurusHex <>
437 lines
40 KiB
HTML
437 lines
40 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 - v2/InstanceRegistry.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">v2</a> - InstanceRegistry.sol<span style="font-size: 80%;"> (source / <a href="InstanceRegistry.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">51</td>
|
|
<td class="headerCovTableEntry">53</td>
|
|
<td class="headerCovTableEntryHi">96.2 %</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">15</td>
|
|
<td class="headerCovTableEntry">18</td>
|
|
<td class="headerCovTableEntryMed">83.3 %</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> : pragma experimental ABIEncoderV2;</a>
|
|
<a name="5"><span class="lineNum"> 5 </span> : </a>
|
|
<a name="6"><span class="lineNum"> 6 </span> : // OZ Imports</a>
|
|
<a name="7"><span class="lineNum"> 7 </span> : </a>
|
|
<a name="8"><span class="lineNum"> 8 </span> : import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";</a>
|
|
<a name="9"><span class="lineNum"> 9 </span> : import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";</a>
|
|
<a name="10"><span class="lineNum"> 10 </span> : import { Initializable } from "@openzeppelin/contracts/proxy/Initializable.sol";</a>
|
|
<a name="11"><span class="lineNum"> 11 </span> : </a>
|
|
<a name="12"><span class="lineNum"> 12 </span> : // Tornado Imports</a>
|
|
<a name="13"><span class="lineNum"> 13 </span> : </a>
|
|
<a name="14"><span class="lineNum"> 14 </span> : import { ITornadoInstance } from "tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol";</a>
|
|
<a name="15"><span class="lineNum"> 15 </span> : </a>
|
|
<a name="16"><span class="lineNum"> 16 </span> : // Local imports</a>
|
|
<a name="17"><span class="lineNum"> 17 </span> : </a>
|
|
<a name="18"><span class="lineNum"> 18 </span> : import { ENSResolver } from "./libraries/ENSResolver.sol";</a>
|
|
<a name="19"><span class="lineNum"> 19 </span> : import { NameEncoder } from "./libraries/NameEncoder.sol";</a>
|
|
<a name="20"><span class="lineNum"> 20 </span> : import { TornadoRouter } from "./TornadoRouter.sol";</a>
|
|
<a name="21"><span class="lineNum"> 21 </span> : </a>
|
|
<a name="22"><span class="lineNum"> 22 </span> : /**</a>
|
|
<a name="23"><span class="lineNum"> 23 </span> : * @title InstanceRegistry</a>
|
|
<a name="24"><span class="lineNum"> 24 </span> : * @author AlienTornadosaurusHex</a>
|
|
<a name="25"><span class="lineNum"> 25 </span> : * @notice A contract which enumerates Tornado Cash pool instances, and also stores essential data regarding</a>
|
|
<a name="26"><span class="lineNum"> 26 </span> : * them.</a>
|
|
<a name="27"><span class="lineNum"> 27 </span> : * @dev This contract will help us layout storage properly for a proxy upgrade for the impl</a>
|
|
<a name="28"><span class="lineNum"> 28 </span> : * InstanceRegistry.</a>
|
|
<a name="29"><span class="lineNum"> 29 </span> : */</a>
|
|
<a name="30"><span class="lineNum"> 30 </span> : contract InstanceRegistryLegacyStorage {</a>
|
|
<a name="31"><span class="lineNum"> 31 </span> : /* From first contract, just so right uint type is chosen */</a>
|
|
<a name="32"><span class="lineNum"> 32 </span> : enum LegacyStatePlaceholder {</a>
|
|
<a name="33"><span class="lineNum"> 33 </span> : DISABLED,</a>
|
|
<a name="34"><span class="lineNum"> 34 </span> : ENABLED</a>
|
|
<a name="35"><span class="lineNum"> 35 </span> : }</a>
|
|
<a name="36"><span class="lineNum"> 36 </span> : </a>
|
|
<a name="37"><span class="lineNum"> 37 </span> : /* From first contract, just if necessary to be able to properly unpack and determine value storage</a>
|
|
<a name="38"><span class="lineNum"> 38 </span> : addresses and offsets */</a>
|
|
<a name="39"><span class="lineNum"> 39 </span> : struct LegacyInstanceStructPlaceholder {</a>
|
|
<a name="40"><span class="lineNum"> 40 </span> : bool deprecatedIsERC20;</a>
|
|
<a name="41"><span class="lineNum"> 41 </span> : address deprecatedToken;</a>
|
|
<a name="42"><span class="lineNum"> 42 </span> : LegacyStatePlaceholder deprecatedState;</a>
|
|
<a name="43"><span class="lineNum"> 43 </span> : uint24 deprecatedUniswapPoolSwappingFee;</a>
|
|
<a name="44"><span class="lineNum"> 44 </span> : uint32 deprecatedProtocolFeePercentage;</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> : * @dev From Initializable.sol of first contract</a>
|
|
<a name="49"><span class="lineNum"> 49 </span> : */</a>
|
|
<a name="50"><span class="lineNum"> 50 </span> : bool private _deprecatedInitialized;</a>
|
|
<a name="51"><span class="lineNum"> 51 </span> : </a>
|
|
<a name="52"><span class="lineNum"> 52 </span> : /**</a>
|
|
<a name="53"><span class="lineNum"> 53 </span> : * @dev From Initializable.sol of first contract</a>
|
|
<a name="54"><span class="lineNum"> 54 </span> : */</a>
|
|
<a name="55"><span class="lineNum"> 55 </span> : bool private _deprecatedInitializing;</a>
|
|
<a name="56"><span class="lineNum"> 56 </span> : </a>
|
|
<a name="57"><span class="lineNum"> 57 </span> : /**</a>
|
|
<a name="58"><span class="lineNum"> 58 </span> : * @dev From first contract</a>
|
|
<a name="59"><span class="lineNum"> 59 </span> : */</a>
|
|
<a name="60"><span class="lineNum"> 60 </span> : address private _deprecatedRouterAddress;</a>
|
|
<a name="61"><span class="lineNum"> 61 </span> : </a>
|
|
<a name="62"><span class="lineNum"> 62 </span> : /**</a>
|
|
<a name="63"><span class="lineNum"> 63 </span> : * @dev From first contract</a>
|
|
<a name="64"><span class="lineNum"> 64 </span> : */</a>
|
|
<a name="65"><span class="lineNum"> 65 </span> : mapping(address => LegacyInstanceStructPlaceholder) private _deprecatedInstances;</a>
|
|
<a name="66"><span class="lineNum"> 66 </span> : </a>
|
|
<a name="67"><span class="lineNum"> 67 </span> : /**</a>
|
|
<a name="68"><span class="lineNum"> 68 </span> : * @dev From first contract</a>
|
|
<a name="69"><span class="lineNum"> 69 </span> : */</a>
|
|
<a name="70"><span class="lineNum"> 70 </span> : ITornadoInstance[] private _deprecatedInstanceIds;</a>
|
|
<a name="71"><span class="lineNum"> 71 </span> : }</a>
|
|
<a name="72"><span class="lineNum"> 72 </span> : </a>
|
|
<a name="73"><span class="lineNum"> 73 </span> : /**</a>
|
|
<a name="74"><span class="lineNum"> 74 </span> : * @dev This struct holds barebones information regarding an instance and its data location in storage.</a>
|
|
<a name="75"><span class="lineNum"> 75 </span> : */</a>
|
|
<a name="76"><span class="lineNum"> 76 </span> : struct InstanceState {</a>
|
|
<a name="77"><span class="lineNum"> 77 </span> : IERC20 token;</a>
|
|
<a name="78"><span class="lineNum"> 78 </span> : uint80 index;</a>
|
|
<a name="79"><span class="lineNum"> 79 </span> : bool isERC20;</a>
|
|
<a name="80"><span class="lineNum"> 80 </span> : bool isEnabled;</a>
|
|
<a name="81"><span class="lineNum"> 81 </span> : }</a>
|
|
<a name="82"><span class="lineNum"> 82 </span> : </a>
|
|
<a name="83"><span class="lineNum"> 83 </span> : /**</a>
|
|
<a name="84"><span class="lineNum"> 84 </span> : * @title InstanceRegistry</a>
|
|
<a name="85"><span class="lineNum"> 85 </span> : * @author AlienTornadosaurusHex</a>
|
|
<a name="86"><span class="lineNum"> 86 </span> : * @notice A contract which enumerates Tornado Cash pool instances, and also stores essential data regarding</a>
|
|
<a name="87"><span class="lineNum"> 87 </span> : * them.</a>
|
|
<a name="88"><span class="lineNum"> 88 </span> : * @dev This is an improved version of the InstanceRegistry with a modified design from the original contract.</a>
|
|
<a name="89"><span class="lineNum"> 89 </span> : */</a>
|
|
<a name="90"><span class="lineNum"> 90 </span> : contract InstanceRegistry is InstanceRegistryLegacyStorage, ENSResolver, Initializable {</a>
|
|
<a name="91"><span class="lineNum"> 91 </span> : using SafeERC20 for IERC20;</a>
|
|
<a name="92"><span class="lineNum"> 92 </span> : </a>
|
|
<a name="93"><span class="lineNum"> 93 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="94"><span class="lineNum"> 94 </span> : </a>
|
|
<a name="95"><span class="lineNum"> 95 </span> : /**</a>
|
|
<a name="96"><span class="lineNum"> 96 </span> : * @notice The address of the Governance proxy</a>
|
|
<a name="97"><span class="lineNum"> 97 </span> : */</a>
|
|
<a name="98"><span class="lineNum"> 98 </span> : address public immutable governanceProxyAddress;</a>
|
|
<a name="99"><span class="lineNum"> 99 </span> : </a>
|
|
<a name="100"><span class="lineNum"> 100 </span> : /**</a>
|
|
<a name="101"><span class="lineNum"> 101 </span> : * @notice Essential data regarding instances, see struct above</a>
|
|
<a name="102"><span class="lineNum"> 102 </span> : */</a>
|
|
<a name="103"><span class="lineNum"> 103 </span> : mapping(ITornadoInstance => InstanceState) public instanceData;</a>
|
|
<a name="104"><span class="lineNum"> 104 </span> : </a>
|
|
<a name="105"><span class="lineNum"> 105 </span> : /**</a>
|
|
<a name="106"><span class="lineNum"> 106 </span> : * @notice All instances enumerable</a>
|
|
<a name="107"><span class="lineNum"> 107 </span> : */</a>
|
|
<a name="108"><span class="lineNum"> 108 </span> : ITornadoInstance[] public instances;</a>
|
|
<a name="109"><span class="lineNum"> 109 </span> : </a>
|
|
<a name="110"><span class="lineNum"> 110 </span> : /**</a>
|
|
<a name="111"><span class="lineNum"> 111 </span> : * @notice The router which processes txs which we must command to approve tokens</a>
|
|
<a name="112"><span class="lineNum"> 112 </span> : */</a>
|
|
<a name="113"><span class="lineNum"> 113 </span> : TornadoRouter public router;</a>
|
|
<a name="114"><span class="lineNum"> 114 </span> : </a>
|
|
<a name="115"><span class="lineNum"> 115 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="116"><span class="lineNum"> 116 </span> : </a>
|
|
<a name="117"><span class="lineNum"> 117 </span> : event RouterRegistered(address newRouterAddress);</a>
|
|
<a name="118"><span class="lineNum"> 118 </span> : event InstanceAdded(address indexed instance, uint80 dataIndex, bool isERC20);</a>
|
|
<a name="119"><span class="lineNum"> 119 </span> : event InstanceRemoved(address indexed instance);</a>
|
|
<a name="120"><span class="lineNum"> 120 </span> : </a>
|
|
<a name="121"><span class="lineNum"> 121 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LOGIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="122"><span class="lineNum"> 122 </span> : </a>
|
|
<a name="123"><span class="lineNum"> 123 </span> : constructor(address _governanceProxyAddress) public {</a>
|
|
<a name="124"><span class="lineNum"> 124 </span> : governanceProxyAddress = _governanceProxyAddress;</a>
|
|
<a name="125"><span class="lineNum"> 125 </span> : }</a>
|
|
<a name="126"><span class="lineNum"> 126 </span> : </a>
|
|
<a name="127"><span class="lineNum"> 127 </span> : modifier onlyGovernance() {</a>
|
|
<a name="128"><span class="lineNum"> 128 </span> : require(msg.sender == governanceProxyAddress, "InstanceRegistry: onlyGovernance");</a>
|
|
<a name="129"><span class="lineNum"> 129 </span> : _;</a>
|
|
<a name="130"><span class="lineNum"> 130 </span> : }</a>
|
|
<a name="131"><span class="lineNum"> 131 </span> : </a>
|
|
<a name="132"><span class="lineNum"> 132 </span> : function version() public pure virtual returns (string memory) {</a>
|
|
<a name="133"><span class="lineNum"> 133 </span><span class="lineCov"> 2 : return "v2-oracle-manager";</span></a>
|
|
<a name="134"><span class="lineNum"> 134 </span> : }</a>
|
|
<a name="135"><span class="lineNum"> 135 </span> : </a>
|
|
<a name="136"><span class="lineNum"> 136 </span> : function initialize(ITornadoInstance[] memory _instances, TornadoRouter _router)</a>
|
|
<a name="137"><span class="lineNum"> 137 </span> : external</a>
|
|
<a name="138"><span class="lineNum"> 138 </span> : onlyGovernance</a>
|
|
<a name="139"><span class="lineNum"> 139 </span> : initializer</a>
|
|
<a name="140"><span class="lineNum"> 140 </span> : {</a>
|
|
<a name="141"><span class="lineNum"> 141 </span><span class="lineCov"> 4 : uint256 numInstances = _instances.length;</span></a>
|
|
<a name="142"><span class="lineNum"> 142 </span> : </a>
|
|
<a name="143"><span class="lineNum"> 143 </span> : // Router must be initialized before otherwise below will fail</a>
|
|
<a name="144"><span class="lineNum"> 144 </span><span class="lineCov"> 4 : router = _router;</span></a>
|
|
<a name="145"><span class="lineNum"> 145 </span> : </a>
|
|
<a name="146"><span class="lineNum"> 146 </span><span class="lineCov"> 4 : for (uint256 i = 0; i < numInstances; i++) {</span></a>
|
|
<a name="147"><span class="lineNum"> 147 </span><span class="lineCov"> 68 : addInstance(_instances[i]);</span></a>
|
|
<a name="148"><span class="lineNum"> 148 </span> : }</a>
|
|
<a name="149"><span class="lineNum"> 149 </span> : }</a>
|
|
<a name="150"><span class="lineNum"> 150 </span> : </a>
|
|
<a name="151"><span class="lineNum"> 151 </span> : function addInstance(ITornadoInstance _instance) public virtual onlyGovernance {</a>
|
|
<a name="152"><span class="lineNum"> 152 </span> : // The instance may not already be enabled</a>
|
|
<a name="153"><span class="lineNum"> 153 </span> : </a>
|
|
<a name="154"><span class="lineNum"> 154 </span><span class="lineCov"> 80 : bool isEnabled = instanceData[_instance].isEnabled;</span></a>
|
|
<a name="155"><span class="lineNum"> 155 </span> : </a>
|
|
<a name="156"><span class="lineNum"> 156 </span><span class="lineCov"> 80 : require(!isEnabled, "InstanceRegistry: can't add the same instance.");</span></a>
|
|
<a name="157"><span class="lineNum"> 157 </span> : </a>
|
|
<a name="158"><span class="lineNum"> 158 </span> : // Determine whether it is an ERC20 or not</a>
|
|
<a name="159"><span class="lineNum"> 159 </span> : </a>
|
|
<a name="160"><span class="lineNum"> 160 </span><span class="lineCov"> 80 : IERC20 token = IERC20(address(0));</span></a>
|
|
<a name="161"><span class="lineNum"> 161 </span> : </a>
|
|
<a name="162"><span class="lineNum"> 162 </span><span class="lineCov"> 80 : bool isERC20 = false;</span></a>
|
|
<a name="163"><span class="lineNum"> 163 </span> : </a>
|
|
<a name="164"><span class="lineNum"> 164 </span> : // ETH instances do not know of a `token()` call</a>
|
|
<a name="165"><span class="lineNum"> 165 </span><span class="lineCov"> 80 : try _instance.token() returns (address _tokenAddress) {</span></a>
|
|
<a name="166"><span class="lineNum"> 166 </span> : token = IERC20(_tokenAddress);</a>
|
|
<a name="167"><span class="lineNum"> 167 </span> : isERC20 = true;</a>
|
|
<a name="168"><span class="lineNum"> 168 </span> : } catch {</a>
|
|
<a name="169"><span class="lineNum"> 169 </span> : /* It's an ETH instance, do nothing */</a>
|
|
<a name="170"><span class="lineNum"> 170 </span> : }</a>
|
|
<a name="171"><span class="lineNum"> 171 </span> : </a>
|
|
<a name="172"><span class="lineNum"> 172 </span> : // If it is ERC20 then make the router give an approval for the Tornado instance to allow the token</a>
|
|
<a name="173"><span class="lineNum"> 173 </span> : // amount, if it hasn't already done so</a>
|
|
<a name="174"><span class="lineNum"> 174 </span><span class="lineCov"> 80 : if (isERC20) {</span></a>
|
|
<a name="175"><span class="lineNum"> 175 </span><span class="lineCov"> 63 : uint256 routerAllowanceForInstance = token.allowance(address(router), address(_instance));</span></a>
|
|
<a name="176"><span class="lineNum"> 176 </span> : </a>
|
|
<a name="177"><span class="lineNum"> 177 </span><span class="lineCov"> 63 : if (routerAllowanceForInstance == 0) {</span></a>
|
|
<a name="178"><span class="lineNum"> 178 </span><span class="lineCov"> 63 : router.approveTokenForInstance(token, address(_instance), type(uint256).max);</span></a>
|
|
<a name="179"><span class="lineNum"> 179 </span> : }</a>
|
|
<a name="180"><span class="lineNum"> 180 </span> : }</a>
|
|
<a name="181"><span class="lineNum"> 181 </span> : </a>
|
|
<a name="182"><span class="lineNum"> 182 </span> : // Add it to the enumerable</a>
|
|
<a name="183"><span class="lineNum"> 183 </span><span class="lineCov"> 80 : instances.push(_instance);</span></a>
|
|
<a name="184"><span class="lineNum"> 184 </span> : </a>
|
|
<a name="185"><span class="lineNum"> 185 </span> : // Read out the index of the instance in the enumerable</a>
|
|
<a name="186"><span class="lineNum"> 186 </span><span class="lineCov"> 80 : uint64 instanceIndex = uint64(instances.length - 1);</span></a>
|
|
<a name="187"><span class="lineNum"> 187 </span> : </a>
|
|
<a name="188"><span class="lineNum"> 188 </span> : // Store the collected data of the instance</a>
|
|
<a name="189"><span class="lineNum"> 189 </span><span class="lineCov"> 80 : instanceData[_instance] =</span></a>
|
|
<a name="190"><span class="lineNum"> 190 </span> : InstanceState({ token: token, index: instanceIndex, isERC20: isERC20, isEnabled: true });</a>
|
|
<a name="191"><span class="lineNum"> 191 </span> : </a>
|
|
<a name="192"><span class="lineNum"> 192 </span> : // Log</a>
|
|
<a name="193"><span class="lineNum"> 193 </span><span class="lineCov"> 80 : emit InstanceAdded(address(_instance), instanceIndex, isERC20);</span></a>
|
|
<a name="194"><span class="lineNum"> 194 </span> : }</a>
|
|
<a name="195"><span class="lineNum"> 195 </span> : </a>
|
|
<a name="196"><span class="lineNum"> 196 </span> : /**</a>
|
|
<a name="197"><span class="lineNum"> 197 </span> : * @notice Remove an instance, only callable by Governance.</a>
|
|
<a name="198"><span class="lineNum"> 198 </span> : * @dev The access modifier is in the internal call.</a>
|
|
<a name="199"><span class="lineNum"> 199 </span> : * @param _instanceIndex The index of the instance to remove.</a>
|
|
<a name="200"><span class="lineNum"> 200 </span> : */</a>
|
|
<a name="201"><span class="lineNum"> 201 </span> : function removeInstanceByIndex(uint256 _instanceIndex) public virtual {</a>
|
|
<a name="202"><span class="lineNum"> 202 </span><span class="lineCov"> 1 : _removeInstanceByAddress(address(instances[_instanceIndex]));</span></a>
|
|
<a name="203"><span class="lineNum"> 203 </span> : }</a>
|
|
<a name="204"><span class="lineNum"> 204 </span> : </a>
|
|
<a name="205"><span class="lineNum"> 205 </span> : /**</a>
|
|
<a name="206"><span class="lineNum"> 206 </span> : * @notice Remove an instance, only callable by Governance.</a>
|
|
<a name="207"><span class="lineNum"> 207 </span> : * @dev The access modifier is in the internal call.</a>
|
|
<a name="208"><span class="lineNum"> 208 </span> : * @param _instanceAddress The adress of the instance to remove.</a>
|
|
<a name="209"><span class="lineNum"> 209 </span> : */</a>
|
|
<a name="210"><span class="lineNum"> 210 </span> : function removeInstanceByAddress(address _instanceAddress) public virtual {</a>
|
|
<a name="211"><span class="lineNum"> 211 </span><span class="lineCov"> 1 : _removeInstanceByAddress(_instanceAddress);</span></a>
|
|
<a name="212"><span class="lineNum"> 212 </span> : }</a>
|
|
<a name="213"><span class="lineNum"> 213 </span> : </a>
|
|
<a name="214"><span class="lineNum"> 214 </span> : function _removeInstanceByAddress(address _instanceAddress) internal virtual onlyGovernance {</a>
|
|
<a name="215"><span class="lineNum"> 215 </span> : // Grab data needed to remove the instance</a>
|
|
<a name="216"><span class="lineNum"> 216 </span> : </a>
|
|
<a name="217"><span class="lineNum"> 217 </span><span class="lineCov"> 2 : ITornadoInstance instance = ITornadoInstance(_instanceAddress);</span></a>
|
|
<a name="218"><span class="lineNum"> 218 </span><span class="lineCov"> 2 : InstanceState memory data = instanceData[instance];</span></a>
|
|
<a name="219"><span class="lineNum"> 219 </span> : </a>
|
|
<a name="220"><span class="lineNum"> 220 </span> : // Checks whether already removed, so allowance can't be killed</a>
|
|
<a name="221"><span class="lineNum"> 221 </span> : </a>
|
|
<a name="222"><span class="lineNum"> 222 </span><span class="lineCov"> 2 : require(data.isEnabled, "InstanceRegistry: already removed");</span></a>
|
|
<a name="223"><span class="lineNum"> 223 </span> : </a>
|
|
<a name="224"><span class="lineNum"> 224 </span> : // Kill the allowance of the router first (arbitrary order)</a>
|
|
<a name="225"><span class="lineNum"> 225 </span> : </a>
|
|
<a name="226"><span class="lineNum"> 226 </span><span class="lineCov"> 2 : if (data.isERC20) {</span></a>
|
|
<a name="227"><span class="lineNum"> 227 </span><span class="lineCov"> 1 : uint256 routerAllowanceForInstance = data.token.allowance(address(router), _instanceAddress);</span></a>
|
|
<a name="228"><span class="lineNum"> 228 </span> : </a>
|
|
<a name="229"><span class="lineNum"> 229 </span><span class="lineCov"> 1 : if (routerAllowanceForInstance != 0) {</span></a>
|
|
<a name="230"><span class="lineNum"> 230 </span><span class="lineCov"> 1 : router.approveTokenForInstance(data.token, _instanceAddress, 0);</span></a>
|
|
<a name="231"><span class="lineNum"> 231 </span> : }</a>
|
|
<a name="232"><span class="lineNum"> 232 </span> : }</a>
|
|
<a name="233"><span class="lineNum"> 233 </span> : </a>
|
|
<a name="234"><span class="lineNum"> 234 </span> : // We need to revert all changes, meaning modify position of last instance and change index in data</a>
|
|
<a name="235"><span class="lineNum"> 235 </span> : </a>
|
|
<a name="236"><span class="lineNum"> 236 </span><span class="lineCov"> 2 : uint64 lastInstanceIndex = uint64(instances.length - 1);</span></a>
|
|
<a name="237"><span class="lineNum"> 237 </span> : </a>
|
|
<a name="238"><span class="lineNum"> 238 </span><span class="lineCov"> 2 : ITornadoInstance lastInstance = instances[lastInstanceIndex];</span></a>
|
|
<a name="239"><span class="lineNum"> 239 </span> : </a>
|
|
<a name="240"><span class="lineNum"> 240 </span> : // Swap position of last instance with old</a>
|
|
<a name="241"><span class="lineNum"> 241 </span> : </a>
|
|
<a name="242"><span class="lineNum"> 242 </span><span class="lineCov"> 2 : instances[data.index] = lastInstance;</span></a>
|
|
<a name="243"><span class="lineNum"> 243 </span> : </a>
|
|
<a name="244"><span class="lineNum"> 244 </span><span class="lineCov"> 2 : instanceData[lastInstance].index = data.index;</span></a>
|
|
<a name="245"><span class="lineNum"> 245 </span> : </a>
|
|
<a name="246"><span class="lineNum"> 246 </span><span class="lineCov"> 2 : instances.pop();</span></a>
|
|
<a name="247"><span class="lineNum"> 247 </span> : </a>
|
|
<a name="248"><span class="lineNum"> 248 </span> : // Delete old instance data</a>
|
|
<a name="249"><span class="lineNum"> 249 </span> : </a>
|
|
<a name="250"><span class="lineNum"> 250 </span><span class="lineCov"> 2 : delete instanceData[instance];</span></a>
|
|
<a name="251"><span class="lineNum"> 251 </span> : </a>
|
|
<a name="252"><span class="lineNum"> 252 </span> : // Log</a>
|
|
<a name="253"><span class="lineNum"> 253 </span> : </a>
|
|
<a name="254"><span class="lineNum"> 254 </span><span class="lineCov"> 2 : emit InstanceRemoved(_instanceAddress);</span></a>
|
|
<a name="255"><span class="lineNum"> 255 </span> : }</a>
|
|
<a name="256"><span class="lineNum"> 256 </span> : </a>
|
|
<a name="257"><span class="lineNum"> 257 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="258"><span class="lineNum"> 258 </span> : </a>
|
|
<a name="259"><span class="lineNum"> 259 </span> : function setTornadoRouter(address _newRouterAddress) external onlyGovernance {</a>
|
|
<a name="260"><span class="lineNum"> 260 </span><span class="lineCov"> 1 : router = TornadoRouter(_newRouterAddress);</span></a>
|
|
<a name="261"><span class="lineNum"> 261 </span><span class="lineCov"> 1 : emit RouterRegistered(_newRouterAddress);</span></a>
|
|
<a name="262"><span class="lineNum"> 262 </span> : }</a>
|
|
<a name="263"><span class="lineNum"> 263 </span> : </a>
|
|
<a name="264"><span class="lineNum"> 264 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="265"><span class="lineNum"> 265 </span> : </a>
|
|
<a name="266"><span class="lineNum"> 266 </span> : function getAllInstances() public view virtual returns (ITornadoInstance[] memory allInstances) {</a>
|
|
<a name="267"><span class="lineNum"> 267 </span><span class="lineCov"> 5 : return getInstances(0, instances.length - 1);</span></a>
|
|
<a name="268"><span class="lineNum"> 268 </span> : }</a>
|
|
<a name="269"><span class="lineNum"> 269 </span> : </a>
|
|
<a name="270"><span class="lineNum"> 270 </span> : function getInstances(uint256 _inclusiveStartIndex, uint256 _inclusiveEndIndex)</a>
|
|
<a name="271"><span class="lineNum"> 271 </span> : public</a>
|
|
<a name="272"><span class="lineNum"> 272 </span> : view</a>
|
|
<a name="273"><span class="lineNum"> 273 </span> : virtual</a>
|
|
<a name="274"><span class="lineNum"> 274 </span> : returns (ITornadoInstance[] memory allInstances)</a>
|
|
<a name="275"><span class="lineNum"> 275 </span> : {</a>
|
|
<a name="276"><span class="lineNum"> 276 </span><span class="lineCov"> 5 : allInstances = new ITornadoInstance[](1 + _inclusiveEndIndex - _inclusiveStartIndex);</span></a>
|
|
<a name="277"><span class="lineNum"> 277 </span> : </a>
|
|
<a name="278"><span class="lineNum"> 278 </span><span class="lineCov"> 5 : for (uint256 i = _inclusiveStartIndex; i < _inclusiveEndIndex + 1; i++) {</span></a>
|
|
<a name="279"><span class="lineNum"> 279 </span><span class="lineCov"> 95 : allInstances[i - _inclusiveStartIndex] = instances[i];</span></a>
|
|
<a name="280"><span class="lineNum"> 280 </span> : }</a>
|
|
<a name="281"><span class="lineNum"> 281 </span> : }</a>
|
|
<a name="282"><span class="lineNum"> 282 </span> : </a>
|
|
<a name="283"><span class="lineNum"> 283 </span> : function getAllInstanceStates() public view virtual returns (InstanceState[] memory data) {</a>
|
|
<a name="284"><span class="lineNum"> 284 </span><span class="lineCov"> 1 : return getInstanceState(0, instances.length - 1);</span></a>
|
|
<a name="285"><span class="lineNum"> 285 </span> : }</a>
|
|
<a name="286"><span class="lineNum"> 286 </span> : </a>
|
|
<a name="287"><span class="lineNum"> 287 </span> : function getInstanceState(uint256 _inclusiveStartIndex, uint256 _inclusiveEndIndex)</a>
|
|
<a name="288"><span class="lineNum"> 288 </span> : public</a>
|
|
<a name="289"><span class="lineNum"> 289 </span> : view</a>
|
|
<a name="290"><span class="lineNum"> 290 </span> : virtual</a>
|
|
<a name="291"><span class="lineNum"> 291 </span> : returns (InstanceState[] memory data)</a>
|
|
<a name="292"><span class="lineNum"> 292 </span> : {</a>
|
|
<a name="293"><span class="lineNum"> 293 </span><span class="lineCov"> 2 : data = new InstanceState[](1 + _inclusiveEndIndex - _inclusiveStartIndex);</span></a>
|
|
<a name="294"><span class="lineNum"> 294 </span> : </a>
|
|
<a name="295"><span class="lineNum"> 295 </span><span class="lineCov"> 2 : for (uint256 i = _inclusiveStartIndex; i < _inclusiveEndIndex + 1; i++) {</span></a>
|
|
<a name="296"><span class="lineNum"> 296 </span><span class="lineCov"> 26 : data[i - _inclusiveStartIndex] = instanceData[instances[i]];</span></a>
|
|
<a name="297"><span class="lineNum"> 297 </span> : }</a>
|
|
<a name="298"><span class="lineNum"> 298 </span> : }</a>
|
|
<a name="299"><span class="lineNum"> 299 </span> : </a>
|
|
<a name="300"><span class="lineNum"> 300 </span> : function getInstanceState(uint256 _index) public view virtual returns (InstanceState memory data) {</a>
|
|
<a name="301"><span class="lineNum"> 301 </span><span class="lineCov"> 2 : return instanceData[instances[_index]];</span></a>
|
|
<a name="302"><span class="lineNum"> 302 </span> : }</a>
|
|
<a name="303"><span class="lineNum"> 303 </span> : </a>
|
|
<a name="304"><span class="lineNum"> 304 </span> : function getInstanceState(ITornadoInstance _instance)</a>
|
|
<a name="305"><span class="lineNum"> 305 </span> : public</a>
|
|
<a name="306"><span class="lineNum"> 306 </span> : view</a>
|
|
<a name="307"><span class="lineNum"> 307 </span> : virtual</a>
|
|
<a name="308"><span class="lineNum"> 308 </span> : returns (InstanceState memory data)</a>
|
|
<a name="309"><span class="lineNum"> 309 </span> : {</a>
|
|
<a name="310"><span class="lineNum"> 310 </span><span class="lineCov"> 137 : return instanceData[_instance];</span></a>
|
|
<a name="311"><span class="lineNum"> 311 </span> : }</a>
|
|
<a name="312"><span class="lineNum"> 312 </span> : </a>
|
|
<a name="313"><span class="lineNum"> 313 </span> : function getInstanceToken(ITornadoInstance _instance) public view virtual returns (IERC20) {</a>
|
|
<a name="314"><span class="lineNum"> 314 </span><span class="lineCov"> 2 : return instanceData[_instance].token;</span></a>
|
|
<a name="315"><span class="lineNum"> 315 </span> : }</a>
|
|
<a name="316"><span class="lineNum"> 316 </span> : </a>
|
|
<a name="317"><span class="lineNum"> 317 </span> : function getInstanceIndex(ITornadoInstance _instance) public view virtual returns (uint80) {</a>
|
|
<a name="318"><span class="lineNum"> 318 </span><span class="lineCov"> 1 : return instanceData[_instance].index;</span></a>
|
|
<a name="319"><span class="lineNum"> 319 </span> : }</a>
|
|
<a name="320"><span class="lineNum"> 320 </span> : </a>
|
|
<a name="321"><span class="lineNum"> 321 </span> : function isRegisteredInstance(ITornadoInstance _instance) public view virtual returns (bool) {</a>
|
|
<a name="322"><span class="lineNum"> 322 </span><span class="lineCov"> 2 : return isEnabledInstance(_instance);</span></a>
|
|
<a name="323"><span class="lineNum"> 323 </span> : }</a>
|
|
<a name="324"><span class="lineNum"> 324 </span> : </a>
|
|
<a name="325"><span class="lineNum"> 325 </span> : function isEnabledInstance(ITornadoInstance _instance) public view virtual returns (bool) {</a>
|
|
<a name="326"><span class="lineNum"> 326 </span><span class="lineCov"> 4 : return instanceData[_instance].isEnabled;</span></a>
|
|
<a name="327"><span class="lineNum"> 327 </span> : }</a>
|
|
<a name="328"><span class="lineNum"> 328 </span> : </a>
|
|
<a name="329"><span class="lineNum"> 329 </span> : /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ENS GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */</a>
|
|
<a name="330"><span class="lineNum"> 330 </span> : </a>
|
|
<a name="331"><span class="lineNum"> 331 </span> : function isRegisteredInstanceByENSName(string memory _instanceENSName)</a>
|
|
<a name="332"><span class="lineNum"> 332 </span> : public</a>
|
|
<a name="333"><span class="lineNum"> 333 </span> : view</a>
|
|
<a name="334"><span class="lineNum"> 334 </span> : virtual</a>
|
|
<a name="335"><span class="lineNum"> 335 </span> : returns (bool)</a>
|
|
<a name="336"><span class="lineNum"> 336 </span> : {</a>
|
|
<a name="337"><span class="lineNum"> 337 </span><span class="lineNoCov"> 0 : return isEnabledInstanceByENSName(_instanceENSName);</span></a>
|
|
<a name="338"><span class="lineNum"> 338 </span> : }</a>
|
|
<a name="339"><span class="lineNum"> 339 </span> : </a>
|
|
<a name="340"><span class="lineNum"> 340 </span> : function isEnabledInstanceByENSName(string memory _instanceENSName) public view virtual returns (bool) {</a>
|
|
<a name="341"><span class="lineNum"> 341 </span><span class="lineNoCov"> 0 : return isEnabledInstance(getInstanceByENSName(_instanceENSName));</span></a>
|
|
<a name="342"><span class="lineNum"> 342 </span> : }</a>
|
|
<a name="343"><span class="lineNum"> 343 </span> : </a>
|
|
<a name="344"><span class="lineNum"> 344 </span> : function getInstanceByENSName(string memory _instanceENSName)</a>
|
|
<a name="345"><span class="lineNum"> 345 </span> : public</a>
|
|
<a name="346"><span class="lineNum"> 346 </span> : view</a>
|
|
<a name="347"><span class="lineNum"> 347 </span> : virtual</a>
|
|
<a name="348"><span class="lineNum"> 348 </span> : returns (ITornadoInstance)</a>
|
|
<a name="349"><span class="lineNum"> 349 </span> : {</a>
|
|
<a name="350"><span class="lineNum"> 350 </span><span class="lineCov"> 1 : return ITornadoInstance(resolveByName(_instanceENSName));</span></a>
|
|
<a name="351"><span class="lineNum"> 351 </span> : }</a>
|
|
<a name="352"><span class="lineNum"> 352 </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>
|