Remove unnecessary files

Signed-off-by: AlienTornadosaurusHex <>
This commit is contained in:
AlienTornadosaurusHex 2023-06-22 16:49:22 +00:00
commit ce43bb4787
5 changed files with 2 additions and 394 deletions

@ -2,6 +2,3 @@
MAINNET_RPC_URL=
ETHERSCAN_KEY=
PRIVATE_KEY=
# The one deployed from this repo
TORNADO_ROUTER_ADDRESS=

@ -5,6 +5,7 @@ The `relayer-registry` infra repository.
* [Latest Contracts](./src/v2/)
* [Contract Tests](./test/)
* [Test Coverage](./coverage/)
* [Gas usage](./gas/all.md)
* [Storage Layout](./storage/)
* [Deployment Scripts](./script/)

@ -1,138 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// STD imports
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";
// Local imports
import { ITornadoInstance } from "tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol";
import { FeeManager } from "../src/v1/tornado-proxy/FeeManager.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// SPD
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical
/// UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by
/// the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by
/// the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
}
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params)
external
payable
returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in
/// calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params)
external
payable
returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path
/// (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in
/// calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}
contract DeployScript is Script {
IERC20 public constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IERC20 public constant TORN = IERC20(0x77777FeDdddFfC19Ff86DB637967013e6C6A116C);
function run() external {
uint256 key = vm.envUint("PRIVATE_KEY");
ISwapRouter router = ISwapRouter(0xE592427A0AEce92De3Edee1F18E0157C05861564);
uint256 bal = TORN.balanceOf(0x895CB4C75e9be8ABA117bF4E044416C855018ea0);
vm.startBroadcast(key);
TORN.approve(address(router), bal);
ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
path: abi.encodePacked(TORN, uint24(10_000), WETH),
recipient: 0x895CB4C75e9be8ABA117bF4E044416C855018ea0,
deadline: block.timestamp + 6 minutes,
amountIn: bal,
amountOutMinimum: 0
});
router.exactInput(params);
vm.stopBroadcast();
}
}

@ -1,214 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// OZ imports
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
// Uniswap imports
import { IUniswapV3Factory } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import { IUniswapV3PoolState } from "@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol";
// Tornado imports
import { ITornadoInstance } from "tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol";
// Local imports
import { IFeeOracle, FeeData } from "./interfaces/IFeeOracle.sol";
import { UniswapV3OracleHelper } from "./libraries/UniswapV3OracleHelper.sol";
import { InstanceState } from "./InstanceRegistry.sol";
/**
* @dev The global configuration for the `UniswapV3FeeOracle` contract. TORN is used in all `getFee()` calls,
* the interval seconds for the TWAP oracle are global, and the minimum observation cardinality assures the
* former interval can be requested.
*/
struct GlobalOracleConfig {
uint24 tornPoolFee;
uint32 twapIntervalSeconds;
uint16 minObservationCardinality;
}
/**
* @title UniswapV3FeeOracle
* @author AlienTornadosaurusHex
* @notice A TORN fee oracle for any Uniswap V3 token pool.
*/
contract UniswapV3FeeOracle is IFeeOracle {
using SafeMath for uint256;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VARIABLES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/**
* @notice The Governance Proxy address
*/
address public immutable governanceProxyAddress;
/**
* @notice Global configuration valid across all `getFee()` (and other) calls
*/
GlobalOracleConfig public globals;
/**
* @notice Uniswap pool fees for each token registered
*/
mapping(IERC20 => uint24) public poolFeesByToken;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ EVENTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
event PoolFeeUpdated(IERC20 token, uint24 newPoolFee);
event GlobalTornPoolFeeUpdated(uint24 newPoolFee);
event GlobalTwapIntervalSecondsUpdated(uint32 newUniswapTimePeriod);
event GlobalMinObservationCardinalityUpdated(uint16 newMinObservationCardinality);
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ LOGIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
constructor(address _governanceProxyAddress) public {
governanceProxyAddress = _governanceProxyAddress;
}
modifier onlyGovernance() {
require(msg.sender == governanceProxyAddress, "UniswapV3FeeOracle: onlyGovernance");
_;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function update() public virtual override { }
function getFee(
IERC20 _torn,
ITornadoInstance _instance,
InstanceState memory _data,
FeeData memory _lastFee,
uint32 _feePercentDivisor
) public view virtual override returns (uint160) {
// If fee is 0 return
if (_lastFee.percent == 0) return 0;
// If it's not an ERC20 it has to be ETH, use the WETH token
_data.token = _data.isERC20 ? _data.token : IERC20(UniswapV3OracleHelper.WETH);
// Get global config
GlobalOracleConfig memory global = globals;
// Get pool fee for the token and calc the price ratio
uint256 tokenPriceRatio = UniswapV3OracleHelper.getPriceRatioOfTokens(
[address(_torn), address(_data.token)],
[global.tornPoolFee, poolFeesByToken[_data.token]],
global.twapIntervalSeconds
);
// And now all according to legacy calculation
return uint160(
_instance.denomination().mul(UniswapV3OracleHelper.RATIO_DIVIDER).div(tokenPriceRatio).mul(
uint256(_lastFee.percent)
).div(uint256(_feePercentDivisor))
);
}
/**
* @notice This function allows an external contract to rely on the selection mechanism of Uniswap pools
* based on this contracts minimum observation cardinality requirement.
*/
function getPriceRatioOfTokens(IERC20 target, IERC20 quote) public view virtual returns (uint256) {
return UniswapV3OracleHelper.getPriceRatioOfTokens(
[address(target), address(quote)],
[poolFeesByToken[target], poolFeesByToken[quote]],
globals.twapIntervalSeconds
);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function setPoolFeeForToken(IERC20 _token, uint24 _tokenPoolFee) public virtual onlyGovernance {
// Get global config
GlobalOracleConfig memory global = globals;
// Check whether globals are initialized
require(global.twapIntervalSeconds != 0, "UniswapV3FeeOracle: time period not initialized");
require(global.minObservationCardinality != 0, "UniswapV3FeeOracle: cardinality not initialized");
// Only do this if not zeroing out
if (_tokenPoolFee != 0) {
// Check whether a pool exists for the token + fee combination
address poolAddress = UniswapV3OracleHelper.UniswapV3Factory.getPool(
address(_token), UniswapV3OracleHelper.WETH, _tokenPoolFee
);
require(poolAddress != address(0), "UniswapV3FeeOracle: pool for token and fee does not exist");
// Check whether the pool has a large enough observation cardinality
(,,,, uint16 observationCardinalityNext,,) = IUniswapV3PoolState(poolAddress).slot0();
require(
global.minObservationCardinality <= observationCardinalityNext,
"UniswapV3FeeOracle: pool observation cardinality low"
);
}
// Store & log
poolFeesByToken[_token] = _tokenPoolFee;
emit PoolFeeUpdated(_token, _tokenPoolFee);
}
function setGlobalTornPoolFee(uint24 _newGlobalTornPoolFee, bool _setSpecific)
public
virtual
onlyGovernance
{
globals.tornPoolFee = _newGlobalTornPoolFee;
// For `getPriceRatioOfTokens`
if (_setSpecific) {
poolFeesByToken[IERC20(0x77777FeDdddFfC19Ff86DB637967013e6C6A116C)] = _newGlobalTornPoolFee;
}
emit GlobalTornPoolFeeUpdated(_newGlobalTornPoolFee);
}
function setGlobalTwapIntervalSeconds(uint32 _newGlobalTwapIntervalSeconds)
public
virtual
onlyGovernance
{
globals.twapIntervalSeconds = _newGlobalTwapIntervalSeconds;
emit GlobalTwapIntervalSecondsUpdated(_newGlobalTwapIntervalSeconds);
}
function setGlobalMinObservationCardinality(uint16 _newGlobalMinObservationCardinality)
public
virtual
onlyGovernance
{
globals.minObservationCardinality = _newGlobalMinObservationCardinality;
emit GlobalMinObservationCardinalityUpdated(_newGlobalMinObservationCardinality);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTERS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
function getGlobalTornPoolFee() public view virtual returns (uint24) {
return globals.tornPoolFee;
}
function getGlobalTwapIntervalSeconds() public view virtual returns (uint32) {
return globals.twapIntervalSeconds;
}
function getGlobalMinObservationCardinality() public view virtual returns (uint16) {
return globals.minObservationCardinality;
}
}

@ -1,38 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
// STD imports
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";
// Local imports
import { ITornadoInstance } from "tornado-anonymity-mining/contracts/interfaces/ITornadoInstance.sol";
import { FeeManager } from "../src/v1/tornado-proxy/FeeManager.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract DeployScript is Script {
IERC20 public constant WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IERC20 public constant TORN = IERC20(0x77777FeDdddFfC19Ff86DB637967013e6C6A116C);
function run() external {
uint256 key = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(key);
FeeManager fees = FeeManager(0x5f6c97C6AD7bdd0AE7E0Dd4ca33A4ED3fDabD4D7);
fees.updateFee(ITornadoInstance(0x910Cbd523D972eb0a6f4cAe4618aD62622b39DbF));
fees.updateFee(ITornadoInstance(0xA160cdAB225685dA1d56aa342Ad8841c3b53f291));
fees.updateFee(ITornadoInstance(0x07687e702b410Fa43f4cB4Af7FA097918ffD2730));
fees.updateFee(ITornadoInstance(0x23773E65ed146A459791799d01336DB287f25334));
vm.stopBroadcast();
}
}